use of org.irods.jargon.core.pub.SpecificQueryAO 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;
}
use of org.irods.jargon.core.pub.SpecificQueryAO 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;
}
use of org.irods.jargon.core.pub.SpecificQueryAO 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;
}
use of org.irods.jargon.core.pub.SpecificQueryAO in project metalnx-web by irods-contrib.
the class SpecQueryServiceImplTest method testCountCollectionsMatchingMetadata.
@Test
public void testCountCollectionsMatchingMetadata() 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);
int count = specQueryService.countCollectionsMatchingMetadata(metadataSearch, irodsAccount.getZone());
Assert.assertTrue("no recs returned", count > 1);
}
use of org.irods.jargon.core.pub.SpecificQueryAO 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());
}
Aggregations