-
Notifications
You must be signed in to change notification settings - Fork 0
/
NativeView.go
137 lines (122 loc) · 4.4 KB
/
NativeView.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
package tm1go
import (
"encoding/json"
"fmt"
)
type NativeView struct {
Type string `json:"@odata.type,omitempty"`
Cube Cube `json:"Cube,omitempty"`
Name string `json:"Name"`
Columns []struct {
Subset Subset `json:"Subset,omitempty"`
} `json:"Columns,omitempty"`
Rows []struct {
Subset Subset `json:"Subset,omitempty"`
} `json:"Rows,omitempty"`
Titles []struct {
Subset Subset `json:"Subset,omitempty"`
Selected Element `json:"Selected,omitempty"`
} `json:"Titles,omitempty"`
SuppressEmptyColumns bool `json:"SuppressEmptyColumns,omitempty"`
SuppressEmptyRows bool `json:"SuppressEmptyRows,omitempty"`
FormatString string `json:"FormatString,omitempty"`
}
func (v *NativeView) GetType() string {
return v.Type
}
func (v *NativeView) GetName() string {
return v.Name
}
func (v *NativeView) getBody(static bool) (string, error) {
type subsetBody struct {
Name string `json:"Name"`
Alias string `json:"Alias,omitempty"`
Hierarchy string `json:"Hierarchy@odata.bind"`
Elements []string `json:"Elements@odata.bind,omitempty"`
Expression string `json:"Expression,omitempty"`
ExpandAbove bool `json:"ExpandAbove,omitempty"`
}
type axisBody struct {
Subset subsetBody `json:"Subset"`
Selected string `json:"Selected@odata.bind,omitempty"`
}
type nativeViewBody struct {
Type string `json:"@odata.type"`
Name string `json:"Name"`
Columns []axisBody `json:"Columns"`
Rows []axisBody `json:"Rows"`
Titles []axisBody `json:"Titles,omitempty"`
}
body := nativeViewBody{
Name: v.Name,
Type: v.Type,
}
body.Columns = make([]axisBody, 0)
for _, column := range v.Columns {
columnBody := axisBody{
Subset: subsetBody{
Name: column.Subset.Name,
Alias: column.Subset.Alias,
Hierarchy: fmt.Sprintf("Dimensions('%s')/Hierarchies('%s')", column.Subset.Hierarchy.Dimension.Name, column.Subset.Hierarchy.Name),
ExpandAbove: column.Subset.ExpandAbove,
},
}
if len(column.Subset.Elements) > 0 && static {
elementsBind := make([]string, len(column.Subset.Elements))
for i, element := range column.Subset.Elements {
elementsBind[i] = fmt.Sprintf("Dimensions('%s')/Hierarchies('%s')/Elements('%s')", column.Subset.Hierarchy.Dimension.Name, column.Subset.Hierarchy.Name, element.Name)
}
columnBody.Subset.Elements = elementsBind
} else {
columnBody.Subset.Expression = column.Subset.Expression
}
body.Columns = append(body.Columns, columnBody)
}
body.Rows = make([]axisBody, 0)
for _, row := range v.Rows {
rowBody := axisBody{
Subset: subsetBody{
Name: row.Subset.Name,
Alias: row.Subset.Alias,
Hierarchy: fmt.Sprintf("Dimensions('%s')/Hierarchies('%s')", row.Subset.Hierarchy.Dimension.Name, row.Subset.Hierarchy.Name),
ExpandAbove: row.Subset.ExpandAbove,
},
}
if len(row.Subset.Elements) > 0 && static {
elementsBind := make([]string, len(row.Subset.Elements))
for i, element := range row.Subset.Elements {
elementsBind[i] = fmt.Sprintf("Dimensions('%s')/Hierarchies('%s')/Elements('%s')", row.Subset.Hierarchy.Dimension.Name, row.Subset.Hierarchy.Name, element.Name)
}
rowBody.Subset.Elements = elementsBind
} else {
rowBody.Subset.Expression = row.Subset.Expression
}
body.Rows = append(body.Rows, rowBody)
}
body.Titles = make([]axisBody, 0)
for _, title := range v.Titles {
titleBody := axisBody{
Subset: subsetBody{
Name: title.Subset.Name,
Alias: title.Subset.Alias,
Hierarchy: fmt.Sprintf("Dimensions('%s')/Hierarchies('%s')", title.Subset.Hierarchy.Dimension.Name, title.Subset.Hierarchy.Name),
},
}
if len(title.Subset.Elements) > 0 && static {
elementsBind := make([]string, len(title.Subset.Elements))
for i, element := range title.Subset.Elements {
elementsBind[i] = fmt.Sprintf("Dimensions('%s')/Hierarchies('%s')/Elements('%s')", title.Subset.Hierarchy.Dimension.Name, title.Subset.Hierarchy.Name, element.Name)
}
titleBody.Subset.Elements = elementsBind
} else {
titleBody.Subset.Expression = title.Subset.Expression
}
titleBody.Selected = fmt.Sprintf("Dimensions('%s')/Hierarchies('%s')/Elements('%s')", title.Selected.Hierarchy.Dimension.Name, title.Selected.Hierarchy.Name, title.Selected.Name)
body.Titles = append(body.Titles, titleBody)
}
jsonData, err := json.Marshal(body)
if err != nil {
return "", err
}
return string(jsonData), nil
}