Repository navigation
Add identification configuration to sensors/processes #359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1240d12
c3abcba
bcd05b3
fed5d28
100f2d1
00a35ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /***************************** BEGIN LICENSE BLOCK *************************** | ||
|
|
||
| The contents of this file are subject to the Mozilla Public License, v. 2.0. | ||
| If a copy of the MPL was not distributed with this file, You can obtain one | ||
| at http://mozilla.org/MPL/2.0/. | ||
|
|
||
| Software distributed under the License is distributed on an "AS IS" basis, | ||
| WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
| for the specific language governing rights and limitations under the License. | ||
|
|
||
| Copyright (C) 2026 GeoRobotix Innovative Research, LLC. All Rights Reserved. | ||
|
|
||
| ******************************* END LICENSE BLOCK ***************************/ | ||
|
|
||
| package org.sensorhub.api.sensor; | ||
|
|
||
| import org.sensorhub.api.config.DisplayInfo; | ||
| import org.vast.util.ResponsibleParty; | ||
|
|
||
| import java.util.Collection; | ||
|
|
||
| public class IdentificationInfo { | ||
|
|
||
| @DisplayInfo.Required | ||
| @DisplayInfo(label = "System UID", desc = "Overrides this resource's system UID") | ||
| public String systemUID; | ||
|
|
||
| @DisplayInfo(label = "System Kind UID", desc = "Optional field overrides this resource's system kind/type UID") | ||
| public String systemKindUID; | ||
|
|
||
| @DisplayInfo(label = "Responsible Parties", desc = "Contact/business information of system/device operators and technical support") | ||
| public Collection<ResponsibleParty> responsibleParties; | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /***************************** BEGIN LICENSE BLOCK *************************** | ||
|
|
||
| The contents of this file are subject to the Mozilla Public License, v. 2.0. | ||
| If a copy of the MPL was not distributed with this file, You can obtain one | ||
| at http://mozilla.org/MPL/2.0/. | ||
|
|
||
| Software distributed under the License is distributed on an "AS IS" basis, | ||
| WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
| for the specific language governing rights and limitations under the License. | ||
|
|
||
| Copyright (C) 2026 GeoRobotix Innovative Research, LLC. All Rights Reserved. | ||
|
|
||
| ******************************* END LICENSE BLOCK ***************************/ | ||
|
|
||
| package org.sensorhub.utils; | ||
|
|
||
| import net.opengis.gml.v32.impl.ReferenceImpl; | ||
| import net.opengis.sensorml.v20.AbstractProcess; | ||
| import net.opengis.sensorml.v20.impl.ContactListImpl; | ||
| import org.isotc211.v2005.gco.impl.CodeListValueImpl; | ||
| import org.isotc211.v2005.gmd.impl.CIAddressImpl; | ||
| import org.isotc211.v2005.gmd.impl.CIContactImpl; | ||
| import org.isotc211.v2005.gmd.impl.CIOnlineResourceImpl; | ||
| import org.isotc211.v2005.gmd.impl.CIResponsiblePartyImpl; | ||
| import org.isotc211.v2005.gmd.impl.CITelephoneImpl; | ||
| import org.sensorhub.api.sensor.IdentificationInfo; | ||
| import org.sensorhub.api.utils.OshAsserts; | ||
|
|
||
|
|
||
| /** Applies configured identification overrides to SensorML descriptions. */ | ||
| public final class IdentificationInfoUtils | ||
| { | ||
| private IdentificationInfoUtils() | ||
| { | ||
| } | ||
|
|
||
|
|
||
| public static void apply(IdentificationInfo info, AbstractProcess description) | ||
| { | ||
| if (info == null) | ||
| return; | ||
|
|
||
| OshAsserts.checkValidUID(info.systemUID); | ||
| description.setUniqueIdentifier(info.systemUID); | ||
| if (info.systemKindUID != null && !info.systemKindUID.isBlank()) | ||
| { | ||
| OshAsserts.checkValidUID(info.systemKindUID); | ||
| description.setTypeOf(new ReferenceImpl(info.systemKindUID)); | ||
| } | ||
|
|
||
| if (info.responsibleParties == null || info.responsibleParties.isEmpty()) | ||
| return; | ||
|
|
||
| var contacts = new ContactListImpl(); | ||
| for (var party : info.responsibleParties) | ||
| { | ||
| var contact = new CIResponsiblePartyImpl(); | ||
| contact.setIndividualName(party.getIndividualName()); | ||
| contact.setOrganisationName(party.getOrganizationName()); | ||
| contact.setPositionName(party.getPositionName()); | ||
| if (party.getRole() != null && !party.getRole().isBlank()) | ||
| { | ||
| var role = new CodeListValueImpl(party.getRole()); | ||
| var codeList = party.getRoleCodeList(); | ||
| role.setCodeList(codeList == null || codeList.isBlank() | ||
| ? "http://www.isotc211.org/2005/resources/codeList.xml#CI_RoleCode" | ||
| : codeList); | ||
| role.setCodeListValue(party.getRole()); | ||
| contact.setRole(role); | ||
| } | ||
|
|
||
| if (party.hasContactInfo()) | ||
| { | ||
| var details = new CIContactImpl(); | ||
| contact.setContactInfo(details); | ||
| details.setHoursOfService(party.getHoursOfService()); | ||
| details.setContactInstructions(party.getContactInstructions()); | ||
| if (party.hasAddress()) | ||
| { | ||
| var address = new CIAddressImpl(); | ||
| address.getDeliveryPointList().addAll(party.getDeliveryPoints()); | ||
| address.setCity(party.getCity()); | ||
| address.setAdministrativeArea(party.getAdministrativeArea()); | ||
| address.setPostalCode(party.getPostalCode()); | ||
| address.setCountry(party.getCountry()); | ||
| address.getElectronicMailAddressList().addAll(party.getEmails()); | ||
| details.setAddress(address); | ||
| } | ||
| if (!party.getVoiceNumbers().isEmpty() || !party.getFaxNumbers().isEmpty()) | ||
| { | ||
| var phone = new CITelephoneImpl(); | ||
| phone.getVoiceList().addAll(party.getVoiceNumbers()); | ||
| phone.getFacsimileList().addAll(party.getFaxNumbers()); | ||
| details.setPhone(phone); | ||
| } | ||
| if (party.getWebsite() != null) | ||
| { | ||
| var website = new CIOnlineResourceImpl(); | ||
| website.setLinkage(party.getWebsite()); | ||
| details.setOnlineResource(website); | ||
| } | ||
| } | ||
| contacts.addContact(contact); | ||
| } | ||
| description.getContactsList().clear(); | ||
| description.addContacts(contacts); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /***************************** BEGIN LICENSE BLOCK *************************** | ||
|
|
||
| The contents of this file are subject to the Mozilla Public License, v. 2.0. | ||
| If a copy of the MPL was not distributed with this file, You can obtain one | ||
| at http://mozilla.org/MPL/2.0/. | ||
|
|
||
| Software distributed under the License is distributed on an "AS IS" basis, | ||
| WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
| for the specific language governing rights and limitations under the License. | ||
|
|
||
| Copyright (C) 2026 GeoRobotix Innovative Research, LLC. All Rights Reserved. | ||
|
|
||
| ******************************* END LICENSE BLOCK ***************************/ | ||
|
|
||
| package org.sensorhub.impl.sensor; | ||
|
|
||
| import static org.junit.Assert.*; | ||
| import java.util.List; | ||
| import org.junit.Test; | ||
| import org.sensorhub.api.sensor.IdentificationInfo; | ||
| import org.sensorhub.api.sensor.SensorConfig; | ||
| import org.vast.util.ResponsibleParty; | ||
|
|
||
| public class TestIdentificationInfo | ||
| { | ||
| @Test | ||
| public void overridesSurviveDescriptionRegeneration() throws Exception | ||
| { | ||
| var config = new SensorConfig(); | ||
| config.identificationInfo = new IdentificationInfo(); | ||
| config.identificationInfo.systemUID = "urn:test:configured"; | ||
| config.identificationInfo.systemKindUID = "urn:test:kind"; | ||
| var party = new ResponsibleParty(); | ||
| party.setOrganizationName("Operator"); | ||
| party.getEmails().addAll(List.of("first@example.org", "second@example.org")); | ||
| party.getVoiceNumbers().addAll(List.of("123", "456")); | ||
| party.setWebsite("https://example.org"); | ||
| config.identificationInfo.responsibleParties = List.of(party); | ||
|
|
||
| var sensor = new FakeSensor(); | ||
| sensor.init(config); | ||
| assertEquals(config.identificationInfo.systemUID, sensor.getUniqueIdentifier()); | ||
| assertFalse(sensor.randomUniqueID); | ||
| for (int i = 0; i < 2; i++) | ||
| { | ||
| var description = sensor.getCurrentDescription(); | ||
| assertEquals(sensor.getUniqueIdentifier(), description.getUniqueIdentifier()); | ||
| assertEquals(config.identificationInfo.systemKindUID, description.getTypeOf().getHref()); | ||
| assertEquals(1, description.getContactsList().size()); | ||
| var contact = description.getContactsList().get(0).getContactList().get(0); | ||
| assertEquals("Operator", contact.getOrganisationName()); | ||
| assertEquals(party.getEmails(), contact.getContactInfo().getAddress().getElectronicMailAddressList()); | ||
| assertEquals(party.getVoiceNumbers(), contact.getContactInfo().getPhone().getVoiceList()); | ||
| assertEquals(party.getWebsite(), contact.getContactInfo().getOnlineResource().getLinkage()); | ||
| sensor.updateSensorDescription(); | ||
| } | ||
| } | ||
| @Test | ||
| public void rolesSerializeWithOptionalCodeList() throws Exception | ||
| { | ||
| for (String codeList : new String[] {null, "", "urn:test:roles"}) | ||
| { | ||
| var info = new IdentificationInfo(); | ||
| info.systemUID = "urn:test:configured"; | ||
| var party = new ResponsibleParty(); | ||
| party.setRole("operator"); | ||
| party.setRoleCodeList(codeList); | ||
| info.responsibleParties = List.of(party); | ||
| var description = new org.vast.sensorML.PhysicalSystemImpl(); | ||
| org.sensorhub.utils.IdentificationInfoUtils.apply(info, description); | ||
|
|
||
| var output = new java.io.StringWriter(); | ||
| var writer = new com.ctc.wstx.stax.WstxOutputFactory().createXMLStreamWriter(output); | ||
| var bindings = new org.vast.sensorML.SMLStaxBindings(); | ||
| bindings.setNamespacePrefixes(writer); | ||
| bindings.declareNamespacesOnRootElement(); | ||
| bindings.writeDescribedObject(writer, description); | ||
| writer.close(); | ||
| assertTrue(output.toString().contains("codeListValue=\"operator\"")); | ||
| assertTrue(output.toString().contains(codeList == null || codeList.isBlank() | ||
| ? "codeList.xml#CI_RoleCode" : codeList)); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,6 +162,31 @@ protected void addMethodProperties(String prefix, Object bean) | |
|
|
||
| String fullName = prefix + prop.getName(); | ||
|
|
||
| // Getter-backed collections need the same list editor as public fields. | ||
| // In particular, live collections often have no setter. | ||
| Field field = fieldMap.get(prop.getName()); | ||
| if (Collection.class.isAssignableFrom(prop.getPropertyType()) && prop.getReadMethod() != null | ||
| && field.getGenericType() instanceof ParameterizedType) | ||
| { | ||
| var listType = (ParameterizedType)field.getGenericType(); | ||
| if (listType.getActualTypeArguments()[0] instanceof Class<?>) | ||
| { | ||
| try | ||
| { | ||
| field.setAccessible(true); | ||
| var list = (Collection<?>)prop.getReadMethod().invoke(bean); | ||
| var elementType = (Class<?>)listType.getActualTypeArguments()[0]; | ||
| var container = new MyBeanItemContainer<Object>(list, elementType, fullName + PROP_SEPARATOR); | ||
| addItemProperty(fullName, new ContainerProperty(bean, field, container)); | ||
| continue; | ||
| } | ||
| catch (ReflectiveOperationException e) | ||
| { | ||
| throw new IllegalStateException("Cannot access property " + fullName, e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we avoid this by making it an ArrayList in the config rather than a Collection?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue here is that the collection/list (these are already
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The unit test in |
||
| //System.out.println(prop.getName() + ", get=" + prop.getReadMethod() + ", set=" + prop.getWriteMethod() + ", hidden=" + prop.isHidden()); | ||
| addItemProperty(fullName, new MethodProperty(prop.getPropertyType(), bean, prop.getReadMethod(), prop.getWriteMethod())); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.