Search in sources :

Example 41 with JargonException

use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.

the class PermissionsController method getPermissionDetails.

/**
 * Gives permission details related to a collection or file that is passed as a
 * parameter
 *
 * @param model
 * @param path
 * @return
 * @throws DataGridConnectionRefusedException
 * @throws JargonException
 * @throws FileNotFoundException
 */
@RequestMapping(value = "/getPermissionDetails/", method = RequestMethod.POST)
public String getPermissionDetails(final Model model, @RequestParam("path") final String path) throws DataGridConnectionRefusedException {
    logger.debug("Getting permission info for {}", path);
    DataGridCollectionAndDataObject obj = null;
    List<DataGridFilePermission> permissions;
    List<DataGridGroupPermission> groupPermissions;
    List<DataGridUserPermission> userPermissions;
    List<DataGridGroupBookmark> bookmarks;
    List<DataGridUserBookmark> userBookmarks;
    Set<String> groupsWithBookmarks;
    Set<String> usersWithBookmarks;
    boolean userCanModify = false;
    boolean isCollection = false;
    try {
        loggedUser = luu.getLoggedDataGridUser();
        permissions = ps.getPathPermissionDetails(path);
        groupPermissions = ps.getGroupsWithPermissions(permissions);
        userPermissions = ps.getUsersWithPermissions(permissions);
        bookmarks = gBMS.findBookmarksOnPath(path);
        userBookmarks = uBMS.findBookmarksOnPath(path);
        userCanModify = loggedUser.isAdmin() || ps.canLoggedUserModifyPermissionOnPath(path);
        groupsWithBookmarks = new HashSet<>();
        for (DataGridGroupBookmark bookmark : bookmarks) {
            groupsWithBookmarks.add(bookmark.getGroup().getGroupname());
        }
        usersWithBookmarks = new HashSet<>();
        for (DataGridUserBookmark userBookmark : userBookmarks) {
            usersWithBookmarks.add(userBookmark.getUser().getUsername());
        }
        obj = cs.findByName(path);
        ps.resolveMostPermissiveAccessForUser(obj, loggedUser);
    } catch (Exception e) {
        logger.error("Could not get permission details {}: {}", path, e.getMessage());
        groupPermissions = new ArrayList<>();
        userPermissions = new ArrayList<>();
        groupsWithBookmarks = new HashSet<>();
        usersWithBookmarks = new HashSet<>();
    }
    model.addAttribute("usersWithBookmarks", usersWithBookmarks);
    model.addAttribute("groupsWithBookmark", groupsWithBookmarks);
    model.addAttribute("groupPermissions", groupPermissions);
    model.addAttribute("userPermissions", userPermissions);
    model.addAttribute("userCanModify", userCanModify);
    model.addAttribute("permissions", PERMISSIONS);
    model.addAttribute("permissionsWithoutNone", PERMISSIONS_WITHOUT_NONE);
    model.addAttribute("collectionAndDataObject", obj);
    model.addAttribute("isCollection", isCollection);
    model.addAttribute("permissionOnCurrentPath", cs.getPermissionsForPath(path));
    model.addAttribute("permissionFlag", true);
    System.out.println("permissionOnCurrentPath =======" + cs.getPermissionsForPath(path));
    System.out.println("------Permission Conroller - /getPermissionDetail/ ends------");
    return "permissions/permissionDetails :: permissionDetails";
}
Also used : DataGridGroupPermission(com.emc.metalnx.core.domain.entity.DataGridGroupPermission) DataGridUserPermission(com.emc.metalnx.core.domain.entity.DataGridUserPermission) DataGridGroupBookmark(com.emc.metalnx.core.domain.entity.DataGridGroupBookmark) ArrayList(java.util.ArrayList) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridUserBookmark(com.emc.metalnx.core.domain.entity.DataGridUserBookmark) DataGridFilePermission(com.emc.metalnx.core.domain.entity.DataGridFilePermission) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with JargonException

use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.

the class CollectionController method indexViaUrl.

/**
 * Responds the collections/ request
 *
 * @param model
 * @return the collection management template
 * @throws JargonException
 * @throws DataGridException
 */
