Search in sources :

Example 6 with SpecificQueryResultSet

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

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

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

the class SpecQueryServiceImplTest method testSearchByFilePropertiesForCollections.

@Test
public void testSearchByFilePropertiesForCollections() throws Exception {
    SpecQueryServiceImpl specQueryService = new SpecQueryServiceImpl();
    IRODSServices irodsService = Mockito.mock(IRODSServices.class);
    AdminServices adminServices = Mockito.mock(AdminServices.class);
    IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties);
    IRODSAccount test3Account = testingPropertiesHelper.buildIRODSAccountFromSecondaryTestProperties(testingProperties);
    EnvironmentalInfoAO environmentalInfoAO = irodsFileSystem.getIRODSAccessObjectFactory().getEnvironmentalInfoAO(irodsAccount);
    SpecificQueryAO specificQueryAO = irodsFileSystem.getIRODSAccessObjectFactory().getSpecificQueryAO(irodsAccount);
    Mockito.when(irodsService.getEnvironmentalInfoAO()).thenReturn(environmentalInfoAO);
    Mockito.when(adminServices.getSpecificQueryAO()).thenReturn(specificQueryAO);
    specQueryService.setIrodsServices(irodsService);
    specQueryService.setAdminServices(adminServices);
    List<DataGridFilePropertySearch> filePropertiesSearch = new ArrayList<>();
    DataGridFilePropertySearch dataSearch = new DataGridFilePropertySearch(FilePropertyField.OWNER_NAME, DataGridSearchOperatorEnum.EQUAL, test3Account.getUserName());
    filePropertiesSearch.add(dataSearch);
    SpecificQueryResultSet result = specQueryService.searchByFileProperties(filePropertiesSearch, irodsAccount.getZone(), true, null, 0, 0);
    Assert.assertFalse("no result", result.getResults().isEmpty());
}
Also used : EnvironmentalInfoAO(org.irods.jargon.core.pub.EnvironmentalInfoAO) AdminServices(com.emc.metalnx.services.interfaces.AdminServices) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) DataGridFilePropertySearch(com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch) ArrayList(java.util.ArrayList) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) IRODSServices(com.emc.metalnx.services.interfaces.IRODSServices) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) Test(org.junit.Test)

Example 9 with SpecificQueryResultSet

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

the class SpecQueryServiceImplTest method testSearchByMetadataCollections.

@Test
public void testSearchByMetadataCollections() throws Exception {
    SpecQueryServiceImpl specQueryService = new SpecQueryServiceImpl();
    IRODSServices irodsService = Mockito.mock(IRODSServices.class);
    AdminServices adminServices = Mockito.mock(AdminServices.class);
    IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties);
    EnvironmentalInfoAO environmentalInfoAO = irodsFileSystem.getIRODSAccessObjectFactory().getEnvironmentalInfoAO(irodsAccount);
    SpecificQueryAO specificQueryAO = irodsFileSystem.getIRODSAccessObjectFactory().getSpecificQueryAO(irodsAccount);
    Mockito.when(irodsService.getEnvironmentalInfoAO()).thenReturn(environmentalInfoAO);
    Mockito.when(adminServices.getSpecificQueryAO()).thenReturn(specificQueryAO);
    specQueryService.setIrodsServices(irodsService);
    specQueryService.setAdminServices(adminServices);
    List<DataGridMetadataSearch> metadataSearch = new ArrayList<DataGridMetadataSearch>();
    DataGridMetadataSearch search = new DataGridMetadataSearch(COLL_AVU_ATTR1, COLL_AVU_VAL1, "", DataGridSearchOperatorEnum.EQUAL);
    metadataSearch.add(search);
    SpecificQueryResultSet result = specQueryService.searchByMetadata(metadataSearch, irodsAccount.getZone(), true, null, 0, 0);
    Assert.assertFalse("no result", result.getResults().isEmpty());
}
Also used : EnvironmentalInfoAO(org.irods.jargon.core.pub.EnvironmentalInfoAO) AdminServices(com.emc.metalnx.services.interfaces.AdminServices) DataGridMetadataSearch(com.emc.metalnx.core.domain.entity.DataGridMetadataSearch) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) ArrayList(java.util.ArrayList) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) IRODSServices(com.emc.metalnx.services.interfaces.IRODSServices) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) Test(org.junit.Test)

Example 10 with SpecificQueryResultSet

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

the class FilePropertyServiceImpl method findByFileProperties.

