-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeRanges.go
176 lines (158 loc) · 5.81 KB
/
timeRanges.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package connect
import "encoding/json"
// @defgroup SUBGROUP4 Definitions
// TimeRangeType - @{
type TimeRangeType string
const (
TimeRangeDaily TimeRangeType = "TimeRangeDaily"
TimeRangeWeekly TimeRangeType = "TimeRangeWeekly"
TimeRangeAbsolute TimeRangeType = "TimeRangeAbsolute"
TimeRangeChildGroup TimeRangeType = "TimeRangeChildGroup" // not supported in QT
)
type UtcDateTime string
type DayType string
const (
Monday DayType = "Monday"
Tuesday DayType = "Tuesday"
Wednesday DayType = "Wednesday"
Thursday DayType = "Thursday"
Friday DayType = "Friday"
Saturday DayType = "Saturday"
Sunday DayType = "Sunday"
)
type DayList []DayType
type TimeRangeGroup struct {
Id KId `json:"id"`
Name string `json:"name"`
}
// Note: If type is changed, all fields representing the associated value must be also assigned, if used in set method.
// And conversely, type must be assigned if value was changed.
// TimeRangeEntry - type + (fromDay, toDay) + (fromDate, toDate) + childGroupId
type TimeRangeEntry struct {
Id KId `json:"id"`
GroupId KId `json:"groupId"`
SharedId KId `json:"sharedId"` // read-only; filled when the item is shared in MyKerio
GroupName string `json:"groupName"`
Description string `json:"description"`
Type TimeRangeType `json:"type"`
Enabled bool `json:"enabled"`
Status StoreStatus `json:"status"`
FromTime Time `json:"fromTime"` // This doesn't contain seconds, so we round data created by QT admin
ToTime Time `json:"toTime"` // This doesn't contain seconds, so we round data created by QT admin
Days DayList `json:"days"`
FromDay DayType `json:"fromDay"`
ToDay DayType `json:"toDay"`
FromDate Date `json:"fromDate"` // hour and min used from Time
ToDate Date `json:"toDate"` // hour and min used from Time
ChildGroupId KId `json:"childGroupId"`
ChildGroupName string `json:"childGroupName"`
}
type TimeRangeEntryList []TimeRangeEntry
type TimeRangeGroupList []TimeRangeGroup
// TimeRangesCreate - Create new ranges.
// Parameters
// ranges - details for new ranges. Field KiD is assigned by the manager to temporary value until apply() or reset().
// Return
// errors - possible errors: - "This time range already exists!" duplicate name-value
// result - list of IDs of created TimeRanges
func (s *ServerConnection) TimeRangesCreate(ranges TimeRangeEntryList) (ErrorList, CreateResultList, error) {
params := struct {
Ranges TimeRangeEntryList `json:"ranges"`
}{ranges}
data, err := s.CallRaw("TimeRanges.create", params)
if err != nil {
return nil, nil, err
}
errors := struct {
Result struct {
Errors ErrorList `json:"errors"`
Result CreateResultList `json:"result"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &errors)
return errors.Result.Errors, errors.Result.Result, err
}
// TimeRangesGet - Get the list of ranges.
// Parameters
// query - conditions and limits. Included from weblib. KWF engine implementation notes: - LIKE matches substring (second argument) in a string (first argument). There are no wildcards. - sort and match are case insensitive. - column alias (first operand):
// Return
// list - list of ranges and its details
// totalItems - count of all ranges on the server (before the start/limit applied)
func (s *ServerConnection) TimeRangesGet(query SearchQuery) (TimeRangeEntryList, int, error) {
query = addMissedParametersToSearchQuery(query)
params := struct {
Query SearchQuery `json:"query"`
}{query}
data, err := s.CallRaw("TimeRanges.get", params)
if err != nil {
return nil, 0, err
}
list := struct {
Result struct {
List TimeRangeEntryList `json:"list"`
TotalItems int `json:"totalItems"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &list)
return list.Result.List, list.Result.TotalItems, err
}
// TimeRangesGetGroupList - Get the list of groups, sorted in ascending order.
// Return
// groups - list of all groups
func (s *ServerConnection) TimeRangesGetGroupList() (TimeRangeGroupList, error) {
data, err := s.CallRaw("TimeRanges.getGroupList", nil)
if err != nil {
return nil, err
}
groups := struct {
Result struct {
Groups TimeRangeGroupList `json:"groups"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &groups)
return groups.Result.Groups, err
}
// TimeRangesRemove - Remove ranges.
// Parameters
// rangeIds - IDs of ranges that should be removed
// Return
// errors - Errors by removing ranges
func (s *ServerConnection) TimeRangesRemove(rangeIds KIdList) (ErrorList, error) {
params := struct {
RangeIds KIdList `json:"rangeIds"`
}{rangeIds}
data, err := s.CallRaw("TimeRanges.remove", params)
if err != nil {
return nil, err
}
errors := struct {
Result struct {
Errors ErrorList `json:"errors"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &errors)
return errors.Result.Errors, err
}
// TimeRangesSet - Set existing ranges.
// Parameters
// rangeIds - IDs of ranges to be updated.
// details - details for update. Field "KId" is ignored. All other fields must be filled in and they are written to all ranges specified by rangeIds.
// Return
// errors - possible errors: - "This time range already exists!" duplicate name-value
func (s *ServerConnection) TimeRangesSet(rangeIds KIdList, details TimeRangeEntry) (ErrorList, error) {
params := struct {
RangeIds KIdList `json:"rangeIds"`
Details TimeRangeEntry `json:"details"`
}{rangeIds, details}
data, err := s.CallRaw("TimeRanges.set", params)
if err != nil {
return nil, err
}
errors := struct {
Result struct {
Errors ErrorList `json:"errors"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &errors)
return errors.Result.Errors, err
}