diff --git a/README.md b/README.md index d1465ce..8673c4d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ gobpmnCounter is a tool for counting the elements, shapes and egdes present in a ## Wiki -The [documentation](https://github.com/deemount/gobpmnCounter/wiki) is now written in the wiki of the respective module +Read the [documentation](https://github.com/deemount/gobpmnCounter/wiki) **Start here** [gobpmn](https://github.com/deemount/gobpmn) diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..d85340e --- /dev/null +++ b/doc.go @@ -0,0 +1 @@ +package gobpmn_counter diff --git a/go.mod b/go.mod index 85f69f1..cff4569 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/deemount/gobpmnCounter go 1.21.7 -require github.com/deemount/gobpmnReflection v0.0.0-20240311195407-66268668805a +require github.com/deemount/gobpmnReflection v0.0.0-20240315112013-036495e4c08d diff --git a/go.sum b/go.sum index 0004800..ab31cf0 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ github.com/deemount/gobpmnReflection v0.0.0-20240311195407-66268668805a h1:NSd968TGgWy0m8tPU+nxPzzWHkWpnGU1Hk9bHDJ/yhs= github.com/deemount/gobpmnReflection v0.0.0-20240311195407-66268668805a/go.mod h1:NhbSOQE5lfqYvNkZXsm6xWTq3Wpy5xBPaERNqM/0OgI= +github.com/deemount/gobpmnReflection v0.0.0-20240315112013-036495e4c08d h1:yQY4ikw/HuvVlPu3hGc0X8gntQnSbLqMnUw/nHRRCKU= +github.com/deemount/gobpmnReflection v0.0.0-20240315112013-036495e4c08d/go.mod h1:j8WCmdzEkTq/FVsWJAdoPtjTiRryLZp/WjOLcIqtt5c= diff --git a/quantities.go b/quantities.go index 6b92814..268ddab 100644 --- a/quantities.go +++ b/quantities.go @@ -8,13 +8,31 @@ import ( gobpmn_reflection "github.com/deemount/gobpmnReflection" ) -// Quantities ... +// Quantities holds all the quantities of the BPMN elements +// in the BPMN model. It is used to count the number of elements type Quantities struct { - Process int - Participant int - Message int - StartEvent int - EndEvent int + // How many processes are in the BPMN model + Process int + // How many participants are in the BPMN model + // This will be counted by the number of pools + Participant int + // How many messages are in the BPMN model + // This will be counted by the number of edges + // and if the string contains the word "Message" + Message int + // How many elements are in the BPMN model + ComplexGateway int + EventBasedGateway int + ExclusiveGateway int + InclusiveGateway int + ParallelGateway int + // How many events are in the BPMN model + BoundaryEvent int + EndEvent int + IntermediateCatchEvent int + IntermediateThrowEvent int + StartEvent int + // How many tasks are in the BPMN model BusinessRuleTask int ManualTask int ReceiveTask int @@ -23,19 +41,28 @@ type Quantities struct { ServiceTask int Task int UserTask int - Flow int - Shape int - Edge int - Words map[int][]string + // How many flows are in the BPMN model + // This will be counted by the number of edges + // and if the string contains a preposition, like + // "From" or "To" + Flow int + // How many shapes and edges are in the BPMN model + Shape int + Edge int + // How many words are in the BPMN model + Words map[int][]string } -// In ... +// In is a copy of the reflection package, but with the +// ability to count the number of elements in the BPMN model. func (q *Quantities) In(p interface{}) *Quantities { ref := gobpmn_reflection.New(p) ref.Interface().Allocate().Maps().Assign() switch true { + + // If the BPMN model is a pool and has embedded structs case len(ref.Anonym) > 0: for _, field := range ref.Anonym { n := ref.Temporary.FieldByName(field) @@ -49,6 +76,8 @@ func (q *Quantities) In(p interface{}) *Quantities { } } } + + // If the BPMN model is not a pool and has no embedded structs case len(ref.Anonym) == 0: for _, field := range ref.Rflct { q.countProcess(field) @@ -56,6 +85,7 @@ func (q *Quantities) In(p interface{}) *Quantities { } } + // Count the number of words in the BPMN model q.countWords() return q @@ -63,10 +93,19 @@ func (q *Quantities) In(p interface{}) *Quantities { } /* - * @private + * @pprivate */ -// countPool ... +// countPool counts the number of processes and participants in the BPMN model. +// A pool is structured as a process and has participants and messages. +// Ruleset: +// - If the field contains the word "Pool" and the reflection field contains the word "Process" +// then it is a process. +// - If the field contains the word "Pool" and the reflection field contains the word "ID" +// then it is a participant. +// +// Note: +// The word "Pool" is case insensitive. func (q *Quantities) countPool(field, reflectionField string) { if strings.ToLower(field) == "pool" { if strings.Contains(reflectionField, "Process") { @@ -96,16 +135,43 @@ func (q *Quantities) countProcess(field string) { } } -// countElements ... +// countElements counts all the elements in the BPMN model +// and increments the counter for each element. +// Ruleset: +// - If the field contains one of the words below and without the word "From" +// then it is an element. +// - If the field contains the word from one of the words below func (q *Quantities) countElements(field string) { if utils.After(field, "From") == "" { switch true { + + // events case strings.Contains(field, "StartEvent"): q.StartEvent++ + case strings.Contains(field, "BoundaryEvent"): + q.BoundaryEvent++ + case strings.Contains(field, "IntermediateCatchEvent"): + q.IntermediateCatchEvent++ + case strings.Contains(field, "IntermediateThrowEvent"): + q.IntermediateThrowEvent++ case strings.Contains(field, "EndEvent"): q.EndEvent++ + + // gateways + case strings.Contains(field, "ComplexGateway"): + q.ComplexGateway++ + case strings.Contains(field, "EventBasedGateway"): + q.EventBasedGateway++ + case strings.Contains(field, "ExclusiveGateway"): + q.ExclusiveGateway++ + case strings.Contains(field, "InclusiveGateway"): + q.InclusiveGateway++ + case strings.Contains(field, "ParallelGateway"): + q.ParallelGateway++ + + // tasks case strings.Contains(field, "BusinessRuleTask"): q.BusinessRuleTask++ case strings.Contains(field, "ManualTask"): @@ -122,8 +188,10 @@ func (q *Quantities) countElements(field string) { q.Task++ case strings.Contains(field, "UserTask"): q.UserTask++ + } + // each element in the switch has a shape q.Shape++ } diff --git a/quantities_test.go b/quantities_test.go new file mode 100644 index 0000000..2288b59 --- /dev/null +++ b/quantities_test.go @@ -0,0 +1 @@ +package gobpmn_counter_test