use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class TicketServiceImpl method findAll.
@Override
public List<DataGridTicket> findAll() throws DataGridConnectionRefusedException {
logger.info("Find all tickets");
TicketAdminService tas = irodsServices.getTicketAdminService();
List<DataGridTicket> dgTickets;
List<Ticket> tickets;
try {
tickets = tas.listAllTickets(OFFSET);
} catch (JargonException e) {
logger.info("Could not list all tickets in the grid: {}.", e.getMessage());
tickets = new ArrayList<>();
}
dgTickets = convertListOfTickets(tickets);
return dgTickets;
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class CollectionServiceImpl method listCollectionsWithPermissionsForEntity.
/**
* Auxiliary method that filters the directories with the specified permission
* level for the given entity, that can be an user or a group
*
* @param path
* The path for which we would like to list the objects with
* permissions
* @param entityName
* The entity name
* @param permissionType
* The permission stype
* @param entityType
* The entity type that can be user or group
* @return
* @throws DataGridConnectionRefusedException
*/
private Set<String> listCollectionsWithPermissionsForEntity(String path, String entityName, FilePermissionEnum permissionType, String entityType) throws DataGridConnectionRefusedException {
logger.info("listCollectionsWithPermissionsForEntity()");
Set<String> collections = new HashSet<String>();
CollectionAndDataObjectListAndSearchAO collectionAndDataObjectListAndSearchAO = irodsServices.getCollectionAndDataObjectListAndSearchAO();
try {
List<CollectionAndDataObjectListingEntry> collList = collectionAndDataObjectListAndSearchAO.listDataObjectsAndCollectionsUnderPath(path);
logger.info("Getting permissions and bookmarks for path {}", path);
for (CollectionAndDataObjectListingEntry collEntry : collList) {
String filePath = "";
if (collEntry.isCollection()) {
filePath = collEntry.getPathOrName();
} else {
filePath = collEntry.getParentPath() + IRODS_PATH_SEPARATOR + collEntry.getPathOrName();
if (collEntry.getParentPath().compareTo(IRODS_PATH_SEPARATOR) == 0) {
filePath = collEntry.getParentPath() + collEntry.getPathOrName();
}
}
List<DataGridFilePermission> permissions = permissionsService.getPathPermissionDetails(filePath, entityName);
// Deciding whether we should get permissions for users or groups
if (entityType.compareTo("user") == 0) {
// Filtering permissions for users
List<DataGridUserPermission> userPermissions = permissionsService.getUsersWithPermissions(permissions);
// Adding collections with permissions into the result list
for (DataGridUserPermission dataGridUserPermission : userPermissions) {
if (dataGridUserPermission.getPermission().equalsIgnoreCase(permissionType.name())) {
collections.add(filePath);
}
}
} else {
// Filtering permissions for groups
List<DataGridGroupPermission> groupPermissions = permissionsService.getGroupsWithPermissions(permissions);
// Adding collections with permissions into the result list
for (DataGridGroupPermission dataGridGroupPermission : groupPermissions) {
if (dataGridGroupPermission.getPermission().equalsIgnoreCase(permissionType.name())) {
collections.add(filePath);
}
}
}
}
} catch (JargonException e) {
logger.error("Could not get permissions: ", e);
}
return collections;
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class CollectionServiceImpl method listCollectionsUnderPathThatMatchSearchText.
/**
* Lists all collections under the given path that match a search term. Any
* collection where the term appears in the beginning, middle, and the end of
* its name will be retrieved.
*
* @param parentPath
* path to the parent collection where you are looking for items that
* match a search term
* @param searchText
* term to be matched
* @param offset
* partial start index
* @param limit
* max number of items retrieved
* @return list of data objects that match the given search text
* @throws DataGridConnectionRefusedException
*/
private List<DataGridCollectionAndDataObject> listCollectionsUnderPathThatMatchSearchText(String parentPath, String searchText, int offset, int limit, int orderColumn, String orderDir) throws DataGridConnectionRefusedException {
logger.info("listCollectionsUnderPathThatMatchSearchText()");
logger.info("parentPath:{}", parentPath);
logger.info("searchText:{}", searchText);
logger.info("offset:{}", offset);
logger.info("limit:{}", limit);
logger.info("orderColumn:{}", orderColumn);
logger.info("orderDir:{}", orderDir);
SpecificQueryAO specificQueryAO = adminServices.getSpecificQueryAO();
SpecificQueryDefinition queryDef = null;
List<CollectionAndDataObjectListingEntry> itemsListingEntries = null;
List<DataGridCollectionAndDataObject> dataGridItemsList = null;
String sqlQueryAlias = "";
try {
sqlQueryAlias = SQL_LIST_COLLS_MATCHING_SEARCH_TEXT_ALIAS_WITH_ORDERING;
ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
String query = provider.buildSelectCollectionsUnderPathThatMatchSearchText(parentPath, searchText, offset, limit, orderColumn, orderDir);
// Creating Specific Query instance
queryDef = new SpecificQueryDefinition();
queryDef.setAlias(sqlQueryAlias);
queryDef.setSql(query);
// Creating spec query on iRODS
specificQueryAO.addSpecificQuery(queryDef);
// Executing specific query
String zone = irodsServices.getCurrentUserZone();
List<String> args = new ArrayList<String>();
String collNameParam = null;
if (IRODS_PATH_SEPARATOR.equals(parentPath)) {
collNameParam = String.format("%%%s%%%%%s%%", IRODS_PATH_SEPARATOR, searchText);
} else {
collNameParam = String.format("%s%s%%%s%%", parentPath, IRODS_PATH_SEPARATOR, searchText);
}
args.add(collNameParam);
args.add(parentPath);
args.add(String.valueOf(offset));
args.add(String.valueOf(limit));
SpecificQuery specQuery = SpecificQuery.instanceArguments(sqlQueryAlias, args, 0, zone);
logger.debug("specificQuery for text search:{}", specQuery);
SpecificQueryResultSet queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, MAX_RESULTS_PER_PAGE, 0);
// Mapping spec query results to DataGrid* objects
itemsListingEntries = DataGridUtils.mapCollectionQueryResultSetToDataGridObjects(queryResultSet);
dataGridItemsList = DataGridUtils.mapListingEntryToDataGridCollectionAndDataObject(itemsListingEntries);
} catch (JargonException | JargonQueryException | UnsupportedDataGridFeatureException e) {
logger.error("Could not execute specific query to find collections matching a search text. ", e);
} finally {
try {
// after running the user specific query, we need to remove from the database
specificQueryAO.removeSpecificQueryByAlias(sqlQueryAlias);
} catch (JargonException e) {
logger.error("Could not remove specific query {}: ", sqlQueryAlias, e.getMessage());
}
}
return dataGridItemsList;
}
use of org.irods.jargon.core.exception.JargonException 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.exception.JargonException in project metalnx-web by irods-contrib.
the class CollectionServiceImpl method getSubCollectionsUnderPath.
@Override
public List<DataGridCollectionAndDataObject> getSubCollectionsUnderPath(String parent) throws DataGridConnectionRefusedException {
logger.info("getSubCollectionsUnderPath()");
CollectionAndDataObjectListAndSearchAO collectionAndDataObjectListAndSearchAO = irodsServices.getCollectionAndDataObjectListAndSearchAO();
List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = null;
try {
List<CollectionAndDataObjectListingEntry> collectionAndDataObjects = collectionAndDataObjectListAndSearchAO.listCollectionsUnderPath(parent, 0);
dataGridCollectionAndDataObjects = this.mapListingEntryToDataGridCollectionAndDataObject(collectionAndDataObjects);
return dataGridCollectionAndDataObjects;
} catch (FileNotFoundException e) {
logger.error("Could not locate file: ", e);
} catch (JargonException e) {
logger.error("Error: ", e);
}
return dataGridCollectionAndDataObjects;
}
Aggregations