-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hierarchy.go
56 lines (50 loc) · 2.13 KB
/
Hierarchy.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
package tm1go
type Hierarchy struct {
Name string `json:"Name"`
UniqueName string `json:"UniqueName,omitempty"`
Elements []Element `json:"Elements,omitempty"`
Edges []Edge `json:"Edges,omitempty"`
Visible bool `json:"Visible,omitempty"`
Cardinality int `json:"Cardinality,omitempty"`
Attributes map[string]interface{} `json:"Attributes,omitempty"`
Dimension Dimension `json:"Dimension,omitempty"`
Subsets []Subset `json:"Subset,omitempty"`
PrivateSubsets []Subset `json:"PrivateSubsets,omitempty"`
SessionSubsets []Subset `json:"SessionSubsets,omitempty"`
Members []Member `json:"Members,omitempty"`
AllMember []Member `json:"AllMember,omitempty"`
DefaultMember Member `json:"DefaultMember,omitempty"`
Levels []Level `json:"Levels,omitempty"`
ElementAttributes []ElementAttribute `json:"ElementAttributes,omitempty"`
}
func (h *Hierarchy) getBody(includeElementAttributes bool) (map[string]interface{}, error) {
bodyAsDict := make(map[string]interface{})
bodyAsDict["Name"] = h.Name
if h.Elements != nil && len(h.Elements) > 0 {
elements := make([]map[string]interface{}, 0)
for _, element := range h.Elements {
elementBody, err := element.getBody()
if err != nil {
return nil, err
}
elements = append(elements, elementBody)
}
bodyAsDict["Elements"] = elements
}
if h.Edges != nil && len(h.Edges) > 0 {
edges := make([]map[string]interface{}, 0)
for _, edge := range h.Edges {
edgeAsDict := map[string]interface{}{
"ParentName": edge.ParentName,
"ComponentName": edge.ComponentName,
"Weight": edge.Weight,
}
edges = append(edges, edgeAsDict)
}
bodyAsDict["Edges"] = edges
}
if includeElementAttributes && h.ElementAttributes != nil && len(h.ElementAttributes) > 0 {
bodyAsDict["ElementAttributes"] = h.ElementAttributes
}
return bodyAsDict, nil
}