diff --git a/.github/workflows/gotest.yaml b/.github/workflows/gotest.yaml new file mode 100644 index 0000000..e28c0bf --- /dev/null +++ b/.github/workflows/gotest.yaml @@ -0,0 +1,14 @@ +name: Go Test +on: + push: + branches: ["main", "dev"] + pull_request: + branches: ["main"] +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.21 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..71d1449 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +*.code-workspace \ No newline at end of file diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..27ccb0d --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,69 @@ +linters-settings: + govet: + check-shadowing: true + settings: + printf: + funcs: + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + gocyclo: + min-complexity: 50 + maligned: + suggest-new: true + dupl: + threshold: 100 + goconst: + min-len: 2 + min-occurrences: 2 + misspell: + locale: US + revive: + confidence: 0.8 + lll: + line-length: 160 + # tab width in spaces. Default to 1. + tab-width: 1 + funlen: + lines: 150 + statements: 80 + +linters: + # please, do not use `enable-all`: it's deprecated and will be removed soon. + # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint + disable-all: true + enable: + - errcheck + - funlen + - goconst + - gocyclo + - gosec + - gosimple + - govet + - ineffassign + - lll + - misspell + - revive + - staticcheck + - typecheck + - unconvert + - unparam + - unused + + # don't enable: + # - gochecknoglobals + # - gocognit + # - godox + # - maligned + # - prealloc + +run: + skip-dirs: [] + # - test/testdata_etc + skip-files: + - ".*_test\\.go$" + +issues: + exclude-rules: [] + # \ No newline at end of file diff --git a/README.md b/README.md index b3ffae2..457eba3 100644 --- a/README.md +++ b/README.md @@ -1 +1,24 @@ -# gobpmnCounter \ No newline at end of file +# gobpmnCounter + +gobpmnCounter is a tool for counting the elements, shapes and egdes present in a process + +## Wiki + +The [documentation](https://github.com/deemount/gobpmnCounter/wiki) is now written in the wiki of the respective module + +**Start here** [gobpmn](https://github.com/deemount/gobpmn) + +## Testing + +You can also test the idea behind it directly. Simply follow the link to the lab + ++ [gobpmnLab](https://github.com/deemount/gobpmnLab) + +## Further Links + ++ [gobpmnTypes](https://github.com/deemount/gobpmnTypes) ++ [gobpmnModels](https://github.com/deemount/gobpmnModels) ++ [gobpmnCamunda](https://github.com/deemount/gobpmnCamunda) ++ [gobpmnDiagram](https://github.com/deemount/gobpmnDiagram) ++ [gobpmnBuilder](https://github.com/deemount/gobpmnBuilder) ++ [gobpmnReflection](https://github.com/deemount/gobpmnReflection) diff --git a/counter.go b/counter.go new file mode 100644 index 0000000..91c9e60 --- /dev/null +++ b/counter.go @@ -0,0 +1,101 @@ +package gobpmn_counter + +import ( + "strings" + + "github.com/deemount/gobpmnCounter/internals/utils" +) + +// Count ... +type Count struct { + Process int + Participant int + Message int + StartEvent int + EndEvent int + BusinessRuleTask int + ManualTask int + ReceiveTask int + ScriptTask int + SendTask int + ServiceTask int + Task int + UserTask int + Flow int + Shape int + Edge int +} + +/* + * @Base + */ + +// countPool ... +func (c *Count) countPool(field, reflectionField string) { + if strings.ToLower(field) == "pool" { + if strings.Contains(reflectionField, "Process") { + c.Process++ + } + if strings.Contains(reflectionField, "ID") { + c.Participant++ + c.Shape++ + } + } +} + +// countMessage ... +func (c *Count) countMessage(field, reflectionField string) { + if strings.ToLower(field) == "message" { + if strings.Contains(reflectionField, "Message") { + c.Message++ + c.Edge++ + } + } +} + +/* + * @Processes + */ + +// countProcess ... +func (c *Count) countProcess(field string) { + if strings.Contains(field, "Process") { + c.Process++ + } +} + +/* + * @Elements + */ + +func (c *Count) countElements(field string) { + + if utils.After(field, "From") == "" { + + switch true { + case strings.Contains(field, "StartEvent"): + c.StartEvent++ + case strings.Contains(field, "EndEvent"): + c.EndEvent++ + case strings.Contains(field, "BusinessRuleTask"): + c.BusinessRuleTask++ + case strings.Contains(field, "ManualTask"): + c.ManualTask++ + case strings.Contains(field, "ReceiveTask"): + c.ReceiveTask++ + case strings.Contains(field, "ScriptTask"): + c.ScriptTask++ + case strings.Contains(field, "SendTask"): + c.SendTask++ + case strings.Contains(field, "ServiceTask"): + c.ServiceTask++ + case strings.Contains(field, "Task"): + c.Task++ + case strings.Contains(field, "UserTask"): + c.UserTask++ + } + + c.Shape++ + + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..93db061 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/deemount/gobpmnCounter + +go 1.21.7 + +require github.com/deemount/gobpmnReflection v0.0.0-20240309120253-66d26591856d diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..08d5c1a --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/deemount/gobpmnReflection v0.0.0-20240309120253-66d26591856d h1:IW2e4maQjHymwLuETWMtbWH/ndSj1tZaceZAJrF60G8= +github.com/deemount/gobpmnReflection v0.0.0-20240309120253-66d26591856d/go.mod h1:NhbSOQE5lfqYvNkZXsm6xWTq3Wpy5xBPaERNqM/0OgI= diff --git a/internals/utils/strings.go b/internals/utils/strings.go new file mode 100644 index 0000000..d4a960a --- /dev/null +++ b/internals/utils/strings.go @@ -0,0 +1,16 @@ +package utils + +import "strings" + +// After get substring after a string +func After(value string, a string) string { + pos := strings.LastIndex(value, a) + if pos == -1 { + return "" + } + adjustedPos := pos + len(a) + if adjustedPos >= len(value) { + return "" + } + return value[adjustedPos:] //len(value) +}