Search in sources :

Example 6 with EncoderRepository

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

the class EReportingHeaderEncoderTest method validate.

protected void validate(EReportingHeader header) throws XMLStreamException, OwsExceptionReport, IOException, SAXException, MalformedURLException, EncodingException {
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        new EReportingHeaderEncoder(EncodingContext.of(EncoderFlags.ENCODER_REPOSITORY, new EncoderRepository()), baos, header).write();
        System.out.println(baos.toString("UTF-8"));
    // xmlValidation(baos);
    }
}
Also used : EncoderRepository(org.n52.svalbard.encode.EncoderRepository) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 7 with EncoderRepository

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

the class RelatedOfferingXmlStreamWriterTest method should_encode_relatedOfferings.

@Test
public void should_encode_relatedOfferings() throws XMLStreamException, EncodingException, XmlException, IOException {
    RelatedOfferings ro = new RelatedOfferings();
    ro.addValue("role_1", "offering_1");
    ro.addValue("role_2", "offering_2");
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        new RelatedOfferingXmlStreamWriter(EncodingContext.of(EncoderFlags.ENCODER_REPOSITORY, new EncoderRepository()), out, ro).write();
        XmlObject.Factory.parse(new String(out.toByteArray()));
    }
}
Also used : EncoderRepository(org.n52.svalbard.encode.EncoderRepository) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RelatedOfferings(org.n52.shetland.ogc.sos.ro.RelatedOfferings) Test(org.junit.Test)

Example 8 with EncoderRepository

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

the class AbstractEReportingHeaderCoding method getEncoder.

