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;
}
Aggregations