Search in sources :

Example 21 with DataGridUser

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";
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with DataGridUser

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/";
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with DataGridUser

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;
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 24 with DataGridUser

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;
}
Also used : HashMap(java.util.HashMap) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) DataGridUserFavorite(com.emc.metalnx.core.domain.entity.DataGridUserFavorite) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 25 with DataGridUser

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/";
}
Also used : TemplateFieldForm(com.emc.metalnx.modelattribute.template.field.TemplateFieldForm) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) DataGridTemplate(com.emc.metalnx.core.domain.entity.DataGridTemplate) DataGridTemplateUnitException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateUnitException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) JAXBException(javax.xml.bind.JAXBException) DataGridTemplateValueException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateValueException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataGridTooLongTemplateNameException(com.emc.metalnx.core.domain.exceptions.DataGridTooLongTemplateNameException) IOException(java.io.IOException) DataGridTemplateAttrException(com.emc.metalnx.core.domain.exceptions.DataGridTemplateAttrException) DataGridTemplateField(com.emc.metalnx.core.domain.entity.DataGridTemplateField) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)48 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)28 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 JargonException (org.irods.jargon.core.exception.JargonException)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 DataGridGroup (com.emc.metalnx.core.domain.entity.DataGridGroup)5 User (org.irods.jargon.core.pub.domain.User)5 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)4 HashMap (java.util.HashMap)4 Query (org.hibernate.Query)4 UserAO (org.irods.jargon.core.pub.UserAO)4 Authentication (org.springframework.security.core.Authentication)4 UserProfile (com.emc.metalnx.core.domain.entity.UserProfile)3 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 DataGridUserBookmark (com.emc.metalnx.core.domain.entity.DataGridUserBookmark)2 DataGridUserFavorite (com.emc.metalnx.core.domain.entity.DataGridUserFavorite)2 URLMap (com.emc.metalnx.modelattribute.enums.URLMap)2 GroupForm (com.emc.metalnx.modelattribute.group.GroupForm)2