Search in sources :

Example 21 with DataGridGroup

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);
    }
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) User(org.irods.jargon.core.pub.domain.User) HashMap(java.util.HashMap) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup) JargonException(org.irods.jargon.core.exception.JargonException)

Example 22 with DataGridGroup

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;
}
Also used : User(org.irods.jargon.core.pub.domain.User) ArrayList(java.util.ArrayList) UserAO(org.irods.jargon.core.pub.UserAO) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup)

Example 23 with DataGridGroup

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

Aggregations

DataGridGroup (com.emc.metalnx.core.domain.entity.DataGridGroup)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)6 UserProfile (com.emc.metalnx.core.domain.entity.UserProfile)5 ArrayList (java.util.ArrayList)4 JargonException (org.irods.jargon.core.exception.JargonException)4 HashSet (java.util.HashSet)3 Query (org.hibernate.Query)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)2 UserForm (com.emc.metalnx.modelattribute.user.UserForm)2 UserProfileForm (com.emc.metalnx.modelattribute.user.profile.UserProfileForm)2 HashMap (java.util.HashMap)2 DuplicateDataException (org.irods.jargon.core.exception.DuplicateDataException)2 UserGroupAO (org.irods.jargon.core.pub.UserGroupAO)2 User (org.irods.jargon.core.pub.domain.User)2 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)1 DataGridZone (com.emc.metalnx.core.domain.entity.DataGridZone)1 DataGridPermType (com.emc.metalnx.core.domain.entity.enums.DataGridPermType)1 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)1