Search in sources :

Example 16 with BinaryTemporalOpType

use of net.opengis.fes.x20.BinaryTemporalOpType in project ddf by codice.

the class WfsFilterDelegateTest method testSequentialPropertyIsOfTemporalType.

private void testSequentialPropertyIsOfTemporalType(String methName, String temporalOpName) throws Exception {
    SequentialTestMockHolder sequentialTestMockHolder = new SequentialTestMockHolder().invoke();
    WfsFilterDelegate delegate = sequentialTestMockHolder.getDelegate();
    String mockMetacardAttribute = sequentialTestMockHolder.getMockMetacardAttribute();
    String mockFeatureProperty = sequentialTestMockHolder.getMockFeatureProperty();
    String mockFeatureType = sequentialTestMockHolder.getMockFeatureType();
    DateTime date = new DateTime().minusDays(365);
    // Perform Test
    Method method = WfsFilterDelegate.class.getMethod(methName, String.class, Date.class);
    FilterType filter = (FilterType) method.invoke(delegate, mockMetacardAttribute, date.toDate());
    // Verify
    assertThat(filter.getTemporalOps().getName().toString(), is(temporalOpName));
    BinaryTemporalOpType binaryTemporalOpType = (BinaryTemporalOpType) filter.getTemporalOps().getValue();
    assertThat(binaryTemporalOpType.isSetValueReference(), is(true));
    assertThat(binaryTemporalOpType.getValueReference(), is(mockFeatureProperty));
    assertThat(binaryTemporalOpType.isSetExpression(), is(true));
    TimeInstantType timeInstant = (TimeInstantType) binaryTemporalOpType.getExpression().getValue();
    assertThat(timeInstant.getTimePosition().getValue().get(0), is(ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC).print(date)));
    assertThat("Strings matches expected pattern", timeInstant.getId().matches(getRegEx(mockFeatureType)), equalTo(true));
}
Also used : TimeInstantType(net.opengis.gml.v_3_2_1.TimeInstantType) FilterType(net.opengis.filter.v_2_0_0.FilterType) Method(java.lang.reflect.Method) DateTime(org.joda.time.DateTime) BinaryTemporalOpType(net.opengis.filter.v_2_0_0.BinaryTemporalOpType)

Example 17 with BinaryTemporalOpType

use of net.opengis.fes.x20.BinaryTemporalOpType in project ddf by codice.

the class WfsFilterDelegateTest method testRelativeTemporalOnlyQueryAfterSupported.

/**
 * If the WFS server does support an 'After' temporal query and supports a 'During' temporal
 * query, the query should remain an 'After' query
 */
@Test
public void testRelativeTemporalOnlyQueryAfterSupported() {
    setupMockMetacardType();
    FilterType afterFilter = setupAfterFilterType();
    assertThat(afterFilter.getTemporalOps().getName().toString(), is("{http://www.opengis.net/fes/2.0}After"));
    BinaryTemporalOpType binaryTemporalOpType = (BinaryTemporalOpType) afterFilter.getTemporalOps().getValue();
    assertThat(binaryTemporalOpType.isSetValueReference(), is(true));
    assertThat(binaryTemporalOpType.isSetExpression(), is(true));
    TimeInstantType timePeriod = (TimeInstantType) binaryTemporalOpType.getExpression().getValue();
    TimePositionType beginPositionType = timePeriod.getTimePosition();
    Date beginDate = timePositionTypeToDate(beginPositionType);
    Date endDate = new Date();
    // Verify Date range is created correctly
    assertThat(endDate.after(beginDate), is(true));
}
Also used : TimeInstantType(net.opengis.gml.v_3_2_1.TimeInstantType) FilterType(net.opengis.filter.v_2_0_0.FilterType) BinaryTemporalOpType(net.opengis.filter.v_2_0_0.BinaryTemporalOpType) TimePositionType(net.opengis.gml.v_3_2_1.TimePositionType) Date(java.util.Date) Test(org.junit.Test)

Example 18 with BinaryTemporalOpType

use of net.opengis.fes.x20.BinaryTemporalOpType in project ddf by codice.

