Hello
We are using GlobalEvents to publish a notification when a new task (through BPM) was created by another user in the platform.
So basically, when a new task is created and it involves current user logged in, the “inbox” menu item from side menu should update the badge accordingly (“1 New”)
We have extended BpmActivitiListener to publish our custom global event when a new task is created (on TASK_CREATED).
The issue is that the inbox is not updated and the reason for that, I believe, is that the event is caught before transaction ends and task gets commited.
Found through debugging that the newly created task is not retrieved from db on event handling, even though we are using the annotation
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
How can we make this work? Is there another way to real-time globally notify after a new Task is created?
@UiController("customMainScreen")
@UiDescriptor("custom-main-screen.xml")
public class CustomMainScreen extends MainScreen {
@Inject
private SideMenu sideMenu;
@Inject
private ProcTaskService procTaskService;
@EventListener(ProcTaskGlobalEvent.class)
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
public void onProcTaskGlobalEvent(ProcTaskGlobalEvent procTaskGlobalEvent) {
SideMenu.MenuItem inboxMenuItem = sideMenu.getMenuItem("inbox-screen");
int numberOfProcTask = procTaskService.getProcTasksForUser(userSession.getAttribute("userId")).size();
String badgeText = numberOfProcTask > 0 ? numberOfProcTask + " New" : "";
if (inboxMenuItem != null) {
inboxMenuItem.setBadgeText(badgeText);
}
}
}
public class ProcTaskGlobalEvent extends GlobalApplicationEvent implements GlobalUiEvent {
private String name;
/**
* Create a new ApplicationEvent.
*
* @param source the object on which the event initially occurred (never {@code null})
*/
public ProcTaskGlobalEvent(Object source, String name) {
super(source);
this.name = name;
}
public String getName() {
return name;
}
}
public class CustomBpmActivitiListener extends BpmActivitiListener {
protected Events events = AppBeans.get(Events.class);
@Override
public void onEvent(ActivitiEvent event) {
super.onEvent(event);
switch (event.getType()) {
case TASK_CREATED:
events.publish(new ProcTaskGlobalEvent(this, "created"));
break;
}
}
}