protected EReportingHeaderJSONEncoder getEncoder() {
    EncoderRepository encoderRepository = new EncoderRepository();
    EReportingHeaderJSONEncoder eReportingHeaderJSONEncoder = new EReportingHeaderJSONEncoder();
    eReportingHeaderJSONEncoder.setEncoderRepository(encoderRepository);
    EReportingChangeJSONEncoder eReportingChangeJSONEncoder = new EReportingChangeJSONEncoder();
    eReportingChangeJSONEncoder.setEncoderRepository(encoderRepository);
    InspireIDJSONEncoder inspireIDJSONEncoder = new InspireIDJSONEncoder();
    inspireIDJSONEncoder.setEncoderRepository(encoderRepository);
    NillableJSONEncoder nillableJSONEncoder = new NillableJSONEncoder();
    nillableJSONEncoder.setEncoderRepository(encoderRepository);
    IterableJSONEncoder iterableJSONEncoder = new IterableJSONEncoder();
    iterableJSONEncoder.setEncoderRepository(encoderRepository);
    RelatedPartyJSONEncoder relatedPartyJSONEncoder = new RelatedPartyJSONEncoder();
    relatedPartyJSONEncoder.setEncoderRepository(encoderRepository);
    ContactJSONEncoder contactJSONEncoder = new ContactJSONEncoder();
    contactJSONEncoder.setEncoderRepository(encoderRepository);
    AddressJSONEncoder addressJSONEncoder = new AddressJSONEncoder();
    addressJSONEncoder.setEncoderRepository(encoderRepository);
    GeographicNameJSONEncoder geographicNameJSONEncoder = new GeographicNameJSONEncoder();
    geographicNameJSONEncoder.setEncoderRepository(encoderRepository);
    CodeTypeJSONEncoder codeTypeJSONEncoder = new CodeTypeJSONEncoder();
    codeTypeJSONEncoder.setEncoderRepository(encoderRepository);
    StringJSONEncoder stringJSONEncoder = new StringJSONEncoder();
    stringJSONEncoder.setEncoderRepository(encoderRepository);
    PronunciationJSONEncoder pronunciationJSONEncoder = new PronunciationJSONEncoder();
    pronunciationJSONEncoder.setEncoderRepository(encoderRepository);
    URIJSONEncoder uriJSONEncoder = new URIJSONEncoder();
    uriJSONEncoder.setEncoderRepository(encoderRepository);
    SpellingJSONEncoder spellingJSONEncoder = new SpellingJSONEncoder();
    spellingJSONEncoder.setEncoderRepository(encoderRepository);
    ReferenceJSONEncoder referenceJSONEncoder = new ReferenceJSONEncoder();
    referenceJSONEncoder.setEncoderRepository(encoderRepository);
    PTFreeTextJSONEncoder ptFreeTextJSONEncoder = new PTFreeTextJSONEncoder();
    ptFreeTextJSONEncoder.setEncoderRepository(encoderRepository);
    ReferenceableJSONEncoder referenceableJSONEncoder = new ReferenceableJSONEncoder();
    referenceableJSONEncoder.setEncoderRepository(encoderRepository);
    TimeJSONEncoder timeJSONEncoder = new TimeJSONEncoder();
    timeJSONEncoder.setEncoderRepository(encoderRepository);
    encoderRepository.setEncoders(Arrays.asList(eReportingHeaderJSONEncoder, eReportingChangeJSONEncoder, inspireIDJSONEncoder, nillableJSONEncoder, iterableJSONEncoder, relatedPartyJSONEncoder, contactJSONEncoder, addressJSONEncoder, geographicNameJSONEncoder, codeTypeJSONEncoder, stringJSONEncoder, pronunciationJSONEncoder, uriJSONEncoder, spellingJSONEncoder, referenceJSONEncoder, ptFreeTextJSONEncoder, referenceableJSONEncoder, timeJSONEncoder));
    encoderRepository.init();
    return eReportingHeaderJSONEncoder;
}
Also used : IterableJSONEncoder(org.n52.svalbard.encode.json.IterableJSONEncoder) TimeJSONEncoder(org.n52.svalbard.encode.json.base.TimeJSONEncoder) InspireIDJSONEncoder(org.n52.svalbard.encode.json.InspireIDJSONEncoder) EReportingChangeJSONEncoder(org.n52.svalbard.encode.json.EReportingChangeJSONEncoder) ContactJSONEncoder(org.n52.svalbard.encode.json.ContactJSONEncoder) CodeTypeJSONEncoder(org.n52.svalbard.encode.json.CodeTypeJSONEncoder) RelatedPartyJSONEncoder(org.n52.svalbard.encode.json.RelatedPartyJSONEncoder) SpellingJSONEncoder(org.n52.svalbard.encode.json.SpellingJSONEncoder) EncoderRepository(org.n52.svalbard.encode.EncoderRepository) PTFreeTextJSONEncoder(org.n52.svalbard.encode.json.PTFreeTextJSONEncoder) GeographicNameJSONEncoder(org.n52.svalbard.encode.json.GeographicNameJSONEncoder) StringJSONEncoder(org.n52.svalbard.encode.json.base.StringJSONEncoder) AddressJSONEncoder(org.n52.svalbard.encode.json.AddressJSONEncoder) ReferenceableJSONEncoder(org.n52.svalbard.encode.json.ReferenceableJSONEncoder) EReportingHeaderJSONEncoder(org.n52.svalbard.encode.json.EReportingHeaderJSONEncoder) NillableJSONEncoder(org.n52.svalbard.encode.json.NillableJSONEncoder) PronunciationJSONEncoder(org.n52.svalbard.encode.json.PronunciationJSONEncoder) URIJSONEncoder(org.n52.svalbard.encode.json.base.URIJSONEncoder) ReferenceJSONEncoder(org.n52.svalbard.encode.json.ReferenceJSONEncoder)

Example 9 with EncoderRepository

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

the class ReportingHeaderReaderTest method testValidity.

