Search in sources :

Example 16 with CodeWithAuthority

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

the class InsertResultTemplateRequest method getIdentifier.

public CodeWithAuthority getIdentifier() {
    if (resultTemplate.getIdentifier() == null) {
        StringBuilder builder = new StringBuilder();
        builder.append(getObservationTemplate().toString());
        builder.append(new DateTime().getMillis());
        resultTemplate.setIdentifier(new CodeWithAuthority(JavaHelper.generateID(builder.toString())));
    }
    return resultTemplate.getIdentifier();
}
Also used : CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) DateTime(org.joda.time.DateTime)

Example 17 with CodeWithAuthority

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

the class MeasurementDecodingTest method testIdentifier.

@Test
public void testIdentifier() {
    assertThat(observation, is(notNullValue()));
    final CodeWithAuthority cwa = observation.getIdentifierCodeWithAuthority();
    assertThat(cwa, is(notNullValue()));
    assertThat(cwa.getValue(), is(equalTo(IDENTIFIER)));
    assertThat(cwa.getCodeSpace(), is(equalTo(UNKNOWN_CODESPACE)));
}
Also used : CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) Test(org.junit.Test)

Example 18 with CodeWithAuthority

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

the class SpecimenDecoderv20 method getSampledFeatures.

/**
 * Parse {@link FeaturePropertyType} sampledFeature to
 * {@link AbstractFeature} list.
 *
 * @param sampledFeature
 *            SampledFeature to parse
 * @return List with the parsed sampledFeature
 * @throws DecodingException
 *             If an error occurs
 */
private List<AbstractFeature> getSampledFeatures(final FeaturePropertyType sampledFeature) throws DecodingException {
    final List<AbstractFeature> sampledFeatures = new ArrayList<AbstractFeature>(1);
    if (sampledFeature != null && !sampledFeature.isNil()) {
        // if xlink:href is set
        if (sampledFeature.getHref() != null && !sampledFeature.getHref().isEmpty()) {
            if (sampledFeature.getHref().startsWith("#")) {
                sampledFeatures.add(new SamplingFeature(null, sampledFeature.getHref().replace("#", "")));
            } else {
                final AbstractSamplingFeature sampFeat = new SamplingFeature(new CodeWithAuthority(sampledFeature.getHref()));
                if (sampledFeature.getTitle() != null && !sampledFeature.getTitle().isEmpty()) {
                    sampFeat.addName(new CodeType(sampledFeature.getTitle()));
                }
                sampledFeatures.add(sampFeat);
            }
        } else {
            XmlObject abstractFeature = null;
            if (sampledFeature.getAbstractFeature() != null) {
                abstractFeature = sampledFeature.getAbstractFeature();
            } else if (sampledFeature.getDomNode().hasChildNodes()) {
                try {
                    abstractFeature = XmlObject.Factory.parse(XmlHelper.getNodeFromNodeList(sampledFeature.getDomNode().getChildNodes()));
                } catch (final XmlException xmle) {
                    throw new DecodingException("Error while parsing feature request!", xmle);
                }
            }
            if (abstractFeature != null) {
                final Object decodedObject = decodeXmlObject(abstractFeature);
                if (decodedObject instanceof AbstractFeature) {
                    sampledFeatures.add((AbstractFeature) decodedObject);
                }
            }
            throw new DecodingException("The requested sampledFeature type is not supported by this service!");
        }
    }
    return sampledFeatures;
}
Also used : AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) XmlException(org.apache.xmlbeans.XmlException) ArrayList(java.util.ArrayList) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) CodeType(org.n52.shetland.ogc.gml.CodeType) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlObject(org.apache.xmlbeans.XmlObject) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority)

Example 19 with CodeWithAuthority

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

the class SwesDecoderv20 method parseRelatedFeature.

