Search in sources :

Example 1 with JargonQueryException

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

the class CollectionServiceImpl method getTotalCollectionsUnderPathThatMatchSearchText.

/**
 * Calculates the number of collections 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
 * @throws JargonException
 * @throws DuplicateDataException
 * @throws JargonQueryException
 */
private int getTotalCollectionsUnderPathThatMatchSearchText(String parentPath, String searchText) throws DataGridConnectionRefusedException {
    logger.info("getTotalCollectionsUnderPathThatMatchSearchText()");
    SpecificQueryAO specificQueryAO = adminServices.getSpecificQueryAO();
    int totalNumberOfItems = 0;
    SpecificQueryDefinition queryDef = null;
    String sqlQueryAlias = "totalNumberOfCollectionsThatMatchSearchText";
    try {
        sqlQueryAlias = SQL_TOTAL_NUMBER_OF_COLLS_MATCHING_SEARCH_TEXT_ALIAS;
        ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
        SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
        String query = provider.buildSelectTotalCollectionsUnderPathThatMatchSearchText(parentPath, searchText);
        // 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);
        SpecificQuery specQuery = SpecificQuery.instanceArguments(sqlQueryAlias, args, 0, zone);
        SpecificQueryResultSet queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, MAX_RESULTS_PER_PAGE, 0);
        totalNumberOfItems = DataGridUtils.mapCountQueryResultSetToInteger(queryResultSet);
    } 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 totalNumberOfItems;
}
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) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) SpecificQueryDefinition(org.irods.jargon.core.pub.domain.SpecificQueryDefinition) JargonQueryException(org.irods.jargon.core.query.JargonQueryException) SpecificQuery(org.irods.jargon.core.query.SpecificQuery)

Example 2 with JargonQueryException

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

the class SpecQueryServiceImpl method countItemsMatchingFileProperties.

/**
 * Counts the number of items matching a file properties search criteria.
 *
 * @param filePropertiesSearch
 *            filePropertiesSearch criteria
 * @param zone
 *            zone name
 * @param searchAgainstColls
 *            flag set to true when searching collections and false when
 *            searching data data objects
 * @return total number of items matching a file properties search criteria
 * @throws DataGridConnectionRefusedException
 * @throws UnsupportedDataGridFeatureException
 * @throws JargonException
 */
private int countItemsMatchingFileProperties(List<DataGridFilePropertySearch> filePropertiesSearch, String zone, boolean searchAgainstColls) throws DataGridConnectionRefusedException, UnsupportedDataGridFeatureException, JargonException {
    logger.info("countItemsMatchingFileProperties()");
    int totalItems = 0;
    SpecificQueryAO specificQueryAO = null;
    SpecificQuery specQuery = null;
    SpecificQueryResultSet queryResultSet = null;
    String userSQLAlias = "metalnxUserQuery_" + System.currentTimeMillis();
    try {
        specificQueryAO = adminServices.getSpecificQueryAO();
        ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
        SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
        String query = provider.buildQueryCountItemsMatchingPropertiesSearch(filePropertiesSearch, zone, searchAgainstColls);
        logger.debug("query:{}", query);
        // Creating Specific Query instance
        SpecificQueryDefinition queryDef = new SpecificQueryDefinition();
        queryDef.setAlias(userSQLAlias);
        queryDef.setSql(query);
        // Creating spec query on iRODS
        specificQueryAO.addSpecificQuery(queryDef);
        specQuery = SpecificQuery.instanceWithNoArguments(userSQLAlias, 0, zone);
        logger.info("Specific query: {}", query.toString());
        queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, 99999, 0);
        // after running the user specific query, we need to remove from the database
        specificQueryAO.removeSpecificQueryByAlias(userSQLAlias);
        totalItems = DataGridUtils.mapCountQueryResultSetToInteger(queryResultSet);
    } catch (JargonException e) {
        logger.error("Could not get specific query: ", e);
        throw e;
    } catch (JargonQueryException e) {
        logger.error("Could not get specific query: ", e);
        throw new JargonException(e);
    }
    return totalItems;
}
Also used : JargonQueryException(org.irods.jargon.core.query.JargonQueryException) SpecificQueryProvider(com.emc.metalnx.services.irods.utils.SpecificQueryProvider) JargonException(org.irods.jargon.core.exception.JargonException) ClientHints(org.irods.jargon.core.pub.domain.ClientHints) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) SpecificQuery(org.irods.jargon.core.query.SpecificQuery) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) SpecificQueryDefinition(org.irods.jargon.core.pub.domain.SpecificQueryDefinition)

Example 3 with JargonQueryException

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

the class SpecQueryServiceImpl method searchByFileProperties.

