Search in sources :

Example 1 with UserGroupAO

use of org.irods.jargon.core.pub.UserGroupAO 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 UserGroupAO

use of org.irods.jargon.core.pub.UserGroupAO in project metalnx-web by irods-contrib.

the class UserServiceImpl method getGroupIdsForUser.

@Override
public String[] getGroupIdsForUser(DataGridUser user) throws DataGridConnectionRefusedException {
    UserGroupAO userGroupAO = irodsServices.getGroupAO();
    try {
        // Getting list of groups the user belongs to.
        List<UserGroup> groups = userGroupAO.findUserGroupsForUser(user.getUsername());
        // Building Data Grid IDs list
        String[] ids = new String[groups.size()];
        for (int i = 0; i < groups.size(); i++) {
            ids[i] = groups.get(i).getUserGroupId();
        }
        // Returning results
        return ids;
    } catch (JargonException e) {
        logger.error("Could not find group list for user [" + user.getUsername() + "], ", e);
    }
    // If something goes wrong, return empty list.
    return new String[0];
}
Also used : JargonException(org.irods.jargon.core.exception.JargonException) UserGroupAO(org.irods.jargon.core.pub.UserGroupAO) UserGroup(org.irods.jargon.core.pub.domain.UserGroup)

Example 3 with UserGroupAO

use of org.irods.jargon.core.pub.UserGroupAO in project metalnx-web by irods-contrib.

the class GroupServiceImpl method getMemberList.

@Override
public String[] getMemberList(DataGridGroup group) throws DataGridConnectionRefusedException {
    UserGroupAO userGroupAO = irodsServices.getGroupAO();
    try {
        List<User> groupMembers = userGroupAO.listUserGroupMembers(group.getGroupname());
        String[] dataGridIds = new String[groupMembers.size()];
        for (int i = 0; i < groupMembers.size(); i++) {
            dataGridIds[i] = groupMembers.get(i).getId();
        }
        return dataGridIds;
    } catch (JargonException e) {
        logger.error("Could not get members list for group [" + group.getGroupname() + "]: ", e);
    }
    return new String[0];
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) User(org.irods.jargon.core.pub.domain.User) JargonException(org.irods.jargon.core.exception.JargonException) UserGroupAO(org.irods.jargon.core.pub.UserGroupAO)

Example 4 with UserGroupAO

use of org.irods.jargon.core.pub.UserGroupAO in project metalnx-web by irods-contrib.

the class GroupServiceImpl method deleteGroupByGroupname.

@Override
public boolean deleteGroupByGroupname(String groupname) throws DataGridConnectionRefusedException {
    boolean groupDeleted = false;
    UserGroupAO groupAO = irodsServices.getGroupAO();
    try {
        DataGridGroup group = groupDao.findByGroupnameAndZone(groupname, configService.getIrodsZone());
        // remove group from the data grid
        groupAO.removeUserGroup(groupname);
        // Removing group bookmarks associated to this group
        userBookmarkService.removeBookmarkBasedOnPath(String.format("/%s/home/%s", configService.getIrodsZone(), groupname));
        groupBookmarkService.removeBookmarkBasedOnGroup(group);
        // remove user from the Mlx database
        groupDeleted = groupDao.deleteByGroupname(groupname);
    } catch (JargonException e) {
        logger.error("Could not execute removeUserGroup(String groupname)/" + "deleteByGroupname(groupname) on UserGroupAO/GroupDao class(es): ", e);
    } catch (Exception e) {
        logger.error("Could not execute delete group (dao)");
    }
    return groupDeleted;
}
Also used : JargonException(org.irods.jargon.core.exception.JargonException) UserGroupAO(org.irods.jargon.core.pub.UserGroupAO) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DuplicateDataException(org.irods.jargon.core.exception.DuplicateDataException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException)

Example 5 with UserGroupAO

use of org.irods.jargon.core.pub.UserGroupAO 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

JargonException (org.irods.jargon.core.exception.JargonException)6 UserGroupAO (org.irods.jargon.core.pub.UserGroupAO)6 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)3 DuplicateDataException (org.irods.jargon.core.exception.DuplicateDataException)3 UserGroup (org.irods.jargon.core.pub.domain.UserGroup)3 DataGridGroup (com.emc.metalnx.core.domain.entity.DataGridGroup)2 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)2 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)2 User (org.irods.jargon.core.pub.domain.User)2 HashMap (java.util.HashMap)1