Search in sources :

Example 6 with SensorML

use of org.n52.shetland.ogc.sensorML.SensorML in project arctic-sea by 52North.

the class SensorMLEncoderv20 method createComponents.

/**
 * Creates the components section of the SensorML description.
 *
 * @param sosComponents
 *            SOS SWE representation.
 *
 * @return encoded sml:components
 *
 * @throws EncodingException
 *             if the process encoding fails
 */
private ComponentListPropertyType createComponents(final List<SmlComponent> sosComponents) throws EncodingException {
    ComponentListPropertyType clpt = ComponentListPropertyType.Factory.newInstance(getXmlOptions());
    final ComponentListType clt = clpt.addNewComponentList();
    for (final SmlComponent sosSMLComponent : sosComponents) {
        final Component component = clt.addNewComponent();
        if (sosSMLComponent.isSetName()) {
            component.setName(sosSMLComponent.getName());
        }
        if (sosSMLComponent.isSetHref()) {
            component.setHref(sosSMLComponent.getHref());
            if (sosSMLComponent.isSetTitle()) {
                component.setTitle(sosSMLComponent.getTitle());
            }
        } else if (sosSMLComponent.isSetProcess()) {
            XmlObject xmlObject = encode(sosSMLComponent.getProcess(), EncodingContext.of(XmlBeansEncodingFlags.TYPE));
            // }
            if (xmlObject != null) {
                // AbstractProcessType xbProcess = null;
                // if (xmlObject instanceof AbstractProcessType) {
                // xbProcess = (AbstractProcessType) xmlObject;
                // } else {
                // throw new NoApplicableCodeException()
                // .withMessage("The sensor type is not supported by this
                // SOS");
                // }
                // TODO add feature/parentProcs/childProcs to component - is
                // this already done?
                // XmlObject substituteElement =
                // XmlHelper.substituteElement(component.addNewAbstractProcess(),
                // xmlObject);
                // substituteElement.set(xmlObject);
                substitute(component.addNewAbstractProcess(), xmlObject);
            }
        }
    }
    return clpt;
}
Also used : ComponentListPropertyType(net.opengis.sensorml.x20.ComponentListPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) PhysicalComponent(org.n52.shetland.ogc.sensorML.v20.PhysicalComponent) SmlComponent(org.n52.shetland.ogc.sensorML.elements.SmlComponent) Component(net.opengis.sensorml.x20.ComponentListType.Component) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) ComponentListType(net.opengis.sensorml.x20.ComponentListType) SmlComponent(org.n52.shetland.ogc.sensorML.elements.SmlComponent)

Example 7 with SensorML

use of org.n52.shetland.ogc.sensorML.SensorML 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()]);
}
Also used : SmlCharacteristics(org.n52.shetland.ogc.sensorML.elements.SmlCharacteristics) Characteristics(net.opengis.sensorml.x20.DescribedObjectType.Characteristics) SmlCharacteristics(org.n52.shetland.ogc.sensorML.elements.SmlCharacteristics) SmlCharacteristic(org.n52.shetland.ogc.sensorML.elements.SmlCharacteristic) SmlCharacteristic(org.n52.shetland.ogc.sensorML.elements.SmlCharacteristic) Characteristic(net.opengis.sensorml.x20.CharacteristicListType.Characteristic) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) ArrayList(java.util.ArrayList) CharacteristicListType(net.opengis.sensorml.x20.CharacteristicListType) XmlObject(org.apache.xmlbeans.XmlObject)

Example 8 with SensorML

use of org.n52.shetland.ogc.sensorML.SensorML in project arctic-sea by 52North.

the class SensorMLEncoderv20 method createOutputs.

/**
 * Creates the outputs section of the SensorML description.
 *
 * @param sosOutputs
 *            SOS SWE representation.
 *
 * @return XML Outputs element
 *
 * @throws org.n52.svalbard.encode.exception.EncodingException
 *             if the encoding fails
 */
private Outputs createOutputs(final List<SmlIo> sosOutputs) throws EncodingException {
    final Outputs outputs = Outputs.Factory.newInstance(getXmlOptions());
    final OutputListType outputList = outputs.addNewOutputList();
    final Set<String> definitions = Sets.newHashSet();
    int counter = 1;
    final Set<String> outputNames = Sets.newHashSet();
    for (final SmlIo sosSMLIo : sosOutputs) {
        if (sosSMLIo.isSetValue() && !definitions.contains(sosSMLIo.getIoValue().getDefinition())) {
            if (!sosSMLIo.isSetName() || outputNames.contains(sosSMLIo.getIoName())) {
                sosSMLIo.setIoName(getValidOutputName(counter++, outputNames));
            } else {
                sosSMLIo.setIoName(NcName.makeValid(sosSMLIo.getIoName()));
            }
            outputNames.add(sosSMLIo.getIoName());
            addOutput(outputList.addNewOutput(), sosSMLIo);
            definitions.add(sosSMLIo.getIoValue().getDefinition());
        }
    }
    return outputs;
}
Also used : Outputs(net.opengis.sensorml.x20.AbstractProcessType.Outputs) OutputListType(net.opengis.sensorml.x20.OutputListType) SmlIo(org.n52.shetland.ogc.sensorML.elements.SmlIo)

Example 9 with SensorML

use of org.n52.shetland.ogc.sensorML.SensorML in project arctic-sea by 52North.

the class InsertResultTemplateRequestEncoderTest method setup.

