use of net.opengis.sensorML.x101.ResponsiblePartyDocument.ResponsibleParty 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.ResponsiblePartyDocument.ResponsibleParty in project arctic-sea by 52North.
the class SensorMLEncoderV101Test method checkResponsibleParty.
private void checkResponsibleParty(final SmlResponsibleParty responsibleParty, final ResponsibleParty xbResponsibleParty) {
assertThat(xbResponsibleParty.getIndividualName(), is(responsibleParty.getIndividualName()));
assertThat(xbResponsibleParty.getOrganizationName(), is(responsibleParty.getOrganizationName()));
assertThat(xbResponsibleParty.getPositionName(), is(responsibleParty.getPositionName()));
final ContactInfo xbContactInfo = xbResponsibleParty.getContactInfo();
assertThat(xbContactInfo.getContactInstructions(), is(responsibleParty.getContactInstructions()));
assertThat(xbContactInfo.getHoursOfService(), is(responsibleParty.getHoursOfService()));
assertThat(xbContactInfo.getOnlineResourceArray(0).getHref(), is(responsibleParty.getOnlineResources().get(0)));
final Phone xbPhone = xbContactInfo.getPhone();
assertThat(xbPhone.getVoiceArray(0), is(responsibleParty.getPhoneVoice().get(0)));
assertThat(xbPhone.getFacsimileArray(0), is(responsibleParty.getPhoneFax().get(0)));
final Address xbAddress = xbContactInfo.getAddress();
assertThat(xbAddress.getAdministrativeArea(), is(responsibleParty.getAdministrativeArea()));
assertThat(xbAddress.getCity(), is(responsibleParty.getCity()));
assertThat(xbAddress.getCountry(), is(responsibleParty.getCountry()));
assertThat(xbAddress.getElectronicMailAddress(), is(responsibleParty.getEmail()));
assertThat(xbAddress.getDeliveryPointArray(0), is(responsibleParty.getDeliveryPoint().get(0)));
assertThat(xbAddress.getPostalCode(), is(responsibleParty.getPostalCode()));
}
use of net.opengis.sensorML.x101.ResponsiblePartyDocument.ResponsibleParty in project arctic-sea by 52North.
the class SensorMLEncoderV101Test method should_encode_single_contact_responsibleParty.
@Test
public void should_encode_single_contact_responsibleParty() throws EncodingException {
final SensorML sensorML = new SensorML();
final System system = new System();
sensorML.addMember(system);
final SmlResponsibleParty responsibleParty = createResponsibleParty("");
system.addContact(responsibleParty);
final SystemType xbSystem = encodeSystem(sensorML);
assertThat(xbSystem.sizeOfContactArray(), is(1));
assertThat(xbSystem.getContactArray(0).getContactList().getMemberArray(0).isSetResponsibleParty(), is(true));
final ResponsibleParty xbResponsibleParty = xbSystem.getContactArray(0).getContactList().getMemberArray(0).getResponsibleParty();
checkResponsibleParty(responsibleParty, xbResponsibleParty);
}
use of net.opengis.sensorML.x101.ResponsiblePartyDocument.ResponsibleParty in project arctic-sea by 52North.
the class SensorMLEncoderV101Test method should_merge_and_encode_multiple_contacts.
@Test
public void should_merge_and_encode_multiple_contacts() throws EncodingException {
final SensorML sensorML = new SensorML();
final System system = new System();
sensorML.addMember(system);
final SmlPerson p1 = createPerson("1");
final SmlResponsibleParty rp1 = createResponsibleParty("1");
system.addContact(p1);
system.addContact(rp1);
final SensorMLDocument xbSensorML = SensorMLDocument.Factory.newInstance();
final SystemType xbSystem = SystemType.Factory.newInstance();
final ContactList xbContactList = xbSystem.addNewContact().addNewContactList();
final Person xbP1 = xbContactList.addNewMember().addNewPerson();
setPersonValues(p1, xbP1);
final ResponsibleParty xbRP1 = xbContactList.addNewMember().addNewResponsibleParty();
setResponsiblePartyValues(rp1, xbRP1);
final XmlObject xbProcess = xbSensorML.addNewSensorML().addNewMember().addNewProcess().set(xbSystem);
XmlHelper.substituteElement(xbProcess, xbSystem);
xbSensorML.getSensorML().setVersion("1.0.1");
sensorML.setXml(xbSensorML.xmlText());
final SystemType xbEncodedSystem = encodeSystem(sensorML);
assertThat(xbEncodedSystem.sizeOfContactArray(), is(1));
assertThat(xbEncodedSystem.getContactArray(0).isSetContactList(), is(true));
assertThat(xbEncodedSystem.getContactArray(0).getContactList().sizeOfMemberArray(), is(2));
boolean personChecked = false, responsiblePartyChecked = false;
for (final Member member : xbEncodedSystem.getContactArray(0).getContactList().getMemberArray()) {
if (member.isSetPerson()) {
checkPerson(p1, member.getPerson());
personChecked = true;
} else if (member.isSetResponsibleParty()) {
checkResponsibleParty(rp1, member.getResponsibleParty());
responsiblePartyChecked = true;
}
}
if (!personChecked) {
fail("sml:Person not found in contact/contactList");
}
if (!responsiblePartyChecked) {
fail("sml:ResponsibleParty not found in contact/ContactList");
}
}
use of net.opengis.sensorML.x101.ResponsiblePartyDocument.ResponsibleParty in project arctic-sea by 52North.
the class SensorMLEncoderV101Test method should_merge_and_encode_two_same_contact_responsibleParty_only_once.
@Test
public void should_merge_and_encode_two_same_contact_responsibleParty_only_once() throws EncodingException {
final SensorML sensorML = new SensorML();
final System system = new System();
sensorML.addMember(system);
final SmlResponsibleParty p1 = createResponsibleParty("1");
system.addContact(p1);
final SensorMLDocument xbSensorML = SensorMLDocument.Factory.newInstance();
final SystemType xbSystem = SystemType.Factory.newInstance();
final ResponsibleParty xbP1 = xbSystem.addNewContact().addNewResponsibleParty();
setResponsiblePartyValues(p1, xbP1);
final XmlObject xbProcess = xbSensorML.addNewSensorML().addNewMember().addNewProcess().set(xbSystem);
XmlHelper.substituteElement(xbProcess, xbSystem);
xbSensorML.getSensorML().setVersion("1.0.1");
sensorML.setXml(xbSensorML.xmlText());
final SystemType xbEncodedSystem = encodeSystem(sensorML);
assertThat(xbEncodedSystem.sizeOfContactArray(), is(1));
assertThat(xbEncodedSystem.getContactArray(0).isSetResponsibleParty(), is(true));
checkResponsibleParty(p1, xbEncodedSystem.getContactArray(0).getResponsibleParty());
}
Aggregations