-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobservedproperty.go
82 lines (67 loc) · 2.67 KB
/
observedproperty.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
package core
import (
"encoding/json"
"errors"
)
// ObservedProperty in SensorThings represents the physical phenomenon being observed by the Sensor. An ObserveProperty is
// linked to a Datastream which can only have one ObserveProperty
type ObservedProperty struct {
BaseEntity
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Definition string `json:"definition,omitempty"`
NavDatastreams string `json:"[email protected],omitempty"`
Datastreams []*Datastream `json:"Datastreams,omitempty"`
}
func (o *ObservedProperty) ClearNav() {
o.NavSelf = ""
o.NavDatastreams = ""
}
// GetEntityType returns the EntityType for ObservedProperty
func (o ObservedProperty) GetEntityType() EntityType {
return EntityTypeObservedProperty
}
// GetPropertyNames returns the available properties for a ObservedProperty
func (o *ObservedProperty) GetPropertyNames() []string {
return []string{"id", "name", "description", "definition"}
}
// ParseEntity tries to parse the given json byte array into the current entity
func (o *ObservedProperty) ParseEntity(data []byte) error {
op := &o
err := json.Unmarshal(data, op)
if err != nil {
return errors.New("Unable to parse ObservedProperty")
}
return nil
}
// ContainsMandatoryParams checks if all mandatory params for ObservedProperty are available before posting.
func (o *ObservedProperty) ContainsMandatoryParams() (bool, []error) {
err := []error{}
CheckMandatoryParam(&err, o.Name, o.GetEntityType(), "name")
CheckMandatoryParam(&err, o.Definition, o.GetEntityType(), "definition")
CheckMandatoryParam(&err, o.Description, o.GetEntityType(), "description")
if len(err) != 0 {
return false, err
}
return true, nil
}
// SetAllLinks sets the self link and relational links
func (o *ObservedProperty) SetAllLinks(externalURL string) {
o.SetSelfLink(externalURL)
o.SetLinks(externalURL)
for _, d := range o.Datastreams {
d.SetAllLinks(externalURL)
}
}
// SetSelfLink sets the self link for the entity
func (o *ObservedProperty) SetSelfLink(externalURL string) {
o.NavSelf = CreateEntitySelfLink(externalURL, EntityLinkObservedProperties.ToString(), o.ID)
}
// SetLinks sets the entity specific navigation links, empty string if linked(expanded) data is not nil
func (o *ObservedProperty) SetLinks(externalURL string) {
o.NavDatastreams = CreateEntityLink(o.Datastreams == nil, externalURL, EntityLinkObservedProperties.ToString(), EntityLinkDatastreams.ToString(), o.ID)
}
// GetSupportedEncoding returns the supported encoding tye for this entity
func (o ObservedProperty) GetSupportedEncoding() map[int]EncodingType {
return map[int]EncodingType{}
}