use of org.camunda.bpm.engine.task.Task in project camunda-bpm-platform by camunda.
the class XmlValueTest method testXmlValueInCondition.
@Deployment(resources = "org/camunda/spin/plugin/xmlConditionProcess.bpmn20.xml")
public void testXmlValueInCondition() {
// given
String xmlString = "<customer age=\"22\" />";
XmlValue value = xmlValue(xmlString).create();
VariableMap variables = Variables.createVariables().putValueTyped("customer", value);
// when
runtimeService.startProcessInstanceByKey("process", variables);
// then
Task task = taskService.createTaskQuery().singleResult();
assertEquals("task1", task.getTaskDefinitionKey());
}
use of org.camunda.bpm.engine.task.Task in project camunda-bpm-platform by camunda.
the class TaskResourceImpl method getForm.
@Override
public FormDto getForm() {
FormService formService = engine.getFormService();
Task task = getTaskById(taskId);
FormData formData;
try {
formData = formService.getTaskFormData(taskId);
} catch (AuthorizationException e) {
throw e;
} catch (ProcessEngineException e) {
throw new RestException(Status.BAD_REQUEST, e, "Cannot get form for task " + taskId);
}
FormDto dto = FormDto.fromFormData(formData);
if (dto.getKey() == null || dto.getKey().isEmpty()) {
if (formData != null && formData.getFormFields() != null && !formData.getFormFields().isEmpty()) {
dto.setKey("embedded:engine://engine/:engine/task/" + taskId + "/rendered-form");
}
}
// to get the application context path it is necessary to
// execute it without authentication (tries to fetch the
// process definition), because:
// - user 'demo' has READ permission on a specific task resource
// - user 'demo' does not have a READ permission on the corresponding
// process definition
// -> running the following lines with authorization would lead
// to an AuthorizationException because the user 'demo' does not
// have READ permission on the corresponding process definition
IdentityService identityService = engine.getIdentityService();
Authentication currentAuthentication = identityService.getCurrentAuthentication();
try {
identityService.clearAuthentication();
String processDefinitionId = task.getProcessDefinitionId();
String caseDefinitionId = task.getCaseDefinitionId();
if (processDefinitionId != null) {
dto.setContextPath(ApplicationContextPathUtil.getApplicationPathByProcessDefinitionId(engine, processDefinitionId));
} else if (caseDefinitionId != null) {
dto.setContextPath(ApplicationContextPathUtil.getApplicationPathByCaseDefinitionId(engine, caseDefinitionId));
}
} finally {
identityService.setAuthentication(currentAuthentication);
}
return dto;
}
use of org.camunda.bpm.engine.task.Task in project camunda-bpm-platform by camunda.
the class ScopingTest method run.
/**
* this code instantiates a business process that in turn delegates to a few Spring beans that in turn inject a process scoped object, {@link StatefulObject}.
*
* @return the StatefulObject that was injected across different components, that all share the same state.
* @throws Throwable if anythign goes wrong
*/
private StatefulObject run() throws Throwable {
logger.info("----------------------------------------------");
Map<String, Object> vars = new HashMap<String, Object>();
vars.put(customerIdProcVarName, CUSTOMER_ID_PROC_VAR_VALUE);
ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey("component-waiter", vars);
StatefulObject scopedObject = (StatefulObject) processEngine.getRuntimeService().getVariable(processInstance.getId(), "scopedTarget.c1");
Assert.assertNotNull("the scopedObject can't be null", scopedObject);
Assert.assertTrue("the 'name' property can't be null.", StringUtils.hasText(scopedObject.getName()));
Assert.assertEquals(scopedObject.getVisitedCount(), 2);
// the process has paused
String procId = processInstance.getProcessInstanceId();
List<Task> tasks = taskService.createTaskQuery().executionId(procId).list();
Assert.assertEquals("there should be 1 (one) task enqueued at this point.", tasks.size(), 1);
Task t = tasks.iterator().next();
this.taskService.claim(t.getId(), "me");
logger.info("sleeping for 10 seconds while a user performs his task. " + "The first transaction has committed. A new one will start in 10 seconds");
Thread.sleep(1000 * 5);
this.taskService.complete(t.getId());
scopedObject = (StatefulObject) processEngine.getRuntimeService().getVariable(processInstance.getId(), "scopedTarget.c1");
Assert.assertEquals(scopedObject.getVisitedCount(), 3);
Assert.assertEquals("the customerId injected should " + "be what was given as a processVariable parameter.", ScopingTest.CUSTOMER_ID_PROC_VAR_VALUE, scopedObject.getCustomerId());
return scopedObject;
}
use of org.camunda.bpm.engine.task.Task in project camunda-bpm-platform by camunda.
the class JPASpringTest method testJpaVariableHappyPath.
@Deployment(resources = { "org/camunda/bpm/engine/spring/test/jpa/JPASpringTest.bpmn20.xml" })
public void testJpaVariableHappyPath() {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("customerName", "John Doe");
variables.put("amount", 15000L);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("LoanRequestProcess", variables);
// Variable should be present containing the loanRequest created by the spring bean
Object value = runtimeService.getVariable(processInstance.getId(), "loanRequest");
assertNotNull(value);
assertTrue(value instanceof LoanRequest);
LoanRequest request = (LoanRequest) value;
assertEquals("John Doe", request.getCustomerName());
assertEquals(15000L, request.getAmount().longValue());
assertFalse(request.isApproved());
// We will approve the request, which will update the entity
variables = new HashMap<String, Object>();
variables.put("approvedByManager", Boolean.TRUE);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
taskService.complete(task.getId(), variables);
// If approved, the processsInstance should be finished, gateway based on loanRequest.approved value
assertEquals(0, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count());
}
use of org.camunda.bpm.engine.task.Task in project camunda-bpm-platform by camunda.
the class BoundaryErrorEventSpringTest method assertThatErrorHasBeenCaught.
private void assertThatErrorHasBeenCaught(String procId) {
// The service task will throw an error event,
// which is caught on the service task boundary
assertEquals("No tasks found in task list.", 1, taskService.createTaskQuery().count());
Task task = taskService.createTaskQuery().singleResult();
assertEquals("Escalated Task", task.getName());
// Completing the task will end the process instance
taskService.complete(task.getId());
assertProcessEnded(procId);
}
Aggregations