Search in sources :

Example 1 with DataGridPageContext

use of com.emc.metalnx.core.domain.entity.DataGridPageContext 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();
    }
}
Also used : DataGridPageContext(com.emc.metalnx.core.domain.entity.DataGridPageContext) ServletOutputStream(javax.servlet.ServletOutputStream) DataGridFilePropertySearch(com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with DataGridPageContext

use of com.emc.metalnx.core.domain.entity.DataGridPageContext 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)

Example 3 with DataGridPageContext

use of com.emc.metalnx.core.domain.entity.DataGridPageContext 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;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) HashMap(java.util.HashMap) JargonException(org.irods.jargon.core.exception.JargonException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DataGridPageContext(com.emc.metalnx.core.domain.entity.DataGridPageContext) DataGridFilePropertySearch(com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) ParseException(java.text.ParseException) 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)

Example 4 with DataGridPageContext

use of com.emc.metalnx.core.domain.entity.DataGridPageContext in project metalnx-web by irods-contrib.

the class MetadataController method exportSearchResultsToCSVFile.

@RequestMapping(value = "/downloadCSVResults/")
public void exportSearchResultsToCSVFile(final HttpServletResponse response) throws DataGridConnectionRefusedException, IOException {
    String loggedUser = loggedUserUtils.getLoggedDataGridUser().getUsername();
    String date = new SimpleDateFormat(METADATA_CSV_DATE_FORMAT).format(new Date());
    String filename = String.format(METADATA_CSV_FILENAME_FORMAT, loggedUser, date);
    // Setting CSV Mime type
    response.setContentType("text/csv");
    response.setHeader("Content-disposition", "attachment;filename=" + filename);
    ServletOutputStream outputStream = response.getOutputStream();
    // Building search parameters lines
    outputStream.print("Search condition #;Condition\n");
    ListIterator<DataGridMetadataSearch> resultEnumeration = currSearch.listIterator();
    while (resultEnumeration.hasNext()) {
        String condition = resultEnumeration.next().toString();
        outputStream.print(String.format("%d;%s\n", resultEnumeration.nextIndex() + 1, condition));
    }
    outputStream.print("\n");
    outputStream.flush();
    // Executing query
    DataGridPageContext pageContext = new DataGridPageContext();
    List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = metadataService.findByMetadata(currSearch, 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");
    // Printing results
    outputStream.print(METADATA_CSV_HEADER);
    for (DataGridCollectionAndDataObject obj : dataGridCollectionAndDataObjects) {
        String kind = obj.isCollection() ? "collection" : "data object";
        StringBuilder row = new StringBuilder();
        row.append(obj.getName() + ";");
        row.append(obj.getPath() + ";");
        row.append(obj.getOwner() + ";");
        row.append(kind + ";");
        row.append(obj.getModifiedAtFormattedForCSVReport() + ";");
        row.append(String.valueOf(obj.getSize()) + ";");
        row.append(String.valueOf(obj.getNumberOfMatches()));
        row.append("\n");
        outputStream.print(row.toString());
        outputStream.flush();
    }
}
Also used : DataGridPageContext(com.emc.metalnx.core.domain.entity.DataGridPageContext) DataGridMetadataSearch(com.emc.metalnx.core.domain.entity.DataGridMetadataSearch) ServletOutputStream(javax.servlet.ServletOutputStream) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with DataGridPageContext

use of com.emc.metalnx.core.domain.entity.DataGridPageContext in project metalnx-web by irods-contrib.

the class BrowseController method getPaginatedJSONObjs.

/*
	 * *************************************************************************
	 * ******************************** UTILS **********************************
	 * *************************************************************************
	 */
/**
 * Finds all collections and data objects existing under a certain path
 *
 * @param request
 *            contains all parameters in a map, we can use it to get all
 *            parameters passed in request
 * @return json with collections and data objects
 * @throws DataGridConnectionRefusedException
 * @throws JargonException
 */
@RequestMapping(value = "getPaginatedJSONObjs/")
@ResponseBody
public String getPaginatedJSONObjs(final HttpServletRequest request) throws DataGridConnectionRefusedException, JargonException {
    logger.info("getPaginatedJSONObjs()");
    List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects;
    int draw = Integer.parseInt(request.getParameter("draw"));
    int start = Integer.parseInt(request.getParameter("start"));
    int length = Integer.parseInt(request.getParameter("length"));
    String searchString = request.getParameter("search[value]");
    int orderColumn = Integer.parseInt(request.getParameter("order[0][column]"));
    String orderDir = request.getParameter("order[0][dir]");
    boolean deployRule = request.getParameter("rulesdeployment") != null;
    // Pagination context to get the sequence number for the listed items
    DataGridPageContext pageContext = new DataGridPageContext();
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> jsonResponse = new HashMap<String, Object>();
    jsonResponse.put("draw", String.valueOf(draw));
    jsonResponse.put("recordsTotal", String.valueOf(1));
    jsonResponse.put("recordsFiltered", String.valueOf(0));
    jsonResponse.put("data", new ArrayList<String>());
    String jsonString = "";
    try {
        logger.info("using path of:{}", currentPath);
        String path = currentPath;
        if (deployRule) {
            path = ruleDeploymentService.getRuleCachePath();
        }
        Math.floor(start / length);
        logger.info("getting subcollections under path:{}", path);
        // TODO: temporary add
        dataGridCollectionAndDataObjects = cs.getSubCollectionsAndDataObjectsUnderPath(path);
        // paging service
        logger.debug("dataGridCollectionAndDataObjects:{}", dataGridCollectionAndDataObjects);
        /*
			 * cs.getSubCollectionsAndDataObjectsUnderPathThatMatchSearchTextPaginated(
			 * path, searchString, startPage.intValue(), length, orderColumn, orderDir,
			 * pageContext);
			 */
        totalObjsForCurrentSearch = pageContext.getTotalNumberOfItems();
        totalObjsForCurrentPath = pageContext.getTotalNumberOfItems();
        jsonResponse.put("recordsTotal", String.valueOf(totalObjsForCurrentPath));
        jsonResponse.put("recordsFiltered", String.valueOf(totalObjsForCurrentSearch));
        jsonResponse.put("data", dataGridCollectionAndDataObjects);
    } catch (DataGridConnectionRefusedException e) {
        logger.error("connection refused", e);
        throw e;
    } catch (Exception e) {
        logger.error("Could not get collections/data objs under path {}: {}", currentPath, e.getMessage());
        throw new JargonException("exception getting paginated objects", e);
    }
    try {
        jsonString = mapper.writeValueAsString(jsonResponse);
    } catch (JsonProcessingException e) {
        logger.error("Could not parse hashmap in collections to json: {}", e.getMessage());
        throw new JargonException("exception in json parsing", e);
    }
    return jsonString;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) HashMap(java.util.HashMap) JargonException(org.irods.jargon.core.exception.JargonException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DataGridPageContext(com.emc.metalnx.core.domain.entity.DataGridPageContext) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) IconObject(com.emc.metalnx.core.domain.entity.IconObject) 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)6 DataGridPageContext (com.emc.metalnx.core.domain.entity.DataGridPageContext)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 HashMap (java.util.HashMap)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 DataGridFilePropertySearch (com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch)2 DataGridMetadataSearch (com.emc.metalnx.core.domain.entity.DataGridMetadataSearch)2 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 IOException (java.io.IOException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)2 JargonException (org.irods.jargon.core.exception.JargonException)2 IconObject (com.emc.metalnx.core.domain.entity.IconObject)1 DataGridSearchOperatorEnum (com.emc.metalnx.core.domain.entity.enums.DataGridSearchOperatorEnum)1