Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@eclipse-emfcloud/coffee-custom-commands-example
Advanced tools
Example custom command plug-in for the Model Server.
This package provides an example of a command provider plug-in for the Model Server.
It provides an implementation of the custom 'increment-duration'
command for a workflow Task
in a Coffee model.
See the parent readme for details of how to set up and build the project.
For detailed instructions how to run the example server configuration that includes this plug-in example, see the Example Server readme.
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 for custom commands.
Next, send a request to execute the custom "increment duration" command. This command is a composite of two commands in a four-step process:
duration
property of the affected Task
.
The default is 0
when the property is not present, as is initially the case in this example model.1
to the current duration
and execute a set
command to update the duration.duration
from the CommandExecutionResult
returned by the server.
Add the new duration
value calculated at step 2 to this previous value of the duration
.duration
computation into the Task
.The example command provider uses a transaction on the target model to execute these two commands, receiving intermediate results that are inputs to later commands in the sequence, in a single undoable operation on the undo stack.
To execute this custom command, send a PATCH
request to
http://localhost:8082/api/v2/models?modeluri=SuperBrewer3000.coffee&format=json-v2
with the following body:
{
"data": {
"type": "modelserver.emfcommand",
"data": {
"type": "increment-duration",
"$type": "http://www.eclipse.org/emfcloud/modelserver/command#//Command",
"owner": {
"$ref": "SuperBrewer3000.coffee#//@workflows.0/@nodes.0",
"$type": "http://www.eclipse.org/emfcloud/coffee/model#//AutomaticTask"
}
}
}
}
You also need to set the following two headers for the request to work:
Note that this uses the EMF URI fragment determined earlier in the owner.$ref
property.
The command is a custom increment-duration
type and has no other parameters.
Fetch the model again with a GET request to see the updated duration
of the PreHeat task.
Now repeat the same command a few times, each time getting the model again to see how the duration
changes.
Do you recognize a pattern?
A critical component of this custom command provider framework is the new Model Server protocol for opening and closing transactions on models. This transaction context allows a command provider plug-in in the Model Server to execute a chain of commands with intermediate results, all captured as a single undoable unit on the stack. During the transaction, the Model Server receives private notification of the model changes and broadcast to subscribers at large is deferred to the close of the transaction. If the transaction is rolled back, of course such broadcast will not occur as all changes performed are reverted.
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 +1
increments are not evident because both original commands are undone at each step.
FAQs
Example custom command plug-in for the Model Server.
We found that @eclipse-emfcloud/coffee-custom-commands-example demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.