Search in sources :

Example 1 with IRODSFileSystemAO

use of org.irods.jargon.core.pub.IRODSFileSystemAO 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 IRODSFileSystemAO

use of org.irods.jargon.core.pub.IRODSFileSystemAO in project metalnx-web by irods-contrib.

the class PermissionsServiceImpl method canLoggedUserModifyPermissionOnPath.

@Override
public boolean canLoggedUserModifyPermissionOnPath(String path) throws DataGridConnectionRefusedException {
    String userName = irodsServices.getCurrentUser();
    final IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
    final IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
    try {
        int resultingPermission;
        final IRODSFile fileObj = irodsFileFactory.instanceIRODSFile(path);
        if (irodsFileSystemAO.isDirectory(fileObj)) {
            resultingPermission = irodsFileSystemAO.getDirectoryPermissionsForGivenUser(fileObj, userName);
        } else {
            resultingPermission = irodsFileSystemAO.getFilePermissionsForGivenUser(fileObj, userName);
        }
        return resultingPermission > FilePermissionEnum.WRITE.getPermissionNumericValue();
    } catch (final Exception e) {
        logger.error("Could not get permissions for current user: {}", e.getMessage());
    }
    return false;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) IRODSFileSystemAO(org.irods.jargon.core.pub.IRODSFileSystemAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException)

Example 3 with IRODSFileSystemAO

use of org.irods.jargon.core.pub.IRODSFileSystemAO in project metalnx-web by irods-contrib.

the class CollectionServiceImpl method modifyCollectionAndDataObject.

