on 2023 Nov 13 9:23 PM
I use a PrepareInterceptor to detect specific changes made to the model. When one of those changes is detected, I need to fire a business process. However, doing so is recalling the interceptor over and over again. I configured my interceptor to only execute on a specific type. I don't understand why my interceptor is called after saving the process model.
public void onPrepare(MyModel itemModel, InterceptorContext interceptorContext) throws InterceptorException {
if (conditionIsMet(itemModel)) {
itemModel.setAttributeA(someValue);
itemModel.setAttributeB(someOtherValue);
MyProcessModel myProcesModel = businessProcessService.createProcess("someId", "myProcessName");
myProcess.setAttributeXYZ(someXYZValue);
modelService.save(myProcessModel);
}
}
Request clarification before answering.
As suggested in the documentation "To modify models within interceptors, use registerElementFor() instead of the modelService.save() and modelService.remove() methods."
I am not sure about whether triggering a BusinessProcess from an interceptor cause an issue but within the same documentation it is suggested that "To avoid issues with thread or process synchronization, do not use the eventService.publishEvent() method from within interceptors." So you may want to find another way to trigger BusinessProcess to stay within the safe-side.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
businessProcessService.startProcess() is calling an internal method which does this which as you can see is calling save from modelService...
protected void doStartProcessInsideTx(ProcessDefinition processDefinition, BusinessProcessModel process) {
processDefinition.start(process);
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Setting state of process with code %s to RUNNING", process.getCode()));
}
process.setState(ProcessState.RUNNING);
this.getModelService().save(process);
}
Then you need to find another way to trigger BusinessProcess instead of interceptor. Maybe you can create an attribute on the model to specify business process needs to be triggered and within a Job trigger BusinessProcesses then reset the attribute.
I also tried with creating my business process within a different context like this but I still get error
sessionService.executeInLocalView(new SessionExecutionBody()
{
@Override
public void executeWithoutResult()
{
MyProcessModel processModel = createMyProcessModel(...);
businessProcessService.startProcess(processModel);
}
});
User | Count |
---|---|
19 | |
5 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.