Search in sources :

Example 16 with DataGridGroup

use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.

the class UserController method addUser.

/**
 * Controller method that executes action 'create user'
 *
 * @param user
 * @return the name of the template to render
 * @throws DataGridConnectionRefusedException
 */
@RequestMapping(value = "add/action/", method = RequestMethod.POST)
public String addUser(@ModelAttribute UserForm user, HttpServletRequest request, RedirectAttributes redirectAttributes) throws DataGridConnectionRefusedException {
    logger.info("addUser()");
    if (user == null) {
        throw new IllegalArgumentException("null user");
    }
    DataGridUser newUser = new DataGridUser();
    newUser.setAdditionalInfo(user.getAdditionalInfo());
    newUser.setUsername(user.getUsername());
    newUser.setFirstName(user.getFirstName());
    newUser.setLastName(user.getLastName());
    newUser.setEmail(user.getEmail());
    newUser.setUserType(user.getUserType());
    newUser.setOrganizationalRole(user.getOrganizationalRole() != null ? user.getOrganizationalRole() : "");
    newUser.setCompany(user.getCompany() != null ? user.getCompany() : "");
    newUser.setDepartment(user.getDepartment() != null ? user.getDepartment() : "");
    logger.info("adding user:{}", newUser);
    String selectedProfile = request.getParameter("selectedProfile");
    String[] groupList = groupsToBeAdded.toArray(new String[groupsToBeAdded.size()]);
    List<DataGridGroup> groups = new ArrayList<DataGridGroup>();
    if (groupList != null && groupList.length != 0) {
        groups = groupService.findByDataGridIdList(groupList);
    }
    boolean groupsUpdateSuccessful = false;
    boolean creationSucessful = false;
    try {
        logger.info("creating the user...");
        creationSucessful = userService.createUser(newUser, user.getPassword());
        logger.info("creation successful? {}", creationSucessful);
        // Updating the group list for the recently-created user
        if (creationSucessful) {
            // adding read, write and ownership permissions to a set of collections
            userService.updateReadPermissions(newUser, addReadPermissionsOnDirs, removeReadPermissionsOnDirs);
            userService.updateWritePermissions(newUser, addWritePermissionsOnDirs, removeWritePermissionsOnDirs);
            userService.updateOwnership(newUser, addOwnerOnDirs, removeOwnerOnDirs);
            cleanPermissionsSets();
            DataGridUser userForGroups = userService.findByUsernameAndAdditionalInfo(newUser.getUsername(), newUser.getAdditionalInfo());
            groupsUpdateSuccessful = userService.updateGroupList(userForGroups, groups);
            if (selectedProfile != null && selectedProfile != "") {
                UserProfile userProfile = userProfileService.findById(Long.valueOf(selectedProfile));
                userService.applyProfileToUser(userProfile, userForGroups);
                userForGroups.setUserProfile(userProfile);
            } else {
                user.setUserProfile(null);
            }
            // User bookmarks
            updateBookmarksList(newUser.getUsername(), newUser.getAdditionalInfo());
            userService.modifyUser(userForGroups);
            redirectAttributes.addFlashAttribute("userAddedSuccessfully", user.getUsername());
        }
    } catch (DuplicateDataException e) {
        redirectAttributes.addFlashAttribute("duplicateUser", ExceptionEnum.USERS_DATA_DUPLICATE_EXCEPTION.getCode());
        logger.error("Could not create user: ", e);
    } catch (JargonException e) {
        redirectAttributes.addFlashAttribute("error", ExceptionEnum.JARGON_EXCEPTION.getCode());
        logger.error("Could not create user: ", e);
    }
    return creationSucessful && groupsUpdateSuccessful ? "redirect:/users/" : "redirect:/users/add/";
}
Also used : DuplicateDataException(org.irods.jargon.core.exception.DuplicateDataException) UserProfile(com.emc.metalnx.core.domain.entity.UserProfile) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) JargonException(org.irods.jargon.core.exception.JargonException) ArrayList(java.util.ArrayList) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with DataGridGroup

use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.

the class UserProfileController method createUserProfile.

@RequestMapping(value = "/create/action/")
public String createUserProfile(@ModelAttribute UserProfileForm userProfileForm, Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
    UserProfile newUserProfile = new UserProfile();
    newUserProfile.setProfileName(userProfileForm.getProfileName());
    newUserProfile.setDescription(userProfileForm.getDescription());
    // Getting group list from UI
    // String[] groupList = request.getParameterValues("groupIdsList");
    String[] groupList = groupIdsList.toArray(new String[groupIdsList.size()]);
    List<DataGridGroup> groups = new ArrayList<DataGridGroup>();
    if (groupList != null && groupList.length != 0) {
        groups = groupService.findByIdList(groupList);
    }
    Set<DataGridGroup> groupSet = new HashSet<DataGridGroup>(groups);
    Long userProfileId = userProfileService.createUserProfile(newUserProfile);
    newUserProfile = userProfileService.findById(userProfileId);
    newUserProfile.setGroups(groupSet);
    userProfileService.modifyUserProfile(newUserProfile);
    if (newUserProfile != null) {
        redirectAttributes.addFlashAttribute("userProfileAddedSuccessfully", newUserProfile.getProfileName());
    }
    return "redirect:/users/profile/";
}
Also used : UserProfile(com.emc.metalnx.core.domain.entity.UserProfile) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup)

