use of org.n52.shetland.ogc.swe.RangeValue in project arctic-sea by 52North.
the class SweCommonDecoderV20 method parseAllowedTimes.
@SuppressWarnings("rawtypes")
private SweAllowedTimes parseAllowedTimes(AllowedTimesType att) throws DateTimeParseException {
SweAllowedTimes allowedTimes = new SweAllowedTimes();
if (att.isSetId()) {
allowedTimes.setGmlId(att.getId());
}
if (CollectionHelper.isNotNullOrEmpty(att.getValueArray())) {
for (Object value : att.getValueArray()) {
allowedTimes.addValue(DateTimeHelper.parseIsoString2DateTime(value.toString()));
}
}
if (CollectionHelper.isNotNullOrEmpty(att.getIntervalArray())) {
for (List interval : att.getIntervalArray()) {
RangeValue<DateTime> rangeValue = new RangeValue<DateTime>();
Iterator iterator = interval.iterator();
if (iterator.hasNext()) {
rangeValue.setRangeStart(DateTimeHelper.parseIsoString2DateTime(iterator.next().toString()));
}
if (iterator.hasNext()) {
rangeValue.setRangeEnd(DateTimeHelper.parseIsoString2DateTime(iterator.next().toString()));
}
allowedTimes.addInterval(rangeValue);
}
}
if (att.isSetSignificantFigures()) {
allowedTimes.setSignificantFigures(att.getSignificantFigures());
}
return allowedTimes;
}
use of org.n52.shetland.ogc.swe.RangeValue in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldTimeRange.
@Test
public void should_encode_Datarecord_with_fieldTimeRange() throws EncodingException {
final String field1Name = "test-name";
final RangeValue<DateTime> field1Value = new RangeValue<DateTime>();
final long now = System.currentTimeMillis();
final DateTime rangeStart = new DateTime(now - 1000);
final DateTime rangeEnd = new DateTime(now + 1000);
field1Value.setRangeStart(rangeStart);
field1Value.setRangeEnd(rangeEnd);
final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweTimeRange().setValue(field1Value))));
assertThat(encode, is(instanceOf(DataRecordType.class)));
final DataRecordType xbDataRecord = (DataRecordType) encode;
assertThat(xbDataRecord.getFieldArray().length, is(1));
final DataComponentPropertyType field1 = xbDataRecord.getFieldArray(0);
assertThat(field1.isSetTimeRange(), is(TRUE));
final DateTime xbTimeRangeStart = new DateTime(((XmlCalendar) field1.getTimeRange().getValue().get(0)).getTimeInMillis());
final DateTime xbTimeRangeEnd = new DateTime(((XmlCalendar) field1.getTimeRange().getValue().get(1)).getTimeInMillis());
assertThat(field1.getName(), is(field1Name));
assertThat(xbTimeRangeStart, is(field1Value.getRangeStart()));
assertThat(xbTimeRangeEnd, is(field1Value.getRangeEnd()));
}
use of org.n52.shetland.ogc.swe.RangeValue in project arctic-sea by 52North.
the class SweCommonDecoderV101Test method should_decode_Category_with_Quality_QuantityRange.
@Test
public void should_decode_Category_with_Quality_QuantityRange() throws DecodingException {
final CategoryDocument xbQuantity = CategoryDocument.Factory.newInstance();
final BigDecimal rangeStart = BigDecimal.valueOf(1.0);
final BigDecimal rangeEnd = BigDecimal.valueOf(2.0);
final ArrayList<BigDecimal> categoryValue = Lists.newArrayList(rangeStart, rangeEnd);
xbQuantity.addNewCategory().addNewQuality().addNewQuantityRange().setValue(categoryValue);
final Object decodedObject = new SweCommonDecoderV101().decode(xbQuantity);
assertThat(decodedObject, is(instanceOf(SweCategory.class)));
final SweCategory sweCategory = (SweCategory) decodedObject;
assertThat(sweCategory.isSetQuality(), is(true));
assertThat(sweCategory.getQuality().size(), is(1));
assertThat(sweCategory.getQuality().iterator().next(), is(instanceOf(SweQuantityRange.class)));
assertThat(((SweQuantityRange) sweCategory.getQuality().iterator().next()).getValue(), is(new RangeValue<BigDecimal>(rangeStart, rangeEnd)));
}
use of org.n52.shetland.ogc.swe.RangeValue in project arctic-sea by 52North.
the class FieldDecoder method decodeCountRange.
protected SweAbstractDataComponent decodeCountRange(JsonNode node) {
SweCountRange swe = new SweCountRange();
if (node.hasNonNull(JSONConstants.VALUE)) {
int start = node.path(JSONConstants.VALUE).path(0).intValue();
int end = node.path(JSONConstants.VALUE).path(1).intValue();
swe.setValue(new RangeValue<Integer>(start, end));
}
return swe;
}
use of org.n52.shetland.ogc.swe.RangeValue in project arctic-sea by 52North.
the class SweCommonDecoderV101 method parseCountRange.
private SweCountRange parseCountRange(CountRange xbCountRange) throws DecodingException {
SweCountRange sosCountRange = new SweCountRange();
// }
if (xbCountRange.getQualityArray() != null) {
sosCountRange.setQuality(parseQuality(xbCountRange.getQualityArray()));
}
// }
if (xbCountRange.isSetDefinition()) {
sosCountRange.setDefinition(xbCountRange.getDefinition());
}
if (xbCountRange.isSetDescription()) {
sosCountRange.setDescription(xbCountRange.getDescription().getStringValue());
}
if (xbCountRange.isSetValue()) {
List<?> value = xbCountRange.getValue();
Integer rangeStart = Integer.parseInt(value.get(0).toString());
Integer rangeEnd = Integer.parseInt(value.get(1).toString());
sosCountRange.setValue(new RangeValue<>(rangeStart, rangeEnd));
}
return sosCountRange;
}
Aggregations