Search in sources :

Example 1 with ContactList

use of net.opengis.sensorML.x101.ContactListDocument.ContactList in project arctic-sea by 52North.

the class SensorMLEncoderv101 method addAbstractProcessValues.

// TODO refactor/rename
private void addAbstractProcessValues(final AbstractProcessType abstractProcess, final AbstractProcess sosAbstractProcess) throws EncodingException {
    if (sosAbstractProcess.isSetGmlID()) {
        abstractProcess.setId(sosAbstractProcess.getGmlId());
    }
    if (sosAbstractProcess.isSetCapabilities()) {
        final Capabilities[] existing = abstractProcess.getCapabilitiesArray();
        final Set<String> names = Sets.newHashSetWithExpectedSize(existing.length);
        for (final Capabilities element : existing) {
            if (element.getName() != null) {
                names.add(element.getName());
            }
        }
        for (final SmlCapabilities sosCapability : sosAbstractProcess.getCapabilities()) {
            final Capabilities c = createCapability(sosCapability);
            // replace existing capability with the same name
            if (names.contains(c.getName())) {
                removeCapability(abstractProcess, c);
            }
            abstractProcess.addNewCapabilities().set(c);
        }
    }
    // set description
    if (sosAbstractProcess.isSetDescription() && !abstractProcess.isSetDescription()) {
        abstractProcess.addNewDescription().setStringValue(sosAbstractProcess.getDescription());
    }
    if (sosAbstractProcess.isSetName() && CollectionHelper.isNullOrEmpty(abstractProcess.getNameArray())) {
        // TODO check if override existing names
        addNamesToAbstractProcess(abstractProcess, sosAbstractProcess.getNames());
    }
    // set identification
    if (sosAbstractProcess.isSetIdentifications()) {
        abstractProcess.setIdentificationArray(createIdentification(sosAbstractProcess.getIdentifications()));
    }
    // set classification
    if (sosAbstractProcess.isSetClassifications()) {
        abstractProcess.setClassificationArray(createClassification(sosAbstractProcess.getClassifications()));
    }
    // set characteristics
    if (sosAbstractProcess.isSetCharacteristics()) {
        abstractProcess.setCharacteristicsArray(createCharacteristics(sosAbstractProcess.getCharacteristics()));
    }
    // set documentation
    if (sosAbstractProcess.isSetDocumentation() && CollectionHelper.isNullOrEmpty(abstractProcess.getDocumentationArray())) {
        abstractProcess.setDocumentationArray(createDocumentationArray(sosAbstractProcess.getDocumentation()));
    }
    // process
    if (sosAbstractProcess.isSetContact() && CollectionHelper.isNullOrEmpty(abstractProcess.getContactArray())) {
        ContactList contactList = createContactList(sosAbstractProcess.getContact());
        if (contactList != null && contactList.getMemberArray().length > 0) {
            abstractProcess.addNewContact().setContactList(contactList);
        }
    }
    // set keywords
    if (sosAbstractProcess.isSetKeywords()) {
        final List<String> keywords = sosAbstractProcess.getKeywords();
        final int length = abstractProcess.getKeywordsArray().length;
        for (int i = 0; i < length; ++i) {
            abstractProcess.removeKeywords(i);
        }
        abstractProcess.addNewKeywords().addNewKeywordList().setKeywordArray(keywords.toArray(new String[keywords.size()]));
    }
    if (sosAbstractProcess.isSetValidTime()) {
        if (abstractProcess.isSetValidTime()) {
            // remove existing validTime element
            final XmlCursor newCursor = abstractProcess.getValidTime().newCursor();
            newCursor.removeXml();
            newCursor.dispose();
        }
        final Time time = sosAbstractProcess.getMergedValidTime();
        final XmlObject xbtime = encodeObjectToXml(GmlConstants.NS_GML, time);
        if (time instanceof TimeInstant) {
            abstractProcess.addNewValidTime().addNewTimeInstant().set(xbtime);
        } else if (time instanceof TimePeriod) {
            abstractProcess.addNewValidTime().addNewTimePeriod().set(xbtime);
        }
    }
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) Time(org.n52.shetland.ogc.gml.time.Time) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) ContactList(net.opengis.sensorML.x101.ContactListDocument.ContactList) SmlContactList(org.n52.shetland.ogc.sensorML.SmlContactList) XmlCursor(org.apache.xmlbeans.XmlCursor) SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) Capabilities(net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities) SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) XmlObject(org.apache.xmlbeans.XmlObject) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 2 with ContactList

