use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject 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.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.
the class MetadataController method getMetadata.
@RequestMapping(value = "/getMetadata/", method = RequestMethod.POST)
public String getMetadata(final Model model, final String path) throws DataGridConnectionRefusedException, FileNotFoundException {
logger.info("MetadataController getMetadata() starts !!");
List<DataGridMetadata> metadataList = metadataService.findMetadataValuesByPath(path);
DataGridCollectionAndDataObject dgColObj = null;
try {
dgColObj = collectionService.findByName(path);
permissionsService.resolveMostPermissiveAccessForUser(dgColObj, loggedUserUtils.getLoggedDataGridUser());
} catch (DataGridException e) {
logger.error("Could not retrieve collection/dataobject from path: {}", path);
}
model.addAttribute("permissionOnCurrentPath", collectionService.getPermissionsForPath(path));
model.addAttribute("dataGridMetadataList", metadataList);
model.addAttribute("currentPath", path);
model.addAttribute("collectionAndDataObject", dgColObj);
model.addAttribute("metadataFlag", true);
logger.info("MetadataController getMetadata() ends !!");
return "metadata/metadataTable :: metadataTable";
}
use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject 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.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.
the class BrowseController method getDirectoriesAndFilesForGroupForm.
/**
* Finds all collections and files existing under a certain path for a given
* group name.
*
* @param model
* @param path
* start point to get collections and files
* @param groupName
* group that all collections and files permissions will be listed
* @return
* @throws DataGridConnectionRefusedException
* @throws JargonException
* @throws FileNotFoundException
*/
@RequestMapping(value = "/getDirectoriesAndFilesForGroupForm")
public String getDirectoriesAndFilesForGroupForm(final Model model, @RequestParam("path") String path, @RequestParam("groupName") final String groupName, @RequestParam("retrievePermissions") final boolean retrievePermissions) throws DataGridConnectionRefusedException, FileNotFoundException, JargonException {
if (path == null || path == "") {
path = "/";
}
List<DataGridCollectionAndDataObject> list = null;
list = cs.getSubCollectionsAndDataObjectsUnderPath(path);
Set<String> readPermissions = null;
Set<String> writePermissions = null;
Set<String> ownershipPermissions = null;
Set<String> inheritPermissions = null;
if (retrievePermissions) {
readPermissions = cs.listReadPermissionsForPathAndGroup(path, groupName);
writePermissions = cs.listWritePermissionsForPathAndGroup(path, groupName);
ownershipPermissions = cs.listOwnershipForPathAndGroup(path, groupName);
inheritPermissions = cs.listInheritanceForPath(path);
} else {
readPermissions = new HashSet<String>();
writePermissions = new HashSet<String>();
ownershipPermissions = new HashSet<String>();
inheritPermissions = new HashSet<String>();
}
List<String> groupBookmarks = new ArrayList<String>();
if (groupName.length() > 0) {
DataGridGroup group = groupService.findByGroupname(groupName).get(0);
groupBookmarks = groupBookmarkService.findBookmarksForGroupAsString(group);
}
model.addAttribute("dataGridCollectionAndDataObjectList", list);
model.addAttribute("currentPath", path);
model.addAttribute("encodedCurrentPath", URLEncoder.encode(currentPath));
model.addAttribute("readPermissions", readPermissions);
model.addAttribute("writePermissions", writePermissions);
model.addAttribute("ownershipPermissions", ownershipPermissions);
model.addAttribute("inheritPermissions", inheritPermissions);
model.addAttribute("addBookmark", groupBookmarkController.getAddBookmark());
model.addAttribute("removeBookmark", groupBookmarkController.getRemoveBookmark());
model.addAttribute("groupBookmarks", groupBookmarks);
return "collections/treeViewForGroupForm :: treeView";
}
use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject 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