Search in sources :

Example 1 with DuplicateDataException

use of org.irods.jargon.core.exception.DuplicateDataException 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 2 with DuplicateDataException

use of org.irods.jargon.core.exception.DuplicateDataException in project metalnx-web by irods-contrib.

the class GroupServiceImpl method createGroup.

@Override
public boolean createGroup(DataGridGroup newGroup, List<DataGridUser> usersToBeAttached) throws DataGridConnectionRefusedException {
    UserGroupAO groupAO = irodsServices.getGroupAO();
    // Translating to iRODS model format
    UserGroup irodsGroup = new UserGroup();
    irodsGroup.setUserGroupName(newGroup.getGroupname());
    irodsGroup.setZone(newGroup.getAdditionalInfo());
    try {
        irodsGroup.setUserGroupName(newGroup.getGroupname());
        irodsGroup.setZone(newGroup.getAdditionalInfo());
        // creating group in iRODS
        groupAO.addUserGroup(irodsGroup);
        // Recovering the recently created group to get the data grid id.
        irodsGroup = groupAO.findByName(irodsGroup.getUserGroupName());
        newGroup.setDataGridId(Long.parseLong(irodsGroup.getUserGroupId()));
        // Persisting the new group into our database
        groupDao.save(newGroup);
        // attaching users to this group
        updateMemberList(newGroup, usersToBeAttached);
        return true;
    } catch (DuplicateDataException e) {
        logger.error("UserGroup " + newGroup.getGroupname() + " already exists: ", e);
    } catch (JargonException e) {
        logger.error("Could not execute createGroup() on UserGroupAO class: ", e);
    }
    return false;
}
Also used : DuplicateDataException(org.irods.jargon.core.exception.DuplicateDataException) JargonException(org.irods.jargon.core.exception.JargonException) UserGroupAO(org.irods.jargon.core.pub.UserGroupAO) UserGroup(org.irods.jargon.core.pub.domain.UserGroup)

Aggregations

DuplicateDataException (org.irods.jargon.core.exception.DuplicateDataException)2 JargonException (org.irods.jargon.core.exception.JargonException)2 DataGridGroup (com.emc.metalnx.core.domain.entity.DataGridGroup)1 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)1 UserProfile (com.emc.metalnx.core.domain.entity.UserProfile)1 ArrayList (java.util.ArrayList)1 UserGroupAO (org.irods.jargon.core.pub.UserGroupAO)1 UserGroup (org.irods.jargon.core.pub.domain.UserGroup)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1