@Override
public SpecificQueryResultSet searchByFileProperties(List<DataGridFilePropertySearch> filePropertySearch, String zone, boolean searchAgainstColls, DataGridPageContext pageContext, int offset, int limit) throws DataGridConnectionRefusedException, JargonException {
    SpecificQueryAO specificQueryAO = null;
    SpecificQuery specQuery = null;
    SpecificQueryResultSet queryResultSet = null;
    String userSQLAlias = "metalnxUserQuery_" + System.currentTimeMillis();
    try {
        specificQueryAO = adminServices.getSpecificQueryAO();
        ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
        SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
        String query = provider.buildQueryForFilePropertiesSearch(filePropertySearch, zone, searchAgainstColls, offset, limit);
        // Creating Specific Query instance
        SpecificQueryDefinition queryDef = new SpecificQueryDefinition();
        queryDef.setAlias(userSQLAlias);
        queryDef.setSql(query);
        // Creating spec query on iRODS
        specificQueryAO.addSpecificQuery(queryDef);
        specQuery = SpecificQuery.instanceWithNoArguments(userSQLAlias, 0, zone);
        logger.info("Specific query: {}", query);
        queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, 99999, 0);
    } catch (JargonException e) {
        logger.error("Could not get specific query: ", e);
        throw e;
    } catch (JargonQueryException e) {
        logger.error("Could not get specific query: ", e);
        throw new JargonException(e);
    } catch (UnsupportedDataGridFeatureException e) {
        logger.error("Could not get specific query: ", e);
        throw new JargonException(e);
    } finally {
        try {
            // after running the user specific query, we need to remove from the database
            specificQueryAO.removeSpecificQueryByAlias(userSQLAlias);
        } catch (JargonException e) {
            logger.error("Could not remove specific query {}: ", userSQLAlias, e.getMessage());
        }
    }
    return queryResultSet;
}
Also used : UnsupportedDataGridFeatureException(com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException) JargonQueryException(org.irods.jargon.core.query.JargonQueryException) SpecificQueryProvider(com.emc.metalnx.services.irods.utils.SpecificQueryProvider) JargonException(org.irods.jargon.core.exception.JargonException) ClientHints(org.irods.jargon.core.pub.domain.ClientHints) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) SpecificQuery(org.irods.jargon.core.query.SpecificQuery) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) SpecificQueryDefinition(org.irods.jargon.core.pub.domain.SpecificQueryDefinition)

Example 4 with JargonQueryException

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

the class SpecQueryServiceImpl method countItemsMatchingMetadata.

/**
 * Counts the number of items matching a metadata search criteria.
 *
 * @param metadataSearch
 *            metadata criteria
 * @param zone
 *            zone name
 * @param searchAgainstColls
 *            flag set to true when searching collections and false when
 *            searching data data objects
 * @return total number of items matching a metadata search criteria
 * @throws DataGridConnectionRefusedException
 * @throws JargonException
 */
private int countItemsMatchingMetadata(List<DataGridMetadataSearch> metadataSearch, String zone, boolean searchAgainstColls) throws DataGridConnectionRefusedException, JargonException {
    int totalItems = 0;
    SpecificQueryAO specificQueryAO = null;
    SpecificQuery specQuery = null;
    SpecificQueryResultSet queryResultSet = null;
    String userSQLAlias = "metalnxUserQuery_" + System.currentTimeMillis();
    try {
        specificQueryAO = adminServices.getSpecificQueryAO();
        ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
        SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
        String query = provider.buildQueryForCountOfItemsMatchingMetadataSearch(metadataSearch, zone, searchAgainstColls);
        // Creating Specific Query instance
        SpecificQueryDefinition queryDef = new SpecificQueryDefinition();
        queryDef.setAlias(userSQLAlias);
        queryDef.setSql(query);
        // Creating spec query on iRODS
        specificQueryAO.addSpecificQuery(queryDef);
        specQuery = SpecificQuery.instanceWithNoArguments(userSQLAlias, 0, zone);
        logger.info("Specific query: {}", query.toString());
        queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, 99999, 0);
        // after running the user specific query, we need to remove from the database
        specificQueryAO.removeSpecificQueryByAlias(userSQLAlias);
        totalItems = DataGridUtils.mapCountQueryResultSetToInteger(queryResultSet);
    } catch (JargonException e) {
        logger.error("Could not get specific query: ", e);
        throw e;
    } catch (JargonQueryException e) {
        logger.error("Could not get specific query: ", e);
        throw new JargonException(e);
    } catch (UnsupportedDataGridFeatureException e) {
        logger.error("Could not get specific query: ", e);
        throw new JargonException(e);
    }
    return totalItems;
}
Also used : UnsupportedDataGridFeatureException(com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException) JargonQueryException(org.irods.jargon.core.query.JargonQueryException) SpecificQueryProvider(com.emc.metalnx.services.irods.utils.SpecificQueryProvider) JargonException(org.irods.jargon.core.exception.JargonException) ClientHints(org.irods.jargon.core.pub.domain.ClientHints) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) SpecificQuery(org.irods.jargon.core.query.SpecificQuery) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) SpecificQueryDefinition(org.irods.jargon.core.pub.domain.SpecificQueryDefinition)

