Search in sources :

Example 16 with CodeType

use of org.n52.shetland.ogc.gml.CodeType in project arctic-sea by 52North.

the class AbstractWmlEncoderv20 method createMonitoringPoint.

/**
 * Creates a WaterML 2.0 MonitoringPoint XML object from SOS feature object
 *
 * @param absFeature
 *            SOS feature
 * @return WaterML 2.0 MonitoringPoint XML object
 * @throws EncodingException
 *             If an error occurs
 */
protected XmlObject createMonitoringPoint(AbstractFeature absFeature) throws EncodingException {
    if (absFeature instanceof AbstractSamplingFeature) {
        AbstractSamplingFeature sampFeat = (AbstractSamplingFeature) absFeature;
        StringBuilder builder = new StringBuilder();
        builder.append("mp_");
        builder.append(JavaHelper.generateID(absFeature.getIdentifierCodeWithAuthority().getValue()));
        absFeature.setGmlId(builder.toString());
        MonitoringPointDocument monitoringPointDoc = MonitoringPointDocument.Factory.newInstance(getXmlOptions());
        if (sampFeat.isSetXml()) {
            try {
                XmlObject feature = XmlObject.Factory.parse(sampFeat.getXml());
                if (XmlHelper.getNamespace(feature).equals(WaterMLConstants.NS_WML_20)) {
                    if (feature instanceof MonitoringPointDocument) {
                        monitoringPointDoc = (MonitoringPointDocument) feature;
                    } else if (feature instanceof MonitoringPointType) {
                        monitoringPointDoc.setSFSpatialSamplingFeature((MonitoringPointType) feature);
                    }
                    XmlHelper.updateGmlIDs(monitoringPointDoc.getDomNode(), absFeature.getGmlId(), null);
                    return monitoringPointDoc;
                }
            } catch (XmlException xmle) {
                throw new EncodingException("Error while encoding GetFeatureOfInterest response, invalid samplingFeature description!", xmle);
            }
        }
        MonitoringPointType mpt = monitoringPointDoc.addNewMonitoringPoint();
        // set gml:id
        mpt.setId(absFeature.getGmlId());
        if (sampFeat.isSetIdentifier()) {
            XmlObject xmlObject = encodeGML(sampFeat.getIdentifierCodeWithAuthority());
            if (xmlObject != null) {
                mpt.addNewIdentifier().set(xmlObject);
            }
        }
        if (sampFeat.isSetName()) {
            for (CodeType sosName : sampFeat.getName()) {
                mpt.addNewName().set(encodeGML(sosName));
            }
        }
        if (sampFeat.isSetDescription()) {
            if (!mpt.isSetDescription()) {
                mpt.addNewDescription();
            }
            mpt.getDescription().setStringValue(sampFeat.getDescription());
        }
        // TODO: CHECK
        if (sampFeat.getSampledFeatures() != null && !sampFeat.getSampledFeatures().isEmpty()) {
            if (sampFeat.getSampledFeatures().size() == 1) {
                XmlObject encodeObjectToXml = encodeObjectToXml(GmlConstants.NS_GML_32, sampFeat.getSampledFeatures().get(0));
                mpt.addNewSampledFeature().set(encodeObjectToXml);
            } else {
                FeatureCollection featureCollection = new FeatureCollection();
                featureCollection.setGmlId("sampledFeatures_" + absFeature.getGmlId());
                for (AbstractFeature sampledFeature : sampFeat.getSampledFeatures()) {
                    featureCollection.addMember(sampledFeature);
                }
                XmlObject encodeObjectToXml = encodeGML(featureCollection);
                mpt.addNewSampledFeature().set(encodeObjectToXml);
            }
        } else {
            mpt.addNewSampledFeature().setHref(GmlConstants.NIL_UNKNOWN);
        }
        if (sampFeat.isSetParameter()) {
            addParameter(mpt, sampFeat);
        }
        // set position
        ShapeType xbShape = mpt.addNewShape();
        Encoder<XmlObject, Geometry> encoder = getEncoder(getEncoderKey(GmlConstants.NS_GML_32, sampFeat.getGeometry()));
        if (encoder != null) {
            XmlObject xmlObject = encoder.encode(sampFeat.getGeometry(), new EncodingContext().with(XmlBeansEncodingFlags.GMLID, absFeature.getGmlId()));
            xbShape.addNewAbstractGeometry().set(xmlObject);
            XmlHelper.substituteElement(xbShape.getAbstractGeometry(), xmlObject);
        } else {
            throw new EncodingException("Error while encoding geometry for feature, needed encoder is missing!");
        }
        if (absFeature instanceof WmlMonitoringPoint) {
            addMonitoringPointValues(mpt, (WmlMonitoringPoint) absFeature);
        }
        sampFeat.wasEncoded();
        return monitoringPointDoc;
    }
    throw new UnsupportedEncoderInputException(this, absFeature);
}
Also used : MonitoringPointType(net.opengis.waterml.x20.MonitoringPointType) MonitoringPointDocument(net.opengis.waterml.x20.MonitoringPointDocument) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) EncodingException(org.n52.svalbard.encode.exception.EncodingException) ShapeType(net.opengis.samplingSpatial.x20.ShapeType) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) WmlMonitoringPoint(org.n52.shetland.ogc.om.series.wml.WmlMonitoringPoint) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) Geometry(org.locationtech.jts.geom.Geometry) FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) XmlException(org.apache.xmlbeans.XmlException) CodeType(org.n52.shetland.ogc.gml.CodeType) XmlObject(org.apache.xmlbeans.XmlObject)

