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