Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/bpmn_engine/jobs_activated.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ type ActivatedJob interface {
// Variable from the process instance's variable context
Variable(key string) interface{}

// Variables from the process instance's variable context
Variables() map[string]interface{}

// SetVariable in the variables context of the given process instance
SetVariable(key string, value interface{})

Expand Down Expand Up @@ -108,6 +111,11 @@ func (aj *activatedJob) Variable(key string) interface{} {
return aj.variableHolder.GetVariable(key)
}

// Variables implements ActivatedJob
func (aj *activatedJob) Variables() map[string]interface{} {
return aj.variableHolder.Variables()
}

// SetVariable implements ActivatedJob
func (aj *activatedJob) SetVariable(key string, value interface{}) {
aj.variableHolder.SetVariable(key, value)
Expand Down
14 changes: 14 additions & 0 deletions pkg/bpmn_engine/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/corbym/gocrest/has"
"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
"github.com/nitram509/lib-bpmn-engine/pkg/spec/BPMN20"
)

const (
Expand Down Expand Up @@ -44,6 +45,19 @@ func Test_a_job_can_fail_and_keeps_the_instance_in_active_state(t *testing.T) {
then.AssertThat(t, instance.State, is.EqualTo(Active))
}

func Test_a_job_can_fail_and_keeps_the_instance_in_active_state_for_set_matcher(t *testing.T) {
// setup
bpmnEngine := New()
process, _ := bpmnEngine.LoadFromFile("../../test-cases/simple_task.bpmn")
bpmnEngine.NewTaskHandler().SetMatcher(func(element *BPMN20.TaskElement) bool {
return (*element).GetId() == "id"
}, taskHandlerForId).Handler(jobFailHandler)

instance, _ := bpmnEngine.CreateAndRunInstance(process.ProcessKey, nil)

then.AssertThat(t, instance.State, is.EqualTo(Active))
}

// Test_simple_count_loop requires correct Task-Output-Mapping in the BPMN file
func Test_simple_count_loop(t *testing.T) {
// setup
Expand Down
10 changes: 10 additions & 0 deletions pkg/bpmn_engine/task_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type NewTaskHandlerCommand1 interface {
// For the handler you can specify one or more groups.
// If at least one matches a given user task, the handler will be called.
CandidateGroups(groups ...string) NewTaskHandlerCommand2

// Assignee defines a handler for a User Task with custom rules;
SetMatcher(matcher func(element *BPMN20.TaskElement) bool, handlerType string) NewTaskHandlerCommand2
}

// NewTaskHandler registers a handler function to be called for service tasks with a given taskId
Expand Down Expand Up @@ -111,6 +114,13 @@ func (thc newTaskHandlerCommand) CandidateGroups(groups ...string) NewTaskHandle
return thc
}

// SetMatcher implements NewTaskHandlerCommand2
func (thc newTaskHandlerCommand) SetMatcher(matcher func(element *BPMN20.TaskElement) bool, handlerType string) NewTaskHandlerCommand2 {
thc.matcher = matcher
thc.handlerType = taskHandlerType(handlerType)
return thc
}

func (state *BpmnEngineState) findTaskHandler(element *BPMN20.TaskElement) func(job ActivatedJob) {
searchOrder := []taskHandlerType{taskHandlerForId}
if (*element).GetType() == BPMN20.ServiceTask {
Expand Down