Search in sources :

Example 11 with Type

use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.

the class InsertSensorRequestDecoder method parseProcedureDescription.

private SosProcedureDescription<?> parseProcedureDescription(JsonNode path, String pdf) throws DecodingException {
    try {
        final XmlObject xb = XmlObject.Factory.parse(path.textValue());
        Decoder<?, XmlObject> decoder = getProcedureDescriptionDecoder(pdf, xb);
        if (decoder == null) {
            throw new DecodingException(JSONConstants.PROCEDURE_DESCRIPTION_FORMAT, "The requested %s is not supported!", JSONConstants.PROCEDURE_DESCRIPTION_FORMAT);
        }
        Object decode = decoder.decode(xb);
        if (decode instanceof SosProcedureDescription<?>) {
            return (SosProcedureDescription<?>) decode;
        } else if (decode instanceof AbstractFeature) {
            return new SosProcedureDescription<AbstractFeature>((AbstractFeature) decode);
        } else {
            throw new DecodingException("The decoded element {} is not of type {}!", decode.getClass().getName(), AbstractFeature.class.getName());
        }
    } catch (final XmlException xmle) {
        throw new DecodingException("Error while parsing procedure description of InsertSensor request!", xmle);
    }
}
Also used : XmlException(org.apache.xmlbeans.XmlException) SosProcedureDescription(org.n52.shetland.ogc.sos.SosProcedureDescription) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlObject(org.apache.xmlbeans.XmlObject)

Example 12 with Type

use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.

the class SosDecoderv20 method parseInsertObservation.

private OwsServiceRequest parseInsertObservation(final InsertObservationDocument insertObservationDoc) throws DecodingException {
    // set namespace for default XML type (e.g. xs:string, xs:integer,
    // xs:boolean, ...)
    // Fix for problem with XmlBeans: namespace is not set in child elements
    // when defined in root of request (SOAP)
    final XmlCursor cursor = insertObservationDoc.newCursor();
    if (cursor.toFirstChild() && cursor.namespaceForPrefix(W3CConstants.NS_XS_PREFIX) == null) {
        cursor.prefixForNamespace(W3CConstants.NS_XS);
    }
    cursor.dispose();
    final InsertObservationRequest insertObservationRequest = new InsertObservationRequest();
    final InsertObservationType insertObservationType = insertObservationDoc.getInsertObservation();
    insertObservationRequest.setService(insertObservationType.getService());
    insertObservationRequest.setVersion(insertObservationType.getVersion());
    if (insertObservationDoc.getInsertObservation().getOfferingArray() != null) {
        insertObservationRequest.setOfferings(Arrays.asList(insertObservationType.getOfferingArray()));
    }
    insertObservationRequest.setExtensions(parseExtensibleRequest(insertObservationType));
    if (insertObservationType.getObservationArray() != null) {
        final int length = insertObservationType.getObservationArray().length;
        final Map<String, Time> phenomenonTimes = new HashMap<>(length);
        final Map<String, TimeInstant> resultTimes = new HashMap<>(length);
        final Map<String, AbstractFeature> features = new HashMap<>(length);
        CompositeException exceptions = new CompositeException();
        for (final Observation observation : insertObservationType.getObservationArray()) {
            final Object decodedObject = decodeXmlElement(observation.getOMObservation());
            if (decodedObject instanceof OmObservation) {
                final OmObservation sosObservation = (OmObservation) decodedObject;
                checkAndAddPhenomenonTime(sosObservation.getPhenomenonTime(), phenomenonTimes);
                checkAndAddResultTime(sosObservation.getResultTime(), resultTimes);
                checkAndAddFeatures(sosObservation.getObservationConstellation().getFeatureOfInterest(), features);
                insertObservationRequest.addObservation(sosObservation);
            } else {
                exceptions.add(new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested observation type (%s) is not supported by this server!", observation.getOMObservation().getDomNode().getNodeName()));
            }
        }
        checkReferencedElements(insertObservationRequest.getObservations(), phenomenonTimes, resultTimes, features);
        try {
            exceptions.throwIfNotEmpty();
        } catch (CompositeException ex) {
            throw new DecodingException(ex, Sos2Constants.InsertObservationParams.observation);
        }
    } else {
        // TODO MissingMandatoryParameterException?
        throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The request does not contain an observation");
    }
    return insertObservationRequest;
}
Also used : HashMap(java.util.HashMap) CompositeException(org.n52.janmayen.exception.CompositeException) OmObservation(org.n52.shetland.ogc.om.OmObservation) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) Time(org.n52.shetland.ogc.gml.time.Time) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlString(org.apache.xmlbeans.XmlString) InsertObservationType(net.opengis.sos.x20.InsertObservationType) XmlCursor(org.apache.xmlbeans.XmlCursor) InsertObservationRequest(org.n52.shetland.ogc.sos.request.InsertObservationRequest) OmObservation(org.n52.shetland.ogc.om.OmObservation) Observation(net.opengis.sos.x20.InsertObservationType.Observation) OwsServiceCommunicationObject(org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject) XmlObject(org.apache.xmlbeans.XmlObject) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 13 with Type

