bzinchenko / bpmnview

Viewing and printing business process diagrams in a popular BPMN format
MIT License
92 stars 31 forks source link

How to add a sequence flow (edge) to a subprocess? #15

Open dan18ro opened 5 years ago

dan18ro commented 5 years ago

Hi, I am trying to create an exporter to BPMN format using BPMN.Sharp library.When I try to add a sequence flow to a subprocess, I get the flow added to the parent Process and not in the subprocess.

_editor.AddFlow(
                parentId,
                string.Empty,
                fromNode.Id,
                toNode.Id,
                null,
                type,
                null,
                false,
                FlowDirection.None);

where parentId is the Id of the SubProcess. Can you please lend me a hand here?

Thank you.

bzinchenko commented 5 years ago

Hello Is it possible to have full code fragment? We will run it in debugger and will find out.

dan18ro commented 5 years ago

Hello,

Here is a simplified extracted code example. TestApp.zip Please don't take the coordinates and sizes into consideration they are just "thrown" in there.

Thank you. Looking forward to your answer and help :)

dan18ro commented 5 years ago

Hi Boris,

Did you have a chance to take a look at my test application? Do you have any hints or suggestions?

Thank you,

Dan

On Fri, Sep 27, 2019 at 3:04 PM Boris Zinchenko notifications@github.com wrote:

Hello Is it possible to have full code fragment? We will run it in debugger and will find out.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bzinchenko/bpmnview/issues/15?email_source=notifications&email_token=ANKKRHHNDO2IR5HHLL3QYQ3QLXZGTA5CNFSM4I3FD3W2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7YVWZY#issuecomment-535911271, or mute the thread https://github.com/notifications/unsubscribe-auth/ANKKRHF35RVAMQOXMVQDSNDQLXZGTANCNFSM4I3FD3WQ .

bzinchenko commented 5 years ago

Hello

Attribution of edge to certain process or sub-process is not trivial. It can be an edge between two processes or inside a process or sub-process. Edge type also radically impacts the result. I see certain misfit that FlowDirection.None while a flow should be normally directed.

You must check that source and target elements of the model do belong to sub-process. Further, you must ensure and ID of this sub-process is passed as parentId parameter. Then it should work properly. I had a review of the code but not sure that I traced all conditions properly.

dan18ro commented 5 years ago

Hello,

Thank you for your response. Please ignore my previous message (I didn't noticed that the SubProcess was not there anymore).

I have tried your suggestions:

  1. Edge is, now, directed
  2. Both, source and target elements (tasks) are inside the subprocess.
  3. The Sequence flow is added to the editor with parentId equal to subprocess Id( but it is still added to the Parent process).

Is there any available documentation of the BPMN.Sharp library? Thank you

bzinchenko commented 5 years ago

Hello

We are glad it worked.

We often receive requests for documentation on BPMN.Sharp library. However, we consider such documentation not strictly necessary. Most issues, which users have with the library, are due to their confusion on BPMN standard. BPMN.Sharp library strictly complies to all aspects of BPMN 2.0 as confirmed by tests published on OMG site and it usage in a number of commercial products. Parameters for most function calls exactly replicate respective attributes of BPMN elements described in OMG specification.

To clarify details on calling specific functions, it is enough to read respective chapters of BPMN reference on OMG site: http://www.bpmn.org/ , https://www.omg.org/spec/BPMN/2.0/About-BPMN/

Instead of reading BPMN documentation, users expect that we will provide some small magic document to make things simple. We cannot do it simply because we support all aspects of BPMN standard, which can be quite versatile and complex in general case.

dan18ro commented 5 years ago

Hi Boris,

As I previously mentioned, I was wrong to think it was working. Unfortunately, it's not. The problem is that the Flow is added to the parent and not to the sub-process. All the conditions that you specified are respected... but... it still goes to the parent...

Please, have a look at the TestApp.zip I attached previously.

On Tue, Oct 1, 2019 at 1:31 PM Boris Zinchenko notifications@github.com wrote:

Hello

We are glad it worked.

We often receive requests for documentation on BPMN.Sharp library. However, we consider such documentation not strictly necessary. Most issues, which users have with the library, are due to their confusion on BPMN standard. BPMN.Sharp library strictly complies to all aspects of BPMN 2.1 as confirmed by tests published on OMG site and it usage in a number of commercial products. Parameters for most function calls exactly replicate respective attributes of BPMN elements described in OMG specification.

To clarify details on calling specific functions, it is enough to read respective chapters of BPMN reference on OMG site: http://www.bpmn.org/ , https://www.omg.org/spec/BPMN/2.0/About-BPMN/

Instead of reading BPMN documentation, users expect that we will provide some small magic document to make things simple. We cannot do it simply because we support all aspects of BPMN standard, which can be quite versatile and complex in general case.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bzinchenko/bpmnview/issues/15?email_source=notifications&email_token=ANKKRHG62ETU6P6YXYLVAHTQMMRHHA5CNFSM4I3FD3W2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAAZPBY#issuecomment-536975239, or mute the thread https://github.com/notifications/unsubscribe-auth/ANKKRHC6QL6G4ROBVU5ENJTQMMRHHANCNFSM4I3FD3WQ .

bzinchenko commented 5 years ago

Hello

I see. I will have deeper look in the code when time allows.

Important aspect. All elements to model must be added before you add any edges. This is because edges must reference already existing elements. It is evident but still worth mentioning.

Logic for adding edge is as follows.

  1. Find processes for source and target elements.
  2. If processes coincide, then edge belongs to this process.
  3. Use parentId as process ID.
  4. If ID not found, use default process as parent.

Hope it helps.

dan18ro commented 5 years ago

Hello,

Thank you for taking time to investigating this issue.

  1. Having the source and target elements correctly added in the sub-process
    • checked :)
  2. SequenceFlow... outside :))

