use of org.irods.jargon.core.pub.io.IRODSFile 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.IRODSFile 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.IRODSFile 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.IRODSFile 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.IRODSFile in project metalnx-web by irods-contrib.
the class TestUploadWithTicket method testUploadFileUsingATicket.
@Test
public void testUploadFileUsingATicket() throws DataGridConnectionRefusedException, DataGridTicketUploadException, DataGridTicketInvalidUserException, JargonException {
ticketClientService.transferFileToIRODSUsingTicket(ticketString, localFile, targetPath);
IRODSFile ticketIRODSFile = irodsServices.getIRODSFileFactory().instanceIRODSFile(filePath);
assertTrue(ticketIRODSFile.exists());
}
Aggregations