AssignedId is 0 in my event listener after I assign a User (assignUserTaskIfNotAssigned ) to my Human Activity

1
0
-1

I can register a Event Listener, also I am receiving events with:

eventService.addHandler("HUMAN_TASK_INSTANCE_ASSIGNEE_UPDATED", this);

I convert my event object to

SUserTaskInstanceImpl userTaskInstance = (SUserTaskInstanceImpl) event.getObject();

I have a Unit Test to assign a User to my Human Task, works well and even fire an event in my custom event listener

// Fire a User assignation of Task Id = 580013 to user = 102
     @Test
         @DisplayName("assign")
         public void assign() throws Exception {
             APISession apiSession = getAPISession("install", "install");
            final ProcessAPI processAPI = TenantAPIAccessor.getProcessAPI(apiSession);
           // The next line show me 0 (must be 102) in the event
              processAPI.assignUserTaskIfNotAssigned(580013, 102);
           // The next line works well
           //        processAPI.assignUserTask(580013, 102);
      }


 // Event Listener
    @Override
             public void execute(SEvent event) throws SHandlerExecutionException {

                Object eventObject = event.getObject();
                 if (eventObject instanceof SFlowNodeInstance) {
                     SFlowNodeInstance flowNodeInstance = (SFlowNodeInstance) eventObject;
                         if (event.getType().equalsIgnoreCase("HUMAN_TASK_INSTANCE_ASSIGNEE_UPDATED")) {
                                    if (event.getObject() instanceof SUserTaskInstanceImpl) {
                                SUserTaskInstanceImpl userTaskInstance = (SUserTaskInstanceImpl) event.getObject();
                                String user = getUser(userTaskInstance.getAssigneeId());
                                String processName = getProcessDefinitionName(userTaskInstance.getProcessDefinitionId());


                System.out.println("AssigneeId:" + userTaskInstance.getAssigneeId());
                System.out.println("Parent Process Id:" + userTaskInstance.getParentProcessInstanceId());
                System.out.println("Process DefinitionId:" + userTaskInstance.getProcessDefinitionId());
                System.out.println("Name:" + userTaskInstance.getName());
                System.out.println("DisplayName:" + userTaskInstance.getDisplayName());
                System.out.println("ExecutedBy:" + userTaskInstance.getExecutedBy());
                System.out.println("StateId:" + userTaskInstance.getStateId());
                System.out.println("StateName:" + userTaskInstance.getStateName());

the value AssigneeId: 0 (Must be 1002, because I assign to 102)

But, if I query my assigned (102) tasks I have assigned the task (580013)

My question is, Could be a BUG? because I want to send an email when the user got a task.

Update: If the assignation is auto the event show me correctly the user (102), but If the assignation is manual the assignedId will be 0... And if If useassignUserTask instead of assignUserTaskIfNotAssigned works well to

Comments

Submitted by julio.rey_1395310 on Fri, 03/29/2019 - 14:22

I downloaded the source code. the main difference in the class org.bonitasoft.engine.core.process.instance.impl.ActivityInstanceServiceImpl is

in the method assignHumanTask (Works well for me)
getRecorder().recordUpdate(UpdateRecord.buildSetFields(flowNodeInstance, descriptor), HUMAN_TASK_INSTANCE_ASSIGNEE);

and in the method assignHumanTaskIfNotAssigned(Works wrong for me)
the update sentence (event trigger) is
int updatedRows = getRecorder().recordUpdateWithQuery(UpdateRecord.buildSetFields(flowNodeInstance, descriptor),
HUMAN_TASK_INSTANCE_ASSIGNEE, QUERY_HUMAN_TASK_INSTANCE_ASSIGNEE );

I don't know what is the PersistenceService implementation to follow my problem in detail.

Submitted by julio.rey_1395310 on Fri, 03/29/2019 - 22:53

If assignHumanTaskIfNotAssigned, the update is the following

int updateCount = persistenceService.update(query, record.getFields());
        if(updateCount > 0 )
            eventService.fireEvent(createUpdateEvent(record.getEntity(), record.getFields(), type));
        return updateCount;

then the record.getEntity doesn't have the assignedId new value... but in assignHumanTask the update line is

@Override
public void recordUpdate(final UpdateRecord record, String type) throws SRecorderException {
    final UpdateDescriptor desc = UpdateDescriptor.buildSetFields(record.getEntity(), record.getFields());
    try {
        persistenceService.update(desc);
        eventService.fireEvent(createUpdateEvent(record.getEntity(), record.getFields(), type));
    } catch (final Exception e) {
        logExceptionsFromHandlers(e);
        throw new SRecorderException(e);
    }
}

and record.getEntity before the event trigger the update change the value of the property with the correct value

No answers yet.
Notifications