Search in sources :

Example 1 with SosOffering

use of org.n52.shetland.ogc.sos.SosOffering in project arctic-sea by 52North.

the class SosOffering method from.

/**
 * Creates a set of {@literal SosOffering}s from SWE simple type.
 *
 * @param type
 *            the type (may be {@literal null})
 *
 * @return the set (never {@literal null})
 */
public static SosOffering from(SweAbstractSimpleType<?> type) {
    if (type == null) {
        return null;
    }
    String identifer = type.getValue().toString();
    CodeType name = type.getName();
    SosOffering offering = new SosOffering(identifer, name);
    if (type.isSetDescription()) {
        offering.setDescription(type.getDescription());
    }
    return offering;
}
Also used : CodeType(org.n52.shetland.ogc.gml.CodeType)

Example 2 with SosOffering

use of org.n52.shetland.ogc.sos.SosOffering in project arctic-sea by 52North.

the class GetCapabilitiesResponseEncoder method encodeOffering.

private JsonNode encodeOffering(SosObservationOffering soo) throws EncodingException {
    if (soo == null) {
        return nodeFactory().nullNode();
    }
    ObjectNode jsoo = nodeFactory().objectNode();
    SosOffering offering = soo.getOffering();
    jsoo.put(JSONConstants.IDENTIFIER, offering.getIdentifier());
    if (offering.isSetName()) {
        jsoo.put(JSONConstants.NAME, offering.getFirstName().getValue());
    }
    if (soo.isSetProcedures()) {
        jsoo.set(JSONConstants.PROCEDURE, soo.getProcedures().stream().map(nodeFactory()::textNode).collect(toJsonArray()));
    }
    if (soo.isSetObservableProperties()) {
        jsoo.set(JSONConstants.OBSERVABLE_PROPERTY, soo.getObservableProperties().stream().map(nodeFactory()::textNode).collect(toJsonArray()));
    }
    if (soo.isSetRelatedFeature()) {
        ArrayNode jrf = jsoo.putArray(JSONConstants.RELATED_FEATURE);
        soo.getRelatedFeatures().forEach((feature, roles) -> {
            jrf.addObject().put(JSONConstants.FEATURE_OF_INTEREST, feature).set(JSONConstants.ROLE, roles.stream().map(nodeFactory()::textNode).collect(toJsonArray()));
        });
    }
    if (soo.isSetObservedArea() && soo.getObservedArea().isSetEnvelope() && soo.getObservedArea().isSetSrid()) {
        Envelope e = soo.getObservedArea().getEnvelope();
        ObjectNode oa = jsoo.putObject(JSONConstants.OBSERVED_AREA);
        oa.putArray(JSONConstants.LOWER_LEFT).add(e.getMinX()).add(e.getMinY());
        oa.putArray(JSONConstants.UPPER_RIGHT).add(e.getMaxX()).add(e.getMaxY());
        oa.putObject(JSONConstants.CRS).put(JSONConstants.TYPE, JSONConstants.LINK).putObject(JSONConstants.PROPERTIES).put(JSONConstants.HREF, GeoJSONEncoder.SRID_LINK_PREFIX + soo.getObservedArea().getSrid());
    }
    if (soo.isSetPhenomenonTime()) {
        jsoo.set(JSONConstants.PHENOMENON_TIME, encodeObjectToJson(soo.getPhenomenonTime()));
    }
    if (soo.isSetResultTime()) {
        jsoo.set(JSONConstants.RESULT_TIME, encodeObjectToJson(soo.getResultTime()));
    }
    if (soo.isSetResponseFormats()) {
        jsoo.set(JSONConstants.RESPONSE_FORMAT, soo.getResponseFormats().stream().map(nodeFactory()::textNode).collect(toJsonArray()));
    }
    if (soo.isSetObservationTypes()) {
        jsoo.set(JSONConstants.OBSERVATION_TYPE, soo.getObservationTypes().stream().map(nodeFactory()::textNode).collect(toJsonArray()));
    }
    if (soo.isSetFeatureOfInterestTypes()) {
        jsoo.set(JSONConstants.FEATURE_OF_INTEREST_TYPE, soo.getFeatureOfInterestTypes().stream().map(nodeFactory()::textNode).collect(toJsonArray()));
    }
    if (soo.isSetProcedureDescriptionFormats()) {
        jsoo.set(JSONConstants.PROCEDURE_DESCRIPTION_FORMAT, soo.getProcedureDescriptionFormats().stream().map(nodeFactory()::textNode).collect(toJsonArray()));
    }
    // TODO soo.getResponseModes();
    return jsoo;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SosOffering(org.n52.shetland.ogc.sos.SosOffering) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Envelope(org.locationtech.jts.geom.Envelope)

Example 3 with SosOffering

use of org.n52.shetland.ogc.sos.SosOffering in project arctic-sea by 52North.

the class GetCapabilitiesResponseEncoder method encodeObservationOffering.

private void encodeObservationOffering(SosObservationOffering offering, int offeringCounter, ContentsType xbContType) throws EncodingException {
    final ObservationOfferingType xbObsOff = ObservationOfferingType.Factory.newInstance(getXmlOptions());
    SosOffering sosOffering = offering.getOffering();
    xbObsOff.setIdentifier(sosOffering.getIdentifier());
    if (sosOffering.isSetName()) {
        for (CodeType name : sosOffering.getName()) {
            xbObsOff.addNewName().set(encodeObjectToXml(GmlConstants.NS_GML_32, name));
        }
    }
    if (sosOffering.isSetDescription()) {
        xbObsOff.setDescription(sosOffering.getDescription());
    }
    encodeOfferingExtension(offering, xbObsOff);
    offering.getProcedures().forEach(xbObsOff::setProcedure);
    encodeObservableProperties(offering, xbObsOff);
    encodeRelatedFeatures(offering, xbObsOff);
    encodeObservedArea(offering, xbObsOff);
    encodePhenomenonTime(offering, offeringCounter, xbObsOff);
    encodeResultTime(offering, offeringCounter, xbObsOff);
    encodeResponseFormat(offering, xbObsOff);
    encodeObservationType(offering, xbObsOff);
    encodeFeatureOfInterestTypes(offering, xbObsOff);
    encodeProcedureDescriptionFormats(offering, xbObsOff);
    xbContType.addNewOffering().setAbstractOffering(xbObsOff);
/*
         * Offering addNewOffering = xbContType.addNewOffering();
         * addNewOffering.addNewAbstractOffering().set(xbObsOff); XmlHelper
         * .substituteElement(addNewOffering.getAbstractOffering(), xbObsOff);
         */
}
Also used : ObservationOfferingType(net.opengis.sos.x20.ObservationOfferingType) CodeType(org.n52.shetland.ogc.gml.CodeType) SosOffering(org.n52.shetland.ogc.sos.SosOffering)

Example 4 with SosOffering

use of org.n52.shetland.ogc.sos.SosOffering in project arctic-sea by 52North.

the class SensorMLEncoderV101Test method should_encode_single_contact_person.

// @Test
// public void should_encode_features_of_interest() throws EncodingException {
// final SensorML sensorMl = new SensorML();
// final System system = new System();
// sensorMl.addMember(system);
// system.addFeatureOfInterest(TEST_ID_1);
// system.addFeatureOfInterest(TEST_ID_2);
// final SimpleDataRecordType xbSimpleDataRecord =
// encodeSimpleDataRecord(sensorMl, SensorMLConstants.ELEMENT_NAME_FEATURES_OF_INTEREST, 2);
// validateField(xbSimpleDataRecord.getFieldArray()[0], SensorMLConstants.FEATURE_OF_INTEREST_FIELD_NAME + 1,
// SensorMLConstants.FEATURE_OF_INTEREST_FIELD_DEFINITION, TEST_ID_1);
// validateField(xbSimpleDataRecord.getFieldArray()[1], SensorMLConstants.FEATURE_OF_INTEREST_FIELD_NAME + 2,
// SensorMLConstants.FEATURE_OF_INTEREST_FIELD_DEFINITION, TEST_ID_2);
// }
// 
// @Test
// public void should_encode_offerings() throws EncodingException {
// final SensorML sensorMl = new SensorML();
// final System system = new System();
// sensorMl.addMember(system);
// system.addOffering(new SosOffering(TEST_ID_1, TEST_NAME_1));
// system.addOffering(new SosOffering(TEST_ID_2, TEST_NAME_2));
// final SimpleDataRecordType xbSimpleDataRecord =
// encodeSimpleDataRecord(sensorMl, SensorMLConstants.ELEMENT_NAME_OFFERINGS, 2);
// validateField(xbSimpleDataRecord.getFieldArray()[0], TEST_NAME_1, SensorMLConstants.OFFERING_FIELD_DEFINITION,
// TEST_ID_1);
// validateField(xbSimpleDataRecord.getFieldArray()[1], TEST_NAME_2, SensorMLConstants.OFFERING_FIELD_DEFINITION,
// TEST_ID_2);
// }
// 
// @Test
// public void should_encode_parent_procedures() throws EncodingException {
// final SensorML sensorMl = new SensorML();
// final System system = new System();
// sensorMl.addMember(system);
// system.addParentProcedure(TEST_ID_1);
// system.addParentProcedure(TEST_ID_2);
// final SimpleDataRecordType xbSimpleDataRecord =
// encodeSimpleDataRecord(sensorMl, SensorMLConstants.ELEMENT_NAME_PARENT_PROCEDURES, 2);
// validateField(xbSimpleDataRecord.getFieldArray()[0], SensorMLConstants.PARENT_PROCEDURE_FIELD_NAME + 1,
// SensorMLConstants.PARENT_PROCEDURE_FIELD_DEFINITION, TEST_ID_1);
// validateField(xbSimpleDataRecord.getFieldArray()[1], SensorMLConstants.PARENT_PROCEDURE_FIELD_NAME + 2,
// SensorMLConstants.PARENT_PROCEDURE_FIELD_DEFINITION, TEST_ID_2);
// }
// 
// @Test
// public void should_encode_child_procedures() throws EncodingException {
// final SensorML sensorMl = new SensorML();
// final System system = new System();
// sensorMl.addMember(system);
// final System childProcedure = new System();
// childProcedure.setIdentifier(TEST_CHILD_1);
// system.addChildProcedure(childProcedure);
// childProcedure.addFeatureOfInterest(TEST_ID_1);
// final SystemType xbSystemType = encodeSystem(sensorMl);
// assertThat(xbSystemType.getComponents().getComponentList().sizeOfComponentArray(), is(1));
// final Component xbComponent = xbSystemType.getComponents().getComponentList().getComponentArray(0);
// assertThat(xbComponent.getProcess(), instanceOf(SystemType.class));
// final SystemType xbComponentSystem = (SystemType) xbComponent.getProcess();
// final SimpleDataRecordType xbSimpleDataRecord =
// encodeSimpleDataRecord(xbComponentSystem, SensorMLConstants.ELEMENT_NAME_FEATURES_OF_INTEREST, 1);
// validateField(xbSimpleDataRecord.getFieldArray(0), SensorMLConstants.FEATURE_OF_INTEREST_FIELD_NAME,
// SensorMLConstants.FEATURE_OF_INTEREST_FIELD_DEFINITION, TEST_ID_1);
// }
// 
// @Test
// @SuppressWarnings("unchecked")
// public void should_aggregate_child_outputs() throws EncodingException {
// final SweQuantity q1 = new SweQuantity();
// q1.setDefinition("def1");
// q1.setUom("uom1");
// final SmlIo<?> output1 = new SmlIo<SweQuantity>(q1);
// 
// final SweQuantity q2 = new SweQuantity();
// q2.setDefinition("def2");
// q2.setUom("uom2");
// final SmlIo<?> output2 = new SmlIo<SweQuantity>(q2);
// 
// final SweQuantity q3 = new SweQuantity();
// q3.setDefinition("def3");
// q3.setUom("uom3");
// final SmlIo<?> output3 = new SmlIo<SweQuantity>(q3);
// 
// final SensorML sensorMl = new SensorML();
// sensorMl.setIdentifier("sensorMl");
// final System system = new System();
// system.setIdentifier("system");
// sensorMl.addMember(system);
// system.getOutputs().add(output1);
// 
// final SensorML childSml = new SensorML();
// childSml.setIdentifier("childSml");
// final System childSystem = new System();
// childSystem.setIdentifier("childSystem");
// childSml.addMember(childSystem);
// system.addChildProcedure(childSml);
// childSystem.getOutputs().add(output2);
// 
// final SensorML grandchildSml = new SensorML();
// grandchildSml.setIdentifier("grandchildSml");
// final System grandchildSystem = new System();
// grandchildSystem.setIdentifier("grandchildSystem");
// grandchildSml.addMember(grandchildSystem);
// childSystem.addChildProcedure(grandchildSml);
// grandchildSystem.getOutputs().add(output3);
// 
// encodeSystem(sensorMl);
// 
// assertThat(system.getOutputs(), hasItems(output1, output2, output3));
// assertThat(childSystem.getOutputs(), hasItems(output2, output3));
// assertThat(grandchildSystem.getOutputs(), hasItem(output3));
// }
@Test
public void should_encode_single_contact_person() throws EncodingException {
    final SensorML sensorML = new SensorML();
    final System system = new System();
    sensorML.addMember(system);
    final SmlPerson contact = createPerson("");
    system.addContact(contact);
    final SystemType xbSystem = encodeSystem(sensorML);
    assertThat(xbSystem.sizeOfContactArray(), is(1));
    assertThat(xbSystem.getContactArray(0).getContactList().getMemberArray(0).isSetPerson(), is(true));
    checkPerson(contact, xbSystem.getContactArray(0).getContactList().getMemberArray(0).getPerson());
}
Also used : SystemType(net.opengis.sensorML.x101.SystemType) SensorML(org.n52.shetland.ogc.sensorML.SensorML) System(org.n52.shetland.ogc.sensorML.System) SmlPerson(org.n52.shetland.ogc.sensorML.SmlPerson) Test(org.junit.Test)

Example 5 with SosOffering

use of org.n52.shetland.ogc.sos.SosOffering in project arctic-sea by 52North.

the class SensorMLDecoderV101Test method should_decode_offerings_from_sml.

@Test
public void should_decode_offerings_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_OFFERINGS);
    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.getOfferings().size(), is(2));
    assertThat(absProcess.getCapabilities().size(), is(1));
