use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class SweHelper method createElementType.
private SweAbstractDataComponent createElementType(TimeValuePair tvp, String name) throws EncodingException {
SweDataRecord dataRecord = new SweDataRecord();
dataRecord.addField(getPhenomenonTimeField(tvp.getTime()));
dataRecord.addField(getFieldForValue(tvp.getValue(), name));
return dataRecord;
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class SweHelper method createSosSweDataArray.
/**
* Create {@link SweDataArray} from {@link AbstractObservationValue}
*
* @param observationValue
* The {@link AbstractObservationValue} to create
* {@link SweDataArray} from
*
* @return Created {@link SweDataArray}
*
* @throws EncodingException
* If the service does not support the {@link SweDataArray}
* creation from {@link AbstractObservationValue}
*/
public SweDataArray createSosSweDataArray(AbstractObservationValue<?> observationValue) throws EncodingException {
String observablePropertyIdentifier = observationValue.getObservableProperty();
SweDataArrayValue dataArrayValue = new SweDataArrayValue();
SweDataArray dataArray = new SweDataArray();
dataArray.setEncoding(createTextEncoding(observationValue));
dataArrayValue.setValue(dataArray);
if (observationValue instanceof SingleObservationValue) {
SingleObservationValue<?> singleValue = (SingleObservationValue<?>) observationValue;
if (singleValue.getValue() instanceof SweDataArrayValue) {
return (SweDataArray) singleValue.getValue().getValue();
} else {
dataArray.setElementType(createElementType(singleValue, observablePropertyIdentifier));
dataArrayValue.addBlock(createBlock(dataArray.getElementType(), observationValue.getPhenomenonTime(), observablePropertyIdentifier, singleValue.getValue()));
}
} else if (observationValue instanceof MultiObservationValues) {
MultiObservationValues<?> multiValue = (MultiObservationValues<?>) observationValue;
if (multiValue.getValue() instanceof SweDataArrayValue) {
return ((SweDataArrayValue) multiValue.getValue()).getValue();
} else if (multiValue.getValue() instanceof TVPValue) {
TVPValue tvpValues = (TVPValue) multiValue.getValue();
for (TimeValuePair timeValuePair : tvpValues.getValue()) {
if (timeValuePair != null && timeValuePair.getValue() != null && timeValuePair.getValue().isSetValue()) {
if (!dataArray.isSetElementTyp()) {
dataArray.setElementType(createElementType(timeValuePair, observablePropertyIdentifier));
}
List<String> newBlock = createBlock(dataArray.getElementType(), timeValuePair.getTime(), observablePropertyIdentifier, timeValuePair.getValue());
dataArrayValue.addBlock(newBlock);
}
}
}
}
return dataArray;
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class SweHelper method createSosSweDataArray.
/**
* Create {@link SweDataArray} from {@link OmObservation}
*
* @param sosObservation
* The {@link OmObservation} to create {@link SweDataArray} from
*
* @return Created {@link SweDataArray}
*
* @throws EncodingException
* If the service does not support the {@link SweDataArray}
* creation from value of {@link OmObservation}
*/
public SweDataArray createSosSweDataArray(OmObservation sosObservation) throws EncodingException {
String observablePropertyIdentifier = sosObservation.getObservationConstellation().getObservableProperty().getIdentifier();
SweDataArrayValue dataArrayValue = new SweDataArrayValue();
SweDataArray dataArray = new SweDataArray();
dataArray.setEncoding(createTextEncoding(sosObservation));
dataArrayValue.setValue(dataArray);
if (sosObservation.getValue() instanceof SingleObservationValue) {
SingleObservationValue<?> singleValue = (SingleObservationValue<?>) sosObservation.getValue();
if (singleValue.getValue() instanceof SweDataArrayValue) {
return (SweDataArray) singleValue.getValue().getValue();
} else {
dataArray.setElementType(createElementType(singleValue, observablePropertyIdentifier));
dataArrayValue.addBlock(createBlock(dataArray.getElementType(), sosObservation.getPhenomenonTime(), observablePropertyIdentifier, singleValue.getValue()));
}
} else if (sosObservation.getValue() instanceof MultiObservationValues) {
MultiObservationValues<?> multiValue = (MultiObservationValues<?>) sosObservation.getValue();
if (multiValue.getValue() instanceof SweDataArrayValue) {
return ((SweDataArrayValue) multiValue.getValue()).getValue();
} else if (multiValue.getValue() instanceof TVPValue) {
TVPValue tvpValues = (TVPValue) multiValue.getValue();
for (TimeValuePair timeValuePair : tvpValues.getValue()) {
if (timeValuePair != null && timeValuePair.getValue() != null && timeValuePair.getValue().isSetValue()) {
if (!dataArray.isSetElementTyp()) {
dataArray.setElementType(createElementType(timeValuePair, observablePropertyIdentifier));
}
List<String> newBlock = createBlock(dataArray.getElementType(), timeValuePair.getTime(), observablePropertyIdentifier, timeValuePair.getValue());
dataArrayValue.addBlock(newBlock);
}
}
}
}
return dataArray;
}
use of org.n52.svalbard.encode.exception.EncodingException 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.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class ExiEncoder method encode.
@Override
public EXIObject<XmlObject> encode(T response) throws EncodingException {
Encoder<Object, T> encoder = getEncoder(response);
Object encode = encoder.encode(response);
if (encode != null && encode instanceof XmlObject) {
return new EXIObject<XmlObject>((XmlObject) encode);
} else {
throw new UnsupportedEncoderInputException(encoder, response);
}
}
Aggregations