Search in sources :

Example 36 with DataGridCollectionAndDataObject

use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.

the class RuleServiceImpl method execManifestFileRule.

@Override
public void execManifestFileRule(String host, String targetPath, String objPath, String filePath) throws DataGridRuleException, DataGridConnectionRefusedException, FileNotFoundException, JargonException {
    if (!DataGridCoreUtils.isPrideXMLManifestFile(objPath))
        return;
    logger.info("Get Manifest Rule called");
    DataGridRule rule = new DataGridRule(DataGridRule.XML_MANIFEST_RULE, host);
    List<DataGridCollectionAndDataObject> objs = cs.getSubCollectionsAndDataObjectsUnderPath(targetPath);
    for (DataGridCollectionAndDataObject obj : objs) {
        logger.info("Extracting metadata from [{}] and applying on [{}]", filePath, obj.getPath());
        rule.setInputRuleParams(obj.getPath(), filePath, filePath);
        executeRule(rule.toString());
    }
}
Also used : DataGridRule(com.emc.metalnx.core.domain.entity.DataGridRule) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)

Example 37 with DataGridCollectionAndDataObject

use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.

the class CollectionServiceImpl method listCollectionsUnderPathThatMatchSearchText.

/**
 * Lists all collections under the given path that match a search term. Any
 * collection 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> listCollectionsUnderPathThatMatchSearchText(String parentPath, String searchText, int offset, int limit, int orderColumn, String orderDir) throws DataGridConnectionRefusedException {
    logger.info("listCollectionsUnderPathThatMatchSearchText()");
    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> itemsListingEntries = null;
    List<DataGridCollectionAndDataObject> dataGridItemsList = null;
    String sqlQueryAlias = "";
    try {
        sqlQueryAlias = SQL_LIST_COLLS_MATCHING_SEARCH_TEXT_ALIAS_WITH_ORDERING;
        ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
        SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
        String query = provider.buildSelectCollectionsUnderPathThatMatchSearchText(parentPath, searchText, offset, limit, orderColumn, orderDir);
        // 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);
        args.add(String.valueOf(offset));
        args.add(String.valueOf(limit));
        SpecificQuery specQuery = SpecificQuery.instanceArguments(sqlQueryAlias, args, 0, zone);
        logger.debug("specificQuery for text search:{}", specQuery);
        SpecificQueryResultSet queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, MAX_RESULTS_PER_PAGE, 0);
        // Mapping spec query results to DataGrid* objects
        itemsListingEntries = DataGridUtils.mapCollectionQueryResultSetToDataGridObjects(queryResultSet);
        dataGridItemsList = DataGridUtils.mapListingEntryToDataGridCollectionAndDataObject(itemsListingEntries);
    } 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 dataGridItemsList;
}
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) JargonQueryException(org.irods.jargon.core.query.JargonQueryException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) SpecificQuery(org.irods.jargon.core.query.SpecificQuery)

Example 38 with DataGridCollectionAndDataObject

use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.

the class CollectionServiceImpl method getSubCollectionsUnderPath.

@Override
public List<DataGridCollectionAndDataObject> getSubCollectionsUnderPath(String parent) throws DataGridConnectionRefusedException {
    logger.info("getSubCollectionsUnderPath()");
    CollectionAndDataObjectListAndSearchAO collectionAndDataObjectListAndSearchAO = irodsServices.getCollectionAndDataObjectListAndSearchAO();
    List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = null;
    try {
        List<CollectionAndDataObjectListingEntry> collectionAndDataObjects = collectionAndDataObjectListAndSearchAO.listCollectionsUnderPath(parent, 0);
        dataGridCollectionAndDataObjects = this.mapListingEntryToDataGridCollectionAndDataObject(collectionAndDataObjects);
        return dataGridCollectionAndDataObjects;
    } catch (FileNotFoundException e) {
        logger.error("Could not locate file: ", e);
    } catch (JargonException e) {
        logger.error("Error: ", e);
    }
    return dataGridCollectionAndDataObjects;
}
Also used : CollectionAndDataObjectListAndSearchAO(org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO) JargonException(org.irods.jargon.core.exception.JargonException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) CollectionAndDataObjectListingEntry(org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)

Example 39 with DataGridCollectionAndDataObject

use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.

the class CollectionServiceImpl method getSubCollectionsAndDataObjectsUnderPath.

@Override
public List<DataGridCollectionAndDataObject> getSubCollectionsAndDataObjectsUnderPath(String parent) throws DataGridConnectionRefusedException, JargonException {
    logger.info("getSubCollectionsAndDataObjectsUnderPath()");
    if (parent == null || parent.isEmpty()) {
        throw new IllegalArgumentException("null or empty parent");
    }
    logger.info("parent:{}", parent);
    CollectionAndDataObjectListAndSearchAO collectionAndDataObjectListAndSearchAO = irodsServices.getCollectionAndDataObjectListAndSearchAO();
    List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = null;
    try {
        List<CollectionAndDataObjectListingEntry> collectionAndDataObjects = collectionAndDataObjectListAndSearchAO.listDataObjectsAndCollectionsUnderPath(parent);
        dataGridCollectionAndDataObjects = new ArrayList<DataGridCollectionAndDataObject>();
        dataGridCollectionAndDataObjects = this.mapListingEntryToDataGridCollectionAndDataObject(collectionAndDataObjects);
        return dataGridCollectionAndDataObjects;
    } catch (FileNotFoundException e) {
        logger.error("Could not locate file: ", e);
        throw e;
    } catch (JargonException e) {
        logger.error("Error: ", e);
        throw e;
    }
}
Also used : CollectionAndDataObjectListAndSearchAO(org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO) JargonException(org.irods.jargon.core.exception.JargonException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) CollectionAndDataObjectListingEntry(org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)

Example 40 with DataGridCollectionAndDataObject

use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.

the class CollectionServiceImpl method isFileInCollection.

@Override
public boolean isFileInCollection(String filename, String collectionPath) throws DataGridConnectionRefusedException, JargonException {
    logger.info("isFileInCollection()");
    if (filename == null || collectionPath == null)
        return false;
    List<DataGridCollectionAndDataObject> items = getSubCollectionsAndDataObjectsUnderPath(collectionPath);
    for (DataGridCollectionAndDataObject i : items) {
        if (!i.isCollection() && filename.equals(i.getName()))
            return true;
    }
    return false;
}
Also used : DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)

Aggregations

DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)55 JargonException (org.irods.jargon.core.exception.JargonException)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Before (org.junit.Before)11 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)9 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)9 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)7 ArrayList (java.util.ArrayList)7 CollectionAndDataObjectListingEntry (org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)7 DataGridPageContext (com.emc.metalnx.core.domain.entity.DataGridPageContext)6 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)6 DataGridMetadata (com.emc.metalnx.core.domain.entity.DataGridMetadata)5 CollectionAndDataObjectListAndSearchAO (org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO)5 Date (java.util.Date)4 HashMap (java.util.HashMap)4 JargonQueryException (org.irods.jargon.core.query.JargonQueryException)4 DataGridResource (com.emc.metalnx.core.domain.entity.DataGridResource)3 UnsupportedDataGridFeatureException (com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3