This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Don't use any custom model package types but the types from the api package for REST. - GuiStateMachineApi works now with IDs for the state machines. This allows the removal and retrieval of state machines based on the unique ID. - Remove persistence layer since the Scala API provides persistence calls. - Add bodys for the parameters for `get-state` and `execute-action`. - Only use one service class GuiStateMachineService. - Swagger uses the correct service class now (not RestService). - Add initial JsonFormat types for all the required Scala API types. - Remove model package and Bash scripts for the old REST API. - Simplify documentation. - Adapt unit tests.
- Loading branch information
Showing
44 changed files
with
242 additions
and
381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...etest/guistatemachine/rest/model/Id.scala → ...la/de/retest/guistatemachine/api/Id.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 7 additions & 10 deletions
17
src/main/scala/de/retest/guistatemachine/api/impl/GuiStateMachineApiImpl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
src/main/scala/de/retest/guistatemachine/persistence/Persistence.scala
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
src/main/scala/de/retest/guistatemachine/rest/DefaultJsonFormats.scala
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
src/main/scala/de/retest/guistatemachine/rest/ExecuteActionBody.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package de.retest.guistatemachine.rest | ||
|
||
import de.retest.guistatemachine.api.{Action, Descriptors, State} | ||
|
||
case class ExecuteActionBody(from: State, a: Action, descriptors: Descriptors, neverExploredActions: Set[Action]) |
5 changes: 5 additions & 0 deletions
5
src/main/scala/de/retest/guistatemachine/rest/GetStateBody.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package de.retest.guistatemachine.rest | ||
|
||
import de.retest.guistatemachine.api.{Action, Descriptors} | ||
|
||
case class GetStateBody(descriptors: Descriptors, neverExploredActions: Set[Action]) |
83 changes: 83 additions & 0 deletions
83
src/main/scala/de/retest/guistatemachine/rest/GuiStateMachineService.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package de.retest.guistatemachine.rest | ||
|
||
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ | ||
import akka.http.scaladsl.model.{StatusCode, StatusCodes} | ||
import akka.http.scaladsl.server.{Directives, Route} | ||
import de.retest.guistatemachine.api.{GuiStateMachine, GuiStateMachineApi, Id, State} | ||
import de.retest.guistatemachine.rest.json.DefaultJsonFormats | ||
import io.swagger.annotations.{Api, ApiOperation, ApiResponse, ApiResponses} | ||
import javax.ws.rs.Path | ||
|
||
@Api(value = "/state-machine", description = "Gets a state machine") | ||
@Path("/state-machine") | ||
class GuiStateMachineService(api: GuiStateMachineApi) extends Directives with DefaultJsonFormats { | ||
|
||
def getRoute(): Route = getStateMachine() ~ deleteStateMachine() ~ postStateMachine() ~ getState() | ||
|
||
@ApiOperation(httpMethod = "GET", response = classOf[GuiStateMachine], value = "Returns a state machine based on the ID") | ||
@ApiResponses(Array(new ApiResponse(code = 404, message = "State machine not found"))) | ||
def getStateMachine(): Route = get { | ||
path("state-machine" / LongNumber) { id => | ||
val r = api.getStateMachine(Id(id)) | ||
r match { | ||
case Some(x) => complete(x) | ||
case None => complete(StatusCodes.NotFound) | ||
} | ||
} | ||
} | ||
|
||
@ApiOperation(httpMethod = "DELETE", response = classOf[StatusCode], value = "Returns the status code") | ||
@ApiResponses( | ||
Array( | ||
new ApiResponse(code = 200, message = "Successful deletion"), | ||
new ApiResponse(code = 404, message = "State machine not found") | ||
)) | ||
def deleteStateMachine(): Route = delete { | ||
path("state-machine" / LongNumber) { stateMachineId => | ||
import de.retest.guistatemachine.api.Id | ||
val r = api.removeStateMachine(Id(stateMachineId)) | ||
complete(if (r) StatusCodes.OK else StatusCodes.NotFound) | ||
} | ||
} | ||
|
||
@ApiOperation(httpMethod = "POST", response = classOf[Id], value = "Returns the ID") | ||
@ApiResponses(Array(new ApiResponse(code = 200, message = "Successful creation"))) | ||
def postStateMachine(): Route = post { | ||
path("state-machine") { | ||
val id = api.createStateMachine() | ||
complete(id) | ||
} | ||
} | ||
|
||
@ApiOperation(httpMethod = "POST", response = classOf[State], value = "Returns the existing or newly created state") | ||
@ApiResponses(Array(new ApiResponse(code = 404, message = "State machine not found"))) | ||
def getState(): Route = post { | ||
path("state-machine" / LongNumber / "get-state") { id => | ||
val app = api.getStateMachine(Id(id)) | ||
app match { | ||
case Some(x) => { | ||
entity(as[GetStateBody]) { body => | ||
complete(x.getState(body.descriptors, body.neverExploredActions)) | ||
} | ||
} | ||
case None => complete(StatusCodes.NotFound) | ||
} | ||
} | ||
} | ||
|
||
@ApiOperation(httpMethod = "POST", response = classOf[State], value = "Returns the state which is reached by executing this action") | ||
@ApiResponses(Array(new ApiResponse(code = 404, message = "State machine not found"))) | ||
def executeAction(): Route = post { | ||
path("state-machine" / LongNumber / "execute-action") { id => | ||
val app = api.getStateMachine(Id(id)) | ||
app match { | ||
case Some(x) => { | ||
entity(as[ExecuteActionBody]) { body => | ||
complete(x.executeAction(body.from, body.a, body.descriptors, body.neverExploredActions)) | ||
} | ||
} | ||
case None => complete(StatusCodes.NotFound) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.