use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class DefaultViewManager method showTaskPage.
// Tasks
/**
* Generic method which will figure out to which
* task page must be jumped, based on the task data.
*
* Note that, if possible, it is always more
* performant to use the more specific showXXXPage() methods.
*/
public void showTaskPage(String taskId) {
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
String loggedInUserId = ExplorerApp.get().getLoggedInUser().getId();
if (task == null) {
// If no runtime task exists, our only hope is the archive page
boolean isOwner = historyService.createHistoricTaskInstanceQuery().taskId(taskId).taskOwner(loggedInUserId).count() == 1;
if (isOwner) {
showArchivedPage(taskId);
} else {
showNavigationError(taskId);
}
} else if (loggedInUserId.equals(task.getOwner())) {
showTasksPage(taskId);
} else if (loggedInUserId.equals(task.getAssignee())) {
showInboxPage(taskId);
} else if (taskService.createTaskQuery().taskInvolvedUser(loggedInUserId).count() == 1) {
showInvolvedPage(taskId);
} else {
// queued
List<String> groupIds = getGroupIds(loggedInUserId);
List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(task.getId());
Iterator<IdentityLink> identityLinkIterator = identityLinks.iterator();
boolean pageFound = false;
while (!pageFound && identityLinkIterator.hasNext()) {
IdentityLink identityLink = identityLinkIterator.next();
if (identityLink.getGroupId() != null && groupIds.contains(identityLink.getGroupId())) {
showQueuedPage(identityLink.getGroupId(), task.getId());
pageFound = true;
}
}
// We've tried hard enough, the user now gets a notification. He deserves it.
if (!pageFound) {
showNavigationError(taskId);
}
}
}
use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class DemoDataGenerator method generateReportData.
protected void generateReportData() {
if (generateReportData) {
// Report data is generated in background thread
Thread thread = new Thread(new Runnable() {
public void run() {
// We need to temporarily disable the job executor or it would interfere with the process execution
((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getJobExecutor().shutdown();
Random random = new Random();
Date now = new Date(new Date().getTime() - (24 * 60 * 60 * 1000));
((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getClock().setCurrentTime(now);
for (int i = 0; i < 50; i++) {
if (random.nextBoolean()) {
processEngine.getRuntimeService().startProcessInstanceByKey("fixSystemFailure");
}
if (random.nextBoolean()) {
processEngine.getIdentityService().setAuthenticatedUserId("kermit");
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("customerName", "testCustomer");
variables.put("details", "Looks very interesting!");
variables.put("notEnoughInformation", false);
processEngine.getRuntimeService().startProcessInstanceByKey("reviewSaledLead", variables);
}
if (random.nextBoolean()) {
processEngine.getRuntimeService().startProcessInstanceByKey("escalationExample");
}
if (random.nextInt(100) < 20) {
now = new Date(now.getTime() - ((24 * 60 * 60 * 1000) - (60 * 60 * 1000)));
((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getClock().setCurrentTime(now);
}
}
List<Job> jobs = processEngine.getManagementService().createJobQuery().list();
for (int i = 0; i < jobs.size() / 2; i++) {
((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getClock().setCurrentTime(jobs.get(i).getDuedate());
processEngine.getManagementService().executeJob(jobs.get(i).getId());
}
List<Task> tasks = processEngine.getTaskService().createTaskQuery().list();
while (!tasks.isEmpty()) {
for (Task task : tasks) {
if (task.getAssignee() == null) {
String assignee = random.nextBoolean() ? "kermit" : "fozzie";
processEngine.getTaskService().claim(task.getId(), assignee);
}
((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getClock().setCurrentTime(new Date(task.getCreateTime().getTime() + random.nextInt(60 * 60 * 1000)));
processEngine.getTaskService().complete(task.getId());
}
tasks = processEngine.getTaskService().createTaskQuery().list();
}
((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getClock().reset();
((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getJobExecutor().start();
LOGGER.info("Demo report data generated");
}
});
thread.start();
}
}
use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class TaskNavigator method directToSpecificTaskPage.
protected void directToSpecificTaskPage(String category, String taskId, UriFragment uriFragment) {
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
ViewManager viewManager = ExplorerApp.get().getViewManager();
String loggedInUserId = ExplorerApp.get().getLoggedInUser().getId();
boolean pageFound = false;
if (CATEGORY_TASKS.equals(category)) {
if (loggedInUserId.equals(task.getOwner())) {
viewManager.showTasksPage(task.getId());
pageFound = true;
}
} else if (CATEGORY_INBOX.equals(category)) {
if (loggedInUserId.equals(task.getAssignee())) {
viewManager.showInboxPage(task.getId());
pageFound = true;
}
} else if (CATEGORY_QUEUED.equals(category)) {
String groupId = uriFragment.getParameter(PARAMETER_GROUP);
boolean isTaskAssignedToGroup = taskService.createTaskQuery().taskId(task.getId()).taskCandidateGroup(groupId).count() == 1;
boolean isUserMemberOfGroup = identityService.createGroupQuery().groupMember(loggedInUserId).groupId(groupId).count() == 1;
if (isTaskAssignedToGroup && isUserMemberOfGroup) {
viewManager.showQueuedPage(groupId, task.getId());
pageFound = true;
}
} else if (CATEGORY_INVOLVED.equals(category)) {
boolean isUserInvolved = taskService.createTaskQuery().taskInvolvedUser(loggedInUserId).count() == 1;
if (isUserInvolved) {
viewManager.showInvolvedPage(task.getId());
pageFound = true;
}
} else if (CATEGORY_ARCHIVED.equals(category)) {
if (task == null) {
boolean isOwner = historyService.createHistoricTaskInstanceQuery().taskId(taskId).taskOwner(loggedInUserId).finished().count() == 1;
if (isOwner) {
viewManager.showArchivedPage(taskId);
pageFound = true;
}
}
} else {
throw new ActivitiException("Couldn't find a matching category");
}
if (!pageFound) {
// If URL doesnt match anymore, we must use the task data to redirect to the right page
viewManager.showTaskPage(taskId);
}
}
use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class TaskResourceTest method testCompleteTask.
/**
* Test completing a single task.
* POST runtime/tasks/{taskId}
*/
@Deployment
public void testCompleteTask() throws Exception {
try {
Task task = taskService.newTask();
taskService.saveTask(task);
String taskId = task.getId();
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "complete");
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId()));
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
// Task shouldn't exist anymore
task = taskService.createTaskQuery().taskId(taskId).singleResult();
assertNull(task);
// Test completing with variables
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskId = task.getId();
requestNode = objectMapper.createObjectNode();
ArrayNode variablesNode = objectMapper.createArrayNode();
requestNode.put("action", "complete");
requestNode.put("variables", variablesNode);
ObjectNode var1 = objectMapper.createObjectNode();
variablesNode.add(var1);
var1.put("name", "var1");
var1.put("value", "First value");
ObjectNode var2 = objectMapper.createObjectNode();
variablesNode.add(var2);
var2.put("name", "var2");
var2.put("value", "Second value");
httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, taskId));
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_OK));
task = taskService.createTaskQuery().taskId(taskId).singleResult();
assertNull(task);
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
assertNotNull(historicTaskInstance);
List<HistoricVariableInstance> updates = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).list();
assertNotNull(updates);
assertEquals(2, updates.size());
boolean foundFirst = false;
boolean foundSecond = false;
for (HistoricVariableInstance var : updates) {
if (var.getVariableName().equals("var1")) {
assertEquals("First value", var.getValue());
foundFirst = true;
} else if (var.getVariableName().equals("var2")) {
assertEquals("Second value", var.getValue());
foundSecond = true;
}
}
assertTrue(foundFirst);
assertTrue(foundSecond);
}
} finally {
// Clean adhoc-tasks even if test fails
List<Task> tasks = taskService.createTaskQuery().list();
for (Task task : tasks) {
taskService.deleteTask(task.getId(), true);
}
// Clean historic tasks with no runtime-counterpart
List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery().list();
for (HistoricTaskInstance task : historicTasks) {
historyService.deleteHistoricTaskInstance(task.getId());
}
}
}
use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class TaskVariableResourceTest method testUpdateBinaryTaskVariable.
/**
* Test updating a single task variable using a binary stream.
* PUT runtime/tasks/{taskId}/variables/{variableName}
*/
public void testUpdateBinaryTaskVariable() throws Exception {
try {
Task task = taskService.newTask();
taskService.saveTask(task);
taskService.setVariable(task.getId(), "binaryVariable", "Original value".getBytes());
InputStream binaryContent = new ByteArrayInputStream("This is binary content".getBytes());
// Add name, type and scope
Map<String, String> additionalFields = new HashMap<String, String>();
additionalFields.put("name", "binaryVariable");
additionalFields.put("type", "binary");
additionalFields.put("scope", "local");
// Upload a valid BPMN-file using multipart-data
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE, task.getId(), "binaryVariable"));
httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("value", "application/octet-stream", binaryContent, additionalFields));
CloseableHttpResponse response = executeBinaryRequest(httpPut, HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("binaryVariable", responseNode.get("name").asText());
assertTrue(responseNode.get("value").isNull());
assertEquals("local", responseNode.get("scope").asText());
assertEquals("binary", responseNode.get("type").asText());
assertNotNull(responseNode.get("valueUrl").isNull());
assertTrue(responseNode.get("valueUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE_DATA, task.getId(), "binaryVariable")));
// Check actual value of variable in engine
Object variableValue = taskService.getVariableLocal(task.getId(), "binaryVariable");
assertNotNull(variableValue);
assertTrue(variableValue instanceof byte[]);
assertEquals("This is binary content", new String((byte[]) variableValue));
} finally {
// Clean adhoc-tasks even if test fails
List<Task> tasks = taskService.createTaskQuery().list();
for (Task task : tasks) {
taskService.deleteTask(task.getId(), true);
}
}
}
Aggregations