use of net.opengis.sensorml.x20.DescribedObjectType.Characteristics in project arctic-sea by 52North.
the class SensorMLEncoderv20 method createCharacteristics.
/**
* Creates the characteristics section of the SensorML description.
*
* @param smlCharacteristics
* SOS characteristics list
*
* @return XML Characteristics array
*
* @throws EncodingException
* If an error occurs
*/
private Characteristics[] createCharacteristics(final List<SmlCharacteristics> smlCharacteristics) throws EncodingException {
final List<Characteristics> characteristicsList = new ArrayList<>(smlCharacteristics.size());
for (final SmlCharacteristics sosSMLCharacteristics : smlCharacteristics) {
Characteristics xbCharacteristics = Characteristics.Factory.newInstance(getXmlOptions());
if (sosSMLCharacteristics.isSetName()) {
xbCharacteristics.setName(sosSMLCharacteristics.getName());
} else {
xbCharacteristics.setName("characteristics_" + smlCharacteristics.lastIndexOf(sosSMLCharacteristics));
}
CharacteristicListType characteristicList = xbCharacteristics.addNewCharacteristicList();
if (sosSMLCharacteristics.isSetCharacteristics()) {
for (SmlCharacteristic characteristic : sosSMLCharacteristics.getCharacteristic()) {
Characteristic c = characteristicList.addNewCharacteristic();
c.setName(NcName.makeValid(characteristic.getName()));
if (characteristic.isSetAbstractDataComponent()) {
XmlObject encodeObjectToXml = encodeObjectToXml(SweConstants.NS_SWE_20, characteristic.getAbstractDataComponent());
XmlObject substituteElement = XmlHelper.substituteElement(c.addNewAbstractDataComponent(), encodeObjectToXml);
substituteElement.set(encodeObjectToXml);
} else if (characteristic.isSetHref()) {
c.setHref(characteristic.getHref());
if (characteristic.isSetTitle()) {
c.setTitle(characteristic.getTitle());
}
}
}
}
if (sosSMLCharacteristics.isSetAbstractDataComponents()) {
if (sosSMLCharacteristics.isSetAbstractDataComponents()) {
for (SweAbstractDataComponent component : sosSMLCharacteristics.getAbstractDataComponents()) {
XmlObject encodeObjectToXml = encodeObjectToXml(SweConstants.NS_SWE_20, component);
Characteristic c = characteristicList.addNewCharacteristic();
c.setName(NcName.makeValid(component.getName().getValue()));
XmlObject substituteElement = XmlHelper.substituteElement(c.addNewAbstractDataComponent(), encodeObjectToXml);
substituteElement.set(encodeObjectToXml);
}
}
}
characteristicsList.add(xbCharacteristics);
}
return characteristicsList.toArray(new Characteristics[characteristicsList.size()]);
}
use of net.opengis.sensorml.x20.DescribedObjectType.Characteristics in project arctic-sea by 52North.
the class SensorMLDecoderV20 method parseCharacteristics.
/**
* Parses the characteristics
*
* @param clpts
* XML characteristics
* @return SOS characteristics
*
* @throws DecodingException
* * if an error occurs
*/
private List<SmlCharacteristics> parseCharacteristics(final CharacteristicListPropertyType[] clpts) throws DecodingException {
final List<SmlCharacteristics> sosCharacteristicsList = new ArrayList<>(clpts.length);
for (final CharacteristicListPropertyType clpt : clpts) {
final SmlCharacteristics sosCharacteristics = new SmlCharacteristics();
if (clpt.isSetCharacteristicList()) {
CharacteristicListType clt = clpt.getCharacteristicList();
if (CollectionHelper.isNotNullOrEmpty(clt.getCharacteristicArray())) {
for (Characteristic c : clt.getCharacteristicArray()) {
final SmlCharacteristic characteristic = new SmlCharacteristic(c.getName());
if (c.isSetAbstractDataComponent()) {
final Object o = decodeXmlElement(c.getAbstractDataComponent());
if (o instanceof SweAbstractDataComponent) {
characteristic.setAbstractDataComponent((SweAbstractDataComponent) o);
} else {
throw new DecodingException(XmlHelper.getLocalName(clpt), "Error while parsing the characteristics of the SensorML " + "(the characteristics' data record is not of " + "type DataRecordPropertyType)!");
}
} else if (c.isSetHref()) {
characteristic.setHref(c.getHref());
if (c.isSetTitle()) {
characteristic.setTitle(c.getTitle());
}
}
sosCharacteristics.addCharacteristic(characteristic);
}
}
}
sosCharacteristicsList.add(sosCharacteristics);
}
return sosCharacteristicsList;
}
use of net.opengis.sensorml.x20.DescribedObjectType.Characteristics in project arctic-sea by 52North.
the class SensorMLEncoderv20 method addDescribedObjectValues.
private void addDescribedObjectValues(DescribedObjectType dot, DescribedObject describedObject) throws EncodingException {
if (!describedObject.isSetGmlID()) {
describedObject.setGmlId("do_" + JavaHelper.generateID(describedObject.toString()));
}
if (dot.getId() == null || dot.getId().isEmpty()) {
dot.setId(describedObject.getGmlId());
}
// update/set gml:identifier
if (describedObject.isSetIdentifier()) {
describedObject.getIdentifierCodeWithAuthority().setCodeSpace(OGCConstants.UNIQUE_ID);
XmlObject encodeObjectToXml = encodeObjectToXmlGml32(describedObject.getIdentifierCodeWithAuthority());
if (encodeObjectToXml != null) {
if (dot.isSetIdentifier()) {
dot.getIdentifier().set(encodeObjectToXml);
} else {
dot.addNewIdentifier().set(encodeObjectToXml);
}
}
}
// set capabilities
if (describedObject.isSetCapabilities()) {
final Capabilities[] existing = dot.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 : describedObject.getCapabilities()) {
// Update Discovery Profile
if (!SensorMLConstants.ELEMENT_NAME_OBSERVED_BBOX.equals(sosCapability.getName())) {
final Capabilities c = createCapability(sosCapability);
// replace existing capability with the same name
if (c != null) {
if (names.contains(c.getName())) {
removeCapability(dot, c);
}
dot.addNewCapabilities().set(c);
}
}
}
}
// set description
if (describedObject.isSetDescription() && !dot.isSetDescription()) {
dot.addNewDescription().setStringValue(describedObject.getDescription());
}
// set names
if (describedObject.isSetName() && CollectionHelper.isNullOrEmpty(dot.getNameArray())) {
// TODO check if override existing names
addNamesToAbstractProcess(dot, describedObject.getNames());
}
// set keywords
if (describedObject.isSetKeywords()) {
if (CollectionHelper.isNullOrEmpty(dot.getKeywordsArray())) {
final List<String> keywords = describedObject.getKeywords();
// final int length = dot.getKeywordsArray().length;
// for (int i = 0; i < length; ++i) {
// dot.removeKeywords(i);
// }
dot.addNewKeywords().addNewKeywordList().setKeywordArray(keywords.toArray(new String[keywords.size()]));
// TODO else
}
}
// set identification
if (describedObject.isSetIdentifications()) {
// TODO check for merging identifications if exists
dot.setIdentificationArray(createIdentification(describedObject.getIdentifications()));
}
// set classification
if (describedObject.isSetClassifications()) {
dot.setClassificationArray(createClassification(describedObject.getClassifications()));
}
// set validTime
if (describedObject.isSetValidTime() && CollectionHelper.isNullOrEmpty(dot.getValidTimeArray())) {
for (Time time : describedObject.getValidTime()) {
final XmlObject xbtime = encodeObjectToXmlGml32(time);
if (time instanceof TimeInstant) {
dot.addNewValidTime().addNewTimeInstant().set(xbtime);
} else if (time instanceof TimePeriod) {
dot.addNewValidTime().addNewTimePeriod().set(xbtime);
}
}
// } else {
// TODO remove or
// remove existing validTime element
// final XmlCursor newCursor = dot.getValidTime().newCursor();
// newCursor.removeXml();
// newCursor.dispose();
}
// set characteristics
if (describedObject.isSetCharacteristics()) {
dot.setCharacteristicsArray(createCharacteristics(describedObject.getCharacteristics()));
}
// CollectionHelper.isNotNullOrEmpty(dot.getContactsArray())) {
if (describedObject.isSetContact()) {
if (CollectionHelper.isNullOrEmpty(dot.getContactsArray())) {
ContactListType cl = ContactListType.Factory.newInstance();
for (SmlContact contact : describedObject.getContact()) {
if (contact instanceof SmlResponsibleParty) {
if (contact.isSetHref()) {
XmlObject xml = encodeObjectToXml(GmdConstants.NS_GMD, (SmlResponsibleParty) contact, EncodingContext.of(XmlBeansEncodingFlags.PROPERTY_TYPE));
cl.addNewContact().set(xml);
} else {
XmlObject encodeObjectToXml = encodeObjectToXml(GmdConstants.NS_GMD, contact);
if (encodeObjectToXml != null) {
cl.addNewContact().addNewCIResponsibleParty().set(encodeObjectToXml);
}
}
}
}
if (CollectionHelper.isNotNullOrEmpty(cl.getContactArray())) {
dot.addNewContacts().setContactList(cl);
}
}
}
// set documentation
if (describedObject.isSetDocumentation()) {
if (CollectionHelper.isNullOrEmpty(dot.getDocumentationArray())) {
dot.setDocumentationArray(createDocumentationArray(describedObject.getDocumentation()));
}
}
// set history
}
Aggregations