01-01-2016 12:56 PM
<property name="postBpmnParseHandlers">
<list>
<bean class="xxx.yyy.TopBpmnCustomParseListener" />
</list>
</property>
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);
}
}
}
}
01-01-2016 02:40 PM
(TaskDefinition) bpmnParse.getCurrentActivity().getProperty(UserTaskParseHandler.PROPERTY_TASK_DEFINITION)
works fine. the current code is:
public class TopBpmnCustomParseListener extends AbstractBpmnParseHandler<UserTask> {
public static final String COMMENT_ATTRIBUTE_FORM_SUFFIX = "_comment";
public static final String COMMENT_ATTRIBUTE_FORM_NAME = "comment";
@Override
protected Class< ? extends BaseElement> getHandledType() {
return UserTask.class;
}
@Override
protected void executeParse(BpmnParse bpmnParse, UserTask element) {
TaskDefinition taskDefinition = (TaskDefinition) bpmnParse.getCurrentActivity().getProperty(UserTaskParseHandler.PROPERTY_TASK_DEFINITION);
System.out.println("custom processing of :" + ((UserTask) element).getName());
System.out.println("with properties :"+bpmnParse.getCurrentActivity().getProperties());
// if there are not already any of our listeners attached to the TaskListener.EVENTNAME_ALL_EVENTS event. then add one.
if (taskDefinition.getTaskListeners().containsKey(TaskListener.EVENTNAME_ALL_EVENTS)){
if (!taskDefinition.getTaskListeners().get(TaskListener.EVENTNAME_ALL_EVENTS).stream().anyMatch(y->y instanceof TopTaskEventListener)) {
System.out.println("Adding task listener…to " + ((UserTask) element).getName());
TaskListener listener = new TopTaskEventListener();
taskDefinition.addTaskListener(TaskListener.EVENTNAME_ALL_EVENTS, listener);
}
}
String commentFieldName = element.getId() + COMMENT_ATTRIBUTE_FORM_SUFFIX;
List<FormPropertyHandler> fphList = ((DefaultTaskFormHandler)(taskDefinition.getTaskFormHandler())).getFormPropertyHandlers();
// if we don't already have an id_comment form property, then add one
if (!fphList.stream().anyMatch(field -> field.getId().equals(commentFieldName))) {
System.out.println("adding required _comment string field…");
FormPropertyHandler field = new FormPropertyHandler();
field.setId(commentFieldName);
field.setType(new StringFormType());
field.setRequired(false);
field.setWritable(true);
field.setReadable(true);
field.setName(COMMENT_ATTRIBUTE_FORM_NAME);
field.setVariableName(COMMENT_ATTRIBUTE_FORM_NAME);
fphList.add(field);
}
}
}
and it works fine. I guess now that doing the same thing with implementing BpmnParseHandler would have the same effect, but at least here I don't have to cast element to UserTask Should I assume that what I was doing previously - altering the passed in element has no effect on the parsing process since this is a POST processing. Unless perhaps I use a preBpmnParseHandlers to change the objects before the normal parsing happens? I'm not sure if what I'm saying here makes sense though 01-04-2016 03:23 PM
05-02-2016 03:07 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.