use of net.opengis.sensorML.x101.ContactListDocument.ContactList 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 3 with ContactList

use of net.opengis.sensorML.x101.ContactListDocument.ContactList in project arctic-sea by 52North.

the class SensorMLEncoderv101 method createContactList.

private ContactList createContactList(final List<SmlContact> contacts) {
    final ContactList xbContacts = ContactList.Factory.newInstance();
    contacts.forEach(smlContact -> {
        if (smlContact.isSetHref()) {
            ContactList.Member member = xbContacts.addNewMember();
            member.setHref(smlContact.getHref());
            if (smlContact.isSetTitle()) {
                member.setTitle(smlContact.getTitle());
            }
            if (smlContact.isSetRole()) {
                member.setRole(smlContact.getRole());
            }
        } else if (smlContact instanceof SmlPerson) {
            ContactList.Member member = xbContacts.addNewMember();
            member.addNewPerson().set(createPerson((SmlPerson) smlContact));
            if (smlContact.isSetRole()) {
                member.setRole(smlContact.getRole());
            }
        } else if (smlContact instanceof SmlResponsibleParty) {
            ContactList.Member member = xbContacts.addNewMember();
            member.addNewResponsibleParty().set(createResponsibleParty((SmlResponsibleParty) smlContact));
            if (smlContact.isSetRole()) {
                member.setRole(smlContact.getRole());
            }
        } else if (smlContact instanceof SmlContactList) {
            SmlContactList contactList = (SmlContactList) smlContact;
            ContactList innerContactList = createContactList(contactList.getMembers());
            int innerContactLength = innerContactList.getMemberArray().length;
            for (int i = 0; i < innerContactLength; i++) {
                xbContacts.addNewMember().set(innerContactList.getMemberArray(i));
            }
        }
    });
    return xbContacts;
}
Also used : SmlResponsibleParty(org.n52.shetland.ogc.sensorML.SmlResponsibleParty) SmlContactList(org.n52.shetland.ogc.sensorML.SmlContactList) ContactList(net.opengis.sensorML.x101.ContactListDocument.ContactList) SmlContactList(org.n52.shetland.ogc.sensorML.SmlContactList) Member(net.opengis.sensorML.x101.SensorMLDocument.SensorML.Member) SmlPerson(org.n52.shetland.ogc.sensorML.SmlPerson)

Example 4 with ContactList

use of net.opengis.sensorML.x101.ContactListDocument.ContactList in project arctic-sea by 52North.

the class SensorMLEncoderV101Test method should_encode_multiple_contacts_in_contactList.

@Test
public void should_encode_multiple_contacts_in_contactList() throws EncodingException {
    final SensorML sensorML = new SensorML();
    final System system = new System();
    sensorML.addMember(system);
    final SmlPerson contact1 = createPerson("1");
    final SmlPerson contact2 = createPerson("2");
    system.addContact(contact1);
    system.addContact(contact2);
    final SystemType xbSystem = encodeSystem(sensorML);
    assertThat(xbSystem.sizeOfContactArray(), is(1));
    assertThat(xbSystem.getContactArray(0).isSetContactList(), is(true));
    final ContactList xbContactList = xbSystem.getContactArray(0).getContactList();
    assertThat(xbContactList.sizeOfMemberArray(), is(2));
    final Member member = xbContactList.getMemberArray(0);
    final Member member2 = xbContactList.getMemberArray(1);
    assertThat(member.isSetPerson(), is(true));
    assertThat(member2.isSetPerson(), is(true));
    if (member.getPerson().getName().equals(contact1.getName())) {
        checkPerson(contact1, member.getPerson());
        checkPerson(contact2, member2.getPerson());
    } else {
        checkPerson(contact1, member2.getPerson());
        checkPerson(contact2, member.getPerson());
    }
}
Also used : SystemType(net.opengis.sensorML.x101.SystemType) ContactList(net.opengis.sensorML.x101.ContactListDocument.ContactList) SensorML(org.n52.shetland.ogc.sensorML.SensorML) Member(net.opengis.sensorML.x101.ContactListDocument.ContactList.Member) System(org.n52.shetland.ogc.sensorML.System) SmlPerson(org.n52.shetland.ogc.sensorML.SmlPerson) Test(org.junit.Test)

