use of com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch in project metalnx-web by irods-contrib.
the class FilePropertiesController method search.
@RequestMapping(value = "/search")
@ResponseBody
public String search(@RequestParam(value = "jsonFilePropertySearch", required = false) final String jsonFilePropertySearch, @RequestParam("draw") final int draw, @RequestParam("start") final int start, @RequestParam("length") final int length) throws DataGridConnectionRefusedException, JargonException {
if (jsonFilePropertySearch != null) {
currentPage = (int) (Math.floor(start / length) + 1);
this.jsonFilePropertySearch = jsonFilePropertySearch;
}
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> jsonResponse = new HashMap<String, Object>();
jsonResponse.put("draw", String.valueOf(draw));
jsonResponse.put("recordsTotal", String.valueOf(0));
jsonResponse.put("recordsFiltered", String.valueOf(0));
jsonResponse.put("data", new ArrayList<String>());
String jsonString = "";
try {
JsonNode jsonNode = mapper.readTree(this.jsonFilePropertySearch);
currentFilePropertySearch = new ArrayList<>();
JsonNode attributes = jsonNode.get("attribute");
JsonNode operators = jsonNode.get("operator");
JsonNode values = jsonNode.get("value");
for (int i = 0; i < attributes.size(); i++) {
DataGridFilePropertySearch ms = new DataGridFilePropertySearch(FilePropertyField.valueOf(attributes.get(i).textValue()), DataGridSearchOperatorEnum.valueOf(operators.get(i).textValue()), values.get(i).textValue());
currentFilePropertySearch.add(ms);
}
DataGridPageContext pageContext = new DataGridPageContext();
List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = filePropertyService.findByFileProperties(currentFilePropertySearch, pageContext, currentPage, length);
jsonResponse.put("recordsTotal", String.valueOf(pageContext.getTotalNumberOfItems()));
jsonResponse.put("recordsFiltered", String.valueOf(pageContext.getTotalNumberOfItems()));
jsonResponse.put("data", dataGridCollectionAndDataObjects);
} catch (DataGridConnectionRefusedException e) {
logger.error("data grid error in search", e);
throw e;
} catch (JargonException e) {
logger.error("Could not search by metadata: ", e.getMessage());
throw e;
} catch (ParseException e) {
logger.error("Could not search by metadata: ", e.getMessage());
throw new JargonException(e);
} catch (JsonProcessingException e) {
logger.error("Could not search by metadata: ", e.getMessage());
throw new JargonException(e);
} catch (IOException e) {
logger.error("Could not search by metadata: ", e.getMessage());
throw new JargonException(e);
}
try {
jsonString = mapper.writeValueAsString(jsonResponse);
} catch (JsonProcessingException e) {
logger.error("Could not parse hashmap in file properties search to json: {}", e.getMessage());
throw new JargonException(e);
}
return jsonString;
}
use of com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch 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());
}
Aggregations