Search in sources :

Example 36 with DataGridUser

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

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

the class UserController method usersToCSVFile.

@RequestMapping(value = "/usersToCSVFile/")
public void usersToCSVFile(HttpServletResponse response) {
    String loggedUser = loggedUserUtils.getLoggedDataGridUser().getUsername();
    String date = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String filename = String.format("users_%s_%s.csv", loggedUser, date);
    // Setting CSV Mime type
    response.setContentType("text/csv");
    response.setHeader("Content-disposition", "attachment;filename=" + filename);
    List<DataGridUser> users = userService.findAll();
    List<String> rows = new ArrayList<String>();
    rows.add("Username;Zone;FirstName;LastName;Email;UserType;UserProfile;Title;Company;Department;OrganizationalRole\n");
    for (DataGridUser user : users) {
        rows.add(user.getUsername() + ";");
        rows.add(user.getAdditionalInfo() + ";");
        rows.add((user.getFirstName() == null ? "" : user.getFirstName()) + ";");
        rows.add((user.getLastName() == null ? "" : user.getLastName()) + ";");
        rows.add((user.getEmail() == null ? "" : user.getEmail()) + ";");
        rows.add(user.getUserType() + ";");
        rows.add((user.getUserProfile() == null ? "" : user.getUserProfile()) + ";");
        rows.add((user.getTitle() == null ? "" : user.getTitle()) + ";");
        rows.add((user.getCompany() == null ? "" : user.getCompany()) + ";");
        rows.add((user.getDepartment() == null ? "" : user.getDepartment()) + ";");
        rows.add(user.getOrganizationalRole() == null ? "" : user.getOrganizationalRole());
        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 users", e);
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 38 with DataGridUser

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

the class UserController method findUserByQueryy.

/**
 * Queries the user DB to match users with the given query string. Returns JSON
 * body.
 *
 * @param model
 */
@RequestMapping(value = "/query/{query}/")
@ResponseBody
public String findUserByQueryy(Model model, @PathVariable String query) {
    ObjectMapper mapper = new ObjectMapper();
    List<DataGridUser> users = userService.findByQueryString(query);
    List<Map<String, Object>> userList = new ArrayList<Map<String, Object>>();
    for (DataGridUser user : users) {
        Map<String, Object> userMap = new LinkedHashMap<String, Object>();
        userMap.put("username", user.getUsername());
        userMap.put("first_name", user.getFirstName());
        userMap.put("last_name", user.getLastName());
        userList.add(userMap);
    }
    Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
    resultMap.put("results", userList);
    String resultJson = "";
    try {
        resultJson = mapper.writeValueAsString(resultMap);
    } catch (JsonProcessingException e) {
        logger.info("Could not parse Object to Json: ", e.getMessage());
    }
    return resultJson;
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) ArrayList(java.util.ArrayList) URLMap(com.emc.metalnx.modelattribute.enums.URLMap) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LinkedHashMap(java.util.LinkedHashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 39 with DataGridUser

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

the class DataGridAuthenticationSuccessHandler method onAuthenticationSuccess.

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
    logger.debug("Authentication successful!");
    String username = (String) authentication.getPrincipal();
    logger.debug("Applying user preferences to user [" + username + "]");
    DataGridUser loggedUser = userService.findByUsernameAndAdditionalInfo(username, zoneName);
    localeResolver.setLocale(request, response, StringUtils.parseLocaleString(loggedUser.getLocale()));
    if (loggedUser.isAdmin()) {
        response.sendRedirect("/emc-metalnx-web/dashboard/");
    } else {
        response.sendRedirect("/emc-metalnx-web/browse/home");
    }
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser)

Example 40 with DataGridUser

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

the class GroupController method showModifyGroupForm.

/**
 * Controller that shows the modification of group view.
 *
 * @param username
 * @param additionalInfo
 * @param model
 * @return
 * @throws DataGridConnectionRefusedException
 */
@RequestMapping(value = "modify/{groupname}/{additionalInfo}/", method = RequestMethod.GET)
public String showModifyGroupForm(@PathVariable String groupname, @PathVariable String additionalInfo, Model model) throws DataGridConnectionRefusedException {
    List<DataGridUser> users = userService.findAll();
    currentGroup = groupService.findByGroupnameAndZone(groupname, additionalInfo);
    String[] membersList;
    if (currentGroup != null) {
        membersList = groupService.getMemberList(currentGroup);
    } else {
        membersList = new String[0];
    }
    usersToBeAdded = new ArrayList<String>(Arrays.asList(membersList));
    currentGroup = groupService.findByGroupnameAndZone(groupname, additionalInfo);
    GroupForm groupForm = new GroupForm();
    if (currentGroup != null) {
        groupForm.setGroupname(groupname);
        groupForm.setAdditionalInfo(currentGroup.getAdditionalInfo());
        groupForm.setDataGridId(currentGroup.getDataGridId());
    }
    model.addAttribute("groupBookmarks", groupBookmarkService.findBookmarksForGroupAsString(currentGroup));
    model.addAttribute("groupForm", groupForm);
    model.addAttribute("requestMapping", "/groups/modify/action/");
    model.addAttribute("addReadPermissionsOnDirs", addReadPermissionsOnDirs);
    model.addAttribute("addWritePermissionsOnDirs", addWritePermissionsOnDirs);
    model.addAttribute("addOwnerOnDirs", addOwnerOnDirs);
    model.addAttribute("addInheritanceOnDirs", addInheritanceOnDirs);
    model.addAttribute("users", users);
    model.addAttribute("membersList", membersList);
    model.addAttribute("resultSize", users.size());
    model.addAttribute("foundUsers", users.size() > 0);
    model.addAttribute("zones", zoneService.findAll());
    model.addAttribute("groupZone", additionalInfo);
    return "groups/groupForm";
}
Also used : GroupForm(com.emc.metalnx.modelattribute.group.GroupForm) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser)

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