Skip to content

Commit e27be61

Browse files
committed
- TORGI now acts as a limited SOS in responding to both web POSTs as well as Android broadcasts
- TORGIListener sample app updated to reflect new changes - TORGI SOS structure changed to make adding future capabilities easier - TORGI responds to GetObservations with and without a time filter
1 parent 6b9d4a2 commit e27be61

13 files changed

Lines changed: 530 additions & 173 deletions

sample/TORGIListener/app/src/main/java/tech/plugs/torgilistener/AbstractSOSBroadcastTransceiver.java

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import android.content.Intent;
66
import android.util.Log;
77

8+
import org.json.JSONArray;
9+
import org.json.JSONException;
10+
import org.json.JSONObject;
11+
812
import java.io.StringWriter;
913
import java.text.ParseException;
1014
import java.text.SimpleDateFormat;
@@ -77,11 +81,27 @@ public void onMessageReceived(Context context,String source,String input) {
7781
}
7882

7983
public final static String getOperationDescribeSensor() {
80-
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><DescribeSensor version=\"1.0.0\" service=\"SOS\" mobileEnabled=\"true\" xmlns=\"http://www.opengis.net/sos/1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosDescribeSensor.xsd\" outputFormat=\"text/xml;subtype=&quot;sensorML/1.0.1&quot;\"><procedure>urn:ogc:object:feature:Sensor:IFGI:ifgi-sensor-1</procedure></DescribeSensor>";
84+
JSONObject obj = new JSONObject();
85+
try {
86+
obj.put("request","DescribeSensor");
87+
obj.put("service","SOS");
88+
obj.put("version","2.0.0");
89+
} catch (JSONException e) {
90+
e.printStackTrace();
91+
}
92+
return obj.toString();
8193
}
8294

8395
public final static String getOperationGetCapabilities() {
84-
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><GetCapabilities xmlns=\"http://www.opengis.net/sos/1.0\" xmlns:ows=\"http://www.opengis.net/ows/1.1\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/sos/1.0http://schemas.opengis.net/sos/1.0.0/sosGetCapabilities.xsd\" service=\"SOS\" updateSequence=\"\"><ows:AcceptVersions><ows:Version>1.0.0</ows:Version></ows:AcceptVersions><ows:Sections><ows:Section>OperationsMetadata</ows:Section><ows:Section>ServiceIdentification</ows:Section><ows:Section>Filter_Capabilities</ows:Section><ows:Section>Contents</ows:Section></ows:Sections></GetCapabilities>";
96+
JSONObject obj = new JSONObject();
97+
try {
98+
obj.put("request","GetCapabilities");
99+
obj.put("service","SOS");
100+
} catch (JSONException e) {
101+
e.printStackTrace();
102+
}
103+
104+
return obj.toString();
85105
}
86106

