use of org.kie.kogito.process.workitem.Policy in project kogito-runtimes by kiegroup.
the class BaseHumanTaskLifeCycle method transitionTo.
@Override
public Map<String, Object> transitionTo(KogitoWorkItem workItem, KogitoWorkItemManager manager, Transition<Map<String, Object>> transition) {
logger.debug("Transition method invoked for work item {} to transition to {}, currently in phase {} and status {}", workItem.getStringId(), transition.phase(), workItem.getPhaseId(), workItem.getPhaseStatus());
HumanTaskWorkItemImpl humanTaskWorkItem = (HumanTaskWorkItemImpl) workItem;
LifeCyclePhase targetPhase = phases.get(transition.phase());
if (targetPhase == null) {
logger.debug("Target life cycle phase '{}' does not exist in {}", transition.phase(), this.getClass().getSimpleName());
throw new InvalidLifeCyclePhaseException(transition.phase());
}
LifeCyclePhase currentPhase = phases.get(humanTaskWorkItem.getPhaseId());
if (!targetPhase.canTransition(currentPhase)) {
logger.debug("Target life cycle phase '{}' cannot transition from current state '{}'", targetPhase.id(), currentPhase.id());
throw new InvalidTransitionException("Cannot transition from " + humanTaskWorkItem.getPhaseId() + " to " + targetPhase.id());
}
if (!targetPhase.id().equals(Active.ID) && !targetPhase.id().equals(Abort.ID) && !humanTaskWorkItem.enforce(transition.policies().toArray(new Policy[transition.policies().size()]))) {
throw new NotAuthorizedException("User is not authorized to access task instance with id " + humanTaskWorkItem.getStringId());
}
humanTaskWorkItem.setPhaseId(targetPhase.id());
humanTaskWorkItem.setPhaseStatus(targetPhase.status());
targetPhase.apply(humanTaskWorkItem, transition);
if (transition.data() != null) {
logger.debug("Updating data for phase {} and work item {}", targetPhase.id(), humanTaskWorkItem.getStringId());
humanTaskWorkItem.getResults().putAll(transition.data());
}
logger.debug("Transition for work item {} to {} done, currently in phase {} and status {}", workItem.getStringId(), transition.phase(), workItem.getPhaseId(), workItem.getPhaseStatus());
if (targetPhase.isTerminating()) {
logger.debug("Target life cycle phase '{}' is terminiating, completing work item {}", targetPhase.id(), humanTaskWorkItem.getStringId());
// since target life cycle phase is terminating completing work item
((InternalKogitoWorkItemManager) manager).internalCompleteWorkItem(humanTaskWorkItem);
}
return data(humanTaskWorkItem);
}
use of org.kie.kogito.process.workitem.Policy in project kogito-runtimes by kiegroup.
the class TaskManagementService method updateTask.
@Override
public TaskInfo updateTask(String processId, String processInstanceId, String taskId, TaskInfo taskInfo, boolean shouldReplace, Policy<?>... policies) {
ProcessInstance<?> pi = getProcessInstance(processId, processInstanceId, taskId);
KogitoWorkItem workItem = UnitOfWorkExecutor.executeInUnitOfWork(processConfig.unitOfWorkManager(), () -> pi.updateWorkItem(taskId, wi -> {
HumanTaskWorkItemImpl humanTask = HumanTaskHelper.asHumanTask(wi);
setField(humanTask::setAdminGroups, taskInfo::getAdminGroups, shouldReplace);
setField(humanTask::setAdminUsers, taskInfo::getAdminUsers, shouldReplace);
setField(humanTask::setExcludedUsers, taskInfo::getExcludedUsers, shouldReplace);
setField(humanTask::setPotentialUsers, taskInfo::getPotentialUsers, shouldReplace);
setField(humanTask::setPotentialGroups, taskInfo::getPotentialGroups, shouldReplace);
setField(humanTask::setTaskPriority, taskInfo::getPriority, shouldReplace);
setField(humanTask::setTaskDescription, taskInfo::getDescription, shouldReplace);
setMap(humanTask::setParameters, humanTask::setParameter, taskInfo.getInputParams(), shouldReplace);
return wi;
}, policies));
return convert((HumanTaskWorkItem) workItem);
}
use of org.kie.kogito.process.workitem.Policy in project kogito-runtimes by kiegroup.
the class JsonSchemaUtilTest method testJsonSchemaPhases.
@Test
<T> void testJsonSchemaPhases() throws IOException {
InputStream in = new ByteArrayInputStream(example.getBytes());
Policy<T>[] policies = new Policy[0];
Map<String, Object> schemaMap = JsonSchemaUtil.load(in);
in.close();
Process<T> process = mock(Process.class);
ProcessInstances<T> processInstances = mock(ProcessInstances.class);
when(process.instances()).thenReturn(processInstances);
ProcessInstance<T> processInstance = mock(ProcessInstance.class);
when(processInstances.findById("pepe", ProcessInstanceReadMode.READ_ONLY)).thenReturn((Optional) Optional.of(processInstance));
WorkItem task = mock(WorkItem.class);
when(processInstance.workItem("task", policies)).thenReturn(task);
when(task.getPhase()).thenReturn("active");
Config config = mock(Config.class);
ProcessConfig processConfig = mock(ProcessConfig.class);
when(config.get(any())).thenReturn(processConfig);
WorkItemHandlerConfig workItemHandlerConfig = mock(WorkItemHandlerConfig.class);
when(processConfig.workItemHandlers()).thenReturn(workItemHandlerConfig);
KogitoWorkItemHandler workItemHandler = new HumanTaskWorkItemHandler();
when(workItemHandlerConfig.forName("Human Task")).thenReturn(workItemHandler);
schemaMap = JsonSchemaUtil.addPhases(process, workItemHandler, "pepe", "task", policies, schemaMap);
assertFalse(((Collection) schemaMap.get("phases")).isEmpty());
}
Aggregations