use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.

the class OmDecoderv20 method getResult.

private ObservationValue<?> getResult(OMObservationType omObservation) throws DecodingException {
    XmlObject xbResult = omObservation.getResult();
    if (xbResult.schemaType() == XmlAnyTypeImpl.type) {
        // Template observation for InsertResultTemplate operation
        if (!xbResult.getDomNode().hasChildNodes()) {
            return new SingleObservationValue<>(new NilTemplateValue());
        } else {
            try {
                xbResult = XmlObject.Factory.parse(xbResult.xmlText().trim());
            } catch (XmlException e) {
                LOGGER.error("Error while parsing NamedValueValue", e);
            }
        }
    }
    if (xbResult.schemaType() == XmlBoolean.type) {
        // TruthObservation
        XmlBoolean xbBoolean = (XmlBoolean) xbResult;
        BooleanValue booleanValue = new BooleanValue(xbBoolean.getBooleanValue());
        return new SingleObservationValue<>(booleanValue);
    } else if (xbResult.schemaType() == XmlInteger.type) {
        // CountObservation
        XmlInteger xbInteger = (XmlInteger) xbResult;
        CountValue countValue = new CountValue(Integer.parseInt(xbInteger.getBigIntegerValue().toString()));
        return new SingleObservationValue<>(countValue);
    } else if (xbResult.schemaType() == XmlString.type) {
        // TextObservation
        XmlString xbString = (XmlString) xbResult;
        TextValue stringValue = new TextValue(xbString.getStringValue());
        return new SingleObservationValue<>(stringValue);
    } else {
        // result elements with other encoding like SWE_ARRAY_OBSERVATION
        Object decodedObject = decodeXmlObject(xbResult);
        if (decodedObject instanceof ObservationValue) {
            return (ObservationValue<?>) decodedObject;
        } else if (decodedObject instanceof GmlMeasureType) {
            GmlMeasureType measureType = (GmlMeasureType) decodedObject;
            QuantityValue quantitiyValue = new QuantityValue(measureType.getValue(), measureType.getUnit());
            return new SingleObservationValue<>(quantitiyValue);
        } else if (decodedObject instanceof ReferenceType) {
            if (omObservation.isSetType() && omObservation.getType().isSetHref() && omObservation.getType().getHref().equals(OmConstants.OBS_TYPE_REFERENCE_OBSERVATION)) {
                return new SingleObservationValue<>(new ReferenceValue((ReferenceType) decodedObject));
            }
            return new SingleObservationValue<>(new CategoryValue(((ReferenceType) decodedObject).getHref()));
        } else if (decodedObject instanceof Geometry) {
            return new SingleObservationValue<>(new GeometryValue((Geometry) decodedObject));
        } else if (decodedObject instanceof AbstractGeometry) {
            SingleObservationValue<Geometry> result = new SingleObservationValue<>();
            result.setValue(new GeometryValue(((AbstractGeometry) decodedObject).getGeometry()));
            return result;
        } else if (decodedObject instanceof SweDataArray) {
            return new SingleObservationValue<>(new SweDataArrayValue((SweDataArray) decodedObject));
        } else if (decodedObject instanceof SweDataRecord) {
            return new SingleObservationValue<>(new ComplexValue((SweDataRecord) decodedObject));
        }
        throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested result type '{}' is not supported by this service!", decodedObject.getClass().getSimpleName());
    }
}
Also used : AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) XmlBoolean(org.apache.xmlbeans.XmlBoolean) ReferenceValue(org.n52.shetland.ogc.om.values.ReferenceValue) XmlInteger(org.apache.xmlbeans.XmlInteger) DecodingException(org.n52.svalbard.decode.exception.DecodingException) ReferenceType(org.n52.shetland.ogc.gml.ReferenceType) SweDataArrayValue(org.n52.shetland.ogc.om.values.SweDataArrayValue) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) CountValue(org.n52.shetland.ogc.om.values.CountValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) ComplexValue(org.n52.shetland.ogc.om.values.ComplexValue) XmlString(org.apache.xmlbeans.XmlString) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) Geometry(org.locationtech.jts.geom.Geometry) AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) XmlException(org.apache.xmlbeans.XmlException) TextValue(org.n52.shetland.ogc.om.values.TextValue) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue) XmlObject(org.apache.xmlbeans.XmlObject) XmlObject(org.apache.xmlbeans.XmlObject) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) ObservationValue(org.n52.shetland.ogc.om.ObservationValue) NilTemplateValue(org.n52.shetland.ogc.om.values.NilTemplateValue) GmlMeasureType(org.n52.shetland.ogc.gml.GmlMeasureType)

