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