Boolean conditional or conditional creation of participants or order priority of participants

0 votes
asked Jan 18 in Wanted features by mgrol (1,230 points)
edited Jan 18 by mgrol

Hi,

currently I work on an internal service repository defining macros for sequence diagrams that describe how services call subsequent other services. For that I need to automatically create participant for services if they are used.

 I tried to use the following, as there is no "real if" condition, such as !if boolean=true of !if boolean, but only  !ifdef MACRO:

'Definition of the participant
!ifndef PARTICIPANT_CREATED
    participant "P" as p #color
    !define PARTICIPANT_CREATED true
!endif

However, this doesn't work reliable. So sometimes plantuml generates the according participant automatically, which is a good behavior, but for me the color and the name of the participant are wrong.
If I always create a participant by "participant "P" as p #Red" the moment a service call would expect it. However the ordering of participants is often weird. Therefore, I would need either: 

  • a real boolean condition to check a flag

    • e.g. !if boolean=true or !if boolean/!ifn boolean

  • a conditional to check whether a participant was already create

  • a priority that I can attach to a participant which orders the participants

    • e.g. participant "P" as p order 10 #color

Is there any chance to get something like that?

Best Regards,

Michael

2 Answers

0 votes
answered Jan 18 by plantuml (141,890 points)
  • 1) Conditional to check wether a participant was already created :

This is really not possible. The preprocessor runs *before* any processing and parsing of the diagram.

  • 2) a priority that I can attach to a participant which orders the participants

This is possible and should be easy to implement

  • 3) a real boolean condition to check a flag

We need more information about what you are expecting. Are you looking for some variable definition ?
Something like:

!define MY_BOOLEAN=true
...
!if MY_BOOLEAN
...
!endif

That does not sound very different of what we have today ? So probably we miss the point here.

commented Jan 19 by mgrol (1,230 points)
Hi,

thanks for getting back.

* 1) I though so and this would be my least preferred option.

* 2) IMHO is this solution the most interesting as it also covers other feature requests made here to keep certain participants stick together put them close to each other.

* 3) It might be that I have a bug in my definitions. However, I currently can't figure it out and it is difficult to prepare a sample for that.  I have prepared a sample below that is similar to the setup I use today.

For the ordering I prepared the following setup to display the ordering problem:
* file application.puml:
___
@startuml
participant "App" as application #green
!include service.iuml
!include service2.iuml

' call 1st service
service_one(application)
' call 2nd directly
service_two(application)
'call 1st service again
service_one(application,"set of parameters")

@enduml
___

* file service.iuml:
' 1st Service(s)

!definelong service_one(CALLER="consumer", PARAM="parameter")
!ifdef SIMPLE
    note over CALLER: Simple service call with parameter
!else
    'Definition of the participant
    !ifndef PARTICIPANT_CREATED
        participant "P1" as p #red
        !define PARTICIPANT_CREATED true
    !endif
    CALLER -> p ++: request(PARAM)
    CALLER <-- p --: response
!endif
!enddefinelong
___

* file service2.iuml:
___
' 2nd service
!definelong service_two(CALLER="consumer")
!ifdef SIMPLE
    note over CALLER: yet another simple service call
!else
'Definition of the participant
    !ifndef PARTICIPANT_CREATED
        participant "P1" as p #orange
        !define PARTICIPANT_CREATED true
    !endif
    !ifndef PARTICIPANT2_CREATED
        participant "P2" as ptwo #orange
        !define PARTICIPANT2_CREATED true
    !endif
    CALLER -> ptwo ++: request
    CALLER <-- ptwo --: response
!endif
!enddefinelong
___

This setup results in my case P2 showing up in front of P1 which is not the preferred order. The different colors for P1 just tell me which "service" created the participant.

I hope that helps.

BR,
Michael
0 votes
answered Jan 20 by plantuml (141,890 points)

In last beta http://beta.plantuml.net/plantuml.jar , we have added the "order" feature.

So you can now have:

@startuml
participant A30 as P30 order 30
participant A20 order 20
participant A21 order 20
participant A10
@enduml

Tell us if this is what you were expecting and if it helps.

Note that few tests have been done, so feedback is welcome!

commented Jan 22 by mgrol (1,230 points)
Hi,

thank you. At first glance it looks exactly for what I was looking for. I try to "stress test" this feature in the next days.

BR,
Michael
commented Jan 23 by mgrol (1,230 points)
HI,

after a few more tests, it looks good and was exacly what I was looking for.

* What I found out is that no "order <number>" is equal to "order 0". Thus they are ordered by time of creation, which I am fine with. Correct?
* Negative values are not allowed and Iget a syntax error.
* If the number is to big, you will get a NumberFormatException (CommandParticipant.java:101). Maybe add a high default value to the catch block or ignore the parse int.  Try "order 100000000000" to get the error.


BR,
Michael
commented Jan 25 by plantuml (141,890 points)
Thanks for your tests!

Yes, the order by default is 0.
When two participants have the same order (either 0 or any other value), they are ordered by time of creation.
We've just publish a new beta http://beta.plantuml.net/plantuml.jar :
* Negative value are now accepted.
* Large numbers (more than 7 digit) throw now an error.
commented Jan 26 by mgrol (1,230 points)
Hi,

thank you for beta10
* negative numbers for ordering work fine and give an additional degree of freedom
* the default behavior is perfect
* for large numbers I am not quit sure about the syntax error. In general, I have sometimes problems to pinpoint the exact location of the syntax error. Maybe there is a hint for that.

Nevertheless, good work. Thank you, the feature works perfect for me.

BR,
Michael
...