Adding Services

MDWorkbench Server is an extensible platform in which you can create your own services, to execute data transformation or code generation on server side.

A service is either implemented using an MDWorkbench Ruleset or an MDWorkbench Operation. Services implemented by an operation can execute concurrently whereas only one service can execute at a time when implemented by a ruleset.

Declaring a Service Extension

Here are the steps to add a service:

  1. Edit the plug-in MANIFEST file of the created plug-in (in which is defined the MDWorkbench ruleset or operation).
  2. In the Dependencies tab, add a dependency to the plug-in com.sodius.mdw.server
  3. Select the Extensions tab, click Add..., select the com.sodius.mdw.server.service extension point and click Finish.
  4. Select the com.sodius.mdw.server.service extension and right-click New > Service.
  5. Specify the implementation of the service using one of those two options:
  6. Declare parameters in the Service declaration to reflect the arguments expected by the Ruleset and the rule or the properties expected in the OperationContext sent to the OperationFactory.
  7. Save the MANIFEST file.

Implementing an MDWorkbench Ruleset Service

Please refer to MDWorkbench documentation to create an MDWorkbench Project:
MDWorkbench Documentation > Tasks > Developing Rules

Servlet Context Parameters are accessible within the rules by querying the EvaluationContext.getProperty(String) method, e.g.:
String workspaceLocation = (String) context.getProperty("mdw.server.workspace");

Implementing an MDWorkbench Operation

Please refer to MDWorkbench documentation to create an MDWorkbench Project:
MDWorkbench Documentation > Tasks > Developing Operations

The OperationFactory subclass to create (and to reference in the service extension) is in charge to create the main Operation to execute. It receives an OperationContext that contains the values associated with the parameters declared by the service, e.g.:
String myParameterValue = (String) context.getProperty("myServiceParameterName");

Servlet Context Parameters are accessible in the OperationContext instance as well, e.g.:
String workspaceLocation = (String) context.getProperty("mdw.server.workspace");

If files are to generate, the OPTION_EVALUATION_DIRECTORY option, present in the context, indicates the directory in which such files should be generated for them to appear as a result of the service execution, e.g.:

File directory = new File((String) context.getProperty(LaunchManager.OPTION_EVALUATION_DIRECTORY));
File generatedFile = new File(directory, "result.txt");
// and now write something in that file...

Testing the Service

You can then test the new Service using Jetty and verify you can execute it correctly using the integration page:
http://localhost:27888/mdworkbench/web/dev/services.html

Related concepts
Service

Related tasks
Creating Plug-Ins
Testing with Jetty
Declaring Service Parameters
Reporting Progress
Customizing the Launch Status
Adding a Custom Launch Page

Related reference
Service Extension Point