Example 17 with CodeType

use of org.n52.shetland.ogc.gml.CodeType in project arctic-sea by 52North.

the class AbstractWmlEncoderv20 method createObservationProcess.

/**
 * Creates an WaterML 2.0 ObservationProcess XML object from SOS
 * ObservationProcess object
 *
 * @param procedure
 *            SOS ObservationProcess
 * @param context
 *            Additional values
 * @return WaterML 2.0 ObservationProcess XML object
 * @throws EncodingException
 *             If an error occurs
 */
protected ObservationProcessDocument createObservationProcess(ObservationProcess procedure, EncodingContext context) throws EncodingException {
    XmlObject encodedObject = null;
    try {
        if (procedure.isSetXml()) {
            encodedObject = XmlObject.Factory.parse(procedure.getXml());
            checkAndAddIdentifier(procedure, ((ObservationProcessDocument) encodedObject).getObservationProcess());
        } else {
            encodedObject = ObservationProcessDocument.Factory.newInstance();
            ObservationProcessType observationProcess = ((ObservationProcessDocument) encodedObject).addNewObservationProcess();
            if (context.has(XmlBeansEncodingFlags.GMLID)) {
                observationProcess.setId(PROCESS_ID_PREFIX + context.get(XmlBeansEncodingFlags.GMLID));
            } else {
                observationProcess.setId(PROCESS_ID_PREFIX + JavaHelper.generateID(procedure.toString()));
            }
            if (procedure.isSetIdentifier()) {
                observationProcess.addNewIdentifier().set(encodeGML(procedure.getIdentifierCodeWithAuthority()));
            }
            if (procedure.isSetName()) {
                for (final CodeType sosName : procedure.getName()) {
                    observationProcess.addNewName().set(encodeGML(sosName));
                }
            }
            addProcessType(observationProcess, procedure);
            addOriginatingProcess(observationProcess, procedure);
            addAggregatingDuration(observationProcess, procedure);
            addVerticalDatum(observationProcess, procedure);
            addComment(observationProcess, procedure);
            addProcessReference(observationProcess, procedure);
            addInput(observationProcess, procedure);
            addParameter(observationProcess, procedure);
        }
    } catch (final XmlException xmle) {
        throw new EncodingException(xmle);
    }
    try {
        LOGGER.debug("Encoded object {} is valid: {}", encodedObject.schemaType().toString(), XmlHelper.validateDocument(encodedObject));
    } catch (DecodingException e) {
        throw new EncodingException(e);
    }
    return (ObservationProcessDocument) encodedObject;
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) ObservationProcessType(net.opengis.waterml.x20.ObservationProcessType) XmlException(org.apache.xmlbeans.XmlException) ObservationProcessDocument(net.opengis.waterml.x20.ObservationProcessDocument) CodeType(org.n52.shetland.ogc.gml.CodeType) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException)

Example 18 with CodeType

use of org.n52.shetland.ogc.gml.CodeType in project arctic-sea by 52North.

the class OwsEncoderv110 method encodeServiceIdentification.

