Search in sources :

Example 21 with IRODSFileFactory

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

the class TicketClientServiceImpl method getFileFromIRODSUsingTicket.

@Override
public File getFileFromIRODSUsingTicket(String ticketString, String path) throws DataGridTicketInvalidUserException, DataGridTicketDownloadException {
    deleteTempTicketDir();
    File tempDir = new File(TEMP_TICKET_DIR);
    if (!tempDir.exists()) {
        tempDir.mkdir();
    }
    File file;
    try {
        setUpAccess();
        IRODSFileFactory irodsFileFactory = irodsAccessObjectFactory.getIRODSFileFactory(irodsAccount);
        IRODSFile irodsFile = irodsFileFactory.instanceIRODSFile(path);
        ticketClientOperations.getOperationFromIRODSUsingTicket(ticketString, irodsFile, tempDir, null, null);
        String filename = path.substring(path.lastIndexOf("/") + 1, path.length());
        File obj = findFileInDirectory(tempDir, filename);
        if (obj == null) {
            throw new DataGridTicketDownloadException("File not found", path, ticketString);
        }
        file = obj;
        if (obj.isDirectory()) {
            file = zipService.createZip(tempDir, obj);
        }
    } catch (InvalidUserException e) {
        logger.error("Invalid user. Cannot download files as anonymous.");
        throw new DataGridTicketInvalidUserException("Invalid user anonymous");
    } catch (FileNotFoundException e) {
        logger.error("Could not get file using ticket. File not found: {}", e);
        throw new DataGridTicketDownloadException("File not found", path, ticketString);
    } catch (JargonException e) {
        logger.error("Get file using a ticket caused an error: {}", e);
        int code = e.getUnderlyingIRODSExceptionCode();
        String msg = "Download failed";
        if (ticketErroCodeMap.containsKey(code)) {
            msg = ticketErroCodeMap.get(code);
        }
        throw new DataGridTicketDownloadException(msg, path, ticketString);
    } finally {
        closeAccess();
    }
    return file;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) DataGridTicketInvalidUserException(com.emc.metalnx.core.domain.exceptions.DataGridTicketInvalidUserException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) File(java.io.File) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) DataGridTicketDownloadException(com.emc.metalnx.core.domain.exceptions.DataGridTicketDownloadException) DataGridTicketInvalidUserException(com.emc.metalnx.core.domain.exceptions.DataGridTicketInvalidUserException)

Example 22 with IRODSFileFactory

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

the class UserServiceImpl method updateWritePermissions.

@Override
public boolean updateWritePermissions(DataGridUser user, Map<String, Boolean> addCollectionsToWrite, Map<String, Boolean> removeCollectionsToWrite) throws DataGridConnectionRefusedException {
    CollectionAO collectionAO = null;
    DataObjectAO dataObjectAO = null;
    IRODSFile irodsFile = null;
    IRODSFileFactory irodsFileFactory = null;
    boolean writePermissionsUpdated = false;
    try {
        collectionAO = irodsServices.getCollectionAO();
        dataObjectAO = irodsServices.getDataObjectAO();
        irodsFileFactory = irodsServices.getIRODSFileFactory();
        for (String path : addCollectionsToWrite.keySet()) {
            irodsFile = irodsFileFactory.instanceIRODSFile(path);
            if (irodsFile.isDirectory()) {
                collectionAO.setAccessPermissionWriteAsAdmin(user.getAdditionalInfo(), path, user.getUsername(), addCollectionsToWrite.get(path));
            } else {
                dataObjectAO.setAccessPermissionWriteInAdminMode(user.getAdditionalInfo(), path, user.getUsername());
            }
        }
        removeAccessPermissionForUserAsAdmin(user, removeCollectionsToWrite);
        writePermissionsUpdated = true;
    } catch (JargonException e) {
        logger.error("Could not set write permission:", e);
    }
    return writePermissionsUpdated;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) CollectionAO(org.irods.jargon.core.pub.CollectionAO) JargonException(org.irods.jargon.core.exception.JargonException) DataObjectAO(org.irods.jargon.core.pub.DataObjectAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Example 23 with IRODSFileFactory

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

the class UserServiceImpl method updateOwnership.

@Override
public boolean updateOwnership(DataGridUser user, Map<String, Boolean> addCollectionsToOwn, Map<String, Boolean> removeCollectionsToOwn) throws DataGridConnectionRefusedException {
    CollectionAO collectionAO = null;
    DataObjectAO dataObjectAO = null;
    IRODSFile irodsFile = null;
    IRODSFileFactory irodsFileFactory = null;
    boolean ownPermissionsUpdated = false;
    try {
        collectionAO = irodsServices.getCollectionAO();
        dataObjectAO = irodsServices.getDataObjectAO();
        irodsFileFactory = irodsServices.getIRODSFileFactory();
        for (String path : addCollectionsToOwn.keySet()) {
            irodsFile = irodsFileFactory.instanceIRODSFile(path);
            if (irodsFile.isDirectory()) {
                collectionAO.setAccessPermissionOwnAsAdmin(user.getAdditionalInfo(), path, user.getUsername(), addCollectionsToOwn.get(path));
            } else {
                dataObjectAO.setAccessPermissionOwnInAdminMode(user.getAdditionalInfo(), path, user.getUsername());
            }
        }
        removeAccessPermissionForUserAsAdmin(user, removeCollectionsToOwn);
        ownPermissionsUpdated = true;
    } catch (JargonException e) {
        logger.error("Could not set ownership permission:", e);
    }
    return ownPermissionsUpdated;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) CollectionAO(org.irods.jargon.core.pub.CollectionAO) JargonException(org.irods.jargon.core.exception.JargonException) DataObjectAO(org.irods.jargon.core.pub.DataObjectAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

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