Search in sources :

Example 1 with CollectionAndDataObjectListingEntry

use of org.irods.jargon.core.query.CollectionAndDataObjectListingEntry in project metalnx-web by irods-contrib.

the class CollectionServiceImpl method listInheritanceForPath.

@Override
public Set<String> listInheritanceForPath(String path) throws DataGridConnectionRefusedException {
    logger.info("listInheritanceForPath()");
    Set<String> collections = new HashSet<String>();
    CollectionAO collectionAO = irodsServices.getCollectionAO();
    CollectionAndDataObjectListAndSearchAO collectionAndDataObjectListAndSearchAO = irodsServices.getCollectionAndDataObjectListAndSearchAO();
    try {
        List<CollectionAndDataObjectListingEntry> collList = collectionAndDataObjectListAndSearchAO.listCollectionsUnderPathWithPermissions(path, 0);
        for (CollectionAndDataObjectListingEntry collEntry : collList) {
            String currentCollPath = collEntry.getPathOrName();
            if (collectionAO.isCollectionSetForPermissionInheritance(currentCollPath)) {
                collections.add(currentCollPath);
            }
        }
        return collections;
    } catch (JargonException e) {
        logger.error("Could not get collections with inheritance option enabled: ", e);
    }
    return null;
}
Also used : CollectionAndDataObjectListAndSearchAO(org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO) CollectionAO(org.irods.jargon.core.pub.CollectionAO) JargonException(org.irods.jargon.core.exception.JargonException) CollectionAndDataObjectListingEntry(org.irods.jargon.core.query.CollectionAndDataObjectListingEntry) HashSet(java.util.HashSet)

Example 2 with CollectionAndDataObjectListingEntry

use of org.irods.jargon.core.query.CollectionAndDataObjectListingEntry in project metalnx-web by irods-contrib.

the class CollectionServiceImpl method listDataObjectsUnderPathThatMatchSearchText.

/**
 * Lists all data objects under the given path that match a search term. Any
 * data object 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> listDataObjectsUnderPathThatMatchSearchText(String parentPath, String searchText, int offset, int limit, int orderColumn, String orderDir) throws DataNotFoundException, JargonQueryException, DataGridConnectionRefusedException {
    logger.info("listDataObjectsUnderPathThatMatchSearchText()");
    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> dataGridList = null;
    List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = null;
    String sqlAlias = null;
    try {
        dataGridCollectionAndDataObjects = new ArrayList<DataGridCollectionAndDataObject>();
        sqlAlias = SQL_LIST_DATA_OBJECTS_MATCHING_SEARCH_TEXT_ALIAS_WITH_ORDERING;
        ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
        SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
        String query = provider.buildSelectDataObjectsUnderPathThatMatchSearchText(parentPath, searchText, offset, limit, orderColumn, orderDir);
        // 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 + "%");
        args.add(String.valueOf(offset));
        args.add(String.valueOf(limit));
        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
        dataGridList = DataGridUtils.mapQueryResultSetToDataGridObjectsForSearch(queryResultSet);
        dataGridCollectionAndDataObjects.addAll(DataGridUtils.mapListingEntryToDataGridCollectionAndDataObject(dataGridList));
    } catch (JargonException | UnsupportedDataGridFeatureException e) {
        logger.error("Could not execute specific query for listing data objects that match 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 dataGridCollectionAndDataObjects;
}
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) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) SpecificQuery(org.irods.jargon.core.query.SpecificQuery)

Example 3 with CollectionAndDataObjectListingEntry

use of org.irods.jargon.core.query.CollectionAndDataObjectListingEntry in project metalnx-web by irods-contrib.

the class DataGridUtils method mapQueryResultSetToDataGridObjectsForSearch.

/**
 * Maps the results from the specific query for listing files in a collection into DataGrid
 * objects
 *
 * @param queryResultSet
 * @return
 * @throws JargonException
 */
public static List<CollectionAndDataObjectListingEntry> mapQueryResultSetToDataGridObjectsForSearch(SpecificQueryResultSet queryResultSet) throws JargonException {
    List<CollectionAndDataObjectListingEntry> dataGridCollectionAndDataObjects = new ArrayList<CollectionAndDataObjectListingEntry>();
    List<IRODSQueryResultRow> results = queryResultSet.getResults();
    for (IRODSQueryResultRow irodsQueryResultRow : results) {
        CollectionAndDataObjectListingEntry collectionAndDataObject = new CollectionAndDataObjectListingEntry();
        collectionAndDataObject.setId(Integer.valueOf(irodsQueryResultRow.getColumn("data_id")));
        collectionAndDataObject.setPathOrName(irodsQueryResultRow.getColumn("data_name"));
        collectionAndDataObject.setParentPath(irodsQueryResultRow.getColumn("coll_name"));
        collectionAndDataObject.setObjectType(ObjectType.DATA_OBJECT);
        collectionAndDataObject.setDataSize(Long.valueOf(irodsQueryResultRow.getColumn("data_size")));
        collectionAndDataObject.setOwnerName(irodsQueryResultRow.getColumn("data_owner_name"));
        collectionAndDataObject.setOwnerZone(irodsQueryResultRow.getColumn("data_owner_zone"));
        collectionAndDataObject.setModifiedAt(IRODSDataConversionUtil.getDateFromIRODSValue(irodsQueryResultRow.getColumn("create_ts")));
        collectionAndDataObject.setModifiedAt(IRODSDataConversionUtil.getDateFromIRODSValue(irodsQueryResultRow.getColumn("modify_ts")));
        dataGridCollectionAndDataObjects.add(collectionAndDataObject);
    }
    return dataGridCollectionAndDataObjects;
}
Also used : IRODSQueryResultRow(org.irods.jargon.core.query.IRODSQueryResultRow) CollectionAndDataObjectListingEntry(org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)

Example 4 with CollectionAndDataObjectListingEntry

use of org.irods.jargon.core.query.CollectionAndDataObjectListingEntry 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 5 with CollectionAndDataObjectListingEntry

use of org.irods.jargon.core.query.CollectionAndDataObjectListingEntry 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)

Aggregations

CollectionAndDataObjectListingEntry (org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)13 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)8 JargonException (org.irods.jargon.core.exception.JargonException)8 CollectionAndDataObjectListAndSearchAO (org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO)6 ArrayList (java.util.ArrayList)3 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)3 IRODSQueryResultRow (org.irods.jargon.core.query.IRODSQueryResultRow)3 UnsupportedDataGridFeatureException (com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException)2 SpecificQueryProvider (com.emc.metalnx.services.irods.utils.SpecificQueryProvider)2 HashSet (java.util.HashSet)2 SpecificQueryAO (org.irods.jargon.core.pub.SpecificQueryAO)2 ClientHints (org.irods.jargon.core.pub.domain.ClientHints)2 SpecificQueryDefinition (org.irods.jargon.core.pub.domain.SpecificQueryDefinition)2 SpecificQuery (org.irods.jargon.core.query.SpecificQuery)2 SpecificQueryResultSet (org.irods.jargon.core.query.SpecificQueryResultSet)2 DataGridFilePermission (com.emc.metalnx.core.domain.entity.DataGridFilePermission)1 DataGridGroupPermission (com.emc.metalnx.core.domain.entity.DataGridGroupPermission)1 DataGridUserPermission (com.emc.metalnx.core.domain.entity.DataGridUserPermission)1 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)1 CollectionAO (org.irods.jargon.core.pub.CollectionAO)1