Search in sources :

Example 6 with DefaultInstant

use of org.geotools.temporal.object.DefaultInstant in project ddf by codice.

the class GeotoolsBuilder method build.

//
// /**
// * @param expression the expression to set
// */
// void setExpression(Expression expression) {
// this.expression = expression;
// }
protected Filter build() {
    LOGGER.debug("BUILDING attribute = {}, operator = {}, value = {}, secondaryValue = {}", attribute, operator, value, secondaryValue);
    Filter filter = null;
    String wkt = null;
    Date date = null;
    double distance = 0;
    switch(operator) {
        case AFTER:
            date = getValue(Date.class);
            if (date != null) {
                filter = factory.after(factory.property(attribute), factory.literal(new DefaultInstant(new DefaultPosition(date))));
            }
            break;
        case BEFORE:
            date = getValue(Date.class);
            if (date != null) {
                filter = factory.before(factory.property(attribute), factory.literal(new DefaultInstant(new DefaultPosition(date))));
            }
            break;
        case BETWEEN:
            filter = factory.between(factory.property(attribute), factory.literal(value), factory.literal(secondaryValue));
            break;
        case DURING:
            Date start = getValue(Date.class);
            Date end = getSecondaryValue(Date.class);
            if (start != null && end != null) {
                DefaultPosition defaultPosition = new DefaultPosition(start);
                Instant startInstant = new DefaultInstant(defaultPosition);
                Instant endInstant = new DefaultInstant(new DefaultPosition(end));
                Period period = new DefaultPeriod(startInstant, endInstant);
                filter = factory.during(factory.property(attribute), factory.literal(period));
            }
            break;
        case DURING_RELATIVE:
            Long longValue = getValue(Long.class);
            if (null != value) {
                filter = factory.during(factory.property(attribute), factory.literal(new DefaultPeriodDuration(longValue)));
            }
            break;
        case EQ:
            filter = factory.equals(factory.property(attribute), factory.literal(value));
            break;
        case GT:
            filter = factory.greater(factory.property(attribute), factory.literal(value));
            break;
        case GTE:
            filter = factory.greaterOrEqual(factory.property(attribute), factory.literal(value));
            break;
        case LT:
            filter = factory.less(factory.property(attribute), factory.literal(value));
            break;
        case LTE:
            filter = factory.lessOrEqual(factory.property(attribute), factory.literal(value));
            break;
        case NEQ:
            filter = factory.notEqual(factory.property(attribute), factory.literal(value));
            break;
        case NULL:
            filter = factory.isNull(factory.property(attribute));
            break;
        case TOVERLAPS:
            filter = factory.toverlaps(factory.property(attribute), factory.literal(value));
            break;
        case BEYOND:
            wkt = getValue(String.class);
            distance = getSecondaryValue(Double.class);
            if (wkt != null && wkt.length() > 0) {
                filter = factory.beyond(attribute, toGeometry(wkt), distance, METERS);
            }
            break;
        case CONTAINS:
            wkt = getValue(String.class);
            if (wkt != null && wkt.length() > 0) {
                filter = factory.contains(attribute, toGeometry(wkt));
            }
            break;
        case DWITHIN:
            wkt = getValue(String.class);
            distance = getSecondaryValue(Double.class);
            if (wkt != null && wkt.length() > 0) {
                filter = factory.dwithin(attribute, toGeometry(wkt), distance, METERS);
            }
            break;
        case INTERSECTS:
            wkt = getValue(String.class);
            if (wkt != null && wkt.length() > 0) {
                filter = factory.intersects(attribute, toGeometry(wkt));
            }
            break;
        case WITHIN:
            wkt = getValue(String.class);
            if (wkt != null && wkt.length() > 0) {
                filter = factory.within(attribute, toGeometry(wkt));
            }
            break;
        case LIKE:
            filter = factory.like(factory.property(attribute), getValue(String.class), "*", "%", "'", getSecondaryValue(Boolean.class));
            break;
        case FUZZY:
            Expression expression = factory.property(attribute);
            filter = factory.like(new FuzzyFunction(Arrays.asList(expression), factory.literal(Metacard.ANY_TEXT)), getValue(String.class), "*", "%", "'", getSecondaryValue(Boolean.class));
            break;
        default:
    }
    if (filter == null) {
        throw new IllegalArgumentException("Illegal argument for operation [" + operator.name() + "]");
    }
    return filter;
}
Also used : FuzzyFunction(ddf.catalog.impl.filter.FuzzyFunction) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Instant(org.opengis.temporal.Instant) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Period(org.opengis.temporal.Period) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) Date(java.util.Date) DefaultPeriodDuration(org.geotools.temporal.object.DefaultPeriodDuration) Filter(org.opengis.filter.Filter) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) Expression(org.opengis.filter.expression.Expression) DefaultPosition(org.geotools.temporal.object.DefaultPosition)

Example 7 with DefaultInstant

use of org.geotools.temporal.object.DefaultInstant in project ddf by codice.

the class CommonQueryBuilder method during.