87107
public static long parseTime(String time) {
@@ -105,7 +125,7 @@ public static String formatTime(long time) {
105125
* @return
106126
*/
107127
public static String getOperationGetObservations() {
108-
return getOperationGetObservations(Long.MIN_VALUE, Long.MIN_VALUE);
128+
return getOperationGetObservations(Long.MIN_VALUE, Long.MAX_VALUE);
109129
}
110130

111131
/**
@@ -115,31 +135,26 @@ public static String getOperationGetObservations() {
115135
* @return
116136
*/
117137
public static String getOperationGetObservations(long start, long end) {
118-
StringWriter writer = new StringWriter();
119-
writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
120-
"<GetObservation xmlns=\"http://www.opengis.net/sos/1.0\" xmlns:ows=\"http://www.opengis.net/ows/1.1\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:om=\"http://www.opengis.net/om/1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/sos/1.0\n" +
121-
"http://schemas.opengis.net/sos/1.0.0/sosGetObservation.xsd\" service=\"SOS\" version=\"1.0.0\" srsName=\"urn:ogc:def:crs:EPSG:4326\">\n" +
122-
" <offering>TORGI</offering>\n"); //TODO change this type of offering
123-
if (end > Long.MIN_VALUE) {
124-
writer.append(" <eventTime>\n" +
125-
" <ogc:TM_During>\n" +
126-
" <ogc:PropertyName>urn:ogc:data:time:iso8601</ogc:PropertyName>\n" +
127-
" <gml:TimePeriod>\n" +
128-
" <gml:beginPosition>");
129-
writer.append(formatTime(start));
130-
writer.append("</gml:beginPosition>\n" +
131-
" <gml:endPosition>");
132-
writer.append(formatTime(end));
133-
writer.append("</gml:endPosition>\n" +
134-
" </gml:TimePeriod>\n" +
135-
" </ogc:TM_During>\n" +
136-
" </eventTime>\n");
138+
JSONObject obj = new JSONObject();
139+
try {
140+
obj.put("request","GetObservation");
141+
obj.put("service","SOS");
142+
obj.put("version","2.0.0");
143+
if ((start != Long.MIN_VALUE) && (end != Long.MAX_VALUE)) {
144+
JSONObject temporalFilter = new JSONObject();
145+
JSONObject during = new JSONObject();
146+
during.put("ref","om:phenomenonTime");
147+
JSONArray values = new JSONArray();
148+
values.put(formatTime(start));
149+
values.put(formatTime(end));
150+
during.put("value",values);
151+
temporalFilter.put("during",during);
152+
obj.put("temporalFilter",temporalFilter);
153+
}
154+
} catch (JSONException e) {
155+
e.printStackTrace();
137156
}
138-
//TODO need to implement " <procedure>urn:ogc:object:feature:Sensor:IFGI:ifgi-sensor-1</procedure>\n" +
139-
//TODO need to implement " <observedProperty>urn:ogc:def:phenomenon:OGC:1.0.30:waterlevel</observedProperty>\n" +
140-
writer.append(" <responseFormat>text/xml;subtype=&quot;om/1.0.0&quot;</responseFormat>\n" +
141-
"</GetObservation>");
142157

143-
return writer.toString();
158+
return obj.toString();
144159
}
145160
}

torgi/src/main/java/org/sofwerx/torgi/ogc/AbstractSOSBroadcastTransceiver.java

Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import android.util.Log;
77

88
import org.sofwerx.torgi.BuildConfig;
9+
import org.sofwerx.torgi.ogc.sos.DescribeSensor;
10+
import org.sofwerx.torgi.ogc.sos.GetCapabilities;
11+
import org.sofwerx.torgi.ogc.sos.GetObservations;
912

1013
import java.io.StringWriter;
1114
import java.text.ParseException;
@@ -28,7 +31,6 @@
2831
*
2932
*/
3033
public abstract class AbstractSOSBroadcastTransceiver extends BroadcastReceiver {
31-
private final static SimpleDateFormat dateFormatISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
3234
protected final static String TAG = "OGC.SOS";
3335
public static final String ACTION_SOS = "org.sofwerx.torgi.ogc.ACTION_SOS";
3436
private static final String EXTRA_PAYLOAD = "SOS";
@@ -81,69 +83,21 @@ public void onMessageReceived(Context context,String source,String input) {
8183
}
8284

8385
public final static String getOperationDescribeSensor() {
84-
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><DescribeSensor version=\"1.0.0\" service=\"SOS\" mobileEnabled=\"true\" xmlns=\"http://www.opengis.net/sos/1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosDescribeSensor.xsd\" outputFormat=\"text/xml;subtype=&quot;sensorML/1.0.1&quot;\"><procedure>urn:ogc:object:feature:Sensor:IFGI:ifgi-sensor-1</procedure></DescribeSensor>";
86+
return new DescribeSensor().toJSON().toString();
8587
}
8688

8789
public final static String getOperationGetCapabilities() {
88-
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><GetCapabilities xmlns=\"http://www.opengis.net/sos/1.0\" xmlns:ows=\"http://www.opengis.net/ows/1.1\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/sos/1.0http://schemas.opengis.net/sos/1.0.0/sosGetCapabilities.xsd\" service=\"SOS\" updateSequence=\"\"><ows:AcceptVersions><ows:Version>1.0.0</ows:Version></ows:AcceptVersions><ows:Sections><ows:Section>OperationsMetadata</ows:Section><ows:Section>ServiceIdentification</ows:Section><ows:Section>Filter_Capabilities</ows:Section><ows:Section>Contents</ows:Section></ows:Sections></GetCapabilities>";
90+
return new GetCapabilities().toJSON().toString();
8991
}
9092

91-
public static long parseTime(String time) {
92-
if (time != null) {
93-
try {
94-
Date date = dateFormatISO8601.parse(time);
95-
return date.getTime();
96-
} catch (ParseException e) {
97-
e.printStackTrace();
98-
}
99-
}
100-
return Long.MIN_VALUE;
101-
}
102-
103-
public static String formatTime(long time) {
104-
return dateFormatISO8601.format(time);
105-
}
106-
107-
/**
108-
* Gets the recent observations
109-
* @return
110-
*/
11193
public static String getOperationGetObservations() {
112-
return getOperationGetObservations(Long.MIN_VALUE, Long.MIN_VALUE);
94+
return new GetObservations().toJSON().toString();
11395
}
11496

115-
/**
116-
* Gets a range of observations
117-
* @param start start time
118-
* @param end end time
119-
* @return
120-
*/
121-
public static String getOperationGetObservations(long start, long end) {
122-
StringWriter writer = new StringWriter();
123-
writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
124-
"<GetObservation xmlns=\"http://www.opengis.net/sos/1.0\" xmlns:ows=\"http://www.opengis.net/ows/1.1\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:om=\"http://www.opengis.net/om/1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/sos/1.0\n" +
125-
"http://schemas.opengis.net/sos/1.0.0/sosGetObservation.xsd\" service=\"SOS\" version=\"1.0.0\" srsName=\"urn:ogc:def:crs:EPSG:4326\">\n" +
126-
" <offering>TORGI</offering>\n"); //TODO change this type of offering
127-
if (end > Long.MIN_VALUE) {
128-
writer.append(" <eventTime>\n" +
129-
" <ogc:TM_During>\n" +
130-
" <ogc:PropertyName>urn:ogc:data:time:iso8601</ogc:PropertyName>\n" +
131-
" <gml:TimePeriod>\n" +
132-
" <gml:beginPosition>");
133-
writer.append(formatTime(start));
134-
writer.append("</gml:beginPosition>\n" +
135-
" <gml:endPosition>");
136-
writer.append(formatTime(end));
137-
writer.append("</gml:endPosition>\n" +
138-
" </gml:TimePeriod>\n" +
139-
" </ogc:TM_During>\n" +
140-
" </eventTime>\n");
141-
}
142-
//TODO need to implement " <procedure>urn:ogc:object:feature:Sensor:IFGI:ifgi-sensor-1</procedure>\n" +
143-
//TODO need to implement " <observedProperty>urn:ogc:def:phenomenon:OGC:1.0.30:waterlevel</observedProperty>\n" +
144-
writer.append(" <responseFormat>text/xml;subtype=&quot;om/1.0.0&quot;</responseFormat>\n" +
145-
"</GetObservation>");
146-
147-
return writer.toString();
97+
public static String getOperationGetObservations(long start, long stop) {
98+
GetObservations getObservations = new GetObservations();
99+
getObservations.setStartTime(start);
100+
getObservations.setStopTime(stop);
101+
return getObservations.toJSON().toString();
148102
}
149103
}

torgi/src/main/java/org/sofwerx/torgi/ogc/LiteWebServer.java

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55
import org.apache.http.conn.util.InetAddressUtils;
66
import org.json.JSONException;
77
import org.json.JSONObject;
8+
import org.sofwerx.torgi.gnss.helper.GeoPackageGPSPtHelper;
89
import org.sofwerx.torgi.gnss.helper.GeoPackageSatDataHelper;
10+
import org.sofwerx.torgi.ogc.sos.AbstractOperation;
11+
import org.sofwerx.torgi.ogc.sos.DescribeSensor;
12+
import org.sofwerx.torgi.ogc.sos.GetCapabilities;
13+
import org.sofwerx.torgi.ogc.sos.GetObservations;
14+
import org.sofwerx.torgi.ogc.sos.UnsupportedOperationException;
915
import org.sofwerx.torgi.service.TorgiService;
1016

1117
import java.io.IOException;
18+
import java.io.StringWriter;
1219
import java.net.InetAddress;
1320
import java.net.NetworkInterface;
1421
import java.util.ArrayList;
@@ -69,20 +76,32 @@ public Response serve(IHTTPSession session) {
6976
} catch (JSONException ignore) {}
7077
}
7178
}
72-
if (obj != null) {
73-
String operation = obj.optString("request",null);
74-
if (operation != null) {
75-
if ("GetObservation".equalsIgnoreCase(operation)) {
79+
try {
80+
AbstractOperation receivedOperation = AbstractOperation.getOperation(obj);
81+
if (receivedOperation != null) {
82+
if (receivedOperation instanceof GetObservations) {
83+
GetObservations getObservations = (GetObservations) receivedOperation;
84+
long start = getObservations.getStartTime();
85+
long stop = getObservations.getStopTime();
86+
StringWriter out = new StringWriter();
7687
ArrayList<GeoPackageSatDataHelper> measurements =
77-
torgiService.getGeoPackageRecorder().getGnssMeasurementsSatDataBlocking(System.currentTimeMillis()-1000l*10l,System.currentTimeMillis());
78-
if (measurements == null)
79-
return newFixedLengthResponse("{}"); //TODO send back a better empty description
80-
else {
81-
String out = SOSHelper.getObservation(measurements);
82-
return newFixedLengthResponse(out);
83-
}
88+
torgiService.getGeoPackageRecorder().getGnssMeasurementsSatDataBlocking(start, stop);
89+
out.append(SOSHelper.getObservationResult(measurements));
90+
out.append('\n');
91+
ArrayList<GeoPackageGPSPtHelper> gpsMeasurements =
92+
torgiService.getGeoPackageRecorder().getGPSObservationPointsBlocking(start,stop);
93+
out.append(SOSHelper.getObservationResultGPSPts(gpsMeasurements));
94+
return newFixedLengthResponse(out.toString());
95+
} else if (receivedOperation instanceof GetCapabilities) {
96+
return newFixedLengthResponse(SOSHelper.getCapabilities());
97+
} else if (receivedOperation instanceof DescribeSensor) {
98+
return newFixedLengthResponse(SOSHelper.getDescribeSensor(torgiService,torgiService.getCurrentLocation()));
8499
}
85100
}
101+
} catch (UnsupportedOperationException e) {
102+
//TODO
103+
Log.e(TAG,e.getMessage());
104+
return newFixedLengthResponse(e.getMessage());
86105
}
87106
}
88107
}

0 commit comments

Comments
 (0)