Search in sources :

Example 11 with EncodingException

use of org.n52.svalbard.encode.exception.EncodingException 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 12 with EncodingException

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

the class GetCapabilitiesResponseEncoder method encodeResponse.

@Override
protected void encodeResponse(ObjectNode json, GetCapabilitiesResponse t) throws EncodingException {
    SosCapabilities caps = (SosCapabilities) t.getCapabilities();
    encodeOptional(json, JSONConstants.UPDATE_SEQUENCE, caps.getUpdateSequence(), nodeFactory()::textNode);
    encodeOptional(json, JSONConstants.SERVICE_IDENTIFICATION, caps.getServiceIdentification(), this::encodeServiceIdentification);
    encodeOptional(json, JSONConstants.SERVICE_PROVIDER, caps.getServiceProvider(), this::encodeServiceProvider);
    encodeOptional(json, JSONConstants.OPERATION_METADATA, caps.getOperationsMetadata(), this::encodeOperationMetadata);
    encodeOptionalChecked(json, JSONConstants.CONTENTS, caps.getContents(), this::encodeContents);
    encodeExtensions(json, caps);
    encodeOptional(json, JSONConstants.FILTER_CAPABILITIES, caps.getFilterCapabilities(), this::encodeFilterCapabilities);
}
Also used : SosCapabilities(org.n52.shetland.ogc.sos.SosCapabilities)

Example 13 with EncodingException

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

the class GetResultTemplateResponseEncoder method encodeResultStructure.

private void encodeResultStructure(GetResultTemplateResponse t, ObjectNode json) throws EncodingException {
    ObjectNode jrs = json.putObject(JSONConstants.RESULT_STRUCTURE);
    SweAbstractDataComponent structure;
    SosResultStructure rs = t.getResultStructure();
    if (rs.isDecoded()) {
        structure = t.getResultStructure().get().get();
    } else {
        try {
            XmlNamespaceDecoderKey key = new XmlNamespaceDecoderKey(SweConstants.NS_SWE_20, SweAbstractDataComponent.class);
            Decoder<SweAbstractDataComponent, XmlObject> decoder = this.decoderRepository.getDecoder(key);
            if (decoder == null) {
                throw new NoDecoderForKeyException(key);
            }
            structure = decoder.decode(XmlObject.Factory.parse(rs.getXml().get()));
        } catch (XmlException | DecodingException ex) {
            throw new EncodingException(ex);
        }
    }
    if (structure instanceof SweDataRecord) {
        encodeSweDataRecord(structure, jrs);
    } else {
        LOG.warn("Unsupported structure: {}", structure == null ? null : structure.getClass());
    }
}
Also used : NoDecoderForKeyException(org.n52.svalbard.decode.exception.NoDecoderForKeyException) XmlNamespaceDecoderKey(org.n52.svalbard.decode.XmlNamespaceDecoderKey) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) EncodingException(org.n52.svalbard.encode.exception.EncodingException) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) XmlException(org.apache.xmlbeans.XmlException) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) SosResultStructure(org.n52.shetland.ogc.sos.SosResultStructure)

Example 14 with EncodingException

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

the class ObservationEncoder method encodeSweDataArrayValue.

private JsonNode encodeSweDataArrayValue(Value<?> value) throws EncodingException {
    SweDataArrayValue sweDataArrayValue = (SweDataArrayValue) value;
    ObjectNode result = nodeFactory().objectNode();
    ArrayNode jfields = result.putArray(JSONConstants.FIELDS);
    ArrayNode jvalues = result.putArray(JSONConstants.VALUES);
    List<SweField> fields = ((SweDataRecord) sweDataArrayValue.getValue().getElementType()).getFields();
    List<List<String>> values = sweDataArrayValue.getValue().getValues();
    TokenConverter[] conv = new TokenConverter[fields.size()];
    int i = 0;
    for (SweField field : fields) {
        try {
            conv[i++] = TokenConverter.forField(field);
        } catch (IllegalArgumentException e) {
            throw new UnsupportedEncoderInputException(this, field);
        }
        jfields.add(encodeObjectToJson(field));
    }
    for (List<String> block : values) {
        ArrayNode jblock = jvalues.addArray();
        i = 0;
        for (String token : block) {
            jblock.add(conv[i++].convert(token));
        }
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweDataArrayValue(org.n52.shetland.ogc.om.values.SweDataArrayValue) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) SweField(org.n52.shetland.ogc.swe.SweField) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) List(java.util.List) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 15 with EncodingException

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

the class ObservationEncoder method encodeComplexValue.

private JsonNode encodeComplexValue(Value<?> value) throws EncodingException {
    ArrayNode result = nodeFactory().arrayNode();
    ComplexValue complexValue = (ComplexValue) value;
    SweAbstractDataRecord sweDataRecord = complexValue.getValue();
    for (SweField field : sweDataRecord.getFields()) {
        result.add(encodeObjectToJson(field));
    }
    return result;
}
Also used : ComplexValue(org.n52.shetland.ogc.om.values.ComplexValue) SweAbstractDataRecord(org.n52.shetland.ogc.swe.SweAbstractDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

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