Example 18 with DataGridGroup

use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.

the class UserProfileController method showModifyForm.

@RequestMapping(value = "/modify/{profileId}/")
public String showModifyForm(Model model, @PathVariable String profileId) {
    UserProfile userProfile = userProfileService.findById(Long.valueOf(profileId));
    List<DataGridGroup> groups = groupService.findAll();
    UserProfileForm userProfileForm = new UserProfileForm();
    if (userProfile != null) {
        userProfileForm.setProfileId(String.valueOf(userProfile.getProfileId()));
        userProfileForm.setProfileName(userProfile.getProfileName());
        userProfileForm.setDescription(userProfile.getDescription());
        int groupsQuantity = userProfile.getGroups().size(), i = 0;
        String[] groupsOnProfileList = new String[groupsQuantity];
        for (DataGridGroup group : userProfile.getGroups()) {
            groupsOnProfileList[i++] = String.valueOf(group.getId());
        }
        model.addAttribute("groupsOnProfileList", groupsOnProfileList);
        groupIdsList = new ArrayList<String>(Arrays.asList(groupsOnProfileList));
    }
    model.addAttribute("userProfileForm", userProfileForm);
    model.addAttribute("groups", groups);
    model.addAttribute("resultSize", groups.size());
    model.addAttribute("foundGroups", groups.size() > 0);
    model.addAttribute("requestMapping", "/users/profile/modify/action/");
    return "userProfile/userProfileForm";
}
Also used : UserProfileForm(com.emc.metalnx.modelattribute.user.profile.UserProfileForm) UserProfile(com.emc.metalnx.core.domain.entity.UserProfile) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup)

Example 19 with DataGridGroup

use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.

the class UserProfileController method modifyUserProfile.

@RequestMapping(value = "/modify/action/")
public String modifyUserProfile(@ModelAttribute UserProfileForm userProfileForm, HttpServletRequest request, RedirectAttributes redirectAttributes) {
    // Getting group list from UI
    // String[] groupList = request.getParameterValues("groupIdsList");
    String[] groupList = groupIdsList.toArray(new String[groupIdsList.size()]);
    List<DataGridGroup> groups = new ArrayList<DataGridGroup>();
    if (groupList != null && groupList.length != 0) {
        groups = groupService.findByIdList(groupList);
    }
    Set<DataGridGroup> groupSet = new HashSet<DataGridGroup>(groups);
    // Updating the UserProfile entity
    UserProfile userProfile = userProfileService.findById(Long.valueOf(userProfileForm.getProfileId()));
    userProfile.setProfileName(userProfileForm.getProfileName());
    userProfile.setDescription(userProfileForm.getDescription());
    userProfile.setGroups(groupSet);
    userProfileService.modifyUserProfile(userProfile);
    if (userProfile != null) {
        redirectAttributes.addFlashAttribute("userProfileModifiedSuccessfully", userProfile.getProfileName());
    }
    return "redirect:/users/profile/";
}
Also used : UserProfile(com.emc.metalnx.core.domain.entity.UserProfile) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup)

Example 20 with DataGridGroup

use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.

the class GroupController method updateBookmarksList.

/*
     * ********************************************************************************************
     * ******************************** PRIVATE ***************************************
     * ********************************************************************************************
     */
/**
 * Persists the changes on the bookmarks lists for the given group on the database
 *
 * @param groupName
 */
private void updateBookmarksList(String groupName) {
    DataGridGroup group = groupService.findByGroupname(groupName).get(0);
    Set<String> bookmarksToAdd = bookmarkController.getAddBookmark();
    Set<String> bookmarksToRemove = bookmarkController.getRemoveBookmark();
    groupBookmarkService.updateBookmarks(group, bookmarksToAdd, bookmarksToRemove);
    bookmarkController.clearBookmarksLists();
}
Also used : DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup)

Aggregations

DataGridGroup (com.emc.metalnx.core.domain.entity.DataGridGroup)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)6 UserProfile (com.emc.metalnx.core.domain.entity.UserProfile)5 ArrayList (java.util.ArrayList)4 JargonException (org.irods.jargon.core.exception.JargonException)4 HashSet (java.util.HashSet)3 Query (org.hibernate.Query)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)2 UserForm (com.emc.metalnx.modelattribute.user.UserForm)2 UserProfileForm (com.emc.metalnx.modelattribute.user.profile.UserProfileForm)2 HashMap (java.util.HashMap)2 DuplicateDataException (org.irods.jargon.core.exception.DuplicateDataException)2 UserGroupAO (org.irods.jargon.core.pub.UserGroupAO)2 User (org.irods.jargon.core.pub.domain.User)2 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)1 DataGridZone (com.emc.metalnx.core.domain.entity.DataGridZone)1 DataGridPermType (com.emc.metalnx.core.domain.entity.enums.DataGridPermType)1 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)1