Example 5 with JargonQueryException

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

the class MetadataServiceImpl method findMetadataValuesByPath.

@Override
public List<DataGridMetadata> findMetadataValuesByPath(String path) throws DataGridConnectionRefusedException {
    List<MetaDataAndDomainData> metadataList;
    List<DataGridMetadata> dataGridMetadataList = new ArrayList<>();
    List<MetaDataAndDomainData> resultingList;
    CollectionAndDataObjectListAndSearchAO collectionAndDataObjectListAndSearchAO = irodsServices.getCollectionAndDataObjectListAndSearchAO();
    try {
        Object obj = collectionAndDataObjectListAndSearchAO.getFullObjectForType(path);
        if (obj instanceof DataObject) {
            DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
            metadataList = dataObjectAO.findMetadataValuesForDataObject(path);
        } else {
            CollectionAO collectionAO = irodsServices.getCollectionAO();
            metadataList = collectionAO.findMetadataValuesForCollection(path);
        }
        // TODO2: Making sure all AVUs are unique. Jargon should do that.
        resultingList = new ArrayList<>();
        Set<Integer> setOfAlreadyListedAVUs = new HashSet<>();
        for (MetaDataAndDomainData avuForItem : metadataList) {
            int avuId = avuForItem.getAvuId();
            if (!setOfAlreadyListedAVUs.contains(avuId)) {
                resultingList.add(avuForItem);
                setOfAlreadyListedAVUs.add(avuId);
            }
        }
        for (MetaDataAndDomainData metadata : resultingList) {
            DataGridMetadata dataGridMetadata = new DataGridMetadata();
            dataGridMetadata.setAttribute(metadata.getAvuAttribute());
            dataGridMetadata.setValue(metadata.getAvuValue());
            dataGridMetadata.setUnit(metadata.getAvuUnit());
            dataGridMetadataList.add(dataGridMetadata);
        }
        Collections.sort(dataGridMetadataList);
    } catch (JargonQueryException e) {
        logger.error("Error getting metadata info from collection: " + e.toString());
    } catch (JargonException e) {
        logger.error("Error getting metadata info from dataobject: " + e.toString());
    }
    return dataGridMetadataList;
}
Also used : CollectionAndDataObjectListAndSearchAO(org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO) CollectionAO(org.irods.jargon.core.pub.CollectionAO) JargonException(org.irods.jargon.core.exception.JargonException) ArrayList(java.util.ArrayList) MetaDataAndDomainData(org.irods.jargon.core.query.MetaDataAndDomainData) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataObject(org.irods.jargon.core.pub.domain.DataObject) JargonQueryException(org.irods.jargon.core.query.JargonQueryException) DataGridMetadata(com.emc.metalnx.core.domain.entity.DataGridMetadata) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataObject(org.irods.jargon.core.pub.domain.DataObject) DataObjectAO(org.irods.jargon.core.pub.DataObjectAO) HashSet(java.util.HashSet)

Aggregations

JargonQueryException (org.irods.jargon.core.query.JargonQueryException)8 JargonException (org.irods.jargon.core.exception.JargonException)7 SpecificQueryProvider (com.emc.metalnx.services.irods.utils.SpecificQueryProvider)6 SpecificQueryAO (org.irods.jargon.core.pub.SpecificQueryAO)6 ClientHints (org.irods.jargon.core.pub.domain.ClientHints)6 SpecificQueryDefinition (org.irods.jargon.core.pub.domain.SpecificQueryDefinition)6 SpecificQuery (org.irods.jargon.core.query.SpecificQuery)6 SpecificQueryResultSet (org.irods.jargon.core.query.SpecificQueryResultSet)6 UnsupportedDataGridFeatureException (com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException)5 ArrayList (java.util.ArrayList)4 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)3 DataGridMetadata (com.emc.metalnx.core.domain.entity.DataGridMetadata)1 DataGridDataNotFoundException (com.emc.metalnx.core.domain.exceptions.DataGridDataNotFoundException)1 DataGridQueryException (com.emc.metalnx.core.domain.exceptions.DataGridQueryException)1 HashSet (java.util.HashSet)1 DataNotFoundException (org.irods.jargon.core.exception.DataNotFoundException)1 CollectionAO (org.irods.jargon.core.pub.CollectionAO)1 CollectionAndDataObjectListAndSearchAO (org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO)1 DataObjectAO (org.irods.jargon.core.pub.DataObjectAO)1 DataObject (org.irods.jargon.core.pub.domain.DataObject)1