use of net.opengis.gml.x32.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 net.opengis.gml.x32.TimePeriodType in project arctic-sea by 52North.
the class GmlDecoderv321 method parseTimePeriod.
/**
* creates SOS representation of time period from XMLBeans representation of time period
*
* @param xbTimePeriod XMLBeans representation of time period
*
* @return Returns SOS representation of time period
*
* @throws DecodingException if the time string is invalid
*/
private Object parseTimePeriod(TimePeriodType xbTimePeriod) throws DecodingException {
// begin position
TimePositionType xbBeginTPT = xbTimePeriod.getBeginPosition();
TimeInstant begin = null;
if (xbBeginTPT != null) {
begin = parseTimePosition(xbBeginTPT);
} else {
throw new DecodingException("gml:TimePeriod must contain gml:beginPosition Element with valid ISO:8601 String!");
}
// end position
TimePositionType xbEndTPT = xbTimePeriod.getEndPosition();
TimeInstant end = null;
if (xbEndTPT != null) {
end = parseTimePosition(xbEndTPT);
} else {
throw new DecodingException("gml:TimePeriod must contain gml:endPosition Element with valid ISO:8601 String!");
}
TimePeriod timePeriod = new TimePeriod(begin, end);
timePeriod.setGmlId(xbTimePeriod.getId());
return timePeriod;
}
use of net.opengis.gml.x32.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 net.opengis.gml.x32.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 net.opengis.gml.x32.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));
}
Aggregations