AnsweredAssumed Answered

How to extend ServiceTask properly?

Question asked by viggo.navarsete on Jan 3, 2014
Latest reply on Jan 4, 2014 by viggo.navarsete
Hi,

I started to create processes programatically inspired by this forum post: http://stacktrace.be/blog/2013/03/dynamic-process-creation-and-deployment-in-100-lines/

I see that I probably need various service tasks in Java where I need to set some common properties like this:
protected FlowElement createServiceTask(String id, String name) {
      ServiceTask serviceTask = new ServiceTask();
      serviceTask.setId(id);
      serviceTask.setName(name);
      serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
      serviceTask.setImplementation("com.foo.CreatePurchaseOrderServiceTaskDelegate");
     return serviceTask;
  }

This work perfectly well if I do it like above, but then I thought I could move most of this code into a base class which extends ServiceTask, like this:
public class CreatePurchaseOrderServiceTask extends ServiceTask {

    public CreatePurchaseOrderServiceTask(String id) {  
        super();
        setId(id);
        setName("Create Purchase Order Task");
        setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
        setImplementation("com.foo.CreatePurchaseOrderServiceTaskDelegate");
    }
}

and call it like this:
protected FlowElement createServiceTask(String id, String name) {
     CreatePurchaseOrderServiceTask serviceTask = new CreatePurchaseOrderServiceTask(id);  
     return serviceTask;
  }


but then I end up with this stacktrace:
03 Jan 2014 17:45:34 ERROR BpmnXMLConverter - Error writing BPMN XML
org.activiti.bpmn.exceptions.XMLException: No converter for class com.foo.CreatePurchaseOrderServiceTask found
   at org.activiti.bpmn.converter.BpmnXMLConverter.createXML(BpmnXMLConverter.java:541)
   at org.activiti.bpmn.converter.BpmnXMLConverter.convertToXML(BpmnXMLConverter.java:464)
   at org.activiti.bpmn.converter.BpmnXMLConverter.convertToXML(BpmnXMLConverter.java:436)
   at org.activiti.engine.impl.repository.DeploymentBuilderImpl.addBpmnModel(DeploymentBuilderImpl.java:110)
   at com.navarsete.stand012.DynamicActivitiProcessTestWithSpring.testMyJavaServiceTask(DynamicActivitiProcessTestWithSpring.java:82)

…and really don't understand why. The only thing I've done is to extend the ServiceTask class, calling the constructor of the super class and then populating some properties. I haven't added, modified or removed any fields, so why is a (new?) converter needed? And what kind of converter?

I would appreciate some help on this one since I'm new to Activiti :)

Best regards,
Viggo

Outcomes