Search in sources :

Example 1 with DataGridGroup

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

the class UserServiceImpl method updateGroupList.

@Override
public boolean updateGroupList(DataGridUser user, List<DataGridGroup> groups) throws DataGridConnectionRefusedException {
    UserGroupAO groupAO = irodsServices.getGroupAO();
    try {
        // List current groups for user
        List<UserGroup> groupsFromIrods = groupAO.findUserGroupsForUser(user.getUsername());
        // Building set with iRODS IDs already on this group
        HashMap<Long, UserGroup> idsFromIrods = new HashMap<Long, UserGroup>();
        for (UserGroup groupFromIrods : groupsFromIrods) {
            idsFromIrods.put(Long.valueOf(groupFromIrods.getUserGroupId()), groupFromIrods);
        }
        // Building set with iRODS IDs coming from UI
        HashMap<Long, DataGridGroup> idsFromUi = new HashMap<Long, DataGridGroup>();
        for (DataGridGroup groupFromUi : groups) {
            idsFromUi.put(groupFromUi.getDataGridId(), groupFromUi);
        }
        // Resolving differences from UI to iRODS
        Set<Long> keysFromUi = idsFromUi.keySet();
        Set<Long> keysFromIrods = idsFromIrods.keySet();
        // Committing changes to iRODS
        for (Long dataGridId : keysFromUi) {
            if (!keysFromIrods.contains(dataGridId)) {
                groupService.attachUserToGroup(user, idsFromUi.get(dataGridId));
            }
        }
        for (Long dataGridId : keysFromIrods) {
            if (!keysFromUi.contains(dataGridId)) {
                DataGridGroup group = new DataGridGroup();
                group.setGroupname(idsFromIrods.get(dataGridId).getUserGroupName());
                if (group.getGroupname().compareTo("public") != 0) {
                    groupService.removeUserFromGroup(user, group);
                }
            }
        }
        return true;
    } catch (Exception e) {
        logger.info("Could not update [" + user.getUsername() + "] group list: ", e);
    }
    return false;
}
Also used : HashMap(java.util.HashMap) UserGroupAO(org.irods.jargon.core.pub.UserGroupAO) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException) UserGroup(org.irods.jargon.core.pub.domain.UserGroup)

Example 2 with DataGridGroup

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

the class GroupDaoImpl method findByGroupname.

@Override
public List<DataGridGroup> findByGroupname(String groupname) {
    List<DataGridGroup> dataGridGroups = null;
    Query q = sessionFactory.getCurrentSession().createQuery("from DataGridGroup where groupname = :groupname");
    q.setString("groupname", groupname);
    dataGridGroups = q.list();
    return dataGridGroups;
}
Also used : Query(org.hibernate.Query) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup)

Example 3 with DataGridGroup

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

the class GroupDaoImpl method findByGroupnameAndZone.

@Override
public DataGridGroup findByGroupnameAndZone(String groupname, String zone) {
    Query q = sessionFactory.getCurrentSession().createQuery("from DataGridGroup where groupname = :groupname and additional_info = :zone");
    q.setString("groupname", groupname);
    q.setParameter("zone", zone);
    return (DataGridGroup) q.uniqueResult();
}
Also used : Query(org.hibernate.Query) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup)

Example 4 with DataGridGroup

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

the class GroupDaoImpl method findByDataGridId.

@Override
public DataGridGroup findByDataGridId(long id) {
    Query q = sessionFactory.getCurrentSession().createQuery("from DataGridGroup where data_grid_id=(:id)");
    q.setParameter("id", id);
    List<DataGridGroup> groups = q.list();
    return groups.size() > 0 ? groups.get(0) : null;
}
Also used : Query(org.hibernate.Query) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup)

Example 5 with DataGridGroup

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

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