use of com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch in project metalnx-web by irods-contrib.
the class PostgresSpecificQueryProviderImpl method buildQueryForFilePropertiesSearch.
@Override
public String buildQueryForFilePropertiesSearch(List<DataGridFilePropertySearch> filePropertiesSearches, String zone, boolean searchAgainstColls, int offset, int limit) {
StringBuilder query = new StringBuilder();
if (filePropertiesSearches.size() > 0) {
if (searchAgainstColls) {
query.append(buildSelectClauseForCollectionsForPropertiesSearch());
} else {
query.append(buildSelectClauseForDataObjectsForPropertiesSearch());
}
for (DataGridFilePropertySearch filePropertiesSearch : filePropertiesSearches) {
// where clause - conditions
query.append(buildWhereClauseForDataGridPropertySearch(filePropertiesSearch.getAttribute(), filePropertiesSearch.getOperator(), filePropertiesSearch.getValue()));
// appending conditions
if (filePropertiesSearches.indexOf(filePropertiesSearch) != filePropertiesSearches.size() - 1) {
query.append(" AND ");
}
}
}
if (offset == 0 && limit == 0) {
// ignored
} else {
query.append(" OFFSET ");
query.append(offset);
query.append(" LIMIT ");
query.append(limit);
}
return query.toString();
}
use of com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch 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());
}
use of com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch in project metalnx-web by irods-contrib.
the class SpecQueryServiceImplTest method testCountCollectionsMatchingFileProperties.
@Test
public void testCountCollectionsMatchingFileProperties() 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<DataGridFilePropertySearch> filePropertiesSearch = new ArrayList<>();
DataGridFilePropertySearch dataSearch = new DataGridFilePropertySearch(FilePropertyField.OWNER_NAME, DataGridSearchOperatorEnum.EQUAL, irodsAccount.getUserName());
filePropertiesSearch.add(dataSearch);
int count = specQueryService.countCollectionsMatchingFileProperties(filePropertiesSearch, irodsAccount.getZone());
Assert.assertTrue("no recs returned", count > 1);
}
use of com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch in project metalnx-web by irods-contrib.
the class SpecQueryServiceImplTest method testCountDataObjectsMatchingFileProperties.
@Test
public void testCountDataObjectsMatchingFileProperties() 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<DataGridFilePropertySearch> filePropertiesSearch = new ArrayList<>();
DataGridFilePropertySearch dataSearch = new DataGridFilePropertySearch(FilePropertyField.OWNER_NAME, DataGridSearchOperatorEnum.EQUAL, irodsAccount.getUserName());
filePropertiesSearch.add(dataSearch);
dataSearch = new DataGridFilePropertySearch(FilePropertyField.SIZE, DataGridSearchOperatorEnum.BIGGER_THAN, "200");
filePropertiesSearch.add(dataSearch);
int count = specQueryService.countDataObjectsMatchingFileProperties(filePropertiesSearch, irodsAccount.getZone());
Assert.assertTrue("no recs returned", count > 1);
}
use of com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch in project metalnx-web by irods-contrib.
the class FilePropertiesController method searchToCSVFile.
@RequestMapping(value = "/downloadCSVResults/")
public void searchToCSVFile(final HttpServletResponse response) throws DataGridConnectionRefusedException, IOException, JargonException {
ServletOutputStream outputStream = response.getOutputStream();
String loggedUser = getLoggedDataGridUser().getUsername();
String date = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String filename = String.format("search-result_%s_%s.csv", loggedUser, date);
// Setting CSV Mime type
response.setContentType("text/csv");
response.setHeader("Content-disposition", "attachment;filename=" + filename);
// Building search parameters lines
outputStream.print("Search condition #;Condition\n");
int i = 1;
for (DataGridFilePropertySearch field : currentFilePropertySearch) {
String condition = field.toString();
outputStream.print(String.format("%d;%s\n", i, condition));
i++;
}
outputStream.print("\n");
outputStream.flush();
// Executing query
DataGridPageContext pageContext = new DataGridPageContext();
List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = filePropertyService.findByFileProperties(currentFilePropertySearch, pageContext, 1, Integer.MAX_VALUE);
// Printing number of results
outputStream.print("Number of results\n");
outputStream.print(String.format("%d\n", pageContext.getTotalNumberOfItems()));
outputStream.print("\n");
outputStream.flush();
// Printing results
outputStream.print("Filename;Path;Owner;Kind;Modified;Size;Matches\n");
for (DataGridCollectionAndDataObject obj : dataGridCollectionAndDataObjects) {
outputStream.print(obj.getName() + ";");
outputStream.print(obj.getPath() + ";");
outputStream.print(obj.getOwner() + ";");
outputStream.print((obj.isCollection() ? "collection" : "data object") + ";");
outputStream.print(obj.getModifiedAtFormattedForCSVReport() + ";");
outputStream.print(String.valueOf(obj.getSize()) + ";");
outputStream.print(String.valueOf(obj.getNumberOfMatches()));
outputStream.print("\n");
outputStream.flush();
}
}
Aggregations