use of org.activiti.validation.ValidationError 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());
}
}
}
}
// Validation successfull (or no validation)
createImports();
createItemDefinitions();
createMessages();
createOperations();
transformProcessDefinitions();
} 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.ValidationError in project Activiti by Activiti.
the class DefaultProcessValidatorTest method verifyValidation.
@Test
public void verifyValidation() throws Exception {
InputStream xmlStream = this.getClass().getClassLoader().getResourceAsStream("org/activiti/engine/test/validation/invalidProcess.bpmn20.xml");
XMLInputFactory xif = XMLInputFactory.newInstance();
InputStreamReader in = new InputStreamReader(xmlStream, "UTF-8");
XMLStreamReader xtr = xif.createXMLStreamReader(in);
BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
Assert.assertNotNull(bpmnModel);
List<ValidationError> allErrors = processValidator.validate(bpmnModel);
Assert.assertEquals(65, allErrors.size());
// shortening it a bit
String setName = ValidatorSetNames.ACTIVITI_EXECUTABLE_PROCESS;
// isExecutable should be true
List<ValidationError> problems = findErrors(allErrors, setName, Problems.ALL_PROCESS_DEFINITIONS_NOT_EXECUTABLE, 1);
Assert.assertNotNull(problems.get(0).getValidatorSetName());
Assert.assertNotNull(problems.get(0).getProblem());
Assert.assertNotNull(problems.get(0).getDefaultDescription());
// Event listeners
problems = findErrors(allErrors, setName, Problems.EVENT_LISTENER_IMPLEMENTATION_MISSING, 1);
assertProcessElementError(problems.get(0));
problems = findErrors(allErrors, setName, Problems.EVENT_LISTENER_INVALID_THROW_EVENT_TYPE, 1);
assertProcessElementError(problems.get(0));
// Execution listeners
problems = findErrors(allErrors, setName, Problems.EXECUTION_LISTENER_IMPLEMENTATION_MISSING, 2);
assertProcessElementError(problems.get(0));
assertCommonProblemFieldForActivity(problems.get(1));
// Association
problems = findErrors(allErrors, setName, Problems.ASSOCIATION_INVALID_SOURCE_REFERENCE, 1);
assertProcessElementError(problems.get(0));
problems = findErrors(allErrors, setName, Problems.ASSOCIATION_INVALID_TARGET_REFERENCE, 1);
assertProcessElementError(problems.get(0));
// Signals
problems = findErrors(allErrors, setName, Problems.SIGNAL_MISSING_ID, 1);
assertCommonErrorFields(problems.get(0));
problems = findErrors(allErrors, setName, Problems.SIGNAL_MISSING_NAME, 2);
assertCommonErrorFields(problems.get(0));
assertCommonErrorFields(problems.get(1));
problems = findErrors(allErrors, setName, Problems.SIGNAL_DUPLICATE_NAME, 2);
assertCommonErrorFields(problems.get(0));
assertCommonErrorFields(problems.get(1));
problems = findErrors(allErrors, setName, Problems.SIGNAL_INVALID_SCOPE, 1);
assertCommonErrorFields(problems.get(0));
// Start event
problems = findErrors(allErrors, setName, Problems.START_EVENT_MULTIPLE_FOUND, 2);
assertCommonProblemFieldForActivity(problems.get(0));
assertCommonProblemFieldForActivity(problems.get(1));
problems = findErrors(allErrors, setName, Problems.START_EVENT_INVALID_EVENT_DEFINITION, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Sequence flow
problems = findErrors(allErrors, setName, Problems.SEQ_FLOW_INVALID_SRC, 1);
assertCommonProblemFieldForActivity(problems.get(0));
problems = findErrors(allErrors, setName, Problems.SEQ_FLOW_INVALID_TARGET, 2);
assertCommonProblemFieldForActivity(problems.get(0));
// User task
problems = findErrors(allErrors, setName, Problems.USER_TASK_LISTENER_IMPLEMENTATION_MISSING, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Service task
problems = findErrors(allErrors, setName, Problems.SERVICE_TASK_RESULT_VAR_NAME_WITH_DELEGATE, 1);
assertCommonProblemFieldForActivity(problems.get(0));
problems = findErrors(allErrors, setName, Problems.SERVICE_TASK_INVALID_TYPE, 1);
assertCommonProblemFieldForActivity(problems.get(0));
problems = findErrors(allErrors, setName, Problems.SERVICE_TASK_MISSING_IMPLEMENTATION, 1);
assertCommonProblemFieldForActivity(problems.get(0));
problems = findErrors(allErrors, setName, Problems.SERVICE_TASK_WEBSERVICE_INVALID_OPERATION_REF, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Send task
problems = findErrors(allErrors, setName, Problems.SEND_TASK_INVALID_IMPLEMENTATION, 1);
assertCommonProblemFieldForActivity(problems.get(0));
problems = findErrors(allErrors, setName, Problems.SEND_TASK_INVALID_TYPE, 1);
assertCommonProblemFieldForActivity(problems.get(0));
problems = findErrors(allErrors, setName, Problems.SEND_TASK_WEBSERVICE_INVALID_OPERATION_REF, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Mail task
problems = findErrors(allErrors, setName, Problems.MAIL_TASK_NO_RECIPIENT, 2);
assertCommonProblemFieldForActivity(problems.get(0));
assertCommonProblemFieldForActivity(problems.get(1));
problems = findErrors(allErrors, setName, Problems.MAIL_TASK_NO_CONTENT, 4);
assertCommonProblemFieldForActivity(problems.get(0));
assertCommonProblemFieldForActivity(problems.get(1));
// Shell task
problems = findErrors(allErrors, setName, Problems.SHELL_TASK_NO_COMMAND, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Script task
problems = findErrors(allErrors, setName, Problems.SCRIPT_TASK_MISSING_SCRIPT, 2);
assertCommonProblemFieldForActivity(problems.get(0));
assertCommonProblemFieldForActivity(problems.get(1));
// Exclusive gateway
problems = findErrors(allErrors, setName, Problems.EXCLUSIVE_GATEWAY_CONDITION_NOT_ALLOWED_ON_SINGLE_SEQ_FLOW, 1);
assertCommonProblemFieldForActivity(problems.get(0));
problems = findErrors(allErrors, setName, Problems.EXCLUSIVE_GATEWAY_CONDITION_ON_DEFAULT_SEQ_FLOW, 1);
assertCommonProblemFieldForActivity(problems.get(0));
problems = findErrors(allErrors, setName, Problems.EXCLUSIVE_GATEWAY_NO_OUTGOING_SEQ_FLOW, 1);
assertCommonProblemFieldForActivity(problems.get(0));
problems = findErrors(allErrors, setName, Problems.EXCLUSIVE_GATEWAY_SEQ_FLOW_WITHOUT_CONDITIONS, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Event gateway
problems = findErrors(allErrors, setName, Problems.EVENT_GATEWAY_ONLY_CONNECTED_TO_INTERMEDIATE_EVENTS, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Subprocesses
problems = findErrors(allErrors, setName, Problems.SUBPROCESS_MULTIPLE_START_EVENTS, 1);
assertCommonProblemFieldForActivity(problems.get(0));
problems = findErrors(allErrors, setName, Problems.SUBPROCESS_START_EVENT_EVENT_DEFINITION_NOT_ALLOWED, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Event subprocesses
problems = findErrors(allErrors, setName, Problems.EVENT_SUBPROCESS_INVALID_START_EVENT_DEFINITION, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Boundary events
problems = findErrors(allErrors, setName, Problems.BOUNDARY_EVENT_NO_EVENT_DEFINITION, 1);
assertCommonProblemFieldForActivity(problems.get(0));
problems = findErrors(allErrors, setName, Problems.BOUNDARY_EVENT_CANCEL_ONLY_ON_TRANSACTION, 1);
assertCommonProblemFieldForActivity(problems.get(0));
problems = findErrors(allErrors, setName, Problems.BOUNDARY_EVENT_MULTIPLE_CANCEL_ON_TRANSACTION, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Intermediate catch event
problems = findErrors(allErrors, setName, Problems.INTERMEDIATE_CATCH_EVENT_NO_EVENTDEFINITION, 1);
assertCommonProblemFieldForActivity(problems.get(0));
problems = findErrors(allErrors, setName, Problems.INTERMEDIATE_CATCH_EVENT_INVALID_EVENTDEFINITION, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Intermediate throw event
problems = findErrors(allErrors, setName, Problems.THROW_EVENT_INVALID_EVENTDEFINITION, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Multi instance
problems = findErrors(allErrors, setName, Problems.MULTI_INSTANCE_MISSING_COLLECTION, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Message events
problems = findErrors(allErrors, setName, Problems.MESSAGE_EVENT_MISSING_MESSAGE_REF, 2);
assertCommonProblemFieldForActivity(problems.get(0));
assertCommonProblemFieldForActivity(problems.get(1));
// Signal events
problems = findErrors(allErrors, setName, Problems.SIGNAL_EVENT_MISSING_SIGNAL_REF, 1);
assertCommonProblemFieldForActivity(problems.get(0));
problems = findErrors(allErrors, setName, Problems.SIGNAL_EVENT_INVALID_SIGNAL_REF, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Compensate event
problems = findErrors(allErrors, setName, Problems.COMPENSATE_EVENT_INVALID_ACTIVITY_REF, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Timer event
problems = findErrors(allErrors, setName, Problems.EVENT_TIMER_MISSING_CONFIGURATION, 2);
assertCommonProblemFieldForActivity(problems.get(0));
// Data association
problems = findErrors(allErrors, setName, Problems.DATA_ASSOCIATION_MISSING_TARGETREF, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Data object
problems = findErrors(allErrors, setName, Problems.DATA_OBJECT_MISSING_NAME, 2);
assertCommonErrorFields(problems.get(0));
assertCommonErrorFields(problems.get(1));
// End event
problems = findErrors(allErrors, setName, Problems.END_EVENT_CANCEL_ONLY_INSIDE_TRANSACTION, 1);
assertCommonProblemFieldForActivity(problems.get(0));
// Messages
problems = findErrors(allErrors, setName, Problems.MESSAGE_INVALID_ITEM_REF, 1);
assertCommonErrorFields(problems.get(0));
}
use of org.activiti.validation.ValidationError in project Activiti by Activiti.
the class DefaultProcessValidatorTest method testAllNonExecutableProcesses.
/*
* Test for https://activiti.atlassian.net/browse/ACT-2071:
*
* If all processes in a deployment are not executable, throw an exception
* as this doesn't make sense to do.
*/
@Test
public void testAllNonExecutableProcesses() {
BpmnModel bpmnModel = new BpmnModel();
for (int i = 0; i < 5; i++) {
org.activiti.bpmn.model.Process process = TestProcessUtil.createOneTaskProcess();
process.setExecutable(false);
bpmnModel.addProcess(process);
}
List<ValidationError> errors = processValidator.validate(bpmnModel);
Assert.assertEquals(1, errors.size());
}
use of org.activiti.validation.ValidationError in project Activiti by Activiti.
the class InCompleteSignalConverterTest method validateModel.
private void validateModel(BpmnModel model) {
FlowElement flowElement = model.getMainProcess().getFlowElement("task");
assertNotNull(flowElement);
assertTrue(flowElement instanceof UserTask);
assertEquals("task", flowElement.getId());
ProcessValidator processValidator = new ProcessValidatorFactory().createDefaultProcessValidator();
List<ValidationError> errors = processValidator.validate(model);
assertNotNull(errors);
assertEquals(2, errors.size());
}
use of org.activiti.validation.ValidationError in project Activiti by Activiti.
the class ValidatorImpl method addError.
protected void addError(List<ValidationError> validationErrors, String problem, Process process, BaseElement baseElement, String description, boolean isWarning) {
ValidationError error = new ValidationError();
error.setWarning(isWarning);
if (process != null) {
error.setProcessDefinitionId(process.getId());
error.setProcessDefinitionName(process.getName());
}
if (baseElement != null) {
error.setXmlLineNumber(baseElement.getXmlRowNumber());
error.setXmlColumnNumber(baseElement.getXmlColumnNumber());
}
error.setProblem(problem);
error.setDefaultDescription(description);
if (baseElement instanceof FlowElement) {
FlowElement flowElement = (FlowElement) baseElement;
error.setActivityId(flowElement.getId());
error.setActivityName(flowElement.getName());
}
addError(validationErrors, error);
}
Aggregations