Search in sources :

Example 56 with JargonException

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;
}
Also used : DataGridTicket(com.emc.metalnx.core.domain.entity.DataGridTicket) Ticket(org.irods.jargon.ticket.Ticket) JargonException(org.irods.jargon.core.exception.JargonException) ArrayList(java.util.ArrayList) DataGridTicket(com.emc.metalnx.core.domain.entity.DataGridTicket) TicketAdminService(org.irods.jargon.ticket.TicketAdminService)

Example 57 with JargonException

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;
}
Also used : CollectionAndDataObjectListAndSearchAO(org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO) DataGridUserPermission(com.emc.metalnx.core.domain.entity.DataGridUserPermission) DataGridGroupPermission(com.emc.metalnx.core.domain.entity.DataGridGroupPermission) JargonException(org.irods.jargon.core.exception.JargonException) CollectionAndDataObjectListingEntry(org.irods.jargon.core.query.CollectionAndDataObjectListingEntry) DataGridFilePermission(com.emc.metalnx.core.domain.entity.DataGridFilePermission) HashSet(java.util.HashSet)

Example 58 with JargonException

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;
}
Also used : UnsupportedDataGridFeatureException(com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException) SpecificQueryProvider(com.emc.metalnx.services.irods.utils.SpecificQueryProvider) JargonException(org.irods.jargon.core.exception.JargonException) ClientHints(org.irods.jargon.core.pub.domain.ClientHints) ArrayList(java.util.ArrayList) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) CollectionAndDataObjectListingEntry(org.irods.jargon.core.query.CollectionAndDataObjectListingEntry) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) SpecificQueryDefinition(org.irods.jargon.core.pub.domain.SpecificQueryDefinition) JargonQueryException(org.irods.jargon.core.query.JargonQueryException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) SpecificQuery(org.irods.jargon.core.query.SpecificQuery)

Example 59 with JargonException

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;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) CollectionAO(org.irods.jargon.core.pub.CollectionAO) JargonException(org.irods.jargon.core.exception.JargonException) IRODSFileSystemAO(org.irods.jargon.core.pub.IRODSFileSystemAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Example 60 with JargonException

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;
}
Also used : CollectionAndDataObjectListAndSearchAO(org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO) JargonException(org.irods.jargon.core.exception.JargonException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) CollectionAndDataObjectListingEntry(org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)

Aggregations

JargonException (org.irods.jargon.core.exception.JargonException)86 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)20 CollectionAO (org.irods.jargon.core.pub.CollectionAO)20 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)18 DataObjectAO (org.irods.jargon.core.pub.DataObjectAO)18 IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)17 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)15 ArrayList (java.util.ArrayList)12 SpecificQueryAO (org.irods.jargon.core.pub.SpecificQueryAO)12 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)11 CollectionAndDataObjectListAndSearchAO (org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO)10 SpecificQueryDefinition (org.irods.jargon.core.pub.domain.SpecificQueryDefinition)10 SpecificQueryResultSet (org.irods.jargon.core.query.SpecificQueryResultSet)9 UnsupportedDataGridFeatureException (com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException)8 SpecificQueryProvider (com.emc.metalnx.services.irods.utils.SpecificQueryProvider)8 ClientHints (org.irods.jargon.core.pub.domain.ClientHints)8 DataObject (org.irods.jargon.core.pub.domain.DataObject)8 CollectionAndDataObjectListingEntry (org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)8 SpecificQuery (org.irods.jargon.core.query.SpecificQuery)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8