Search in sources :

Example 1 with EReportingHeader

use of org.n52.shetland.aqd.EReportingHeader in project arctic-sea by 52North.

the class EReportingHeaderJSONDecoder method decodeJSON.

@Override
public EReportingHeader decodeJSON(JsonNode node, boolean validate) throws DecodingException {
    EReportingHeader header = new EReportingHeader();
    header.setChange(decodeJsonToObject(node.path(AQDJSONConstants.CHANGE), EReportingChange.class));
    header.setIdentifier(decodeJsonToObject(node.path(AQDJSONConstants.INSPIRE_ID), Identifier.class));
    header.setReportingAuthority(decodeJsonToObject(node.path(AQDJSONConstants.REPORTING_AUTHORITY), RelatedParty.class));
    header.setReportingPeriod(parseReferenceableTime(node.path(AQDJSONConstants.REPORTING_PERIOD)));
    for (JsonNode child : node.path(AQDJSONConstants.CONTENT)) {
        header.addContent(decodeJsonToReferencable(child, AbstractFeature.class));
    }
    for (JsonNode child : node.path(AQDJSONConstants.DELETE)) {
        header.addDelete(decodeJsonToReferencable(child, AbstractFeature.class));
    }
    return header;
}
Also used : Identifier(org.n52.shetland.inspire.base.Identifier) EReportingHeader(org.n52.shetland.aqd.EReportingHeader) RelatedParty(org.n52.shetland.inspire.base2.RelatedParty) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) JsonNode(com.fasterxml.jackson.databind.JsonNode) EReportingChange(org.n52.shetland.aqd.EReportingChange)

Example 2 with EReportingHeader

use of org.n52.shetland.aqd.EReportingHeader in project arctic-sea by 52North.

the class EReportingHeaderJSONDecoderTest method test.

