-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.go
394 lines (323 loc) · 12.5 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
package gossamer
type ObservationType string
type ProtocolType int
const (
HTTP ProtocolType = 0
COAP ProtocolType = 1
)
type ResourcePath interface {
All() []ResourcePathItem
Current() ResourcePathItem
Next() ResourcePathItem
Prev() ResourcePathItem
First() ResourcePathItem
Last() ResourcePathItem
// Get the containing resource for the target resource
// e.g. returns
Containing() ResourcePathItem
IsLast() bool
IsFirst() bool
HasNext() bool
CurrentIndex() int
Size() int
Add(ResourcePathItem)
At(int) ResourcePathItem
}
type ResourcePathItem interface {
GetEntity() EntityType
GetId() string
GetQueryOptions() QueryOptions
}
type EntityType string
const (
ENTITY_THING EntityType = "Thing"
ENTITY_THINGS EntityType = "Things"
ENTITY_OBSERVEDPROPERTY EntityType = "ObservedProperty"
ENTITY_OBSERVEDPROPERTIES EntityType = "ObservedProperties"
ENTITY_LOCATION EntityType = "Location"
ENTITY_LOCATIONS EntityType = "Locations"
ENTITY_DATASTREAM EntityType = "Datastream"
ENTITY_DATASTREAMS EntityType = "Datastreams"
ENTITY_SENSOR EntityType = "Sensor"
ENTITY_SENSORS EntityType = "Sensors"
ENTITY_OBSERVATION EntityType = "Observation"
ENTITY_OBSERVATIONS EntityType = "Observations"
ENTITY_FEATURESOFINTEREST EntityType = "FeaturesOfInterest"
ENTITY_HISTORICALLOCATION EntityType = "HistoricalLocation"
ENTITY_HISTORICALLOCATIONS EntityType = "HistoricalLocations"
ENTITY_UNKNOWN EntityType = "UNKNOWN"
)
type QueryOptionType string
const (
QUERYOPT_EXPAND QueryOptionType = "$expand"
QUERYOPT_SELECT QueryOptionType = "$select"
QUERYOPT_ORDERBY QueryOptionType = "$orderby"
QUERYOPT_TOP QueryOptionType = "$top"
QUERYOPT_SKIP QueryOptionType = "$skip"
QUERYOPT_COUNT QueryOptionType = "$count"
QUERYOPT_FILTER QueryOptionType = "$filter"
QUERYOPT_UNKNOWN QueryOptionType = "UNKNOWN"
)
// Determines a list of Query Options that has been set for a request
type QueryOptions interface {
ExpandSet() bool
SelectSet() bool
OrderBySet() bool
TopSet() bool
SkipSet() bool
CountSet() bool
FilterSet() bool
GetExpandOption() ExpandOption
GetSelectOption() SelectOption
GetOrderByOption() OrderByOption
GetTopOption() TopOption
GetSkipOption() SkipOption
GetCountOption() CountOption
GetFilterOption() FilterOption
}
// Query Option
type QueryOption interface {
GetType() QueryOptionType
}
// The $expand system query option indicates the related entities to be represented inline. The value of the $expand
// query option must be a comma separated list of navigation property names. Additionally each navigation property
// can be followed by a forward slash and another navigation property to enable identifying a multi-level relationship.
type ExpandOption interface {
QueryOption
GetValue() []string
}
// The $select system query option requests that the service to return only the properties explicitly requested by
// the client. The value of a $select query option is a comma-separated list of selection clauses. Each selection
// clause may be a property name (including navigation property names). The service returns the specified content, if available, along with any available expanded navigation properties.
type SelectOption interface {
QueryOption
GetValue() []string
}
// The $orderby system query option specifies the order in which items are returned from the service.
type OrderByOption interface {
QueryOption
GetValue() []OrderByOptionValue
GetSortProperties() []string
}
// asc, desc
type OrderByOptionValue interface {
GetSortProperty() string
}
type TopOption interface {
QueryOption
GetValue() int
}
type SkipOption interface {
QueryOption
GetValue() int
}
type CountOption interface {
QueryOption
GetValue() bool
}
type FilterOption interface {
QueryOption
}
type Server interface {
Stop()
Start()
UseStore(Datastore)
}
type Request interface {
GetProtocol() ProtocolType
GetQueryOptions() QueryOptions
GetResourcePath() ResourcePath
}
type Datastore interface {
Query(ResourcePath, QueryOptions) (interface{}, error)
Insert(ResourcePath, SensorThing) error
Delete(EntityType, string) error
Update(SensorThing) error
Patch(SensorThing) error
Init()
Shutdown()
}
// Entities
type SensorThing interface {
GetId() string
GetSelfLink() string
GetType() EntityType
}
// The OGC SensorThings API follows the ITU-T definition, i.e., with regard to the Internet of Things,
// a thing is an object of the physical world (physical things) or the information world (virtual things)
// that is capable of being identified and integrated into communication networks [ITU-T Y.2060].
type Thing interface {
SensorThing
// This is a short description of the corresponding Thing entity.
GetDescription() string
// An Object containing user-annotated properties as key-value pairs.
GetProperties() map[string]string
}
type LocationEncodingType string
const (
LOCATION_ENCTYPE_GEOJSON LocationEncodingType = "application/vnd.geo+json"
)
// The Location entity locates the Thing or the Things it associated with. A Thing’s Location entity is
// defined as the last known location of the Thing.
// A Thing’s Location may be identical to the Thing’s Observations’ FeatureOfInterest. In the context of the IoT,
// the principle location of interest is usually associated with the location of the Thing, especially for in-situ
// sensing applications. For example, the location of interest of a wifi-connected thermostat should be the building
// or the room in which the smart thermostat is located. And the FeatureOfInterest of the Observations made by the
// thermostat (e.g., room temperature readings) should also be the building or the room. In this case, the content
// of the smart thermostat’s location should be the same as the content of the temperature readings’ feature of interest.
type Location interface {
SensorThing
GetDescription() string
GetEncodingType() LocationEncodingType
// GetLocationType() // !! depending on GetEncodingType()
// GetThings() []Thing
// GetHistoricalLocations() []HistoricalLocation
}
// A Thing’s HistoricalLocation entity set provides the current (i.e., last known) and previous locations of the
// Thing with their time.
type HistoricalLocation interface {
SensorThing
// The time when the Thing is known at the Location.
GetTime() *TimeInstant
}
type DatastreamObservationType string
const (
DATASTREAM_OBSTYPE_CATEGORY DatastreamObservationType = "http://www.opengis.net/def/observationType/ OGC-OM/2.0/OM_CategoryObservation"
DATASTREAM_OBSTYPE_COUNT DatastreamObservationType = "http://www.opengis.net/def/observationType/ OGC-OM/2.0/OM_CountObservation"
DATASTREAM_OBSTYPE_MEASUREMENT DatastreamObservationType = "http://www.opengis.net/def/observationType/ OGC-OM/2.0/OM_Measurement"
DATASTREAM_OBSTYPE_OBSERVATION DatastreamObservationType = "http://www.opengis.net/def/observationType/ OGC-OM/2.0/OM_Observation"
DATASTREAM_OBSTYPE_TRUTHOBSERVATION DatastreamObservationType = "http://www.opengis.net/def/observationType/ OGC-OM/2.0/OM_TruthObservation"
)
// A Datastream groups a collection of Observations and the Observations in a Datastream measure the
// same ObservedProperty and are produced by the same Sensor.
type Datastream interface {
SensorThing
// GetDescription() string
// A JSON Object containing three key- value pairs. The name property presents the full name of the
// unitOfMeasurement; the symbol property shows the textual form of the unit symbol; and the definition
// contains the IRI defining the unitOfMeasurement.
// The values of these properties SHOULD follow the Unified Code for Unit of Measure (UCUM).
// GetUnitOfMeasurement() // UnitOfMeasure !!
// The type of Observation (with unique result type), which is used by the service to encode observations.
// GetObservationType() // !!
// The spatial bounding box of the spatial extent of all FeaturesOfInterest that belong to the
// Observations associated with this Datastream.
// GetObservedArea() // !!
// The temporal bounding box of the phenomenon times of all observations belonging to this Datastream.
// GetPhenomenonTime() time.Time
// The temporal bounding box of the result times of all observations belonging to this Datastream.
// GetResultTime() time.Time
// GetThing() Thing
// GetSensor() Sensor
// GetObservedProperty() ObservedProperty
// GetObservations() []Observation
}
type SensorEncodingType string
const (
SENSOR_ENCTYPE_PDF SensorEncodingType = "application/pdf"
SENSOR_ENCTYPE_SENSORML SensorEncodingType = "http://www.opengis.net/doc/IS/SensorML/2.0"
)
// A Sensor is an instrument that observes a property or phenomenon with the goal of producing an estimate of the
// value of the property.
type Sensor interface {
SensorThing
GetDescription() string
GetEncodingType() SensorEncodingType
GetMetadata() interface{}
}
// An ObservedProperty specifies the phenomenon of an Observation.
type ObservedProperty interface {
SensorThing
GetName() string
GetDefinition() string
GetDescription() string
}
// An Observation is act of measuring or otherwise determining the value of a property
type Observation interface {
SensorThing
// The time instant or period of when the Observation happens.
GetPhenomenonTime() *TimePeriod
// The time of the Observation's result was generated.
GetResultTime() *TimeInstant
// The estimated value of an ObservedProperty from the Observation.
GetResult() interface{}
// Describes the quality of the result.
GetResultQuality() interface{}
// The time period during which the result may be used.
GetValidTime() *TimePeriod
// Key-value pairs showing the environmental conditions during measurement.
GetParameters() map[string]interface{}
}
// An Observation results in a value being assigned to a phenomenon. The phenomenon is a property of a feature, the
// latter being the FeatureOfInterest of the Observation [OGC and ISO 19156:2001]. In the context of the Internet of
// Things, many Observations’ FeatureOfInterest can be the Location of the Thing. For example, the FeatureOfInterest
// of a wifi-connect thermostat can be the Location of the thermostat (i.e., the living room where the thermostat is
// located in). In the case of remote sensing, the FeatureOfInterest can be the geographical area or volume that is
// being sensed.
type FeatureOfInterest interface {
SensorThing
GetDescription() string
GetEncodingType() LocationEncodingType
GetFeature() interface{}
}
// Client API
type Client interface {
QueryObservations() ClientQuery
QueryThings() ClientQuery
QueryObservedProperties() ClientQuery
QueryLocations() ClientQuery
QueryDatastreams() ClientQuery
QuerySensors() ClientQuery
QueryFeaturesOfInterest() ClientQuery
QueryHistoricalLocations() ClientQuery
GetObservation(string) (Observation, error)
GetThing(string) (Thing, error)
GetObservedProperty(string) (ObservedProperty, error)
GetLocation(string) (Location, error)
GetDatastream(string) (Datastream, error)
GetSensor(string) (Sensor, error)
GetFeaturesOfInterest(string) (FeatureOfInterest, error)
GetHistoricalLocation(string) (HistoricalLocation, error)
FindObservations() ([]Observation, error)
FindThings() ([]Thing, error)
FindObservedProperties() ([]ObservedProperty, error)
FindLocations() ([]Location, error)
FindDatastreams() ([]Datastream, error)
FindSensors() ([]Sensor, error)
FindFeaturesOfInterest() ([]FeatureOfInterest, error)
FindHistoricalLocations() ([]HistoricalLocation, error)
InsertObservation(Observation) error
InsertThing(Thing) error
InsertObservedProperty(ObservedProperty) error
InsertLocation(Location) error
InsertDatastream(Datastream) error
InsertSensor(Sensor) error
InsertFeaturesOfInterest(FeatureOfInterest) error
DeleteObservation(string) error
DeleteThing(string) error
DeleteObservedProperty(string) error
DeleteLocation(string) error
DeleteDatastream(string) error
DeleteSensor(string) error
DeleteFeaturesOfInterest(string) error
UpdateObservation(Observation) error
UpdateThing(Thing) error
UpdateObservedProperty(ObservedProperty) error
UpdateLocation(Location) error
UpdateDatastream(Datastream) error
UpdateSensor(Sensor) error
UpdateFeaturesOfInterest(FeatureOfInterest) error
PatchObservation(Observation) error
PatchThing(Thing) error
PatchObservedProperty(ObservedProperty) error
PatchLocation(Location) error
PatchDatastream(Datastream) error
PatchSensor(Sensor) error
PatchFeaturesOfInterest(FeatureOfInterest) error
}
type ClientQuery interface {
GetEntityType() EntityType
Top(int) ClientQuery
All() ([]SensorThing, error)
One(string) (SensorThing, error)
}