Search in sources :

Example 11 with DataGridUser

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

the class UserBookmarkController method addBookmarkToGroup.

@RequestMapping(value = "/addBookmarkToUser/")
@ResponseBody
public String addBookmarkToGroup(@RequestParam("username") final String username, @RequestParam("path") final String path) {
    logger.info("addBookmarkToGroup()");
    String zoneName = irodsServices.getCurrentUserZone();
    DataGridUser user = userService.findByUsernameAndAdditionalInfo(username, zoneName);
    if (user == null) {
        return REQUEST_ERROR;
    }
    Set<String> toAdd = new HashSet<String>();
    toAdd.add(path);
    return userBookmarkService.updateBookmarks(user, toAdd, null) ? 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 12 with DataGridUser

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

the class SyncJobs method executeUsersSync.

private void executeUsersSync() {
    try {
        // Gets all users existing in iRODS
        List<User> irodsUsers = this.findAllIRODSUsers();
        HashMap<Long, User> hashMapIRodsUsers = new HashMap<Long, User>();
        for (User user : irodsUsers) {
            if (user.getUserType() != UserTypeEnum.RODS_GROUP) {
                hashMapIRodsUsers.put(Long.valueOf(user.getId()), user);
            }
        }
        // Gets all users existing in our database
        List<DataGridUser> dbUsers = userDao.findAll(DataGridUser.class);
        HashMap<Long, DataGridUser> hashMapDBUsers = new HashMap<Long, DataGridUser>();
        for (DataGridUser dataGridUser : dbUsers) {
            hashMapDBUsers.put(dataGridUser.getDataGridId(), dataGridUser);
        }
        Set<Long> irodsUserIDs = hashMapIRodsUsers.keySet();
        Set<Long> dbDataGridUserIDs = hashMapDBUsers.keySet();
        // action: remove this user from our database
        for (Long id : dbDataGridUserIDs) {
            if (!irodsUserIDs.contains(id)) {
                String usernameDeleted = hashMapDBUsers.get(id).getUsername();
                long userID = hashMapDBUsers.get(id).getId();
                long dataGridID = hashMapDBUsers.get(id).getDataGridId();
                userDao.deleteByDataGridId(id);
                logger.info("[DELETE] User " + usernameDeleted + " (iRODS id: " + userID + ") " + " (DataGrid id: " + dataGridID + ") " + " was deleted from database.");
            }
        }
        // action: add this user to our database
        for (Long id : irodsUserIDs) {
            if (!dbDataGridUserIDs.contains(id)) {
                User irodsUserMissingInDB = hashMapIRodsUsers.get(id);
                DataGridUser userMissingInDB = new DataGridUser();
                userMissingInDB.setDataGridId(Long.valueOf(irodsUserMissingInDB.getId()));
                userMissingInDB.setUsername(irodsUserMissingInDB.getName());
                userMissingInDB.setAdditionalInfo(irodsUserMissingInDB.getZone());
                userMissingInDB.setUserType(irodsUserMissingInDB.getUserType().getTextValue());
                userMissingInDB.setEnabled(true);
                userDao.save(userMissingInDB);
                logger.info("[INSERT] User " + userMissingInDB.getUsername() + " (iRODS id: " + userMissingInDB.getDataGridId() + ") " + " was added to database.");
            }
        }
    } catch (Exception e) {
        logger.error("Could not synchronize database and iRODS (users): ", e);
    }
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) User(org.irods.jargon.core.pub.domain.User) HashMap(java.util.HashMap) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) JargonException(org.irods.jargon.core.exception.JargonException)

Example 13 with DataGridUser

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

the class GroupController method showAddGroupForm.

/**
 * Responds the request for the url "add/". It adds a new GroupForm to the Model and sets the
 * form's action to "add".
 *
 * @param model
 * @return the userForm template
 * @throws DataGridConnectionRefusedException
 */
@RequestMapping(value = "add/", method = RequestMethod.GET)
public String showAddGroupForm(Model model) throws DataGridConnectionRefusedException {
    groupForm = new GroupForm();
    model.addAttribute("groupForm", groupForm);
    model.addAttribute("requestMapping", "/groups/add/action/");
    // gets all users from iRODS to be attached to a group
    List<DataGridUser> users = userService.findAll();
    String[] membersList = new String[0];
    usersToBeAdded = new ArrayList<String>(Arrays.asList(membersList));
    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", "");
    return "groups/groupForm";
}
Also used : GroupForm(com.emc.metalnx.modelattribute.group.GroupForm) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser)

Example 14 with DataGridUser

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

the class GroupController method addGroup.

/**
 * Controller method that executes action 'create group'
 *
 * @param user
 * @return the name of the template to render
 * @throws DataGridConnectionRefusedException
 */
@RequestMapping(value = "add/action/", method = RequestMethod.POST)
public String addGroup(@ModelAttribute GroupForm groupForm, HttpServletRequest httpServletRequest, RedirectAttributes redirectAttributes) throws DataGridConnectionRefusedException {
    DataGridGroup newGroup = new DataGridGroup();
    newGroup.setGroupname(groupForm.getGroupname());
    newGroup.setAdditionalInfo(groupForm.getAdditionalInfo());
    // Get the list of users to be attached to the group
    String[] idsList = usersToBeAdded.toArray(new String[usersToBeAdded.size()]);
    List<DataGridUser> usersToBeAttached = new ArrayList<DataGridUser>();
    if (idsList != null && idsList.length != 0) {
        usersToBeAttached = userService.findByDataGridIds(idsList);
    }
    if (groupService.createGroup(newGroup, usersToBeAttached) == false) {
        return "redirect:/groups/add/";
    }
    // Updating permissions on collections
    // boolean recursive = false;
    groupService.updateReadPermissions(newGroup, addReadPermissionsOnDirs, removeReadPermissionsOnDirs);
    groupService.updateWritePermissions(newGroup, addWritePermissionsOnDirs, removeWritePermissionsOnDirs);
    groupService.updateOwnership(newGroup, addOwnerOnDirs, removeOwnerOnDirs);
    // Setting the Group's home collection as a bookmark by default
    bookmarkController.addPathAsGroupBookmark(groupService.getGroupCollectionPath(newGroup.getGroupname()));
    // Updating bookmarks
    updateBookmarksList(newGroup.getGroupname());
    redirectAttributes.addFlashAttribute("groupAddedSuccessfully", groupForm.getGroupname());
    collectionService.updateInheritanceOptions(addInheritanceOnDirs, removeInheritanceOnDirs, newGroup.getAdditionalInfo());
    cleanModificationSets();
    currentGroup = null;
    return "redirect:/groups/";
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup)

Example 15 with DataGridUser

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

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