Search in sources :

Example 6 with UnsupportedDataGridFeatureException

use of com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException in project metalnx-web by irods-contrib.

the class SpecQueryServiceImpl method countItemsMatchingMetadata.

/**
 * Counts the number of items matching a metadata search criteria.
 *
 * @param metadataSearch
 *            metadata criteria
 * @param zone
 *            zone name
 * @param searchAgainstColls
 *            flag set to true when searching collections and false when
 *            searching data data objects
 * @return total number of items matching a metadata search criteria
 * @throws DataGridConnectionRefusedException
 * @throws JargonException
 */
private int countItemsMatchingMetadata(List<DataGridMetadataSearch> metadataSearch, String zone, boolean searchAgainstColls) throws DataGridConnectionRefusedException, JargonException {
    int totalItems = 0;
    SpecificQueryAO specificQueryAO = null;
    SpecificQuery specQuery = null;
    SpecificQueryResultSet queryResultSet = null;
    String userSQLAlias = "metalnxUserQuery_" + System.currentTimeMillis();
    try {
        specificQueryAO = adminServices.getSpecificQueryAO();
        ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
        SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
        String query = provider.buildQueryForCountOfItemsMatchingMetadataSearch(metadataSearch, zone, searchAgainstColls);
        // Creating Specific Query instance
        SpecificQueryDefinition queryDef = new SpecificQueryDefinition();
        queryDef.setAlias(userSQLAlias);
        queryDef.setSql(query);
        // Creating spec query on iRODS
        specificQueryAO.addSpecificQuery(queryDef);
        specQuery = SpecificQuery.instanceWithNoArguments(userSQLAlias, 0, zone);
        logger.info("Specific query: {}", query.toString());
        queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, 99999, 0);
        // after running the user specific query, we need to remove from the database
        specificQueryAO.removeSpecificQueryByAlias(userSQLAlias);
        totalItems = DataGridUtils.mapCountQueryResultSetToInteger(queryResultSet);
    } catch (JargonException e) {
        logger.error("Could not get specific query: ", e);
        throw e;
    } catch (JargonQueryException e) {
        logger.error("Could not get specific query: ", e);
        throw new JargonException(e);
    } catch (UnsupportedDataGridFeatureException e) {
        logger.error("Could not get specific query: ", e);
        throw new JargonException(e);
    }
    return totalItems;
}
Also used : UnsupportedDataGridFeatureException(com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException) JargonQueryException(org.irods.jargon.core.query.JargonQueryException) SpecificQueryProvider(com.emc.metalnx.services.irods.utils.SpecificQueryProvider) JargonException(org.irods.jargon.core.exception.JargonException) ClientHints(org.irods.jargon.core.pub.domain.ClientHints) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) SpecificQuery(org.irods.jargon.core.query.SpecificQuery) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) SpecificQueryDefinition(org.irods.jargon.core.pub.domain.SpecificQueryDefinition)

Example 7 with UnsupportedDataGridFeatureException

use of com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException in project metalnx-web by irods-contrib.

the class FilePropertyServiceImpl method findByFileProperties.

