use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.
the class FieldDecoder method decodeJSON.
public SweField decodeJSON(JsonNode node) throws DecodingException {
final String type = node.path(JSONConstants.TYPE).textValue();
final SweAbstractDataComponent element;
if (type.equals(JSONConstants.BOOLEAN_TYPE)) {
element = decodeBoolean(node);
} else if (type.equals(JSONConstants.COUNT_TYPE)) {
element = decodeCount(node);
} else if (type.equals(JSONConstants.COUNT_RANGE_TYPE)) {
element = decodeCountRange(node);
} else if (type.equals(JSONConstants.OBSERVABLE_PROPERTY_TYPE)) {
element = decodeObservableProperty(node);
} else if (type.equals(JSONConstants.QUALITY_TYPE)) {
element = decodeQuality(node);
} else if (type.equals(JSONConstants.TEXT_TYPE)) {
element = decodeText(node);
} else if (type.equals(JSONConstants.QUANTITY_TYPE)) {
element = decodeQuantity(node);
} else if (type.equals(JSONConstants.QUANTITY_RANGE_TYPE)) {
element = decodeQuantityRange(node);
} else if (type.equals(JSONConstants.TIME_TYPE)) {
element = decodeTime(node);
} else if (type.equals(JSONConstants.TIME_RANGE_TYPE)) {
element = decodeTimeRange(node);
} else if (type.equals(JSONConstants.CATEGORY_TYPE)) {
element = decodeCategory(node);
} else {
throw new UnsupportedDecoderInputException(this, node);
}
final String name = node.path(JSONConstants.NAME).textValue();
element.setDescription(node.path(JSONConstants.DESCRIPTION).textValue());
element.setIdentifier(node.path(JSONConstants.IDENTIFIER).textValue());
element.setDefinition(node.path(JSONConstants.DEFINITION).textValue());
element.setLabel(node.path(JSONConstants.LABEL).textValue());
return new SweField(name, element);
}
use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.
the class GeoJSONDecoder method decodeCRS.
protected GeometryFactory decodeCRS(JsonNode node, GeometryFactory factory) throws GeoJSONDecodingException {
if (!node.path(JSONConstants.CRS).hasNonNull(JSONConstants.TYPE)) {
throw new GeoJSONDecodingException("Missing CRS type");
}
String type = node.path(JSONConstants.CRS).path(JSONConstants.TYPE).textValue();
JsonNode properties = node.path(JSONConstants.CRS).path(JSONConstants.PROPERTIES);
switch(type) {
case JSONConstants.NAME:
return decodeNamedCRS(properties, factory);
case JSONConstants.LINK:
return decodeLinkedCRS(properties, factory);
default:
throw new GeoJSONDecodingException("Unknown CRS type: " + type);
}
}
use of org.n52.shetland.w3c.xlink.Type 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.w3c.xlink.Type in project arctic-sea by 52North.
the class CountObservationDecodingTest method testObservation.
@Test
public void testObservation() {
assertThat(observation, is(notNullValue()));
final String type = observation.getObservationConstellation().getObservationType();
assertThat(type, is(equalTo(OmConstants.OBS_TYPE_COUNT_OBSERVATION)));
final ObservationValue<?> value = observation.getValue();
assertThat(value, is(instanceOf(SingleObservationValue.class)));
assertThat(value.getPhenomenonTime(), is(instanceOf(TimeInstant.class)));
TimeInstant pt = (TimeInstant) value.getPhenomenonTime();
assertThat(pt.getValue(), is(equalTo(phenomenonTime)));
assertThat(value.getValue(), is(instanceOf(CountValue.class)));
CountValue v = (CountValue) value.getValue();
assertThat(v.getValue(), is(1));
assertThat(v.getUnit(), is(nullValue()));
}
use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.
the class TruthObservationDecodingTest method testObservation.
@Test
public void testObservation() {
assertThat(observation, is(notNullValue()));
final String type = observation.getObservationConstellation().getObservationType();
assertThat(type, is(equalTo(OmConstants.OBS_TYPE_TRUTH_OBSERVATION)));
final ObservationValue<?> value = observation.getValue();
assertThat(value, is(instanceOf(SingleObservationValue.class)));
assertThat(value.getPhenomenonTime(), is(instanceOf(TimeInstant.class)));
TimeInstant pt = (TimeInstant) value.getPhenomenonTime();
assertThat(pt.getValue(), is(equalTo(phenomenonTime)));
assertThat(value.getValue(), is(instanceOf(BooleanValue.class)));
BooleanValue v = (BooleanValue) value.getValue();
assertThat(v.getValue(), is(true));
assertThat(v.getUnit(), is(nullValue()));
}
Aggregations