AnsweredAssumed Answered

problem with adding custom xml parser - added objects disappearing..

Question asked by atirosselet on Jan 1, 2016
Latest reply on May 2, 2016 by bikithalee
I have created a custom parser to add a listener and a form field to each  UserTask in our processes when imported from xml (so we don't have to add them all at design time).   When I debug, it gets called for each task, and the system.out logs are called, showing that it seems to be operating correctly, but after the import, neither the  TaskListener, nor the FormProperty is in the deployed definition.  I check this by instantiating a process and running through it, but nada.  Any ideas?  It appears to be registered correctly in the process engine config the activiti.cfg.xml since it IS being called

  <property name="postBpmnParseHandlers">
        <list>
            <bean class="xxx.yyy.TopBpmnCustomParseListener" />
        </list>
      </property>

The code for the custom parser is :

public class TopBpmnCustomParseListener implements BpmnParseHandler{

  public static final String CUSTOM_TASK_LISTENER = "xxx.yyy.TopTaskEventListener";
  public static final String COMMENT_ATTRIBUTE_FORM_SUFFIX = "_comment";
  public static final String COMMENT_ATTRIBUTE_FORM_NAME = "comment";
  

    @Override
    public Collection<Class<? extends BaseElement>> getHandledTypes() {
        System.out.println("HEEEEE");
        Collection<Class<? extends BaseElement>>  list = new ArrayList<>();
        list.add(UserTask.class);
        return list;
    }
      @Override
    public void parse(BpmnParse bpmnParse, BaseElement element) {

        System.out.println("custom parsing … ");
        if (element instanceof UserTask) {
           
            if (!((UserTask) element).getTaskListeners().stream().anyMatch((x) -> x.getImplementation().equals(CUSTOM_TASK_LISTENER))) {
                System.out.println("Adding task listener…");
                ActivitiListener listener = new ActivitiListener();
                listener.setEvent("all");
                listener.setImplementation(CUSTOM_TASK_LISTENER);
                listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
                ((UserTask) element).getTaskListeners().add(listener);
            }
            String commentFieldName = element.getId() + COMMENT_ATTRIBUTE_FORM_SUFFIX;
            if (!((UserTask) element).getFormProperties().stream().anyMatch(field -> field.getId().equals(commentFieldName))) {
                System.out.println("adding required _comment string field…");
                FormProperty property = new FormProperty();
                property.setId(commentFieldName);
                property.setName(COMMENT_ATTRIBUTE_FORM_NAME);
                property.setType(ELEMENT_FIELD_STRING);
                ((UserTask) element).getFormProperties().add(property);
            }
        }
    }
}

Did I misunderstand something, or is there something else that needs to be set/added?
Thanks
Ati

Outcomes