Search in sources :

Example 36 with EncodingException

use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.

the class OmEncoderv100 method createObservationCollection.

private XmlObject createObservationCollection(ObservationStream sosObservationCollectionIterable, String resultModel) throws EncodingException {
    ObservationCollectionDocument xbObservationCollectionDoc = ObservationCollectionDocument.Factory.newInstance(getXmlOptions());
    ObservationCollectionType xbObservationCollection = xbObservationCollectionDoc.addNewObservationCollection();
    xbObservationCollection.setId(SosConstants.OBS_COL_ID_PREFIX + new DateTime().getMillis());
    if (sosObservationCollectionIterable != null) {
        List<OmObservation> sosObservationCollection = new LinkedList<>();
        try {
            sosObservationCollectionIterable.forEachRemaining(sosObservationCollection::add);
            ReferencedEnvelope sosEnvelope = getEnvelope(sosObservationCollection);
            Encoder<XmlObject, ReferencedEnvelope> envEncoder = getEncoder(GmlConstants.NS_GML, sosEnvelope);
            xbObservationCollection.addNewBoundedBy().addNewEnvelope().set(envEncoder.encode(sosEnvelope));
            for (OmObservation sosObservation : sosObservationCollection) {
                String observationType = checkObservationType(sosObservation);
                if (Strings.isNullOrEmpty(resultModel) || (!Strings.isNullOrEmpty(resultModel) && observationType.equals(resultModel))) {
                    if (sosObservation.getValue() instanceof StreamingValue) {
                        StreamingValue<?> streamingValue = (StreamingValue<?>) sosObservation.getValue();
                        while (streamingValue.hasNext()) {
                            xbObservationCollection.addNewMember().set(createObservation(streamingValue.next(), null));
                        }
                    } else {
                        xbObservationCollection.addNewMember().set(createObservation(sosObservation, null));
                    }
                } else {
                    throw new EncodingException("The requested resultModel '%s' is invalid for the resulting observations!", OMHelper.getEncodedResultModelFor(resultModel));
                }
            }
        } catch (OwsExceptionReport owse) {
            throw new EncodingException(owse);
        }
    } else {
        ObservationPropertyType xbObservation = xbObservationCollection.addNewMember();
        xbObservation.setHref(GmlConstants.NIL_INAPPLICABLE);
    }
    XmlHelper.makeGmlIdsUnique(xbObservationCollectionDoc.getDomNode());
    N52XmlHelper.setSchemaLocationsToDocument(xbObservationCollectionDoc, Sets.newHashSet(N52XmlHelper.getSchemaLocationForSOS100(), N52XmlHelper.getSchemaLocationForOM100(), N52XmlHelper.getSchemaLocationForSA100()));
    return xbObservationCollectionDoc;
}
Also used : StreamingValue(org.n52.shetland.ogc.om.StreamingValue) EncodingException(org.n52.svalbard.encode.exception.EncodingException) ObservationPropertyType(net.opengis.om.x10.ObservationPropertyType) OmObservation(org.n52.shetland.ogc.om.OmObservation) ObservationCollectionType(net.opengis.om.x10.ObservationCollectionType) XmlString(org.apache.xmlbeans.XmlString) DateTime(org.joda.time.DateTime) LinkedList(java.util.LinkedList) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) ObservationCollectionDocument(net.opengis.om.x10.ObservationCollectionDocument) XmlObject(org.apache.xmlbeans.XmlObject) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 37 with EncodingException

use of org.n52.svalbard.encode.exception.EncodingException 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;
}
Also used : OmCompositePhenomenon(org.n52.shetland.ogc.om.OmCompositePhenomenon) Time(org.n52.shetland.ogc.gml.time.Time) DateTime(org.joda.time.DateTime) XmlString(org.apache.xmlbeans.XmlString) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty)

Example 38 with EncodingException

use of org.n52.svalbard.encode.exception.EncodingException 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;
}
Also used : TruthObservationType(net.opengis.om.x10.TruthObservationType) ObservationType(net.opengis.om.x10.ObservationType) CategoryObservationType(net.opengis.om.x10.CategoryObservationType) CountObservationType(net.opengis.om.x10.CountObservationType) GeometryObservationType(net.opengis.om.x10.GeometryObservationType) GeometryObservationDocument(net.opengis.om.x10.GeometryObservationDocument) CountObservationDocument(net.opengis.om.x10.CountObservationDocument) TruthObservationDocument(net.opengis.om.x10.TruthObservationDocument) ObservationDocument(net.opengis.om.x10.ObservationDocument) CategoryObservationDocument(net.opengis.om.x10.CategoryObservationDocument) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty)