@Override
public boolean modifyCollectionAndDataObject(String previousPath, String newPath, boolean inheritOption) throws DataGridConnectionRefusedException {
    logger.info("modifyCollectionAndDataObject()");
    IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
    IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
    CollectionAO collectionAO = irodsServices.getCollectionAO();
    logger.debug("Modify Collection/DataObject {} to {}", previousPath, newPath);
    try {
        logger.debug("Locating {} in iRODS", previousPath);
        IRODSFile previousFile = irodsFileFactory.instanceIRODSFile(previousPath);
        logger.info("Creating new IRODSFile instance for {}", newPath);
        IRODSFile newFile = irodsFileFactory.instanceIRODSFile(newPath);
        boolean isDirectory = irodsFileSystemAO.isDirectory(previousFile);
        if (previousPath.compareTo(newPath) != 0) {
            // checking if the path given is a collection
            if (isDirectory) {
                logger.debug("{} is a collection", previousPath);
                irodsFileSystemAO.renameDirectory(previousFile, newFile);
            } else // the path given is a data object
            {
                logger.debug("{} is a data object", previousPath);
                irodsFileSystemAO.renameFile(previousFile, newFile);
            }
        }
        // Updating inheritance option on the collection, if needed
        String zoneName = irodsFileSystemAO.getIRODSServerProperties().getRodsZone();
        if (isDirectory) {
            boolean isInheritanceSetForNewCollection = collectionAO.isCollectionSetForPermissionInheritance(newPath);
            if (inheritOption != isInheritanceSetForNewCollection) {
                // enable inheritance for this collection
                if (inheritOption) {
                    logger.debug("Setting inheritance option on {}", newPath);
                    collectionAO.setAccessPermissionInherit(zoneName, newPath, false);
                } else // disable inheritance for this collection
                {
                    logger.debug("Removing inheritance setting on {}", newPath);
                    collectionAO.setAccessPermissionToNotInherit(zoneName, newPath, false);
                }
            }
        }
        return true;
    } catch (JargonException e) {
        logger.error("Could not edit Collection/DataObject {} to {}: ", previousPath, newPath, e);
    }
    return false;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) CollectionAO(org.irods.jargon.core.pub.CollectionAO) JargonException(org.irods.jargon.core.exception.JargonException) IRODSFileSystemAO(org.irods.jargon.core.pub.IRODSFileSystemAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Example 4 with IRODSFileSystemAO

use of org.irods.jargon.core.pub.IRODSFileSystemAO in project metalnx-web by irods-contrib.

the class CollectionServiceImpl method createCollection.

@Override
public boolean createCollection(DataGridCollectionAndDataObject collection) throws DataGridException {
    logger.info("createCollection()");
    boolean collCreated;
    try {
        IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
        IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
        IRODSFile newFile = irodsFileFactory.instanceIRODSFile(collection.getParentPath(), collection.getName());
        irodsFileSystemAO.mkdir(newFile, false);
        // Updating inheritance option on the collection, if needed
        CollectionAO collectionAO = irodsServices.getCollectionAO();
        String zoneName = irodsFileSystemAO.getIRODSServerProperties().getRodsZone();
        // enable inheritance for this collection
        if (collection.isInheritanceOption()) {
            collectionAO.setAccessPermissionInherit(zoneName, collection.getPath(), false);
        } else // disable inheritance for this collection
        if ("own".equals(getPermissionsForPath(collection.getParentPath()))) {
            collectionAO.setAccessPermissionToNotInherit(zoneName, collection.getPath(), false);
        }
        collCreated = true;
    } catch (JargonException e) {
        logger.debug("Could not create a collection in the data grid: {}", e.getMessage());
        throw new DataGridException(e.getMessage());
    }
    return collCreated;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) CollectionAO(org.irods.jargon.core.pub.CollectionAO) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) JargonException(org.irods.jargon.core.exception.JargonException) IRODSFileSystemAO(org.irods.jargon.core.pub.IRODSFileSystemAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Example 5 with IRODSFileSystemAO

use of org.irods.jargon.core.pub.IRODSFileSystemAO in project metalnx-web by irods-contrib.

the class FileOperationServiceImpl method deleteItem.

@Override
public boolean deleteItem(String path, boolean force) throws DataGridConnectionRefusedException {
    if (path == null || path.isEmpty())
        return false;
    IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
    IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
    boolean itemDeleted = false;
    try {
        IRODSFile itemToBeRemoved = irodsFileFactory.instanceIRODSFile(path);
        if (irodsFileSystemAO.isDirectory(itemToBeRemoved)) {
            // if force set to true, we do an irm -rf
            if (force) {
                logger.info("Deleting directory (force) {}", path);
                irodsFileSystemAO.directoryDeleteForce(itemToBeRemoved);
            } else // irm
            {
                logger.info("Deleting directory {}", path);
                irodsFileSystemAO.directoryDeleteNoForce(itemToBeRemoved);
            }
        } else {
            // if force set to false, we do an irm
            if (force) {
                logger.info("Deleting data obj (force) {}", path);
                irodsFileSystemAO.fileDeleteForce(itemToBeRemoved);
            } else // irm
            {
                logger.info("Deleting data obj {}", path);
                irodsFileSystemAO.fileDeleteNoForce(itemToBeRemoved);
            }
        }
        itemDeleted = true;
        // item deleted, we need to delete any bookmarks related to it
        userBookmarkService.removeBookmarkBasedOnPath(path);
        userBookmarkService.removeBookmarkBasedOnRelativePath(path);
        groupBookmarkService.removeBookmarkBasedOnPath(path);
        groupBookmarkService.removeBookmarkBasedOnRelativePath(path);
        favoritesService.removeFavoriteBasedOnPath(path);
        favoritesService.removeFavoriteBasedOnRelativePath(path);
    } catch (JargonException e) {
        logger.error("Could not delete item " + path + ": ", e);
    }
    return itemDeleted;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) JargonException(org.irods.jargon.core.exception.JargonException) IRODSFileSystemAO(org.irods.jargon.core.pub.IRODSFileSystemAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Aggregations

JargonException (org.irods.jargon.core.exception.JargonException)7 IRODSFileSystemAO (org.irods.jargon.core.pub.IRODSFileSystemAO)7 IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)7 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)7 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)2 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)2 CollectionAO (org.irods.jargon.core.pub.CollectionAO)2 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)1 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)1 JargonQueryException (org.irods.jargon.core.query.JargonQueryException)1