Search in sources :

Example 66 with JargonException

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

the class CollectionServiceImpl method createCollection.

@Override
public boolean createCollection(DataGridCollectionAndDataObject collection) throws DataGridException {
    logger.info("createCollection()");
    boolean collCreated;
    try {
        IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
        IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
        IRODSFile newFile = irodsFileFactory.instanceIRODSFile(collection.getParentPath(), collection.getName());
        irodsFileSystemAO.mkdir(newFile, false);
        // Updating inheritance option on the collection, if needed
        CollectionAO collectionAO = irodsServices.getCollectionAO();
        String zoneName = irodsFileSystemAO.getIRODSServerProperties().getRodsZone();
        // enable inheritance for this collection
        if (collection.isInheritanceOption()) {
            collectionAO.setAccessPermissionInherit(zoneName, collection.getPath(), false);
        } else // disable inheritance for this collection
        if ("own".equals(getPermissionsForPath(collection.getParentPath()))) {
            collectionAO.setAccessPermissionToNotInherit(zoneName, collection.getPath(), false);
        }
        collCreated = true;
    } catch (JargonException e) {
        logger.debug("Could not create a collection in the data grid: {}", e.getMessage());
        throw new DataGridException(e.getMessage());
    }
    return collCreated;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) CollectionAO(org.irods.jargon.core.pub.CollectionAO) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) JargonException(org.irods.jargon.core.exception.JargonException) IRODSFileSystemAO(org.irods.jargon.core.pub.IRODSFileSystemAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Example 67 with JargonException

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

the class CollectionServiceImpl method updateInheritanceOptions.

@Override
public boolean updateInheritanceOptions(Map<String, Boolean> toAdd, Map<String, Boolean> toRemove, String zoneName) throws DataGridConnectionRefusedException {
    logger.info("updateInheritanceOptions()");
    CollectionAO collectionAO = irodsServices.getCollectionAO();
    try {
        for (String addColl : toAdd.keySet()) {
            collectionAO.setAccessPermissionInheritAsAdmin(zoneName, addColl, toAdd.get(addColl));
        }
        for (String removeColl : toRemove.keySet()) {
            collectionAO.setAccessPermissionToNotInheritInAdminMode(zoneName, removeColl, toRemove.get(removeColl));
        }
        return true;
    } catch (JargonException e) {
        logger.error("Could not set inheritance: ", e);
    }
    return false;
}
Also used : CollectionAO(org.irods.jargon.core.pub.CollectionAO) JargonException(org.irods.jargon.core.exception.JargonException)

Example 68 with JargonException

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

the class CollectionServiceImpl method getTotalDataObjectsUnderPathThatMatchSearchText.

/**
 * Calculates the number of data objects that match the given search term.
 *
 * @param parentPath
 *            path to the parent collection where you are looking for items that
 *            match a search term
 * @param searchText
 *            term to be matched
 * @return total number of collections matching the given search text
 * @throws DataGridConnectionRefusedException
 */
private int getTotalDataObjectsUnderPathThatMatchSearchText(String parentPath, String searchText) throws DataNotFoundException, JargonQueryException, DataGridConnectionRefusedException {
    logger.info("getTotalCollectionsUnderPathThatMatchSearchText()");
    logger.info("parentPath:{}", parentPath);
    logger.info("searchText:{}", searchText);
    SpecificQueryAO specificQueryAO = adminServices.getSpecificQueryAO();
    SpecificQueryDefinition queryDef = null;
    String sqlAlias = null;
    int totalNumberOfItems = 0;
    try {
        sqlAlias = SQL_TOTAL_NUMBER_OF_DATA_OBJECTS_MATCHING_SEARCH_TEXT_ALIAS;
        ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
        SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
        String query = provider.buildSelectTotalDataObjectsUnderPathThatMatchSearchText(parentPath, searchText);
        // Creating Specific Query instance
        queryDef = new SpecificQueryDefinition();
        queryDef.setAlias(sqlAlias);
        queryDef.setSql(query.toString());
        // Creating spec query on iRODS
        specificQueryAO.addSpecificQuery(queryDef);
        // Executing specific query
        String zone = irodsServices.getCurrentUserZone();
        List<String> args = new ArrayList<String>();
        args.add(parentPath);
        args.add("%" + searchText + "%");
        SpecificQuery specQuery = SpecificQuery.instanceArguments(sqlAlias, args, 0, zone);
        SpecificQueryResultSet queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, MAX_RESULTS_PER_PAGE, 0);
        // Mapping spec query results to DataGrid* objects
        totalNumberOfItems = DataGridUtils.mapCountQueryResultSetToInteger(queryResultSet);
    } catch (JargonException | UnsupportedDataGridFeatureException e) {
        logger.error("Could not execute specific query to get the total number of data objects matching a search text.", e);
    } finally {
        try {
            // after running the user specific query, we need to remove from the database
            specificQueryAO.removeSpecificQueryByAlias(sqlAlias);
        } catch (JargonException e) {
            logger.error("Could not remove specific query {}: ", sqlAlias, e.getMessage());
        }
    }
    return totalNumberOfItems;
}
Also used : UnsupportedDataGridFeatureException(com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException) SpecificQueryProvider(com.emc.metalnx.services.irods.utils.SpecificQueryProvider) JargonException(org.irods.jargon.core.exception.JargonException) ClientHints(org.irods.jargon.core.pub.domain.ClientHints) ArrayList(java.util.ArrayList) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) SpecificQueryDefinition(org.irods.jargon.core.pub.domain.SpecificQueryDefinition) SpecificQuery(org.irods.jargon.core.query.SpecificQuery)

