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