@Test
public void test() throws OwsExceptionReport, URISyntaxException, EncodingException, DecodingException {
    EReportingHeader header = getHeader();
    JsonNode encode = getEncoder().encode(header);
    EReportingHeader o = getDecoder().decode(encode);
    assertThat(o.getInspireID() != null, is(true));
    assertThat(o.getInspireID().getLocalId(), equalTo(header.getInspireID().getLocalId()));
    assertThat(o.getInspireID().getValue(), equalTo(header.getInspireID().getValue()));
    assertThat(o.getInspireID().getVersionId(), equalTo(header.getInspireID().getVersionId()));
    assertThat(o.getChange(), equalTo(header.getChange()));
    assertThat(o.getReportingPeriod().isInstance(), is(true));
    assertThat(o.getReportingPeriod().getInstance().isPresent(), is(true));
    assertThat(o.getReportingPeriod().getInstance().get(), equalTo(header.getReportingPeriod().getInstance().get()));
    assertThat(o.getReportingAuthority() != null, is(true));
    assertThat(o.getReportingAuthority(), instanceOf(RelatedParty.class));
    assertThat(o.getReportingAuthority().getIndividualName().isNil(), is(true));
    assertThat(o.getReportingAuthority().getIndividualName().getNilReason().isPresent(), is(true));
    assertThat(o.getReportingAuthority().getIndividualName().getNilReason().get(), equalTo(header.getReportingAuthority().getIndividualName().getNilReason().get()));
    assertThat(o.getReportingAuthority().getOrganisationName().isPresent(), is(true));
    assertThat(o.getReportingAuthority().getOrganisationName().get(), equalTo(header.getReportingAuthority().getOrganisationName().get()));
    assertThat(o.getReportingAuthority().getPositionName().isPresent(), is(true));
    assertThat(o.getReportingAuthority().getPositionName().get(), equalTo(header.getReportingAuthority().getPositionName().get()));
    assertThat(o.getReportingAuthority().getRoles() != null, is(true));
    assertThat(o.getReportingAuthority().getRoles().size(), is(2));
    assertThat(o.getReportingAuthority().getRoles().get(0).isPresent(), is(true));
    assertThat(o.getReportingAuthority().getRoles().get(0).get().getHref().isPresent(), is(true));
    assertThat(o.getReportingAuthority().getRoles().get(0).get().getHref().get(), equalTo(header.getReportingAuthority().getRoles().get(0).get().getHref().get()));
    assertThat(o.getReportingAuthority().getRoles().get(1).isNil(), is(true));
    assertThat(o.getReportingAuthority().getRoles().get(1).getNilReason().isPresent(), is(true));
    assertThat(o.getReportingAuthority().getRoles().get(1).getNilReason(), equalTo(header.getReportingAuthority().getRoles().get(1).getNilReason()));
    assertThat(o.getReportingAuthority().getContact().isPresent(), is(true));
    assertThat(o.getReportingAuthority().getContact().get().getTelephoneFacsimile().isPresent(), is(true));
    assertThat(o.getReportingAuthority().getContact().get().getTelephoneFacsimile().get().size(), is(2));
    assertThat(o.getReportingAuthority().getContact().get().getTelephoneFacsimile().get().get(0).isPresent(), is(true));
    assertThat(o.getReportingAuthority().getContact().get().getTelephoneFacsimile().get().get(0).get(), equalTo(header.getReportingAuthority().getContact().get().getTelephoneFacsimile().get().get(0).get()));
    assertThat(o.getReportingAuthority().getContact().get().getTelephoneFacsimile().get().get(1).isNil(), is(true));
    assertThat(o.getReportingAuthority().getContact().get().getTelephoneFacsimile().get().get(1).getNilReason().isPresent(), is(true));
    assertThat(o.getReportingAuthority().getContact().get().getTelephoneFacsimile().get().get(1).getNilReason(), equalTo(o.getReportingAuthority().getContact().get().getTelephoneFacsimile().get().get(1).getNilReason()));
    assertThat(o.getReportingAuthority().getContact().get().getTelephoneVoice().isPresent(), is(true));
    assertThat(o.getReportingAuthority().getContact().get().getTelephoneVoice().get().size(), is(1));
    assertThat(o.getReportingAuthority().getContact().get().getTelephoneVoice().get().get(0).isPresent(), is(true));
    assertThat(o.getReportingAuthority().getContact().get().getTelephoneVoice().get().get(0).get(), equalTo(header.getReportingAuthority().getContact().get().getTelephoneVoice().get().get(0).get()));
    assertThat(o.getReportingAuthority().getContact().get().getHoursOfService().isPresent(), is(true));
    checkPtFreeText(o.getReportingAuthority().getContact().get().getHoursOfService().get(), header.getReportingAuthority().getContact().get().getHoursOfService().get());
    assertThat(o.getReportingAuthority().getContact().get().getWebsite().isNil(), is(true));
    assertThat(o.getReportingAuthority().getContact().get().getWebsite().getNilReason().isPresent(), is(true));
    assertThat(o.getReportingAuthority().getContact().get().getWebsite().getNilReason().get(), equalTo(header.getReportingAuthority().getContact().get().getWebsite().getNilReason().get()));
    assertThat(o.getReportingAuthority().getContact().get().getElectronicMailAddress().isNil(), is(true));
    assertThat(o.getReportingAuthority().getContact().get().getElectronicMailAddress().getNilReason().isPresent(), is(true));
    assertThat(o.getReportingAuthority().getContact().get().getElectronicMailAddress().getNilReason().get(), equalTo(header.getReportingAuthority().getContact().get().getWebsite().getNilReason().get()));
    checkAddress(o.getReportingAuthority().getContact().get().getAddress(), header.getReportingAuthority().getContact().get().getAddress());
    assertThat(o.getReportingAuthority().getContact().get().getAddress().get().getAdminUnits() != null, is(true));
    assertThat(o.getReportingAuthority().getContact().get().getAddress().get().getAdminUnits().size(), is(1));
    chekGeographicalName(o.getReportingAuthority().getContact().get().getAddress().get().getAdminUnits().get(0), header.getReportingAuthority().getContact().get().getAddress().get().getAdminUnits().get(0));
}
Also used : EReportingHeader(org.n52.shetland.aqd.EReportingHeader) RelatedParty(org.n52.shetland.inspire.base2.RelatedParty) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 3 with EReportingHeader

use of org.n52.shetland.aqd.EReportingHeader in project arctic-sea by 52North.

the class AqdEncoder method encodeGetObservationResponse.