the class WfsFilterDelegateTest method testAbsoluteTemporalOnlyQueryDuringUnSupported.

/**
 * If the WFS server does not support an 'After' and 'Before' temporal query, and supports a
 * 'During' temporal query, the query should be translated into 'During <after> to <before>'
 */
@Test
public void testAbsoluteTemporalOnlyQueryDuringUnSupported() {
    setupMockMetacardType();
    FilterType afterFilter = setupAfterFilterType();
    FilterType beforeFilter = setupBeforeFilterType();
    WfsFilterDelegate delegate = setupTemporalFilterDelegate();
    // Get After Filter Date
    BinaryTemporalOpType binaryTemporalOpType = (BinaryTemporalOpType) afterFilter.getTemporalOps().getValue();
    assertThat(binaryTemporalOpType.isSetValueReference(), is(true));
    assertThat(binaryTemporalOpType.isSetExpression(), is(true));
    TimeInstantType timePeriod = (TimeInstantType) binaryTemporalOpType.getExpression().getValue();
    TimePositionType beginPositionType = timePeriod.getTimePosition();
    Date afterDate = timePositionTypeToDate(beginPositionType);
    // Get Before Filter Date
    binaryTemporalOpType = (BinaryTemporalOpType) beforeFilter.getTemporalOps().getValue();
    assertThat(binaryTemporalOpType.isSetValueReference(), is(true));
    assertThat(binaryTemporalOpType.isSetExpression(), is(true));
    timePeriod = (TimeInstantType) binaryTemporalOpType.getExpression().getValue();
    TimePositionType endPositionType = timePeriod.getTimePosition();
    Date beforeDate = timePositionTypeToDate(endPositionType);
    List<FilterType> testFilters = new ArrayList<>();
    testFilters.add(afterFilter);
    testFilters.add(beforeFilter);
    List<FilterType> convertedFilters = delegate.applyTemporalFallbacks(testFilters);
    FilterType resultAfterFilter = convertedFilters.get(0);
    FilterType resultBeforeFilter = convertedFilters.get(1);
    assertThat(resultAfterFilter.getTemporalOps().getName().toString(), is("{http://www.opengis.net/fes/2.0}After"));
    assertThat(resultBeforeFilter.getTemporalOps().getName().toString(), is("{http://www.opengis.net/fes/2.0}Before"));
    // Get Resulting After Filter Date
    binaryTemporalOpType = (BinaryTemporalOpType) resultAfterFilter.getTemporalOps().getValue();
    assertThat(binaryTemporalOpType.isSetValueReference(), is(true));
    assertThat(binaryTemporalOpType.isSetExpression(), is(true));
    TimeInstantType timePeriodType = (TimeInstantType) binaryTemporalOpType.getExpression().getValue();
    beginPositionType = timePeriodType.getTimePosition();
    Date beginDate = timePositionTypeToDate(beginPositionType);
    // Get Resulting Before Filter Date
    binaryTemporalOpType = (BinaryTemporalOpType) resultBeforeFilter.getTemporalOps().getValue();
    assertThat(binaryTemporalOpType.isSetValueReference(), is(true));
    assertThat(binaryTemporalOpType.isSetExpression(), is(true));
    timePeriodType = (TimeInstantType) binaryTemporalOpType.getExpression().getValue();
    endPositionType = timePeriodType.getTimePosition();
    Date endDate = timePositionTypeToDate(endPositionType);
    // Verify Date range is created correctly
    assertThat(endDate.after(beginDate), is(true));
    assertThat(endDate.equals(beforeDate), is(true));
    assertThat(beginDate.equals(afterDate), is(true));
}
Also used : TimeInstantType(net.opengis.gml.v_3_2_1.TimeInstantType) FilterType(net.opengis.filter.v_2_0_0.FilterType) ArrayList(java.util.ArrayList) BinaryTemporalOpType(net.opengis.filter.v_2_0_0.BinaryTemporalOpType) TimePositionType(net.opengis.gml.v_3_2_1.TimePositionType) Date(java.util.Date) Test(org.junit.Test)

