Search in sources :

Example 1 with DataGridTicketUploadException

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

the class TicketClientServiceImpl method transferFileToIRODSUsingTicket.

@Override
public void transferFileToIRODSUsingTicket(String ticketString, File localFile, String destPath) throws DataGridTicketUploadException, DataGridTicketInvalidUserException {
    if (ticketString == null || ticketString.isEmpty()) {
        throw new DataGridTicketUploadException("Ticket String not provided");
    } else if (destPath == null || destPath.isEmpty()) {
        throw new DataGridTicketUploadException("Ticket path not provided");
    } else if (localFile == null) {
        throw new DataGridTicketUploadException("File not provided");
    }
    try {
        setUpAccess();
        IRODSFileFactory irodsFileFactory = irodsAccessObjectFactory.getIRODSFileFactory(irodsAccount);
        String targetPath = String.format("%s/%s", destPath, localFile.getName());
        IRODSFile targetFile = irodsFileFactory.instanceIRODSFile(targetPath);
        ticketClientOperations.putFileToIRODSUsingTicket(ticketString, localFile, targetFile, null, null);
    } catch (InvalidUserException e) {
        logger.error("Invalid user. Cannot download files as anonymous.");
        throw new DataGridTicketInvalidUserException("Invalid user anonymous");
    } catch (OverwriteException | DuplicateDataException e) {
        logger.error("Could not transfer file to the grid. File already exists: {}", e);
        throw new DataGridTicketUploadException("File already exists");
    } catch (CatNoAccessException e) {
        logger.error("Could not transfer file to the grid. Cat no access: {}", e);
        throw new DataGridTicketUploadException(e.getMessage());
    } catch (DataNotFoundException e) {
        logger.error("Could not transfer file to the grid. File not found: {}", e);
        throw new DataGridTicketUploadException("File not found");
    } catch (JargonException e) {
        logger.error("Could not transfer file to the grid using a ticket: {}", e);
        int code = e.getUnderlyingIRODSExceptionCode();
        String msg = "Transfer failed";
        if (ticketErroCodeMap.containsKey(code)) {
            msg = ticketErroCodeMap.get(code);
        }
        throw new DataGridTicketUploadException(msg);
    } finally {
        closeAccess();
        FileUtils.deleteQuietly(localFile);
    }
}
Also used : DataGridTicketUploadException(com.emc.metalnx.core.domain.exceptions.DataGridTicketUploadException) IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) DataGridTicketInvalidUserException(com.emc.metalnx.core.domain.exceptions.DataGridTicketInvalidUserException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) DataGridTicketInvalidUserException(com.emc.metalnx.core.domain.exceptions.DataGridTicketInvalidUserException)

Aggregations

DataGridTicketInvalidUserException (com.emc.metalnx.core.domain.exceptions.DataGridTicketInvalidUserException)1 DataGridTicketUploadException (com.emc.metalnx.core.domain.exceptions.DataGridTicketUploadException)1 IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)1 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)1