Search in sources :

Example 1 with ActivitiEventSupport

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();
}
Also used : ActivitiEventSupport(org.activiti.engine.delegate.event.impl.ActivitiEventSupport)

Example 2 with 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;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) XMLException(org.activiti.bpmn.exceptions.XMLException) ValidationError(org.activiti.validation.ValidationError) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ProcessValidator(org.activiti.validation.ProcessValidator) ActivitiEventSupport(org.activiti.engine.delegate.event.impl.ActivitiEventSupport) ActivitiException(org.activiti.engine.ActivitiException) XMLException(org.activiti.bpmn.exceptions.XMLException) MalformedURLException(java.net.MalformedURLException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter)

Example 3 with ActivitiEventSupport

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();
}
Also used : ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEventSupport(org.activiti.engine.delegate.event.impl.ActivitiEventSupport) BpmnModel(org.activiti.bpmn.model.BpmnModel) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ActivitiEventSupport (org.activiti.engine.delegate.event.impl.ActivitiEventSupport)3 MalformedURLException (java.net.MalformedURLException)1 BpmnXMLConverter (org.activiti.bpmn.converter.BpmnXMLConverter)1 XMLException (org.activiti.bpmn.exceptions.XMLException)1 BpmnModel (org.activiti.bpmn.model.BpmnModel)1 ActivitiException (org.activiti.engine.ActivitiException)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)1 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)1 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1 Deployment (org.activiti.engine.test.Deployment)1 ProcessValidator (org.activiti.validation.ProcessValidator)1 ValidationError (org.activiti.validation.ValidationError)1