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;
}
Aggregations