// public QueryImpl fuzzy(String searchPhrase, boolean isCaseSensitive) {
//
// QueryImpl query = new QueryImpl(
// filterFactory.like(
// new FuzzyFunction(
// Arrays.asList((Expression)(filterFactory.property(Metacard.ANY_TEXT))),
// filterFactory.literal("")),
// searchPhrase,
// "*", "?", "\\",
// isCaseSensitive) ) ;
//
// query.setStartIndex(1) ;
//
// query.setRequestsTotalResultsCount(true);
//
// return query;
// }
public QueryImpl during(String property, Date start, Date end) {
    Instant startInstant = new DefaultInstant(new DefaultPosition(start));
    Instant endInstant = new DefaultInstant(new DefaultPosition(end));
    Period period = new DefaultPeriod(startInstant, endInstant);
    Filter filter = filterFactory.during(filterFactory.property(property), filterFactory.literal(period));
    QueryImpl query = new QueryImpl(filter);
    query.setStartIndex(1);
    query.setRequestsTotalResultsCount(true);
    return query;
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) Filter(org.opengis.filter.Filter) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Instant(org.opengis.temporal.Instant) DefaultPosition(org.geotools.temporal.object.DefaultPosition) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Period(org.opengis.temporal.Period) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod)

Example 8 with DefaultInstant

use of org.geotools.temporal.object.DefaultInstant in project ddf by codice.

the class MockQuery method addTemporalFilter.

public void addTemporalFilter(TemporalFilter temporalFilter) {
    if (temporalFilter != null) {
        // t1.start < timeType instance < t1.end
        Instant startInstant = new DefaultInstant(new DefaultPosition(temporalFilter.getStartDate()));
        Instant endInstant = new DefaultInstant(new DefaultPosition(temporalFilter.getEndDate()));
        Period period = new DefaultPeriod(startInstant, endInstant);
        Filter filter = FILTER_FACTORY.during(FILTER_FACTORY.property(MODIFIED_DATE), FILTER_FACTORY.literal(period));
        filters.add(filter);
        this.filter = getFilter();
    }
}
Also used : DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) Filter(org.opengis.filter.Filter) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Instant(org.opengis.temporal.Instant) DefaultPosition(org.geotools.temporal.object.DefaultPosition) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Period(org.opengis.temporal.Period) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod)

Example 9 with DefaultInstant

use of org.geotools.temporal.object.DefaultInstant in project ddf by codice.

the class OpenSearchQuery method addTemporalFilter.

public void addTemporalFilter(TemporalFilter temporalFilter) {
    String methodName = "addTemporalFilter";
    if (temporalFilter != null) {
        // t1.start < timeType instance < t1.end
        Instant startInstant = new DefaultInstant(new DefaultPosition(temporalFilter.getStartDate()));
        Instant endInstant = new DefaultInstant(new DefaultPosition(temporalFilter.getEndDate()));
        Period period = new DefaultPeriod(startInstant, endInstant);
        Filter filter = FILTER_FACTORY.during(FILTER_FACTORY.property(Metacard.MODIFIED), FILTER_FACTORY.literal(period));
        LOGGER.debug("Adding temporal filter");
        filters.add(filter);
    }
}
Also used : DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) BBoxSpatialFilter(org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Instant(org.opengis.temporal.Instant) DefaultPosition(org.geotools.temporal.object.DefaultPosition) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Period(org.opengis.temporal.Period) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod)

Example 10 with DefaultInstant

use of org.geotools.temporal.object.DefaultInstant in project ddf by codice.

the class MockQuery method addTemporalFilter.

public void addTemporalFilter(XMLGregorianCalendar start, XMLGregorianCalendar end, String timeType) {
    Filter filter = null;
    String timeProperty = Metacard.MODIFIED;
    if (timeType != null && timeType.toLowerCase().equals(Metacard.EFFECTIVE)) {
        timeProperty = Metacard.EFFECTIVE;
    }
    if (start != null && end != null) {
        int compareTo = start.toGregorianCalendar().compareTo(end.toGregorianCalendar());
        if (compareTo > 0) {
            throw new IllegalArgumentException("start date [" + start + "] should not be later than" + " end date [" + end + "]");
        } else if (compareTo == 0) {
            filter = FILTER_FACTORY.equals(FILTER_FACTORY.property(timeProperty), FILTER_FACTORY.literal(start.toGregorianCalendar().getTime()));
        } else {
            // t1.start < timeType instance < t1.end
            DefaultPosition defaultPosition = new DefaultPosition(start.toGregorianCalendar().getTime());
            Instant startInstant = new DefaultInstant(defaultPosition);
            Instant endInstant = new DefaultInstant(new DefaultPosition(end.toGregorianCalendar().getTime()));
            Period period = new DefaultPeriod(startInstant, endInstant);
            filter = FILTER_FACTORY.during(FILTER_FACTORY.property(timeProperty), FILTER_FACTORY.literal(period));
        }
        filters.add(filter);
    }
}
Also used : SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) Filter(org.opengis.filter.Filter) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) DefaultPosition(org.geotools.temporal.object.DefaultPosition) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Instant(org.opengis.temporal.Instant) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Period(org.opengis.temporal.Period) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod)

Aggregations

DefaultInstant (org.geotools.temporal.object.DefaultInstant)12 DefaultPosition (org.geotools.temporal.object.DefaultPosition)12 DefaultPeriod (org.geotools.temporal.object.DefaultPeriod)10 Instant (org.opengis.temporal.Instant)10 Period (org.opengis.temporal.Period)8 QueryImpl (ddf.catalog.operation.impl.QueryImpl)5 Filter (org.opengis.filter.Filter)5 Metacard (ddf.catalog.data.Metacard)4 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)4 FederationException (ddf.catalog.federation.FederationException)4 CreateResponse (ddf.catalog.operation.CreateResponse)4 QueryRequest (ddf.catalog.operation.QueryRequest)4 QueryResponse (ddf.catalog.operation.QueryResponse)4 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)4 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)4 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)4 ArrayList (java.util.ArrayList)4 Calendar (java.util.Calendar)4 FilterFactoryImpl (org.geotools.filter.FilterFactoryImpl)4 Test (org.junit.Test)4