// List<SosOffering> sosOfferings = new ArrayList<SosOffering>(absProcess.getOfferings());
// Collections.sort(sosOfferings);
// assertThat(sosOfferings.get(0).getIdentifier(), is(TEST_ID_1));
// assertThat(sosOfferings.get(0).getOfferingName(), is(TEST_NAME_1));
// assertThat(sosOfferings.get(1).getIdentifier(), is(TEST_ID_2));
// assertThat(sosOfferings.get(1).getOfferingName(), is(TEST_NAME_2));
}
Also used : SensorMLDocument(net.opengis.sensorML.x101.SensorMLDocument) AbstractProcess(org.n52.shetland.ogc.sensorML.AbstractProcess) Capabilities(net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities) SystemType(net.opengis.sensorML.x101.SystemType) SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) Test(org.junit.Test)

Aggregations

SystemType (net.opengis.sensorML.x101.SystemType)2 Test (org.junit.Test)2 CodeType (org.n52.shetland.ogc.gml.CodeType)2 SosOffering (org.n52.shetland.ogc.sos.SosOffering)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Capabilities (net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities)1 SensorMLDocument (net.opengis.sensorML.x101.SensorMLDocument)1 ObservationOfferingType (net.opengis.sos.x20.ObservationOfferingType)1 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)1 Envelope (org.locationtech.jts.geom.Envelope)1 AbstractProcess (org.n52.shetland.ogc.sensorML.AbstractProcess)1 SensorML (org.n52.shetland.ogc.sensorML.SensorML)1 SmlPerson (org.n52.shetland.ogc.sensorML.SmlPerson)1 System (org.n52.shetland.ogc.sensorML.System)1