Example 14 with Type

use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.

the class OmDecoderv20 method getPhenomenonTime.

private Time getPhenomenonTime(OMObservationType omObservation) throws DecodingException {
    TimeObjectPropertyType phenomenonTime = omObservation.getPhenomenonTime();
    if (phenomenonTime.isSetHref() && phenomenonTime.getHref().startsWith("#")) {
        TimeInstant timeInstant = new TimeInstant();
        timeInstant.setGmlId(phenomenonTime.getHref());
        return timeInstant;
    } else if (phenomenonTime.isSetNilReason() && phenomenonTime.getNilReason() instanceof String && ((String) phenomenonTime.getNilReason()).equals(IndeterminateValue.TEMPLATE.getValue())) {
        return new TimeInstant(IndeterminateValue.TEMPLATE);
    } else if (phenomenonTime.isSetAbstractTimeObject()) {
        Object decodedObject = decodeXmlObject(phenomenonTime.getAbstractTimeObject());
        if (decodedObject instanceof Time) {
            return (Time) decodedObject;
        }
    // FIXME else
    }
    throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested phenomenonTime type is not supported by this service!");
}
Also used : TimeObjectPropertyType(net.opengis.om.x20.TimeObjectPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) Time(org.n52.shetland.ogc.gml.time.Time) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlString(org.apache.xmlbeans.XmlString) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 15 with Type

use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.

the class SensorMLDecoderV101 method parseIoComponentPropertyType.

/**
 * Parses the components
 *
 * @param xbIoCompPropType XML components
 *
 * @return SOS components
 *
 * @throws DecodingException if an error occurs
 */
