Search in sources :

Example 1 with DefaultInstant

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

the class CswRecordMapperFilterVisitor method visit.

@Override
public Object visit(PropertyIsGreaterThan filter, Object extraData) {
    Expression expr1 = visit(filter.getExpression1(), extraData);
    Expression expr2 = visit(filter.getExpression2(), expr1);
    // work around since Solr Provider doesn't support greater on temporal  (DDF-311)
    if (isTemporalQuery(expr1, expr2)) {
        // also not supported by provider (DDF-311)
        //TODO: work around 1: return getFactory(extraData).after(expr1, expr2);
        Object val = null;
        Expression other = null;
        if (expr2 instanceof Literal) {
            val = ((Literal) expr2).getValue();
            other = expr1;
        } else if (expr1 instanceof Literal) {
            val = ((Literal) expr1).getValue();
            other = expr2;
        }
        if (val != null) {
            Date orig = (Date) val;
            orig.setTime(orig.getTime() + 1);
            Instant start = new DefaultInstant(new DefaultPosition(orig));
            Instant end = new DefaultInstant(new DefaultPosition(new Date()));
            DefaultPeriod period = new DefaultPeriod(start, end);
            Literal literal = getFactory(extraData).literal(period);
            return getFactory(extraData).during(other, literal);
        }
    } else {
        AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression1()).getPropertyName());
        LiteralExpressionImpl typedExpression = (LiteralExpressionImpl) filter.getExpression2();
        setExpressionType(type, typedExpression);
        expr2 = visit((Expression) typedExpression, expr1);
    }
    return getFactory(extraData).greater(expr1, expr2);
}
Also used : Expression(org.opengis.filter.expression.Expression) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) AttributeType(ddf.catalog.data.AttributeType) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) Literal(org.opengis.filter.expression.Literal) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Instant(org.opengis.temporal.Instant) DefaultPosition(org.geotools.temporal.object.DefaultPosition) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Date(java.util.Date)

Example 2 with DefaultInstant

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

the class CswRecordMapperFilterVisitor method visit.

@Override
public Object visit(PropertyIsGreaterThanOrEqualTo filter, Object extraData) {
    Expression expr1 = visit(filter.getExpression1(), extraData);
    Expression expr2 = visit(filter.getExpression2(), expr1);
    // work around since Solr Provider doesn't support greaterOrEqual on temporal (DDF-311)
    if (isTemporalQuery(expr1, expr2)) {
        // also not supported by provider (DDF-311)
        //TEquals tEquals = getFactory(extraData).tequals(expr1, expr2);
        //After after = getFactory(extraData).after(expr1, expr2);
        //return getFactory(extraData).or(tEquals, after);
        Object val = null;
        Expression other = null;
        if (expr2 instanceof Literal) {
            val = ((Literal) expr2).getValue();
            other = expr1;
        } else if (expr1 instanceof Literal) {
            val = ((Literal) expr1).getValue();
            other = expr2;
        }
        if (val != null) {
            Date orig = (Date) val;
            Instant start = new DefaultInstant(new DefaultPosition(orig));
            Instant end = new DefaultInstant(new DefaultPosition(new Date()));
            DefaultPeriod period = new DefaultPeriod(start, end);
            Literal literal = getFactory(extraData).literal(period);
            return getFactory(extraData).during(other, literal);
        }
    } else {
        AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression1()).getPropertyName());
        LiteralExpressionImpl typedExpression = (LiteralExpressionImpl) filter.getExpression2();
        setExpressionType(type, typedExpression);
        expr2 = visit((Expression) typedExpression, expr1);
    }
    return getFactory(extraData).greaterOrEqual(expr1, expr2);
}
Also used : Expression(org.opengis.filter.expression.Expression) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) AttributeType(ddf.catalog.data.AttributeType) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) Literal(org.opengis.filter.expression.Literal) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Instant(org.opengis.temporal.Instant) DefaultPosition(org.geotools.temporal.object.DefaultPosition) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Date(java.util.Date)

Example 3 with DefaultInstant

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

the class SolrFilterBuilderTest method makePeriod.

private Period makePeriod(Date start, Date end) {
    DefaultPosition defaultPosition = new DefaultPosition(start);
    Instant startInstant = new DefaultInstant(defaultPosition);
    Instant endInstant = new DefaultInstant(new DefaultPosition(end));
    Period period = new DefaultPeriod(startInstant, endInstant);
    return period;
}
Also used : 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)

Example 4 with DefaultInstant

use of org.geotools.temporal.object.DefaultInstant in project sldeditor by robward-scisys.

