Search in sources :

Example 1 with CollectionAndPath

use of org.irods.jargon.core.utils.CollectionAndPath 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)

Aggregations

DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)1 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)1 JargonException (org.irods.jargon.core.exception.JargonException)1 CollectionAndPath (org.irods.jargon.core.utils.CollectionAndPath)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1