use of org.irods.jargon.core.exception.JargonException 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.exception.JargonException in project metalnx-web by irods-contrib.
the class CollectionServiceImpl method updateInheritanceOptions.
@Override
public boolean updateInheritanceOptions(Map<String, Boolean> toAdd, Map<String, Boolean> toRemove, String zoneName) throws DataGridConnectionRefusedException {
logger.info("updateInheritanceOptions()");
CollectionAO collectionAO = irodsServices.getCollectionAO();
try {
for (String addColl : toAdd.keySet()) {
collectionAO.setAccessPermissionInheritAsAdmin(zoneName, addColl, toAdd.get(addColl));
}
for (String removeColl : toRemove.keySet()) {
collectionAO.setAccessPermissionToNotInheritInAdminMode(zoneName, removeColl, toRemove.get(removeColl));
}
return true;
} catch (JargonException e) {
logger.error("Could not set inheritance: ", e);
}
return false;
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class CollectionServiceImpl method getTotalDataObjectsUnderPathThatMatchSearchText.
/**
* Calculates the number of data objects that match the given search term.
*
* @param parentPath
* path to the parent collection where you are looking for items that
* match a search term
* @param searchText
* term to be matched
* @return total number of collections matching the given search text
* @throws DataGridConnectionRefusedException
*/
private int getTotalDataObjectsUnderPathThatMatchSearchText(String parentPath, String searchText) throws DataNotFoundException, JargonQueryException, DataGridConnectionRefusedException {
logger.info("getTotalCollectionsUnderPathThatMatchSearchText()");
logger.info("parentPath:{}", parentPath);
logger.info("searchText:{}", searchText);
SpecificQueryAO specificQueryAO = adminServices.getSpecificQueryAO();
SpecificQueryDefinition queryDef = null;
String sqlAlias = null;
int totalNumberOfItems = 0;
try {
sqlAlias = SQL_TOTAL_NUMBER_OF_DATA_OBJECTS_MATCHING_SEARCH_TEXT_ALIAS;
ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
String query = provider.buildSelectTotalDataObjectsUnderPathThatMatchSearchText(parentPath, searchText);
// Creating Specific Query instance
queryDef = new SpecificQueryDefinition();
queryDef.setAlias(sqlAlias);
queryDef.setSql(query.toString());
// Creating spec query on iRODS
specificQueryAO.addSpecificQuery(queryDef);
// Executing specific query
String zone = irodsServices.getCurrentUserZone();
List<String> args = new ArrayList<String>();
args.add(parentPath);
args.add("%" + searchText + "%");
SpecificQuery specQuery = SpecificQuery.instanceArguments(sqlAlias, args, 0, zone);
SpecificQueryResultSet queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, MAX_RESULTS_PER_PAGE, 0);
// Mapping spec query results to DataGrid* objects
totalNumberOfItems = DataGridUtils.mapCountQueryResultSetToInteger(queryResultSet);
} catch (JargonException | UnsupportedDataGridFeatureException e) {
logger.error("Could not execute specific query to get the total number of data objects matching a search text.", e);
} finally {
try {
// after running the user specific query, we need to remove from the database
specificQueryAO.removeSpecificQueryByAlias(sqlAlias);
} catch (JargonException e) {
logger.error("Could not remove specific query {}: ", sqlAlias, e.getMessage());
}
}
return totalNumberOfItems;
}
use of org.irods.jargon.core.exception.JargonException 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.exception.JargonException 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;
}
Aggregations