use of org.geotoolkit.gml.xml.v311.TimePeriodType 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));
}
use of org.geotoolkit.gml.xml.v311.TimePeriodType 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(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<>();
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<>();
newValue.add(endDate);
timeEndPosition.unsetValue();
timeEndPosition.setValue(newValue);
timePeriod.setEndPosition(timeEndPosition);
}
}
}
return newFilters;
}
use of org.geotoolkit.gml.xml.v311.TimePeriodType in project ddf by codice.
the class WfsFilterDelegate method createTimePeriodType.
private TimePeriodType createTimePeriodType(String type, String startDate, String endDate) {
TimePeriodType timePeriodType = gml320ObjectFactory.createTimePeriodType();
timePeriodType.setBeginPosition(createTimePositionType(startDate));
timePeriodType.setEndPosition(createTimePositionType(endDate));
timePeriodType.setId(type + "." + System.currentTimeMillis());
return timePeriodType;
}
use of org.geotoolkit.gml.xml.v311.TimePeriodType in project ddf by codice.
the class WfsFilterDelegateTest 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));
}
use of org.geotoolkit.gml.xml.v311.TimePeriodType in project geotoolkit by Geomatys.
the class ObservationXMLBindingTest method marshallingTest.
/**
* Test simple Record Marshalling.
*
* @throws java.lang.Exception
*/
@Test
public void marshallingTest() throws Exception {
DirectPositionType pos = new DirectPositionType("urn:ogc:crs:espg:4326", 2, Arrays.asList(3.2, 6.5));
PointType location = new PointType("point-ID", pos);
SamplingPointType sp = new SamplingPointType("samplingID-007", "urn:sampling:test:007", "a sampling Test", new FeaturePropertyType(""), location);
PhenomenonType observedProperty = new PhenomenonType("phenomenon-007", "urn:OGC:phenomenon-007");
TimePeriodType samplingTime = new TimePeriodType("t1", "2007-01-01", "2008-09-09");
TextBlockType encoding = new TextBlockType("encoding-001", ",", "@@", ".");
List<AnyScalarPropertyType> fields = new ArrayList<>();
AnyScalarPropertyType field = new AnyScalarPropertyType("text-field-001", new Text("urn:something", "some value"));
fields.add(field);
SimpleDataRecordType record = new SimpleDataRecordType(fields);
DataArrayType array = new DataArrayType("array-001", 1, "array-001", record, encoding, "somevalue", null);
DataArrayPropertyType arrayProp = new DataArrayPropertyType(array);
ObservationType obs = new ObservationType("urn:Observation-007", "observation definition", sp, observedProperty, "urn:sensor:007", arrayProp, samplingTime);
StringWriter sw = new StringWriter();
marshaller.marshal(obs, sw);
String result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
String expResult = "<om:Observation xmlns:sampling=\"http://www.opengis.net/sampling/1.0\"" + " xmlns:om=\"http://www.opengis.net/om/1.0\"" + " xmlns:xlink=\"http://www.w3.org/1999/xlink\"" + " xmlns:gml=\"http://www.opengis.net/gml\"" + " xmlns:swe=\"http://www.opengis.net/swe/1.0.1\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + '\n' + " <gml:name>urn:Observation-007</gml:name>" + '\n' + " <om:samplingTime>" + '\n' + " <gml:TimePeriod gml:id=\"t1\">" + '\n' + " <gml:beginPosition>2007-01-01</gml:beginPosition>" + '\n' + " <gml:endPosition>2008-09-09</gml:endPosition>" + '\n' + " </gml:TimePeriod>" + '\n' + " </om:samplingTime>" + '\n' + " <om:procedure xlink:href=\"urn:sensor:007\"/>" + '\n' + " <om:observedProperty>" + '\n' + " <swe:Phenomenon gml:id=\"phenomenon-007\">" + '\n' + " <gml:name>urn:OGC:phenomenon-007</gml:name>" + '\n' + " </swe:Phenomenon>" + '\n' + " </om:observedProperty>" + '\n' + " <om:featureOfInterest>" + '\n' + " <sampling:SamplingPoint gml:id=\"samplingID-007\">" + '\n' + " <gml:description>a sampling Test</gml:description>" + '\n' + " <gml:name>urn:sampling:test:007</gml:name>" + '\n' + " <gml:boundedBy>" + '\n' + " <gml:Null>not_bounded</gml:Null>" + '\n' + " </gml:boundedBy>" + '\n' + " <sampling:sampledFeature xlink:href=\"\"/>" + '\n' + " <sampling:position>" + '\n' + " <gml:Point gml:id=\"point-ID\">" + '\n' + " <gml:pos srsName=\"urn:ogc:crs:espg:4326\" srsDimension=\"2\">3.2 6.5</gml:pos>" + '\n' + " </gml:Point>" + '\n' + " </sampling:position>" + '\n' + " </sampling:SamplingPoint>" + '\n' + " </om:featureOfInterest>" + '\n' + " <om:result xsi:type=\"swe:DataArrayPropertyType\" >" + '\n' + " <swe:DataArray gml:id=\"array-001\">" + '\n' + " <swe:elementCount>" + '\n' + " <swe:Count>" + '\n' + " <swe:value>1</swe:value>" + '\n' + " </swe:Count>" + '\n' + " </swe:elementCount>" + '\n' + " <swe:elementType name=\"array-001\">" + '\n' + " <swe:SimpleDataRecord>" + '\n' + " <swe:field name=\"text-field-001\">" + '\n' + " <swe:Text definition=\"urn:something\">" + '\n' + " <swe:value>some value</swe:value>" + '\n' + " </swe:Text>" + '\n' + " </swe:field>" + '\n' + " </swe:SimpleDataRecord>" + '\n' + " </swe:elementType>" + '\n' + " <swe:encoding>" + '\n' + " <swe:TextBlock blockSeparator=\"@@\" decimalSeparator=\".\" tokenSeparator=\",\" id=\"encoding-001\"/>" + '\n' + " </swe:encoding>" + '\n' + " <swe:values>somevalue</swe:values>" + '\n' + " </swe:DataArray>" + '\n' + " </om:result>" + '\n' + "</om:Observation>\n";
assertXmlEquals(expResult, result, "xmlns:*");
UnitOfMeasureEntry uom = new UnitOfMeasureEntry("m", "meters", "distance", "meters");
MeasureType meas = new MeasureType(uom, 7);
MeasurementType measmt = new MeasurementType("urn:Observation-007", "observation definition", sp, observedProperty, "urn:sensor:007", meas, samplingTime);
sw = new StringWriter();
marshaller.marshal(measmt, sw);
result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
expResult = "<om:Measurement xmlns:sampling=\"http://www.opengis.net/sampling/1.0\"" + " xmlns:om=\"http://www.opengis.net/om/1.0\"" + " xmlns:xlink=\"http://www.w3.org/1999/xlink\"" + " xmlns:gml=\"http://www.opengis.net/gml\"" + " xmlns:swe=\"http://www.opengis.net/swe/1.0.1\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + '\n' + " <gml:name>urn:Observation-007</gml:name>" + '\n' + " <om:samplingTime>" + '\n' + " <gml:TimePeriod gml:id=\"t1\">" + '\n' + " <gml:beginPosition>2007-01-01</gml:beginPosition>" + '\n' + " <gml:endPosition>2008-09-09</gml:endPosition>" + '\n' + " </gml:TimePeriod>" + '\n' + " </om:samplingTime>" + '\n' + " <om:procedure xlink:href=\"urn:sensor:007\"/>" + '\n' + " <om:observedProperty>" + '\n' + " <swe:Phenomenon gml:id=\"phenomenon-007\">" + '\n' + " <gml:name>urn:OGC:phenomenon-007</gml:name>" + '\n' + " </swe:Phenomenon>" + '\n' + " </om:observedProperty>" + '\n' + " <om:featureOfInterest>" + '\n' + " <sampling:SamplingPoint gml:id=\"samplingID-007\">" + '\n' + " <gml:description>a sampling Test</gml:description>" + '\n' + " <gml:name>urn:sampling:test:007</gml:name>" + '\n' + " <gml:boundedBy>" + '\n' + " <gml:Null>not_bounded</gml:Null>" + '\n' + " </gml:boundedBy>" + '\n' + " <sampling:sampledFeature xlink:href=\"\"/>" + '\n' + " <sampling:position>" + '\n' + " <gml:Point gml:id=\"point-ID\">" + '\n' + " <gml:pos srsName=\"urn:ogc:crs:espg:4326\" srsDimension=\"2\">3.2 6.5</gml:pos>" + '\n' + " </gml:Point>" + '\n' + " </sampling:position>" + '\n' + " </sampling:SamplingPoint>" + '\n' + " </om:featureOfInterest>" + '\n' + " <om:result xsi:type=\"om:MeasureType\" uom=\"meters\">7.0</om:result>" + '\n' + "</om:Measurement>\n";
assertXmlEquals(expResult, result, "xmlns:*");
ObservationCollectionType collection = new ObservationCollectionType();
collection.add(measmt);
sw = new StringWriter();
marshaller.marshal(collection, sw);
result = sw.toString();
// System.out.println(result);
collection = new ObservationCollectionType();
collection.add(obs.getTemporaryTemplate("temporaryName", samplingTime));
sw = new StringWriter();
marshaller.marshal(collection, sw);
result = sw.toString();
}
Aggregations