use of org.kie.internal.task.api.TaskInstanceService in project jbpm by kiegroup.
the class CompleteTaskCommand method execute.
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
doCallbackUserOperation(userId, context, true);
groupIds = doUserGroupCallbackOperation(userId, null, context);
context.set("local:groups", groupIds);
Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
if (task == null) {
throw new PermissionDeniedException("Task '" + taskId + "' not found");
}
context.loadTaskVariables(task);
Map<String, Object> outputdata = task.getTaskData().getTaskOutputVariables();
if (outputdata != null) {
// if there are data given with completion, merged them into existing outputs
if (data != null) {
outputdata.putAll(data);
}
// since output data was non null make it the actual data
data = outputdata;
}
context.getTaskRuleService().executeRules(task, userId, data, TaskRuleService.COMPLETE_TASK_SCOPE);
((InternalTaskData) task.getTaskData()).setTaskOutputVariables(data);
TaskInstanceService instanceService = context.getTaskInstanceService();
instanceService.complete(taskId, userId, data);
return null;
}
use of org.kie.internal.task.api.TaskInstanceService in project jbpm by kiegroup.
the class ProcessSubTaskCommand method execute.
@Override
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
TaskInstanceService instanceService = context.getTaskInstanceService();
TaskQueryService queryService = context.getTaskQueryService();
Task task = queryService.getTaskInstanceById(taskId);
if (task == null) {
return null;
}
Task parentTask = null;
if (task.getTaskData().getParentId() != -1) {
parentTask = queryService.getTaskInstanceById(task.getTaskData().getParentId());
}
if (parentTask != null) {
if (((InternalTask) parentTask).getSubTaskStrategy() != null && ((InternalTask) parentTask).getSubTaskStrategy().equals(SubTasksStrategy.EndParentOnAllSubTasksEnd)) {
List<TaskSummary> subTasks = queryService.getSubTasksByParent(parentTask.getId());
// If there are no more sub tasks or if the last sub task is the one that we are completing now
if (subTasks.isEmpty() || (subTasks.size() == 1 && subTasks.get(0).getId().equals(taskId))) {
// Completing parent task if all the sub task has being completed, including the one that we are completing now
instanceService.complete(parentTask.getId(), "Administrator", data);
}
}
}
if (((InternalTask) task).getSubTaskStrategy() != null && ((InternalTask) task).getSubTaskStrategy().equals(SubTasksStrategy.SkipAllSubTasksOnParentSkip)) {
List<TaskSummary> subTasks = queryService.getSubTasksByParent(task.getId());
for (TaskSummary taskSummary : subTasks) {
Task subTask = queryService.getTaskInstanceById(taskSummary.getId());
// Exit each sub task because the parent task was aborted
instanceService.skip(subTask.getId(), "Administrator");
}
}
return null;
}
use of org.kie.internal.task.api.TaskInstanceService in project jbpm by kiegroup.
the class SetTaskPropertyCommand method execute.
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
TaskInstanceService service = context.getTaskInstanceService();
switch(property) {
case FAULT_PROPERTY:
doCallbackUserOperation(userId, context, true);
service.setFault(taskId, userId, faultData);
break;
case OUTPUT_PROPERTY:
doCallbackUserOperation(userId, context, true);
service.setOutput(taskId, userId, output);
break;
case PRIORITY_PROPERTY:
service.setPriority(taskId, priority);
break;
case TASK_NAMES_PROPERTY:
List<I18NText> names = null;
if (namesOrDescriptions != null) {
names = JaxbI18NText.convertListFromJaxbImplToInterface(namesOrDescriptions);
}
service.setTaskNames(taskId, names);
break;
case EXPIRATION_DATE_PROPERTY:
service.setExpirationDate(taskId, expirationDate);
break;
case DESCRIPTION_PROPERTY:
List<I18NText> descriptions = null;
if (namesOrDescriptions != null) {
descriptions = JaxbI18NText.convertListFromJaxbImplToInterface(namesOrDescriptions);
}
service.setDescriptions(taskId, descriptions);
break;
case SKIPPABLE_PROPERTY:
service.setSkipable(taskId, skippable);
break;
case SUB_TASK_STRATEGY_PROPERTY:
service.setSubTaskStrategy(taskId, subTasksStrategy);
break;
default:
throw new IllegalStateException("Unknown property in " + this.getClass().getSimpleName() + " execute: " + property);
}
return null;
}
use of org.kie.internal.task.api.TaskInstanceService in project jbpm by kiegroup.
the class GetTaskPropertyCommand method execute.
public Object execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
TaskInstanceService service = context.getTaskInstanceService();
Object result = null;
switch(property) {
case SetTaskPropertyCommand.PRIORITY_PROPERTY:
result = service.getPriority(taskId);
break;
case SetTaskPropertyCommand.EXPIRATION_DATE_PROPERTY:
result = service.getExpirationDate(taskId);
break;
case SetTaskPropertyCommand.DESCRIPTION_PROPERTY:
result = service.getDescriptions(taskId);
break;
case SetTaskPropertyCommand.SKIPPABLE_PROPERTY:
result = service.isSkipable(taskId);
break;
case SetTaskPropertyCommand.SUB_TASK_STRATEGY_PROPERTY:
result = service.getSubTaskStrategy(taskId);
break;
default:
break;
}
return result;
}
use of org.kie.internal.task.api.TaskInstanceService in project jbpm by kiegroup.
the class JaxbTaskSerializationTest method setTaskPropertyCommandTest.
@Test
public void setTaskPropertyCommandTest() throws Exception {
SetTaskPropertyCommand cmd;
int taskId = 1;
String userId = "user";
FaultDataImpl faultData = new FaultDataImpl();
faultData.setAccessType(AccessType.Inline);
faultData.setContent("skinned shins".getBytes());
faultData.setFaultName("Whoops!");
faultData.setType("skates");
List<I18NText> textList = new ArrayList<I18NText>();
I18NText text = new I18NTextImpl("nl-NL", "Stroopwafel!");
textList.add(text);
Object[][] testData = { { FAULT_PROPERTY, faultData }, { OUTPUT_PROPERTY, new Object() }, { PRIORITY_PROPERTY, 23 }, { TASK_NAMES_PROPERTY, textList }, { EXPIRATION_DATE_PROPERTY, new Date() }, { DESCRIPTION_PROPERTY, new ArrayList<I18NText>() }, { SKIPPABLE_PROPERTY, false }, { SUB_TASK_STRATEGY_PROPERTY, SubTasksStrategy.EndParentOnAllSubTasksEnd } };
TaskContext mockContext = mock(TaskContext.class);
TaskInstanceService mockTaskService = mock(TaskInstanceService.class);
UserGroupCallback mockUserGroupCallback = mock(UserGroupCallback.class);
when(mockContext.getTaskInstanceService()).thenReturn(mockTaskService);
when(mockContext.getUserGroupCallback()).thenReturn(mockUserGroupCallback);
when(mockUserGroupCallback.existsUser(anyString())).thenReturn(false);
for (Object[] data : testData) {
int property = (Integer) data[0];
cmd = new SetTaskPropertyCommand(taskId, userId, property, data[1]);
try {
cmd.execute(mockContext);
} catch (IllegalArgumentException e) {
// expected for fault and output
assertTrue(e.getMessage().startsWith("User user was not found in callback "));
}
}
}
Aggregations