{"id":18329622,"url":"https://github.com/jupiter-tools/statemachine-utils","last_synced_at":"2025-04-09T17:38:30.369Z","repository":{"id":107563234,"uuid":"205645248","full_name":"jupiter-tools/statemachine-utils","owner":"jupiter-tools","description":null,"archived":false,"fork":false,"pushed_at":"2019-09-08T22:35:37.000Z","size":108,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-15T10:30:36.069Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jupiter-tools.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-01T07:42:50.000Z","updated_at":"2019-09-02T23:01:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"f8841983-faaa-4aa0-9857-4d16ae46a74d","html_url":"https://github.com/jupiter-tools/statemachine-utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupiter-tools%2Fstatemachine-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupiter-tools%2Fstatemachine-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupiter-tools%2Fstatemachine-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupiter-tools%2Fstatemachine-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jupiter-tools","download_url":"https://codeload.github.com/jupiter-tools/statemachine-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248078350,"owners_count":21044093,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T19:18:05.059Z","updated_at":"2025-04-09T17:38:30.349Z","avatar_url":"https://github.com/jupiter-tools.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":":toc: preamble\n\n# State Machine Utils\n\nimage:https://travis-ci.com/jupiter-tools/statemachine-utils.svg?branch=master[\"Build Status\", link=\"https://travis-ci.com/jupiter-tools/statemachine-utils\"]\nimage:https://codecov.io/gh/jupiter-tools/statemachine-utils/branch/master/graph/badge.svg[\"\", link=\"https://codecov.io/gh/jupiter-tools/statemachine-utils\"]\n\nTools to improve the Spring State Machine library.\n\n## Dependencies\n\n[source,xml]\n----\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.jupiter-tools\u003c/groupId\u003e\n    \u003cartifactId\u003estatemachine-utils-starter\u003c/artifactId\u003e\n    \u003cversion\u003e0.1\u003c/version\u003e\n\u003c/dependency\u003e\n----\n\n## How to resolve available events from a current state of the state machine\n\nIf you need to get a list of all available events from the current state then you can use the `StateMachineResolver`. Let’s look at the state machine below. This is a typical example of the Kanban workflow for tasks. Firstly we create a new task in the state `BACKLOG` then we move this task to `IN_PROGRESS` while making an implementation (send event `START_FEATURE`). When our task is done we need to deploy it on the testing environment (event `DEPLOY`), and after that, we can move the task to the state `TESTING` by using an event `FINISH_FEATURE`.\n\nWe can move a state machine from `IN_PROGRESS` to `TESTING` only if we already deployed our feature to the testing environment. This rule implements by the guard on the transition (`FINISH_FEATURE`). In this guard, we check the value of the variable `deployed` which will set to true in the DEPLOY transition.\n\nimage:./docs/statemachine_1.png[\"state machine uml\", width=400]\n\nThe next code sample shows how to resolve available transitions from the `BACKLOG` state:\n\n[source, java]\n----\n@SpringBootTest\nclass StateMachineResolverTest {\n\n\t@Autowired\n\tprivate StateMachineResolver\u003cStates, Events\u003e resolver;\n\n\t@Autowired\n\tprivate StateMachineFactory\u003cStates, Events\u003e factory;\n\n\t@Test\n\tvoid testResolverWithoutGuard() {\n\t\t// Arrange\n\t\tStateMachine\u003cStates, Events\u003e machine = factory.getStateMachine();\n\t\t// Act\n\t\tList\u003cEvents\u003e availableEvents = resolver.getAvailableEvents(machine);\n\t\t// Asserts\n\t\tassertThat(availableEvents).containsOnly(Events.START_FEATURE,\n\t\t                                         Events.DEPLOY);\n\t}\n}\n----\n\nStateMachineResolver evaluates all reachable transitions from the current state of the state machine, in this process tries to check all existed transitions with its guard conditions. And we can find available events in the state `IN_PROGRESS`:\n\n\n[source, java]\n----\n@Test\nvoid testResolverWithGuard() {\n    // Arrange\n    StateMachine\u003cStates, Events\u003e machine = factory.getStateMachine();\n    machine.sendEvent(Events.START_FEATURE);\n    // Act\n    List\u003cEvents\u003e availableEvents = resolver.getAvailableEvents(machine);\n    // Asserts\n    assertThat(availableEvents).containsOnly(Events.DEPLOY);\n}\n----\n\nWe don't find the `FINISH_FEATURE` event because our statemachine didn't deploy to the testing environment.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjupiter-tools%2Fstatemachine-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjupiter-tools%2Fstatemachine-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjupiter-tools%2Fstatemachine-utils/lists"}