@Test
public void testValidity() throws Exception {
    EReportingHeader header = new EReportingHeader().setInspireID(new Identifier("id", "namespace").setVersionId(Nillable.missing())).setChange(new EReportingChange("Changed because... you know")).setReportingPeriod(Referenceable.of(Nillable.present(new TimeInstant(DateTime.now())))).setReportingAuthority(new RelatedParty().setIndividualName(Nillable.missing()).setOrganisationName("Organisation").setPositionName("Postionti").addRole(new Reference().setHref(URI.create("http://hallo"))).addRole(Nillable.withheld()).setContact(new Contact().addTelephoneFacsimile("1234").addTelephoneFacsimile(Nillable.missing()).addTelephoneVoice("asdfasdf").setHoursOfService(new PT_FreeText().addTextGroup(new LocalisedCharacterString("asdfasdf"))).setWebsite(Nillable.unknown()).setElectronicMailAddress(Nillable.unknown()).setAddress(new AddressRepresentation().setPostCode("12341234").setAddressFeature(new Reference().setHref(URI.create("http://asdfasdf"))).addLocatorDesignator("localtor").addAddressArea(Nillable.withheld()).addAddressArea(new GeographicalName().setGrammaticalGender(new CodeType("a", new URI("b"))).setGrammaticalNumber(new CodeType("c", new URI("d"))).setLanguage("eng").setNativeness(new CodeType("<asdfasdf")).setNameStatus(Nillable.unknown()).addSpelling(new Spelling().setScript("asdfasdf").setText("asdfasdf").setTransliterationScheme("asdfasdfasdf")).setPronunciation(new Pronunciation().setIPA("asdfasdf").setSoundLink(URI.create("http://asdfasdf")))).addAdminUnit(new GeographicalName().setGrammaticalGender(new CodeType("a", new URI("b"))).setGrammaticalNumber(new CodeType("c", new URI("d"))).setLanguage("eng").setNativeness(new CodeType("<asdfasdf")).setNameStatus(Nillable.unknown()).addSpelling(new Spelling().setScript("asdfasdf").setText("asdfasdf").setTransliterationScheme("asdfasdfasdf")).setPronunciation(new Pronunciation().setIPA("asdfasdf").setSoundLink(URI.create("http://asdfasdf")))).addPostName(Nillable.withheld()).addPostName(new GeographicalName().setGrammaticalGender(new CodeType("a", new URI("b"))).setGrammaticalNumber(new CodeType("c", new URI("d"))).setLanguage("eng").setNativeness(new CodeType("<asdfasdf")).setNameStatus(Nillable.unknown()).addSpelling(new Spelling().setScript("asdfasdf").setText("asdfasdf").setTransliterationScheme("asdfasdfasdf")).setPronunciation(new Pronunciation().setIPA("asdfasdf").setSoundLink(URI.create("http://asdfasdf")))).addThoroughfare(Nillable.withheld()).addThoroughfare(new GeographicalName().setGrammaticalGender(new CodeType("a", new URI("b"))).setGrammaticalNumber(new CodeType("c", new URI("d"))).setLanguage("eng").setNativeness(new CodeType("<asdfasdf")).setNameStatus(Nillable.unknown()).addSpelling(new Spelling().setScript("asdfasdf").setText("asdfasdf").setTransliterationScheme("asdfasdfasdf")).setPronunciation(new Pronunciation().setIPA("asdfasdf").setSoundLink(URI.create("http://asdfasdf")))))));
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        new EReportingHeaderEncoder(EncodingContext.of(EncoderFlags.ENCODER_REPOSITORY, new EncoderRepository()), baos, header).write();
        ByteArrayInputStream in = new ByteArrayInputStream(baos.toByteArray());
        EReportingHeader read = new ReportingHeaderReader().read(in);
        errors.checkThat(read.getChange(), is(equalTo(header.getChange())));
        errors.checkThat(read.getContent(), is(equalTo(header.getContent())));
        errors.checkThat(read.getDelete(), is(equalTo(header.getDelete())));
        errors.checkThat(read.getInspireID(), is(equalTo(header.getInspireID())));
        errors.checkThat(read.getReportingPeriod(), is(equalTo(header.getReportingPeriod())));
        errors.checkThat(read.getReportingAuthority(), is(equalTo(header.getReportingAuthority())));
        errors.checkThat(read.getReportingAuthority().getIndividualName(), is(header.getReportingAuthority().getIndividualName()));
        errors.checkThat(read.getReportingAuthority().getOrganisationName().get(), is(header.getReportingAuthority().getOrganisationName().get()));
        errors.checkThat(read.getReportingAuthority().getPositionName().get(), is(header.getReportingAuthority().getPositionName().get()));
        Contact c1 = read.getReportingAuthority().getContact().get();
        Contact c2 = header.getReportingAuthority().getContact().get();
        errors.checkThat(c1, is(c2));
        errors.checkThat(c1.getContactInstructions(), is(c2.getContactInstructions()));
        errors.checkThat(c1.getElectronicMailAddress(), is(c2.getElectronicMailAddress()));
        errors.checkThat(c1.getHoursOfService().get(), is(c2.getHoursOfService().get()));
        errors.checkThat(c1.getTelephoneFacsimile(), is(c2.getTelephoneFacsimile()));
        errors.checkThat(c1.getTelephoneVoice(), is(c2.getTelephoneVoice()));
        errors.checkThat(c1.getWebsite(), is(c2.getWebsite()));
        AddressRepresentation a1 = c1.getAddress().get();
        AddressRepresentation a2 = c2.getAddress().get();
        errors.checkThat(a1.getAddressAreas(), is(a2.getAddressAreas()));
        errors.checkThat(a1.getAddressFeature(), is(a2.getAddressFeature()));
        errors.checkThat(a1.getAdminUnits(), is(a2.getAdminUnits()));
        errors.checkThat(a1.getLocatorDesignators(), is(a2.getLocatorDesignators()));
        errors.checkThat(a1.getLocatorNames(), is(a2.getLocatorNames()));
        errors.checkThat(a1.getPostCode(), is(a2.getPostCode()));
        errors.checkThat(a1.getPostNames(), is(a2.getPostNames()));
        errors.checkThat(a1.getThoroughfares(), is(a2.getThoroughfares()));
    } catch (Exception e) {
        errors.addError(e);
    }
}
Also used : LocalisedCharacterString(org.n52.shetland.iso.gmd.LocalisedCharacterString) Spelling(org.n52.shetland.inspire.Spelling) Pronunciation(org.n52.shetland.inspire.Pronunciation) Reference(org.n52.shetland.w3c.xlink.Reference) EncoderRepository(org.n52.svalbard.encode.EncoderRepository) PT_FreeText(org.n52.shetland.iso.gmd.PT_FreeText) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URI(java.net.URI) Contact(org.n52.shetland.inspire.base2.Contact) Identifier(org.n52.shetland.inspire.base.Identifier) ByteArrayInputStream(java.io.ByteArrayInputStream) ReportingHeaderReader(org.n52.svalbard.read.ReportingHeaderReader) EReportingHeader(org.n52.shetland.aqd.EReportingHeader) AddressRepresentation(org.n52.shetland.inspire.ad.AddressRepresentation) GeographicalName(org.n52.shetland.inspire.GeographicalName) RelatedParty(org.n52.shetland.inspire.base2.RelatedParty) CodeType(org.n52.shetland.ogc.gml.CodeType) EReportingChange(org.n52.shetland.aqd.EReportingChange) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) Test(org.junit.Test)

Aggregations

EncoderRepository (org.n52.svalbard.encode.EncoderRepository)5 XmlOptions (org.apache.xmlbeans.XmlOptions)4 Before (org.junit.Before)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 CodeType (org.n52.shetland.ogc.gml.CodeType)3 Test (org.junit.Test)2 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)2 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 URI (java.net.URI)1 EReportingChange (org.n52.shetland.aqd.EReportingChange)1 EReportingHeader (org.n52.shetland.aqd.EReportingHeader)1 GeographicalName (org.n52.shetland.inspire.GeographicalName)1 Pronunciation (org.n52.shetland.inspire.Pronunciation)1 Spelling (org.n52.shetland.inspire.Spelling)1 AddressRepresentation (org.n52.shetland.inspire.ad.AddressRepresentation)1 Identifier (org.n52.shetland.inspire.base.Identifier)1 Contact (org.n52.shetland.inspire.base2.Contact)1 RelatedParty (org.n52.shetland.inspire.base2.RelatedParty)1 LocalisedCharacterString (org.n52.shetland.iso.gmd.LocalisedCharacterString)1