use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class UserServiceImpl method removeAccessPermissionForUserAsAdmin.
@Override
public void removeAccessPermissionForUserAsAdmin(DataGridUser user, Map<String, Boolean> paths) throws JargonException, DataGridConnectionRefusedException {
if (paths == null || paths.isEmpty()) {
return;
}
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
CollectionAO collectionAO = irodsServices.getCollectionAO();
DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
IRODSFile irodsFile = null;
for (String path : paths.keySet()) {
irodsFile = irodsFileFactory.instanceIRODSFile(path);
if (irodsFile.isDirectory()) {
collectionAO.removeAccessPermissionForUserAsAdmin(user.getAdditionalInfo(), path, user.getUsername(), paths.get(path));
} else {
dataObjectAO.removeAccessPermissionsForUserInAdminMode(user.getAdditionalInfo(), path, user.getUsername());
}
}
}
use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class TestRuleDeploymentService method createRuleCacheColl.
/**
* Create the rule cache collection in the grid
* @throws DataGridConnectionRefusedException
* @throws JargonException
*/
private void createRuleCacheColl() throws DataGridConnectionRefusedException, JargonException {
IRODSFileFactory iff = irodsServices.getIRODSFileFactory();
IRODSFile ruleCacheColl = iff.instanceIRODSFile("/" + configService.getIrodsZone(), RULE_CACHE_DIR);
irodsServices.getIRODSFileSystemAO().mkdir(ruleCacheColl, false);
}
use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class UploadServiceImpl method upload.
@Override
public boolean upload(MultipartFile file, String targetPath, boolean computeCheckSum, boolean replicateFile, String replicationResc, String destResc, boolean overwrite) throws DataGridException {
logger.info("upload()");
if (file == null || file.isEmpty() || "".equals(targetPath) || targetPath == null || "".equals(destResc) || destResc == null) {
logger.error("File could not be sent to the data grid.");
return false;
}
logger.info("file:{}", file);
logger.info("targetPath:{}", targetPath);
logger.info("computeCheckSum:{}", computeCheckSum);
logger.info("replicateFile:{}", replicateFile);
logger.info("replicationResc:{}", replicationResc);
logger.info("destResc:{}", destResc);
logger.info("overwrite:{}", overwrite);
InputStream inputStream;
try {
inputStream = file.getInputStream();
} catch (IOException e) {
logger.error("Could not get input stream from file: ", e.getMessage());
throw new DataGridException("Could not get input stream from file.");
}
String defaultStorageResource = is.getDefaultStorageResource();
logger.info("Setting default resource to {}", destResc);
// Setting temporarily the defaultStorageResource for the logged user
is.setDefaultStorageResource(destResc);
boolean isFileUploaded;
// Getting DataObjectAO in order to create the new file
IRODSFileFactory irodsFileFactory = is.getIRODSFileFactory();
Stream2StreamAO stream2StreamA0 = is.getStream2StreamAO();
IRODSFile targetFile = null;
try {
String fileName = file.getOriginalFilename();
if (fileName.isEmpty())
fileName = file.getName();
targetFile = irodsFileFactory.instanceIRODSFile(targetPath, fileName);
logger.info("targetFile:{}", targetFile);
// aborted.
if (targetFile.exists() && !overwrite) {
String msg = "File already exists. Not overwriting it.";
logger.info(msg);
throw new DataGridFileAlreadyExistsException(msg);
}
// Transfering file to iRODS filesystem
stream2StreamA0.transferStreamToFileUsingIOStreams(inputStream, (File) targetFile, 0, BUFFER_SIZE);
logger.info("transfer complete, compute checksum if required");
// Computing a check sum for this file just uploaded to iRODS
if (computeCheckSum)
fos.computeChecksum(targetPath, fileName);
// Replicating file into desired resource
if (replicateFile)
fos.replicateDataObject(targetFile.getPath(), replicationResc, false);
if (configService.isUploadRulesEnabled()) {
logger.info("applying upload rules");
processUploadRules(targetPath, destResc, targetFile);
}
isFileUploaded = true;
} catch (JargonException e) {
fos.deleteDataObject(targetFile.getPath(), true);
logger.error("Upload stream failed from Metalnx to the data grid. {}", e.getMessage());
throw new DataGridException("Upload failed. Resource(s) might be full.");
} catch (DataGridFileAlreadyExistsException e) {
logger.warn("File already exists..will rethrow.");
throw e;
} catch (Throwable e) {
logger.error("Exception in upload processing", e);
throw new DataGridException("Could not upload due to system exception");
} finally {
try {
// Closing streams opened
inputStream.close();
} catch (IOException e) {
logger.error("Could close stream: ", e.getMessage());
}
}
// Setting the default resource back to the original one.
is.setDefaultStorageResource(defaultStorageResource);
return isFileUploaded;
}
use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class PermissionsServiceImpl method canLoggedUserModifyPermissionOnPath.
@Override
public boolean canLoggedUserModifyPermissionOnPath(String path) throws DataGridConnectionRefusedException {
String userName = irodsServices.getCurrentUser();
final IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
final IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
try {
int resultingPermission;
final IRODSFile fileObj = irodsFileFactory.instanceIRODSFile(path);
if (irodsFileSystemAO.isDirectory(fileObj)) {
resultingPermission = irodsFileSystemAO.getDirectoryPermissionsForGivenUser(fileObj, userName);
} else {
resultingPermission = irodsFileSystemAO.getFilePermissionsForGivenUser(fileObj, userName);
}
return resultingPermission > FilePermissionEnum.WRITE.getPermissionNumericValue();
} catch (final Exception e) {
logger.error("Could not get permissions for current user: {}", e.getMessage());
}
return false;
}
use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class PreviewServiceImpl method filePreview.
@Override
public boolean filePreview(String path, String mimeType, HttpServletResponse response) {
logger.info("getting file preview for {} ::" + path + " and mimetype :: " + mimeType);
boolean isCopySuccessFul = true;
IRODSFileInputStream irodsFileInputStream = null;
IRODSFile irodsFile = null;
try {
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
irodsFile = irodsFileFactory.instanceIRODSFile(path);
irodsFileInputStream = irodsFileFactory.instanceIRODSFileInputStream(irodsFile);
response.setContentType(mimeType);
FileCopyUtils.copy(irodsFileInputStream, response.getOutputStream());
} catch (IOException | JargonException | DataGridConnectionRefusedException e) {
e.printStackTrace();
isCopySuccessFul = false;
} finally {
try {
if (irodsFileInputStream != null)
irodsFileInputStream.close();
if (irodsFile != null)
irodsFile.close();
} catch (Exception e) {
logger.error("Could not close stream(s): ", e.getMessage());
}
}
return isCopySuccessFul;
}
Aggregations