use of org.activiti.engine.TaskService in project Activiti by Activiti.
the class WorkflowConversionTest method testMultipleConditionsInChoice.
@Test
public void testMultipleConditionsInChoice() throws Exception {
TaskService taskService = activitiRule.getTaskService();
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").inChoice().inList().addCondition("test", "==", "'hello'").addCondition("test2", "==", "'world'").addHumanStep("first task", "kermit").endList().inList().addHumanStep("gonzo task", "gonzo").endList().endChoice();
// Validate
Map<String, Object> varMap = new HashMap<String, Object>();
varMap.put("test", "hello");
varMap.put("test2", "world");
String definitionKey = convertAndDeploy(workflowDefinition);
ProcessInstance instance = activitiRule.getRuntimeService().startProcessInstanceByKey(definitionKey, varMap);
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
assertEquals(0, taskService.createTaskQuery().taskAssignee("gonzo").count());
Task task = taskService.createTaskQuery().singleResult();
assertEquals("first task", task.getName());
taskService.complete(task.getId());
assertEquals(0, activitiRule.getRuntimeService().createProcessInstanceQuery().processInstanceId(instance.getId()).count());
varMap = new HashMap<String, Object>();
varMap.put("test", "world");
varMap.put("test2", "world");
instance = activitiRule.getRuntimeService().startProcessInstanceByKey(definitionKey, varMap);
assertEquals(0, taskService.createTaskQuery().taskAssignee("kermit").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("gonzo").count());
task = taskService.createTaskQuery().singleResult();
assertEquals("gonzo task", task.getName());
taskService.complete(task.getId());
assertEquals(0, activitiRule.getRuntimeService().createProcessInstanceQuery().processInstanceId(instance.getId()).count());
}
use of org.activiti.engine.TaskService in project Activiti by Activiti.
the class WorkflowConversionTest method testFeedbackStepWithUserSelectionAtRuntimeAllFeedbackProvided.
@Test
public void testFeedbackStepWithUserSelectionAtRuntimeAllFeedbackProvided() {
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").addFeedbackStep("Test feedback", "kermit");
activitiRule.getRuntimeService().startProcessInstanceByKey(convertAndDeploy(workflowDefinition));
// First, a task should be assigned to kermit to select the people
assertEquals(1, taskService.createTaskQuery().count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
Task task = taskService.createTaskQuery().singleResult();
// Completing the task using the predefined process variable (normally done through the form)
TaskService taskService = activitiRule.getTaskService();
taskService.complete(task.getId(), CollectionUtil.singletonMap(FeedbackStepDefinitionConverter.VARIABLE_FEEDBACK_PROVIDERS, Arrays.asList("gonzo", "fozzie")));
// Three tasks should be available now
assertEquals(3, taskService.createTaskQuery().count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("gonzo").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("fozzie").count());
// Completing the feedback tasks first should only leave the 'gather feedback' task for kermit open
for (Task feedbackTask : taskService.createTaskQuery().list()) {
if (!feedbackTask.getAssignee().equals("kermit")) {
activitiRule.getTaskService().complete(feedbackTask.getId());
}
}
assertEquals(1, taskService.createTaskQuery().count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
// Completing this last task should finish the process
activitiRule.getTaskService().complete(activitiRule.getTaskService().createTaskQuery().singleResult().getId());
assertEquals(0, activitiRule.getRuntimeService().createProcessInstanceQuery().count());
}
use of org.activiti.engine.TaskService in project Activiti by Activiti.
the class WorkflowConversionTest method testUserTasksInChoice.
@Test
public void testUserTasksInChoice() throws Exception {
TaskService taskService = activitiRule.getTaskService();
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").inChoice().inList().addCondition("test", "==", "'hello'").addHumanStep("first task", "kermit").addHumanStep("second task", "kermit").endList().inList().addHumanStep("gonzo task", "gonzo").endList().endChoice().addHumanStep("last task", "kermit");
// Validate
Map<String, Object> varMap = new HashMap<String, Object>();
varMap.put("test", "hello");
String definitionKey = convertAndDeploy(workflowDefinition);
ProcessInstance instance = activitiRule.getRuntimeService().startProcessInstanceByKey(definitionKey, varMap);
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
assertEquals(0, taskService.createTaskQuery().taskAssignee("gonzo").count());
Task task = taskService.createTaskQuery().singleResult();
assertEquals("first task", task.getName());
taskService.complete(task.getId());
task = taskService.createTaskQuery().singleResult();
assertEquals("second task", task.getName());
taskService.complete(task.getId());
task = taskService.createTaskQuery().singleResult();
assertEquals("last task", task.getName());
taskService.complete(task.getId());
assertEquals(0, activitiRule.getRuntimeService().createProcessInstanceQuery().processInstanceId(instance.getId()).count());
varMap = new HashMap<String, Object>();
varMap.put("test", "world");
instance = activitiRule.getRuntimeService().startProcessInstanceByKey(definitionKey, varMap);
assertEquals(0, taskService.createTaskQuery().taskAssignee("kermit").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("gonzo").count());
task = taskService.createTaskQuery().singleResult();
assertEquals("gonzo task", task.getName());
taskService.complete(task.getId());
task = taskService.createTaskQuery().singleResult();
assertEquals("last task", task.getName());
taskService.complete(task.getId());
assertEquals(0, activitiRule.getRuntimeService().createProcessInstanceQuery().processInstanceId(instance.getId()).count());
}
use of org.activiti.engine.TaskService in project Activiti by Activiti.
the class ProcessDefinitionInfoCacheTest method testStartProcessInstanceByIdAfterReboot.
// Test for a bug: when the process engine is rebooted the
// cache is cleaned and the deployed process definition is
// removed from the process cache. This led to problems because
// the id wasn't fetched from the DB after a redeploy.
public void testStartProcessInstanceByIdAfterReboot() {
// In case this test is run in a test suite, previous engines might
// have been initialized and cached. First we close the
// existing process engines to make sure that the db is clean
// and that there are no existing process engines involved.
ProcessEngines.destroy();
// Creating the DB schema (without building a process engine)
ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
processEngineConfiguration.setProcessEngineName("reboot-info-test-schema");
processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-info-test;DB_CLOSE_DELAY=1000");
ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine();
// Create process engine and deploy test process
ProcessEngine processEngine = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-info-test").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-reboot-info-test;DB_CLOSE_DELAY=1000").setJobExecutorActivate(false).setEnableProcessDefinitionInfoCache(true).buildProcessEngine();
processEngine.getRepositoryService().createDeployment().addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml").deploy();
// verify existance of process definiton
List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();
assertEquals(1, processDefinitions.size());
String processDefinitionId = processDefinitions.get(0).getId();
ObjectNode infoNode = processEngine.getDynamicBpmnService().getProcessDefinitionInfo(processDefinitionId);
assertNotNull(infoNode);
infoNode = processEngineConfiguration.getObjectMapper().createObjectNode();
infoNode.put("test", "test");
processEngine.getDynamicBpmnService().saveProcessDefinitionInfo(processDefinitionId, infoNode);
infoNode = processEngine.getDynamicBpmnService().getProcessDefinitionInfo(processDefinitionId);
assertNotNull(infoNode);
assertEquals("test", infoNode.get("test").asText());
// Start a new Process instance
ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitionId);
String processInstanceId = processInstance.getId();
assertNotNull(processInstance);
// Close the process engine
processEngine.close();
assertNotNull(processEngine.getRuntimeService());
// Reboot the process engine
processEngine = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-info-test").setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-reboot-info-test;DB_CLOSE_DELAY=1000").setJobExecutorActivate(false).setEnableProcessDefinitionInfoCache(true).buildProcessEngine();
infoNode = processEngine.getDynamicBpmnService().getProcessDefinitionInfo(processDefinitionId);
assertNotNull(infoNode);
assertEquals("test", infoNode.get("test").asText());
// Check if the existing process instance is still alive
processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
assertNotNull(processInstance);
// Complete the task. That will end the process instance
TaskService taskService = processEngine.getTaskService();
Task task = taskService.createTaskQuery().list().get(0);
taskService.complete(task.getId());
// Check if the process instance has really ended. This means that the process definition has
// re-loaded into the process definition cache
processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
assertNull(processInstance);
// Extra check to see if a new process instance can be started as well
processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
assertNotNull(processInstance);
// close the process engine
processEngine.close();
// Cleanup schema
schemaProcessEngine.close();
}
use of org.activiti.engine.TaskService in project Activiti by Activiti.
the class ImageAttachmentRenderer method getDetailComponent.
@Override
public Component getDetailComponent(Attachment attachment) {
VerticalLayout verticalLayout = new VerticalLayout();
verticalLayout.setSizeUndefined();
verticalLayout.setSpacing(true);
verticalLayout.setMargin(true);
Label description = new Label(attachment.getDescription());
description.setSizeUndefined();
verticalLayout.addComponent(description);
// Image
TaskService taskService = ProcessEngines.getDefaultProcessEngine().getTaskService();
String mimeType = extractMineType(attachment.getType());
InputStream imageStream = ImageUtil.resizeImage(taskService.getAttachmentContent(attachment.getId()), mimeType, 900, 550);
Resource resource = new StreamResource(new InputStreamStreamSource(imageStream), attachment.getName() + extractExtention(attachment.getType()), ExplorerApp.get());
Embedded image = new Embedded(null, resource);
verticalLayout.addComponent(image);
// Linke
HorizontalLayout LinkLayout = new HorizontalLayout();
LinkLayout.setSpacing(true);
verticalLayout.addComponent(LinkLayout);
verticalLayout.setComponentAlignment(LinkLayout, Alignment.MIDDLE_CENTER);
Label fullSizeLabel = new Label(ExplorerApp.get().getI18nManager().getMessage(Messages.RELATED_CONTENT_SHOW_FULL_SIZE));
LinkLayout.addComponent(fullSizeLabel);
Link link = null;
if (attachment.getUrl() != null) {
link = new Link(attachment.getUrl(), new ExternalResource(attachment.getUrl()));
} else {
taskService = ProcessEngines.getDefaultProcessEngine().getTaskService();
Resource res = new StreamResource(new InputStreamStreamSource(taskService.getAttachmentContent(attachment.getId())), attachment.getName() + extractExtention(attachment.getType()), ExplorerApp.get());
link = new Link(attachment.getName(), res);
}
link.setIcon(Images.RELATED_CONTENT_PICTURE);
link.setTargetName(ExplorerLayout.LINK_TARGET_BLANK);
LinkLayout.addComponent(link);
return verticalLayout;
}
Aggregations