use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class MetadataServiceImpl method populateVisibilityForCurrentUser.
/**
* Sets whether or not a user can check an object resulting from a metadata
* search
*
* @param objectList
* list of data objects/collections
* @throws DataGridConnectionRefusedException
*/
@Override
public void populateVisibilityForCurrentUser(List<DataGridCollectionAndDataObject> objectList) throws DataGridConnectionRefusedException {
if (objectList == null || objectList.isEmpty()) {
return;
}
final String currentUser = irodsServices.getCurrentUser();
final IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
final IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
for (final DataGridCollectionAndDataObject obj : objectList) {
try {
int resultingPermission;
final IRODSFile fileObj = irodsFileFactory.instanceIRODSFile(obj.getPath());
if (obj.isCollection()) {
resultingPermission = irodsFileSystemAO.getDirectoryPermissionsForGivenUser(fileObj, currentUser);
} else {
resultingPermission = irodsFileSystemAO.getFilePermissionsForGivenUser(fileObj, currentUser);
}
// By default, the visibility of a user over an object is set to false
obj.setVisibleToCurrentUser(resultingPermission != FilePermissionEnum.NONE.getPermissionNumericValue());
} catch (final Exception e) {
logger.error("Could not get permissions for current user: {}", e.getMessage());
}
}
}
use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class FileOperationServiceImpl method computeChecksum.
@Override
public void computeChecksum(String path, String filename) throws DataGridChecksumException, DataGridConnectionRefusedException {
if (path == null || path.isEmpty() || filename == null || filename.isEmpty())
throw new DataGridChecksumException("Could not calculate checksum. File path is invalid.");
logger.info("Computing checksum for {} ({})", filename, path);
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
IRODSFile file;
try {
file = irodsFileFactory.instanceIRODSFile(path, filename);
dataObjectAO.computeMD5ChecksumOnDataObject(file);
} catch (JargonException e) {
logger.error("Could not calculate checksum: {}", e.getMessage());
throw new DataGridChecksumException("Could not calculate checksum.");
}
}
use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class FileOperationServiceImpl method copy.
@Override
public boolean copy(String sourcePath, String dstPath, boolean copyWithMetadata) throws DataGridConnectionRefusedException {
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
DataTransferOperations dataTransferOperations = irodsServices.getDataTransferOperations();
boolean isCopied = false;
try {
IRODSFile source = irodsFileFactory.instanceIRODSFile(sourcePath);
IRODSFile target = irodsFileFactory.instanceIRODSFile(dstPath);
dataTransferOperations.copy(source, target, null, null);
isCopied = true;
if (copyWithMetadata) {
String objName = sourcePath.substring(sourcePath.lastIndexOf("/") + 1, sourcePath.length());
dstPath = String.format("%s/%s", dstPath, objName);
metadataService.copyMetadata(sourcePath, dstPath);
}
} catch (JargonException e) {
logger.error("Could not copy item from " + sourcePath + " to " + dstPath + ": ", e.getMessage());
}
return isCopied;
}
use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class FileOperationServiceImpl method move.
@Override
public boolean move(String sourcePath, String targetPath) throws DataGridConnectionRefusedException {
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
DataTransferOperations dataTransferOperations = irodsServices.getDataTransferOperations();
try {
IRODSFile source = irodsFileFactory.instanceIRODSFile(sourcePath);
if (source.isDirectory()) {
targetPath += "/" + FilenameUtils.getBaseName(sourcePath);
}
IRODSFile target = irodsFileFactory.instanceIRODSFile(targetPath);
dataTransferOperations.move(source, target);
return true;
} catch (JargonException e) {
logger.error("Could not move item from " + sourcePath + " to " + targetPath + ": ", e.getMessage());
}
return false;
}
use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class UserServiceImpl method updateReadPermissions.
@Override
public boolean updateReadPermissions(DataGridUser user, Map<String, Boolean> addCollectionsToRead, Map<String, Boolean> removeCollectionsToRead) throws DataGridConnectionRefusedException {
CollectionAO collectionAO = null;
DataObjectAO dataObjectAO = null;
IRODSFile irodsFile = null;
IRODSFileFactory irodsFileFactory = null;
boolean readPermissionsUpdated = false;
try {
collectionAO = irodsServices.getCollectionAO();
dataObjectAO = irodsServices.getDataObjectAO();
irodsFileFactory = irodsServices.getIRODSFileFactory();
for (String path : addCollectionsToRead.keySet()) {
irodsFile = irodsFileFactory.instanceIRODSFile(path);
if (irodsFile.isDirectory()) {
// applying read permissions on a collection (not recursively)
collectionAO.setAccessPermissionReadAsAdmin(user.getAdditionalInfo(), path, user.getUsername(), addCollectionsToRead.get(path));
} else {
// applying read permissions on a data object
dataObjectAO.setAccessPermissionReadInAdminMode(user.getAdditionalInfo(), path, user.getUsername());
}
}
removeAccessPermissionForUserAsAdmin(user, removeCollectionsToRead);
readPermissionsUpdated = true;
} catch (JargonException e) {
logger.error("Could not set read permission:", e);
}
return readPermissionsUpdated;
}
Aggregations