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);
}
}
}
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;
}
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;
}
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());
}
}
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;
}
Aggregations