Search in sources :

Example 1 with Contact

use of org.n52.shetland.inspire.base2.Contact in project arctic-sea by 52North.

the class ContactJSONDecoder method decodeJSON.

@Override
public Contact decodeJSON(JsonNode node, boolean validate) throws DecodingException {
    Contact contact = new Contact();
    contact.setAddress(decodeJsonToNillable(node.path(AQDJSONConstants.ADDRESS), AddressRepresentation.class));
    contact.setContactInstructions(parseNillable(node.path(AQDJSONConstants.CONTACT_INSTRUCTIONS)).map(this::parseFreeText));
    contact.setElectronicMailAddress(parseNillableString(node.path(AQDJSONConstants.ELECTRONIC_MAIL_ADDRESS)));
    contact.setHoursOfService(parseNillable(node.path(AQDJSONConstants.HOURS_OF_SERVICE)).map(this::parseFreeText));
    contact.setWebsite(parseNillableString(node.path(AQDJSONConstants.WEBSITE)));
    JsonNode tfNode = node.path(AQDJSONConstants.TELEPHONE_FACSIMILE);
    if (tfNode.isArray()) {
        for (JsonNode n : tfNode) {
            contact.addTelephoneFacsimile(parseNillableString(n));
        }
    } else {
        contact.addTelephoneFacsimile(parseNillableString(tfNode));
    }
    JsonNode tvNode = node.path(AQDJSONConstants.TELEPHONE_VOICE);
    if (tvNode.isArray()) {
        for (JsonNode n : tvNode) {
            contact.addTelephoneVoice(parseNillableString(n));
        }
    } else {
        contact.addTelephoneVoice(parseNillableString(tvNode));
    }
    return contact;
}
Also used : AddressRepresentation(org.n52.shetland.inspire.ad.AddressRepresentation) JsonNode(com.fasterxml.jackson.databind.JsonNode) Contact(org.n52.shetland.inspire.base2.Contact)

Example 2 with Contact

use of org.n52.shetland.inspire.base2.Contact in project arctic-sea by 52North.

the class RelatedPartyTypeDecoder method parseContact.

private Contact parseContact(RelatedPartyType rpt) throws DecodingException {
    ContactType ct = rpt.getContact().getContact();
    Contact contact = new Contact();
    contact.setAddress(parseAddress(ct));
    contact.setContactInstructions(parseContactInstructions(ct));
    contact.setElectronicMailAddress(parseElectronicMailAddress(ct));
    contact.setTelephoneFacsimile(parseTelephoneFacsimile(ct));
    contact.setTelephoneVoice(parseTelephoneVoice(ct));
    contact.setWebsite(parseWebsite(ct));
    return contact;
}
Also used : ContactType(eu.europa.ec.inspire.schemas.base2.x20.ContactType) Contact(org.n52.shetland.inspire.base2.Contact)

Example 3 with Contact

use of org.n52.shetland.inspire.base2.Contact in project arctic-sea by 52North.

the class SensorMLEncoderv101 method mergeContacts.

@SuppressWarnings("unused")
private Contact[] mergeContacts(final Contact[] contacts, final ContactList additionalContactsList) {
    final Set<Person> mergedPersons = Sets.newHashSet();
    final Set<ResponsibleParty> mergedResponsibleParties = Sets.newHashSet();
    for (final Contact contact : contacts) {
        if (isContactListSetAndContainingElements(contact)) {
            for (final net.opengis.sensorML.x101.ContactListDocument.ContactList.Member member : contact.getContactList().getMemberArray()) {
                if (member.isSetPerson()) {
                    mergedPersons.add(member.getPerson());
                } else if (member.isSetResponsibleParty()) {
                    mergedResponsibleParties.add(member.getResponsibleParty());
                }
            }
        } else if (contact.isSetPerson()) {
            mergedPersons.add(contact.getPerson());
        } else if (contact.isSetResponsibleParty()) {
            mergedResponsibleParties.add(contact.getResponsibleParty());
        }
    }
    for (final net.opengis.sensorML.x101.ContactListDocument.ContactList.Member member : additionalContactsList.getMemberArray()) {
        if (member.isSetPerson() && !isContained(member.getPerson(), mergedPersons)) {
            mergedPersons.add(member.getPerson());
        } else if (member.isSetResponsibleParty() && !isContained(member.getResponsibleParty(), mergedResponsibleParties)) {
            mergedResponsibleParties.add(member.getResponsibleParty());
        }
    }
    final Contact newContact = Contact.Factory.newInstance();
    final ContactList newContactList = ContactList.Factory.newInstance();
    mergedResponsibleParties.forEach(responsibleParty -> newContactList.addNewMember().addNewResponsibleParty().set(responsibleParty));
    mergedPersons.forEach(person -> newContactList.addNewMember().addNewPerson().set(person));
    if (newContactList.sizeOfMemberArray() == 1) {
        if (newContactList.getMemberArray(0).isSetPerson()) {
            newContact.addNewPerson().set(newContactList.getMemberArray(0).getPerson());
        } else if (newContactList.getMemberArray(0).isSetResponsibleParty()) {
            newContact.addNewResponsibleParty().set(newContactList.getMemberArray(0).getResponsibleParty());
        }
    } else {
        newContact.addNewContactList().set(newContactList);
    }
    final Contact[] result = { newContact };
    return result;
}
Also used : ContactList(net.opengis.sensorML.x101.ContactListDocument.ContactList) SmlContactList(org.n52.shetland.ogc.sensorML.SmlContactList) ResponsibleParty(net.opengis.sensorML.x101.ResponsiblePartyDocument.ResponsibleParty) SmlResponsibleParty(org.n52.shetland.ogc.sensorML.SmlResponsibleParty) SmlPerson(org.n52.shetland.ogc.sensorML.SmlPerson) Person(net.opengis.sensorML.x101.PersonDocument.Person) Contact(net.opengis.sensorML.x101.ContactDocument.Contact) SmlContact(org.n52.shetland.ogc.sensorML.SmlContact)

