Skip to content

Commit

Permalink
Fix duplicate process end notifications (MID-4850)
Browse files Browse the repository at this point in the history
When process has finished during the start() call, an extra "process
finished" event was generated.
  • Loading branch information
mederly committed Sep 18, 2018
1 parent 5787be2 commit 9cf7bb6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Expand Up @@ -103,7 +103,7 @@ public void startActivitiProcessInstance(StartProcessCommand spic, Task task, Op
processInterfaceFinder);
event.setRunning(!pi.isEnded());
LOGGER.trace("Event to be sent to IDM: {}", event);
wfTaskController.onProcessEvent(event, task, result);
wfTaskController.onProcessEvent(event, true, task, result);
}
}

Expand Down Expand Up @@ -150,7 +150,7 @@ public void queryActivitiProcessInstance(QueryProcessCommand qpc, Task task, Ope
LOGGER.trace("Running process instance = {}, isRunning: {}", pi, qpr.isRunning());
LOGGER.trace("Response to be sent to midPoint: {}", qpr);

wfTaskController.onProcessEvent(qpr, task, result);
wfTaskController.onProcessEvent(qpr, false, task, result);
}

public void notifyMidpointAboutProcessFinishedEvent(DelegateExecution execution) {
Expand All @@ -176,7 +176,7 @@ private void notifyMidpointAboutProcessEvent(ProcessEvent event) {
return;
}
try {
wfTaskController.onProcessEvent(event, task, result);
wfTaskController.onProcessEvent(event, false, task, result);
} catch (SchemaException|ObjectNotFoundException|ObjectAlreadyExistsException|RuntimeException e) {
throw new SystemException("Couldn't process a process-related event: " + e.getMessage(), e);
}
Expand Down
Expand Up @@ -49,7 +49,6 @@
import com.evolveum.midpoint.wf.impl.processors.primary.PcpWfTask;
import com.evolveum.midpoint.wf.impl.processors.primary.PrimaryChangeProcessor;
import com.evolveum.midpoint.wf.impl.util.MiscDataUtil;
import com.evolveum.midpoint.wf.util.ApprovalUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType;
import org.apache.commons.lang.BooleanUtils;
Expand Down Expand Up @@ -230,7 +229,12 @@ private void startWorkflowProcessInstance(WfTask wfTask, WfTaskCreationInstructi
LOGGER.trace("startWorkflowProcessInstance finished");
}

public void onProcessEvent(ProcessEvent event, Task task, OperationResult result)
// skipProcessEndNotification is a bit of hack: It is to avoid sending process end notification twice if the process ends
// in the same thread in which it was started (MID-4850). It could be probably solved in a more brave way e.g. by removing
// the whole onProcessEvent call in startActivitiProcessInstance but that could have other consequences.
//
// We get rid of these hacks when we replace Activiti with our own implementation (4.0 or 4.1).
public void onProcessEvent(ProcessEvent event, boolean skipProcessEndNotification, Task task, OperationResult result)
throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException {
WfTask wfTask = recreateWfTask(task);

Expand All @@ -249,7 +253,7 @@ public void onProcessEvent(ProcessEvent event, Task task, OperationResult result

wfTask.commitChanges(result);

if (event instanceof ProcessFinishedEvent || !event.isRunning()) {
if (!skipProcessEndNotification && (event instanceof ProcessFinishedEvent || !event.isRunning())) {
onProcessFinishedEvent(event, wfTask, result);
}
}
Expand Down
Expand Up @@ -161,6 +161,8 @@ boolean decideOnApproval(String executionId) throws Exception {
return decideOnRoleApproval(executionId);
}
});
displayAllNotifications();
checkDummyTransportMessages("simpleWorkflowNotifier-Processes", 2); // start + end
}

protected void assertWfContextAfterClockworkRun(Task rootTask, List<Task> subtasks, OperationResult result, String... processNames) throws Exception {
Expand Down Expand Up @@ -774,6 +776,8 @@ boolean decideOnApproval(String executionId) throws Exception {
}

});
displayAllNotifications();
checkDummyTransportMessages("simpleWorkflowNotifier-Processes", 2); // start + end
}

@Test(enabled = true)
Expand Down Expand Up @@ -838,6 +842,8 @@ boolean decideOnApproval(String executionId) throws Exception {
}

});
displayAllNotifications();
checkDummyTransportMessages("simpleWorkflowNotifier-Processes", 2); // start + end
}

@Test
Expand Down

0 comments on commit 9cf7bb6

Please sign in to comment.