Search in sources :

Example 11 with SpecificQueryDefinition

use of org.irods.jargon.core.pub.domain.SpecificQueryDefinition in project metalnx-web by irods-contrib.

the class SpecQueryServiceImpl method searchByMetadata.

@Override
public SpecificQueryResultSet searchByMetadata(List<DataGridMetadataSearch> metadataSearch, 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.buildSpecificQueryForMetadataSearch(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);
    } 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)

Aggregations

SpecificQueryDefinition (org.irods.jargon.core.pub.domain.SpecificQueryDefinition)11 JargonException (org.irods.jargon.core.exception.JargonException)10 SpecificQueryAO (org.irods.jargon.core.pub.SpecificQueryAO)10 SpecificQueryProvider (com.emc.metalnx.services.irods.utils.SpecificQueryProvider)8 ClientHints (org.irods.jargon.core.pub.domain.ClientHints)8 SpecificQuery (org.irods.jargon.core.query.SpecificQuery)8 SpecificQueryResultSet (org.irods.jargon.core.query.SpecificQueryResultSet)8 UnsupportedDataGridFeatureException (com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException)7 JargonQueryException (org.irods.jargon.core.query.JargonQueryException)6 ArrayList (java.util.ArrayList)5 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)2 CollectionAndDataObjectListingEntry (org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)2 DataGridSpecificQuery (com.emc.metalnx.core.domain.entity.DataGridSpecificQuery)1