Search in sources :

Example 1 with DataGridSearchOperatorEnum

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;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataGridSearchOperatorEnum(com.emc.metalnx.core.domain.entity.enums.DataGridSearchOperatorEnum) HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DataGridPageContext(com.emc.metalnx.core.domain.entity.DataGridPageContext) DataGridMetadataSearch(com.emc.metalnx.core.domain.entity.DataGridMetadataSearch) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)1 DataGridMetadataSearch (com.emc.metalnx.core.domain.entity.DataGridMetadataSearch)1 DataGridPageContext (com.emc.metalnx.core.domain.entity.DataGridPageContext)1 DataGridSearchOperatorEnum (com.emc.metalnx.core.domain.entity.enums.DataGridSearchOperatorEnum)1 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)1 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1