@Override
public List<DataGridCollectionAndDataObject> findByFileProperties(List<DataGridFilePropertySearch> searchList, DataGridPageContext pageContext, int pageNum, int pageSize) throws DataGridConnectionRefusedException, JargonException {
    List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = null;
    List<DataGridCollectionAndDataObject> dataGridObjects = null;
    List<DataGridCollectionAndDataObject> dataGridCollections = null;
    int totalCollections = 0;
    int totalDataObjects = 0;
    int startIndex = (pageNum - 1) * pageSize;
    int endIndex = (pageNum * pageSize) - 1;
    int endIndexForDataObjs;
    int endIndexForCollections;
    try {
        String zone = irodsServices.getCurrentUserZone();
        totalCollections = specQueryService.countCollectionsMatchingFileProperties(searchList, zone);
        totalDataObjects = specQueryService.countDataObjectsMatchingFileProperties(searchList, zone);
        pageContext.setStartItemNumber(startIndex + 1);
        pageContext.setTotalNumberOfItems(totalCollections + totalDataObjects);
        dataGridCollectionAndDataObjects = new ArrayList<DataGridCollectionAndDataObject>();
        if (endIndex + 1 <= totalCollections) {
            // looking for collections
            SpecificQueryResultSet resultSetColls = specQueryService.searchByFileProperties(searchList, zone, true, pageContext, startIndex, pageSize);
            dataGridCollections = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetColls);
            endIndexForCollections = dataGridCollections.size();
            dataGridCollectionAndDataObjects.addAll(dataGridCollections);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + endIndexForCollections - 1);
        } else if (startIndex + 1 > totalCollections) {
            // looking for data objects
            SpecificQueryResultSet resultSetDataObjs = specQueryService.searchByFileProperties(searchList, zone, false, pageContext, startIndex - totalCollections, pageSize);
            dataGridObjects = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetDataObjs);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + dataGridObjects.size() - 1);
            dataGridCollectionAndDataObjects.addAll(dataGridObjects);
        } else {
            // looking for collections
            SpecificQueryResultSet resultSetColls = specQueryService.searchByFileProperties(searchList, zone, true, pageContext, startIndex, pageSize);
            dataGridCollections = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetColls);
            endIndexForDataObjs = pageSize - (totalCollections % pageSize);
            // looking for data objects
            SpecificQueryResultSet resultSetDataObjs = specQueryService.searchByFileProperties(searchList, zone, false, pageContext, 0, endIndexForDataObjs);
            dataGridObjects = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetDataObjs);
            endIndexForDataObjs = endIndexForDataObjs > dataGridObjects.size() ? dataGridObjects.size() : endIndexForDataObjs;
            dataGridCollectionAndDataObjects.addAll(dataGridCollections);
            dataGridCollectionAndDataObjects.addAll(dataGridObjects);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + endIndexForDataObjs + dataGridCollections.size() - 1);
        }
    } catch (JargonException | UnsupportedDataGridFeatureException e) {
        logger.error("Could not find data objects by metadata. ", e);
        if (e.getCause() instanceof ConnectException) {
            throw new DataGridConnectionRefusedException();
        }
    }
    this.populateVisibilityForCurrentUser(dataGridCollectionAndDataObjects);
    return dataGridCollectionAndDataObjects;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) UnsupportedDataGridFeatureException(com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) ConnectException(java.net.ConnectException)

Aggregations

SpecificQueryResultSet (org.irods.jargon.core.query.SpecificQueryResultSet)15 SpecificQueryAO (org.irods.jargon.core.pub.SpecificQueryAO)12 JargonException (org.irods.jargon.core.exception.JargonException)10 ArrayList (java.util.ArrayList)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 SpecificQueryDefinition (org.irods.jargon.core.pub.domain.SpecificQueryDefinition)8 SpecificQuery (org.irods.jargon.core.query.SpecificQuery)8 JargonQueryException (org.irods.jargon.core.query.JargonQueryException)7 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)4 AdminServices (com.emc.metalnx.services.interfaces.AdminServices)4 IRODSServices (com.emc.metalnx.services.interfaces.IRODSServices)4 IRODSAccount (org.irods.jargon.core.connection.IRODSAccount)4 EnvironmentalInfoAO (org.irods.jargon.core.pub.EnvironmentalInfoAO)4 Test (org.junit.Test)4 DataGridFilePropertySearch (com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch)2 DataGridMetadataSearch (com.emc.metalnx.core.domain.entity.DataGridMetadataSearch)2 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)2 CollectionAndDataObjectListingEntry (org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)2