Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #158

Merged
merged 7 commits into from
Nov 10, 2023
Merged
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
1 change: 0 additions & 1 deletion pkg/bpmn_engine/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func (a activityCommand) Type() commandType {
// ---------------------------------------------------------------------

type continueActivityCommand struct {
sourceId string
activity activity
originActivity activity
}
Expand Down
1 change: 1 addition & 0 deletions pkg/bpmn_engine/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bpmn_engine

import (
"fmt"

"github.com/nitram509/lib-bpmn-engine/pkg/spec/BPMN20"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/bpmn_engine/conditions_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package bpmn_engine

import (
"testing"

"github.com/corbym/gocrest/has"
"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
"testing"
)

func Test_exclusive_gateway_with_expressions_selects_one_and_not_the_other(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/bpmn_engine/engine_fork_join_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package bpmn_engine

import (
"testing"

"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
"testing"
)

func TestForkUncontrolledJoin(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/bpmn_engine/engine_properties.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package bpmn_engine

import (
"sort"

"github.com/bwmarrin/snowflake"
"github.com/nitram509/lib-bpmn-engine/pkg/bpmn_engine/exporter"
"github.com/nitram509/lib-bpmn-engine/pkg/spec/BPMN20"
"sort"
)

type BpmnEngineState struct {
Expand Down
7 changes: 4 additions & 3 deletions pkg/bpmn_engine/engine_properties_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package bpmn_engine

import (
"github.com/corbym/gocrest/has"
"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
"os"
"strings"
"testing"

"github.com/corbym/gocrest/has"
"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
)

func Test_FindProcessInstance_ComfortFunction_ReturnsNilIfNoInstanceFound(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/bpmn_engine/engine_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package bpmn_engine

import (
"github.com/corbym/gocrest/has"
"testing"
"time"

"github.com/corbym/gocrest/has"

"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/bpmn_engine/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package bpmn_engine

import (
"fmt"
"github.com/nitram509/lib-bpmn-engine/pkg/spec/BPMN20"
"time"

"github.com/nitram509/lib-bpmn-engine/pkg/spec/BPMN20"
)

type MessageSubscription struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/bpmn_engine/events_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package bpmn_engine

import (
"testing"

"github.com/corbym/gocrest/has"
"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
"testing"
)

func Test_creating_a_process_sets_state_to_READY(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/bpmn_engine/expressions.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package bpmn_engine

import (
"strings"

"github.com/antonmedv/expr"
"github.com/nitram509/lib-bpmn-engine/pkg/bpmn_engine/var_holder"
"github.com/nitram509/lib-bpmn-engine/pkg/spec/BPMN20/extensions"
"strings"
)

func evaluateExpression(expression string, variableContext map[string]interface{}) (interface{}, error) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/bpmn_engine/jobs.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package bpmn_engine

import (
"github.com/nitram509/lib-bpmn-engine/pkg/bpmn_engine/var_holder"
"time"

"github.com/nitram509/lib-bpmn-engine/pkg/bpmn_engine/var_holder"

"github.com/nitram509/lib-bpmn-engine/pkg/spec/BPMN20"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/bpmn_engine/jobs_activated.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package bpmn_engine

import (
"github.com/nitram509/lib-bpmn-engine/pkg/bpmn_engine/var_holder"
"time"

"github.com/nitram509/lib-bpmn-engine/pkg/bpmn_engine/var_holder"
)

// ActivatedJob is a struct to provide information for registered task handler
Expand Down
3 changes: 2 additions & 1 deletion pkg/bpmn_engine/key_gen.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package bpmn_engine

import (
"github.com/bwmarrin/snowflake"
"hash/adler32"
"os"

"github.com/bwmarrin/snowflake"
)

var globalIdGenerator *snowflake.Node = nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/bpmn_engine/links.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package bpmn_engine

import (
"fmt"
"strings"

"github.com/nitram509/lib-bpmn-engine/pkg/bpmn_engine/var_holder"
"github.com/nitram509/lib-bpmn-engine/pkg/spec/BPMN20"
"strings"
)

func (state *BpmnEngineState) handleIntermediateThrowEvent(process *ProcessInfo, instance *processInstanceInfo, ite BPMN20.TIntermediateThrowEvent, activity activity) (nextCommands []command) {
Expand All @@ -27,8 +28,7 @@ func (state *BpmnEngineState) handleIntermediateThrowEvent(process *ProcessInfo,
elementName: ite.Name,
}}
} else {
var element BPMN20.BaseElement
element = ice
var element BPMN20.BaseElement = ice
nextCommands = []command{activityCommand{
sourceId: ice.Id,
element: &element,
Expand Down
3 changes: 2 additions & 1 deletion pkg/bpmn_engine/links_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package bpmn_engine

import (
"testing"

"github.com/corbym/gocrest/has"
"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
"testing"
)

func Test_Link_events_are_thrown_and_caught_and_flow_continued(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions pkg/bpmn_engine/marshalling.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"

"github.com/nitram509/lib-bpmn-engine/pkg/bpmn_engine/var_holder"
"github.com/nitram509/lib-bpmn-engine/pkg/spec/BPMN20"
)
Expand Down Expand Up @@ -156,11 +157,11 @@ func (pii *processInstanceInfo) MarshalJSON() ([]byte, error) {
ProcessInstanceInfoAlias: (*ProcessInstanceInfoAlias)(pii),
}
for _, a := range pii.activities {
switch a.(type) {
switch activity := a.(type) {
case *gatewayActivity:
piia.ActivityAdapters = append(piia.ActivityAdapters, createGatewayActivityAdapter(a.(*gatewayActivity)))
piia.ActivityAdapters = append(piia.ActivityAdapters, createGatewayActivityAdapter(activity))
case *eventBasedGatewayActivity:
piia.ActivityAdapters = append(piia.ActivityAdapters, createEventBasedGatewayActivityAdapter(a.(*eventBasedGatewayActivity)))
piia.ActivityAdapters = append(piia.ActivityAdapters, createEventBasedGatewayActivityAdapter(activity))
default:
panic(fmt.Sprintf("[invariant check] missing activity adapter for the type %T", a))
}
Expand Down Expand Up @@ -243,7 +244,6 @@ func Unmarshal(data []byte) (BpmnEngineState, error) {
Msg: msg,
Err: err,
}
return state, err
}
}
}
Expand Down Expand Up @@ -299,11 +299,11 @@ func recoverProcessInstanceActivitiesPart1(pii *processInstanceInfo, adapter *pr
func recoverProcessInstanceActivitiesPart2(state *BpmnEngineState) {
for _, pi := range state.processInstances {
for _, a := range pi.activities {
switch a.(type) {
switch activity := a.(type) {
case *eventBasedGatewayActivity:
a.(*eventBasedGatewayActivity).element = BPMN20.FindBaseElementsById(&pi.ProcessInfo.definitions, (*a.Element()).GetId())[0]
activity.element = BPMN20.FindBaseElementsById(&pi.ProcessInfo.definitions, (*a.Element()).GetId())[0]
case *gatewayActivity:
a.(*gatewayActivity).element = BPMN20.FindBaseElementsById(&pi.ProcessInfo.definitions, (*a.Element()).GetId())[0]
activity.element = BPMN20.FindBaseElementsById(&pi.ProcessInfo.definitions, (*a.Element()).GetId())[0]
default:
panic(fmt.Sprintf("[invariant check] missing case for activity type=%T", a))
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/bpmn_engine/process_instance.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package bpmn_engine

import (
"github.com/nitram509/lib-bpmn-engine/pkg/bpmn_engine/var_holder"
"time"

"github.com/nitram509/lib-bpmn-engine/pkg/bpmn_engine/var_holder"
)

// FIXME: shall this be exported?
Expand Down
10 changes: 3 additions & 7 deletions pkg/bpmn_engine/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package bpmn_engine

import (
"fmt"
"time"

"github.com/nitram509/lib-bpmn-engine/pkg/spec/BPMN20"
"github.com/senseyeio/duration"
"time"
)

// Timer is created, when a process instance reaches a Timer Intermediate Message Event.
Expand Down Expand Up @@ -124,10 +125,5 @@ func findExistingTimerNotYetTriggered(state *BpmnEngineState, id string, instanc
}

func findDurationValue(ice BPMN20.TIntermediateCatchEvent) (duration.Duration, error) {
durationStr := &ice.TimerEventDefinition.TimeDuration.XMLText
if durationStr == nil {
return duration.Duration{}, newEngineErrorf("Can't find 'timeDuration' value for INTERMEDIATE_CATCH_EVENT with id=%s", ice.Id)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error message is lost

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

durationStr could never be nil, so that error never actually occured.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GodsBoss good catch, if durationStr can't be nil - but then we need to rewrite the if clause, to capture the case when the text is empty. The goal here is to capture required and missing input as early as possible and provide good error message to the user.
If you agree, would you please bring the check back?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nitram509 I'd rather have this PR only change cosmetics, not behaviour. If you wish I can remove that particular change.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point was rather to rework this change towards a fail fast check and not removing "dead code".
Don't worry, I will merge it and then bring back the change on my own ... that round trip is shorter.

}
d, err := duration.ParseISO8601(*durationStr)
return d, err
return duration.ParseISO8601(ice.TimerEventDefinition.TimeDuration.XMLText)
}
5 changes: 3 additions & 2 deletions pkg/bpmn_engine/timer_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package bpmn_engine

import (
"testing"
"time"

"github.com/corbym/gocrest/has"
"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
"testing"
"time"
)

func Test_EventBasedGateway_selects_path_where_timer_occurs(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/bpmn_engine/usertasks_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package bpmn_engine

import (
"testing"

"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
"testing"
)

func Test_user_tasks_can_be_handled(t *testing.T) {
Expand Down
11 changes: 0 additions & 11 deletions pkg/bpmn_engine/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,3 @@ func contains(strings []string, s string) bool {
}
return false
}

func remove(strings []string, s string) []string {
for i, aString := range strings {
if aString == s {
strings[i] = strings[0]
strings = strings[1:]
break
}
}
return strings
}
3 changes: 2 additions & 1 deletion pkg/bpmn_engine/xml_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"encoding/ascii85"
"encoding/hex"
"encoding/xml"
"github.com/nitram509/lib-bpmn-engine/pkg/spec/BPMN20"
"io"
"os"

"github.com/nitram509/lib-bpmn-engine/pkg/spec/BPMN20"
)

// LoadFromFile loads a given BPMN file by filename into the engine
Expand Down
3 changes: 2 additions & 1 deletion pkg/bpmn_engine/xml_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package bpmn_engine

import (
"fmt"
"testing"

"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
"testing"
)

const XmlTestString = `<?xml version="1.0" encoding="UTF-8"?><bpmn:process id="Simple_Task_Process" name="aName" isExecutable="true"></bpmn:process></xml>`
Expand Down
3 changes: 2 additions & 1 deletion pkg/spec/BPMN20/helper_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package BPMN20

import (
"testing"

"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
"testing"
)

func Test_no_expression_when_only_blanks(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions tests/marshalling_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package tests

import (
"os"
"testing"
"time"

"github.com/corbym/gocrest/has"
"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
"github.com/nitram509/lib-bpmn-engine/pkg/bpmn_engine"
"os"
"testing"
"time"
)

type CallPath struct {
Expand Down Expand Up @@ -238,8 +239,7 @@ func Test_Unmarshal_restores_processKey(t *testing.T) {
// when
bpmnEngine, err = bpmn_engine.Unmarshal(bytes)
then.AssertThat(t, err, is.Nil())
var processes []*bpmn_engine.ProcessInfo
processes = bpmnEngine.FindProcessesById("Simple_Task_Process")
processes := bpmnEngine.FindProcessesById("Simple_Task_Process")

// then
then.AssertThat(t, processes, has.Length(1))
Expand Down