use of org.activiti.engine.delegate.event.impl.ActivitiEventSupport in project Activiti by Activiti.
the class ProcessDefinitionEntity method readObject.
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
eventSupport = new ActivitiEventSupport();
}
use of org.activiti.engine.delegate.event.impl.ActivitiEventSupport in project Activiti by Activiti.
the class BpmnParse method execute.
public BpmnParse execute() {
try {
ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
BpmnXMLConverter converter = new BpmnXMLConverter();
boolean enableSafeBpmnXml = false;
String encoding = null;
if (processEngineConfiguration != null) {
enableSafeBpmnXml = processEngineConfiguration.isEnableSafeBpmnXml();
encoding = processEngineConfiguration.getXmlEncoding();
}
if (encoding != null) {
bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml, encoding);
} else {
bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml);
}
// XSD validation goes first, then process/semantic validation
if (validateProcess) {
ProcessValidator processValidator = processEngineConfiguration.getProcessValidator();
if (processValidator == null) {
LOGGER.warn("Process should be validated, but no process validator is configured on the process engine configuration!");
} else {
List<ValidationError> validationErrors = processValidator.validate(bpmnModel);
if (validationErrors != null && !validationErrors.isEmpty()) {
StringBuilder warningBuilder = new StringBuilder();
StringBuilder errorBuilder = new StringBuilder();
for (ValidationError error : validationErrors) {
if (error.isWarning()) {
warningBuilder.append(error.toString());
warningBuilder.append("\n");
} else {
errorBuilder.append(error.toString());
errorBuilder.append("\n");
}
}
// Throw exception if there is any error
if (errorBuilder.length() > 0) {
throw new ActivitiException("Errors while parsing:\n" + errorBuilder.toString());
}
// Write out warnings (if any)
if (warningBuilder.length() > 0) {
LOGGER.warn("Following warnings encountered during process validation: " + warningBuilder.toString());
}
}
}
}
bpmnModel.setSourceSystemId(sourceSystemId);
bpmnModel.setEventSupport(new ActivitiEventSupport());
// Validation successful (or no validation)
// Attach logic to the processes (eg. map ActivityBehaviors to bpmn model elements)
applyParseHandlers();
// Finally, process the diagram interchange info
processDI();
} catch (Exception e) {
if (e instanceof ActivitiException) {
throw (ActivitiException) e;
} else if (e instanceof XMLException) {
throw (XMLException) e;
} else {
throw new ActivitiException("Error parsing XML", e);
}
}
return this;
}
use of org.activiti.engine.delegate.event.impl.ActivitiEventSupport in project Activiti by Activiti.
the class ProcessDefinitionScopedEventListenerTest method testProcessDefinitionScopedListener.
/**
* Test to verify listeners on a process-definition are only called for events related to that definition.
*/
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml", "org/activiti/engine/test/api/event/simpleProcess.bpmn20.xml" })
public void testProcessDefinitionScopedListener() throws Exception {
ProcessDefinition firstDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentIdFromDeploymentAnnotation).processDefinitionKey("oneTaskProcess").singleResult();
assertThat(firstDefinition).isNotNull();
ProcessDefinition secondDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentIdFromDeploymentAnnotation).processDefinitionKey("simpleProcess").singleResult();
assertThat(firstDefinition).isNotNull();
// Fetch a reference to the process definition entity to add the listener
TestActivitiEventListener listener = new TestActivitiEventListener();
BpmnModel bpmnModel = repositoryService.getBpmnModel(firstDefinition.getId());
assertThat(bpmnModel).isNotNull();
((ActivitiEventSupport) bpmnModel.getEventSupport()).addEventListener(listener);
// Start a process for the first definition, events should be received
ProcessInstance processInstance = runtimeService.startProcessInstanceById(firstDefinition.getId());
assertThat(processInstance).isNotNull();
assertThat(listener.getEventsReceived().isEmpty()).isFalse();
listener.clearEventsReceived();
// Start an instance of the other definition
ProcessInstance otherInstance = runtimeService.startProcessInstanceById(secondDefinition.getId());
assertThat(otherInstance).isNotNull();
assertThat(listener.getEventsReceived().isEmpty()).isTrue();
}
Aggregations