ソースを参照

changed type of @iot.id to String for OGC SensorThings

Lukas Cerny 5 年 前
コミット
54324558a0

+ 3 - 3
connector-model/src/main/java/io/connector/model/sensorthings/Datastream.java

@@ -8,12 +8,12 @@ import java.util.List;
 
 public class Datastream extends JsonObject {
 
-    public void setId(Integer id) {
+    public void setId(String id) {
         put("@iot.id", id);
     }
 
-    public Integer getId() {
-        return getInteger("@iot.id");
+    public String getId() {
+        return getString("@iot.id");
     }
 
     public void setSelfLink(String selfLink) {

+ 3 - 3
connector-model/src/main/java/io/connector/model/sensorthings/FeatureOfInterest.java

@@ -4,12 +4,12 @@ import io.vertx.core.json.JsonObject;
 
 public class FeatureOfInterest extends JsonObject {
 
-    public void setId(Integer id) {
+    public void setId(String id) {
         put("@iot.id", id);
     }
 
-    public Integer getId() {
-        return getInteger("@iot.id");
+    public String getId() {
+        return getString("@iot.id");
     }
 
     public void setSelfLink(String selfLink) {

+ 3 - 3
connector-model/src/main/java/io/connector/model/sensorthings/HistoricalLocation.java

@@ -31,12 +31,12 @@ public class HistoricalLocation extends JsonObject {
 
     public static class Value extends JsonObject {
 
-        public void setId(Integer id) {
+        public void setId(String id) {
             put("@iot.id", id);
         }
 
-        public Integer getId() {
-            return getInteger("@iot.id");
+        public String getId() {
+            return getString("@iot.id");
         }
 
         public void setSelfLink(String selfLink) {

+ 3 - 3
connector-model/src/main/java/io/connector/model/sensorthings/Location.java

@@ -4,12 +4,12 @@ import io.vertx.core.json.JsonObject;
 
 public class Location extends JsonObject {
 
-    public void setId(Integer id) {
+    public void setId(String id) {
         put("@iot.id", id);
     }
 
-    public Integer getId() {
-        return getInteger("@iot.id");
+    public String getId() {
+        return getString("@iot.id");
     }
 
     public void setSelfLink(String selfLink) {

+ 3 - 3
connector-model/src/main/java/io/connector/model/sensorthings/Observation.java

@@ -4,12 +4,12 @@ import io.vertx.core.json.JsonObject;
 
 public class Observation extends JsonObject {
 
-    public void setId(Integer id) {
+    public void setId(String id) {
         put("@iot.id", id);
     }
 
-    public Integer getId() {
-        return getInteger("@iot.id");
+    public String getId() {
+        return getString("@iot.id");
     }
 
     public void setSelfLink(String selfLink) {

+ 3 - 3
connector-model/src/main/java/io/connector/model/sensorthings/ObservedProperty.java

@@ -4,12 +4,12 @@ import io.vertx.core.json.JsonObject;
 
 public class ObservedProperty extends JsonObject {
 
-    public void setId(Integer id) {
+    public void setId(String id) {
         put("@iot.id", id);
     }
 
-    public Integer getId() {
-        return getInteger("@iot.id");
+    public String getId() {
+        return getString("@iot.id");
     }
 
     public void setSelfLink(String selfLink) {

+ 3 - 3
connector-model/src/main/java/io/connector/model/sensorthings/Sensor.java

@@ -4,12 +4,12 @@ import io.vertx.core.json.JsonObject;
 
 public class Sensor extends JsonObject {
 
-    public void setId(Integer id) {
+    public void setId(String id) {
         put("@iot.id", id);
     }
 
-    public Integer getId() {
-        return getInteger("@iot.id");
+    public String getId() {
+        return getString("@iot.id");
     }
 
     public void setSelfLink(String selfLink) {

+ 3 - 3
connector-model/src/main/java/io/connector/model/sensorthings/Think.java

@@ -5,12 +5,12 @@ import io.vertx.core.json.JsonObject;
 
 public class Think extends JsonObject {
 
-    public void setId(Integer id) {
+    public void setId(String id) {
         put("@iot.id", id);
     }
 
-    public Integer getId() {
-        return getInteger("@iot.id");
+    public String getId() {
+        return getString("@iot.id");
     }
 
     public void setSelfLink(String selfLink) {

+ 8 - 16
connector-module-afarcloud/src/main/java/io/connector/module/afarcloud/gateway/OGCSensorThingsGateway.java

@@ -31,7 +31,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
 
         router().get(create("Things(:id)")).handler(ctx -> {
             RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
-            int id = Integer.parseInt(ctx.pathParam("id"));
+            String id = ctx.pathParam("id");
 
             Think think = new Think();
             think.setId(id);
@@ -56,7 +56,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
             Unit afcUnit = client.getSensor(id);
 
             Location ogcLocation = new Location();
-            ogcLocation.setId(Integer.parseInt(id));
+            ogcLocation.setId(id);
             ogcLocation.setSelfLink(format("%s/Locations(%s)", uriComponent.getGatewayUri(), id));
             ogcLocation.setHistoricalLocationsNavigationLink("unknown");
             ogcLocation.setName(afcUnit.getResourceType());
@@ -97,7 +97,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
 
         router().get(create("Datastreams(:id)")).handler(ctx -> {
             RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
-            int id = Integer.parseInt(ctx.pathParam("id"));
+            String id = ctx.pathParam("id");
 
             Datastream datastream = new Datastream();
             datastream.setId(id);
@@ -143,7 +143,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
             List<HistoricalLocation.Value> valueList = new ArrayList<>();
             for (int valueId = id; valueId < id + 2; valueId++) {
                 HistoricalLocation.Value value = new HistoricalLocation.Value();
-                value.setId(valueId);
+                value.setId(String.valueOf(valueId));
                 value.setSelfLink(format("%s/HistoricalLocations(%s)", uriComponent.getGatewayUri(), valueId));
                 value.setLocationsNavigationLink(format("HistoricalLocations(%s)/Locations", valueId));
                 value.setThingNavigationLink(format("HistoricalLocations(%s)/Thing", valueId));
@@ -185,7 +185,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
 
         router().get(create("ObservedProperties(:id)")).handler(ctx -> {
             RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
-            int id = Integer.parseInt(ctx.pathParam("id"));
+            String id = ctx.pathParam("id");
 
             ObservedProperty observedProperty = new ObservedProperty();
             observedProperty.setId(id);
@@ -200,7 +200,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
 
         router().get(create("Observations(:id)")).handler(ctx -> {
             RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
-            int id = Integer.parseInt(ctx.pathParam("id"));
+            String id = ctx.pathParam("id");
 
             Observation observation = new Observation();
             observation.setId(id);
@@ -216,7 +216,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
 
         router().get(create("FeaturesOfInterest(:id)")).handler(ctx -> {
             RequestUriComponent uriComponent = parseUriToComponents(ctx.request());
-            int id = Integer.parseInt(ctx.pathParam("id"));
+            String id = ctx.pathParam("id");
 
             FeatureOfInterest featureOfInterest = new FeatureOfInterest();
             featureOfInterest.setId(id);
@@ -243,15 +243,7 @@ public class OGCSensorThingsGateway extends AbstractGateway {
 
         static Sensor convertSensor(Unit afcUnit, RequestUriComponent uriComponent) {
             Sensor ogcSensor = new Sensor();
-
-            int ogcId;
-            try {
-                ogcId = Integer.parseInt(afcUnit.getResourceId());
-            } catch (NumberFormatException e) {
-                throw new NumberFormatException(format("Number %s can not be converted as integer.", afcUnit.getResourceId()));
-            }
-
-            ogcSensor.setId(ogcId);
+            ogcSensor.setId(afcUnit.getResourceId());
             ogcSensor.setSelfLink(format("%s/Sensors(%s)", uriComponent.getGatewayUri(), afcUnit.getResourceId()));
             ogcSensor.setDataStreamNavigationLink("unknown"); // TODO add Datastream navigation link
             ogcSensor.setName(afcUnit.getResourceType());