Search in sources :

Example 21 with TimePeriodType

use of org.geotoolkit.gml.xml.v321.TimePeriodType in project ddf by codice.

the class TestWfsFilterDelegate method testDuringFilterTypeDates.

@Test
public void testDuringFilterTypeDates() throws Exception {
    setupMockMetacardType();
    FilterType duringFilter = setupDuringFilterType();
    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);
    assertThat(endDate.after(beginDate), is(true));
}
Also used : FilterType(net.opengis.filter.v_2_0_0.FilterType) TimePeriodType(net.opengis.gml.v_3_2_1.TimePeriodType) 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 22 with TimePeriodType

use of org.geotoolkit.gml.xml.v321.TimePeriodType in project ddf by codice.

the class TestWfsFilterDelegate method testDuringTemporalFallback.

@Test
public void testDuringTemporalFallback() throws Exception {
    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)", Double.valueOf(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) 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 23 with TimePeriodType

use of org.geotoolkit.gml.xml.v321.TimePeriodType in project ddf by codice.

the class TestWfsFilterDelegate 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.
     *
     *   <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() throws Exception {
    // 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)

Example 24 with TimePeriodType

use of org.geotoolkit.gml.xml.v321.TimePeriodType in project ddf by codice.

the class TestWfsFilterDelegate method testDuringPropertyIsOfTemporalType.

@Test
public /**
     * Doing a Absolute query from the search UI creates a During filter with the selected Begin and End date/times.
     *
     * Example During filter:
     *
     *   <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 testDuringPropertyIsOfTemporalType() throws Exception {
    SequentialTestMockHolder sequentialTestMockHolder = new SequentialTestMockHolder().invoke();
    WfsFilterDelegate delegate = sequentialTestMockHolder.getDelegate();
    String mockMetacardAttribute = sequentialTestMockHolder.getMockMetacardAttribute();
    String mockFeatureProperty = sequentialTestMockHolder.getMockFeatureProperty();
    String mockFeatureType = sequentialTestMockHolder.getMockFeatureType();
    DateTime startDate = new DateTime(2014, 01, 01, 01, 01, 01, 123, DateTimeZone.forID("-07:00"));
    DateTime endDate = new DateTime(2014, 01, 02, 01, 01, 01, 123, DateTimeZone.forID("-07:00"));
    // Perform Test
    FilterType filter = delegate.during(mockMetacardAttribute, startDate.toDate(), endDate.toDate());
    //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("2014-01-01T08:01:01Z"));
    assertThat(timePeriod.getEndPosition().getValue().get(0), is("2014-01-02T08:01:01Z"));
    assertThat("Strings matches expected pattern", timePeriod.getId().matches(getRegEx(mockFeatureType)), equalTo(true));
}
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)

Example 25 with TimePeriodType

use of org.geotoolkit.gml.xml.v321.TimePeriodType in project ddf by codice.

the class TestWfsFilterDelegate method testRelativeTemporalOnlyQueryAfterUnsupported.

/**
     * If the WFS server does not support an 'After' temporal query and supports a
     * 'During' temporal query, the query should be translated into a 'During <date> to <now>'
     */
@Test
public void testRelativeTemporalOnlyQueryAfterUnsupported() {
    setupMockMetacardType();
    FilterType afterFilter = setupAfterFilterType();
    FilterCapabilities duringFilterCapabilities = setupFilterCapabilities();
    WfsFilterDelegate duringDelegate = new WfsFilterDelegate(mockFeatureMetacardType, duringFilterCapabilities, GeospatialUtil.EPSG_4326_URN, mockMapper, GeospatialUtil.LAT_LON_ORDER);
    List<FilterType> testFilters = new ArrayList<>();
    testFilters.add(afterFilter);
    List<FilterType> convertedFilters = duringDelegate.applyTemporalFallbacks(testFilters);
    FilterType duringFilter = convertedFilters.get(0);
    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) 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)

Aggregations

TimePeriodType (net.opengis.gml.v_3_2_1.TimePeriodType)14 BinaryTemporalOpType (net.opengis.filter.v_2_0_0.BinaryTemporalOpType)13 FilterType (net.opengis.filter.v_2_0_0.FilterType)13 Test (org.junit.Test)12 TimePeriodType (org.geotoolkit.gml.xml.v311.TimePeriodType)11 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 TimePositionType (net.opengis.gml.v_3_2_1.TimePositionType)9 TimePositionType (org.geotoolkit.gml.xml.v311.TimePositionType)7 FilterCapabilities (net.opengis.filter.v_2_0_0.FilterCapabilities)6 JAXBElement (javax.xml.bind.JAXBElement)5 TimePeriodType (org.geotoolkit.gml.xml.v321.TimePeriodType)5 StringWriter (java.io.StringWriter)4 TimePositionType (org.geotoolkit.gml.xml.v321.TimePositionType)4 DateTime (org.joda.time.DateTime)4 StringReader (java.io.StringReader)3 List (java.util.List)3 TimeInstantType (net.opengis.gml.v_3_2_1.TimeInstantType)3 DirectPositionType (org.geotoolkit.gml.xml.v311.DirectPositionType)3 TimeInstantType (org.geotoolkit.gml.xml.v311.TimeInstantType)3