@Override public void afterTaskExitedEvent(TaskEvent event) { String userId = event.getTaskContext().getUserId(); Task ti = event.getTask(); TaskEventImpl taskEvent = new TaskEventImpl(ti.getId(), org.kie.internal.task.api.model.TaskEvent.TaskEventType.EXITED, ti.getTaskData().getProcessInstanceId(), ti.getTaskData().getWorkItemId(), userId); AuditTaskImpl auditTaskImpl = createAuditTask(ti, event.getEventDate()); auditTaskImpl.setDescription(ti.getDescription()); auditTaskImpl.setName(ti.getName()); auditTaskImpl.setActivationTime(ti.getTaskData().getActivationTime()); auditTaskImpl.setPriority(ti.getPriority()); auditTaskImpl.setDueDate(ti.getTaskData().getExpirationTime()); auditTaskImpl.setStatus(ti.getTaskData().getStatus().name()); auditTaskImpl.setActualOwner(getActualOwner(ti)); auditTaskImpl.setLastModificationDate(event.getEventDate()); sendMessage(new AuditTaskData(auditTaskImpl, taskEvent), 2); }
protected AuditTaskImpl createAuditTask(Task ti, Date date) { AuditTaskImpl auditTaskImpl = new AuditTaskImpl( ti.getId(), ti.getName(), ti.getTaskData().getStatus().name(), ti.getTaskData().getActivationTime(), (ti.getTaskData().getActualOwner() != null) ? ti.getTaskData().getActualOwner().getId() : "", ti.getDescription(), ti.getPriority(), (ti.getTaskData().getCreatedBy() != null) ? ti.getTaskData().getCreatedBy().getId() : "", ti.getTaskData().getCreatedOn(), ti.getTaskData().getExpirationTime(), ti.getTaskData().getProcessInstanceId(), ti.getTaskData().getProcessId(), ti.getTaskData().getProcessSessionId(), ti.getTaskData().getDeploymentId(), ti.getTaskData().getParentId(), ti.getTaskData().getWorkItemId(), date ); return auditTaskImpl; }
/** * Generates a queue name that is based on data retrieved from the task. The form of the generated queue name is: * Process ID + "_" + Deployment ID + " " + Task Name * @param task Source of the data used to generate the queue name * @return The generated queue name */ protected String getQueueName(Task task) { return task.getTaskData().getProcessId() + "_" + task.getTaskData().getDeploymentId() + "_" + task.getName(); }
private String buildDefafultEmailBody(TaskData taskData,Task task){ Map<String, Object> vars = new HashMap<String, Object>(); vars.put("taskName", task.getName()); vars.put("taskId", task.getId()); vars.put("deploymentId", taskData.getDeploymentId()); vars.put("processId", taskData.getProcessId()); vars.put("processInstanceId", taskData.getProcessInstanceId()); String body = (String) TemplateRuntime.eval(defaultEmailBody, vars); return body; }
public void testReleaseFromReserved() { // One potential owner, should go straight to state Reserved String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), "; str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ],businessAdministrators = [ new User('Administrator') ], }),"; str += "name = 'This is my task name'})"; Task task = TaskFactory.evalTask(new StringReader(str)); taskService.addTask(task, new HashMap<String, Object>()); long taskId = task.getId(); // Go straight from Ready to Inprogress taskService.claim(taskId, "Darth Vader"); Task task1 = taskService.getTaskById(taskId); assertEquals(Status.Reserved, task1.getTaskData().getStatus()); assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId()); // Check is Released taskService.release(taskId, "Darth Vader"); Task task2 = taskService.getTaskById(taskId); assertEquals(Status.Ready, task2.getTaskData().getStatus()); assertNull(task2.getTaskData().getActualOwner()); }
Task parentTask = TaskFactory.evalTask(new StringReader(parentTaskstr)); taskService.addTask(parentTask, new HashMap<String, Object>()); long taskParentId = parentTask.getId(); Task parentTask1 = taskService.getTaskById(taskParentId); assertEquals(parentTask1.getTaskData().getStatus(), Status.Reserved); taskService.start(taskParentId, "salaboy"); child1Taskstr += "names = [ new I18NText( 'en-UK', 'This is my task Child 1 name')] })"; Task child1Task = TaskFactory.evalTask(new StringReader(child1Taskstr)); taskService.addTask(child1Task, new HashMap<String, Object>()); long child1TaskId = child1Task.getId(); Task childTask1 = taskService.getTaskById(child1TaskId); assertEquals(taskParentId, childTask1.getTaskData().getParentId()); taskService.start(child1TaskId, "Darth Vader"); childTask1 = taskService.getTaskById(child1TaskId); assertEquals(Status.Completed, childTask1.getTaskData().getStatus()); assertEquals(Status.Completed, parentTask1.getTaskData().getStatus() );
@Test public void testExitFromReserved() { String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { skipable = false} ), "; str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet') ], businessAdministrators = [ new User('Administrator')] }),"; str += "name = 'This is my task name' })"; Task task = TaskFactory.evalTask(new StringReader(str)); taskService.addTask(task, new HashMap<String, Object>()); long taskId = task.getId(); task = taskService.getTaskById(taskId); assertEquals(Status.Reserved, task.getTaskData().getStatus()); taskService.exit(taskId, "Administrator"); Task task1 = taskService.getTaskById(taskId); assertEquals(Status.Exited, task1.getTaskData().getStatus()); }
@Test public void testAssignmentsWhenNoRuleWasFired() throws Exception { String str = "(with (new Task()) { priority = 51, taskData = (with( new TaskData()) { } ), "; str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Ben Dover') ],businessAdministrators = [ new User('Administrator') ],}),"; str += "name = 'Not Bobbas tasks' })"; Task task = TaskFactory.evalTask(new StringReader(str)); assertPotentialOwners(task, 1); long taskId = taskService.addTask(task, Collections.emptyMap()); task = taskService.getTaskById(taskId); assertPotentialOwners(task, 0); User actualOwner = task.getTaskData().getActualOwner(); Assertions.assertThat(actualOwner).isNull(); }
return; this.compositeId = System.getProperty("org.kie.server.id", "") + "_" + source.getId(); this.activationTime = source.getTaskData().getActivationTime(); this.actualOwner = safeOrgEntity(source.getTaskData().getActualOwner()); .map(entity -> safeOrgEntity(entity)) .collect(Collectors.toList()); this.containerId = source.getTaskData().getDeploymentId(); this.createdBy = safeOrgEntity(source.getTaskData().getCreatedBy()); this.createdOn = source.getTaskData().getCreatedOn(); .map(entity -> safeOrgEntity(entity)) .collect(Collectors.toList()); this.expirationDate = source.getTaskData().getExpirationTime(); this.inputData = source.getTaskData().getTaskInputVariables(); this.name = source.getName(); this.outputData = source.getTaskData().getTaskOutputVariables(); this.parentId = source.getTaskData().getParentId(); this.processId = source.getTaskData().getProcessId(); this.processInstanceId = source.getTaskData().getProcessInstanceId(); this.skipable = source.getTaskData().isSkipable(); this.status = source.getTaskData().getStatus().name(); this.workItemId = source.getTaskData().getWorkItemId();
@Override public void afterTaskFailedEvent(TaskEvent event) { String userId = event.getTaskContext().getUserId(); Task ti = event.getTask(); TaskPersistenceContext persistenceContext = getPersistenceContext(((TaskContext)event.getTaskContext()).getPersistenceContext()); try { persistenceContext.persist(new TaskEventImpl(ti.getId(), org.kie.internal.task.api.model.TaskEvent.TaskEventType.FAILED, ti.getTaskData().getProcessInstanceId(), ti.getTaskData().getWorkItemId(), userId)); AuditTaskImpl auditTaskImpl = getAuditTask(event, persistenceContext, ti); if (auditTaskImpl == null) { logger.warn("Unable find audit task entry for task id {} '{}', skipping audit task update", ti.getId(), ti.getName()); return; } auditTaskImpl.setStatus(ti.getTaskData().getStatus().name()); auditTaskImpl.setActualOwner(getActualOwner(ti)); auditTaskImpl.setLastModificationDate(event.getEventDate()); persistenceContext.merge(auditTaskImpl); } finally { cleanup(persistenceContext); } }
@Override public void afterTaskClaimedEvent(TaskEvent event) { String userId = event.getTaskContext().getUserId(); Task ti = event.getTask(); TaskEventImpl taskEvent = new TaskEventImpl(ti.getId(), org.kie.internal.task.api.model.TaskEvent.TaskEventType.CLAIMED, ti.getTaskData().getProcessInstanceId(), ti.getTaskData().getWorkItemId(), userId); AuditTaskImpl auditTaskImpl = createAuditTask(ti, event.getEventDate()); auditTaskImpl.setStatus(ti.getTaskData().getStatus().name()); auditTaskImpl.setActualOwner(getActualOwner(ti)); auditTaskImpl.setDescription(ti.getDescription()); auditTaskImpl.setLastModificationDate(event.getEventDate()); sendMessage(new AuditTaskData(auditTaskImpl, taskEvent), 8); }
this.status = taskData.getStatus(); this.previousStatus = taskData.getPreviousStatus(); User actualOwnerUser = taskData.getActualOwner(); if( actualOwnerUser != null ) { this.actualOwner = actualOwnerUser.getId(); User createdByUser = taskData.getCreatedBy(); if( createdByUser != null ) { this.createdBy = createdByUser.getId(); this.createdOn = taskData.getCreatedOn(); this.activationTime = taskData.getActivationTime(); this.expirationTime = taskData.getExpirationTime(); this.skipable = taskData.isSkipable(); this.workItemId = taskData.getWorkItemId(); this.processInstanceId = taskData.getProcessInstanceId(); this.documentType = taskData.getDocumentType(); if( taskData instanceof JaxbTaskData ) { JaxbTaskData jaxbTaskData = (JaxbTaskData) taskData; this.documentContentId = taskData.getDocumentContentId(); this.outputType = taskData.getOutputType(); this.outputContentId = taskData.getOutputContentId(); this.faultName = taskData.getFaultName(); this.faultType = taskData.getFaultType(); this.faultContentId = taskData.getFaultContentId(); this.parentId = taskData.getParentId(); this.processId = taskData.getProcessId(); this.processSessionId = taskData.getProcessSessionId();
private void testTaskWithExpectedDescription(final Task task, final String expectedDescription) { assertEquals("TaskName " + task.getTaskData().getProcessInstanceId(), task.getName()); assertEquals(10, task.getPriority().intValue()); assertEquals(expectedDescription, task.getDescription()); assertEquals(Status.Reserved, task.getTaskData().getStatus()); assertEquals("Darth Vader", task.getTaskData().getActualOwner().getId()); assertEquals(10L, task.getTaskData().getProcessInstanceId()); }
@Override public void afterTaskAddedEvent(TaskEvent event) { String userId = event.getTaskContext().getUserId(); Task ti = event.getTask(); if(ti.getTaskData().getProcessId() != null){ userId = ti.getTaskData().getProcessId(); } AuditTaskImpl auditTask = createAuditTask(ti, event.getEventDate()); TaskEventImpl taskEvent = new TaskEventImpl(ti.getId(), org.kie.internal.task.api.model.TaskEvent.TaskEventType.ADDED, ti.getTaskData().getProcessInstanceId(), ti.getTaskData().getWorkItemId(), userId); sendMessage(new AuditTaskData(auditTask, taskEvent), 9); }
protected long createAndAssertTask(TaskFluent tf, String expectedOwner) { Task task = tf.getTask(); taskService.addTask(task, data); long taskId = task.getId(); assertEquals("Owner mismatch",expectedOwner,taskService.getTaskById(taskId).getTaskData().getActualOwner().getId()); return taskId; }
protected void completeTask(Task task) { taskService.start(task.getId(), task.getTaskData().getActualOwner().getId()); taskService.complete(task.getId(), task.getTaskData().getActualOwner().getId(), new HashMap<String,Object>()); }
@Test public void testTaskWithVariables() throws Exception { final TestWorkItemManager manager = new TestWorkItemManager(); ksession.setWorkItemManager(manager); final String taskDescriptionParam = "Comment for task " + "${task.id} " + "${task.taskData.processSessionId} " + "${task.taskData.actualOwner.id} " + "${task.taskData.parentId}"; handler.executeWorkItem(prepareWorkItemWithTaskVariables(taskDescriptionParam), manager); final List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", "en-UK"); assertEquals(1, tasks.size()); final Task task = taskService.getTaskById(tasks.get(0).getId()); testTaskWithExpectedDescription(task, "Comment for task " + task.getId() + " " + task.getTaskData().getProcessSessionId() + " " + task.getTaskData().getActualOwner().getId() + " " + task.getTaskData().getParentId()); taskService.start(task.getId(), "Darth Vader"); taskService.complete(task.getId(), "Darth Vader", null); assertTrue(manager.waitTillCompleted(MANAGER_COMPLETION_WAIT_TIME)); final String actualOwner = (String) manager.getResults().get("ActorId"); assertNotNull(actualOwner); assertEquals("Darth Vader", actualOwner); }
boolean isExcludedOwner = ((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners().contains(user); operationAllowed = !isExcludedOwner && (task.getTaskData().getActualOwner() != null && task.getTaskData().getActualOwner().equals(user)); break; operationAllowed = ( !isExcludedOwner && task.getTaskData().getCreatedBy() != null && (task.getTaskData().getCreatedBy().equals(user) || groupIds != null && groupIds.contains(task.getTaskData().getCreatedBy().getId()))); break; operationAllowed = task.getTaskData().isSkipable();
protected String getActualOwner(Task ti) { String userId = ""; if (ti.getTaskData().getActualOwner() != null) { userId = ti.getTaskData().getActualOwner().getId(); } return userId; }
@Test public void testDeleteAuditTaskInfoLogByProcessIdAndNotMatchingDate() { int p = 0; String processId = taskTestData[p++].getTaskData().getProcessId(); Date endDate = taskTestData[p++].getTaskData().getCreatedOn(); AuditTaskDeleteBuilder updateBuilder = this.auditTaskDelete().date(endDate).processId(processId); int result = updateBuilder.build().execute(); assertEquals(0, result); }