Skip to content

Commit

Permalink
Merge pull request #117 from CarstenHollmann/fix/result_insertion
Browse files Browse the repository at this point in the history
Fis issue #116
  • Loading branch information
CarstenHollmann committed Aug 26, 2014
2 parents 0121151 + d38df7d commit 286cd8d
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 17 deletions.
2 changes: 2 additions & 0 deletions core/api/src/main/java/org/n52/sos/ogc/om/OmConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ public interface OmConstants {
String PHEN_SAMPLING_TIME = "http://www.opengis.net/def/property/OGC/0/SamplingTime";

String PHENOMENON_TIME = "http://www.opengis.net/def/property/OGC/0/PhenomenonTime";

String RESULT_TIME = "http://www.opengis.net/def/property/OGC/0/ResultTime";

String PHENOMENON_TIME_NAME = EN_PHENOMENON_TIME;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.n52.sos.ogc.gml.time.TimePeriod;
import org.n52.sos.ogc.om.MultiObservationValues;
import org.n52.sos.ogc.om.ObservationValue;
import org.n52.sos.ogc.om.OmConstants;
import org.n52.sos.ogc.om.OmObservation;
import org.n52.sos.ogc.om.OmObservationConstellation;
import org.n52.sos.ogc.om.SingleObservationValue;
Expand Down Expand Up @@ -97,6 +98,7 @@ public List<OmObservation> unfold() throws OwsExceptionReport {
for (final List<String> block : values) {
int tokenIndex = 0;
Time phenomenonTime = null;
TimeInstant resultTime = null;
final List<Value<?>> observedValues = new LinkedList<Value<?>>();
// map to store the observed properties
final Map<Value<?>, String> definitionsForObservedValues = Maps.newHashMap();
Expand All @@ -111,7 +113,13 @@ public List<OmObservation> unfold() throws OwsExceptionReport {
*/
if (fieldForToken instanceof SweTime) {
try {
phenomenonTime = new TimeInstant(DateTimeHelper.parseIsoString2DateTime(token));
if (fieldForToken.isSetDefinition() && OmConstants.RESULT_TIME.equals(fieldForToken.getDefinition())) {
resultTime = new TimeInstant(DateTimeHelper.parseIsoString2DateTime(token));
} else {
if (phenomenonTime == null) {
phenomenonTime = new TimeInstant(DateTimeHelper.parseIsoString2DateTime(token));
}
}
} catch (final OwsExceptionReport e) {
throw e;
} catch (final Exception e) {
Expand Down Expand Up @@ -167,7 +175,7 @@ else if (fieldForToken instanceof SweQuantity) {
}
for (final Value<?> iValue : observedValues) {
final OmObservation newObservation =
createSingleValueObservation(multiObservation, phenomenonTime, iValue);
createSingleValueObservation(multiObservation, phenomenonTime, resultTime, iValue);
observationCollection.add(newObservation);
}
}
Expand All @@ -177,7 +185,7 @@ else if (fieldForToken instanceof SweQuantity) {

@SuppressWarnings({ "unchecked", "rawtypes" })
private OmObservation createSingleValueObservation(final OmObservation multiObservation,
final Time phenomenonTime, final Value<?> iValue) {
final Time phenomenonTime, TimeInstant resultTime, final Value<?> iValue) {
final ObservationValue<?> value = new SingleObservationValue(phenomenonTime, iValue);
final OmObservation newObservation = new OmObservation();
newObservation.setNoDataValue(multiObservation.getNoDataValue());
Expand All @@ -193,7 +201,17 @@ private OmObservation createSingleValueObservation(final OmObservation multiObse
*/
newObservation.setObservationConstellation(obsConst);
newObservation.setValidTime(multiObservation.getValidTime());
newObservation.setResultTime(multiObservation.getResultTime());
if (resultTime != null && !resultTime.isEmpty()) {
newObservation.setResultTime(resultTime);
} else if (multiObservation.isSetResultTime() && !multiObservation.getResultTime().isEmpty()) {
newObservation.setResultTime(multiObservation.getResultTime());
} else {
if (phenomenonTime instanceof TimeInstant) {
newObservation.setResultTime((TimeInstant)phenomenonTime);
} else if (phenomenonTime instanceof TimePeriod) {
newObservation.setResultTime(new TimeInstant(((TimePeriod)phenomenonTime).getEnd()));
}
}
newObservation.setTokenSeparator(multiObservation.getTokenSeparator());
newObservation.setTupleSeparator(multiObservation.getTupleSeparator());
newObservation.setResultType(multiObservation.getResultType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
import org.n52.sos.ds.hibernate.dao.ResultTemplateDAO;
import org.n52.sos.ds.hibernate.entities.FeatureOfInterest;
import org.n52.sos.ds.hibernate.entities.ObservationConstellation;
import org.n52.sos.ds.hibernate.util.ResultHandlingHelper;
import org.n52.sos.exception.ows.NoApplicableCodeException;
import org.n52.sos.exception.ows.concrete.InvalidObservationTypeException;
import org.n52.sos.ogc.om.OmConstants;
import org.n52.sos.ogc.om.OmObservationConstellation;
import org.n52.sos.ogc.ows.OwsExceptionReport;
import org.n52.sos.ogc.sos.CapabilitiesExtension;
Expand Down Expand Up @@ -104,7 +106,7 @@ public InsertResultTemplateResponse insertResultTemplate(InsertResultTemplateReq
featureOfInterestDAO.checkOrInsertFeatureOfInterestRelatedFeatureRelation(feature,
obsConst.getOffering(), session);
// check if result structure elements are supported
checkResultStructure(request.getResultStructure());
checkResultStructure(request.getResultStructure(), obsConst.getObservableProperty().getIdentifier());
new ResultTemplateDAO().checkOrInsertResultTemplate(request, obsConst, feature, session);
} else {
// TODO make better exception.
Expand Down Expand Up @@ -158,15 +160,35 @@ public String getRelatedOperation() {
}


private void checkResultStructure(SosResultStructure resultStructure) throws OwsExceptionReport {
// TODO modify or remove if complex field elements are supported
final SweDataRecord record = setRecordFrom(resultStructure.getResultStructure());

for (final SweField swefield : record.getFields()) {
if (!(swefield.getElement() instanceof SweAbstractSimpleType<?>)) {
throw new NoApplicableCodeException().withMessage("The swe:Field element of type %s is not yet supported!", swefield.getElement().getClass().getName());
}
}
}
private void checkResultStructure(SosResultStructure resultStructure,
String observedProperty) throws OwsExceptionReport {
// TODO modify or remove if complex field elements are supported
final SweDataRecord record = setRecordFrom(resultStructure
.getResultStructure());

for (final SweField swefield : record.getFields()) {
if (!(swefield.getElement() instanceof SweAbstractSimpleType<?>)) {
throw new NoApplicableCodeException()
.withMessage(
"The swe:Field element of type %s is not yet supported!",
swefield.getElement().getClass().getName());
}
}
if (ResultHandlingHelper.hasPhenomenonTime(record) == -1) {
throw new NoApplicableCodeException()
.at(Sos2Constants.InsertResultTemplateParams.resultStructure)
.withMessage(
"Missing swe:Time or swe:TimeRange with definition %s",
OmConstants.PHENOMENON_TIME);
}
if (ResultHandlingHelper.checkFields(record.getFields(),
observedProperty) == -1) {
throw new NoApplicableCodeException()
.at(Sos2Constants.InsertResultTemplateParams.resultStructure)
.withMessage(
"Missing swe:field content with element definition %s",
observedProperty);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.n52.sos.ds.hibernate.entities.interfaces.GeometryObservation;
import org.n52.sos.ds.hibernate.entities.interfaces.NumericObservation;
import org.n52.sos.ds.hibernate.entities.interfaces.TextObservation;
import org.n52.sos.ogc.om.OmConstants;
import org.n52.sos.ogc.ows.OwsExceptionReport;
import org.n52.sos.ogc.sos.SosResultEncoding;
import org.n52.sos.ogc.sos.SosResultStructure;
Expand All @@ -68,9 +69,9 @@
*/
public class ResultHandlingHelper {

private static final String RESULT_TIME = "http://www.opengis.net/def/property/OGC/0/ResultTime";
private static final String RESULT_TIME = OmConstants.RESULT_TIME;

private static final String PHENOMENON_TIME = "http://www.opengis.net/def/property/OGC/0/PhenomenonTime";
private static final String PHENOMENON_TIME = OmConstants.PHENOMENON_TIME;

/**
* Create internal ResultEncoding from String representation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,10 @@ private void insertResultTemplate(String identifier, String procedureId, String
SweDataRecord dataRecord = new SweDataRecord();
SweTime sweTime = new SweTime();
sweTime.setUom(OmConstants.PHEN_UOM_ISO8601);
sweTime.setDefinition(OmConstants.PHENOMENON_TIME);
dataRecord.addField(new SweField("time", sweTime));
SweQuantity airTemp = new SweQuantity();
airTemp.setDefinition(obsPropId);
airTemp.setUom(TEMP_UNIT);
dataRecord.addField(new SweField("air_temperature", airTemp));
SosResultStructure resultStructure = new SosResultStructure();
Expand Down
52 changes: 52 additions & 0 deletions webapp/src/main/webapp/static/conf/client-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,32 @@
},
"method":"POST"
},
{
"request":"static/examples/sos_v20/requests_xml/ResultHandling/InsertResultWithResultTime.xml",
"service":"SOS",
"version":"2.0.0",
"binding": "application/xml",
"operation":"InsertResult",
"title":"with ResultTime",
"headers":{
"Accept":"application/xml",
"Content-Type":"application/xml"
},
"method":"POST"
},
{
"request":"static/examples/sos_v20/requests_xml/ResultHandling/InsertResultTemplateWithResultTime.xml",
"service":"SOS",
"version":"2.0.0",
"binding": "application/xml",
"operation":"InsertResultTemplate",
"title":"with ResultTime",
"headers":{
"Accept":"application/xml",
"Content-Type":"application/xml"
},
"method":"POST"
},
{
"request":"static/examples/sos_v20/requests_xml/Transactional/InsertSensor.xml",
"service":"SOS",
Expand Down Expand Up @@ -1763,6 +1789,32 @@
},
"method":"POST"
},
{
"request":"static/examples/sos_v20/requests_soap/ResultHandling/InsertResultWithResultTime.xml",
"service":"SOS",
"version":"2.0.0",
"binding": "application/soap+xml",
"operation":"InsertResult",
"title":"with ResultTime",
"headers":{
"Accept":"application/soap+xml",
"Content-Type":"application/soap+xml"
},
"method":"POST"
},
{
"request":"static/examples/sos_v20/requests_soap/ResultHandling/InsertResultTemplateWithResultTime.xml",
"service":"SOS",
"version":"2.0.0",
"binding": "application/soap+xml",
"operation":"InsertResultTemplate",
"title":"with ResultTime",
"headers":{
"Accept":"application/soap+xml",
"Content-Type":"application/soap+xml"
},
"method":"POST"
},
{
"request":"static/examples/sos_v20/requests_soap/Transactional/InsertSensor.xml",
"service":"SOS",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope/soap-envelope.xsd">
<env:Body>
<sos:InsertResultTemplate service="SOS"
version="2.0.0" xmlns:swes="http://www.opengis.net/swes/2.0"
xmlns:sos="http://www.opengis.net/sos/2.0" xmlns:swe="http://www.opengis.net/swe/2.0"
xmlns:sml="http://www.opengis.net/sensorML/1.0.1" xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:om="http://www.opengis.net/om/2.0"
xmlns:sams="http://www.opengis.net/samplingSpatial/2.0" xmlns:sf="http://www.opengis.net/sampling/2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation="http://www.opengis.net/sos/2.0 http://schemas.opengis.net/sos/2.0/sos.xsd">
<sos:proposedTemplate>
<!-- Before using this example, make sure that all preconditions are
fulfilled, e.g. perform InsertSensor example. -->
<sos:ResultTemplate>
<swes:identifier>http://www.52north.org/test/procedure/9/template/2</swes:identifier>
<sos:offering>http://www.52north.org/test/offering/9</sos:offering>
<sos:observationTemplate>
<om:OM_Observation gml:id="sensor2obsTemplate">
<om:type
xlink:href="http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_CountObservation" />
<om:phenomenonTime nilReason="template" />
<om:resultTime nilReason="template" />
<om:procedure xlink:href="http://www.52north.org/test/procedure/9" />
<om:observedProperty
xlink:href="http://www.52north.org/test/observableProperty/9_2" />
<om:featureOfInterest>
<sams:SF_SpatialSamplingFeature
gml:id="sf_test_feature_9">
<gml:identifier codeSpace="">http://www.52north.org/test/featureOfInterest/9</gml:identifier>
<gml:name>52°North</gml:name>
<sf:type
xlink:href="http://www.opengis.net/def/samplingFeatureType/OGC-OM/2.0/SF_SamplingPoint" />
<sf:sampledFeature
xlink:href="http://www.opengis.net/def/nil/OGC/0/unknown" />
<sams:shape>
<gml:Point gml:id="point_sf_test_feature_9">
<gml:pos srsName="http://www.opengis.net/def/crs/EPSG/0/4326">51.935101100104916 7.651968812254194</gml:pos>
</gml:Point>
</sams:shape>
</sams:SF_SpatialSamplingFeature>
</om:featureOfInterest>
<om:result />
</om:OM_Observation>
</sos:observationTemplate>
<sos:resultStructure>
<swe:DataRecord>
<swe:field name="phenomenonTime">
<swe:TimeRange
definition="http://www.opengis.net/def/property/OGC/0/PhenomenonTime">
<swe:uom xlink:href="http://www.opengis.net/def/uom/ISO-8601/0/Gregorian" />
</swe:TimeRange>
</swe:field>
<swe:field name="phenomenonTime">
<swe:Time
definition="http://www.opengis.net/def/property/OGC/0/ResultTime">
<swe:uom xlink:href="http://www.opengis.net/def/uom/ISO-8601/0/Gregorian" />
</swe:Time>
</swe:field>
<swe:field name="test_observable_property_9">
<swe:Count definition="http://www.52north.org/test/observableProperty/9_2">
</swe:Count>
</swe:field>
</swe:DataRecord>
</sos:resultStructure>
<sos:resultEncoding>
<swe:TextEncoding tokenSeparator="#"
blockSeparator="@" />
</sos:resultEncoding>
</sos:ResultTemplate>
</sos:proposedTemplate>
</sos:InsertResultTemplate>
</env:Body>
</env:Envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope/soap-envelope.xsd">
<env:Body>
<sos:InsertResult service="SOS" version="2.0.0" xmlns:sos="http://www.opengis.net/sos/2.0"
xsi:schemaLocation="http://www.opengis.net/sos/2.0 http://schemas.opengis.net/sos/2.0/sos.xsd">
<sos:template>http://www.52north.org/test/procedure/9/template/2</sos:template>
<sos:resultValues>15@2012-11-19T13:30:00+02:00/2012-11-19T13:30:59+02:00#2012-11-19T13:31:01+02:00#159@2012-11-19T13:31:00+02:00/2012-11-19T13:31:59+02:00#2012-11-19T13:32:01+02:00#159@2012-11-19T13:32:00+02:00/2012-11-19T13:32:59+02:00#2012-11-19T13:33:01+02:00#159@2012-11-19T13:33:00+02:00/2012-11-19T13:33:59+02:00#2012-11-19T13:34:01+02:00#160@2012-11-19T13:34:00+02:00/2012-11-19T13:34:59+02:00#2012-11-19T13:35:01+02:00#160@2012-11-19T13:35:00+02:00/2012-11-19T13:35:59+02:00#2012-11-19T13:36:01+02:00#160@2012-11-19T13:36:00+02:00/2012-11-19T13:36:59+02:00#2012-11-19T13:37:01+02:00#160@2012-11-19T13:37:00+02:00/2012-11-19T13:37:59+02:00#2012-11-19T13:38:01+02:00#160@2012-11-19T13:38:00+02:00/2012-11-19T13:38:59+02:00#2012-11-19T13:39:01+02:00#160@2012-11-19T13:39:00+02:00/2012-11-19T13:39:59+02:00#2012-11-19T13:40:01+02:00#160@2012-11-19T13:40:00+02:00/2012-11-19T13:40:59+02:00#2012-11-19T13:41:01+02:00#160@2012-11-19T13:41:00+02:00/2012-11-19T13:41:59+02:00#2012-11-19T13:42:01+02:00#160@2012-11-19T13:42:00+02:00/2012-11-19T13:42:59+02:00#2012-11-19T13:43:01+02:00#159@2012-11-19T13:43:00+02:00/2012-11-19T13:43:59+02:00#2012-11-19T13:44:01+02:00#159@2012-11-19T13:44:00+02:00/2012-11-19T13:44:59+02:00#2012-11-19T13:45:01+02:00#159@</sos:resultValues>
</sos:InsertResult>
</env:Body>
</env:Envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<sos:InsertResultTemplate service="SOS"
version="2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:swes="http://www.opengis.net/swes/2.0" xmlns:sos="http://www.opengis.net/sos/2.0"
xmlns:swe="http://www.opengis.net/swe/2.0" xmlns:sml="http://www.opengis.net/sensorML/1.0.1"
xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:om="http://www.opengis.net/om/2.0" xmlns:sams="http://www.opengis.net/samplingSpatial/2.0"
xmlns:sf="http://www.opengis.net/sampling/2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation="http://www.opengis.net/sos/2.0 http://schemas.opengis.net/sos/2.0/sosInsertResultTemplate.xsd http://www.opengis.net/om/2.0 http://schemas.opengis.net/om/2.0/observation.xsd
http://www.opengis.net/samplingSpatial/2.0 http://schemas.opengis.net/samplingSpatial/2.0/spatialSamplingFeature.xsd">
<sos:proposedTemplate>
<!-- Before using this example, make sure that all preconditions are fulfilled,
e.g. perform InsertSensor example. -->
<sos:ResultTemplate>
<swes:identifier>http://www.52north.org/test/procedure/9/template/2</swes:identifier>
<sos:offering>http://www.52north.org/test/offering/9</sos:offering>
<sos:observationTemplate>
<om:OM_Observation gml:id="sensor2obsTemplate">
<om:type
xlink:href="http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_CountObservation" />
<om:phenomenonTime nilReason="template" />
<om:resultTime nilReason="template" />
<om:procedure xlink:href="http://www.52north.org/test/procedure/9" />
<om:observedProperty
xlink:href="http://www.52north.org/test/observableProperty/9_2" />
<om:featureOfInterest>
<sams:SF_SpatialSamplingFeature gml:id="sf_test_feature_9">
<gml:identifier codeSpace="">http://www.52north.org/test/featureOfInterest/9</gml:identifier>
<gml:name>52°North</gml:name>
<sf:type
xlink:href="http://www.opengis.net/def/samplingFeatureType/OGC-OM/2.0/SF_SamplingPoint" />
<sf:sampledFeature xlink:href="http://www.opengis.net/def/nil/OGC/0/unknown" />
<sams:shape>
<gml:Point gml:id="point_sf_test_feature_9">
<gml:pos srsName="http://www.opengis.net/def/crs/EPSG/0/4326">51.935101100104916 7.651968812254194</gml:pos>
</gml:Point>
</sams:shape>
</sams:SF_SpatialSamplingFeature>
</om:featureOfInterest>
<om:result />
</om:OM_Observation>
</sos:observationTemplate>
<sos:resultStructure>
<swe:DataRecord>
<swe:field name="phenomenonTime">
<swe:TimeRange
definition="http://www.opengis.net/def/property/OGC/0/PhenomenonTime">
<swe:uom xlink:href="http://www.opengis.net/def/uom/ISO-8601/0/Gregorian" />
</swe:TimeRange>
</swe:field>
<swe:field name="phenomenonTime">
<swe:Time
definition="http://www.opengis.net/def/property/OGC/0/ResultTime">
<swe:uom xlink:href="http://www.opengis.net/def/uom/ISO-8601/0/Gregorian" />
</swe:Time>
</swe:field>
<swe:field name="test_observable_property_9">
<swe:Count definition="http://www.52north.org/test/observableProperty/9_2">
</swe:Count>
</swe:field>
</swe:DataRecord>
</sos:resultStructure>
<sos:resultEncoding>
<swe:TextEncoding tokenSeparator="#"
blockSeparator="@" />
</sos:resultEncoding>
</sos:ResultTemplate>
</sos:proposedTemplate>
</sos:InsertResultTemplate>
Loading

0 comments on commit 286cd8d

Please sign in to comment.