Search in sources :

Example 11 with DecodingException

use of org.n52.svalbard.decode.exception.DecodingException in project arctic-sea by 52North.

the class AddressJSONDecoder method decodeJSON.

@Override
public AddressRepresentation decodeJSON(JsonNode node, boolean validate) throws DecodingException {
    AddressRepresentation address = new AddressRepresentation();
    address.setAddressFeature(parseNillableReference(node.path(AQDJSONConstants.ADDRESS_FEATURE)));
    address.setPostCode(parseNillableString(node.path(AQDJSONConstants.POST_CODE)));
    for (JsonNode n : node.path(AQDJSONConstants.ADDRESS_AREAS)) {
        address.addAddressArea(decodeJsonToNillable(n, GeographicalName.class));
    }
    for (JsonNode n : node.path(AQDJSONConstants.ADMIN_UNITS)) {
        address.addAdminUnit(decodeJsonToObject(n, GeographicalName.class));
    }
    for (JsonNode n : node.path(AQDJSONConstants.LOCATOR_DESIGNATORS)) {
        address.addLocatorDesignator(n.textValue());
    }
    for (JsonNode n : node.path(AQDJSONConstants.LOCATOR_NAMES)) {
        address.addLocatorName(decodeJsonToObject(n, GeographicalName.class));
    }
    for (JsonNode n : node.path(AQDJSONConstants.POST_NAMES)) {
        address.addPostName(decodeJsonToNillable(n, GeographicalName.class));
    }
    for (JsonNode n : node.path(AQDJSONConstants.THOROUGHFARES)) {
        address.addThoroughfare(decodeJsonToNillable(n, GeographicalName.class));
    }
    return address;
}
Also used : AddressRepresentation(org.n52.shetland.inspire.ad.AddressRepresentation) GeographicalName(org.n52.shetland.inspire.GeographicalName) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 12 with DecodingException

use of org.n52.svalbard.decode.exception.DecodingException in project arctic-sea by 52North.

the class BatchRequestDecodingTest method before.

@Before
public void before() throws DecodingException {
    DecoderRepository decoderRepository = new DecoderRepository();
    this.decoder = new BatchRequestDecoder();
    this.decoder.setDecoderRepository(decoderRepository);
    InsertSensorRequestDecoder insertSensorRequestDecoder = new InsertSensorRequestDecoder();
    insertSensorRequestDecoder.setDecoderRepository(decoderRepository);
    InsertObservationRequestDecoder insertObservationRequestDecoder = new InsertObservationRequestDecoder();
    insertObservationRequestDecoder.setDecoderRepository(decoderRepository);
    SensorMLDecoderV101 sensorMLDecoder = new SensorMLDecoderV101();
    sensorMLDecoder.setXmlOptions(XmlOptions::new);
    sensorMLDecoder.setDecoderRepository(decoderRepository);
    SweCommonDecoderV101 sweCommonDecoder = new SweCommonDecoderV101();
    sweCommonDecoder.setXmlOptions(XmlOptions::new);
    sweCommonDecoder.setDecoderRepository(decoderRepository);
    GmlDecoderv311 gmlDecoderv311 = new GmlDecoderv311();
    ObservationDecoder observationDecoder = new ObservationDecoder();
    observationDecoder.setDecoderRepository(decoderRepository);
    InsertResultTemplateRequestDecoder insertResultTemplateRequestDecoder = new InsertResultTemplateRequestDecoder();
    insertResultTemplateRequestDecoder.setDecoderRepository(decoderRepository);
    InsertResultRequestDecoder insertResultRequestDecoder = new InsertResultRequestDecoder();
    insertResultRequestDecoder.setDecoderRepository(decoderRepository);
    FieldDecoder fieldDecoder = new FieldDecoder();
    fieldDecoder.setDecoderRepository(decoderRepository);
    decoderRepository.setDecoders(Arrays.asList(decoder, insertSensorRequestDecoder, insertObservationRequestDecoder, insertResultTemplateRequestDecoder, insertResultRequestDecoder, sensorMLDecoder, sweCommonDecoder, observationDecoder, fieldDecoder, gmlDecoderv311));
    decoderRepository.init();
    this.request = decoder.decodeJSON(json, true);
}
Also used : InsertResultTemplateRequestDecoder(org.n52.svalbard.decode.json.InsertResultTemplateRequestDecoder) SensorMLDecoderV101(org.n52.svalbard.decode.SensorMLDecoderV101) BatchRequestDecoder(org.n52.svalbard.decode.json.BatchRequestDecoder) SweCommonDecoderV101(org.n52.svalbard.decode.SweCommonDecoderV101) InsertResultRequestDecoder(org.n52.svalbard.decode.json.InsertResultRequestDecoder) XmlOptions(org.apache.xmlbeans.XmlOptions) ObservationDecoder(org.n52.svalbard.decode.json.ObservationDecoder) InsertSensorRequestDecoder(org.n52.svalbard.decode.json.InsertSensorRequestDecoder) InsertObservationRequestDecoder(org.n52.svalbard.decode.json.InsertObservationRequestDecoder) DecoderRepository(org.n52.svalbard.decode.DecoderRepository) FieldDecoder(org.n52.svalbard.decode.json.FieldDecoder) GmlDecoderv311(org.n52.svalbard.decode.GmlDecoderv311) Before(org.junit.Before)