private List<SwesFeatureRelationship> parseRelatedFeature(final RelatedFeature[] relatedFeatureArray) throws DecodingException {
    List<SwesFeatureRelationship> sosRelatedFeatures = new ArrayList<>(relatedFeatureArray.length);
    for (final RelatedFeature relatedFeature : relatedFeatureArray) {
        final SwesFeatureRelationship sosFeatureRelationship = new SwesFeatureRelationship();
        final FeaturePropertyType fpt = relatedFeature.getFeatureRelationship().getTarget();
        if (fpt.getHref() != null && !fpt.getHref().isEmpty()) {
            final String identifier = fpt.getHref();
            final AbstractSamplingFeature feature = new SamplingFeature(new CodeWithAuthority(identifier));
            if (fpt.getTitle() != null && !fpt.getTitle().isEmpty()) {
                feature.setName(Lists.newArrayList(new CodeType(fpt.getTitle())));
            }
            if (checkForRequestUrl(fpt.getHref())) {
                feature.setUrl(fpt.getHref());
            }
            feature.setFeatureType(OGCConstants.UNKNOWN);
            sosFeatureRelationship.setFeature(feature);
        } else {
            final Object decodedObject = decodeXmlElement(fpt);
            if (decodedObject instanceof AbstractSamplingFeature) {
                sosFeatureRelationship.setFeature((AbstractSamplingFeature) decodedObject);
            } else {
                throw new DecoderResponseUnsupportedException(fpt.xmlText(), decodedObject);
            }
        }
        sosFeatureRelationship.setRole(relatedFeature.getFeatureRelationship().getRole());
        sosRelatedFeatures.add(sosFeatureRelationship);
    }
    return sosRelatedFeatures;
}
Also used : DecoderResponseUnsupportedException(org.n52.svalbard.decode.exception.DecoderResponseUnsupportedException) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) RelatedFeature(net.opengis.swes.x20.InsertSensorType.RelatedFeature) ArrayList(java.util.ArrayList) CodeType(org.n52.shetland.ogc.gml.CodeType) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) OwsServiceCommunicationObject(org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject) XmlObject(org.apache.xmlbeans.XmlObject) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) SwesFeatureRelationship(org.n52.shetland.ogc.swes.SwesFeatureRelationship) FeaturePropertyType(net.opengis.gml.x32.FeaturePropertyType)

Example 20 with CodeWithAuthority

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

the class SamplingDecoderv20 method getSampledFeatures.

/**
 * Parse {@link FeaturePropertyType} sampledFeature to
 * {@link AbstractFeature} list.
 *
 * @param sampledFeature
 *            SampledFeature to parse
 * @return List with the parsed sampledFeature
 * @throws DecodingException
 *             If an error occurs
 */
private List<AbstractFeature> getSampledFeatures(final FeaturePropertyType sampledFeature) throws DecodingException {
    final List<AbstractFeature> sampledFeatures = new ArrayList<>(1);
    if (sampledFeature != null && !sampledFeature.isNil()) {
        // if xlink:href is set
        if (sampledFeature.getHref() != null && !sampledFeature.getHref().isEmpty()) {
            if (sampledFeature.getHref().startsWith("#")) {
                sampledFeatures.add(new SamplingFeature(null, sampledFeature.getHref().replace("#", "")));
            } else {
                final SamplingFeature sampFeat = new SamplingFeature(new CodeWithAuthority(sampledFeature.getHref()));
                if (sampledFeature.getTitle() != null && !sampledFeature.getTitle().isEmpty()) {
                    sampFeat.addName(new CodeType(sampledFeature.getTitle()));
                }
                sampledFeatures.add(sampFeat);
            }
        } else {
            XmlObject abstractFeature = null;
            if (sampledFeature.getAbstractFeature() != null) {
                abstractFeature = sampledFeature.getAbstractFeature();
            } else if (sampledFeature.getDomNode().hasChildNodes()) {
                try {
                    abstractFeature = XmlObject.Factory.parse(XmlHelper.getNodeFromNodeList(sampledFeature.getDomNode().getChildNodes()));
                } catch (XmlException xmle) {
                    throw new DecodingException("Error while parsing feature request!", xmle);
                }
            }
            if (abstractFeature != null) {
                final Object decodedObject = decodeXmlObject(abstractFeature);
                if (decodedObject instanceof AbstractFeature) {
                    sampledFeatures.add((AbstractFeature) decodedObject);
                }
            }
            throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested sampledFeature type is not supported by this service!");
        }
    }
    return sampledFeatures;
}
Also used : XmlException(org.apache.xmlbeans.XmlException) ArrayList(java.util.ArrayList) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) CodeType(org.n52.shetland.ogc.gml.CodeType) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlObject(org.apache.xmlbeans.XmlObject) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority)

Aggregations

CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)28 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)17 Test (org.junit.Test)9 CodeType (org.n52.shetland.ogc.gml.CodeType)7 XmlObject (org.apache.xmlbeans.XmlObject)6 OmObservation (org.n52.shetland.ogc.om.OmObservation)6 SamplingFeatureComplex (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeatureComplex)6 OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)5 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)5 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)4 EncodingException (org.n52.svalbard.encode.exception.EncodingException)4 ArrayList (java.util.ArrayList)3 DateTime (org.joda.time.DateTime)3 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)3 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)3 XmlException (org.apache.xmlbeans.XmlException)2 XmlOptions (org.apache.xmlbeans.XmlOptions)2 Before (org.junit.Before)2 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)2 QuantityValue (org.n52.shetland.ogc.om.values.QuantityValue)2