Search in sources :

Example 11 with IRODSFileFactory

use of org.irods.jargon.core.pub.io.IRODSFileFactory 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 12 with IRODSFileFactory

use of org.irods.jargon.core.pub.io.IRODSFileFactory 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 13 with IRODSFileFactory

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

Example 14 with IRODSFileFactory

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

the class FileOperationServiceImpl method deleteCollection.

@Override
public boolean deleteCollection(String collectionPath, boolean forceFlag) throws DataGridException {
    IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
    IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
    try {
        IRODSFile collectionToBeRemoved = irodsFileFactory.instanceIRODSFile(collectionPath);
        if (forceFlag) {
            irodsFileSystemAO.directoryDeleteForce(collectionToBeRemoved);
        } else {
            irodsFileSystemAO.directoryDeleteNoForce(collectionToBeRemoved);
        }
        return true;
    } catch (JargonException e) {
        logger.error("Could not delete collection: ", e.getMessage());
    }
    return false;
}
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)

Example 15 with IRODSFileFactory

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

the class FileOperationServiceImpl method copyFileIntoHttpResponse.

/**
 * Copies a buffered input stream from a file to a HTTP response for
 * downloading.
 *
 * @param path
 *            path to the file in iRODS to be added to the HTTP response
 * @param response
 *            HTTP response to let the user download the file
 * @return True, if the file was successfully added to the HTTP response. False,
 *         otherwise.
 * @throws DataGridConnectionRefusedException
 *             is Metalnx cannot connect to the data grid
 */
private boolean copyFileIntoHttpResponse(String path, HttpServletResponse response) throws DataGridConnectionRefusedException {
    boolean isCopySuccessFul = true;
    IRODSFileInputStream irodsFileInputStream = null;
    IRODSFile irodsFile = null;
    logger.debug("Trying to copy path stream {} to user", path);
    try {
        String fileName = path.substring(path.lastIndexOf("/") + 1, path.length());
        logger.debug("The filename is [{}]", fileName);
        logger.debug("Initiating iRodsFileFactory");
        IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
        logger.debug("Getting iRodsFileFactory instance for {}", path);
        irodsFile = irodsFileFactory.instanceIRODSFile(path);
        logger.debug("Creating stream from {}", irodsFile);
        irodsFileInputStream = irodsFileFactory.instanceIRODSFileInputStream(irodsFile);
        // set file mime type
        response.setContentType(CONTENT_TYPE);
        response.setHeader("Content-Disposition", String.format(HEADER_FORMAT, fileName));
        response.setContentLength((int) irodsFile.length());
        FileCopyUtils.copy(irodsFileInputStream, response.getOutputStream());
    } catch (IOException e) {
        logger.error("Could not put the file in the Http response ", e);
        isCopySuccessFul = false;
    } catch (JargonException e) {
        logger.error("Could not copy file in the Http response: ", e.getMessage());
        isCopySuccessFul = false;
    } finally {
        try {
            if (irodsFileInputStream != null)
                irodsFileInputStream.close();
            if (irodsFile != null)
                irodsFile.close();
        } catch (Exception e) {
            logger.error("Could not close stream(s): ", e.getMessage());
        }
    }
    return isCopySuccessFul;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) IRODSFileInputStream(org.irods.jargon.core.pub.io.IRODSFileInputStream) JargonException(org.irods.jargon.core.exception.JargonException) IOException(java.io.IOException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) DataGridChecksumException(com.emc.metalnx.core.domain.exceptions.DataGridChecksumException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataNotFoundException(org.irods.jargon.core.exception.DataNotFoundException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridReplicateException(com.emc.metalnx.core.domain.exceptions.DataGridReplicateException) DataGridRuleException(com.emc.metalnx.core.domain.exceptions.DataGridRuleException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) IOException(java.io.IOException)

Aggregations

IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)23 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)23 JargonException (org.irods.jargon.core.exception.JargonException)17 CollectionAO (org.irods.jargon.core.pub.CollectionAO)7 IRODSFileSystemAO (org.irods.jargon.core.pub.IRODSFileSystemAO)7 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)6 DataObjectAO (org.irods.jargon.core.pub.DataObjectAO)6 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)4 IOException (java.io.IOException)4 DataTransferOperations (org.irods.jargon.core.pub.DataTransferOperations)4 File (java.io.File)3 DataGridChecksumException (com.emc.metalnx.core.domain.exceptions.DataGridChecksumException)2 DataGridTicketInvalidUserException (com.emc.metalnx.core.domain.exceptions.DataGridTicketInvalidUserException)2 InputStream (java.io.InputStream)2 IRODSAccount (org.irods.jargon.core.connection.IRODSAccount)2 Stream2StreamAO (org.irods.jargon.core.pub.Stream2StreamAO)2 IRODSFileInputStream (org.irods.jargon.core.pub.io.IRODSFileInputStream)2 IRODSTestSetupUtilities (org.irods.jargon.testutils.IRODSTestSetupUtilities)2 TestingPropertiesHelper (org.irods.jargon.testutils.TestingPropertiesHelper)2 ScratchFileUtils (org.irods.jargon.testutils.filemanip.ScratchFileUtils)2