use of org.irods.jargon.core.pub.io.IRODSFileFactory 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;
}
use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class UserServiceImpl method updateWritePermissions.
@Override
public boolean updateWritePermissions(DataGridUser user, Map<String, Boolean> addCollectionsToWrite, Map<String, Boolean> removeCollectionsToWrite) throws DataGridConnectionRefusedException {
CollectionAO collectionAO = null;
DataObjectAO dataObjectAO = null;
IRODSFile irodsFile = null;
IRODSFileFactory irodsFileFactory = null;
boolean writePermissionsUpdated = false;
try {
collectionAO = irodsServices.getCollectionAO();
dataObjectAO = irodsServices.getDataObjectAO();
irodsFileFactory = irodsServices.getIRODSFileFactory();
for (String path : addCollectionsToWrite.keySet()) {
irodsFile = irodsFileFactory.instanceIRODSFile(path);
if (irodsFile.isDirectory()) {
collectionAO.setAccessPermissionWriteAsAdmin(user.getAdditionalInfo(), path, user.getUsername(), addCollectionsToWrite.get(path));
} else {
dataObjectAO.setAccessPermissionWriteInAdminMode(user.getAdditionalInfo(), path, user.getUsername());
}
}
removeAccessPermissionForUserAsAdmin(user, removeCollectionsToWrite);
writePermissionsUpdated = true;
} catch (JargonException e) {
logger.error("Could not set write permission:", e);
}
return writePermissionsUpdated;
}
use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class UserServiceImpl method updateOwnership.
@Override
public boolean updateOwnership(DataGridUser user, Map<String, Boolean> addCollectionsToOwn, Map<String, Boolean> removeCollectionsToOwn) throws DataGridConnectionRefusedException {
CollectionAO collectionAO = null;
DataObjectAO dataObjectAO = null;
IRODSFile irodsFile = null;
IRODSFileFactory irodsFileFactory = null;
boolean ownPermissionsUpdated = false;
try {
collectionAO = irodsServices.getCollectionAO();
dataObjectAO = irodsServices.getDataObjectAO();
irodsFileFactory = irodsServices.getIRODSFileFactory();
for (String path : addCollectionsToOwn.keySet()) {
irodsFile = irodsFileFactory.instanceIRODSFile(path);
if (irodsFile.isDirectory()) {
collectionAO.setAccessPermissionOwnAsAdmin(user.getAdditionalInfo(), path, user.getUsername(), addCollectionsToOwn.get(path));
} else {
dataObjectAO.setAccessPermissionOwnInAdminMode(user.getAdditionalInfo(), path, user.getUsername());
}
}
removeAccessPermissionForUserAsAdmin(user, removeCollectionsToOwn);
ownPermissionsUpdated = true;
} catch (JargonException e) {
logger.error("Could not set ownership permission:", e);
}
return ownPermissionsUpdated;
}
Aggregations