use of org.n52.shetland.ogc.swe.simpleType.SweTime in project arctic-sea by 52North.
the class SweDataArrayValue method getPhenomenonTime.
@Override
public Time getPhenomenonTime() {
final TimePeriod timePeriod = new TimePeriod();
Set<Integer> dateTokenIndizes = Sets.newHashSet();
if (getValue() != null && getValue().getElementType() != null && getValue().getEncoding() != null) {
// get index of time token from elementtype
if (getValue().getElementType() instanceof SweDataRecord) {
final SweDataRecord elementType = (SweDataRecord) getValue().getElementType();
final List<SweField> fields = elementType.getFields();
for (int i = 0; i < fields.size(); i++) {
final SweField sweField = fields.get(i);
if (sweField.getElement() instanceof SweTime || sweField.getElement() instanceof SweTimeRange) {
if (checkFieldNameAndElementDefinition(sweField)) {
dateTokenIndizes.add(i);
}
}
}
}
if (CollectionHelper.isNotEmpty(dateTokenIndizes)) {
for (final List<String> block : getValue().getValues()) {
// datetimehelper to DateTime from joda time
for (Integer index : dateTokenIndizes) {
String token = null;
try {
token = block.get(index);
final Time time = DateTimeHelper.parseIsoString2DateTime2Time(token);
timePeriod.extendToContain(time);
} catch (final DateTimeParseException dte) {
LOGGER.error(String.format("Could not parse ISO8601 string \"%s\"", token), dte);
// try next block;
continue;
}
}
}
} else {
final String errorMsg = "PhenomenonTime field could not be found in ElementType";
LOGGER.error(errorMsg);
}
} else {
final String errorMsg = String.format("Value of type \"%s\" not set correct.", SweDataArrayValue.class.getName());
LOGGER.error(errorMsg);
}
return timePeriod;
}
use of org.n52.shetland.ogc.swe.simpleType.SweTime in project arctic-sea by 52North.
the class SweHelper method getPhenomenonTimeField.
private SweField getPhenomenonTimeField(Time sosTime) {
SweAbstractUomType<?> time;
if (sosTime instanceof TimePeriod) {
time = new SweTimeRange();
} else {
time = new SweTime();
}
time.setDefinition(OmConstants.PHENOMENON_TIME);
time.setUom(OmConstants.PHEN_UOM_ISO8601);
return new SweField(OmConstants.PHENOMENON_TIME_NAME, time);
}
use of org.n52.shetland.ogc.swe.simpleType.SweTime in project arctic-sea by 52North.
the class FieldDecoderTest method time.
@Test
public void time() throws DecodingException {
ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.TIME_TYPE).put(JSONConstants.UOM, UOM);
SweField field = checkCommon(json, false);
assertThat(field.getElement(), is(instanceOf(SweTime.class)));
SweTime swe = (SweTime) field.getElement();
errors.checkThat(swe.getValue(), is(nullValue()));
errors.checkThat(swe.getUom(), is(UOM));
}
use of org.n52.shetland.ogc.swe.simpleType.SweTime in project arctic-sea by 52North.
the class FieldDecoderTest method timeWithValue.
@Test
public void timeWithValue() throws DecodingException {
ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.TIME_TYPE).put(JSONConstants.UOM, UOM).put(JSONConstants.VALUE, TIME_START);
SweField field = checkCommon(json, true);
assertThat(field.getElement(), is(instanceOf(SweTime.class)));
SweTime swe = (SweTime) field.getElement();
errors.checkThat(swe.getValue(), is(timeStart));
errors.checkThat(swe.getUom(), is(UOM));
}
use of org.n52.shetland.ogc.swe.simpleType.SweTime in project arctic-sea by 52North.
the class InsertResultTemplateRequestDecoderTest method resultStructure.
@Test
public void resultStructure() throws IOException, DecodingException {
InsertResultTemplateRequest req = load();
assertThat(req.getResultStructure(), is(notNullValue()));
assertThat(req.getResultStructure().isDecoded(), is(true));
assertThat(req.getResultStructure().isEncoded(), is(false));
assertThat(req.getResultStructure().get().get(), is(instanceOf(SweDataRecord.class)));
SweDataRecord structure = (SweDataRecord) req.getResultStructure().get().get();
assertThat(structure.getFields(), is(notNullValue()));
assertThat(structure.getFields(), hasSize(3));
SweField field1 = structure.getFields().get(0);
assertThat(field1, is(notNullValue()));
errors.checkThat(field1.getName().getValue(), is("phenomenonTime"));
assertThat(field1.getElement(), is(instanceOf(SweTimeRange.class)));
SweTimeRange phenomenonTime = (SweTimeRange) field1.getElement();
errors.checkThat(phenomenonTime.getDefinition(), is("http://www.opengis.net/def/property/OGC/0/PhenomenonTime"));
errors.checkThat(phenomenonTime.getUom(), is("http://www.opengis.net/def/uom/ISO-8601/0/Gregorian"));
SweField field2 = structure.getFields().get(1);
assertThat(field2, is(notNullValue()));
errors.checkThat(field2.getName().getValue(), is("resultTime"));
assertThat(field2.getElement(), is(instanceOf(SweTime.class)));
SweTime resultTime = (SweTime) field2.getElement();
errors.checkThat(resultTime.getDefinition(), is("http://www.opengis.net/def/property/OGC/0/ResultTime"));
errors.checkThat(resultTime.getUom(), is("testunit1"));
SweField field3 = structure.getFields().get(2);
assertThat(field3, is(notNullValue()));
errors.checkThat(field3.getName().getValue(), is("observable_property_6"));
assertThat(field3.getElement(), is(instanceOf(SweQuantity.class)));
SweQuantity quantity = (SweQuantity) field3.getElement();
errors.checkThat(quantity.getDefinition(), is("http://www.52north.org/test/observableProperty/6"));
errors.checkThat(quantity.getUom(), is("test_unit_6"));
}
Aggregations