use of org.kie.kogito.MappableToModel in project kogito-runtimes by kiegroup.
the class HumanTaskServiceImpl method get.
@Override
public ExtendedDataContext get(LocalId id, MetaDataContext meta) {
TaskMetaDataContext metaCtx = meta.as(TaskMetaDataContext.class);
SecurityPolicy securityPolicy = convertPolicyObject(metaCtx.policy());
try {
// /tasks
TaskIds taskIds = ProcessIdParser.select(id, TaskIds.class);
ProcessInstanceId instanceId = taskIds.processInstanceId();
Process<MappableToModel<Model>> process = parseProcess(instanceId.processId());
String processInstanceIdString = instanceId.processInstanceId();
List<String> tasks = svc.getTasks(process, processInstanceIdString, securityPolicy).orElseThrow().stream().map(wi -> taskIds.get(wi.getName()).instances().get(wi.getId()).asLocalUri().path()).collect(Collectors.toList());
MapDataContext mdc = MapDataContext.create();
mdc.set("tasks", tasks);
return ExtendedDataContext.of(mdc, EmptyDataContext.Instance);
} catch (IllegalArgumentException e) {
// /tasks/id
TaskInstanceId taskInstanceId = ProcessIdParser.select(id, TaskInstanceId.class);
ProcessInstanceId instanceId = taskInstanceId.taskId().processInstanceId();
Process<MappableToModel<Model>> process = parseProcess(instanceId.processId());
String taskInstanceIdString = taskInstanceId.taskInstanceId();
String processInstanceIdString = instanceId.processInstanceId();
WorkItem workItem = svc.getTask(process, processInstanceIdString, taskInstanceIdString, securityPolicy, Function.identity()).orElseThrow(() -> new IllegalArgumentException("Cannot find ID " + id.asLocalUri().path()));
return ExtendedDataContext.ofData(MapDataContext.of(workItem.getResults()));
}
}
use of org.kie.kogito.MappableToModel in project kogito-runtimes by kiegroup.
the class StatefulProcessServiceImpl method signal.
@Override
public ExtendedDataContext signal(LocalId localId, DataContext dataContext) {
SignalId signalId = ProcessIdParser.select(localId, SignalId.class);
Process<MappableToModel<Model>> process = parseProcess(signalId.processInstanceId().processId());
Model m = svc.signalProcessInstance(process, signalId.processInstanceId().processInstanceId(), dataContext, signalId.signalId()).orElseThrow();
MapDataContext data = MapDataContext.from(m.toMap());
ProcessMetaDataContext meta = ProcessMetaDataContext.of(signalId.processInstanceId());
return ExtendedDataContext.of(meta, data);
}
use of org.kie.kogito.MappableToModel in project kogito-runtimes by kiegroup.
the class StatefulProcessServiceImpl method update.
@Override
public ExtendedDataContext update(LocalId localId, DataContext dataContext) {
ProcessInstanceId instanceId = ProcessIdParser.select(localId, ProcessInstanceId.class);
Process<MappableToModel<Model>> process = parseProcess(instanceId.processId());
MappableToModel<Model> model = (MappableToModel<Model>) toModel(dataContext, process);
Optional<Model> optionalModel = svc.update(process, instanceId.processInstanceId(), model);
Model m = optionalModel.orElseThrow();
Map<String, Object> map = m.toMap();
return ExtendedDataContext.ofData(MapDataContext.from(map));
}
use of org.kie.kogito.MappableToModel in project kogito-runtimes by kiegroup.
the class StatefulProcessServiceImpl method get.
@Override
public ExtendedDataContext get(LocalId localId) {
ProcessInstanceId processInstanceId = ProcessIdParser.select(localId, ProcessInstanceId.class);
Process<MappableToModel<Model>> process = parseProcess(processInstanceId.processId());
Model m = svc.findById(process, processInstanceId.processInstanceId()).orElseThrow();
ProcessMetaDataContext meta = ProcessMetaDataContext.of(localId);
MapDataContext data = MapDataContext.of(m.toMap());
return ExtendedDataContext.of(meta, data);
}
use of org.kie.kogito.MappableToModel in project kogito-runtimes by kiegroup.
the class HumanTaskServiceImpl method transition.
@Override
public ExtendedDataContext transition(LocalId id, DataContext dataContext) {
ExtendedDataContext edc = dataContext.as(ExtendedDataContext.class);
TaskMetaDataContext mdc = edc.meta().as(TaskMetaDataContext.class);
SecurityPolicy securityPolicy = convertPolicyObject(mdc.policy());
String phase = mdc.phase();
Objects.requireNonNull(phase, "Phase must be specified");
TaskInstanceId taskInstanceId = ProcessIdParser.select(id, TaskInstanceId.class);
// must validate the task id
TaskId taskId = taskInstanceId.taskId();
ProcessInstanceId instanceId = taskId.processInstanceId();
Process<MappableToModel<Model>> process = parseProcess(instanceId.processId());
Collection<KogitoNode> tasks = process.findNodes(n -> n instanceof HumanTaskNode && ((HumanTaskNode) n).getWork().getParameter("TaskName").equals(taskId.taskId()));
if (tasks.isEmpty()) {
throw new IllegalArgumentException("No such taskId " + taskId.taskId());
}
String taskInstanceIdString = taskInstanceId.taskInstanceId();
String processInstanceIdString = instanceId.processInstanceId();
Map<String, Object> map = dataContext.as(MapDataContext.class).toMap();
MappableToModel<Model> model = process.createModel();
model.fromMap(map);
Model result = svc.taskTransition(process, processInstanceIdString, taskInstanceIdString, phase, securityPolicy, model).orElseThrow();
return ExtendedDataContext.ofData(MapDataContext.of(result.toMap()));
}
Aggregations