use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.
the class OmEncoderv100 method addValuesToObservation.
private List<OmObservableProperty> addValuesToObservation(ObservationType xbObs, OmObservation sosObservation, EncodingContext additionalValues) throws EncodingException {
xbObs.setId(OBSERVATION_ID_PREFIX + Long.toString(System.currentTimeMillis()));
if (!sosObservation.isSetObservationID()) {
sosObservation.setObservationID(xbObs.getId().replace(OBSERVATION_ID_PREFIX, ""));
}
String observationID = sosObservation.getObservationID();
// set samplingTime
Time samplingTime = sosObservation.getPhenomenonTime();
if (samplingTime.getGmlId() == null) {
samplingTime.setGmlId(OmConstants.PHENOMENON_TIME_NAME + "_" + observationID);
}
addSamplingTime(xbObs, samplingTime);
// set resultTime
addResultTime(xbObs, sosObservation);
// set procedure
xbObs.addNewProcedure().setHref(sosObservation.getObservationConstellation().getProcedure().getIdentifier());
// set observedProperty (phenomenon)
List<OmObservableProperty> phenComponents = null;
if (sosObservation.getObservationConstellation().getObservableProperty() instanceof OmObservableProperty) {
xbObs.addNewObservedProperty().setHref(sosObservation.getObservationConstellation().getObservableProperty().getIdentifier());
phenComponents = new ArrayList<>(1);
phenComponents.add((OmObservableProperty) sosObservation.getObservationConstellation().getObservableProperty());
} else if (sosObservation.getObservationConstellation().getObservableProperty() instanceof OmCompositePhenomenon) {
OmCompositePhenomenon compPhen = (OmCompositePhenomenon) sosObservation.getObservationConstellation().getObservableProperty();
xbObs.addNewObservedProperty().setHref(compPhen.getIdentifier());
phenComponents = compPhen.getPhenomenonComponents();
}
// set feature
addFeatureOfInterest(xbObs, sosObservation.getObservationConstellation().getFeatureOfInterest());
return phenComponents;
}
use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.
the class OmEncoderv100 method createOmObservation.
private XmlObject createOmObservation(OmObservation sosObservation, EncodingContext additionalValues) throws EncodingException {
ObservationDocument xbObservationDoc = ObservationDocument.Factory.newInstance(getXmlOptions());
ObservationType xbObs = xbObservationDoc.addNewObservation();
List<OmObservableProperty> phenComponents = addValuesToObservation(xbObs, sosObservation, additionalValues);
addResultToObservation(xbObs.addNewResult(), sosObservation, phenComponents);
return xbObservationDoc;
}
use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.
the class GmlEncoderv311 method encode.
@Override
public XmlObject encode(Object element, EncodingContext ctx) throws EncodingException {
XmlObject encodedObject = null;
if (element instanceof Time) {
encodedObject = createTime((Time) element, ctx);
} else if (element instanceof Geometry) {
encodedObject = createPosition((Geometry) element, ctx.get(XmlBeansEncodingFlags.GMLID));
} else if (element instanceof CategoryValue) {
encodedObject = createReferenceTypeForCategroyValue((CategoryValue) element);
} else if (element instanceof org.n52.shetland.ogc.gml.ReferenceType) {
encodedObject = createReferencType((org.n52.shetland.ogc.gml.ReferenceType) element);
} else if (element instanceof CodeWithAuthority) {
encodedObject = createCodeWithAuthorityType((CodeWithAuthority) element);
} else if (element instanceof QuantityValue) {
encodedObject = createMeasureType((QuantityValue) element);
} else if (element instanceof org.n52.shetland.ogc.gml.CodeType) {
encodedObject = createCodeType((org.n52.shetland.ogc.gml.CodeType) element);
} else if (element instanceof AbstractFeature) {
encodedObject = createFeature((AbstractFeature) element);
} else if (element instanceof ReferencedEnvelope) {
encodedObject = createEnvelope((ReferencedEnvelope) element);
} else if (element instanceof EnvelopeOrGeometry) {
EnvelopeOrGeometry geom = (EnvelopeOrGeometry) element;
if (geom.getGeometry().isPresent()) {
encodedObject = createPosition(geom.getGeometry().get(), ctx.get(XmlBeansEncodingFlags.GMLID));
} else if (geom.getEnvelope().isPresent()) {
encodedObject = createEnvelope(geom.getEnvelope().get());
} else {
throw new UnsupportedEncoderInputException(this, element);
}
} else if (element instanceof GenericMetaData) {
encodedObject = createGenericMetaData((GenericMetaData) element, ctx);
} else {
throw new UnsupportedEncoderInputException(this, element);
}
XmlHelper.validateDocument(encodedObject, EncodingException::new);
return encodedObject;
}
use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.
the class GmlEncoderv321 method createFeature.
private XmlObject createFeature(AbstractFeature feature, EncodingContext ctx) throws EncodingException {
FeaturePropertyType featurePropertyType = FeaturePropertyType.Factory.newInstance(getXmlOptions());
if (isNotSamplingFeature(feature) || ctx.has(XmlBeansEncodingFlags.REFERENCED)) {
featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
return featurePropertyType;
} else {
AbstractSamplingFeature samplingFeature = (AbstractSamplingFeature) feature;
if (samplingFeature.isSetGmlID()) {
featurePropertyType.setHref("#" + samplingFeature.getGmlId());
return featurePropertyType;
} else {
if (ctx.has(XmlBeansEncodingFlags.ENCODE) && !ctx.getBoolean(XmlBeansEncodingFlags.ENCODE) || !samplingFeature.isEncode()) {
featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
if (feature instanceof SamplingFeature && samplingFeature.isSetName()) {
featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
}
return featurePropertyType;
}
if (!samplingFeature.isSetGeometry()) {
featurePropertyType.setHref(samplingFeature.getIdentifierCodeWithAuthority().getValue());
if (samplingFeature.isSetName()) {
featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
}
return featurePropertyType;
}
if (samplingFeature.isSetUrl()) {
featurePropertyType.setHref(samplingFeature.getUrl());
if (samplingFeature.isSetName()) {
featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
}
return featurePropertyType;
} else {
String namespace = ctx.getString(XmlEncoderFlags.ENCODE_NAMESPACE).orElseGet(() -> OMHelper.getNamespaceForFeatureType(samplingFeature.getFeatureType()));
XmlObject encodedXmlObject = encodeObjectToXml(namespace, samplingFeature);
if (encodedXmlObject != null) {
return encodedXmlObject;
} else {
if (feature.isSetXml()) {
try {
// XmlDescription? <-- XmlCursor
return XmlObject.Factory.parse(feature.getXml());
} catch (XmlException xmle) {
throw new EncodingException("Error while encoding featurePropertyType!", xmle);
}
} else {
featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
if (samplingFeature.isSetName()) {
featurePropertyType.setTitle(feature.getFirstName().getValue());
}
return featurePropertyType;
}
}
}
}
}
}
use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.
the class GmlEncoderv321 method createFeatureCollection.
private XmlObject createFeatureCollection(FeatureCollection element, EncodingContext ctx) throws EncodingException {
FeatureCollectionDocument featureCollectionDoc = FeatureCollectionDocument.Factory.newInstance(getXmlOptions());
FeatureCollectionType featureCollection = featureCollectionDoc.addNewFeatureCollection();
featureCollection.setId(element.getGmlId());
EncodingContext context = ctx.with(XmlBeansEncodingFlags.PROPERTY_TYPE).without(XmlBeansEncodingFlags.DOCUMENT);
if (element.isSetMembers()) {
for (AbstractFeature abstractFeature : element.getMembers().values()) {
featureCollection.addNewFeatureMember().set(createFeaturePropertyType(abstractFeature, context));
}
}
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
return featureCollectionDoc;
}
FeaturePropertyType featurePropertyType = FeaturePropertyType.Factory.newInstance(getXmlOptions());
featurePropertyType.addNewAbstractFeature().set(featureCollection);
return XmlHelper.substituteElement(featurePropertyType.getAbstractFeature(), featurePropertyType);
// return featureCollection;
}
Aggregations