Example 13 with DecodingException

use of org.n52.svalbard.decode.exception.DecodingException 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 14 with DecodingException

use of org.n52.svalbard.decode.exception.DecodingException in project arctic-sea by 52North.

the class FieldDecoderTest method testBooleanWithValueTrue.

@Test
public void testBooleanWithValueTrue() throws DecodingException {
    ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.BOOLEAN_TYPE).put(JSONConstants.VALUE, true);
    SweField field = checkCommon(json, true);
    assertThat(field.getElement(), is(instanceOf(SweBoolean.class)));
    SweBoolean swe = (SweBoolean) field.getElement();
    errors.checkThat(swe.getValue(), is(true));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweField(org.n52.shetland.ogc.swe.SweField) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) Test(org.junit.Test)

Example 15 with DecodingException

use of org.n52.svalbard.decode.exception.DecodingException in project arctic-sea by 52North.

the class FieldDecoderTest method timeRange.

@Test
public void timeRange() throws DecodingException {
    ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.TIME_RANGE_TYPE).put(JSONConstants.UOM, UOM);
    SweField field = checkCommon(json, false);
    assertThat(field.getElement(), is(instanceOf(SweTimeRange.class)));
    SweTimeRange swe = (SweTimeRange) field.getElement();
    errors.checkThat(swe.getUom(), is(UOM));
    errors.checkThat(swe.getValue(), is(nullValue()));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweField(org.n52.shetland.ogc.swe.SweField) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)92 DecodingException (org.n52.svalbard.decode.exception.DecodingException)63 XmlObject (org.apache.xmlbeans.XmlObject)52 JsonNode (com.fasterxml.jackson.databind.JsonNode)25 SweField (org.n52.shetland.ogc.swe.SweField)25 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)23 XmlException (org.apache.xmlbeans.XmlException)23 GetObservationRequest (org.n52.shetland.ogc.sos.request.GetObservationRequest)22 UnsupportedDecoderInputException (org.n52.svalbard.decode.exception.UnsupportedDecoderInputException)21 AbstractProcess (org.n52.shetland.ogc.sensorML.AbstractProcess)13 SystemType (net.opengis.sensorML.x101.SystemType)12 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)12 Before (org.junit.Before)11 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)11 SensorMLDocument (net.opengis.sensorML.x101.SensorMLDocument)10 DateTime (org.joda.time.DateTime)10 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)10 XmlString (org.apache.xmlbeans.XmlString)9 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)8 Geometry (org.locationtech.jts.geom.Geometry)8