use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class CollectionServiceImpl method modifyCollectionAndDataObject.
@Override
public boolean modifyCollectionAndDataObject(String previousPath, String newPath, boolean inheritOption) throws DataGridConnectionRefusedException {
logger.info("modifyCollectionAndDataObject()");
IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
CollectionAO collectionAO = irodsServices.getCollectionAO();
logger.debug("Modify Collection/DataObject {} to {}", previousPath, newPath);
try {
logger.debug("Locating {} in iRODS", previousPath);
IRODSFile previousFile = irodsFileFactory.instanceIRODSFile(previousPath);
logger.info("Creating new IRODSFile instance for {}", newPath);
IRODSFile newFile = irodsFileFactory.instanceIRODSFile(newPath);
boolean isDirectory = irodsFileSystemAO.isDirectory(previousFile);
if (previousPath.compareTo(newPath) != 0) {
// checking if the path given is a collection
if (isDirectory) {
logger.debug("{} is a collection", previousPath);
irodsFileSystemAO.renameDirectory(previousFile, newFile);
} else // the path given is a data object
{
logger.debug("{} is a data object", previousPath);
irodsFileSystemAO.renameFile(previousFile, newFile);
}
}
// Updating inheritance option on the collection, if needed
String zoneName = irodsFileSystemAO.getIRODSServerProperties().getRodsZone();
if (isDirectory) {
boolean isInheritanceSetForNewCollection = collectionAO.isCollectionSetForPermissionInheritance(newPath);
if (inheritOption != isInheritanceSetForNewCollection) {
// enable inheritance for this collection
if (inheritOption) {
logger.debug("Setting inheritance option on {}", newPath);
collectionAO.setAccessPermissionInherit(zoneName, newPath, false);
} else // disable inheritance for this collection
{
logger.debug("Removing inheritance setting on {}", newPath);
collectionAO.setAccessPermissionToNotInherit(zoneName, newPath, false);
}
}
}
return true;
} catch (JargonException e) {
logger.error("Could not edit Collection/DataObject {} to {}: ", previousPath, newPath, e);
}
return false;
}
use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class CollectionServiceImpl method createCollection.
@Override
public boolean createCollection(DataGridCollectionAndDataObject collection) throws DataGridException {
logger.info("createCollection()");
boolean collCreated;
try {
IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
IRODSFile newFile = irodsFileFactory.instanceIRODSFile(collection.getParentPath(), collection.getName());
irodsFileSystemAO.mkdir(newFile, false);
// Updating inheritance option on the collection, if needed
CollectionAO collectionAO = irodsServices.getCollectionAO();
String zoneName = irodsFileSystemAO.getIRODSServerProperties().getRodsZone();
// enable inheritance for this collection
if (collection.isInheritanceOption()) {
collectionAO.setAccessPermissionInherit(zoneName, collection.getPath(), false);
} else // disable inheritance for this collection
if ("own".equals(getPermissionsForPath(collection.getParentPath()))) {
collectionAO.setAccessPermissionToNotInherit(zoneName, collection.getPath(), false);
}
collCreated = true;
} catch (JargonException e) {
logger.debug("Could not create a collection in the data grid: {}", e.getMessage());
throw new DataGridException(e.getMessage());
}
return collCreated;
}
use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class FileOperationServiceImpl method deleteItem.
@Override
public boolean deleteItem(String path, boolean force) throws DataGridConnectionRefusedException {
if (path == null || path.isEmpty())
return false;
IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
boolean itemDeleted = false;
try {
IRODSFile itemToBeRemoved = irodsFileFactory.instanceIRODSFile(path);
if (irodsFileSystemAO.isDirectory(itemToBeRemoved)) {
// if force set to true, we do an irm -rf
if (force) {
logger.info("Deleting directory (force) {}", path);
irodsFileSystemAO.directoryDeleteForce(itemToBeRemoved);
} else // irm
{
logger.info("Deleting directory {}", path);
irodsFileSystemAO.directoryDeleteNoForce(itemToBeRemoved);
}
} else {
// if force set to false, we do an irm
if (force) {
logger.info("Deleting data obj (force) {}", path);
irodsFileSystemAO.fileDeleteForce(itemToBeRemoved);
} else // irm
{
logger.info("Deleting data obj {}", path);
irodsFileSystemAO.fileDeleteNoForce(itemToBeRemoved);
}
}
itemDeleted = true;
// item deleted, we need to delete any bookmarks related to it
userBookmarkService.removeBookmarkBasedOnPath(path);
userBookmarkService.removeBookmarkBasedOnRelativePath(path);
groupBookmarkService.removeBookmarkBasedOnPath(path);
groupBookmarkService.removeBookmarkBasedOnRelativePath(path);
favoritesService.removeFavoriteBasedOnPath(path);
favoritesService.removeFavoriteBasedOnRelativePath(path);
} catch (JargonException e) {
logger.error("Could not delete item " + path + ": ", e);
}
return itemDeleted;
}
use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class FileOperationServiceImpl method deleteCollection.
@Override
public boolean deleteCollection(String collectionPath, boolean forceFlag) throws DataGridException {
IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
try {
IRODSFile collectionToBeRemoved = irodsFileFactory.instanceIRODSFile(collectionPath);
if (forceFlag) {
irodsFileSystemAO.directoryDeleteForce(collectionToBeRemoved);
} else {
irodsFileSystemAO.directoryDeleteNoForce(collectionToBeRemoved);
}
return true;
} catch (JargonException e) {
logger.error("Could not delete collection: ", e.getMessage());
}
return false;
}
use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.
the class FileOperationServiceImpl method copyFileIntoHttpResponse.
/**
* Copies a buffered input stream from a file to a HTTP response for
* downloading.
*
* @param path
* path to the file in iRODS to be added to the HTTP response
* @param response
* HTTP response to let the user download the file
* @return True, if the file was successfully added to the HTTP response. False,
* otherwise.
* @throws DataGridConnectionRefusedException
* is Metalnx cannot connect to the data grid
*/
private boolean copyFileIntoHttpResponse(String path, HttpServletResponse response) throws DataGridConnectionRefusedException {
boolean isCopySuccessFul = true;
IRODSFileInputStream irodsFileInputStream = null;
IRODSFile irodsFile = null;
logger.debug("Trying to copy path stream {} to user", path);
try {
String fileName = path.substring(path.lastIndexOf("/") + 1, path.length());
logger.debug("The filename is [{}]", fileName);
logger.debug("Initiating iRodsFileFactory");
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
logger.debug("Getting iRodsFileFactory instance for {}", path);
irodsFile = irodsFileFactory.instanceIRODSFile(path);
logger.debug("Creating stream from {}", irodsFile);
irodsFileInputStream = irodsFileFactory.instanceIRODSFileInputStream(irodsFile);
// set file mime type
response.setContentType(CONTENT_TYPE);
response.setHeader("Content-Disposition", String.format(HEADER_FORMAT, fileName));
response.setContentLength((int) irodsFile.length());
FileCopyUtils.copy(irodsFileInputStream, response.getOutputStream());
} catch (IOException e) {
logger.error("Could not put the file in the Http response ", e);
isCopySuccessFul = false;
} catch (JargonException e) {
logger.error("Could not copy file in the Http response: ", e.getMessage());
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