Search in sources :

Example 1 with DataGridTicketDownloadException

use of com.emc.metalnx.core.domain.exceptions.DataGridTicketDownloadException 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)

Aggregations

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