Search in sources :

Example 1 with UserProfile

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

the class UserController method modifyUser.

/**
 * Updates the user on the current DB.
 *
 * @param userForm
 * @return the users views template name
 * @throws DataGridConnectionRefusedException
 */
@RequestMapping(value = "modify/action/", method = RequestMethod.POST)
public String modifyUser(@ModelAttribute UserForm userForm, HttpServletRequest request, RedirectAttributes redirectAttributes) throws DataGridConnectionRefusedException {
    String[] groupList = groupsToBeAdded.toArray(new String[groupsToBeAdded.size()]);
    List<DataGridGroup> groups = new ArrayList<DataGridGroup>();
    if (groupList != null && groupList.length != 0) {
        groups = groupService.findByDataGridIdList(groupList);
    }
    DataGridUser user = userService.findByUsernameAndAdditionalInfo(userForm.getUsername(), userForm.getAdditionalInfo());
    boolean modificationSucessful = false;
    boolean updateGroupsSuccessful = false;
    if (user != null) {
        user.setAdditionalInfo(userForm.getAdditionalInfo());
        user.setUsername(userForm.getUsername());
        user.setPassword(userForm.getPassword());
        user.setFirstName(userForm.getFirstName());
        user.setLastName(userForm.getLastName());
        user.setEmail(userForm.getEmail());
        user.setOrganizationalRole(userForm.getOrganizationalRole() != null ? userForm.getOrganizationalRole() : "");
        user.setUserType(userForm.getUserType());
        user.setCompany(userForm.getCompany() != null ? userForm.getCompany() : "");
        user.setDepartment(userForm.getDepartment() != null ? userForm.getDepartment() : "");
        // User bookmarks
        updateBookmarksList(user.getUsername(), user.getAdditionalInfo());
        modificationSucessful = userService.modifyUser(user);
        updateGroupsSuccessful = userService.updateGroupList(user, groups);
        if (modificationSucessful && updateGroupsSuccessful) {
            redirectAttributes.addFlashAttribute("userModifiedSuccessfully", userForm.getUsername());
            // Updating permissions on collections
            userService.updateOwnership(user, addOwnerOnDirs, removeOwnerOnDirs);
            userService.updateWritePermissions(user, addWritePermissionsOnDirs, removeWritePermissionsOnDirs);
            userService.updateReadPermissions(user, addReadPermissionsOnDirs, removeReadPermissionsOnDirs);
        }
    }
    // Applying selected profile to the user
    String selectedProfile = request.getParameter("selectedProfile");
    if (selectedProfile != null && selectedProfile != "") {
        UserProfile userProfile = userProfileService.findById(Long.valueOf(selectedProfile));
        userService.applyProfileToUser(userProfile, user);
        user.setUserProfile(userProfile);
    } else {
        user.setUserProfile(null);
    }
    userService.modifyUser(user);
    cleanPermissionsSets();
    return modificationSucessful && updateGroupsSuccessful ? "redirect:/users/" : "redirect:/users/modify/" + user.getUsername() + "/" + user.getAdditionalInfo() + "/";
}
Also used : UserProfile(com.emc.metalnx.core.domain.entity.UserProfile) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) ArrayList(java.util.ArrayList) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with UserProfile

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

the class UserProfileController method groupsToCSVFile.

@RequestMapping(value = "/profilesToCSVFile/")
public void groupsToCSVFile(HttpServletResponse response) {
    String loggedUser = loggedUserUtils.getLoggedDataGridUser().getUsername();
    String date = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String filename = String.format("user_profiles_%s_%s.csv", loggedUser, date);
    // Setting CSV Mime type
    response.setContentType("text/csv");
    response.setHeader("Content-disposition", "attachment;filename=" + filename);
    List<UserProfile> profiles = userProfileService.findAll();
    List<String> rows = new ArrayList<String>();
    rows.add("UserProfileName;Description;Groups\n");
    for (UserProfile profile : profiles) {
        rows.add(profile.getProfileName() + ";");
        rows.add(profile.getDescription() + ";");
        String groupNames = StringUtils.join(profile.getGroups().toArray(), " ");
        rows.add(groupNames);
        rows.add("\n");
    }
    try {
        ServletOutputStream outputStream = response.getOutputStream();
        // Writing CSV file
        Iterator<String> fileIterator = rows.iterator();
        while (fileIterator.hasNext()) {
            outputStream.print(fileIterator.next());
        }
        outputStream.flush();
    } catch (IOException e) {
        logger.error("Could not generate CSV file for groups", e);
    }
}
Also used : UserProfile(com.emc.metalnx.core.domain.entity.UserProfile) ServletOutputStream(javax.servlet.ServletOutputStream) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with UserProfile

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

the class UserProfileServiceImpl method removeUserProfile.

@Override
public void removeUserProfile(UserProfile profile) {
    profile = userProfileDao.findByID(UserProfile.class, profile.getProfileId());
    for (DataGridUser user : profile.getUsers()) {
        DataGridUser userToUpdate = userDao.findByID(DataGridUser.class, user.getId());
        userToUpdate.setUserProfile(null);
        userDao.merge(userToUpdate);
    }
    profile.getUsers().clear();
    userProfileDao.delete(profile);
}
Also used : UserProfile(com.emc.metalnx.core.domain.entity.UserProfile) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser)

Example 4 with UserProfile

use of com.emc.metalnx.core.domain.entity.UserProfile 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 5 with UserProfile

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

the class UserProfileController method remove.

@RequestMapping(value = "/remove/{profileId}/")
public String remove(@PathVariable String profileId, Model model, RedirectAttributes redirectAttributes) {
    UserProfile profileToRemove = userProfileService.findById(Long.valueOf(profileId));
    String profileName = profileToRemove.getProfileName();
    userProfileService.removeUserProfile(profileToRemove);
    redirectAttributes.addFlashAttribute("profileRemovedSuccessfully", profileName);
    return "redirect:/users/profile/";
}
Also used : UserProfile(com.emc.metalnx.core.domain.entity.UserProfile)

Aggregations

UserProfile (com.emc.metalnx.core.domain.entity.UserProfile)8 DataGridGroup (com.emc.metalnx.core.domain.entity.DataGridGroup)5 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)3 ArrayList (java.util.ArrayList)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 UserProfileForm (com.emc.metalnx.modelattribute.user.profile.UserProfileForm)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 DuplicateDataException (org.irods.jargon.core.exception.DuplicateDataException)1 JargonException (org.irods.jargon.core.exception.JargonException)1