Search in sources :

Example 1 with Process

use of org.kie.kogito.process.Process in project kogito-runtimes by kiegroup.

the class EventImplTest method setup.

@BeforeEach
void setup() {
    application = mock(Application.class);
    when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
    process = mock(Process.class);
    processInstances = mock(ProcessInstances.class);
    processInstance = mock(ProcessInstance.class);
    when(process.instances()).thenReturn(processInstances);
    when(processInstances.findById(Mockito.anyString())).thenReturn(Optional.of(processInstance));
    when(process.createInstance(Mockito.any(DummyModel.class))).thenReturn(processInstance);
    processService = mock(ProcessService.class);
    executor = Executors.newSingleThreadExecutor();
}
Also used : ProcessInstances(org.kie.kogito.process.ProcessInstances) CollectingUnitOfWorkFactory(org.kie.kogito.services.uow.CollectingUnitOfWorkFactory) Process(org.kie.kogito.process.Process) ProcessInstance(org.kie.kogito.process.ProcessInstance) ProcessService(org.kie.kogito.process.ProcessService) Application(org.kie.kogito.Application) DefaultUnitOfWorkManager(org.kie.kogito.services.uow.DefaultUnitOfWorkManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with Process

use of org.kie.kogito.process.Process in project kogito-runtimes by kiegroup.

the class PublishEventIT method testProcessWithMilestoneEvents.

@Test
public void testProcessWithMilestoneEvents() throws Exception {
    Application app = generateCodeProcessesOnly("cases/milestones/SimpleMilestone.bpmn");
    assertThat(app).isNotNull();
    TestEventPublisher publisher = new TestEventPublisher();
    app.unitOfWorkManager().eventManager().setService("http://myhost");
    app.unitOfWorkManager().eventManager().addPublisher(publisher);
    UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    Process<? extends Model> p = app.get(Processes.class).processById("TestCase.SimpleMilestone");
    ProcessInstance<?> processInstance = p.createInstance(p.createModel());
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    uow.end();
    List<DataEvent<?>> events = publisher.extract();
    assertThat(events).isNotNull().hasSize(1);
    DataEvent<?> event = events.get(0);
    assertThat(event).isInstanceOf(ProcessInstanceDataEvent.class);
    ProcessInstanceDataEvent processDataEvent = (ProcessInstanceDataEvent) event;
    assertThat(processDataEvent.getKogitoProcessinstanceId()).isNotNull();
    assertThat(processDataEvent.getKogitoParentProcessinstanceId()).isNull();
    assertThat(processDataEvent.getKogitoRootProcessinstanceId()).isNull();
    assertThat(processDataEvent.getKogitoProcessId()).isEqualTo("TestCase.SimpleMilestone");
    assertThat(processDataEvent.getKogitoProcessinstanceState()).isEqualTo("2");
    assertThat(processDataEvent.getSource().toString()).isEqualTo("http://myhost/SimpleMilestone");
    Set<MilestoneEventBody> milestones = ((ProcessInstanceDataEvent) event).getData().getMilestones();
    assertThat(milestones).hasSize(2).extracting(e -> e.getName(), e -> e.getStatus()).containsExactlyInAnyOrder(tuple("AutoStartMilestone", Status.COMPLETED.name()), tuple("SimpleMilestone", Status.COMPLETED.name()));
}
Also used : UnitOfWork(org.kie.kogito.uow.UnitOfWork) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UserTaskInstanceEventBody(org.kie.kogito.services.event.impl.UserTaskInstanceEventBody) HashMap(java.util.HashMap) Status(org.kie.kogito.process.flexible.ItemDescription.Status) Person(org.kie.kogito.codegen.data.Person) ArrayList(java.util.ArrayList) AbstractCodegenIT(org.kie.kogito.codegen.AbstractCodegenIT) VariableInstanceEventBody(org.kie.kogito.services.event.impl.VariableInstanceEventBody) Map(java.util.Map) UserTaskInstanceDataEvent(org.kie.kogito.services.event.UserTaskInstanceDataEvent) Process(org.kie.kogito.process.Process) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Assertions.tuple(org.assertj.core.api.Assertions.tuple) StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) Collection(java.util.Collection) Set(java.util.Set) MilestoneEventBody(org.kie.kogito.services.event.impl.MilestoneEventBody) ProcessInstanceEventBody(org.kie.kogito.services.event.impl.ProcessInstanceEventBody) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test) List(java.util.List) ProcessInstance(org.kie.kogito.process.ProcessInstance) Model(org.kie.kogito.Model) EventPublisher(org.kie.kogito.event.EventPublisher) ProcessError(org.kie.kogito.process.ProcessError) DataEvent(org.kie.kogito.event.DataEvent) VariableInstanceDataEvent(org.kie.kogito.services.event.VariableInstanceDataEvent) Processes(org.kie.kogito.process.Processes) Collections(java.util.Collections) WorkItem(org.kie.kogito.process.WorkItem) UnitOfWork(org.kie.kogito.uow.UnitOfWork) UserTaskInstanceDataEvent(org.kie.kogito.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) DataEvent(org.kie.kogito.event.DataEvent) VariableInstanceDataEvent(org.kie.kogito.services.event.VariableInstanceDataEvent) Processes(org.kie.kogito.process.Processes) MilestoneEventBody(org.kie.kogito.services.event.impl.MilestoneEventBody) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 3 with Process

use of org.kie.kogito.process.Process in project kogito-runtimes by kiegroup.

