Search in sources :

Example 1 with TimePositionType

use of net.opengis.gml.v_3_2_1.TimePositionType in project ddf by codice.

the class WfsFilterDelegate method createTimePositionType.

private TimePositionType createTimePositionType(String dateTime) {
    TimePositionType timePosition = gml320ObjectFactory.createTimePositionType();
    timePosition.getValue().add(dateTime);
    return timePosition;
}
Also used : TimePositionType(net.opengis.gml.v_3_2_1.TimePositionType)

Example 2 with TimePositionType

use of net.opengis.gml.v_3_2_1.TimePositionType in project ddf by codice.

the class WfsFilterDelegate method applyTemporalFallbacks.

protected List<FilterType> applyTemporalFallbacks(List<FilterType> filters) {
    if (null == filters || filters.isEmpty()) {
        return filters;
    }
    String startDate = "";
    String endDate = "";
    String property = "";
    List<FilterType> newFilters = new ArrayList<>();
    for (FilterType filterType : filters) {
        if (null == filterType) {
            continue;
        }
        if (filterType.isSetTemporalOps() && (!isTemporalOpSupported(TEMPORAL_OPERATORS.Before) && !isTemporalOpSupported(TEMPORAL_OPERATORS.After)) && !isDuringFilter(filterType)) {
            BinaryTemporalOpType binaryTemporalOpType = (BinaryTemporalOpType) filterType.getTemporalOps().getValue();
            property = binaryTemporalOpType.getValueReference();
            JAXBElement temporalExpression = binaryTemporalOpType.getExpression();
            TimeInstantType timeInstant = (TimeInstantType) temporalExpression.getValue();
            TimePositionType timePositionType = timeInstant.getTimePosition();
            List<String> value = timePositionType.getValue();
            if (isAfterFilter(filterType)) {
                startDate = value.get(0);
            } else if (isBeforeFilter(filterType)) {
                endDate = value.get(0);
            }
        } else {
            newFilters.add(filterType);
        }
    }
    if (isTemporalOpSupported(TEMPORAL_OPERATORS.During) && (StringUtils.isNotEmpty(startDate))) {
        if (StringUtils.isEmpty(endDate)) {
            endDate = convertDateToIso8601Format(new Date());
        }
        FilterType duringFilter = buildDuringFilterType(featureMetacardType.getFeatureType().getLocalPart() + "." + property, startDate, endDate);
        newFilters.add(duringFilter);
    } else if (isTemporalOpSupported(TEMPORAL_OPERATORS.During) && (StringUtils.isEmpty(startDate) && StringUtils.isNotEmpty(endDate))) {
        for (FilterType filterType : filters) {
            if (!filterType.isSetTemporalOps()) {
                BinaryLogicOpType binaryLogicOpType = (BinaryLogicOpType) filterType.getLogicOps().getValue();
                List<JAXBElement<?>> list = binaryLogicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps();
                for (JAXBElement<?> element : list) {
                    if (StringUtils.contains(element.getDeclaredType().toString(), ("BinaryTemporalOpType"))) {
                        BinaryTemporalOpType binTemp = (BinaryTemporalOpType) element.getValue();
                        JAXBElement temporalExpression = binTemp.getExpression();
                        TimePeriodType timePeriod = (TimePeriodType) temporalExpression.getValue();
                        TimePositionType timeEndPosition = timePeriod.getEndPosition();
                        List<String> newValue = new ArrayList<String>();
                        newValue.add(endDate);
                        timeEndPosition.unsetValue();
                        timeEndPosition.setValue(newValue);
                        timePeriod.setEndPosition(timeEndPosition);
                    }
                }
            } else if ((!isTemporalOpSupported(TEMPORAL_OPERATORS.Before) && !isTemporalOpSupported(TEMPORAL_OPERATORS.After)) && isDuringFilter(filterType)) {
                BinaryTemporalOpType binaryTemporalOpType = (BinaryTemporalOpType) filterType.getTemporalOps().getValue();
                JAXBElement temporalExpression = binaryTemporalOpType.getExpression();
                TimePeriodType timePeriod = (TimePeriodType) temporalExpression.getValue();
                TimePositionType timeEndPosition = timePeriod.getEndPosition();
                List<String> newValue = new ArrayList<String>();
                newValue.add(endDate);
                timeEndPosition.unsetValue();
                timeEndPosition.setValue(newValue);
                timePeriod.setEndPosition(timeEndPosition);
            }
        }
    }
    return newFilters;
}
Also used : ArrayList(java.util.ArrayList) LineString(com.vividsolutions.jts.geom.LineString) JAXBElement(javax.xml.bind.JAXBElement) Date(java.util.Date) TimeInstantType(net.opengis.gml.v_3_2_1.TimeInstantType) FilterType(net.opengis.filter.v_2_0_0.FilterType) BinaryLogicOpType(net.opengis.filter.v_2_0_0.BinaryLogicOpType) TimePeriodType(net.opengis.gml.v_3_2_1.TimePeriodType) 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)

Example 3 with TimePositionType

use of net.opengis.gml.v_3_2_1.TimePositionType in project ddf by codice.

the class TestWfsFilterDelegate 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 4 with TimePositionType

use of net.opengis.gml.v_3_2_1.TimePositionType in project ddf by codice.

the class TestWfsFilterDelegate method testAbsoluteTemporalOnlyQueryDuringSupported.

/**
     * 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 testAbsoluteTemporalOnlyQueryDuringSupported() {
    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);
    // 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 = duringDelegate.applyTemporalFallbacks(testFilters);
    FilterType duringFilter = convertedFilters.get(0);
    assertThat(duringFilter.getTemporalOps().getName().toString(), is("{http://www.opengis.net/fes/2.0}During"));
    binaryTemporalOpType = (BinaryTemporalOpType) duringFilter.getTemporalOps().getValue();
    assertThat(binaryTemporalOpType.isSetValueReference(), is(true));
    assertThat(binaryTemporalOpType.isSetExpression(), is(true));
    TimePeriodType timePeriodType = (TimePeriodType) binaryTemporalOpType.getExpression().getValue();
    beginPositionType = timePeriodType.getBeginPosition();
    Date beginDate = timePositionTypeToDate(beginPositionType);
    endPositionType = timePeriodType.getEndPosition();
    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) 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)

Example 5 with TimePositionType

use of net.opengis.gml.v_3_2_1.TimePositionType in project ddf by codice.

the class TestWfsFilterDelegate 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)

Aggregations

TimePositionType (net.opengis.gml.v_3_2_1.TimePositionType)8 Date (java.util.Date)7 BinaryTemporalOpType (net.opengis.filter.v_2_0_0.BinaryTemporalOpType)7 FilterType (net.opengis.filter.v_2_0_0.FilterType)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 TimePeriodType (net.opengis.gml.v_3_2_1.TimePeriodType)5 TimeInstantType (net.opengis.gml.v_3_2_1.TimeInstantType)4 FilterCapabilities (net.opengis.filter.v_2_0_0.FilterCapabilities)3 List (java.util.List)2 TimePositionType (net.opengis.gml.x32.TimePositionType)2 LineString (com.vividsolutions.jts.geom.LineString)1 JAXBElement (javax.xml.bind.JAXBElement)1 BinaryLogicOpType (net.opengis.filter.v_2_0_0.BinaryLogicOpType)1 LineString (org.locationtech.jts.geom.LineString)1 MultiLineString (org.locationtech.jts.geom.MultiLineString)1 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)1 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)1 DecodingException (org.n52.svalbard.decode.exception.DecodingException)1