@Override
public List<DataGridCollectionAndDataObject> findByFileProperties(List<DataGridFilePropertySearch> searchList, DataGridPageContext pageContext, int pageNum, int pageSize) throws DataGridConnectionRefusedException, JargonException {
    List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = null;
    List<DataGridCollectionAndDataObject> dataGridObjects = null;
    List<DataGridCollectionAndDataObject> dataGridCollections = null;
    int totalCollections = 0;
    int totalDataObjects = 0;
    int startIndex = (pageNum - 1) * pageSize;
    int endIndex = (pageNum * pageSize) - 1;
    int endIndexForDataObjs;
    int endIndexForCollections;
    try {
        String zone = irodsServices.getCurrentUserZone();
        totalCollections = specQueryService.countCollectionsMatchingFileProperties(searchList, zone);
        totalDataObjects = specQueryService.countDataObjectsMatchingFileProperties(searchList, zone);
        pageContext.setStartItemNumber(startIndex + 1);
        pageContext.setTotalNumberOfItems(totalCollections + totalDataObjects);
        dataGridCollectionAndDataObjects = new ArrayList<DataGridCollectionAndDataObject>();
        if (endIndex + 1 <= totalCollections) {
            // looking for collections
            SpecificQueryResultSet resultSetColls = specQueryService.searchByFileProperties(searchList, zone, true, pageContext, startIndex, pageSize);
            dataGridCollections = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetColls);
            endIndexForCollections = dataGridCollections.size();
            dataGridCollectionAndDataObjects.addAll(dataGridCollections);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + endIndexForCollections - 1);
        } else if (startIndex + 1 > totalCollections) {
            // looking for data objects
            SpecificQueryResultSet resultSetDataObjs = specQueryService.searchByFileProperties(searchList, zone, false, pageContext, startIndex - totalCollections, pageSize);
            dataGridObjects = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetDataObjs);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + dataGridObjects.size() - 1);
            dataGridCollectionAndDataObjects.addAll(dataGridObjects);
        } else {
            // looking for collections
            SpecificQueryResultSet resultSetColls = specQueryService.searchByFileProperties(searchList, zone, true, pageContext, startIndex, pageSize);
            dataGridCollections = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetColls);
            endIndexForDataObjs = pageSize - (totalCollections % pageSize);
            // looking for data objects
            SpecificQueryResultSet resultSetDataObjs = specQueryService.searchByFileProperties(searchList, zone, false, pageContext, 0, endIndexForDataObjs);
            dataGridObjects = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetDataObjs);
            endIndexForDataObjs = endIndexForDataObjs > dataGridObjects.size() ? dataGridObjects.size() : endIndexForDataObjs;
            dataGridCollectionAndDataObjects.addAll(dataGridCollections);
            dataGridCollectionAndDataObjects.addAll(dataGridObjects);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + endIndexForDataObjs + dataGridCollections.size() - 1);
        }
    } catch (JargonException | UnsupportedDataGridFeatureException e) {
        logger.error("Could not find data objects by metadata. ", e);
        if (e.getCause() instanceof ConnectException) {
            throw new DataGridConnectionRefusedException();
        }
    }
    this.populateVisibilityForCurrentUser(dataGridCollectionAndDataObjects);
    return dataGridCollectionAndDataObjects;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) UnsupportedDataGridFeatureException(com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) ConnectException(java.net.ConnectException)

Example 8 with UnsupportedDataGridFeatureException

use of com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException in project metalnx-web by irods-contrib.

the class HostInfo method createTicketForm.

@RequestMapping(value = "/ticketForm", method = RequestMethod.GET)
public String createTicketForm(final Model model, @RequestParam(value = "ticketstring", required = false) final String ticketString) throws DataGridConnectionRefusedException, DataGridTicketNotFoundException, UnsupportedDataGridFeatureException {
    if (!configService.getGlobalConfig().isTicketsEnabled()) {
        logger.error("tickets are not enabled");
        throw new UnsupportedDataGridFeatureException("tickets disabled");
    }
    DataGridTicket ticket;
    if (ticketString != null && !ticketString.isEmpty()) {
        ticket = ticketService.find(ticketString);
    } else {
        ticket = new DataGridTicket();
    }
    model.addAttribute("ticket", ticket);
    model.addAttribute("requestMapping", "tickets/");
    return "tickets/ticketForm";
}
Also used : UnsupportedDataGridFeatureException(com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException) DataGridTicket(com.emc.metalnx.core.domain.entity.DataGridTicket) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with UnsupportedDataGridFeatureException

use of com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException 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 10 with UnsupportedDataGridFeatureException

use of com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException 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)

Aggregations

UnsupportedDataGridFeatureException (com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException)11 JargonException (org.irods.jargon.core.exception.JargonException)8 SpecificQueryResultSet (org.irods.jargon.core.query.SpecificQueryResultSet)8 SpecificQueryProvider (com.emc.metalnx.services.irods.utils.SpecificQueryProvider)7 SpecificQueryAO (org.irods.jargon.core.pub.SpecificQueryAO)7 ClientHints (org.irods.jargon.core.pub.domain.ClientHints)7 SpecificQueryDefinition (org.irods.jargon.core.pub.domain.SpecificQueryDefinition)7 SpecificQuery (org.irods.jargon.core.query.SpecificQuery)7 JargonQueryException (org.irods.jargon.core.query.JargonQueryException)5 ArrayList (java.util.ArrayList)4 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)3 DataGridTicket (com.emc.metalnx.core.domain.entity.DataGridTicket)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 CollectionAndDataObjectListingEntry (org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ConnectException (java.net.ConnectException)1 HashMap (java.util.HashMap)1 ResponseEntity (org.springframework.http.ResponseEntity)1