use of org.irods.jargon.core.exception.JargonException 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.exception.JargonException 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.exception.JargonException 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.exception.JargonException 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;
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class UserServiceImpl method getGroupIdsForUser.
@Override
public String[] getGroupIdsForUser(DataGridUser user) throws DataGridConnectionRefusedException {
UserGroupAO userGroupAO = irodsServices.getGroupAO();
try {
// Getting list of groups the user belongs to.
List<UserGroup> groups = userGroupAO.findUserGroupsForUser(user.getUsername());
// Building Data Grid IDs list
String[] ids = new String[groups.size()];
for (int i = 0; i < groups.size(); i++) {
ids[i] = groups.get(i).getUserGroupId();
}
// Returning results
return ids;
} catch (JargonException e) {
logger.error("Could not find group list for user [" + user.getUsername() + "], ", e);
}
// If something goes wrong, return empty list.
return new String[0];
}
Aggregations