the class AdHocFragmentsIT method testStartUserTask.

@Test
void testStartUserTask() throws Exception {
    String taskName = "AdHoc User Task";
    Application app = generateCodeProcessesOnly("cases/AdHocFragments.bpmn");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.get(Processes.class).processById("TestCase.AdHocFragments");
    ProcessInstance<? extends Model> processInstance = p.createInstance(p.createModel());
    processInstance.start();
    Optional<WorkItem> workItem = processInstance.workItems().stream().filter(wi -> wi.getParameters().get("NodeName").equals(taskName)).findFirst();
    assertThat(workItem).isNotPresent();
    processInstance.send(Sig.of(taskName, p.createModel()));
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.status());
    workItem = processInstance.workItems().stream().filter(wi -> wi.getParameters().get("NodeName").equals(taskName)).findFirst();
    assertThat(workItem).isPresent();
    assertThat(workItem.get().getId()).isNotBlank();
    assertThat(workItem.get().getName()).isNotBlank();
}
Also used : ActionNode(org.jbpm.workflow.core.node.ActionNode) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) Collection(java.util.Collection) AdHocFragment(org.kie.kogito.process.flexible.AdHocFragment) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Application(org.kie.kogito.Application) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) AbstractCodegenIT(org.kie.kogito.codegen.AbstractCodegenIT) ProcessInstance(org.kie.kogito.process.ProcessInstance) Model(org.kie.kogito.Model) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) Map(java.util.Map) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Process(org.kie.kogito.process.Process) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Processes(org.kie.kogito.process.Processes) WorkItem(org.kie.kogito.process.WorkItem) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) WorkItem(org.kie.kogito.process.WorkItem) Test(org.junit.jupiter.api.Test)

Example 4 with Process

use of org.kie.kogito.process.Process 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()));
    }
}
Also used : org.kie.kogito.process(org.kie.kogito.process) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) Collection(java.util.Collection) Policy(org.kie.kogito.incubation.processes.services.contexts.Policy) MappableToModel(org.kie.kogito.MappableToModel) HumanTaskHelper(org.jbpm.process.instance.impl.humantask.HumanTaskHelper) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) HumanTaskService(org.kie.kogito.incubation.processes.services.humantask.HumanTaskService) UnitOfWorkExecutor(org.kie.kogito.services.uow.UnitOfWorkExecutor) Application(org.kie.kogito.Application) KogitoNode(org.kie.kogito.internal.process.runtime.KogitoNode) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) org.kie.kogito.incubation.processes(org.kie.kogito.incubation.processes) List(java.util.List) Model(org.kie.kogito.Model) org.kie.kogito.incubation.common(org.kie.kogito.incubation.common) IdentityProviders(org.kie.kogito.auth.IdentityProviders) Map(java.util.Map) Process(org.kie.kogito.process.Process) TaskMetaDataContext(org.kie.kogito.incubation.processes.services.contexts.TaskMetaDataContext) TaskMetaDataContext(org.kie.kogito.incubation.processes.services.contexts.TaskMetaDataContext) Process(org.kie.kogito.process.Process) MappableToModel(org.kie.kogito.MappableToModel) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) MappableToModel(org.kie.kogito.MappableToModel) Model(org.kie.kogito.Model)

Example 5 with Process

use of org.kie.kogito.process.Process in project kogito-runtimes by kiegroup.

the class StatefulProcessServiceImpl method create.

@Override
public ExtendedDataContext create(LocalId localId, DataContext inputContext) {
    LocalProcessId processId = ProcessIdParser.select(localId, LocalProcessId.class);
    ExtendedDataContext extendedDataContext = inputContext.as(ExtendedDataContext.class);
    ProcessMetaDataContext inputMeta = inputContext.as(ProcessMetaDataContext.class);
    Process<Model> process = (Process<Model>) (Object) parseProcess(processId);
    String businessKey = inputMeta.businessKey();
    Model model = toModel(extendedDataContext.data(), process);
    String startFromNodeId = inputMeta.startFrom();
    ProcessInstance<Model> instance = svc.createProcessInstance(process, businessKey, model, startFromNodeId);
    MapDataContext data = MapDataContext.from(instance.variables().toMap());
    ProcessMetaDataContext meta = ProcessMetaDataContext.of(processId.instances().get(instance.id()));
    return ExtendedDataContext.of(meta, data);
}
Also used : LocalProcessId(org.kie.kogito.incubation.processes.LocalProcessId) ProcessMetaDataContext(org.kie.kogito.incubation.processes.services.contexts.ProcessMetaDataContext) MappableToModel(org.kie.kogito.MappableToModel) Model(org.kie.kogito.Model) Process(org.kie.kogito.process.Process)

Aggregations

Process (org.kie.kogito.process.Process)8 Application (org.kie.kogito.Application)6 Model (org.kie.kogito.Model)6 Collection (java.util.Collection)5 List (java.util.List)5 Map (java.util.Map)5 ProcessInstance (org.kie.kogito.process.ProcessInstance)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Test (org.junit.jupiter.api.Test)4 SecurityPolicy (org.kie.kogito.auth.SecurityPolicy)4 WorkItem (org.kie.kogito.process.WorkItem)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Objects (java.util.Objects)3 Collectors (java.util.stream.Collectors)3 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)3 MappableToModel (org.kie.kogito.MappableToModel)3 AbstractCodegenIT (org.kie.kogito.codegen.AbstractCodegenIT)3 Collections (java.util.Collections)2 Optional (java.util.Optional)2