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();
}
}
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;
}
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;
}
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();
}
}
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;
}
Aggregations