use of net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities in project arctic-sea by 52North.
the class SensorMLDecoderV101 method parseCapabilities.
/**
* Parses the capabilities, processing and removing special insertion metadata
*
* @param abstractProcess The AbstractProcess to which capabilities and insertion metadata are added
* @param capabilitiesArray XML capabilities
*
* @throws DecodingException if an error occurs
*/
private void parseCapabilities(final AbstractProcess abstractProcess, final Capabilities[] capabilitiesArray) throws DecodingException {
for (final Capabilities xbcaps : capabilitiesArray) {
final SmlCapabilities caps = new SmlCapabilities();
if (xbcaps.isSetName()) {
caps.setName(xbcaps.getName());
}
if (xbcaps.isSetAbstractDataRecord()) {
final Object o = decodeXmlElement(xbcaps.getAbstractDataRecord());
if (o instanceof DataRecord) {
final DataRecord record = (DataRecord) o;
caps.setDataRecord(record).setName(xbcaps.getName());
} else {
throw new DecodingException(XmlHelper.getLocalName(xbcaps), "Error while parsing the capabilities of the SensorML (the " + "capabilities data record is not of type DataRecordPropertyType)!");
}
} else if (xbcaps.isSetHref()) {
caps.setHref(xbcaps.getHref());
if (xbcaps.isSetTitle()) {
caps.setTitle(xbcaps.getTitle());
}
}
if (caps.isSetName()) {
abstractProcess.addCapabilities(caps);
}
}
}
use of net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities 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.CapabilitiesDocument.Capabilities in project arctic-sea by 52North.
the class SensorMLEncoderv101 method createCapability.
private Capabilities createCapability(final SmlCapabilities capabilities) throws EncodingException {
final Capabilities xbCapabilities = Capabilities.Factory.newInstance(getXmlOptions());
if (capabilities.isSetName()) {
xbCapabilities.setName(capabilities.getName());
}
if (capabilities.isSetAbstractDataRecord() && capabilities.getDataRecord().isSetFields()) {
final XmlObject encodedDataRecord = encodeObjectToXml(SweConstants.NS_SWE_101, capabilities.getDataRecord());
final XmlObject substituteElement = XmlHelper.substituteElement(xbCapabilities.addNewAbstractDataRecord(), encodedDataRecord);
substituteElement.set(encodedDataRecord);
} else if (capabilities.isSetHref()) {
xbCapabilities.setHref(capabilities.getHref());
if (capabilities.isSetTitle()) {
xbCapabilities.setTitle(capabilities.getTitle());
}
}
return xbCapabilities;
}
use of net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities in project arctic-sea by 52North.
the class SosV1GetCapabilitiesResponseEncoder method create.
@Override
protected XmlObject create(GetCapabilitiesResponse response) throws EncodingException {
CapabilitiesDocument xbCapsDoc = CapabilitiesDocument.Factory.newInstance(getXmlOptions());
// cursor for getting prefixes
Capabilities xbCaps = xbCapsDoc.addNewCapabilities();
// set version.
xbCaps.setVersion(response.getVersion());
SosCapabilities sosCapabilities = (SosCapabilities) response.getCapabilities();
if (sosCapabilities.getServiceIdentification().isPresent()) {
xbCaps.addNewServiceIdentification().set(encodeObjectToXml(OWSConstants.NS_OWS, sosCapabilities.getServiceIdentification().get()));
}
if (sosCapabilities.getServiceProvider().isPresent()) {
xbCaps.addNewServiceProvider().set(encodeObjectToXml(OWSConstants.NS_OWS, sosCapabilities.getServiceProvider().get()));
}
if (sosCapabilities.getOperationsMetadata().isPresent()) {
xbCaps.addNewOperationsMetadata().set(encodeObjectToXml(OWSConstants.NS_OWS, sosCapabilities.getOperationsMetadata().get()));
}
if (sosCapabilities.getFilterCapabilities().isPresent()) {
setFilterCapabilities(xbCaps.addNewFilterCapabilities(), sosCapabilities.getFilterCapabilities().get());
}
if (sosCapabilities.getContents().isPresent()) {
setContents(xbCaps.addNewContents(), sosCapabilities.getContents().get(), response.getVersion());
}
N52XmlHelper.setSchemaLocationsToDocument(xbCapsDoc, Sets.newHashSet(N52XmlHelper.getSchemaLocationForSOS100()));
return xbCapsDoc;
}
use of net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities in project arctic-sea by 52North.
the class SensorMLDecoderV101Test method should_decode_features_of_interest_from_sml.
@Test
public void should_decode_features_of_interest_from_sml() throws DecodingException {
SensorMLDocument xbSmlDoc = getSensorMLDoc();
SystemType xbSystem = (SystemType) xbSmlDoc.getSensorML().addNewMember().addNewProcess().substitute(SensorMLConstants.SYSTEM_QNAME, SystemType.type);
Capabilities xbCapabilities = xbSystem.addNewCapabilities();
xbCapabilities.setName(SensorMLConstants.ELEMENT_NAME_FEATURES_OF_INTEREST);
SimpleDataRecordType xbSimpleDataRecord = (SimpleDataRecordType) xbCapabilities.addNewAbstractDataRecord().substitute(SweConstants.QN_SIMPLEDATARECORD_SWE_101, SimpleDataRecordType.type);
addCapabilitiesInsertionMetadata(xbSimpleDataRecord, TEST_ID_1, TEST_NAME_1);
addCapabilitiesInsertionMetadata(xbSimpleDataRecord, TEST_ID_2, TEST_NAME_2);
AbstractProcess absProcess = decodeAbstractProcess(xbSmlDoc);
// assertThat(absProcess.getFeaturesOfInterest().size(), is(2));
assertThat(absProcess.getCapabilities().size(), is(1));
// List<String> featuresOfInterest = new ArrayList<String>(absProcess.getFeaturesOfInterest());
// Collections.sort(featuresOfInterest);
// assertThat(featuresOfInterest.get(0), is(TEST_ID_1));
// assertThat(featuresOfInterest.get(1), is(TEST_ID_2));
}
Aggregations