Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@eclipse-emfcloud/coffee-triggers-example

Package Overview
Dependencies
Maintainers
8
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eclipse-emfcloud/coffee-triggers-example

Example server-side triggers plug-in for the Model Server.

  • 0.2.0-next.c976fe5.48
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-96.77%
Maintainers
8
Weekly downloads
 
Created
Source

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&format=json-v2

with the following body:

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

You also need to set the following two headers for the request to work:

  • Content-Length = <calculated when request is sent>
  • Content-Type = application/json

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.

FAQs

Package last updated on 30 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc