use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.
the class SyncJobs method executeGroupSync.
private void executeGroupSync() {
try {
// Gets all groups existing in iRODS
// OBS: we're using User to find Groups because UserGroup doesn't
// have the get type
// method and if we don't use such method we'll get a list of users
// and groups,
// rather than list containing only groups
List<User> irodsGroups = this.findAllIRODSUsers();
HashMap<Long, User> hashMapIRodsGroups = new HashMap<Long, User>();
for (User group : irodsGroups) {
if (group.getUserType() == UserTypeEnum.RODS_GROUP) {
hashMapIRodsGroups.put(Long.valueOf(group.getId()), group);
}
}
// Gets all groups existing in our database
List<DataGridGroup> dbGroups = groupDao.findAll(DataGridGroup.class);
HashMap<Long, DataGridGroup> hashMapDBGroups = new HashMap<Long, DataGridGroup>();
for (DataGridGroup dataGridGroup : dbGroups) {
hashMapDBGroups.put(dataGridGroup.getDataGridId(), dataGridGroup);
}
Set<Long> irodsGroupIDs = hashMapIRodsGroups.keySet();
Set<Long> dbDataGridGroupIDs = hashMapDBGroups.keySet();
// action: remove this Group from our database
for (Long id : dbDataGridGroupIDs) {
if (!irodsGroupIDs.contains(id)) {
String groupnameDeleted = hashMapDBGroups.get(id).getGroupname();
long groupID = hashMapDBGroups.get(id).getId();
long dataGridID = hashMapDBGroups.get(id).getDataGridId();
groupDao.deleteByDataGridGroupId(id);
logger.info("[DELETE] Group " + groupnameDeleted + " (iRODS id: " + groupID + ") " + " (DataGrid id: " + dataGridID + ") " + " was deleted from database.");
}
}
// action: add this Group to our database
for (Long id : irodsGroupIDs) {
if (!dbDataGridGroupIDs.contains(id)) {
// users and groups are dealt the same way by iRODS
User irodsGroupMissingInDB = hashMapIRodsGroups.get(id);
DataGridGroup groupMissingInDB = new DataGridGroup();
groupMissingInDB.setDataGridId(Long.valueOf(irodsGroupMissingInDB.getId()));
groupMissingInDB.setGroupname(irodsGroupMissingInDB.getName());
groupMissingInDB.setAdditionalInfo(irodsGroupMissingInDB.getZone());
groupDao.save(groupMissingInDB);
logger.info("[INSERT] Group " + groupMissingInDB.getGroupname() + " (iRODS id: " + groupMissingInDB.getDataGridId() + ") " + " was added to database");
}
}
} catch (Exception e) {
logger.error("Could not synchronize database and iRODS (Groups): ", e);
}
}
use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.
the class GroupBookmarkServiceImpl method getGroupsBookmarks.
@Override
public List<DataGridGroup> getGroupsBookmarks(String user, String additionalInfo) throws DataGridConnectionRefusedException, DataNotFoundException, JargonException {
List<DataGridGroup> groups = new ArrayList<DataGridGroup>();
if (user == null || additionalInfo == null || user.isEmpty() || additionalInfo.isEmpty()) {
logger.error("Could not get groups bookmarks. Username or zone empty");
return groups;
}
logger.info("Get groups bookmarks for {}", user);
UserAO userAO = adminServices.getUserAO();
User iRodsUser = userAO.findByName(user);
if (iRodsUser != null) {
String[] groupIds = userService.getGroupIdsForUser(user, additionalInfo);
groups = groupService.findByDataGridIdList(groupIds);
}
return groups;
}
use of com.emc.metalnx.core.domain.entity.DataGridGroup 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;
}
Aggregations