public void testTaskEntitySerialization() throws Exception { TaskEntity task = new TaskEntity(); task.setDelegationState(DelegationState.RESOLVED); task.setExecution(new ExecutionEntity()); task.setProcessInstance(new ExecutionEntity()); task.setTaskDefinition(new TaskDefinition(null)); task.setAssignee("kermit"); task.setCreateTime(new Date()); task.setDescription("Test description"); task.setDueDate(new Date()); task.setName("myTask"); task.setEventName("end"); task.setDeleted(false); task.setDelegationStateString(DelegationState.RESOLVED.name()); byte[] data = writeObject(task); task = (TaskEntity) readObject(data); assertEquals("kermit", task.getAssignee()); assertEquals("myTask", task.getName()); assertEquals("end", task.getEventName()); }
public void testSaveAndUpdateTaskWithTaskAssignPermission() { // given TaskEntity task = TaskEntity.create(); task.setAssignee("demo"); createGrantAuthorization(TASK, ANY, userId, CREATE, TASK_ASSIGN); // when taskService.saveTask(task); task.delegate("demoNew"); taskService.saveTask(task); // then task = (TaskEntity) selectSingleTask(); assertNotNull(task); assertEquals("demoNew", task.getAssignee()); String taskId = task.getId(); deleteTask(taskId, true); }
ProcessDefinitionEntity definition = taskEntity.getProcessDefinition(); if (definition != null) { processDefinitionKey = definition.getKey(); String processDefinitionId = taskEntity.getProcessDefinitionId(); String processInstanceId = taskEntity.getProcessInstanceId(); String executionId = taskEntity.getExecutionId(); CaseDefinitionEntity caseDefinition = taskEntity.getCaseDefinition(); if (caseDefinition != null) { caseDefinitionKey = caseDefinition.getKey(); String caseDefinitionId = taskEntity.getCaseDefinitionId(); String caseExecutionId = taskEntity.getCaseExecutionId(); String caseInstanceId = taskEntity.getCaseInstanceId(); String tenantId = taskEntity.getTenantId(); evt.setId(taskEntity.getId()); evt.setEventType(eventType.getEventName()); evt.setTaskId(taskEntity.getId()); evt.setAssignee(taskEntity.getAssignee()); evt.setDescription(taskEntity.getDescription()); evt.setDueDate(taskEntity.getDueDate()); evt.setFollowUpDate(taskEntity.getFollowUpDate()); evt.setName(taskEntity.getName()); evt.setOwner(taskEntity.getOwner()); evt.setParentTaskId(taskEntity.getParentTaskId()); evt.setPriority(taskEntity.getPriority());
@Override public void delegate(String userId) { setDelegationState(DelegationState.PENDING); if (getOwner() == null) { setOwner(getAssignee()); } setAssignee(userId); }
/** creates and initializes a new persistent task. */ public static TaskEntity createAndInsert(VariableScope execution) { TaskEntity task = create(); if (execution instanceof ExecutionEntity) { ExecutionEntity executionEntity = (ExecutionEntity) execution; task.setExecution(executionEntity); task.skipCustomListeners = executionEntity.isSkipCustomListeners(); task.insert(executionEntity); return task; } else if (execution instanceof CaseExecutionEntity) { task.setCaseExecution((DelegateCaseExecution) execution); } task.insert(null); return task; }
public void testAllTrackedProperties() { Date yesterday = new Date(new Date().getTime() - 86400000); Date tomorrow = new Date(new Date().getTime() + 86400000); TaskEntity entity = new TaskEntity(); // call all tracked setter methods entity.setAssignee("er"); entity.setDelegationState(DelegationState.PENDING); entity.setDeleted(true); entity.setDescription("a description"); entity.setDueDate(tomorrow); entity.setFollowUpDate(yesterday); entity.setName("to do"); entity.setOwner("icke"); entity.setParentTaskId("parent"); entity.setPriority(73); // and validate the change list Map<String, PropertyChange> changes = entity.getPropertyChanges(); assertEquals("er", changes.get(ASSIGNEE).getNewValue()); assertSame(DelegationState.PENDING, changes.get(DELEGATION).getNewValue()); assertTrue((Boolean) changes.get(DELETE).getNewValue()); assertEquals("a description", changes.get(DESCRIPTION).getNewValue()); assertEquals(tomorrow, changes.get(DUE_DATE).getNewValue()); assertEquals(yesterday, changes.get(FOLLOW_UP_DATE).getNewValue()); assertEquals("to do", changes.get(NAME).getNewValue()); assertEquals("icke", changes.get(OWNER).getNewValue()); assertEquals("parent", changes.get(PARENT_TASK).getNewValue()); assertEquals(73, changes.get(PRIORITY).getNewValue()); }
public UserOperationLogContextEntryBuilder inContextOf(TaskEntity task, List<PropertyChange> propertyChanges) { if (propertyChanges == null || propertyChanges.isEmpty()) { if (OPERATION_TYPE_CREATE.equals(entry.getOperationType())) { propertyChanges = Arrays.asList(PropertyChange.EMPTY_CHANGE); } } entry.setPropertyChanges(propertyChanges); ResourceDefinitionEntity definition = task.getProcessDefinition(); if (definition != null) { entry.setProcessDefinitionKey(definition.getKey()); entry.setDeploymentId(definition.getDeploymentId()); } else if (task.getCaseDefinitionId() != null) { definition = task.getCaseDefinition(); entry.setDeploymentId(definition.getDeploymentId()); } entry.setProcessDefinitionId(task.getProcessDefinitionId()); entry.setProcessInstanceId(task.getProcessInstanceId()); entry.setExecutionId(task.getExecutionId()); entry.setCaseDefinitionId(task.getCaseDefinitionId()); entry.setCaseInstanceId(task.getCaseInstanceId()); entry.setCaseExecutionId(task.getCaseExecutionId()); entry.setTaskId(task.getId()); ExecutionEntity execution = task.getExecution(); if (execution != null) { entry.setRootProcessInstanceId(execution.getRootProcessInstanceId()); } return this; }
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneProcessTaskCase.cmmn", "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" }) public void testCallProcessAsConstant() { // given String caseInstanceId = createCaseInstanceByKey(ONE_PROCESS_TASK_CASE).getId(); String processTaskId = queryCaseExecutionByActivityId(PROCESS_TASK).getId(); // then // there exists a process instance ExecutionEntity processInstance = (ExecutionEntity) queryProcessInstance(); assertNotNull(processInstance); // the case instance id is set on called process instance assertEquals(caseInstanceId, processInstance.getCaseInstanceId()); // the super case execution id is equals the processTaskId assertEquals(processTaskId, processInstance.getSuperCaseExecutionId()); TaskEntity task = (TaskEntity) queryTask(); // the case instance id has been also set on the task assertEquals(caseInstanceId, task.getCaseInstanceId()); // the case execution id should be null assertNull(task.getCaseExecutionId()); // complete //////////////////////////////////////////////////////// taskService.complete(task.getId()); assertProcessEnded(processInstance.getId()); close(caseInstanceId); assertCaseEnded(caseInstanceId); }
public void testNotTrackChangeToTheSameValue() { TaskEntity entity = new TaskEntity(); // get and set a properties entity.setPriority(entity.getPriority()); entity.setOwner(entity.getOwner()); entity.setFollowUpDate(entity.getFollowUpDate()); // should not track this change assertTrue(entity.getPropertyChanges().isEmpty()); }
public void checkUpdateTask(TaskEntity task) { String taskId = task.getId(); String executionId = task.getExecutionId(); if (executionId != null) { ExecutionEntity execution = task.getExecution(); ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) execution.getProcessDefinition(); String caseExecutionId = task.getCaseExecutionId(); if (caseExecutionId == null) {
public void checkTaskAssign(TaskEntity task) { String taskId = task.getId(); String executionId = task.getExecutionId(); if (executionId != null) { .disjunctive() .atomicCheckForResourceId(TASK, taskId, TASK_ASSIGN) .atomicCheckForResourceId(PROCESS_DEFINITION, task.getProcessDefinition().getKey(), TASK_ASSIGN) .atomicCheckForResourceId(TASK, taskId, UPDATE) .atomicCheckForResourceId(PROCESS_DEFINITION, task.getProcessDefinition().getKey(), UPDATE_TASK) .build(); String caseExecutionId = task.getCaseExecutionId(); if (caseExecutionId == null) {
public Void execute(CommandContext commandContext) { ensureNotNull("taskId", taskId); TaskManager taskManager = commandContext.getTaskManager(); TaskEntity task = taskManager.findTaskById(taskId); ensureNotNull("Cannot find task with id " + taskId, "task", task); checkClaimTask(task, commandContext); if (userId != null) { if (task.getAssignee() != null) { if (!task.getAssignee().equals(userId)) { // When the task is already claimed by another user, throw exception. Otherwise, ignore // this, post-conditions of method already met. throw new TaskAlreadyClaimedException(task.getId(), task.getAssignee()); } } else { task.setAssignee(userId); } } else { // Task should be assigned to no one task.setAssignee(null); } task.createHistoricTaskDetails(UserOperationLogEntry.OPERATION_TYPE_CLAIM); return null; }
@Override public void execute(ProcessEngine processEngine, String s) { TaskEntity task = TaskEntity.create(); task.setName(TASK_NAME); task.setCreateTime(TIMESTAMP); processEngine.getTaskService().saveTask(task); } };
public void testBeanPropertyChanges() { TaskEntity entity = new TaskEntity(); // assign and validate changes entity.setAssignee("icke"); Map<String, PropertyChange> changes = entity.getPropertyChanges(); assertEquals(1, changes.size()); assertNull(changes.get(ASSIGNEE).getOrgValue()); assertEquals("icke", changes.get(ASSIGNEE).getNewValue()); // assign it again entity.setAssignee("er"); changes = entity.getPropertyChanges(); assertEquals(1, changes.size()); // original value is still null because the task was not saved assertNull(changes.get(ASSIGNEE).getOrgValue()); assertEquals("er", changes.get(ASSIGNEE).getNewValue()); // set a due date entity.setDueDate(new Date()); changes = entity.getPropertyChanges(); assertEquals(2, changes.size()); }
/** new task. Embedded state and create time will be initialized. * But this task still will have to be persisted with * TransactionContext * .getCurrent() * .getPersistenceSession() * .insert(task); */ public static TaskEntity create() { TaskEntity task = new TaskEntity(); task.isIdentityLinksInitialized = true; task.setCreateTime(ClockUtil.getCurrentTime()); return task; }
public void checkDeleteTask(TaskEntity task) { String taskId = task.getId(); // Note: Calling TaskService#deleteTask() to // delete a task which exists in context of // a process instance or case instance cannot // be deleted. In such a case TaskService#deleteTask() // throws an exception before invoking the // authorization check. String executionId = task.getExecutionId(); String caseExecutionId = task.getCaseExecutionId(); if (executionId == null && caseExecutionId == null) { getAuthorizationManager().checkAuthorization(DELETE, TASK, taskId); } }
List<IdentityLink> identityLinks = (List) task.getIdentityLinks(); if (task.getAssignee() != null) { IdentityLinkEntity identityLink = new IdentityLinkEntity(); identityLink.setUserId(task.getAssignee()); identityLink.setTask(task); identityLink.setType(IdentityLinkType.ASSIGNEE); identityLinks.add(identityLink); if (task.getOwner() != null) { IdentityLinkEntity identityLink = new IdentityLinkEntity(); identityLink.setUserId(task.getOwner()); identityLink.setTask(task); identityLink.setType(IdentityLinkType.OWNER); return (List) task.getIdentityLinks();
protected void deleteTask(String taskId, CommandContext commandContext) { TaskManager taskManager = commandContext.getTaskManager(); TaskEntity task = taskManager.findTaskById(taskId); if (task != null) { if(task.getExecutionId() != null) { throw new ProcessEngineException("The task cannot be deleted because is part of a running process"); } else if (task.getCaseExecutionId() != null) { throw new ProcessEngineException("The task cannot be deleted because is part of a running case instance"); } checkDeleteTask(task, commandContext); String reason = (deleteReason == null || deleteReason.length() == 0) ? TaskEntity.DELETE_REASON_DELETED : deleteReason; task.delete(reason, cascade); } else if (cascade) { Context .getCommandContext() .getHistoricTaskInstanceManager() .deleteHistoricTaskInstanceById(taskId); } }
public void testRemoveChangeWhenSetBackToTheOrgValue() { TaskEntity entity = new TaskEntity(); // set an owner (default is null) entity.setOwner("icke"); // should track this change assertFalse(entity.getPropertyChanges().isEmpty()); // reset the owner entity.setOwner(null); // the change is removed assertTrue(entity.getPropertyChanges().isEmpty()); }