-
Notifications
You must be signed in to change notification settings - Fork 479
/
value_descriptor.go
104 lines (96 loc) · 3.31 KB
/
value_descriptor.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
/*******************************************************************************
* Copyright 2018 Dell Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*******************************************************************************/
package models
import (
"github.com/edgexfoundry/edgex-go/internal/pkg/db"
contract "github.com/edgexfoundry/go-mod-core-contracts/models"
"github.com/globalsign/mgo/bson"
)
// ValueDescriptor
//
// Deprecated: Mongo functionality is deprecated as of the Geneva release.
type ValueDescriptor struct {
Id bson.ObjectId `bson:"_id,omitempty"`
Uuid string `bson:"uuid"`
Created int64 `bson:"created"`
Description string `bson:"description,omitempty"`
Modified int64 `bson:"modified"`
Origin int64 `bson:"origin"`
Name string `bson:"name"`
Min interface{} `bson:"min,omitempty"`
Max interface{} `bson:"max,omitempty"`
DefaultValue interface{} `bson:"defaultValue,omitempty"`
Type string `bson:"type,omitempty"`
UomLabel string `bson:"uomLabel,omitempty"`
Formatting string `bson:"formatting,omitempty"`
Labels []string `bson:"labels,omitempty"`
MediaType string `bson:"mediaType,omitempty"`
FloatEncoding string `bson:"floatEncoding,omitempty"`
}
func (v *ValueDescriptor) ToContract() contract.ValueDescriptor {
// Always hand back the UUID as the contract event ID unless it's blank (an old event, for example blackbox test scripts)
id := v.Uuid
if id == "" {
id = v.Id.Hex()
}
to := contract.ValueDescriptor{
Id: id,
Created: v.Created,
Description: v.Description,
Modified: v.Modified,
Origin: v.Origin,
Name: v.Name,
Min: v.Min,
Max: v.Max,
DefaultValue: v.DefaultValue,
Type: v.Type,
UomLabel: v.UomLabel,
Formatting: v.Formatting,
Labels: []string{},
MediaType: v.MediaType,
FloatEncoding: v.FloatEncoding,
}
for _, l := range v.Labels {
to.Labels = append(to.Labels, l)
}
return to
}
func (v *ValueDescriptor) FromContract(from contract.ValueDescriptor) (id string, err error) {
v.Id, v.Uuid, err = fromContractId(from.Id)
if err != nil {
return
}
v.Created = from.Created
v.Description = from.Description
v.Modified = from.Modified
v.Origin = from.Origin
v.Name = from.Name
v.Min = from.Min
v.Max = from.Max
v.DefaultValue = from.DefaultValue
v.Type = from.Type
v.UomLabel = from.UomLabel
v.Formatting = from.Formatting
v.Labels = []string{}
v.MediaType = from.MediaType
v.FloatEncoding = from.FloatEncoding
for _, l := range from.Labels {
v.Labels = append(v.Labels, l)
}
if v.Created == 0 {
v.Created = db.MakeTimestamp()
}
id = toContractId(v.Id, v.Uuid)
return
}