@RequestMapping(method = RequestMethod.GET)
public String indexViaUrl(final Model model, final HttpServletRequest request, @RequestParam("path") final Optional<String> path, @ModelAttribute("requestHeader") String requestHeader) {
    logger.info("indexViaUrl()");
    String myPath = path.orElse("");
    logger.info("dp Header requestHeader is :: " + requestHeader);
    try {
        if (myPath.isEmpty()) {
            model.addAttribute("topnavHeader", headerService.getheader("collections"));
            logger.info("no path, go to home dir");
            myPath = cs.getHomeDirectyForCurrentUser();
        } else {
            logger.info("path provided...go to:{}", path);
            // TODO: do I need to worry about decoding, versus configure
            myPath = URLDecoder.decode(myPath);
        // in filter? - MCC
        // see
        // https://stackoverflow.com/questions/25944964/where-and-how-to-decode-pathvariable
        }
        logger.info("myPath:{}" + myPath);
        DataGridUser loggedUser = loggedUserUtils.getLoggedDataGridUser();
        String uiMode = (String) request.getSession().getAttribute("uiMode");
        sourcePaths = MiscIRODSUtils.breakIRODSPathIntoComponents(myPath);
        CollectionAndPath collectionAndPath = MiscIRODSUtils.separateCollectionAndPathFromGivenAbsolutePath(myPath);
        this.parentPath = collectionAndPath.getCollectionParent();
        this.currentPath = myPath;
        if (uiMode == null || uiMode.isEmpty()) {
            boolean isUserAdmin = loggedUser != null && loggedUser.isAdmin();
            uiMode = isUserAdmin ? UI_ADMIN_MODE : UI_USER_MODE;
        }
        if (cs.isDataObject(myPath)) {
            logger.info("redirect to info page");
            StringBuilder sb = new StringBuilder();
            sb.append("redirect:/collectionInfo?path=");
            sb.append(URLEncoder.encode(myPath));
            return sb.toString();
        }
        logger.info("is collection...continue to collection management");
        if (uiMode.equals(UI_USER_MODE)) {
            model.addAttribute("homePath", cs.getHomeDirectyForCurrentUser());
            model.addAttribute("publicPath", cs.getHomeDirectyForPublic());
        }
        model.addAttribute("uiMode", uiMode);
        model.addAttribute("currentPath", currentPath);
        model.addAttribute("encodedCurrentPath", URLEncoder.encode(currentPath));
        model.addAttribute("parentPath", parentPath);
        model.addAttribute("resources", resourceService.findAll());
        model.addAttribute("overwriteFileOption", loggedUser != null && loggedUser.isForceFileOverwriting());
    } catch (JargonException | DataGridException e) {
        logger.error("error establishing collection location", e);
        model.addAttribute("unexpectedError", true);
    }
    logger.info("displaying collections/collectionManagement");
    return "collections/collectionManagement";
}
Also used : DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) JargonException(org.irods.jargon.core.exception.JargonException) CollectionAndPath(org.irods.jargon.core.utils.CollectionAndPath) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 43 with JargonException

use of org.irods.jargon.core.exception.JargonException 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 44 with JargonException

use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.

the class CollectionInfoController method extractFilePath.

private String extractFilePath(HttpServletRequest request) throws JargonException {
    String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    try {
        path = URLDecoder.decode(path, this.getIrodsServices().getIrodsAccessObjectFactory().getJargonProperties().getEncoding());
    } catch (UnsupportedEncodingException | JargonException e) {
        logger.error("unable to decode path", e);
        throw new JargonException(e);
    }
    String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
    AntPathMatcher apm = new AntPathMatcher();
    return apm.extractPathWithinPattern(bestMatchPattern, path);
}
Also used : JargonException(org.irods.jargon.core.exception.JargonException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AntPathMatcher(org.springframework.util.AntPathMatcher)

Example 45 with JargonException

use of org.irods.jargon.core.exception.JargonException 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

JargonException (org.irods.jargon.core.exception.JargonException)86 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)20 CollectionAO (org.irods.jargon.core.pub.CollectionAO)20 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)18 DataObjectAO (org.irods.jargon.core.pub.DataObjectAO)18 IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)17 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)15 ArrayList (java.util.ArrayList)12 SpecificQueryAO (org.irods.jargon.core.pub.SpecificQueryAO)12 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)11 CollectionAndDataObjectListAndSearchAO (org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO)10 SpecificQueryDefinition (org.irods.jargon.core.pub.domain.SpecificQueryDefinition)10 SpecificQueryResultSet (org.irods.jargon.core.query.SpecificQueryResultSet)9 UnsupportedDataGridFeatureException (com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException)8 SpecificQueryProvider (com.emc.metalnx.services.irods.utils.SpecificQueryProvider)8 ClientHints (org.irods.jargon.core.pub.domain.ClientHints)8 DataObject (org.irods.jargon.core.pub.domain.DataObject)8 CollectionAndDataObjectListingEntry (org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)8 SpecificQuery (org.irods.jargon.core.query.SpecificQuery)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8