Search in sources :

Example 1 with CollectionOrDataObjectForm

use of com.emc.metalnx.modelattribute.collection.CollectionOrDataObjectForm in project metalnx-web by irods-contrib.

the class BrowseController method getCollBrowserView.

/**
 * Finds all collections and data objects existing under a certain path
 *
 * @param model
 * @param path
 *            path to get all directories and data objects from
 * @return collections browser template that renders all items of certain path
 *         (parent)
 * @throws DataGridConnectionRefusedException
 *             if Metalnx cannot connect to the grid.
 */
private String getCollBrowserView(final Model model, String path) throws JargonException, DataGridException {
    logger.info("getCollBrowserView()");
    logger.info("model:{}", model);
    logger.info("path:{}", path);
    logger.info("find collection by name:{}", path);
    DataGridCollectionAndDataObject dataGridObj = null;
    try {
        dataGridObj = cs.findByName(path);
    } catch (FileNotFoundException fnf) {
        logger.warn("file not found for:{}", path);
        // I don't have a path so use the user home
        logger.info("no path, so using user home directory");
        // TODO: refactor into something more elegant - mcc
        model.addAttribute("invalidPath", path);
        IRODSAccount irodsAccount = irodsServices.getCollectionAO().getIRODSAccount();
        path = MiscIRODSUtils.buildIRODSUserHomeForAccountUsingDefaultScheme(irodsAccount);
    }
    if (path.endsWith("/") && path.compareTo("/") != 0) {
        path = path.substring(0, path.length() - 1);
    }
    currentPath = path;
    logger.info("currentPath:{}", currentPath);
    DataGridUser user = loggedUserUtils.getLoggedDataGridUser();
    if (zoneTrashPath == null || zoneTrashPath.isEmpty()) {
        zoneTrashPath = String.format("/%s/trash", irodsServices.getCurrentUserZone());
    }
    // TODO: do I really need these permission path checks? I can let iRODS worry
    // about permissions - mcc
    CollectionOrDataObjectForm collectionForm = new CollectionOrDataObjectForm();
    String permissionType = "none";
    if (dataGridObj.isProxy()) {
        logger.info("this is a proxy, so fake out the options");
        collectionForm.setInheritOption(false);
        permissionType = "read";
    } else {
        logger.info("this is not a proxy, so gather permission info");
        permissionType = cs.getPermissionsForPath(path);
        collectionForm.setInheritOption(cs.getInheritanceOptionForCollection(currentPath));
        permissionsService.resolveMostPermissiveAccessForUser(dataGridObj, user);
    }
    logger.debug("permission options are set");
    boolean isPermissionOwn = "own".equals(permissionType);
    boolean isTrash = path.contains(zoneTrashPath) && (isPermissionOwn || user.isAdmin());
    boolean inheritanceDisabled = !isPermissionOwn && collectionForm.getInheritOption();
    model.addAttribute("collectionAndDataObject", dataGridObj);
    model.addAttribute("isTrash", isTrash);
    model.addAttribute("permissionType", permissionType);
    model.addAttribute("currentPath", currentPath);
    model.addAttribute("encodedCurrentPath", URLEncoder.encode(currentPath));
    model.addAttribute("isCurrentPathCollection", cs.isCollection(path));
    model.addAttribute("user", user);
    model.addAttribute("trashColl", cs.getTrashForPath(currentPath));
    model.addAttribute("collection", collectionForm);
    model.addAttribute("inheritanceDisabled", inheritanceDisabled);
    model.addAttribute("requestMapping", "/browse/add/action/");
    model.addAttribute("parentPath", parentPath);
    setBreadcrumbToModel(model, dataGridObj);
    logger.info("forwarding to collections/collectionsBrowser");
    return "collections/collectionsBrowser";
}
Also used : IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) CollectionOrDataObjectForm(com.emc.metalnx.modelattribute.collection.CollectionOrDataObjectForm)

Example 2 with CollectionOrDataObjectForm

use of com.emc.metalnx.modelattribute.collection.CollectionOrDataObjectForm in project metalnx-web by irods-contrib.

the class FileOperationsController method showModifyForm.

/**
 * Displays the modify user form with all fields set to the selected collection
 *
 * @param model
 *            MVC model
 * @return collectionForm with fields set
 * @throws DataGridException
 *             if item cannot be modified
 * @throws JargonException
 */
@RequestMapping(value = "modify/", method = RequestMethod.GET)
public String showModifyForm(final Model model, @RequestParam("path") final String path) throws DataGridException, JargonException {
    String currentPath = browseController.getCurrentPath();
    String parentPath = browseController.getParentPath();
    String formType = "editDataObjectForm";
    CollectionOrDataObjectForm targetForm = new CollectionOrDataObjectForm();
    DataGridCollectionAndDataObject dataGridCollectionAndDataObject = collectionService.findByName(path);
    logger.info("Modify form for {}", path);
    targetForm.setCollectionName(dataGridCollectionAndDataObject.getName());
    targetForm.setPath(dataGridCollectionAndDataObject.getPath());
    targetForm.setParentPath(currentPath);
    if (dataGridCollectionAndDataObject.isCollection()) {
        formType = "editCollectionForm";
        targetForm.setCollection(true);
        logger.info("Setting inheritance for {}", path);
        targetForm.setInheritOption(collectionService.getInheritanceOptionForCollection(targetForm.getPath()));
    }
    model.addAttribute("currentPath", currentPath);
    model.addAttribute("parentPath", parentPath);
    model.addAttribute("collection", targetForm);
    model.addAttribute("requestMapping", "/browse/modify/action/");
    return String.format("collections/%s", formType);
}
Also used : DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) CollectionOrDataObjectForm(com.emc.metalnx.modelattribute.collection.CollectionOrDataObjectForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)2 CollectionOrDataObjectForm (com.emc.metalnx.modelattribute.collection.CollectionOrDataObjectForm)2 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)1 IRODSAccount (org.irods.jargon.core.connection.IRODSAccount)1 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1