use of com.emc.metalnx.core.domain.entity.enums.DataGridSearchOperatorEnum in project metalnx-web by irods-contrib.
the class MetadataController method searchByMetadata.
@RequestMapping(value = "/search/", method = RequestMethod.POST)
@ResponseBody
public String searchByMetadata(@RequestParam(required = false) final String jsonMetadataSearch, @RequestParam("draw") final int draw, @RequestParam("start") final int start, @RequestParam("length") final int length) throws DataGridConnectionRefusedException {
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 {
if (jsonMetadataSearch != null) {
currPage = (int) (Math.floor(start / length) + 1);
this.jsonMetadataSearch = jsonMetadataSearch;
}
// Creating parser
JsonNode jsonObject = mapper.readTree(this.jsonMetadataSearch);
currSearch = new ArrayList<>();
JsonNode attributes = jsonObject.get("attribute");
JsonNode operators = jsonObject.get("operator");
JsonNode values = jsonObject.get("value");
JsonNode units = jsonObject.get("unit");
for (int i = 0; i < attributes.size(); i++) {
String attr = attributes.get(i).textValue();
String val = values.get(i).textValue();
String unit = units.get(i).textValue();
String opt = operators.get(i).textValue();
DataGridSearchOperatorEnum op = DataGridSearchOperatorEnum.valueOf(opt);
DataGridMetadataSearch ms = new DataGridMetadataSearch(attr, val, unit, op);
currSearch.add(ms);
}
DataGridPageContext pageContext = new DataGridPageContext();
List<DataGridCollectionAndDataObject> dgCollDataObjs = metadataService.findByMetadata(currSearch, pageContext, currPage, length);
jsonResponse.put("recordsTotal", String.valueOf(pageContext.getTotalNumberOfItems()));
jsonResponse.put("recordsFiltered", String.valueOf(pageContext.getTotalNumberOfItems()));
jsonResponse.put("data", dgCollDataObjs);
} catch (DataGridConnectionRefusedException e) {
throw e;
} catch (Exception e) {
logger.error("Could not search by metadata: ", e.getMessage());
}
try {
jsonString = mapper.writeValueAsString(jsonResponse);
} catch (JsonProcessingException e) {
logger.error("Could not parse hashmap in metadata search to json: {}", e.getMessage());
}
return jsonString;
}
Aggregations