Search in sources :

Example 1 with IRODSFile

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

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

the class FileOperationServiceImpl method computeChecksum.

@Override
public void computeChecksum(String path, String filename) throws DataGridChecksumException, DataGridConnectionRefusedException {
    if (path == null || path.isEmpty() || filename == null || filename.isEmpty())
        throw new DataGridChecksumException("Could not calculate checksum. File path is invalid.");
    logger.info("Computing checksum for {} ({})", filename, path);
    IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
    DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
    IRODSFile file;
    try {
        file = irodsFileFactory.instanceIRODSFile(path, filename);
        dataObjectAO.computeMD5ChecksumOnDataObject(file);
    } catch (JargonException e) {
        logger.error("Could not calculate checksum: {}", e.getMessage());
        throw new DataGridChecksumException("Could not calculate checksum.");
    }
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) JargonException(org.irods.jargon.core.exception.JargonException) DataGridChecksumException(com.emc.metalnx.core.domain.exceptions.DataGridChecksumException) DataObjectAO(org.irods.jargon.core.pub.DataObjectAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Example 3 with IRODSFile

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

the class FileOperationServiceImpl method copy.

@Override
public boolean copy(String sourcePath, String dstPath, boolean copyWithMetadata) throws DataGridConnectionRefusedException {
    IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
    DataTransferOperations dataTransferOperations = irodsServices.getDataTransferOperations();
    boolean isCopied = false;
    try {
        IRODSFile source = irodsFileFactory.instanceIRODSFile(sourcePath);
        IRODSFile target = irodsFileFactory.instanceIRODSFile(dstPath);
        dataTransferOperations.copy(source, target, null, null);
        isCopied = true;
        if (copyWithMetadata) {
            String objName = sourcePath.substring(sourcePath.lastIndexOf("/") + 1, sourcePath.length());
            dstPath = String.format("%s/%s", dstPath, objName);
            metadataService.copyMetadata(sourcePath, dstPath);
        }
    } catch (JargonException e) {
        logger.error("Could not copy item from " + sourcePath + " to " + dstPath + ": ", e.getMessage());
    }
    return isCopied;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) DataTransferOperations(org.irods.jargon.core.pub.DataTransferOperations) JargonException(org.irods.jargon.core.exception.JargonException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Example 4 with IRODSFile

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

the class FileOperationServiceImpl method move.

@Override
public boolean move(String sourcePath, String targetPath) throws DataGridConnectionRefusedException {
    IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
    DataTransferOperations dataTransferOperations = irodsServices.getDataTransferOperations();
    try {
        IRODSFile source = irodsFileFactory.instanceIRODSFile(sourcePath);
        if (source.isDirectory()) {
            targetPath += "/" + FilenameUtils.getBaseName(sourcePath);
        }
        IRODSFile target = irodsFileFactory.instanceIRODSFile(targetPath);
        dataTransferOperations.move(source, target);
        return true;
    } catch (JargonException e) {
        logger.error("Could not move item from " + sourcePath + " to " + targetPath + ": ", e.getMessage());
    }
    return false;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) DataTransferOperations(org.irods.jargon.core.pub.DataTransferOperations) JargonException(org.irods.jargon.core.exception.JargonException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Example 5 with IRODSFile

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

the class TestUploadWithTicket method testUploadFileUsingATicket.

@Test
public void testUploadFileUsingATicket() throws DataGridConnectionRefusedException, DataGridTicketUploadException, DataGridTicketInvalidUserException, JargonException {
    ticketClientService.transferFileToIRODSUsingTicket(ticketString, localFile, targetPath);
    IRODSFile ticketIRODSFile = irodsServices.getIRODSFileFactory().instanceIRODSFile(filePath);
    assertTrue(ticketIRODSFile.exists());
}
Also used : IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) Test(org.junit.Test)

Aggregations

IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)28 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)23 JargonException (org.irods.jargon.core.exception.JargonException)19 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 File (java.io.File)4 IOException (java.io.IOException)4 DataTransferOperations (org.irods.jargon.core.pub.DataTransferOperations)4 InputStream (java.io.InputStream)3 Stream2StreamAO (org.irods.jargon.core.pub.Stream2StreamAO)3 DataGridChecksumException (com.emc.metalnx.core.domain.exceptions.DataGridChecksumException)2 DataGridTicketInvalidUserException (com.emc.metalnx.core.domain.exceptions.DataGridTicketInvalidUserException)2 IRODSAccount (org.irods.jargon.core.connection.IRODSAccount)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