|
14 | 14 |
|
15 | 15 | package model
|
16 | 16 |
|
17 |
| -import ( |
18 |
| - "encoding/json" |
19 |
| -) |
20 |
| - |
21 | 17 | const (
|
22 | 18 | // StateTypeDelay ...
|
23 | 19 | StateTypeDelay = "delay"
|
@@ -50,10 +46,7 @@ func getActionsModelMapping(stateType string, s map[string]interface{}) (State,
|
50 | 46 | case StateTypeParallel:
|
51 | 47 | return &ParallelState{}, true
|
52 | 48 | case StateTypeSwitch:
|
53 |
| - if _, ok := s["dataConditions"]; ok { |
54 |
| - return &DataBasedSwitchState{}, true |
55 |
| - } |
56 |
| - return &EventBasedSwitchState{}, true |
| 49 | + return &SwitchState{}, true |
57 | 50 | case StateTypeInject:
|
58 | 51 | return &InjectState{}, true
|
59 | 52 | case StateTypeForEach:
|
@@ -135,200 +128,3 @@ func (s *BaseState) GetStateDataFilter() *StateDataFilter { return s.StateDataFi
|
135 | 128 |
|
136 | 129 | // GetMetadata ...
|
137 | 130 | func (s *BaseState) GetMetadata() *Metadata { return s.Metadata }
|
138 |
| - |
139 |
| -// BaseSwitchState ... |
140 |
| -type BaseSwitchState struct { |
141 |
| - BaseState |
142 |
| - // Default transition of the workflow if there is no matching data conditions. Can include a transition or end definition |
143 |
| - DefaultCondition DefaultCondition `json:"defaultCondition,omitempty"` |
144 |
| -} |
145 |
| - |
146 |
| -// EventBasedSwitchState Permits transitions to other states based on events |
147 |
| -type EventBasedSwitchState struct { |
148 |
| - BaseSwitchState |
149 |
| - // Defines conditions evaluated against events |
150 |
| - EventConditions []EventCondition `json:"eventConditions" validate:"required,min=1,dive"` |
151 |
| - // State specific timeouts |
152 |
| - Timeouts *EventBasedSwitchStateTimeout `json:"timeouts,omitempty"` |
153 |
| -} |
154 |
| - |
155 |
| -// UnmarshalJSON implementation for json Unmarshal function for the EventBasedSwitch type |
156 |
| -func (j *EventBasedSwitchState) UnmarshalJSON(data []byte) error { |
157 |
| - if err := json.Unmarshal(data, &j.BaseSwitchState); err != nil { |
158 |
| - return err |
159 |
| - } |
160 |
| - eventBasedSwitch := make(map[string]json.RawMessage) |
161 |
| - if err := json.Unmarshal(data, &eventBasedSwitch); err != nil { |
162 |
| - return err |
163 |
| - } |
164 |
| - |
165 |
| - eventBaseTimeoutsRawMessage, ok := eventBasedSwitch["timeouts"] |
166 |
| - if ok { |
167 |
| - if err := json.Unmarshal(eventBaseTimeoutsRawMessage, &j.Timeouts); err != nil { |
168 |
| - return err |
169 |
| - } |
170 |
| - } |
171 |
| - |
172 |
| - var rawConditions []json.RawMessage |
173 |
| - if err := json.Unmarshal(eventBasedSwitch["eventConditions"], &rawConditions); err != nil { |
174 |
| - return err |
175 |
| - } |
176 |
| - |
177 |
| - j.EventConditions = make([]EventCondition, len(rawConditions)) |
178 |
| - var mapConditions map[string]interface{} |
179 |
| - for i, rawCondition := range rawConditions { |
180 |
| - if err := json.Unmarshal(rawCondition, &mapConditions); err != nil { |
181 |
| - return err |
182 |
| - } |
183 |
| - var condition EventCondition |
184 |
| - if _, ok := mapConditions["end"]; ok { |
185 |
| - condition = &EndEventCondition{} |
186 |
| - } else { |
187 |
| - condition = &TransitionEventCondition{} |
188 |
| - } |
189 |
| - if err := json.Unmarshal(rawCondition, condition); err != nil { |
190 |
| - return err |
191 |
| - } |
192 |
| - j.EventConditions[i] = condition |
193 |
| - } |
194 |
| - |
195 |
| - return nil |
196 |
| -} |
197 |
| - |
198 |
| -// EventBasedSwitchStateTimeout ... |
199 |
| -type EventBasedSwitchStateTimeout struct { |
200 |
| - StateExecTimeout *StateExecTimeout `json:"stateExecTimeout,omitempty"` |
201 |
| - EventTimeout string `json:"eventTimeout,omitempty"` |
202 |
| -} |
203 |
| - |
204 |
| -// EventCondition ... |
205 |
| -type EventCondition interface { |
206 |
| - GetName() string |
207 |
| - GetEventRef() string |
208 |
| - GetEventDataFilter() EventDataFilter |
209 |
| - GetMetadata() Metadata |
210 |
| -} |
211 |
| - |
212 |
| -// BaseEventCondition ... |
213 |
| -type BaseEventCondition struct { |
214 |
| - // Event condition name |
215 |
| - Name string `json:"name,omitempty"` |
216 |
| - // References a unique event name in the defined workflow events |
217 |
| - EventRef string `json:"eventRef" validate:"required"` |
218 |
| - // Event data filter definition |
219 |
| - EventDataFilter EventDataFilter `json:"eventDataFilter,omitempty"` |
220 |
| - Metadata Metadata `json:"metadata,omitempty"` |
221 |
| -} |
222 |
| - |
223 |
| -// GetEventRef ... |
224 |
| -func (e *BaseEventCondition) GetEventRef() string { return e.EventRef } |
225 |
| - |
226 |
| -// GetEventDataFilter ... |
227 |
| -func (e *BaseEventCondition) GetEventDataFilter() EventDataFilter { return e.EventDataFilter } |
228 |
| - |
229 |
| -// GetMetadata ... |
230 |
| -func (e *BaseEventCondition) GetMetadata() Metadata { return e.Metadata } |
231 |
| - |
232 |
| -// GetName ... |
233 |
| -func (e *BaseEventCondition) GetName() string { return e.Name } |
234 |
| - |
235 |
| -// TransitionEventCondition Switch state data event condition |
236 |
| -type TransitionEventCondition struct { |
237 |
| - BaseEventCondition |
238 |
| - // Next transition of the workflow if there is valid matches |
239 |
| - Transition Transition `json:"transition" validate:"required"` |
240 |
| -} |
241 |
| - |
242 |
| -// EndEventCondition Switch state data event condition |
243 |
| -type EndEventCondition struct { |
244 |
| - BaseEventCondition |
245 |
| - // Explicit transition to end |
246 |
| - End End `json:"end" validate:"required"` |
247 |
| -} |
248 |
| - |
249 |
| -// DataBasedSwitchState Permits transitions to other states based on data conditions |
250 |
| -type DataBasedSwitchState struct { |
251 |
| - BaseSwitchState |
252 |
| - DataConditions []DataCondition `json:"dataConditions" validate:"required,min=1,dive"` |
253 |
| - Timeouts *DataBasedSwitchStateTimeout `json:"timeouts,omitempty"` |
254 |
| -} |
255 |
| - |
256 |
| -// UnmarshalJSON implementation for json Unmarshal function for the DataBasedSwitch type |
257 |
| -func (j *DataBasedSwitchState) UnmarshalJSON(data []byte) error { |
258 |
| - if err := json.Unmarshal(data, &j.BaseSwitchState); err != nil { |
259 |
| - return err |
260 |
| - } |
261 |
| - dataBasedSwitch := make(map[string]json.RawMessage) |
262 |
| - if err := json.Unmarshal(data, &dataBasedSwitch); err != nil { |
263 |
| - return err |
264 |
| - } |
265 |
| - if err := json.Unmarshal(data, &j.Timeouts); err != nil { |
266 |
| - return err |
267 |
| - } |
268 |
| - var rawConditions []json.RawMessage |
269 |
| - if err := json.Unmarshal(dataBasedSwitch["dataConditions"], &rawConditions); err != nil { |
270 |
| - return err |
271 |
| - } |
272 |
| - j.DataConditions = make([]DataCondition, len(rawConditions)) |
273 |
| - var mapConditions map[string]interface{} |
274 |
| - for i, rawCondition := range rawConditions { |
275 |
| - if err := json.Unmarshal(rawCondition, &mapConditions); err != nil { |
276 |
| - return err |
277 |
| - } |
278 |
| - var condition DataCondition |
279 |
| - if _, ok := mapConditions["end"]; ok { |
280 |
| - condition = &EndDataCondition{} |
281 |
| - } else { |
282 |
| - condition = &TransitionDataCondition{} |
283 |
| - } |
284 |
| - if err := json.Unmarshal(rawCondition, condition); err != nil { |
285 |
| - return err |
286 |
| - } |
287 |
| - j.DataConditions[i] = condition |
288 |
| - } |
289 |
| - return nil |
290 |
| -} |
291 |
| - |
292 |
| -// DataBasedSwitchStateTimeout ... |
293 |
| -type DataBasedSwitchStateTimeout struct { |
294 |
| - StateExecTimeout *StateExecTimeout `json:"stateExecTimeout,omitempty"` |
295 |
| -} |
296 |
| - |
297 |
| -// DataCondition ... |
298 |
| -type DataCondition interface { |
299 |
| - GetName() string |
300 |
| - GetCondition() string |
301 |
| - GetMetadata() Metadata |
302 |
| -} |
303 |
| - |
304 |
| -// BaseDataCondition ... |
305 |
| -type BaseDataCondition struct { |
306 |
| - // Data condition name |
307 |
| - Name string `json:"name,omitempty"` |
308 |
| - // Workflow expression evaluated against state data. Must evaluate to true or false |
309 |
| - Condition string `json:"condition" validate:"required"` |
310 |
| - Metadata Metadata `json:"metadata,omitempty"` |
311 |
| -} |
312 |
| - |
313 |
| -// GetName ... |
314 |
| -func (b *BaseDataCondition) GetName() string { return b.Name } |
315 |
| - |
316 |
| -// GetCondition ... |
317 |
| -func (b *BaseDataCondition) GetCondition() string { return b.Condition } |
318 |
| - |
319 |
| -// GetMetadata ... |
320 |
| -func (b *BaseDataCondition) GetMetadata() Metadata { return b.Metadata } |
321 |
| - |
322 |
| -// TransitionDataCondition ... |
323 |
| -type TransitionDataCondition struct { |
324 |
| - BaseDataCondition |
325 |
| - // Workflow transition if condition is evaluated to true |
326 |
| - Transition Transition `json:"transition" validate:"required"` |
327 |
| -} |
328 |
| - |
329 |
| -// EndDataCondition ... |
330 |
| -type EndDataCondition struct { |
331 |
| - BaseDataCondition |
332 |
| - // Workflow end definition |
333 |
| - End End `json:"end" validate:"required"` |
334 |
| -} |
0 commit comments