{"id":13694658,"url":"https://github.com/mapteb/simple-state-machine","last_synced_at":"2025-05-03T04:30:44.585Z","repository":{"id":184908604,"uuid":"198703408","full_name":"mapteb/simple-state-machine","owner":"mapteb","description":"A simple Java state machine for Spring Boot projects","archived":false,"fork":false,"pushed_at":"2024-08-24T20:01:43.000Z","size":15934,"stargazers_count":37,"open_issues_count":1,"forks_count":27,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-12T21:39:02.735Z","etag":null,"topics":["finite-state-machine","fsm","java","spring-boot","state-machine","statechart","statemachine"],"latest_commit_sha":null,"homepage":"","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/mapteb.png","metadata":{"files":{"readme":"README.md","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-07-24T20:11:19.000Z","updated_at":"2024-08-24T20:01:46.000Z","dependencies_parsed_at":"2024-01-14T19:12:07.644Z","dependency_job_id":"1977b21c-2f2b-4c12-8d18-3b9caf6e3fcf","html_url":"https://github.com/mapteb/simple-state-machine","commit_stats":null,"previous_names":["mapteb/simple-state-machine"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapteb%2Fsimple-state-machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapteb%2Fsimple-state-machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapteb%2Fsimple-state-machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapteb%2Fsimple-state-machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mapteb","download_url":"https://codeload.github.com/mapteb/simple-state-machine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252144379,"owners_count":21701398,"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":["finite-state-machine","fsm","java","spring-boot","state-machine","statechart","statemachine"],"created_at":"2024-08-02T17:01:36.685Z","updated_at":"2025-05-03T04:30:43.481Z","avatar_url":"https://github.com/mapteb.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":"# simple-state-machine\n\nA simple state machine for Spring Boot projects. This project contains a framework and an illustration of the usage of the framework for a sample project like online order processing.\n\n## Benefits\n\nEnables building robust applications,\u003cbr\u003e\nSimplifies writing unit tests,\u003cbr\u003e\nEnables adding new processes faster.\n\n## Usage Workflow\n\n|Initial State |Pre-event |   Processor    |        Post-event  |  Final State  |\n| --- | --- | --- | --- | --- |  \n|DEFAULT    -\u003e|  submit -\u003e| orderProcessor() -\u003e| orderCreated   -\u003e |PMTPENDING |\n|PMTPENDING -\u003e | pay    -\u003e| paymentProcessor() -\u003e| paymentError   -\u003e |PMTPENDING |\n|PMTPENDING -\u003e|  pay    -\u003e| paymentProcessor() -\u003e| paymentSuccess -\u003e| COMPLETED |\n\n1. To use this framework first create a state transitions table like above.\n\n2. Then implement the interfaces ProcessState and ProcessEvent.\nSee OrderState and OrderEvent classes for examples\n\n3. Identify a primary key for the process. For the order process it would be orderId, for a time sheet application it would be userId-week-ending-date etc.\n\n4. Implement the StateTransitionsManager. See the OrderStateTransitionsManager class for an example.\n\n5. Implement the Processor class. See the OrderProcessor and the PaymentProcessor classes for examples.\n\n6. Create a controller class. See the OrderController for an example.\n\n### Build\n\nRun the command \".\\gradlew build\" at the project root\n\n### Unit Testing\n\nUnit tests can be run using the \".\\gradlew test\" command at the project root.\n\n### Build and Deploy\n\nRun the command \".\\gradlew bootRun\" at the prject root.\n\n### Integration Testing\n\nFor the order sample considered in this project, the following two APIs are created to test the order process:\n \n1. User request to create an order. This API is implemented as GET so it can be tested quickly in the browser.\nhttp://localhost:8080/order \u003c\u003c creates an order and returns an orderId. Selected product ids are not included in this demo example  \u003e\u003e\n\n2. User makes a payment. This API is also implemented as GET so it can be tested quickly in the browser.\nhttp://localhost:8080/order/cart?payment=123\u0026orderId=123 \u003c\u003c where orderId is the UUID returned by the first API. Payment value less than 1.00 is considered for the error transition \u003e\u003e\n\n\u003c\u003c for quick testing in a browser both of the above are implemented as GET APIs \u003e\u003e\nWhen the above APIs are called the console log displays the state transitions that reflect the above table. (Note: payment=0 is used to mock payment error in this example)\n\n### Related Projects\n\nA refactored versin of this exists in the [branch](https://github.com/mapteb/simple-state-machine/tree/refactor-1).\n\n### Also See\n\nSpring Framework's [State Machine libray](https://docs.spring.io/spring-statemachine/docs/current/reference/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmapteb%2Fsimple-state-machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmapteb%2Fsimple-state-machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmapteb%2Fsimple-state-machine/lists"}