Search in sources :

Example 1 with DataGridConnectionRefusedException

use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.

the class MetadataServiceImpl method populateVisibilityForCurrentUser.

/**
 * Sets whether or not a user can check an object resulting from a metadata
 * search
 *
 * @param objectList
 *            list of data objects/collections
 * @throws DataGridConnectionRefusedException
 */
@Override
public void populateVisibilityForCurrentUser(List<DataGridCollectionAndDataObject> objectList) throws DataGridConnectionRefusedException {
    if (objectList == null || objectList.isEmpty()) {
        return;
    }
    final String currentUser = irodsServices.getCurrentUser();
    final IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
    final IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
    for (final DataGridCollectionAndDataObject obj : objectList) {
        try {
            int resultingPermission;
            final IRODSFile fileObj = irodsFileFactory.instanceIRODSFile(obj.getPath());
            if (obj.isCollection()) {
                resultingPermission = irodsFileSystemAO.getDirectoryPermissionsForGivenUser(fileObj, currentUser);
            } else {
                resultingPermission = irodsFileSystemAO.getFilePermissionsForGivenUser(fileObj, currentUser);
            }
            // By default, the visibility of a user over an object is set to false
            obj.setVisibleToCurrentUser(resultingPermission != FilePermissionEnum.NONE.getPermissionNumericValue());
        } catch (final Exception e) {
            logger.error("Could not get permissions for current user: {}", e.getMessage());
        }
    }
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) IRODSFileSystemAO(org.irods.jargon.core.pub.IRODSFileSystemAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException) JargonQueryException(org.irods.jargon.core.query.JargonQueryException)

Example 2 with DataGridConnectionRefusedException

use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.

the class MetadataServiceImpl method findByMetadata.

@Override
public List<DataGridCollectionAndDataObject> findByMetadata(List<DataGridMetadataSearch> searchList, DataGridPageContext pageContext, int pageNum, int pageSize) throws DataGridConnectionRefusedException {
    List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = new ArrayList<>();
    List<DataGridCollectionAndDataObject> dataGridObjects;
    List<DataGridCollectionAndDataObject> dataGridCollections;
    int totalCollections;
    int totalDataObjects;
    int startIndex = (pageNum - 1) * pageSize;
    int endIndex = (pageNum * pageSize) - 1;
    int endIndexForDataObjs;
    int endIndexForCollections;
    try {
        String zone = irodsServices.getCurrentUserZone();
        totalCollections = specQueryService.countCollectionsMatchingMetadata(searchList, zone);
        totalDataObjects = specQueryService.countDataObjectsMatchingMetadata(searchList, zone);
        pageContext.setStartItemNumber(startIndex + 1);
        pageContext.setTotalNumberOfItems(totalCollections + totalDataObjects);
        if (endIndex + 1 <= totalCollections) {
            // looking for collections
            SpecificQueryResultSet resultSetColls = specQueryService.searchByMetadata(searchList, zone, true, pageContext, startIndex, pageSize);
            dataGridCollections = DataGridUtils.mapMetadataResultSetToDataGridCollections(resultSetColls);
            endIndexForCollections = dataGridCollections.size();
            dataGridCollectionAndDataObjects.addAll(dataGridCollections);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + endIndexForCollections - 1);
        } else if (startIndex + 1 > totalCollections) {
            // looking for data objects
            SpecificQueryResultSet resultSetDataObjs = specQueryService.searchByMetadata(searchList, zone, false, pageContext, startIndex - totalCollections, pageSize);
            dataGridObjects = DataGridUtils.mapMetadataResultSetToDataGridObjects(resultSetDataObjs);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + dataGridObjects.size() - 1);
            dataGridCollectionAndDataObjects.addAll(dataGridObjects);
        } else {
            // looking for collections
            SpecificQueryResultSet resultSetColls = specQueryService.searchByMetadata(searchList, zone, true, pageContext, startIndex, pageSize);
            dataGridCollections = DataGridUtils.mapMetadataResultSetToDataGridCollections(resultSetColls);
            endIndexForDataObjs = pageSize - (totalCollections % pageSize);
            // looking for data objects
            SpecificQueryResultSet resultSetDataObjs = specQueryService.searchByMetadata(searchList, zone, false, pageContext, 0, endIndexForDataObjs);
            dataGridObjects = DataGridUtils.mapMetadataResultSetToDataGridObjects(resultSetDataObjs);
            endIndexForDataObjs = endIndexForDataObjs > dataGridObjects.size() ? dataGridObjects.size() : endIndexForDataObjs;
            dataGridCollectionAndDataObjects.addAll(dataGridCollections);
            dataGridCollectionAndDataObjects.addAll(dataGridObjects);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + endIndexForDataObjs + dataGridCollections.size() - 1);
        }
    } catch (DataGridConnectionRefusedException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Could not find data objects by metadata. ", e.getMessage());
    }
    populateVisibilityForCurrentUser(dataGridCollectionAndDataObjects);
    return dataGridCollectionAndDataObjects;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) ArrayList(java.util.ArrayList) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException) JargonQueryException(org.irods.jargon.core.query.JargonQueryException)