@SuppressWarnings({ "rawtypes" })
private SmlIo parseIoComponentPropertyType(final IoComponentPropertyType xbIoCompPropType) throws DecodingException {
    final SmlIo sosIo = new SmlIo();
    sosIo.setIoName(xbIoCompPropType.getName());
    XmlObject toDecode = null;
    if (xbIoCompPropType.isSetHref()) {
        sosIo.setHref(xbIoCompPropType.getHref());
        if (xbIoCompPropType.isSetTitle()) {
            sosIo.setTitle(xbIoCompPropType.getTitle());
        }
        return sosIo;
    }
    if (xbIoCompPropType.isSetBoolean()) {
        toDecode = xbIoCompPropType.getBoolean();
    } else if (xbIoCompPropType.isSetCategory()) {
        toDecode = xbIoCompPropType.getCategory();
    } else if (xbIoCompPropType.isSetCount()) {
        toDecode = xbIoCompPropType.getCount();
    } else if (xbIoCompPropType.isSetCountRange()) {
        toDecode = xbIoCompPropType.getCountRange();
    } else if (xbIoCompPropType.isSetObservableProperty()) {
        toDecode = xbIoCompPropType.getObservableProperty();
    } else if (xbIoCompPropType.isSetQuantity()) {
        toDecode = xbIoCompPropType.getQuantity();
    } else if (xbIoCompPropType.isSetQuantityRange()) {
        toDecode = xbIoCompPropType.getQuantityRange();
    } else if (xbIoCompPropType.isSetText()) {
        toDecode = xbIoCompPropType.getText();
    } else if (xbIoCompPropType.isSetTime()) {
        toDecode = xbIoCompPropType.getTime();
    } else if (xbIoCompPropType.isSetTimeRange()) {
        toDecode = xbIoCompPropType.getTimeRange();
    } else if (xbIoCompPropType.isSetAbstractDataArray1()) {
        toDecode = xbIoCompPropType.getAbstractDataArray1();
    } else if (xbIoCompPropType.isSetAbstractDataRecord()) {
        toDecode = xbIoCompPropType.getAbstractDataRecord();
    } else {
        throw new DecodingException(XmlHelper.getLocalName(xbIoCompPropType), "An 'IoComponentProperty' is not supported");
    }
    final Object decodedObject = decodeXmlElement(toDecode);
    if (decodedObject instanceof SweAbstractDataComponent) {
        sosIo.setIoValue((SweAbstractDataComponent) decodedObject);
    } else {
        throw new DecodingException(XmlHelper.getLocalName(xbIoCompPropType), "The 'IoComponentProperty' with type '%s' as value for '%s' is not supported.", XmlHelper.getLocalName(toDecode), XmlHelper.getLocalName(xbIoCompPropType));
    }
    return sosIo;
}
Also used : SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlObject(org.apache.xmlbeans.XmlObject) SmlIo(org.n52.shetland.ogc.sensorML.elements.SmlIo)

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)27 DecodingException (org.n52.svalbard.decode.exception.DecodingException)15 Actuate (org.n52.shetland.w3c.xlink.Actuate)14 Reference (org.n52.shetland.w3c.xlink.Reference)14 Show (org.n52.shetland.w3c.xlink.Show)14 Type (org.n52.shetland.w3c.xlink.Type)14 ActuateType (org.w3.x1999.xlink.ActuateType)14 ShowType (org.w3.x1999.xlink.ShowType)14 TypeType (org.w3.x1999.xlink.TypeType)14 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)13 AbstractCRSType (net.opengis.gml.x32.AbstractCRSType)10 CodeType (net.opengis.gml.x32.CodeType)10 EXExtentType (org.isotc211.x2005.gmd.EXExtentType)10 Test (org.junit.Test)10 XmlException (org.apache.xmlbeans.XmlException)9 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)9 CIResponsiblePartyPropertyType (org.isotc211.x2005.gmd.CIResponsiblePartyPropertyType)8 CIResponsiblePartyType (org.isotc211.x2005.gmd.CIResponsiblePartyType)8 BaseUnitType (net.opengis.gml.x32.BaseUnitType)6 SupportedType (org.n52.shetland.ogc.SupportedType)6