Search in sources :

Example 6 with UserGroupAO

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

the class GroupServiceImpl method updateMemberList.

@Override
public boolean updateMemberList(DataGridGroup group, List<DataGridUser> users) throws DataGridConnectionRefusedException {
    try {
        UserGroupAO groupAO = irodsServices.getGroupAO();
        // Users that are currently on this group
        List<User> usersFromIrods = groupAO.listUserGroupMembers(group.getGroupname());
        // Building set with iRODS IDs already on this group
        HashMap<Long, User> idsFromIrods = new HashMap<Long, User>();
        for (User userFromIrods : usersFromIrods) {
            idsFromIrods.put(Long.valueOf(userFromIrods.getId()), userFromIrods);
        }
        // Building set with iRODS IDs coming from UI
        HashMap<Long, DataGridUser> idsFromUi = new HashMap<Long, DataGridUser>();
        for (DataGridUser userFromUi : users) {
            idsFromUi.put(userFromUi.getDataGridId(), userFromUi);
        }
        // Resolving differences from UI to iRODS
        Set<Long> keysFromUi = idsFromUi.keySet();
        Set<Long> keysFromIrods = idsFromIrods.keySet();
        for (Long dataGridId : keysFromUi) {
            if (!keysFromIrods.contains(dataGridId)) {
                attachUserToGroup(idsFromUi.get(dataGridId), group);
            }
        }
        for (Long dataGridId : keysFromIrods) {
            if (!keysFromUi.contains(dataGridId)) {
                DataGridUser user = new DataGridUser();
                user.setUsername(idsFromIrods.get(dataGridId).getName());
                removeUserFromGroup(user, group);
            }
        }
        return true;
    } catch (Exception e) {
        logger.info("Could not update [" + group.getGroupname() + "]: ", e);
    }
    return false;
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) User(org.irods.jargon.core.pub.domain.User) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) UserGroupAO(org.irods.jargon.core.pub.UserGroupAO) 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)

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