Search in sources :

Example 1 with FilterException

use of org.opennms.netmgt.measurements.api.exceptions.FilterException in project opennms by OpenNMS.

the class FilterEngine method filter.

/**
 * Successively applies all of the filters.
 */
public void filter(final List<FilterDef> filterDefinitions, final RowSortedTable<Long, String, Double> table) throws FilterException {
    Preconditions.checkNotNull(filterDefinitions, "filterDefinitions argument");
    Preconditions.checkNotNull(table, "table argument");
    for (FilterDef filterDef : filterDefinitions) {
        Filter filter = getFilter(filterDef);
        if (filter == null) {
            throw new FilterException("No filter implementation found for {}", filterDef.getName());
        }
        try {
            filter.filter(table);
        } catch (Throwable t) {
            throw new FilterException(t, "An error occurred while applying filter {}", t.getMessage());
        }
    }
}
Also used : FilterDef(org.opennms.netmgt.measurements.model.FilterDef) FilterException(org.opennms.netmgt.measurements.api.exceptions.FilterException)

Example 2 with FilterException

use of org.opennms.netmgt.measurements.api.exceptions.FilterException in project opennms by OpenNMS.

the class MeasurementsRestService method query.

/**
 * Retrieves the measurements of many resources and performs
 * arbitrary calculations on these.
 *
 * This a read-only query, however we use a POST instead of GET
 * since the request parameters are difficult to express in a query string.
 */
@POST
@Path("/")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional(readOnly = true)
public QueryResponse query(final QueryRequest request) {
    Preconditions.checkState(service != null);
    LOG.debug("Executing query with {}", request);
    QueryResponse response = null;
    try {
        response = service.query(request);
    } catch (ExpressionException e) {
        throw getException(Status.BAD_REQUEST, e, "An error occurred while evaluating an expression: {}", e.getMessage());
    } catch (FilterException | ValidationException e) {
        throw getException(Status.BAD_REQUEST, e, e.getMessage());
    } catch (ResourceNotFoundException e) {
        throw getException(Status.NOT_FOUND, e, e.getMessage());
    } catch (FetchException e) {
        throw getException(Status.INTERNAL_SERVER_ERROR, e, e.getMessage());
    } catch (Exception e) {
        throw getException(Status.INTERNAL_SERVER_ERROR, e, "Query failed: {}", e.getMessage());
    }
    // Return a 204 if there are no columns
    if (response.getColumns().length == 0) {
        throw getException(Status.NO_CONTENT, "No content.");
    }
    return response;
}
Also used : ValidationException(org.opennms.netmgt.measurements.api.exceptions.ValidationException) QueryResponse(org.opennms.netmgt.measurements.model.QueryResponse) FilterException(org.opennms.netmgt.measurements.api.exceptions.FilterException) FetchException(org.opennms.netmgt.measurements.api.exceptions.FetchException) ResourceNotFoundException(org.opennms.netmgt.measurements.api.exceptions.ResourceNotFoundException) ExpressionException(org.opennms.netmgt.measurements.api.exceptions.ExpressionException) FetchException(org.opennms.netmgt.measurements.api.exceptions.FetchException) FilterException(org.opennms.netmgt.measurements.api.exceptions.FilterException) ResourceNotFoundException(org.opennms.netmgt.measurements.api.exceptions.ResourceNotFoundException) ValidationException(org.opennms.netmgt.measurements.api.exceptions.ValidationException) WebApplicationException(javax.ws.rs.WebApplicationException) ExpressionException(org.opennms.netmgt.measurements.api.exceptions.ExpressionException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

FilterException (org.opennms.netmgt.measurements.api.exceptions.FilterException)2 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ExpressionException (org.opennms.netmgt.measurements.api.exceptions.ExpressionException)1 FetchException (org.opennms.netmgt.measurements.api.exceptions.FetchException)1 ResourceNotFoundException (org.opennms.netmgt.measurements.api.exceptions.ResourceNotFoundException)1 ValidationException (org.opennms.netmgt.measurements.api.exceptions.ValidationException)1 FilterDef (org.opennms.netmgt.measurements.model.FilterDef)1 QueryResponse (org.opennms.netmgt.measurements.model.QueryResponse)1 Transactional (org.springframework.transaction.annotation.Transactional)1