Example 3 with DataGridConnectionRefusedException

use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.

the class UserServiceImpl method deleteUserByUsername.

@Override
public boolean deleteUserByUsername(String username) throws DataGridConnectionRefusedException {
    UserAO userAO = irodsServices.getUserAO();
    try {
        DataGridUser user = findByUsername(username).get(0);
        String userHomeFolder = String.format("/%s/home/%s", configService.getIrodsZone(), username);
        // Removing user
        userAO.deleteUser(username);
        userDao.deleteByUsername(username);
        // Removing favorites and user bookmarks before removing user
        userBookmarkService.removeBookmarkBasedOnUser(user);
        userBookmarkService.removeBookmarkBasedOnPath(userHomeFolder);
        favoritesService.removeFavoriteBasedOnUser(user);
        favoritesService.removeFavoriteBasedOnPath(userHomeFolder);
        return true;
    } catch (Exception e) {
        logger.error("Could not delete user with username [" + username + "]");
    }
    return false;
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) UserAO(org.irods.jargon.core.pub.UserAO) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException)

Example 4 with DataGridConnectionRefusedException

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

Example 5 with DataGridConnectionRefusedException

use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.

the class BrowseController method getFileInfo.

/**
 * Gets checksum, total number of replicas and where each replica lives in the
 * data grid for a specific data object
 *
 * @param model
 * @param path
 *            path to the data object to get checksum and replica information
 * @return the template that shows the data object information
 * @throws DataGridException
 * @throws FileNotFoundException
 */
@RequestMapping(value = "/info/", method = RequestMethod.POST)
public String getFileInfo(final Model model, final String path) throws DataGridException, FileNotFoundException {
    logger.info("CollectionController getInfoFile() starts :: " + path);
    DataGridCollectionAndDataObject dataGridObj = null;
    Map<DataGridCollectionAndDataObject, DataGridResource> replicasMap = null;
    try {
        dataGridObj = cs.findByName(path);
        if (dataGridObj != null && !dataGridObj.isCollection()) {
            replicasMap = cs.listReplicasByResource(path);
            dataGridObj.setChecksum(cs.getChecksum(path));
            dataGridObj.setNumberOfReplicas(cs.getTotalNumberOfReplsForDataObject(path));
            dataGridObj.setReplicaNumber(String.valueOf(cs.getReplicationNumber(path)));
            permissionsService.resolveMostPermissiveAccessForUser(dataGridObj, loggedUserUtils.getLoggedDataGridUser());
        }
    } catch (DataGridConnectionRefusedException e) {
        logger.error("Could not connect to the data grid", e);
        throw e;
    } catch (DataGridException e) {
        logger.error("Could not get file info for {}", path, e);
        throw e;
    } catch (FileNotFoundException e) {
        logger.error("file does not exist for:{}", path, e);
        throw e;
    }
    model.addAttribute("collectionAndDataObject", dataGridObj);
    model.addAttribute("currentCollection", dataGridObj);
    model.addAttribute("replicasMap", replicasMap);
    model.addAttribute("infoFlag", true);
    logger.info("CollectionController getInfoFile() ends !!");
    return "collections/info :: infoView";
// return "collections/info";
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)24 JargonException (org.irods.jargon.core.exception.JargonException)17 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)10 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 IOException (java.io.IOException)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 ArrayList (java.util.ArrayList)6 DataGridResource (com.emc.metalnx.core.domain.entity.DataGridResource)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 HashMap (java.util.HashMap)5 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)5 IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)4 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 DataGridPageContext (com.emc.metalnx.core.domain.entity.DataGridPageContext)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ConnectException (java.net.ConnectException)3 UserGroupAO (org.irods.jargon.core.pub.UserGroupAO)3 DataGridGroup (com.emc.metalnx.core.domain.entity.DataGridGroup)2