Search in sources :

Example 1 with FileNotFoundException

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

the class CollectionServiceImpl method getPermissionsForPath.

@Override
public String getPermissionsForPath(String path) throws DataGridConnectionRefusedException {
    logger.info("getPermissionsForPath()");
    FilePermissionEnum filePermissionEnum = null;
    String permissionType = "none";
    try {
        String user = irodsServices.getCurrentUser();
        String zone = irodsServices.getCurrentUserZone();
        Object obj = irodsServices.getCollectionAndDataObjectListAndSearchAO().getFullObjectForType(path);
        if (obj instanceof Collection) {
            CollectionAO collectionAO = irodsServices.getCollectionAO();
            filePermissionEnum = collectionAO.getPermissionForCollection(path, user, zone);
        } else {
            DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
            filePermissionEnum = dataObjectAO.getPermissionForDataObject(path, user, zone);
        }
        if (filePermissionEnum != null) {
            permissionType = filePermissionEnum.toString().toLowerCase();
        }
    } catch (FileNotFoundException e) {
        logger.error("Could not find path: {}", e.getMessage());
    } catch (JargonException e) {
        logger.error("Could not get permission for path: {}", e.getMessage());
    }
    return permissionType;
}
Also used : CollectionAO(org.irods.jargon.core.pub.CollectionAO) JargonException(org.irods.jargon.core.exception.JargonException) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) Collection(org.irods.jargon.core.pub.domain.Collection) IconObject(com.emc.metalnx.core.domain.entity.IconObject) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) IRODSDomainObject(org.irods.jargon.core.pub.domain.IRODSDomainObject) DataObject(org.irods.jargon.core.pub.domain.DataObject) DataObjectAO(org.irods.jargon.core.pub.DataObjectAO) FilePermissionEnum(org.irods.jargon.core.protovalues.FilePermissionEnum)

Example 2 with FileNotFoundException

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

the class CollectionServiceImpl method getInheritanceOptionForCollection.

@Override
public boolean getInheritanceOptionForCollection(String collPath) throws DataGridConnectionRefusedException, JargonException {
    logger.info("getInheritanceOptionForCollection()");
    if (collPath == null || collPath.isEmpty()) {
        throw new IllegalArgumentException("null or empty collPath");
    }
    logger.info("collPath:{}", collPath);
    CollectionAO collectionAO = irodsServices.getCollectionAO();
    try {
        return collectionAO.isCollectionSetForPermissionInheritance(collPath);
    } catch (FileNotFoundException e) {
        logger.warn("Collection {} does not exist: {}", collPath, e.getMessage());
    } catch (JargonException e) {
        logger.error("Could not retrieve inheritance option value for", collPath, e.getMessage());
        throw e;
    }
    return false;
}
Also used : CollectionAO(org.irods.jargon.core.pub.CollectionAO) JargonException(org.irods.jargon.core.exception.JargonException) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException)

Example 3 with FileNotFoundException

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

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

the class BrowseController method getFileInfo.

/**
 * Gets checksum, total number of replicas and where each replica lives in the
 * data grid for a specific data object
 *
 * @param model
 * @param path
 *            path to the data object to get checksum and replica information
 * @return the template that shows the data object information
 * @throws DataGridException
 * @throws FileNotFoundException
 */
@RequestMapping(value = "/info/", method = RequestMethod.POST)
public String getFileInfo(final Model model, final String path) throws DataGridException, FileNotFoundException {
    logger.info("CollectionController getInfoFile() starts :: " + path);
    DataGridCollectionAndDataObject dataGridObj = null;
    Map<DataGridCollectionAndDataObject, DataGridResource> replicasMap = null;
    try {
        dataGridObj = cs.findByName(path);
        if (dataGridObj != null && !dataGridObj.isCollection()) {
            replicasMap = cs.listReplicasByResource(path);
            dataGridObj.setChecksum(cs.getChecksum(path));
            dataGridObj.setNumberOfReplicas(cs.getTotalNumberOfReplsForDataObject(path));
            dataGridObj.setReplicaNumber(String.valueOf(cs.getReplicationNumber(path)));
            permissionsService.resolveMostPermissiveAccessForUser(dataGridObj, loggedUserUtils.getLoggedDataGridUser());
        }
    } catch (DataGridConnectionRefusedException e) {
        logger.error("Could not connect to the data grid", e);
        throw e;
    } catch (DataGridException e) {
        logger.error("Could not get file info for {}", path, e);
        throw e;
    } catch (FileNotFoundException e) {
        logger.error("file does not exist for:{}", path, e);
        throw e;
    }
    model.addAttribute("collectionAndDataObject", dataGridObj);
    model.addAttribute("currentCollection", dataGridObj);
    model.addAttribute("replicasMap", replicasMap);
    model.addAttribute("infoFlag", true);
    logger.info("CollectionController getInfoFile() ends !!");
    return "collections/info :: infoView";
// return "collections/info";
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with FileNotFoundException

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

Aggregations

FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)10 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)8 JargonException (org.irods.jargon.core.exception.JargonException)6 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)3 CollectionAndDataObjectListAndSearchAO (org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO)3 CollectionAndDataObjectListingEntry (org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)3 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)2 CollectionAO (org.irods.jargon.core.pub.CollectionAO)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 DataGridFilePermission (com.emc.metalnx.core.domain.entity.DataGridFilePermission)1 DataGridGroupBookmark (com.emc.metalnx.core.domain.entity.DataGridGroupBookmark)1 DataGridGroupPermission (com.emc.metalnx.core.domain.entity.DataGridGroupPermission)1 DataGridResource (com.emc.metalnx.core.domain.entity.DataGridResource)1 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)1 DataGridUserBookmark (com.emc.metalnx.core.domain.entity.DataGridUserBookmark)1 DataGridUserPermission (com.emc.metalnx.core.domain.entity.DataGridUserPermission)1 IconObject (com.emc.metalnx.core.domain.entity.IconObject)1 CollectionOrDataObjectForm (com.emc.metalnx.modelattribute.collection.CollectionOrDataObjectForm)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1