Example 19 with BinaryTemporalOpType

use of net.opengis.fes.x20.BinaryTemporalOpType in project ddf by codice.

the class WfsFilterDelegateTest method testDuringTemporalFallback.

@Test
public void testDuringTemporalFallback() {
    setupMockMetacardType();
    FilterType afterFilter = setupAfterFilterType();
    FilterType beforeFilter = setupBeforeFilterType();
    FilterCapabilities duringFilterCapabilities = setupFilterCapabilities();
    WfsFilterDelegate duringDelegate = new WfsFilterDelegate(mockFeatureMetacardType, duringFilterCapabilities, GeospatialUtil.EPSG_4326_URN, mockMapper, GeospatialUtil.LAT_LON_ORDER);
    WfsFilterDelegate spatialDelegate = mockFeatureMetacardCreateDelegate(mockFeatureProperty, mockFeatureType);
    FilterType spatialFilter = spatialDelegate.dwithin(Metacard.ANY_GEO, "POINT (30 10)", 1000);
    List<List<FilterType>> testFilters = new ArrayList<>();
    testFilters.add(Arrays.asList(afterFilter, beforeFilter));
    testFilters.add(Arrays.asList(afterFilter, beforeFilter, spatialFilter));
    for (List<FilterType> filtersToBeConverted : testFilters) {
        List<FilterType> convertedFilters = duringDelegate.applyTemporalFallbacks(filtersToBeConverted);
        FilterType duringFilter = convertedFilters.get(0);
        if (filtersToBeConverted.contains(spatialFilter)) {
            // verify that results contains the spatial filter type
            assertThat(convertedFilters.contains(spatialFilter), is(true));
            assertThat(convertedFilters.size(), is(2));
            if (duringFilter.isSetSpatialOps()) {
                duringFilter = convertedFilters.get(1);
            }
            // Verify during Filter is correct
            assertThat(duringFilter.isSetTemporalOps(), is(true));
        }
        assertThat(duringFilter.getTemporalOps().getName().toString(), is("{http://www.opengis.net/fes/2.0}During"));
        BinaryTemporalOpType binaryTemporalOpType = (BinaryTemporalOpType) duringFilter.getTemporalOps().getValue();
        assertThat(binaryTemporalOpType.isSetValueReference(), is(true));
        assertThat(binaryTemporalOpType.isSetExpression(), is(true));
        TimePeriodType timePeriod = (TimePeriodType) binaryTemporalOpType.getExpression().getValue();
        TimePositionType beginPositionType = timePeriod.getBeginPosition();
        Date beginDate = timePositionTypeToDate(beginPositionType);
        TimePositionType endPositionType = timePeriod.getEndPosition();
        Date endDate = timePositionTypeToDate(endPositionType);
        // Verify Date range is created correctly
        assertThat(endDate.after(beginDate), is(true));
    }
}
Also used : FilterCapabilities(net.opengis.filter.v_2_0_0.FilterCapabilities) FilterType(net.opengis.filter.v_2_0_0.FilterType) TimePeriodType(net.opengis.gml.v_3_2_1.TimePeriodType) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ArrayList(java.util.ArrayList) BinaryTemporalOpType(net.opengis.filter.v_2_0_0.BinaryTemporalOpType) TimePositionType(net.opengis.gml.v_3_2_1.TimePositionType) Date(java.util.Date) Test(org.junit.Test)

Example 20 with BinaryTemporalOpType

use of net.opengis.fes.x20.BinaryTemporalOpType in project ddf by codice.

the class WfsFilterDelegateTest method testRelativePropertyIsOfTemporalType.

@Test
public /**
 * Doing a Relative query from the search UI creates a During filter with the selected End
 * date/time and the Begin date/time calculated based on the duration.
 *
 * <p><Filter> <During> <ValueReference>myFeatureProperty</ValueReference> <ns4:TimePeriod
 * ns4:id="myFeatureType.1406219647420">
 * <ns4:beginPosition>1974-08-01T16:29:45.430-07:00</ns4:beginPosition>
 * <ns4:endPosition>2014-07-22T16:29:45.430-07:00</ns4:endPosition> </ns4:TimePeriod> </During>
 * </Filter>
 */
