Skip to content

Commit d87b2c2

Browse files
author
Frank Martinez
authored
Merge pull request #38 from lixingwang/otherwise-link
support otherwise branch
2 parents 3e21b7f + 1692989 commit d87b2c2

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

definition/definition.go

+3
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ const (
260260

261261
// LtError denotes an error link
262262
LtError LinkType = 3
263+
264+
// LtOtherwise denotes an otherwise link
265+
LtOtherwise = 4
263266
)
264267

265268
// LinkOld is the object that describes the definition of

definition/definition_ser.go

+2
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ func createLink(tasks map[string]*Task, linkRep *LinkRep, id int, ef expression.
361361
link.linkType = LtLabel
362362
case "error", "3":
363363
link.linkType = LtError
364+
case "otherwise", "4":
365+
link.linkType = LtOtherwise
364366
default:
365367
//todo get the flow logger
366368
log.RootLogger().Warnf("Unsupported link type '%s', using default link")

model/simple/taskbehavior.go

+18
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ func (tb *TaskBehavior) Done(ctx model.TaskContext) (notifyFlow bool, taskEntrie
144144
logger.Debugf("Task '%s' has %d outgoing links", ctx.Task().ID(), numLinks)
145145
}
146146

147+
var linkFollowed bool
148+
var otherwiseLinkInst model.LinkInstance
147149
for _, linkInst := range linkInsts {
148150

149151
follow := true
@@ -153,6 +155,11 @@ func (tb *TaskBehavior) Done(ctx model.TaskContext) (notifyFlow bool, taskEntrie
153155
continue
154156
}
155157

158+
if linkInst.Link().Type() == definition.LtOtherwise {
159+
otherwiseLinkInst = linkInst
160+
continue
161+
}
162+
156163
if linkInst.Link().Type() == definition.LtExpression {
157164
//todo handle error
158165
if logger.DebugEnabled() {
@@ -166,6 +173,7 @@ func (tb *TaskBehavior) Done(ctx model.TaskContext) (notifyFlow bool, taskEntrie
166173
}
167174

168175
if follow {
176+
linkFollowed = true
169177
linkInst.SetStatus(model.LinkStatusTrue)
170178

171179
if logger.DebugEnabled() {
@@ -181,6 +189,16 @@ func (tb *TaskBehavior) Done(ctx model.TaskContext) (notifyFlow bool, taskEntrie
181189
}
182190
}
183191

192+
//Otherwise branch while no link to follow
193+
if !linkFollowed && otherwiseLinkInst != nil {
194+
otherwiseLinkInst.SetStatus(model.LinkStatusTrue)
195+
if logger.DebugEnabled() {
196+
logger.Debugf("Task '%s': Following Link to task '%s'", ctx.Task().ID(), otherwiseLinkInst.Link().ToTask().ID())
197+
}
198+
taskEntry := &model.TaskEntry{Task: otherwiseLinkInst.Link().ToTask()}
199+
taskEntries = append(taskEntries, taskEntry)
200+
}
201+
184202
//continue on to successor tasks
185203
return false, taskEntries, nil
186204
}

0 commit comments

Comments
 (0)