Example 39 with EncodingException

use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.

the class GetResultTemplateResponseEncoder method createResultStructure.

private ResultStructure createResultStructure(SosResultStructure resultStructure) throws EncodingException {
    // TODO move encoding to SWECommonEncoder
    final DataRecordDocument dataRecordDoc;
    if (resultStructure.isEncoded()) {
        try {
            dataRecordDoc = DataRecordDocument.Factory.parse(resultStructure.getXml().get());
        } catch (XmlException ex) {
            throw unsupportedResultStructure(ex);
        }
    } else {
        XmlObject xml = encodeSwe(EncodingContext.of(XmlBeansEncodingFlags.DOCUMENT), resultStructure.get().get());
        if (xml instanceof DataRecordDocument) {
            dataRecordDoc = (DataRecordDocument) xml;
        } else {
            throw unsupportedResultStructure();
        }
    }
    ResultStructure xbResultStructure = ResultStructure.Factory.newInstance(getXmlOptions());
    xbResultStructure.addNewAbstractDataComponent().set(dataRecordDoc.getDataRecord());
    XmlHelper.substituteElement(xbResultStructure.getAbstractDataComponent(), dataRecordDoc.getDataRecord());
    return xbResultStructure;
}
Also used : ResultStructure(net.opengis.sos.x20.GetResultTemplateResponseType.ResultStructure) SosResultStructure(org.n52.shetland.ogc.sos.SosResultStructure) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) DataRecordDocument(net.opengis.swe.x20.DataRecordDocument)

Example 40 with EncodingException

use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.

the class GmlEncoderv311 method createTimePeriodType.

/**
 * Creates a XML TimePeriod from the SOS time object.
 *
 * @param timePeriod
 *            SOS time object
 * @param timePeriodType
 *            the xml time period (may be {@code null})
 * @return XML TimePeriod
 *
 * @throws EncodingException
 *             if an error occurs.
 */
private TimePeriodType createTimePeriodType(TimePeriod timePeriod, TimePeriodType timePeriodType) throws EncodingException {
    try {
        TimePeriodType tpt;
        if (timePeriodType == null) {
            tpt = TimePeriodType.Factory.newInstance(getXmlOptions());
        } else {
            tpt = timePeriodType;
        }
        if (timePeriod.getGmlId() != null && !timePeriod.getGmlId().isEmpty()) {
            tpt.setId(timePeriod.getGmlId());
        }
        tpt.setBeginPosition(createTimePositionType(timePeriod.getStartTimePosition()));
        tpt.setEndPosition(createTimePositionType(timePeriod.getEndTimePosition()));
        return tpt;
    } catch (XmlRuntimeException | XmlValueDisconnectedException x) {
        throw new EncodingException("Error while creating TimePeriod!", x);
    }
}
Also used : XmlRuntimeException(org.apache.xmlbeans.XmlRuntimeException) XmlValueDisconnectedException(org.apache.xmlbeans.impl.values.XmlValueDisconnectedException) TimePeriodType(net.opengis.gml.TimePeriodType) EncodingException(org.n52.svalbard.encode.exception.EncodingException)

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)124 Test (org.junit.Test)93 EncodingException (org.n52.svalbard.encode.exception.EncodingException)60 SweField (org.n52.shetland.ogc.swe.SweField)29 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)29 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)22 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)21 XmlException (org.apache.xmlbeans.XmlException)20 DateTime (org.joda.time.DateTime)19 OmObservation (org.n52.shetland.ogc.om.OmObservation)19 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)17 Time (org.n52.shetland.ogc.gml.time.Time)15 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)15 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)13 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)13 AnyScalarPropertyType (net.opengis.swe.x101.AnyScalarPropertyType)12 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)12 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)12 SystemType (net.opengis.sensorML.x101.SystemType)11 DataRecordType (net.opengis.swe.x101.DataRecordType)11