Here is the result file:

On Tue, Oct 1, 2019 at 1:58 PM Boris Zinchenko notifications@github.com wrote:

Hello

I see. I will have deeper look in the code when time allows.

Important aspect. All elements to model must be added before you add any edges. This is because edges must reference already existing elements. It is evident but still worth mentioning.

Logic for adding edge is as follows.

  1. Find processes for source and target elements.
  2. If processes coincide, then edge belongs to this process.
  3. Use parentId as process ID.
  4. If ID not found, use default process as parent.

Hope it helps.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bzinchenko/bpmnview/issues/15?email_source=notifications&email_token=ANKKRHGCJ7WPXHIVGGDR6ZLQMMUMTA5CNFSM4I3FD3W2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAA3Q6Q#issuecomment-536983674, or mute the thread https://github.com/notifications/unsubscribe-auth/ANKKRHGAYGGEBMHEWBDRNBDQMMUMTANCNFSM4I3FD3WQ .

bzinchenko commented 5 years ago

Hello

I went through your code and found the following

            var process = _helper.AddProcess("TestProcess");
            var pool = _helper.AddPool(process, "Pool");
            var loop = _helper.AddLoop(process, "Loop");
            var act1 = _helper.AddActivity("test act", loop);
            var act2 = _helper.AddActivity("test 2", loop);
            var edge = _helper.AddFlow(loop, act1, act2, FlowType.Sequence);

I suppose the error is on these lines

            var act1 = _helper.AddActivity("test act", loop);
            var act2 = _helper.AddActivity("test 2", loop);
            var edge = _helper.AddFlow(loop, act1, act2, FlowType.Sequence);

You are trying to add activities and edges to 'loop', which is not a process. Not being able to find absent process 'loop', editor adds elements to default process. If you pass your process ID in place of 'loop', it should work fine.

dan18ro commented 5 years ago

Hello,

Sorry for the late response, github didn't send me a notification. AddLoop() adds a subprocess to process. If I would add the edge to the process... it's the same behavior as I get now. Please run the code step-by-step .

Thank you

bzinchenko commented 5 years ago

Hello, We inspected the code and still cannot see where sub-process is created. We see only creation of respective shapes. It might be confusion between creation of shapes (visual elements) and sub-process (part of business logic). If you believe that you do create sub-process, please cite exact code lines. Thank you

dan18ro commented 5 years ago

Hello,

The AddLoop method is creating the subprocess in BPMNDrawer class line 55.

public string AddLoop(string parentId, string displayText) { return _editor.AddActivity( parentId, displayText, ActivityType.Process, ActivityMarker.Loop, TaskType.None, null); }

Thank you,

bzinchenko commented 5 years ago

Exactly. Where process is added here? It adds activity of type process: ActivityType.Process, NOT a process! Process is added by another function: AddProcess(). Then, you pass invalid Id of activity as an alleged process Id. Then process is not found and all elements are added to default process instead.

dan18ro commented 5 years ago

The process is provided by the parentId parameter which is created before by calling

var process = _helper.AddProcess("TestProcess"); this is the PROCESS var pool = _helper.AddPool(process, "Pool"); this creates a POOL
var loop = _helper.AddLoop(process, "Loop"); this creates a SubProcess activity with parent the process Id.

bzinchenko commented 5 years ago

var loop = _helper.AddLoop(process, "Loop"); This creates an activity of SubProcess type with parent the process Id. loop - is Id of activity, not a sub-process.

dan18ro commented 5 years ago

Ok, understood. Can you please fix the example, if you have the time? Thank you.

bzinchenko commented 5 years ago

Your question highlighted the fact that we currently do not have a function to create sub-process. There is only function AddProcess(). It adds another top level process, not sub-process. In most cases it must be OK. But we will think on extension to allow adding sub-processes also in next releases.

Regarding your example, we suggest that you add process and then pass it as parentId on loop creation and to all its elements also. It should fix the issue. We see no our error to fix.