private XmlObject encodeServiceIdentification(OwsServiceIdentification serviceIdentification) throws EncodingException {
    ServiceIdentification serviceIdent;
    /* TODO check for required fields and fail on missing ones */
    serviceIdent = ServiceIdentification.Factory.newInstance();
    serviceIdentification.getAccessConstraints().forEach(serviceIdent::addAccessConstraints);
    if (!serviceIdentification.getFees().isEmpty()) {
        serviceIdent.setFees(serviceIdentification.getFees().iterator().next());
    }
    CodeType xbServiceType = serviceIdent.addNewServiceType();
    xbServiceType.setStringValue(serviceIdentification.getServiceType().getValue());
    if (serviceIdentification.getServiceType().getCodeSpace().isPresent()) {
        xbServiceType.setCodeSpace(serviceIdentification.getServiceType().getCodeSpace().get().toString());
    }
    encodeMultilingualString(serviceIdentification.getTitle(), serviceIdent::addNewTitle);
    encodeMultilingualString(serviceIdentification.getAbstract(), serviceIdent::addNewAbstract);
    serviceIdentification.getServiceTypeVersion().stream().forEach(serviceIdent::addServiceTypeVersion);
    serviceIdentification.getProfiles().stream().map(URI::toString).forEach(serviceIdent::addProfile);
    serviceIdentification.getKeywords().stream().collect(groupingBy(OwsKeyword::getType, mapping(OwsKeyword::getKeyword, toList()))).forEach((type, keywords) -> encodeOwsKeywords(type, keywords, serviceIdent.addNewKeywords()));
    return serviceIdent;
}
Also used : OwsKeyword(org.n52.shetland.ogc.ows.OwsKeyword) CodeType(net.opengis.ows.x11.CodeType) ServiceIdentification(net.opengis.ows.x11.ServiceIdentificationDocument.ServiceIdentification) OwsServiceIdentification(org.n52.shetland.ogc.ows.OwsServiceIdentification)

Example 19 with CodeType

use of org.n52.shetland.ogc.gml.CodeType in project arctic-sea by 52North.

the class GetCapabilitiesResponseEncoder method encodeObservationOffering.

private void encodeObservationOffering(SosObservationOffering offering, int offeringCounter, ContentsType xbContType) throws EncodingException {
    final ObservationOfferingType xbObsOff = ObservationOfferingType.Factory.newInstance(getXmlOptions());
    SosOffering sosOffering = offering.getOffering();
    xbObsOff.setIdentifier(sosOffering.getIdentifier());
    if (sosOffering.isSetName()) {
        for (CodeType name : sosOffering.getName()) {
            xbObsOff.addNewName().set(encodeObjectToXml(GmlConstants.NS_GML_32, name));
        }
    }
    if (sosOffering.isSetDescription()) {
        xbObsOff.setDescription(sosOffering.getDescription());
    }
    encodeOfferingExtension(offering, xbObsOff);
    offering.getProcedures().forEach(xbObsOff::setProcedure);
    encodeObservableProperties(offering, xbObsOff);
    encodeRelatedFeatures(offering, xbObsOff);
    encodeObservedArea(offering, xbObsOff);
    encodePhenomenonTime(offering, offeringCounter, xbObsOff);
    encodeResultTime(offering, offeringCounter, xbObsOff);
    encodeResponseFormat(offering, xbObsOff);
    encodeObservationType(offering, xbObsOff);
    encodeFeatureOfInterestTypes(offering, xbObsOff);
    encodeProcedureDescriptionFormats(offering, xbObsOff);
    xbContType.addNewOffering().setAbstractOffering(xbObsOff);
/*
         * Offering addNewOffering = xbContType.addNewOffering();
         * addNewOffering.addNewAbstractOffering().set(xbObsOff); XmlHelper
         * .substituteElement(addNewOffering.getAbstractOffering(), xbObsOff);
         */
}
Also used : ObservationOfferingType(net.opengis.sos.x20.ObservationOfferingType) CodeType(org.n52.shetland.ogc.gml.CodeType) SosOffering(org.n52.shetland.ogc.sos.SosOffering)

Example 20 with CodeType

use of org.n52.shetland.ogc.gml.CodeType in project arctic-sea by 52North.

the class AbstractOmEncoderv20 method setObservationName.

private void setObservationName(OmObservation observation, OMObservationType xb) throws EncodingException {
    // set observation identifier if available
    if (observation.isSetIdentifier()) {
        for (CodeType name : observation.getName()) {
            XmlObject xbId = encodeGML(name);
            xb.addNewName().set(xbId);
        }
    }
}
Also used : CodeType(org.n52.shetland.ogc.gml.CodeType) XmlObject(org.apache.xmlbeans.XmlObject)

Aggregations

CodeType (org.n52.shetland.ogc.gml.CodeType)23 XmlObject (org.apache.xmlbeans.XmlObject)9 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)7 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)7 Test (org.junit.Test)5 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)5 XmlException (org.apache.xmlbeans.XmlException)4 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)4 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 GeographicalName (org.n52.shetland.inspire.GeographicalName)3 Spelling (org.n52.shetland.inspire.Spelling)3 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)3 OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)3 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)3 QuantityValue (org.n52.shetland.ogc.om.values.QuantityValue)3 DecodingException (org.n52.svalbard.decode.exception.DecodingException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 XmlOptions (org.apache.xmlbeans.XmlOptions)2 Before (org.junit.Before)2