Search in sources :

Example 16 with JargonException

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

the class CollectionServiceImpl method getCollectionDataProfile.

@SuppressWarnings("unchecked")
@Override
public DataProfile<IRODSDomainObject> getCollectionDataProfile(String path) throws DataGridException {
    IRODSAccount irodsAccount = irodsServices.getUserAO().getIRODSAccount();
    logger.info("*****************path **************" + path);
    logger.debug("got irodsAccount:{}", irodsAccount);
    DataProfilerService dataProfilerService = dataProfilerFactory.instanceDataProfilerService(irodsAccount);
    logger.debug("got the dataProfilerService");
    // TODO: allow clone()
    try {
        @SuppressWarnings("rawtypes") DataProfile dataProfile = dataProfilerService.retrieveDataProfile(path);
        logger.info("------CollectionInfoController getTestCollectionInfo() ends !!");
        logger.info("data profile retrieved:{}", dataProfile);
        /*
			 * TODO: after this do an if test and send to right view with the DataProfile in
			 * the model
			 */
        return dataProfile;
    } catch (JargonException e) {
        logger.error("Could not retrieve collection/dataobject from path: {}", path, e);
        throw new DataGridException(e.getMessage());
    }
}
Also used : DataProfile(org.irods.jargon.extensions.dataprofiler.DataProfile) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) JargonException(org.irods.jargon.core.exception.JargonException) DataProfilerService(org.irods.jargon.extensions.dataprofiler.DataProfilerService)

Example 17 with JargonException

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

the class CollectionServiceImpl method listDataObjectsUnderPathThatMatchSearchText.

/**
 * Lists all data objects under the given path that match a search term. Any
 * data object where the term appears in the beginning, middle, and the end of
 * its name will be retrieved.
 *
 * @param parentPath
 *            path to the parent collection where you are looking for items that
 *            match a search term
 * @param searchText
 *            term to be matched
 * @param offset
 *            partial start index
 * @param limit
 *            max number of items retrieved
 * @return list of data objects that match the given search text
 * @throws DataGridConnectionRefusedException
 */
private List<DataGridCollectionAndDataObject> listDataObjectsUnderPathThatMatchSearchText(String parentPath, String searchText, int offset, int limit, int orderColumn, String orderDir) throws DataNotFoundException, JargonQueryException, DataGridConnectionRefusedException {
    logger.info("listDataObjectsUnderPathThatMatchSearchText()");
    logger.info("parentPath:{}", parentPath);
    logger.info("searchText:{}", searchText);
    logger.info("offset:{}", offset);
    logger.info("limit:{}", limit);
    logger.info("orderColumn:{}", orderColumn);
    logger.info("orderDir:{}", orderDir);
    SpecificQueryAO specificQueryAO = adminServices.getSpecificQueryAO();
    SpecificQueryDefinition queryDef = null;
    List<CollectionAndDataObjectListingEntry> dataGridList = null;
    List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = null;
    String sqlAlias = null;
    try {
        dataGridCollectionAndDataObjects = new ArrayList<DataGridCollectionAndDataObject>();
        sqlAlias = SQL_LIST_DATA_OBJECTS_MATCHING_SEARCH_TEXT_ALIAS_WITH_ORDERING;
        ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
        SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
        String query = provider.buildSelectDataObjectsUnderPathThatMatchSearchText(parentPath, searchText, offset, limit, orderColumn, orderDir);
        // 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 + "%");
        args.add(String.valueOf(offset));
        args.add(String.valueOf(limit));
        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
        dataGridList = DataGridUtils.mapQueryResultSetToDataGridObjectsForSearch(queryResultSet);
        dataGridCollectionAndDataObjects.addAll(DataGridUtils.mapListingEntryToDataGridCollectionAndDataObject(dataGridList));
    } catch (JargonException | UnsupportedDataGridFeatureException e) {
        logger.error("Could not execute specific query for listing data objects that match 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 dataGridCollectionAndDataObjects;
}
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) CollectionAndDataObjectListingEntry(org.irods.jargon.core.query.CollectionAndDataObjectListingEntry) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) SpecificQueryDefinition(org.irods.jargon.core.pub.domain.SpecificQueryDefinition) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) SpecificQuery(org.irods.jargon.core.query.SpecificQuery)

Example 18 with JargonException

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

the class CollectionServiceImpl method getReplicationNumber.

