use of net.opengis.sensorML.x101.SensorMLDocument.SensorML.Member 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;
}
use of net.opengis.sensorML.x101.SensorMLDocument.SensorML.Member 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;
}
use of net.opengis.sensorML.x101.SensorMLDocument.SensorML.Member in project arctic-sea by 52North.
the class SensorMLEncoderv101 method createDocumentationList.
/**
* Create a XML DocuemntList from SOS documentList
*
* @param sosDocumentationList
* SOS documentList
*
* @return XML DocumentList element
*/
private DocumentList createDocumentationList(final SmlDocumentationList sosDocumentationList) {
final DocumentList documentList = DocumentList.Factory.newInstance();
if (sosDocumentationList.isSetDescription()) {
documentList.addNewDescription().setStringValue(sosDocumentationList.getDescription());
}
if (sosDocumentationList.isSetMembers()) {
sosDocumentationList.getMember().forEach(sosMember -> {
net.opengis.sensorML.x101.DocumentListDocument.DocumentList.Member member = documentList.addNewMember();
member.setName(sosMember.getName());
member.setDocument(createDocument(sosMember.getDocumentation()));
});
}
return documentList;
}
use of net.opengis.sensorML.x101.SensorMLDocument.SensorML.Member 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());
}
}
use of net.opengis.sensorML.x101.SensorMLDocument.SensorML.Member in project arctic-sea by 52North.
the class SensorMLDecoderV101 method addSensorMLWrapperForXmlDescription.
private String addSensorMLWrapperForXmlDescription(final AbstractProcessType xbProcessType) {
final SensorMLDocument xbSensorMLDoc = SensorMLDocument.Factory.newInstance(getXmlOptions());
final net.opengis.sensorML.x101.SensorMLDocument.SensorML xbSensorML = xbSensorMLDoc.addNewSensorML();
xbSensorML.setVersion(SensorMLConstants.VERSION_V101);
final Member member = xbSensorML.addNewMember();
final AbstractProcessType xbAbstractProcessType = (AbstractProcessType) member.addNewProcess().substitute(getQnameForType(xbProcessType.schemaType()), xbProcessType.schemaType());
xbAbstractProcessType.set(xbProcessType);
return xbSensorMLDoc.xmlText(getXmlOptions());
}
Aggregations