Search in sources :

Example 1 with ProcessValidator

use of org.activiti.validation.ProcessValidator in project Activiti by Activiti.

the class InCompleteSignalConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    FlowElement flowElement = model.getMainProcess().getFlowElement("task");
    assertThat(flowElement).isNotNull();
    assertThat(flowElement).isInstanceOf(UserTask.class);
    assertThat(flowElement.getId()).isEqualTo("task");
    ProcessValidator processValidator = new ProcessValidatorFactory().createDefaultProcessValidator();
    List<ValidationError> errors = processValidator.validate(model);
    assertThat(errors).isNotNull();
    assertThat(errors).hasSize(2);
}
Also used : FlowElement(org.activiti.bpmn.model.FlowElement) ProcessValidatorFactory(org.activiti.validation.ProcessValidatorFactory) ValidationError(org.activiti.validation.ValidationError) ProcessValidator(org.activiti.validation.ProcessValidator)

Example 2 with ProcessValidator

use of org.activiti.validation.ProcessValidator 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 ProcessValidator

use of org.activiti.validation.ProcessValidator in project Activiti by Activiti.

the class ProcessEngineAutoConfigurationTest method shouldAddAsyncPropertyValidatorWhenAsyncExecutorIsEnabled.

@Test
public void shouldAddAsyncPropertyValidatorWhenAsyncExecutorIsEnabled() {
    // given
    ActivitiProperties activitiProperties = new ActivitiProperties();
    activitiProperties.setAsyncExecutorActivate(false);
    SpringProcessEngineConfiguration conf = new SpringProcessEngineConfiguration(applicationUpgradeContextServiceMock);
    // when
    processEngineAutoConfiguration.addAsyncPropertyValidator(activitiProperties, conf);
    // then
    ProcessValidator processValidator = conf.getProcessValidator();
    assertThat(processValidator).isNotNull();
    assertThat(processValidator.getValidatorSets()).flatExtracting(ValidatorSet::getValidators).haveExactly(1, new Condition<>(validator -> validator instanceof AsyncPropertyValidator, "instance of AsyncPropertyValidator"));
}
Also used : SpringProcessEngineConfiguration(org.activiti.spring.SpringProcessEngineConfiguration) Test(org.junit.jupiter.api.Test) InjectMocks(org.mockito.InjectMocks) ApplicationUpgradeContextService(org.activiti.core.common.spring.project.ApplicationUpgradeContextService) BeforeEach(org.junit.jupiter.api.BeforeEach) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ValidatorSet(org.activiti.validation.validator.ValidatorSet) Condition(org.assertj.core.api.Condition) AsyncPropertyValidator(org.activiti.spring.boot.process.validation.AsyncPropertyValidator) ProcessValidator(org.activiti.validation.ProcessValidator) SpringProcessEngineConfiguration(org.activiti.spring.SpringProcessEngineConfiguration) ProcessValidator(org.activiti.validation.ProcessValidator) AsyncPropertyValidator(org.activiti.spring.boot.process.validation.AsyncPropertyValidator) Test(org.junit.jupiter.api.Test)

Example 4 with ProcessValidator

use of org.activiti.validation.ProcessValidator in project Activiti by Activiti.

the class ProcessEngineAutoConfigurationTest method shouldNotAddAsyncPropertyValidatorWhenAsyncExecutorIsDisabled.

@Test
public void shouldNotAddAsyncPropertyValidatorWhenAsyncExecutorIsDisabled() {
    // given
    ActivitiProperties activitiProperties = new ActivitiProperties();
    activitiProperties.setAsyncExecutorActivate(true);
    SpringProcessEngineConfiguration conf = new SpringProcessEngineConfiguration(applicationUpgradeContextServiceMock);
    // when
    processEngineAutoConfiguration.addAsyncPropertyValidator(activitiProperties, conf);
    // then
    ProcessValidator processValidator = conf.getProcessValidator();
    assertThat(processValidator).isNull();
}
Also used : SpringProcessEngineConfiguration(org.activiti.spring.SpringProcessEngineConfiguration) ProcessValidator(org.activiti.validation.ProcessValidator) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessValidator (org.activiti.validation.ProcessValidator)4 SpringProcessEngineConfiguration (org.activiti.spring.SpringProcessEngineConfiguration)2 ValidationError (org.activiti.validation.ValidationError)2 Test (org.junit.jupiter.api.Test)2 MalformedURLException (java.net.MalformedURLException)1 BpmnXMLConverter (org.activiti.bpmn.converter.BpmnXMLConverter)1 XMLException (org.activiti.bpmn.exceptions.XMLException)1 FlowElement (org.activiti.bpmn.model.FlowElement)1 ApplicationUpgradeContextService (org.activiti.core.common.spring.project.ApplicationUpgradeContextService)1 ActivitiException (org.activiti.engine.ActivitiException)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 ActivitiEventSupport (org.activiti.engine.delegate.event.impl.ActivitiEventSupport)1 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)1 AsyncPropertyValidator (org.activiti.spring.boot.process.validation.AsyncPropertyValidator)1 ProcessValidatorFactory (org.activiti.validation.ProcessValidatorFactory)1 ValidatorSet (org.activiti.validation.validator.ValidatorSet)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Condition (org.assertj.core.api.Condition)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 InjectMocks (org.mockito.InjectMocks)1