@Override
public int getReplicationNumber(String path) throws DataGridConnectionRefusedException {
    logger.info("getReplicationNumber()");
    logger.debug("Getting replication number of " + path);
    DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
    DataObject dataObject = null;
    try {
        dataObject = dataObjectAO.findByAbsolutePath(path);
    } catch (JargonException e) {
        logger.error("Could not find a data object matching " + path, e);
    }
    if (dataObject != null) {
        return dataObject.getDataReplicationNumber();
    }
    return 0;
}
Also used : DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataObject(org.irods.jargon.core.pub.domain.DataObject) JargonException(org.irods.jargon.core.exception.JargonException) DataObjectAO(org.irods.jargon.core.pub.DataObjectAO)

Example 19 with JargonException

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

the class CollectionServiceImpl method getTotalCollectionsUnderPathThatMatchSearchText.

/**
 * Calculates the number of collections 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
 * @throws JargonException
 * @throws DuplicateDataException
 * @throws JargonQueryException
 */
private int getTotalCollectionsUnderPathThatMatchSearchText(String parentPath, String searchText) throws DataGridConnectionRefusedException {
    logger.info("getTotalCollectionsUnderPathThatMatchSearchText()");
    SpecificQueryAO specificQueryAO = adminServices.getSpecificQueryAO();
    int totalNumberOfItems = 0;
    SpecificQueryDefinition queryDef = null;
    String sqlQueryAlias = "totalNumberOfCollectionsThatMatchSearchText";
    try {
        sqlQueryAlias = SQL_TOTAL_NUMBER_OF_COLLS_MATCHING_SEARCH_TEXT_ALIAS;
        ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
        SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
        String query = provider.buildSelectTotalCollectionsUnderPathThatMatchSearchText(parentPath, searchText);
        // Creating Specific Query instance
        queryDef = new SpecificQueryDefinition();
        queryDef.setAlias(sqlQueryAlias);
        queryDef.setSql(query);
        // Creating spec query on iRODS
        specificQueryAO.addSpecificQuery(queryDef);
        // Executing specific query
        String zone = irodsServices.getCurrentUserZone();
        List<String> args = new ArrayList<String>();
        String collNameParam = null;
        if (IRODS_PATH_SEPARATOR.equals(parentPath)) {
            collNameParam = String.format("%%%s%%%%%s%%", IRODS_PATH_SEPARATOR, searchText);
        } else {
            collNameParam = String.format("%s%s%%%s%%", parentPath, IRODS_PATH_SEPARATOR, searchText);
        }
        args.add(collNameParam);
        args.add(parentPath);
        SpecificQuery specQuery = SpecificQuery.instanceArguments(sqlQueryAlias, args, 0, zone);
        SpecificQueryResultSet queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, MAX_RESULTS_PER_PAGE, 0);
        totalNumberOfItems = DataGridUtils.mapCountQueryResultSetToInteger(queryResultSet);
    } catch (JargonException | JargonQueryException | UnsupportedDataGridFeatureException e) {
        logger.error("Could not execute specific query to find collections matching a search text. ", e);
    } finally {
        try {
            // after running the user specific query, we need to remove from the database
            specificQueryAO.removeSpecificQueryByAlias(sqlQueryAlias);
        } catch (JargonException e) {
            logger.error("Could not remove specific query {}: ", sqlQueryAlias, 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) JargonQueryException(org.irods.jargon.core.query.JargonQueryException) SpecificQuery(org.irods.jargon.core.query.SpecificQuery)

Example 20 with JargonException

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

the class FileOperationServiceImpl method emptyTrash.

@Override
public boolean emptyTrash(DataGridUser user, String collectionPath) throws DataGridConnectionRefusedException, JargonException {
    logger.info("emptyTrash()");
    if (user == null || collectionPath == null || collectionPath.isEmpty()) {
        return false;
    }
    logger.info("user:{}", user);
    logger.info("collectionPath:{}", collectionPath);
    boolean itemsDeleted = false;
    try {
        TrashOperationsAO trashOperationsAO = irodsServices.getTrashOperationsAO();
        /*
			 * if (user.isAdmin()) { logger.info("delete as admin");
			 * trashOperationsAO.emptyAllTrashAsAdmin(irodsServices.getCurrentUserZone(),
			 * 0); // trashOperationsAO.emptyTrashAtPathAdminMode(collectionPath, "", //
			 * irodsServices.getCurrentUserZone(), 0); itemsDeleted = true; } else {
			 */
        logger.info("delete as user");
        trashOperationsAO.emptyTrashAtPathForLoggedInUser(collectionPath, irodsServices.getCurrentUserZone(), 0);
        itemsDeleted = true;
    /* } */
    } catch (JargonException je) {
        logger.error("jargon exception emptying trash", je);
        throw je;
    }
    return itemsDeleted;
}
Also used : TrashOperationsAO(org.irods.jargon.core.pub.TrashOperationsAO) JargonException(org.irods.jargon.core.exception.JargonException)

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