Example 4 with Contact

use of org.n52.shetland.inspire.base2.Contact in project arctic-sea by 52North.

the class EReportingHeaderEncoderTest method testValidity.

@Test
public void testValidity() throws XMLStreamException, OwsExceptionReport, SAXException, MalformedURLException, IOException, URISyntaxException, EncodingException {
    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")))))));
    validate(header);
}
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) PT_FreeText(org.n52.shetland.iso.gmd.PT_FreeText) URI(java.net.URI) Contact(org.n52.shetland.inspire.base2.Contact) Identifier(org.n52.shetland.inspire.base.Identifier) 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)

Example 5 with Contact

use of org.n52.shetland.inspire.base2.Contact in project tests by datanucleus.

the class RelationshipsTest method testOneToManyBidirMappedByDotNotation.

/**
 * Test of 1-N bidir with element having embedded PC, and 1-1 bidir with embedded PC, and using "mappedBy" with DOT notation.
 */
public void testOneToManyBidirMappedByDotNotation() {
    try {
        EntityManager em = getEM();
        EntityTransaction tx = em.getTransaction();
        try {
            tx.begin();
            Contact c1 = new Contact("John Doe");
            Document d1 = new Document("Doc1", c1);
            Document d2 = new Document("Doc2", c1);
            c1.setMainDocument(d1);
            d1.getDetails().setOwner(c1);
            c1.getDocuments().add(d2);
            d2.getDetails().setOwner(c1);
            em.persist(c1);
            em.persist(d1);
            em.persist(d2);
            Contact c2 = new Contact("Jane Dose");
            em.persist(c2);
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
            fail("Exception thrown while creating data");
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            em.close();
        }
        // Query the datastore and check the results
        em = getEM();
        tx = em.getTransaction();
        List<Document> documents = null;
        try {
            tx.begin();
            TypedQuery<Document> query = em.createQuery("SELECT d FROM Document d JOIN FETCH d.details.owner owner_1 WHERE d.name = 'Doc2'", Document.class);
            documents = query.getResultList();
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
            fail("Exception thrown while retrieving data");
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            em.close();
        }
        assertEquals(1, documents.size());
        assertEquals("Doc2", documents.get(0).getName());
        assertEquals("John Doe", documents.get(0).getDetails().getOwner().getName());
        em = getEM();
        tx = em.getTransaction();
        try {
            tx.begin();
            // Null out the relations
            TypedQuery<Contact> query = em.createQuery("SELECT c FROM " + Contact.class.getName() + " c", Contact.class);
            List<Contact> contacts = query.getResultList();
            for (Contact c : contacts) {
                c.setMainDocument(null);
                c.getDocuments().clear();
            }
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
            fail("Exception thrown while retrieving data");
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            em.close();
        }
    } finally {
        clean(Contact.class);
        clean(Document.class);
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) Document(org.datanucleus.samples.annotations.one_many.bidir_3.Document) Contact(org.datanucleus.samples.annotations.one_many.bidir_3.Contact)

Aggregations

Test (org.junit.Test)5 Contact (org.n52.shetland.inspire.base2.Contact)4 SmlPerson (org.n52.shetland.ogc.sensorML.SmlPerson)4 SmlResponsibleParty (org.n52.shetland.ogc.sensorML.SmlResponsibleParty)4 ContactList (net.opengis.sensorML.x101.ContactListDocument.ContactList)3 Person (net.opengis.sensorML.x101.PersonDocument.Person)3 ResponsibleParty (net.opengis.sensorML.x101.ResponsiblePartyDocument.ResponsibleParty)3 SystemType (net.opengis.sensorML.x101.SystemType)3 AddressRepresentation (org.n52.shetland.inspire.ad.AddressRepresentation)3 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)3 URI (java.net.URI)2 Contact (net.opengis.sensorML.x101.ContactDocument.Contact)2 SensorMLDocument (net.opengis.sensorML.x101.SensorMLDocument)2 XmlObject (org.apache.xmlbeans.XmlObject)2 EReportingChange (org.n52.shetland.aqd.EReportingChange)2 EReportingHeader (org.n52.shetland.aqd.EReportingHeader)2 GeographicalName (org.n52.shetland.inspire.GeographicalName)2 Pronunciation (org.n52.shetland.inspire.Pronunciation)2 Spelling (org.n52.shetland.inspire.Spelling)2 Identifier (org.n52.shetland.inspire.base.Identifier)2