Example 5 with ContactList

use of net.opengis.sensorML.x101.ContactListDocument.ContactList in project arctic-sea by 52North.

the class SensorMLDecoderV101 method parseContactListMembers.

private SmlContact parseContactListMembers(final ContactList contactList) {
    SmlContactList smlContactList = new SmlContactList();
    if (contactList.getMemberArray() != null && contactList.getMemberArray().length > 0) {
        for (ContactList.Member member : contactList.getMemberArray()) {
            SmlContact thisSmlContact = null;
            if (member.getPerson() != null) {
                thisSmlContact = parsePerson(member.getPerson());
            } else if (member.getResponsibleParty() != null) {
                thisSmlContact = parseResponsibleParty(member.getResponsibleParty());
            } else if (member.isSetHref()) {
                thisSmlContact = new SmlReferencedContact();
                thisSmlContact.setHref(member.getHref());
                if (member.isSetTitle()) {
                    thisSmlContact.setTitle(member.getTitle());
                }
            }
            if (thisSmlContact != null) {
                if (member.getRole() != null) {
                    thisSmlContact.setRole(member.getRole());
                }
                smlContactList.addMember(thisSmlContact);
            }
        }
    }
    return smlContactList;
}
Also used : SmlReferencedContact(org.n52.shetland.ogc.sensorML.SmlReferencedContact) SmlContactList(org.n52.shetland.ogc.sensorML.SmlContactList) ContactList(net.opengis.sensorML.x101.ContactListDocument.ContactList) SmlContactList(org.n52.shetland.ogc.sensorML.SmlContactList) SmlContact(org.n52.shetland.ogc.sensorML.SmlContact)

Aggregations

ContactList (net.opengis.sensorML.x101.ContactListDocument.ContactList)7 SmlContactList (org.n52.shetland.ogc.sensorML.SmlContactList)5 SmlPerson (org.n52.shetland.ogc.sensorML.SmlPerson)5 SmlResponsibleParty (org.n52.shetland.ogc.sensorML.SmlResponsibleParty)4 Person (net.opengis.sensorML.x101.PersonDocument.Person)3 ResponsibleParty (net.opengis.sensorML.x101.ResponsiblePartyDocument.ResponsibleParty)3 SystemType (net.opengis.sensorML.x101.SystemType)3 Test (org.junit.Test)3 Contact (net.opengis.sensorML.x101.ContactDocument.Contact)2 Member (net.opengis.sensorML.x101.ContactListDocument.ContactList.Member)2 SensorMLDocument (net.opengis.sensorML.x101.SensorMLDocument)2 XmlObject (org.apache.xmlbeans.XmlObject)2 SensorML (org.n52.shetland.ogc.sensorML.SensorML)2 SmlContact (org.n52.shetland.ogc.sensorML.SmlContact)2 System (org.n52.shetland.ogc.sensorML.System)2 Capabilities (net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities)1 ContactInfo (net.opengis.sensorML.x101.ContactInfoDocument.ContactInfo)1 Member (net.opengis.sensorML.x101.SensorMLDocument.SensorML.Member)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 Time (org.n52.shetland.ogc.gml.time.Time)1