void testRelativePropertyIsOfTemporalType() {
    // Setup
    SequentialTestMockHolder sequentialTestMockHolder = new SequentialTestMockHolder().invoke();
    WfsFilterDelegate delegate = sequentialTestMockHolder.getDelegate();
    String mockMetacardAttribute = sequentialTestMockHolder.getMockMetacardAttribute();
    String mockFeatureProperty = sequentialTestMockHolder.getMockFeatureProperty();
    String mockFeatureType = sequentialTestMockHolder.getMockFeatureType();
    long duration = 604800000;
    DateTime now = new DateTime();
    /**
     * When delegate.relative(mockProperty, duration) is called, the current time (now) is
     * calculated and used for the end date/time and the start date/time is calculated based on the
     * end date/time and duration (now - duration). Once we get the current time (now) in the test,
     * we want to hold the System time fixed so when the current time (now) is retrieved in
     * delegate.relative(mockProperty, duration) there is no discrepancy. This allows us to easily
     * assert the begin position and end position in the Verify step of this test.
     */
    DateTimeUtils.setCurrentMillisFixed(now.getMillis());
    String startDate = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC).print(now.minus(duration));
    // Perform Test
    FilterType filter = delegate.relative(mockMetacardAttribute, duration);
    // Verify
    assertThat(filter.getTemporalOps().getName().toString(), is("{http://www.opengis.net/fes/2.0}During"));
    BinaryTemporalOpType binaryTemporalOpType = (BinaryTemporalOpType) filter.getTemporalOps().getValue();
    assertThat(binaryTemporalOpType.isSetValueReference(), is(true));
    assertThat(binaryTemporalOpType.getValueReference(), is(mockFeatureProperty));
    assertThat(binaryTemporalOpType.isSetExpression(), is(true));
    TimePeriodType timePeriod = (TimePeriodType) binaryTemporalOpType.getExpression().getValue();
    assertThat(timePeriod.getBeginPosition().getValue().get(0), is(startDate));
    assertThat(timePeriod.getEndPosition().getValue().get(0), is(ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC).print(now)));
    assertThat("Strings matches expected pattern", timePeriod.getId().matches(getRegEx(mockFeatureType)), equalTo(true));
    // Reset the System time
    DateTimeUtils.setCurrentMillisSystem();
}
Also used : FilterType(net.opengis.filter.v_2_0_0.FilterType) TimePeriodType(net.opengis.gml.v_3_2_1.TimePeriodType) DateTime(org.joda.time.DateTime) BinaryTemporalOpType(net.opengis.filter.v_2_0_0.BinaryTemporalOpType) Test(org.junit.Test)

Aggregations

BinaryTemporalOpType (net.opengis.filter.v_2_0_0.BinaryTemporalOpType)22 FilterType (net.opengis.filter.v_2_0_0.FilterType)21 Test (org.junit.Test)18 Date (java.util.Date)13 TimePeriodType (net.opengis.gml.v_3_2_1.TimePeriodType)13 TimePositionType (net.opengis.gml.v_3_2_1.TimePositionType)13 ArrayList (java.util.ArrayList)11 TimeInstantType (net.opengis.gml.v_3_2_1.TimeInstantType)9 DateTime (org.joda.time.DateTime)8 FilterCapabilities (net.opengis.filter.v_2_0_0.FilterCapabilities)6 List (java.util.List)3 BinaryTemporalOpType (net.opengis.fes.x20.BinaryTemporalOpType)3 BinaryLogicOpType (net.opengis.filter.v_2_0_0.BinaryLogicOpType)3 Method (java.lang.reflect.Method)2 DistanceBufferType (net.opengis.filter.v_2_0_0.DistanceBufferType)2 EncodingException (org.n52.svalbard.encode.exception.EncodingException)2 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 JAXBElement (javax.xml.bind.JAXBElement)1 DuringDocument (net.opengis.fes.x20.DuringDocument)1