@Before
public void setup() throws InvalidSridException, ParseException {
    SensorML procedure = new SensorML();
    procedure.setIdentifier(procedureIdentifier);
    SamplingFeature featureOfInterest = new SamplingFeature(new CodeWithAuthority(featureIdentifier));
    featureOfInterest.setIdentifier(featureIdentifier);
    featureOfInterest.setName(new CodeType(featureName));
    featureOfInterest.setFeatureType(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT);
    featureOfInterest.setGeometry(JTSHelper.createGeometryFromWKT("POINT(30 10)", 4326));
    observationTemplate = new OmObservationConstellation();
    observationTemplate.addOffering(offering);
    observationTemplate.setObservationType(OmConstants.OBS_TYPE_MEASUREMENT);
    observationTemplate.setProcedure(procedure);
    observationTemplate.setObservableProperty(new OmObservableProperty(observedProperty));
    observationTemplate.setFeatureOfInterest(featureOfInterest);
    SweTextEncoding textEncoding = new SweTextEncoding();
    textEncoding.setBlockSeparator(blockSeparator);
    textEncoding.setTokenSeparator(tokenSeparator);
    SweDataRecord resultStructure = new SweDataRecord();
    SweTime sweTime = new SweTime();
    sweTime.setDefinition(field1Definition);
    sweTime.setUom(field1Uom);
    resultStructure.addField(new SweField(field1Name, sweTime));
    request = new InsertResultTemplateRequest(SosConstants.SOS, Sos2Constants.SERVICEVERSION, Sos2Constants.Operations.InsertResultTemplate.name());
    request.setResultEncoding(new SosResultEncoding(textEncoding));
    request.setResultStructure(new SosResultStructure(resultStructure));
    request.setIdentifier(templateIdentifier);
    request.setObservationTemplate(observationTemplate);
    Supplier<XmlOptions> xmlOptions = () -> new XmlOptions();
    encoder = new InsertResultTemplateRequestEncoder();
    encoder.setXmlOptions(xmlOptions);
    OmEncoderv20 omEncoder = new OmEncoderv20();
    omEncoder.setXmlOptions(xmlOptions);
    SamplingEncoderv20 samsEncoder = new SamplingEncoderv20();
    samsEncoder.setXmlOptions(xmlOptions);
    GmlEncoderv321 gml32Encoder = new GmlEncoderv321();
    gml32Encoder.setXmlOptions(xmlOptions);
    SweCommonEncoderv20 sweEncoderv20 = new SweCommonEncoderv20();
    sweEncoderv20.setXmlOptions(xmlOptions);
    EncoderRepository encoderRepository = new EncoderRepository();
    encoderRepository.setEncoders(Arrays.asList(encoder, omEncoder, samsEncoder, gml32Encoder, sweEncoderv20));
    encoderRepository.init();
    encoderRepository.getEncoders().stream().forEach(e -> ((AbstractDelegatingEncoder<?, ?>) e).setEncoderRepository(encoderRepository));
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) XmlOptions(org.apache.xmlbeans.XmlOptions) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) SensorML(org.n52.shetland.ogc.sensorML.SensorML) SosResultEncoding(org.n52.shetland.ogc.sos.SosResultEncoding) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) CodeType(org.n52.shetland.ogc.gml.CodeType) SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) SosResultStructure(org.n52.shetland.ogc.sos.SosResultStructure) InsertResultTemplateRequest(org.n52.shetland.ogc.sos.request.InsertResultTemplateRequest) Before(org.junit.Before)

Example 10 with SensorML

use of org.n52.shetland.ogc.sensorML.SensorML 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());
    }
}
Also used : SystemType(net.opengis.sensorML.x101.SystemType) ContactList(net.opengis.sensorML.x101.ContactListDocument.ContactList) SensorML(org.n52.shetland.ogc.sensorML.SensorML) Member(net.opengis.sensorML.x101.ContactListDocument.ContactList.Member) System(org.n52.shetland.ogc.sensorML.System) SmlPerson(org.n52.shetland.ogc.sensorML.SmlPerson) Test(org.junit.Test)

Aggregations

SensorML (org.n52.shetland.ogc.sensorML.SensorML)13 XmlObject (org.apache.xmlbeans.XmlObject)12 SystemType (net.opengis.sensorML.x101.SystemType)10 Test (org.junit.Test)9 System (org.n52.shetland.ogc.sensorML.System)9 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)7 SensorMLDocument (net.opengis.sensorML.x101.SensorMLDocument)5 DecodingException (org.n52.svalbard.decode.exception.DecodingException)5 SmlIo (org.n52.shetland.ogc.sensorML.elements.SmlIo)4 ResponsibleParty (net.opengis.sensorML.x101.ResponsiblePartyDocument.ResponsibleParty)3 SmlPerson (org.n52.shetland.ogc.sensorML.SmlPerson)3 ArrayList (java.util.ArrayList)2 AbstractProcessType (net.opengis.sensorML.x101.AbstractProcessType)2 ComponentType (net.opengis.sensorML.x101.ComponentType)2 Component (net.opengis.sensorML.x101.ComponentsDocument.Components.ComponentList.Component)2 ContactList (net.opengis.sensorML.x101.ContactListDocument.ContactList)2 Member (net.opengis.sensorML.x101.ContactListDocument.ContactList.Member)2 IdentifierList (net.opengis.sensorML.x101.IdentificationDocument.Identification.IdentifierList)2 Identifier (net.opengis.sensorML.x101.IdentificationDocument.Identification.IdentifierList.Identifier)2 Person (net.opengis.sensorML.x101.PersonDocument.Person)2