private XmlObject encodeGetObservationResponse(GetObservationResponse response, EncodingContext ctx) throws EncodingException {
    try {
        FeatureCollection featureCollection = getFeatureCollection(response);
        // TODO get FLOW from response
        EReportingHeader eReportingHeader = getEReportingHeader(getReportObligationType(response));
        featureCollection.addMember(eReportingHeader);
        TimePeriod timePeriod = new TimePeriod();
        TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
        int counter = 1;
        ObservationStream observationCollection = response.getObservationCollection();
        while (observationCollection.hasNext()) {
            OmObservation observation = observationCollection.next();
            if (observation.getValue() instanceof ObservationStream) {
                ObservationStream value = (ObservationStream) observation.getValue();
                if (value instanceof StreamingValue) {
                    value = value.merge();
                }
                while (value.hasNext()) {
                    processObservation(value.next(), timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
                }
            } else {
                processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
            }
        }
        if (!timePeriod.isEmpty()) {
            eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
        }
        return encodeObjectToXml(GmlConstants.NS_GML_32, featureCollection, ctx.with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT));
    } catch (OwsExceptionReport ex) {
        throw new EncodingException(ex);
    }
}
Also used : FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) StreamingValue(org.n52.shetland.ogc.om.StreamingValue) EncodingException(org.n52.svalbard.encode.exception.EncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AbstractEReportingHeader(org.n52.shetland.aqd.AbstractEReportingHeader) EReportingHeader(org.n52.shetland.aqd.EReportingHeader) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) OmObservation(org.n52.shetland.ogc.om.OmObservation) Time(org.n52.shetland.ogc.gml.time.Time) DateTime(org.joda.time.DateTime) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) DateTime(org.joda.time.DateTime)

Example 4 with EReportingHeader

use of org.n52.shetland.aqd.EReportingHeader in project arctic-sea by 52North.

the class AqdEncoder method encodeEReportingHeader.

private XmlObject encodeEReportingHeader(EReportingHeader element, EncodingContext ctx) throws EncodingException {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
        new EReportingHeaderEncoder(context, baos, element).write();
        if (context.has(XmlStreamEncoderFlags.XML_WRITER)) {
            return null;
        }
        return XmlObject.Factory.parse(baos.toString("UTF8"));
    } catch (XMLStreamException | XmlException | UnsupportedEncodingException xmlse) {
        throw new EncodingException("Error encoding response", xmlse);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlException(org.apache.xmlbeans.XmlException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Supplier(java.util.function.Supplier) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EReportingHeaderEncoder(org.n52.svalbard.write.EReportingHeaderEncoder)

Example 5 with EReportingHeader

use of org.n52.shetland.aqd.EReportingHeader in project arctic-sea by 52North.

the class AqdGetObservationResponseEncoder method create.

@Override
protected XmlObject create(GetObservationResponse response) throws EncodingException {
    try {
        FeatureCollection featureCollection = createFeatureCollection(response);
        // TODO get FLOW from response
        EReportingHeader eReportingHeader = getEReportingHeader(getReportObligationType(response));
        featureCollection.addMember(eReportingHeader);
        TimePeriod timePeriod = new TimePeriod();
        TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
        int counter = 1;
        while (response.getObservationCollection().hasNext()) {
            OmObservation observation = response.getObservationCollection().next();
            processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
        }
        if (!timePeriod.isEmpty()) {
            eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
        }
        EncodingContext ctx = EncodingContext.empty().with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT);
        return encodeGml(ctx, featureCollection);
    } catch (OwsExceptionReport ex) {
        throw new EncodingException(ex);
    }
}
Also used : FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) EncodingException(org.n52.svalbard.encode.exception.EncodingException) EReportingHeader(org.n52.shetland.aqd.EReportingHeader) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) OmObservation(org.n52.shetland.ogc.om.OmObservation) Time(org.n52.shetland.ogc.gml.time.Time) DateTime(org.joda.time.DateTime) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) DateTime(org.joda.time.DateTime)

Aggregations

EReportingHeader (org.n52.shetland.aqd.EReportingHeader)9 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)5 OmObservation (org.n52.shetland.ogc.om.OmObservation)5 DateTime (org.joda.time.DateTime)4 Test (org.junit.Test)4 RelatedParty (org.n52.shetland.inspire.base2.RelatedParty)4 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)4 EncodingException (org.n52.svalbard.encode.exception.EncodingException)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 EReportingChange (org.n52.shetland.aqd.EReportingChange)3 Identifier (org.n52.shetland.inspire.base.Identifier)3 Time (org.n52.shetland.ogc.gml.time.Time)3 FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)3 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 URI (java.net.URI)2 Supplier (java.util.function.Supplier)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 GeographicalName (org.n52.shetland.inspire.GeographicalName)2