Skip to content

Task 2

Your second task is the TouchCORE assisted conversion of Tic Tac Toe into a RESTful service.

WARNING! Start your screen recording now. Your entire on-screen task activity must be captured. This includes your familiarization with the task description!

Task Illustration (Restifying the Zoo)

I will now illustrate the steps of a TouchCORE assisted conversion to a RESTful service on the example of the Zoo.
I will use the previously shown Zoo REST interface description.

Afterwards, your task will be to apply the same TouchCORE assisted methodology on a different application. Your task is not to replicate the Zoo conversion while you are watching.

  • Please now watch this screencast where I demonstrate and explain TouchCORE usage.
    • Below you then find a summary of the main steps.
    • If anything does not work as expected, take a look at the Troubleshoot section.

Load TouchCORE Project

  • Locate the TouchCORE release folder
  • Launch TouchCORE: java -jar TouchCORE.jar
  • Load the prepared Zoo model:
    • Click the folder icon.
      folder
  • Navigate to the provided Class Diagram
    • Tap and hold the "Zoo" box
      openmodel
    • Select "Open Realization Model"
    • Inspect the Class Diagram (Business Logic)
      bl

Draw ResTL Model

  • Use the Navigation bar to leave the Class Diagram
    navbar
  • Open the "ResTL" perspective:
    • Tap and hold the "Zoo" box
      openmodel
    • Select "Open Realization Model"
    • Open the "Exposed Interface" model
  • Modify the ResTL model according to the provided Interface Description
    • Drag down to add new resources to the tree (start dragging slightly under an existing box)
      addresource
    • Click the circles to enable Get / Put / Post / Delete methods for a resource.
      addmethod
  • If you made a mistake, either
    • tap and hold on a resource to remove it
    • double click a resource to rename it

Resource and Parameter Mapping

  • While in the ResTL perspective, additionally open the Class Diagram perspective in split-view mode.
    • Click the Split-View Button splitview
    • Select the Class Diagram model
  • Drag lines to establish mappings
    • Connect Resource Methods (circles) to Class Operations map
    • Connect Dynamic Resources (text in boxes) to Operation Parameters
      parammap

Heads-up: A correctly mapped model showcases lines of both colours, blue and green! If you only see one colour you may have forgotten parameter mappings.

Code Generation

  • Make sure the original application is registered in your system:
    • Clone the sources of the original (unrestified) java application
    • Install it as library, with mvn clean install
  • Generate the RESTified code with the Transformator button
    trafo

Build and Run your REST service

  • Navigate to your TouchCORE model directory
  • Open a terminal in the new generated sources folder
  • Run the RESTful service with: mvn clean package spring-boot:run
  • Test any Get operation with your browser, e.g.:
    http://127.0.0.1:8080/zoo/animals

Compile and Test

To compile and test your produced REST service:

  • Compile your project with: mvn clean package
  • Open the newly generated target folder.
  • Run the generated JAR file with: java -jar YOUR-SERVICE-NAME.jar
  • Test access with your browser. You can directly access any [GET] resource by typing this into the URL bar:
    http://127.0.0.1:8080/zoo/animals
    (where zoo/animals is replaced by a valid GET-enabled resource of your application)

Your Task

Now it is your turn!

WARNING! Double check that your screen recording is still running. Your entire on-screen task activity must be captured.

Instructions

  • All you need to do is replicate the above steps for the requested app.
  • Limits:
    • You may stop whenever you deem the task successfully completed.
    • You may also stop after 90 Minutes of refactoring, whatever the state of your refactoring - You are however also allowed to continue as long as you want.
  • The target REST interface description for your task is below.
  • Please now run a TouchCORE assisted conversion of Tic Tac Toe into a RESTful service.

Legacy Application Details

Below diagram highlights classes and methods of the legacy Tic Tac Toe application, relevant to your RESTification task. For more information on theses methods, also consult the Tic Tac Toe online documentation.
xox-classes

Interface Description: Tic Tac Toe Resources and Methods

  • Your interface should begin with a top-level resource "xox", offering two methods.
    • A [GET] request to the "xox" resource should result in a lookup of all currently running games, as a list of game-identifiers.
    • A [POST] request to the "xox" resource should allow adding of a new game instance. The identifier is generated on server side and does not need to be provided, however the request body should provide all parameters required as game settings.
  • The "xox" resource should possess a dynamic placeholder subresource, representing individual game instances by identifier.
    • A [GET] request on the identifier placeholder resource should retrieve scoring information for the targeted game.
    • A [DELETE] request on the identifier placeholder resource should remove the game from the list of all games.
  • The dynamic resource representing games by their identifier should have two subresources: "players" and "board".
    • A [GET] request on the "players" resource should return a list of player names involved into the specified game. The game instance is in this case provided by value of the parent placeholder resource.
    • A [GET] request on the "board" resource should return a snapshot of the current game board layout, is to say which cells empty or occupied by a given player. The game instance is in this case provided by value of the parent placeholder resource.
  • The "players" resource should possess a dynamic placeholder resource, encoding the name of a given player. This resource has no methods, but in its turn a subresource "actions".
    • A [GET] request on actions should return an array of possible actions for a given player in a given game. Each action represents the claim of an available field. The required player name is provided by the parent dynamic resource representing a player name and the game instance is provided by the value of the dynamic sub resource of the root resource.
  • The "actions" resource should possess a dynamic placeholder resource that serves to identify the a specific selection of the actions available to a given player in a given game.
    • A [POST] request on that dynamic placeholder resource should allow the selection of a given action, to perform it. The precise action is then identified by an int value taken by the dynamic resource, representing the position in the array of all possible actions. The required player name is provided by the parent dynamic resource representing a player name and the game instance is provided by the value of the dynamic sub resource of the root resource.

Click here to download interface description as file.

Troubleshoot

  • Q: I can't start TouchCORE. Nothing happens when I double-click the JAR.
    A: Start by double click is unfortunately not supported. Instead open a terminal in the unzipped TouchCORE folder, then type: java -jar TouchCORE.jar
  • Q: TouchCORE crashes with an exception, right after start.
    A: Most likely you are not using a compatible Java version. Run java -version and verify the output is 11.0.5.
  • Q: I can't resize the TouchCORE window.
    A: The window can not be resized while TouchCORE is running, but if your screen is big enough, you can change the resolution in the file Settings.txt, next to the TouchCORE.jar file.
  • Q: Nothing happens when I click elements in TouchCORE.
    A: TouchCORE was developed for touch screens, therefore some elements require time gestures, e.g. Tap-and-Hold. Try a long click on the element.
  • Q: I cannot scroll around.
    A: Click with the right mouse button, while moving the mouse to scroll.
  • Q: I cannot zoom.
    A: Use the mouse wheel or a two-finger drag up or down on your touchpad to zoom in or out.
  • Q: I can not find how to open the prepared models.
    A: By default TouchCORE shows only models that are in the same location as where the software was launched. Use the upward arrow in the top left corner of the TouchCORE file-explorer to navigate to a different folder on your file-system.
  • Q: TouchCORE says it generated code, but I do not find the output folder.
    A: The java code is always generated inside the model project. Locate the folder with the original models, inside you will find a folder named generated-maven-project.
  • Q: The code is generated, but when I compile it with Maven, it complains about the bookstore/xox-internals not found. What went wrong?
    A: The generated sources use the legacy sources as library. Maven needs to know about the legacy sources , therefore you need to compile the original sources at least once with: mvn clean install.