spring-projects / spring-statemachine

Spring Statemachine is a framework for application developers to use state machine concepts with Spring.
1.53k stars 599 forks source link

New Feature - PlantUML visualization #1158

Open pdalfarr opened 1 month ago

pdalfarr commented 1 month ago

Add the ability to dump a Spring stateMachine to PlanUML format and to .png format 🥳

Features:

  1. Allow you to 'visualize' your Spring State Machine as .puml or .png !
  2. If a state machine is dumped at org.springframework.statemachine.StateContext.Stage.TRANSITION_END phase, a red arrow is used between the 'source' state and the 'target' state. see https://github.com/spring-projects/spring-statemachine/blob/59df160f001877d59b32c24128f4b1a0f8dffa96/spring-statemachine-uml/src/main/java/org/springframework/statemachine/plantuml/PlantUmlWriterParameters.java#L246-L248
  3. Support BeanAware for Actions and Guards, so bean names are used in diagram -> mush better than having labels like Action@0x1f4f5d1d
  4. Support for SpelExpressionAction and SpelExpressionGuard : SpEL expression is used as label.

Unit tests:

  1. Instantiate a Spring State Machine by loading (already existing) .uml file from test folder
  2. Creating a PlantUML text representation of this state machine
  3. Comparing it to to expected result 'see (new) .puml files in test folder)

What does it looks like?

Here are some results (I dumped .puml files to .png):

action-with-transition-choice.uml -> action-with-transition-choice.puml :

image

multijoin-forkjoin.uml -> multijoin-forkjoin.puml :

image

Note: 2 .uml files from test folder leads to unaccurate diagram. These 2 errors, in simple-connectionpointref.puml and simple-root-regions.puml, are likely to be related to some limitations in spring statemachine UML parser.

pivotal-cla commented 1 month ago

@pdalfarr Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

libinbin880521 commented 1 month ago

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

pivotal-cla commented 1 month ago

@pdalfarr Thank you for signing the Contributor License Agreement!

pdalfarr commented 3 weeks ago

Hi @bclozel I would like some Spring members to tell me if this PR can be useful for the Spring State Machine project or not. It turns out that you are second in the list of contributors here, hence this message for you 😄 Can I kindly ask you to have a look at this. I would be happy to elaborate more on why I think this could be useful to the project. Kind Regards, Pascal

bclozel commented 3 weeks ago

Hi there! This is probably a UI bug in GitHub as I don't remember contributing to statemachine and I'm not listed here https://github.com/spring-projects/spring-statemachine/graphs/contributors?from=2015-02-01&to=2024-07-12&type=c

pdalfarr commented 3 weeks ago

@bclozel Thanks for your reply. Yes, this is likely a bug: your avatar is visible in second position on main page of the project and you did not contribute indeed.

I see you are a committer on some Spring projects, so I take the opportunity to ask you this: how I can do to reach out to Spring State Machine "owner(s)" ? It looks like many PR are waiting here (not only mine) and I do not see much activity in Spring State Machine GitHub project. Should we (user of Spring State Mchine) worry about this? Is Spring State Machine still properly maintained?

( ? Maybe someone at Pivotal / VMWare could help regarding my questions ? )

bclozel commented 3 weeks ago

I think @jvalkeal knows.

pdalfarr commented 3 weeks ago

Hi @jvalkeal

Who can I reach out to, to discuss this PR?

Thanks