use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class FilePropertiesController method index.
@RequestMapping(value = "/")
public String index(final Model model, final HttpServletRequest request, @RequestParam(value = "backFromCollections", required = false) final boolean backFromCollections) {
DataGridUser loggedUser = loggedUserUtils.getLoggedDataGridUser();
String uiMode = (String) request.getSession().getAttribute("uiMode");
if (uiMode == null || uiMode.isEmpty()) {
if (loggedUser.isAdmin()) {
uiMode = UI_ADMIN_MODE;
} else {
uiMode = UI_USER_MODE;
}
}
if (backFromCollections) {
model.addAttribute("jsonFilePropertySearch", jsonFilePropertySearch);
}
model.addAttribute("uiMode", uiMode);
return "metadata/metadataDisplay";
}
use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class PreferencesController method action.
@RequestMapping(value = "/action/")
public String action(final Model model, @ModelAttribute final UserPreferences preferences, final HttpServletRequest request, final HttpServletResponse response) throws DataGridConnectionRefusedException {
logger.info("action()");
logger.info("preferences:{}", preferences);
DataGridUser loggedUser = loggedUserUtils.getLoggedDataGridUser();
logger.debug("current logged in user:{}", loggedUser);
loggedUser.setLocale(preferences.getLocaleLanguage());
loggedUser.setForceFileOverwriting(preferences.isForceFileOverwriting());
loggedUser.setAdvanceView(preferences.isAdvancedView());
logger.debug("modified logged in user:{}", loggedUser);
userService.modifyUser(loggedUser);
logger.info("preferences were saved");
localeResolver.setLocale(request, response, StringUtils.parseLocaleString(preferences.getLocaleLanguage()));
return "redirect:/preferences/";
}
use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class FavoritesController method removeFavoriteFromUser.
/**
* Remove a path to the favorites list
*
* @param model
* @param path
* path to be removed from the favorites
*/
@RequestMapping(value = "/removeFavoriteFromUser/")
@ResponseBody
public String removeFavoriteFromUser(@RequestParam("path") final String path) {
String username = irodsServices.getCurrentUser();
logger.info("Request for removing a {} favorite from {}", path, username);
String zoneName = irodsServices.getCurrentUserZone();
DataGridUser user = userService.findByUsernameAndAdditionalInfo(username, zoneName);
Set<String> toRemove = new HashSet<String>();
toRemove.add(path);
boolean operationResult = favoritesService.updateFavorites(user, null, toRemove);
return operationResult ? REQUEST_OK : REQUEST_ERROR;
}
use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class FavoritesController method favoritesPaginated.
@RequestMapping(value = "/favoritesPaginated")
@ResponseBody
public String favoritesPaginated(final HttpServletRequest request) {
int draw = Integer.parseInt(request.getParameter("draw"));
int start = Integer.parseInt(request.getParameter("start"));
int length = Integer.parseInt(request.getParameter("length"));
String searchString = request.getParameter("search[value]");
int orderColumn = Integer.parseInt(request.getParameter("order[0][column]"));
String orderDir = request.getParameter("order[0][dir]");
boolean onlyCollections = Boolean.parseBoolean(request.getParameter("onlyCollections"));
String loggedUsername = irodsServices.getCurrentUser();
String loggedUserZoneName = irodsServices.getCurrentUserZone();
DataGridUser user = userService.findByUsernameAndAdditionalInfo(loggedUsername, loggedUserZoneName);
String[] orderBy = { "name", "path", "created_at", "is_collection" };
List<DataGridUserFavorite> userFavorites = favoritesService.findFavoritesPaginated(user, start, length, searchString, orderBy[orderColumn], orderDir, onlyCollections);
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> jsonResponse = new HashMap<String, Object>();
String jsonString = "";
if ("".equals(searchString)) {
totalFavorites = user.getFavorites().size();
totalFavoritesFiltered = user.getFavorites().size();
} else {
totalFavoritesFiltered = userFavorites.size();
}
jsonResponse.put("draw", String.valueOf(draw));
jsonResponse.put("recordsTotal", String.valueOf(totalFavorites));
jsonResponse.put("recordsFiltered", String.valueOf(totalFavoritesFiltered));
jsonResponse.put("data", userFavorites);
try {
jsonString = mapper.writeValueAsString(jsonResponse);
} catch (Exception e) {
logger.error("Could not parse hashmap in favorites to json", e.getMessage());
}
return jsonString;
}
use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class TemplateController method modifyTemplate.
@RequestMapping(value = "modify/action/")
public String modifyTemplate(final Model model, @ModelAttribute final MetadataTemplateForm templateForm, final RedirectAttributes redirectAttributes) {
DataGridTemplate template = null;
try {
template = templateService.findById(templateForm.getId());
if (template == null) {
throw new Exception("Cannot modify a non-existent template");
}
DataGridUser loggedUser = loggedUserUtils.getLoggedDataGridUser();
if (!template.getOwner().equalsIgnoreCase(loggedUser.getUsername())) {
throw new Exception("Cannot modify a template beloging to another user");
}
template.setTemplateName(templateForm.getTemplateName());
template.setDescription(templateForm.getDescription());
template.setUsageInformation(templateForm.getUsageInformation());
template.setAccessType(templateForm.getAccessType().toString());
List<String> positions = templateForm.getAvuPositions();
List<String> attributes = templateForm.getAvuAttributes();
List<String> values = templateForm.getAvuValues();
List<String> units = templateForm.getAvuUnits();
if (attributes != null) {
for (int i = 0; i < attributes.size(); i++) {
for (int j = i + 1; j < attributes.size(); j++) {
if (attributes.get(i).equals(attributes.get(j)) && !values.get(i).isEmpty() && values.get(i).equals(values.get(j)) && units.get(i).equals(units.get(j))) {
redirectAttributes.addFlashAttribute("repeatedAVU", true);
return "redirect:/templates/modify/";
}
}
}
}
if (positions != null) {
for (int i = 0; i < positions.size(); i++) {
String position = positions.get(i);
if (position.contains("mod_pos_")) {
addTemplateFields.get(Integer.parseInt(position.replace("mod_pos_", ""))).setAttribute(attributes.get(i));
addTemplateFields.get(Integer.parseInt(position.replace("mod_pos_", ""))).setValue(values.get(i));
addTemplateFields.get(Integer.parseInt(position.replace("mod_pos_", ""))).setUnit(units.get(i));
} else if (position.contains("mod_id_")) {
templateFieldService.modifyTemplateField(Long.parseLong(position.replace("mod_id_", "")), attributes.get(i), values.get(i), units.isEmpty() ? "" : units.get(i));
template.setModified(true);
}
}
}
// adding all fields to the template
for (TemplateFieldForm tempFieldForm : addTemplateFields) {
DataGridTemplateField dataGridTempField = mapTempFieldFormToDataGridTemp(tempFieldForm);
dataGridTempField.setTemplate(template);
templateFieldService.createTemplateField(dataGridTempField);
template.setModified(true);
}
Set<DataGridTemplateField> currentTempFields = template.getFields();
// removing fields from the template
for (TemplateFieldForm tempFieldForm : removeTemplateFields) {
DataGridTemplateField dataGridTempField = mapTempFieldFormToDataGridTemp(tempFieldForm);
dataGridTempField.setTemplate(template);
template.setModified(true);
// removing template fields from template
if (currentTempFields.remove(dataGridTempField)) {
templateFieldService.deleteTemplateField(dataGridTempField);
logger.debug("Template removed from memory and database");
} else // template field wasn't removed
{
throw new Exception("Could not removed template field from memory.");
}
}
template.setFields(currentTempFields);
templateService.modifyTemplate(template);
// reseting the temporary fields to be added and removed from a template
addTemplateFields = new ArrayList<TemplateFieldForm>();
removeTemplateFields = new ArrayList<TemplateFieldForm>();
redirectAttributes.addFlashAttribute("templateModifiedSuccessfully", template.getTemplateName());
selectedTemplates.clear();
} catch (Exception e) {
logger.error("Could not modify template {}.", templateForm.getTemplateName());
redirectAttributes.addFlashAttribute("templateNotModifiedSuccessfully", templateForm.getTemplateName());
}
return "redirect:/templates/";
}
Aggregations