Search in sources :

Example 71 with JargonException

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

the class FileOperationServiceImpl method copyFileIntoHttpResponse.

/**
 * Copies a buffered input stream from a file to a HTTP response for
 * downloading.
 *
 * @param path
 *            path to the file in iRODS to be added to the HTTP response
 * @param response
 *            HTTP response to let the user download the file
 * @return True, if the file was successfully added to the HTTP response. False,
 *         otherwise.
 * @throws DataGridConnectionRefusedException
 *             is Metalnx cannot connect to the data grid
 */
private boolean copyFileIntoHttpResponse(String path, HttpServletResponse response) throws DataGridConnectionRefusedException {
    boolean isCopySuccessFul = true;
    IRODSFileInputStream irodsFileInputStream = null;
    IRODSFile irodsFile = null;
    logger.debug("Trying to copy path stream {} to user", path);
    try {
        String fileName = path.substring(path.lastIndexOf("/") + 1, path.length());
        logger.debug("The filename is [{}]", fileName);
        logger.debug("Initiating iRodsFileFactory");
        IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
        logger.debug("Getting iRodsFileFactory instance for {}", path);
        irodsFile = irodsFileFactory.instanceIRODSFile(path);
        logger.debug("Creating stream from {}", irodsFile);
        irodsFileInputStream = irodsFileFactory.instanceIRODSFileInputStream(irodsFile);
        // set file mime type
        response.setContentType(CONTENT_TYPE);
        response.setHeader("Content-Disposition", String.format(HEADER_FORMAT, fileName));
        response.setContentLength((int) irodsFile.length());
        FileCopyUtils.copy(irodsFileInputStream, response.getOutputStream());
    } catch (IOException e) {
        logger.error("Could not put the file in the Http response ", e);
        isCopySuccessFul = false;
    } catch (JargonException e) {
        logger.error("Could not copy file in the Http response: ", e.getMessage());
        isCopySuccessFul = false;
    } finally {
        try {
            if (irodsFileInputStream != null)
                irodsFileInputStream.close();
            if (irodsFile != null)
                irodsFile.close();
        } catch (Exception e) {
            logger.error("Could not close stream(s): ", e.getMessage());
        }
    }
    return isCopySuccessFul;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) IRODSFileInputStream(org.irods.jargon.core.pub.io.IRODSFileInputStream) JargonException(org.irods.jargon.core.exception.JargonException) IOException(java.io.IOException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) DataGridChecksumException(com.emc.metalnx.core.domain.exceptions.DataGridChecksumException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataNotFoundException(org.irods.jargon.core.exception.DataNotFoundException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridReplicateException(com.emc.metalnx.core.domain.exceptions.DataGridReplicateException) DataGridRuleException(com.emc.metalnx.core.domain.exceptions.DataGridRuleException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) IOException(java.io.IOException)

Example 72 with JargonException

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

the class FileOperationServiceImpl method deleteDataObject.

@Override
public boolean deleteDataObject(String dataObjectPath, boolean forceFlag) throws DataGridException {
    boolean dataObjDeleted = false;
    try {
        IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
        IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
        IRODSFile fileToBeRemoved = irodsFileFactory.instanceIRODSFile(dataObjectPath);
        if (forceFlag) {
            irodsFileSystemAO.fileDeleteForce(fileToBeRemoved);
        } else {
            irodsFileSystemAO.fileDeleteNoForce(fileToBeRemoved);
        }
        dataObjDeleted = true;
    } catch (JargonException e) {
        logger.error("Could not delete data object: {}", e.getMessage());
    }
    return dataObjDeleted;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) JargonException(org.irods.jargon.core.exception.JargonException) IRODSFileSystemAO(org.irods.jargon.core.pub.IRODSFileSystemAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Example 73 with JargonException

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

the class GroupServiceImpl method deleteGroupByGroupname.

@Override
public boolean deleteGroupByGroupname(String groupname) throws DataGridConnectionRefusedException {
    boolean groupDeleted = false;
    UserGroupAO groupAO = irodsServices.getGroupAO();
    try {
        DataGridGroup group = groupDao.findByGroupnameAndZone(groupname, configService.getIrodsZone());
        // remove group from the data grid
        groupAO.removeUserGroup(groupname);
        // Removing group bookmarks associated to this group
        userBookmarkService.removeBookmarkBasedOnPath(String.format("/%s/home/%s", configService.getIrodsZone(), groupname));
        groupBookmarkService.removeBookmarkBasedOnGroup(group);
        // remove user from the Mlx database
        groupDeleted = groupDao.deleteByGroupname(groupname);
    } catch (JargonException e) {
        logger.error("Could not execute removeUserGroup(String groupname)/" + "deleteByGroupname(groupname) on UserGroupAO/GroupDao class(es): ", e);
    } catch (Exception e) {
        logger.error("Could not execute delete group (dao)");
    }
    return groupDeleted;
}
Also used : JargonException(org.irods.jargon.core.exception.JargonException) UserGroupAO(org.irods.jargon.core.pub.UserGroupAO) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DuplicateDataException(org.irods.jargon.core.exception.DuplicateDataException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException)

Example 74 with JargonException

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

the class GroupServiceImpl method updateWritePermissions.

@Override
public boolean updateWritePermissions(DataGridGroup group, Map<String, Boolean> addCollectionsToWrite, Map<String, Boolean> removeCollectionsToWrite) throws DataGridConnectionRefusedException {
    DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
    CollectionAO collectionAO = irodsServices.getCollectionAO();
    try {
        for (String path : addCollectionsToWrite.keySet()) {
            if (collectionService.isCollection(path)) {
                collectionAO.setAccessPermissionWriteAsAdmin(group.getAdditionalInfo(), path, group.getGroupname(), addCollectionsToWrite.get(path));
            } else {
                dataObjectAO.setAccessPermissionWriteInAdminMode(group.getAdditionalInfo(), path, group.getGroupname());
            }
        }
        for (String path : removeCollectionsToWrite.keySet()) {
            if (collectionService.isCollection(path)) {
                collectionAO.removeAccessPermissionForUserAsAdmin(group.getAdditionalInfo(), path, group.getGroupname(), removeCollectionsToWrite.get(path));
            } else {
                dataObjectAO.removeAccessPermissionsForUserInAdminMode(group.getAdditionalInfo(), path, group.getGroupname());
            }
        }
        return true;
    } catch (JargonException | DataGridException e) {
        logger.error("Could not set read permission:", e);
    }
    return false;
}
Also used : CollectionAO(org.irods.jargon.core.pub.CollectionAO) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) JargonException(org.irods.jargon.core.exception.JargonException) DataObjectAO(org.irods.jargon.core.pub.DataObjectAO)

Example 75 with JargonException

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

the class GroupServiceImpl method createGroup.

@Override
public boolean createGroup(DataGridGroup newGroup, List<DataGridUser> usersToBeAttached) throws DataGridConnectionRefusedException {
    UserGroupAO groupAO = irodsServices.getGroupAO();
    // Translating to iRODS model format
    UserGroup irodsGroup = new UserGroup();
    irodsGroup.setUserGroupName(newGroup.getGroupname());
    irodsGroup.setZone(newGroup.getAdditionalInfo());
    try {
        irodsGroup.setUserGroupName(newGroup.getGroupname());
        irodsGroup.setZone(newGroup.getAdditionalInfo());
        // creating group in iRODS
        groupAO.addUserGroup(irodsGroup);
        // Recovering the recently created group to get the data grid id.
        irodsGroup = groupAO.findByName(irodsGroup.getUserGroupName());
        newGroup.setDataGridId(Long.parseLong(irodsGroup.getUserGroupId()));
        // Persisting the new group into our database
        groupDao.save(newGroup);
        // attaching users to this group
        updateMemberList(newGroup, usersToBeAttached);
        return true;
    } catch (DuplicateDataException e) {
        logger.error("UserGroup " + newGroup.getGroupname() + " already exists: ", e);
    } catch (JargonException e) {
        logger.error("Could not execute createGroup() on UserGroupAO class: ", e);
    }
    return false;
}
Also used : DuplicateDataException(org.irods.jargon.core.exception.DuplicateDataException) JargonException(org.irods.jargon.core.exception.JargonException) UserGroupAO(org.irods.jargon.core.pub.UserGroupAO) UserGroup(org.irods.jargon.core.pub.domain.UserGroup)

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