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);
}
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;
}
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"));
}
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();
}
Aggregations