use of org.activiti.bpmn.model.BpmnModel in project Activiti by Activiti.
the class ProcessDefinitionImageStreamResourceBuilder method buildStreamResource.
public StreamResource buildStreamResource(String processInstanceId, String processDefinitionId, RepositoryService repositoryService, RuntimeService runtimeService, ProcessDiagramGenerator diagramGenerator, ProcessEngineConfiguration processEngineConfig) {
StreamResource imageResource = null;
ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processDefinitionId);
if (processDefinition != null && processDefinition.isGraphicalNotationDefined()) {
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
InputStream definitionImageStream = diagramGenerator.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processInstanceId), Collections.<String>emptyList(), processEngineConfig.getActivityFontName(), processEngineConfig.getLabelFontName(), processEngineConfig.getAnnotationFontName(), processEngineConfig.getClassLoader(), 1.0);
StreamSource streamSource = new InputStreamStreamSource(definitionImageStream);
// Create image name
String imageExtension = extractImageExtension(processDefinition.getDiagramResourceName());
String fileName = processInstanceId + UUID.randomUUID() + "." + imageExtension;
imageResource = new StreamResource(streamSource, fileName, ExplorerApp.get());
}
return imageResource;
}
use of org.activiti.bpmn.model.BpmnModel in project Activiti by Activiti.
the class RepositoryServiceTest method testGetBpmnModel.
@Deployment
public void testGetBpmnModel() {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
// Some basic assertions
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
assertNotNull(bpmnModel);
assertEquals(1, bpmnModel.getProcesses().size());
assertTrue(!bpmnModel.getLocationMap().isEmpty());
assertTrue(!bpmnModel.getFlowLocationMap().isEmpty());
// Test the flow
org.activiti.bpmn.model.Process process = bpmnModel.getProcesses().get(0);
List<StartEvent> startEvents = process.findFlowElementsOfType(StartEvent.class);
assertEquals(1, startEvents.size());
StartEvent startEvent = startEvents.get(0);
assertEquals(1, startEvent.getOutgoingFlows().size());
assertEquals(0, startEvent.getIncomingFlows().size());
String nextElementId = startEvent.getOutgoingFlows().get(0).getTargetRef();
UserTask userTask = (UserTask) process.getFlowElement(nextElementId);
assertEquals("First Task", userTask.getName());
assertEquals(1, userTask.getOutgoingFlows().size());
assertEquals(1, userTask.getIncomingFlows().size());
nextElementId = userTask.getOutgoingFlows().get(0).getTargetRef();
ParallelGateway parallelGateway = (ParallelGateway) process.getFlowElement(nextElementId);
assertEquals(2, parallelGateway.getOutgoingFlows().size());
nextElementId = parallelGateway.getOutgoingFlows().get(0).getTargetRef();
assertEquals(1, parallelGateway.getIncomingFlows().size());
userTask = (UserTask) process.getFlowElement(nextElementId);
assertEquals(1, userTask.getOutgoingFlows().size());
nextElementId = userTask.getOutgoingFlows().get(0).getTargetRef();
parallelGateway = (ParallelGateway) process.getFlowElement(nextElementId);
assertEquals(1, parallelGateway.getOutgoingFlows().size());
assertEquals(2, parallelGateway.getIncomingFlows().size());
nextElementId = parallelGateway.getOutgoingFlows().get(0).getTargetRef();
EndEvent endEvent = (EndEvent) process.getFlowElement(nextElementId);
assertEquals(0, endEvent.getOutgoingFlows().size());
assertEquals(1, endEvent.getIncomingFlows().size());
}
use of org.activiti.bpmn.model.BpmnModel in project Activiti by Activiti.
the class ImportUploadReceiver method deployUploadedFile.
protected void deployUploadedFile() {
try {
try {
if (fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn")) {
validFile = true;
XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
InputStreamReader in = new InputStreamReader(new ByteArrayInputStream(outputStream.toByteArray()), "UTF-8");
XMLStreamReader xtr = xif.createXMLStreamReader(in);
BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
if (bpmnModel.getMainProcess() == null || bpmnModel.getMainProcess().getId() == null) {
notificationManager.showErrorNotification(Messages.MODEL_IMPORT_FAILED, i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_BPMN_EXPLANATION));
} else {
if (bpmnModel.getLocationMap().isEmpty()) {
notificationManager.showErrorNotification(Messages.MODEL_IMPORT_INVALID_BPMNDI, i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_BPMNDI_EXPLANATION));
} else {
String processName = null;
if (StringUtils.isNotEmpty(bpmnModel.getMainProcess().getName())) {
processName = bpmnModel.getMainProcess().getName();
} else {
processName = bpmnModel.getMainProcess().getId();
}
modelData = repositoryService.newModel();
ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
modelObjectNode.put(MODEL_NAME, processName);
modelObjectNode.put(MODEL_REVISION, 1);
modelData.setMetaInfo(modelObjectNode.toString());
modelData.setName(processName);
repositoryService.saveModel(modelData);
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
ObjectNode editorNode = jsonConverter.convertToJson(bpmnModel);
repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
}
}
} else {
notificationManager.showErrorNotification(Messages.MODEL_IMPORT_INVALID_FILE, i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_FILE_EXPLANATION));
}
} catch (Exception e) {
String errorMsg = e.getMessage().replace(System.getProperty("line.separator"), "<br/>");
notificationManager.showErrorNotification(Messages.MODEL_IMPORT_FAILED, errorMsg);
}
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
notificationManager.showErrorNotification("Server-side error", e.getMessage());
}
}
}
}
use of org.activiti.bpmn.model.BpmnModel 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.bpmn.model.BpmnModel 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());
}
Aggregations