use of org.irods.jargon.core.pub.SpecificQueryAO 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;
}
use of org.irods.jargon.core.pub.SpecificQueryAO in project metalnx-web by irods-contrib.
the class CollectionServiceImpl method getTotalDataObjectsUnderPathThatMatchSearchText.
/**
* Calculates the number of data objects 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
*/
private int getTotalDataObjectsUnderPathThatMatchSearchText(String parentPath, String searchText) throws DataNotFoundException, JargonQueryException, DataGridConnectionRefusedException {
logger.info("getTotalCollectionsUnderPathThatMatchSearchText()");
logger.info("parentPath:{}", parentPath);
logger.info("searchText:{}", searchText);
SpecificQueryAO specificQueryAO = adminServices.getSpecificQueryAO();
SpecificQueryDefinition queryDef = null;
String sqlAlias = null;
int totalNumberOfItems = 0;
try {
sqlAlias = SQL_TOTAL_NUMBER_OF_DATA_OBJECTS_MATCHING_SEARCH_TEXT_ALIAS;
ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
String query = provider.buildSelectTotalDataObjectsUnderPathThatMatchSearchText(parentPath, searchText);
// 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 + "%");
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
totalNumberOfItems = DataGridUtils.mapCountQueryResultSetToInteger(queryResultSet);
} catch (JargonException | UnsupportedDataGridFeatureException e) {
logger.error("Could not execute specific query to get the total number of data objects matching 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 totalNumberOfItems;
}
use of org.irods.jargon.core.pub.SpecificQueryAO in project metalnx-web by irods-contrib.
the class SpecQueryServiceImplTest method testSearchByMetadataDataObjects.
@Test
public void testSearchByMetadataDataObjects() 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(DATA_AVU_ATTR1, DATA_AVU_VAL1, "", DataGridSearchOperatorEnum.EQUAL);
metadataSearch.add(search);
SpecificQueryResultSet result = specQueryService.searchByMetadata(metadataSearch, irodsAccount.getZone(), false, null, 0, 0);
Assert.assertFalse("no result", result.getResults().isEmpty());
}
use of org.irods.jargon.core.pub.SpecificQueryAO in project metalnx-web by irods-contrib.
the class SpecQueryServiceImplTest method testSearchByFilePropertiesForDataObjects.
@Test
public void testSearchByFilePropertiesForDataObjects() 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, // use test3 because its smaller
test3Account.getUserName());
filePropertiesSearch.add(dataSearch);
dataSearch = new DataGridFilePropertySearch(FilePropertyField.SIZE, DataGridSearchOperatorEnum.BIGGER_THAN, "200");
filePropertiesSearch.add(dataSearch);
SpecificQueryResultSet result = specQueryService.searchByFileProperties(filePropertiesSearch, irodsAccount.getZone(), false, null, 0, 0);
Assert.assertNotNull("no result", result.getResults());
}
use of org.irods.jargon.core.pub.SpecificQueryAO 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;
}
Aggregations