use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class Iso19139GmdEncoder method encodeEXExtent.
private XmlObject encodeEXExtent(EXExtent exExtent, EncodingContext context) throws EncodingException {
EXExtentType exet = EXExtentType.Factory.newInstance();
if (exExtent.hasDescription()) {
exet.addNewDescription().setCharacterString(exExtent.getDescription());
}
if (exExtent.hasVerticalExtent()) {
for (Referenceable<EXVerticalExtent> verticalExtent : exExtent.getExVerticalExtent()) {
EXVerticalExtentPropertyType exvept = exet.addNewVerticalElement();
if (verticalExtent.isReference()) {
Reference reference = verticalExtent.getReference();
reference.getActuate().map(Actuate::toString).map(ActuateType.Enum::forString).ifPresent(exvept::setActuate);
reference.getArcrole().ifPresent(exvept::setArcrole);
reference.getHref().map(URI::toString).ifPresent(exvept::setHref);
reference.getRole().ifPresent(exvept::setRole);
reference.getShow().map(Show::toString).map(ShowType.Enum::forString).ifPresent(exvept::setShow);
reference.getTitle().ifPresent(exvept::setTitle);
reference.getType().map(Type::toString).map(TypeType.Enum::forString).ifPresent(exvept::setType);
} else {
if (verticalExtent.isInstance()) {
Nillable<EXVerticalExtent> nillable = verticalExtent.getInstance();
if (nillable.isPresent()) {
XmlObject xml = encodeEXVerticalExtent(nillable.get(), EncodingContext.empty());
if (xml != null && xml instanceof EXVerticalExtentType) {
exvept.setEXVerticalExtent((EXVerticalExtentType) xml);
} else {
exvept.setNil();
exvept.setNilReason(Nillable.missing().get());
}
} else {
exvept.setNil();
if (nillable.hasReason()) {
exvept.setNilReason(nillable.getNilReason().get());
} else {
exvept.setNilReason(Nillable.missing().get());
}
}
}
}
}
}
if (context.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
EXExtentPropertyType exept = EXExtentPropertyType.Factory.newInstance(getXmlOptions());
exept.setEXExtent(exet);
return exept;
} else if (context.has(XmlBeansEncodingFlags.DOCUMENT)) {
EXExtentDocument exed = EXExtentDocument.Factory.newInstance(getXmlOptions());
exed.setEXExtent(exet);
return exed;
}
return exet;
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class Iso19139GmdEncoder method encodeEXVerticalExtent.
private XmlObject encodeEXVerticalExtent(EXVerticalExtent exVerticalExtent, EncodingContext context) throws EncodingException {
EXVerticalExtentType exvet = EXVerticalExtentType.Factory.newInstance();
if (exVerticalExtent.isSetId()) {
exvet.setId(exVerticalExtent.getId());
}
if (exVerticalExtent.isSetUuid()) {
exvet.setUuid(exVerticalExtent.getUuid());
}
// min value
Nillable<Double> minNillable = exVerticalExtent.getMinimumValue();
RealPropertyType rptMinValue = exvet.addNewMinimumValue();
if (minNillable.isPresent()) {
rptMinValue.setReal(minNillable.get());
} else {
rptMinValue.setNil();
if (minNillable.hasReason()) {
rptMinValue.setNilReason(minNillable.getNilReason().get());
} else {
rptMinValue.setNilReason(Nillable.missing().get());
}
}
// max value
Nillable<Double> maxNillable = exVerticalExtent.getMaximumValue();
RealPropertyType rptMinMaxValue = exvet.addNewMaximumValue();
if (maxNillable.isPresent()) {
rptMinMaxValue.setReal(maxNillable.get());
} else {
rptMinMaxValue.setNil();
if (maxNillable.hasReason()) {
rptMinMaxValue.setNilReason(maxNillable.getNilReason().get());
} else {
rptMinMaxValue.setNilReason(Nillable.missing().get());
}
}
// verticalCRS
SCCRSPropertyType sccrspt = exvet.addNewVerticalCRS();
Referenceable<ScCRS> verticalCRS = exVerticalExtent.getVerticalCRS();
if (verticalCRS.isReference()) {
Reference reference = verticalCRS.getReference();
reference.getActuate().map(Actuate::toString).map(ActuateType.Enum::forString).ifPresent(sccrspt::setActuate);
reference.getArcrole().ifPresent(sccrspt::setArcrole);
reference.getHref().map(URI::toString).ifPresent(sccrspt::setHref);
reference.getRole().ifPresent(sccrspt::setRole);
reference.getShow().map(Show::toString).map(ShowType.Enum::forString).ifPresent(sccrspt::setShow);
reference.getTitle().ifPresent(sccrspt::setTitle);
reference.getType().map(Type::toString).map(TypeType.Enum::forString).ifPresent(sccrspt::setType);
} else {
if (verticalCRS.isInstance()) {
Nillable<ScCRS> nillable = verticalCRS.getInstance();
if (nillable.isPresent()) {
XmlObject xml = encodeObjectToXml(GmlConstants.NS_GML_32, nillable.get().getAbstractCrs());
if (xml != null && xml instanceof AbstractCRSType) {
final XmlObject substituteElement = XmlHelper.substituteElement(sccrspt.addNewAbstractCRS(), xml);
substituteElement.set(xml);
} else {
sccrspt.setNil();
sccrspt.setNilReason(Nillable.missing().get());
}
} else {
sccrspt.setNil();
if (nillable.hasReason()) {
sccrspt.setNilReason(nillable.getNilReason().get());
} else {
sccrspt.setNilReason(Nillable.missing().get());
}
}
}
}
if (context.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
EXVerticalExtentPropertyType exvept = EXVerticalExtentPropertyType.Factory.newInstance(getXmlOptions());
exvept.setEXVerticalExtent(exvet);
return exvept;
} else if (context.has(XmlBeansEncodingFlags.DOCUMENT)) {
EXVerticalExtentDocument exved = EXVerticalExtentDocument.Factory.newInstance(getXmlOptions());
exved.setEXVerticalExtent(exvet);
return exved;
}
return exvet;
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class OmEncoderv100 method addResultTime.
private void addResultTime(ObservationType xbObs, OmObservation sosObservation) throws EncodingException {
Time phenomenonTime = sosObservation.getPhenomenonTime();
if (sosObservation.isSetResultTime()) {
if (sosObservation.getResultTime().equals(phenomenonTime)) {
xbObs.addNewResultTime().setHref("#".concat(phenomenonTime.getGmlId()));
} else {
TimeInstant resultTime = sosObservation.getResultTime();
if (!resultTime.isSetGmlId()) {
resultTime.setGmlId(RESULT_TIME_ID_PREFIX.concat(sosObservation.getObservationID()));
}
addResultTime(xbObs, resultTime);
}
} else {
if (phenomenonTime instanceof TimeInstant) {
xbObs.addNewResultTime().setHref("#".concat(phenomenonTime.getGmlId()));
} else if (phenomenonTime instanceof TimePeriod) {
TimeInstant resultTime = new TimeInstant(((TimePeriod) sosObservation.getPhenomenonTime()).getEnd());
resultTime.setGmlId(RESULT_TIME_ID_PREFIX + sosObservation.getObservationID());
addResultTime(xbObs, resultTime);
}
}
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class OmEncoderv100 method encode.
@Override
public XmlObject encode(Object element, EncodingContext additionalValues) throws EncodingException {
XmlObject encodedObject = null;
if (element instanceof OmObservation) {
encodedObject = createObservation((OmObservation) element, additionalValues);
} else if (element instanceof GetObservationResponse) {
GetObservationResponse response = (GetObservationResponse) element;
encodedObject = createObservationCollection(response.getObservationCollection(), response.getResultModel());
} else if (element instanceof GetObservationByIdResponse) {
GetObservationByIdResponse response = (GetObservationByIdResponse) element;
encodedObject = createObservationCollection(response.getObservationCollection(), response.getResultModel());
} else {
throw new UnsupportedEncoderInputException(this, element);
}
XmlHelper.validateDocument(encodedObject, EncodingException::new);
return encodedObject;
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class OmEncoderv100 method addSingleObservationToResult.
// FIXME String.equals(QName) !?
private void addSingleObservationToResult(XmlObject xbResult, OmObservation sosObservation) throws EncodingException {
String observationType = sosObservation.getObservationConstellation().getObservationType();
SingleObservationValue<?> observationValue = (SingleObservationValue<?>) sosObservation.getValue();
if (observationValue.getValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) observationValue.getValue();
xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, quantityValue));
} else if (observationValue.getValue() instanceof CountValue) {
CountValue countValue = (CountValue) observationValue.getValue();
XmlInteger xbInteger = XmlInteger.Factory.newInstance(getXmlOptions());
if (countValue.getValue() != null && countValue.getValue() != Integer.MIN_VALUE) {
xbInteger.setBigIntegerValue(new BigInteger(countValue.getValue().toString()));
} else {
xbInteger.setNil();
}
xbResult.set(xbInteger);
} else if (observationValue.getValue() instanceof TextValue) {
TextValue textValue = (TextValue) observationValue.getValue();
XmlString xbString = XmlString.Factory.newInstance(getXmlOptions());
if (textValue.getValue() != null && !textValue.getValue().isEmpty()) {
xbString.setStringValue(textValue.getValue());
} else {
xbString.setNil();
}
xbResult.set(xbString);
} else if (observationValue.getValue() instanceof BooleanValue) {
BooleanValue booleanValue = (BooleanValue) observationValue.getValue();
XmlBoolean xbBoolean = XmlBoolean.Factory.newInstance(getXmlOptions());
if (booleanValue.getValue() != null) {
xbBoolean.setBooleanValue(booleanValue.getValue());
} else {
xbBoolean.setNil();
}
xbResult.set(xbBoolean);
} else if (observationValue.getValue() instanceof CategoryValue) {
CategoryValue categoryValue = (CategoryValue) observationValue.getValue();
if (categoryValue.getValue() != null && !categoryValue.getValue().isEmpty()) {
xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, categoryValue, EncodingContext.of(XmlBeansEncodingFlags.GMLID, SosConstants.OBS_ID_PREFIX + sosObservation.getObservationID())));
} else {
xbResult.setNil();
}
} else if (observationValue.getValue() instanceof GeometryValue) {
GeometryValue geometryValue = (GeometryValue) observationValue.getValue();
if (geometryValue.getValue() != null) {
xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, geometryValue.getValue(), EncodingContext.of(XmlBeansEncodingFlags.GMLID, SosConstants.OBS_ID_PREFIX + sosObservation.getObservationID())));
} else {
xbResult.setNil();
}
} else if (OmConstants.OBS_TYPE_SWE_ARRAY_OBSERVATION.equals(observationType) || OmConstants.RESULT_MODEL_OBSERVATION.getLocalPart().equals(observationType)) {
SweDataArray dataArray = sweHelper.createSosSweDataArray(sosObservation);
xbResult.set(encodeObjectToXml(SweConstants.NS_SWE_101, dataArray, EncodingContext.of(XmlBeansEncodingFlags.FOR_OBSERVATION)));
}
}
Aggregations