Developing Operations

Understanding Operations

MDWorkbench Services, available in the Services view, allow a user to easily execute a packaged model transformation. An MDWorkbench Service provides a wizard for the user to select transformation options and to launch the service execution.

MDWorkbench Services might be implemented using MDWorkbench Rules. If you have Java skills, services can also be fully implemented in Java, with an Operation Service.

Declaring an Operation Service

Here are the steps to declare an operation service:

  1. Create a Plug-In Project.
  2. Update the project dependencies:
    1. Open the META-INF/MANIFEST.MF file in your project.
    2. Select the Dependencies tab in the opened editor.
    3. Click the Add... button in the Required Plug-ins section, and add the following plugins:
      • com.sodius.mdw.core
      • com.sodius.mdw.platform.services
      • com.sodius.mdw.metamodel.xxx, for each metamodel your project requires.
  3. Add a service extension:
    1. Open the META-INF/MANIFEST.MF file in your project.
    2. Select the Extensions tab in the opened editor.
    3. Click the Add... button in the All Extensions section, and select the extension point com.sodius.mdw.platform.services.service
    4. Add a operationService extension, and fill the necessary information as described in the service extension point.
      • Set the 'wizard' attribute to reference an instance of org.eclipse.jface.wizard.IWizard
      • Set the 'factory' attribute to reference an instance of OperationFactory

Implementing the Service Wizard

The service extension references a wizard to display when the user executes the service. Though this wizard is optional, it is very commonly needed for the user to enter input information used by the launched transformation.

The wizard must implement the org.eclipse.jface.wizard.IWizard interface and is recommended to extend org.eclipse.jface.wizard.Wizard. The wizard is free to display as many pages as needed and to group options in such a way that the interface is intuitive for the end user.

The contract is for the IWizard.performFinish() method to store all user entered data, necessary for the service execution, in the IDialogSettings instance returned by IWizard.getDialogSettings(). All options set in the IDialogSettings instance are then accessible to the associated OperationFactory through the OperationContext argument.

Implementing Operations

The service extension references an OperationFactory to instantiate the main Operation to execute. The OperationFactory is given an instance of OperationContext that contains all user entered data set in the wizard.

An Operation is a block of code to execute and has an associated status, which determines whether warning or errors are encountered during the execution. The status enables to monitor the execution state of the operation and to query the execution result. An operation can be decomposed into sub-operations.

An Operation cannot throw an exception. All exceptions that occur during the execution are to catch and to store into the operation associated status.

The developer is encouraged to regularly check the Operation.isCanceledOrFailed(monitor) method to determine whether the operation shall continue to execute. The operation should return as soon as a cancel request is detected or when an error is stored in the status.

The Operations class provides ready to use operations for common activities, like reading or writing a model.

The MappingFunction class provides a common base for operations that are targeted to model transformation, where an output model is created from an input model.

Running an Operation Service

Running from the Services view

The Services view shows available services. User can execute Operation services from here.

When a service execution is completed, a log is displayed in the Report view. The log shows the flow of executed operations, so that the user can review the various steps of the execution and the associated information. If MappingFunction instances were used during the execution, the log also provides information on the input and output models and the traceability links between their model elements.

Running from Java code

An Operation can also be executed using a code like the following:

// create the context with input options
OperationContext context = OperationContext.Factory.create(MDWorkbenchFactory.create());
context.setProperty("myVariable", "myValue");

// run the operation
Operation operation = new MyOperationFactory().create(context);
new OperationRunner().run(operation, new NullProgressMonitor());

// write the operation's log
FileOutputStream output = new FileOutputStream(new File("c:\\temp\\log.html"));
StatusWriter.Factory.createHTML(context).write(operation.getStatus(), output);
output.close();

Extending an Operation Service

The Operation service author can provide extension points in the transformation so that other plug-in authors can contribute to enhance the transformation.

Related concepts
Service

Related tasks
Running services
Extending Operations

Related reference
com.sodius.mdw.platform.services.service extension point