the class FieldConfigTimePeriodTest method testGenerateExpression.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigTimePeriod#generateExpression()}. Test
 * method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigTimePeriod#populateExpression(java.lang.Object, org.opengis.filter.expression.Expression)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigTimePeriod#populateField(com.sldeditor.filter.v2.function.temporal.TimePeriod)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigTimePeriod#setTestValue(com.sldeditor.ui.detail.config.FieldId, java.lang.String)}.
 */
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;
    class TestFieldConfigTimePeriod extends FieldConfigTimePeriod {

        public TestFieldConfigTimePeriod(FieldConfigCommonData commonData) {
            super(commonData);
        }

        public Expression callGenerateExpression() {
            return generateExpression();
        }
    }
    TestFieldConfigTimePeriod field = new TestFieldConfigTimePeriod(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, null, valueOnly));
    Expression actualExpression = field.callGenerateExpression();
    assertNotNull(actualExpression);
    // Try string values - erroneous
    field.createUI();
    field.createUI();
    String expectedValue = "test string value";
    field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue);
    actualExpression = field.callGenerateExpression();
    assertNotNull(actualExpression);
    expectedValue = "test string value as expression";
    field.populateExpression(expectedValue);
    actualExpression = field.callGenerateExpression();
    assertNotNull(actualExpression);
    // Time period values
    String timePeriod = "07-07-2016T17:42:27Z / 08-07-2016T17:42:27Z";
    field.setTestValue(FieldIdEnum.UNKNOWN, (String) null);
    field.setTestValue(FieldIdEnum.UNKNOWN, timePeriod);
    actualExpression = field.callGenerateExpression();
    assertTrue(timePeriod.compareTo(actualExpression.toString()) == 0);
    TimePeriod period = new TimePeriod();
    Duration start = new Duration();
    start.setDuration(0, 0, 1, 0, 32, 9);
    period.setStart(start);
    field.populateField((TimePeriod) null);
    field.populateField(period);
    actualExpression = field.callGenerateExpression();
    String expectedPeriod = period.getString();
    assertTrue(expectedPeriod.compareTo(actualExpression.toString()) == 0);
    TimePeriod timePeriodObj = new TimePeriod();
    timePeriodObj.decode(timePeriod);
    DefaultPeriod defaultPeriod = new DefaultPeriod(new DefaultInstant(new DefaultPosition(timePeriodObj.getStart().getDate())), new DefaultInstant(new DefaultPosition(timePeriodObj.getEnd().getDate())));
    field.populateExpression(defaultPeriod);
    actualExpression = field.callGenerateExpression();
    assertTrue(timePeriod.compareTo(actualExpression.toString()) == 0);
}
Also used : Expression(org.opengis.filter.expression.Expression) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) FieldConfigTimePeriod(com.sldeditor.ui.detail.config.FieldConfigTimePeriod) TimePeriod(com.sldeditor.filter.v2.function.temporal.TimePeriod) FieldConfigTimePeriod(com.sldeditor.ui.detail.config.FieldConfigTimePeriod) DefaultPosition(org.geotools.temporal.object.DefaultPosition) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Duration(com.sldeditor.filter.v2.function.temporal.Duration) Test(org.junit.Test)

Example 5 with DefaultInstant

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

the class OpenSearchQuery method addTemporalFilter.

private 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(OpenSearchConstants.SUPPORTED_TEMPORAL_SEARCH_TERM), FILTER_FACTORY.literal(period));
        LOGGER.trace("Adding temporal filter");
        filters.add(filter);
    }
}
Also used : DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) PolygonSpatialFilter(org.codice.ddf.opensearch.endpoint.query.filter.PolygonSpatialFilter) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) Filter(org.opengis.filter.Filter) BBoxSpatialFilter(org.codice.ddf.opensearch.endpoint.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)

Aggregations

DefaultInstant (org.geotools.temporal.object.DefaultInstant)17 DefaultPosition (org.geotools.temporal.object.DefaultPosition)17 DefaultPeriod (org.geotools.temporal.object.DefaultPeriod)15 Instant (org.opengis.temporal.Instant)14 Period (org.opengis.temporal.Period)11 Filter (org.opengis.filter.Filter)6 QueryImpl (ddf.catalog.operation.impl.QueryImpl)5 Test (org.junit.Test)5 Expression (org.opengis.filter.expression.Expression)5 Metacard (ddf.catalog.data.Metacard)4 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)4 FederationException (ddf.catalog.federation.FederationException)4 SpatialFilter (ddf.catalog.impl.filter.SpatialFilter)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