Search in sources :

Example 1 with UnsupportedDataGridFeatureException

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

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

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

the class HostInfo method findAll.

/**
 * Finds all tickets in the grid.
 *
 * @return List of tickets in JSON
 * @throws DataGridConnectionRefusedException
 *             if Metalnx cannot connect to the grid
 * @throws UnsupportedDataGridFeatureException
 */
@RequestMapping(value = "/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public String findAll() throws DataGridConnectionRefusedException, JsonProcessingException, UnsupportedDataGridFeatureException {
    logger.info("Find all tickets");
    if (!configService.getGlobalConfig().isTicketsEnabled()) {
        logger.error("tickets are not enabled");
        throw new UnsupportedDataGridFeatureException("tickets disabled");
    }
    List<DataGridTicket> tickets = ticketService.findAll();
    Map<String, Object> ticketsAsJSON = new HashMap<>();
    ticketsAsJSON.put("data", tickets);
    return new ObjectMapper().writeValueAsString(ticketsAsJSON);
}
Also used : UnsupportedDataGridFeatureException(com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException) HashMap(java.util.HashMap) DataGridTicket(com.emc.metalnx.core.domain.entity.DataGridTicket) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with UnsupportedDataGridFeatureException

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

the class HostInfo method find.

/**
 * Finds a specific ticket in the grid by its id or string
 *
 * @param ticketId
 *            ticket id or string
 * @return Ticket as JSON
 * @throws DataGridConnectionRefusedException
 *             if Metalnx cannot connect to the grid
 * @throws UnsupportedDataGridFeatureException
 */
@RequestMapping(value = "/{ticketid}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<DataGridTicket> find(@PathVariable("ticketid") final String ticketId) throws DataGridConnectionRefusedException, DataGridTicketNotFoundException, UnsupportedDataGridFeatureException {
    logger.info("Find ticket by its ID or String");
    if (!configService.getGlobalConfig().isTicketsEnabled()) {
        logger.error("tickets are not enabled");
        throw new UnsupportedDataGridFeatureException("tickets disabled");
    }
    DataGridTicket dgTicket = ticketService.find(ticketId);
    return new ResponseEntity<>(dgTicket, HttpStatus.OK);
}
Also used : UnsupportedDataGridFeatureException(com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException) ResponseEntity(org.springframework.http.ResponseEntity) DataGridTicket(com.emc.metalnx.core.domain.entity.DataGridTicket) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with UnsupportedDataGridFeatureException

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

the class SpecQueryServiceImpl method searchByFileProperties.

@Override
public SpecificQueryResultSet searchByFileProperties(List<DataGridFilePropertySearch> filePropertySearch, String zone, boolean searchAgainstColls, DataGridPageContext pageContext, int offset, int limit) throws DataGridConnectionRefusedException, JargonException {
    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.buildQueryForFilePropertiesSearch(filePropertySearch, zone, searchAgainstColls, offset, limit);
        // 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);
        queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, 99999, 0);
    } 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);
    } finally {
        try {
            // after running the user specific query, we need to remove from the database
            specificQueryAO.removeSpecificQueryByAlias(userSQLAlias);
        } catch (JargonException e) {
            logger.error("Could not remove specific query {}: ", userSQLAlias, e.getMessage());
        }
    }
    return queryResultSet;
}
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)

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