use of org.kie.api.task.model.Status in project jbpm by kiegroup.
the class TaskQueryServiceBaseTest method testGetTasksAssignedAsPotentialOwnerByStatusByGroupWithUserStatusLangOneTask.
@Test
public void testGetTasksAssignedAsPotentialOwnerByStatusByGroupWithUserStatusLangOneTask() {
// 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') ],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>());
List<String> groupIds = new ArrayList<String>();
groupIds.add("Crusaders");
List<Status> statuses = new ArrayList<Status>();
statuses.add(Status.Created);
statuses.add(Status.Ready);
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwnerByStatusByGroup("Bobba Fet", groupIds, statuses);
assertEquals(0, tasks.size());
}
use of org.kie.api.task.model.Status in project jbpm by kiegroup.
the class MVELLifeCycleManager method assignOwnerAndStatus.
/**
* This method will potentially assign the actual owner of this TaskData and set the status
* of the data.
* <li>If there is only 1 potential owner, and it is a <code>User</code>, that will become the actual
* owner of the TaskData and the status will be set to <code>Status.Reserved</code>.</li>
* <li>f there is only 1 potential owner, and it is a <code>Group</code>, no owner will be assigned
* and the status will be set to <code>Status.Ready</code>.</li>
* <li>If there are more than 1 potential owners, the status will be set to <code>Status.Ready</code>.</li>
* <li>otherwise, the task data will be unchanged</li>
*
* @param taskdata - task data
* @param potentialOwners - list of potential owners
* @return current status of task data
*/
public static Status assignOwnerAndStatus(InternalTaskData taskData, List<OrganizationalEntity> potentialOwners) {
if (taskData.getStatus() != Status.Created) {
throw new PermissionDeniedException("Can only assign task owner if status is Created!");
}
Status assignedStatus = null;
if (potentialOwners.size() == 1) {
// if there is a single potential owner, assign and set status to Reserved
OrganizationalEntity potentialOwner = potentialOwners.get(0);
// if there is a single potential user owner, assign and set status to Reserved
if (potentialOwner instanceof User) {
taskData.setActualOwner((User) potentialOwner);
assignedStatus = Status.Reserved;
}
// If there is a group set as potentialOwners, set the status to Ready ??
if (potentialOwner instanceof Group) {
assignedStatus = Status.Ready;
}
} else if (potentialOwners.size() > 1) {
// multiple potential owners, so set to Ready so one can claim.
assignedStatus = Status.Ready;
} else {
// @TODO we have no potential owners
}
if (assignedStatus != null) {
taskData.setStatus(assignedStatus);
} else {
// status wasn't assigned, so just return the currrent status
assignedStatus = taskData.getStatus();
}
return assignedStatus;
}
use of org.kie.api.task.model.Status in project jbpm by kiegroup.
the class MVELLifeCycleManager method evalCommand.
void evalCommand(final Operation operation, final List<OperationCommand> commands, final Task task, final User user, final OrganizationalEntity targetEntity, List<String> groupIds, OrganizationalEntity... entities) throws PermissionDeniedException {
boolean statusMatched = false;
final TaskData taskData = task.getTaskData();
for (OperationCommand command : commands) {
// first find out if we have a matching status
if (command.getStatus() != null) {
for (Status status : command.getStatus()) {
if (task.getTaskData().getStatus() == status) {
statusMatched = true;
// next find out if the user can execute this doOperation
if (!isAllowed(command, task, user, groupIds)) {
String errorMessage = "User '" + user + "' does not have permissions to execute operation '" + operation + "' on task id " + task.getId();
throw new PermissionDeniedException(errorMessage);
}
commands(command, task, user, targetEntity, entities);
} else {
logger.debug("No match on status for task {} :status {} != {}", task.getId(), task.getTaskData().getStatus(), status);
}
}
}
if (command.getPreviousStatus() != null) {
for (Status status : command.getPreviousStatus()) {
if (taskData.getPreviousStatus() == status) {
statusMatched = true;
// next find out if the user can execute this doOperation
if (!isAllowed(command, task, user, groupIds)) {
String errorMessage = "User '" + user + "' does not have permissions to execute operation '" + operation + "' on task id " + task.getId();
throw new PermissionDeniedException(errorMessage);
}
commands(command, task, user, targetEntity, entities);
} else {
logger.debug("No match on previous status for task {} :status {} != {}", task.getId(), task.getTaskData().getStatus(), status);
}
}
}
if (!command.isGroupTargetEntityAllowed() && targetEntity instanceof Group) {
String errorMessage = "User '" + user + "' was unable to execute operation '" + operation + "' on task id " + task.getId() + " due to 'target entity cannot be group'";
throw new PermissionDeniedException(errorMessage);
}
}
if (!statusMatched) {
String errorMessage = "User '" + user + "' was unable to execute operation '" + operation + "' on task id " + task.getId() + " due to a no 'current status' match";
throw new PermissionDeniedException(errorMessage);
}
}
use of org.kie.api.task.model.Status in project jbpm by kiegroup.
the class RuntimeDataServiceImplTest method testGetTaskAssignedAsBusinessAdminByStatus.
@Test
public void testGetTaskAssignedAsBusinessAdminByStatus() {
for (int i = 0; i < 10; i++) {
processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
}
List<Status> statuses = new ArrayList<Status>();
statuses.add(Status.Ready);
statuses.add(Status.Reserved);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsBusinessAdministratorByStatus("Administrator", statuses, new QueryFilter(0, 5));
assertNotNull(tasks);
assertEquals(5, tasks.size());
statuses = new ArrayList<Status>();
statuses.add(Status.InProgress);
tasks = runtimeDataService.getTasksAssignedAsBusinessAdministratorByStatus("Administrator", statuses, new QueryFilter(0, 5));
assertNotNull(tasks);
assertEquals(0, tasks.size());
Collection<ProcessInstanceDesc> activeProcesses = runtimeDataService.getProcessInstances(new QueryContext(0, 20));
for (ProcessInstanceDesc pi : activeProcesses) {
processService.abortProcessInstance(pi.getId());
}
}
use of org.kie.api.task.model.Status in project jbpm by kiegroup.
the class RuntimeDataServiceImplTest method testGetTasksByVariableAndValueSorted.
@Test
public void testGetTasksByVariableAndValueSorted() {
Map<String, Object> params = new HashMap<String, Object>();
params.put("approval_document", "initial content");
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
assertNotNull(processInstanceId);
Long processInstanceId2 = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
assertNotNull(processInstanceId2);
List<Status> statuses = new ArrayList<Status>();
statuses.add(Status.Ready);
statuses.add(Status.Reserved);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwnerByStatus("salaboy", statuses, new QueryFilter());
assertNotNull(tasks);
assertEquals(2, tasks.size());
String userId = "salaboy";
String varName = "Comment";
String varValue = "Write a Document";
List<TaskSummary> tasksByVariable = runtimeDataService.getTasksByVariableAndValue(userId, varName, varValue, statuses, new QueryFilter(0, 10, "processInstanceId", true));
assertNotNull(tasksByVariable);
assertEquals(2, tasksByVariable.size());
assertEquals(processInstanceId, tasksByVariable.get(0).getProcessInstanceId());
assertEquals(processInstanceId2, tasksByVariable.get(1).getProcessInstanceId());
tasksByVariable = runtimeDataService.getTasksByVariableAndValue(userId, varName, varValue, statuses, new QueryFilter(0, 10, "processInstanceId", false));
assertNotNull(tasksByVariable);
assertEquals(2, tasksByVariable.size());
assertEquals(processInstanceId2, tasksByVariable.get(0).getProcessInstanceId());
assertEquals(processInstanceId, tasksByVariable.get(1).getProcessInstanceId());
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
processService.abortProcessInstance(processInstanceId2);
}
Aggregations