Search in sources :

Example 1 with CswRecordMapperFilterVisitor

use of org.codice.ddf.spatial.ogc.csw.catalog.endpoint.mappings.CswRecordMapperFilterVisitor in project ddf by codice.

the class CswQueryFactory method buildFilter.

private CswRecordMapperFilterVisitor buildFilter(QueryConstraintType constraint) throws CswException {
    CswRecordMapperFilterVisitor visitor = new CswRecordMapperFilterVisitor(metacardType, metacardTypes);
    Filter filter = null;
    if (constraint != null) {
        if (constraint.isSetCqlText()) {
            try {
                filter = CQL.toFilter(constraint.getCqlText());
            } catch (CQLException e) {
                throw new CswException("Unable to parse CQL Constraint: " + e.getMessage(), e);
            }
        } else if (constraint.isSetFilter()) {
            FilterType constraintFilter = constraint.getFilter();
            filter = parseFilter(constraintFilter);
        }
    } else {
        // not supported by catalog:
        //filter = Filter.INCLUDE;
        filter = builder.attribute(Core.ID).is().like().text(FilterDelegate.WILDCARD_CHAR);
    }
    if (filter == null) {
        throw new CswException("Invalid Filter Expression", CswConstants.NO_APPLICABLE_CODE, null);
    }
    filter = transformCustomFunctionToFilter(filter);
    try {
        visitor.setVisitedFilter((Filter) filter.accept(visitor, new FilterFactoryImpl()));
    } catch (UnsupportedOperationException ose) {
        throw new CswException(ose.getMessage(), CswConstants.INVALID_PARAMETER_VALUE, null);
    }
    return visitor;
}
Also used : FilterType(net.opengis.filter.v_1_1_0.FilterType) Filter(org.opengis.filter.Filter) CswRecordMapperFilterVisitor(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.mappings.CswRecordMapperFilterVisitor) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) CQLException(org.geotools.filter.text.cql2.CQLException)

Aggregations

FilterType (net.opengis.filter.v_1_1_0.FilterType)1 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)1 CswRecordMapperFilterVisitor (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.mappings.CswRecordMapperFilterVisitor)1 FilterFactoryImpl (org.geotools.filter.FilterFactoryImpl)1 CQLException (org.geotools.filter.text.cql2.CQLException)1 Filter (org.opengis.filter.Filter)1