@eclipse-emfcloud/coffee-triggers-example

0.2.0-next.961a1a0.14 • Public • Published

Trigger Example

This package provides an example of a trigger provider plug-in for the Model Server. It provides a trigger that ensures the duration of a workflow Task in a Coffee model is always a multiple of ten.

Setup

See the parent readme for details of how to set up and build the project.

How to Run

For detailed instructions how to run the example server configuration that includes this plug-in example, see the Example Server readme.

Send Requests to the Model Server

There are a variety of tools available for ad hoc REST interactions with services such as the Model Server. A recommended option is the Postman application.

Start by fetching the current state of the model. Send a GET request to

    http://localhost:8082/api/v2/models?modeluri=SuperBrewer3000.coffee

The result should look something like this:

{
  "type": "success",
  "data": {
    "$type": "http://www.eclipsesource.com/modelserver/example/coffeemodel#//Machine",
    "$id": "/",
    "children": [
      // ... structural components here ...
    ],
    "name": "Super Brewer 3000",
    "workflows": [
      {
        "$id": "//@workflows.0",
        "name": "Simple Workflow",
        "nodes": [
          {
            "$type": "http://www.eclipsesource.com/modelserver/example/coffeemodel#//AutomaticTask",
            "$id": "//@workflows.0/@nodes.0",
            "name": "PreHeat",
            "component": {
              "$type": "http://www.eclipsesource.com/modelserver/example/coffeemodel#//BrewingUnit",
              "$ref": "//@children.0"
            }
          }
        ]
      }
    ]
  }
}

Make note of the EMF-style URI fragment $id of the PreHeat task, which must be inferred from the model structure. The URI fragment is //@workflows.0/@nodes.0: the first node of the first workflow in the root Machine object. This will be used to build requests to edit the duration.

Next, send a request to change the duration property of this task. For example, this could be the example custom increment-duration command or a simple SetCommand or replace JSON Patch operation.

For example, send a PATCH request to

    http://localhost:8082/api/v2/models?modeluri=SuperBrewer3000.coffee

with the following body:

{
  "data": {
    "type": "modelserver.patch",
    "data": [
      {
        "op": "replace",
        "path": "SuperBrewer3000.coffee#//@workflows.0/@nodes.0/duration",
        "value": 37
      }
    ]
  }
}

Observe in the response that there is a final change to the duration that rounds it up to the next multiple of ten. A typical response looks something like this:

{
  "type": "success",
  "data": {
    "success": true,
    "patch": [
      {
        "op": "replace",
        "path": "/workflows/0/nodes/0/duration",
        "value": 37
      },
      {
        "op": "replace",
        "path": "/workflows/0/nodes/0/duration",
        "value": 40
      }
    ]
  }
}

Fetch the model again with a GET request to see that the final value of the duration of the PreHeat task is a nice round multiple of ten.

Undo the Commands

A critical component of this trigger provider framework is that the changes made by triggers are included in undo/redo of whatever changes triggered them.

To send an undo command to the Model Server, simply send a GET request to

    http://localhost:8082/api/v2/undo?modeluri=SuperBrewer3000.coffee

Follow that up with a GET on the /api/v2/models endpoint to see how the duration of the PreHeat Task is reverted. The intermediate values that are not multiples of ten are not evident because all changes are undone at each step.

Readme

Keywords

none

Package Sidebar

Install

npm i @eclipse-emfcloud/coffee-triggers-example

Weekly Downloads

0

Version

0.2.0-next.961a1a0.14

License

(EPL-2.0 OR MIT)

Unpacked Size

34.2 kB

Total Files

11

Last publish

Collaborators

  • ndoschek
  • tortmayr
  • eugenneufeld
  • eclipse-emfcloud-bot
  • mfleck
  • jfaltermeier
  • planger
  • lkoehler