import org.activiti.engine.delegate.event.ActivitiEntityEvent;
import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.valz.framework.common.utility.StringUtility;
public class ValzActivitiEventListener implements ActivitiEventListener {
@Override
public boolean isFailOnException() {
return false;
}
@Override
public void onEvent(ActivitiEvent event) {
switch (event.getType()) {
case TASK_CREATED: {
ActivitiEntityEvent activityEntityEvent = (ActivitiEntityEvent) event;
TaskEntity taskEntity = (TaskEntity) activityEntityEvent.getEntity();
ExecutionEntity exEntity = taskEntity.getProcessInstance();
String prevTaskId =(String) exEntity.getVariable("prevTaskId");
if(StringUtility.isNullOrEmpty( prevTaskId ))
prevTaskId=taskEntity.getId();
taskEntity.setVariableLocal("prevTaskId", prevTaskId);
}
break;
default:
}
}
}
答案 0 :(得分:1)
我认为TaskListener应该为您服务
@Component
@Slf4j
public class HumanTaskListener implements TaskListener {
@Override
public void notify(final DelegateTask delegateTask) {
LOGGER.debug("Notify... {}", delegateTask);
}
}
并注册监听器
@Component
public class HumanTaskBpmnListener extends AbstractBpmnParseListener {
@Autowired
private HumanTaskListener humanTaskListener;
@Override
public void parseUserTask(final Element humanTaskElement, final ScopeImpl scope, final ActivityImpl activity) {
final TaskDefinition taskDefinition = ((UserTaskActivityBehavior) activity.getActivityBehavior()).getTaskDefinition();
taskDefinition.addBuiltInTaskListener(TaskListener.EVENTNAME_CREATE, humanTaskListener);
}
}