Example 69 with JargonException

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

the class FileOperationServiceImpl method deleteItem.

@Override
public boolean deleteItem(String path, boolean force) throws DataGridConnectionRefusedException {
    if (path == null || path.isEmpty())
        return false;
    IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
    IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
    boolean itemDeleted = false;
    try {
        IRODSFile itemToBeRemoved = irodsFileFactory.instanceIRODSFile(path);
        if (irodsFileSystemAO.isDirectory(itemToBeRemoved)) {
            // if force set to true, we do an irm -rf
            if (force) {
                logger.info("Deleting directory (force) {}", path);
                irodsFileSystemAO.directoryDeleteForce(itemToBeRemoved);
            } else // irm
            {
                logger.info("Deleting directory {}", path);
                irodsFileSystemAO.directoryDeleteNoForce(itemToBeRemoved);
            }
        } else {
            // if force set to false, we do an irm
            if (force) {
                logger.info("Deleting data obj (force) {}", path);
                irodsFileSystemAO.fileDeleteForce(itemToBeRemoved);
            } else // irm
            {
                logger.info("Deleting data obj {}", path);
                irodsFileSystemAO.fileDeleteNoForce(itemToBeRemoved);
            }
        }
        itemDeleted = true;
        // item deleted, we need to delete any bookmarks related to it
        userBookmarkService.removeBookmarkBasedOnPath(path);
        userBookmarkService.removeBookmarkBasedOnRelativePath(path);
        groupBookmarkService.removeBookmarkBasedOnPath(path);
        groupBookmarkService.removeBookmarkBasedOnRelativePath(path);
        favoritesService.removeFavoriteBasedOnPath(path);
        favoritesService.removeFavoriteBasedOnRelativePath(path);
    } catch (JargonException e) {
        logger.error("Could not delete item " + path + ": ", e);
    }
    return itemDeleted;
}
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 70 with JargonException

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

the class FileOperationServiceImpl method deleteCollection.

@Override
public boolean deleteCollection(String collectionPath, boolean forceFlag) throws DataGridException {
    IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
    IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
    try {
        IRODSFile collectionToBeRemoved = irodsFileFactory.instanceIRODSFile(collectionPath);
        if (forceFlag) {
            irodsFileSystemAO.directoryDeleteForce(collectionToBeRemoved);
        } else {
            irodsFileSystemAO.directoryDeleteNoForce(collectionToBeRemoved);
        }
        return true;
    } catch (JargonException e) {
        logger.error("Could not delete collection: ", e.getMessage());
    }
    return false;
}
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)

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