Search in sources :

Example 21 with DataGridCollectionAndDataObject

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;
}
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 22 with DataGridCollectionAndDataObject

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";
}
Also used : DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataGridMetadata(com.emc.metalnx.core.domain.entity.DataGridMetadata) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with DataGridCollectionAndDataObject

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();
    }
}
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 24 with DataGridCollectionAndDataObject

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";
}
Also used : DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) ArrayList(java.util.ArrayList) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with DataGridCollectionAndDataObject

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;
}
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)55 JargonException (org.irods.jargon.core.exception.JargonException)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Before (org.junit.Before)11 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)9 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)9 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)7 ArrayList (java.util.ArrayList)7 CollectionAndDataObjectListingEntry (org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)7 DataGridPageContext (com.emc.metalnx.core.domain.entity.DataGridPageContext)6 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)6 DataGridMetadata (com.emc.metalnx.core.domain.entity.DataGridMetadata)5 CollectionAndDataObjectListAndSearchAO (org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO)5 Date (java.util.Date)4 HashMap (java.util.HashMap)4 JargonQueryException (org.irods.jargon.core.query.JargonQueryException)4 DataGridResource (com.emc.metalnx.core.domain.entity.DataGridResource)3 UnsupportedDataGridFeatureException (com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3