-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensor.go
79 lines (65 loc) · 2.54 KB
/
sensor.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
package core
import (
"encoding/json"
"errors"
)
// Sensor in SensorThings represents the physical device capable of observing a physical property and converting
// it to an electrical impulse and be converted to a empirical value to represent a measurement value of the physical property
type Sensor struct {
BaseEntity
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
EncodingType string `json:"encodingType,omitempty"`
Metadata string `json:"metadata,omitempty"`
NavDatastreams string `json:"[email protected],omitempty"`
Datastreams []*Datastream `json:"Datastreams,omitempty"`
}
func (s *Sensor) ClearNav() {
s.NavSelf = ""
s.NavDatastreams = ""
}
// GetEntityType returns the EntityType for Sensor
func (s Sensor) GetEntityType() EntityType {
return EntityTypeSensor
}
// GetPropertyNames returns the available properties for a Sensor
func (s *Sensor) GetPropertyNames() []string {
return []string{"id", "name", "description", "encodingType", "metadata"}
}
// ParseEntity tries to parse the given json byte array into the current entity
func (s *Sensor) ParseEntity(data []byte) error {
sensor := &s
err := json.Unmarshal(data, sensor)
if err != nil {
return errors.New("Unable to parse Sensor")
}
return nil
}
// ContainsMandatoryParams checks if all mandatory params for Sensor are available before posting.
func (s *Sensor) ContainsMandatoryParams() (bool, []error) {
err := []error{}
CheckMandatoryParam(&err, s.Name, s.GetEntityType(), "name")
CheckMandatoryParam(&err, s.Description, s.GetEntityType(), "description")
CheckMandatoryParam(&err, s.EncodingType, s.GetEntityType(), "encodingType")
CheckMandatoryParam(&err, s.Metadata, s.GetEntityType(), "metadata")
if len(err) != 0 {
return false, err
}
return true, nil
}
// SetAllLinks sets the self link and relational links
func (s *Sensor) SetAllLinks(externalURL string) {
s.SetSelfLink(externalURL)
s.SetLinks(externalURL)
for _, d := range s.Datastreams {
d.SetAllLinks(externalURL)
}
}
// SetSelfLink sets the self link for the entity
func (s *Sensor) SetSelfLink(externalURL string) {
s.NavSelf = CreateEntitySelfLink(externalURL, EntityLinkSensors.ToString(), s.ID)
}
// SetLinks sets the entity specific navigation links, empty string if linked(expanded) data is not nil
func (s *Sensor) SetLinks(externalURL string) {
s.NavDatastreams = CreateEntityLink(s.Datastreams == nil, externalURL, EntityLinkSensors.ToString(), EntityLinkDatastreams.ToString(), s.ID)
}