use of org.n52.shetland.ogc.gml.time.TimePeriod 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.gml.time.TimePeriod 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.gml.time.TimePeriod in project arctic-sea by 52North.
the class UVFEncoder method encodeToUvf.
private File encodeToUvf(ObservationStream observationStream, File tempDir, MediaType contentType) throws IOException, EncodingException {
List<OmObservation> mergeObservations = mergeTotoList(observationStream);
String ending = getLineEnding(contentType);
String filename = getFilename(mergeObservations);
File uvfFile = new File(tempDir, filename);
try (Writer fw = new OutputStreamWriter(new FileOutputStream(uvfFile), "UTF-8")) {
for (OmObservation o : mergeObservations) {
if (o.isSetValue() && !checkForSingleObservationValue(o.getValue()) && !checkForMultiObservationValue(o.getValue())) {
String errorMessage = String.format("The resulting values are not of numeric type " + "which is only supported by this encoder '%s'.", this.getClass().getName());
LOGGER.error(errorMessage);
throw new EncodingException(errorMessage);
}
/*
* HEADER: Metadata
*/
writeFunktionInterpretation(fw, o, ending);
writeIndex(fw, ending);
writeMessGroesse(fw, o, ending);
writeMessEinheit(fw, o, ending);
writeMessStellennummer(fw, o, ending);
writeMessStellenname(fw, o, ending);
/*
* HEADER: Lines 1 - 4
*/
writeLine1(fw, ending);
TimePeriod temporalBBox = getTemporalBBoxFromObservations(mergeObservations);
writeLine2(fw, o, temporalBBox, ending);
writeLine3(fw, o, ending);
writeLine4(fw, temporalBBox, ending);
/*
* Observation Data
*/
writeObservationValue(fw, o, ending);
}
}
return uvfFile;
}
use of org.n52.shetland.ogc.gml.time.TimePeriod in project arctic-sea by 52North.
the class TimeJSONEncoder method encodeJSON.
@Override
public JsonNode encodeJSON(Time time) {
if (time instanceof TimeInstant) {
TimeInstant ti = (TimeInstant) time;
return nodeFactory().textNode(encodeTimePosition(ti.getTimePosition()));
}
if (time instanceof TimePeriod) {
TimePeriod tp = (TimePeriod) time;
ArrayNode a = nodeFactory().arrayNode();
a.add(encodeTimePosition(tp.getStartTimePosition()));
a.add(encodeTimePosition(tp.getEndTimePosition()));
return a;
} else {
return null;
}
}
use of org.n52.shetland.ogc.gml.time.TimePeriod in project arctic-sea by 52North.
the class GetObservationRequestDecoderTest method hasSingleTemporalFilter.
@Test
public void hasSingleTemporalFilter() throws IOException, DecodingException {
final GetObservationRequest req = loadSingle();
assertThat(req.getTemporalFilters(), is(notNullValue()));
assertThat(req.getTemporalFilters(), hasSize(1));
assertThat(req.getTemporalFilters().get(0), is(notNullValue()));
assertThat(req.getTemporalFilters().get(0).getOperator(), is(TimeOperator.TM_Equals));
assertThat(req.getTemporalFilters().get(0).getValueReference(), is("om:phenomenonTime"));
assertThat(req.getTemporalFilters().get(0).getTime(), is(instanceOf(TimePeriod.class)));
final TimePeriod time = (TimePeriod) req.getTemporalFilters().get(0).getTime();
assertThat(time.getStart(), is(equalTo(new DateTime(2013, 01, 01, 00, 00, 00, 00, DateTimeZone.forOffsetHours(2)))));
assertThat(time.getEnd(), is(equalTo(new DateTime(2013, 01, 01, 01, 00, 00, 00, DateTimeZone.forOffsetHours(2)))));
}
Aggregations