Search in sources :

Example 1 with AbstractProcess

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

the class ProtobufProcessInstanceReader method buildWorkflow.

private RuleFlowProcessInstance buildWorkflow(KogitoProcessInstanceProtobuf.ProcessInstance processInstanceProtobuf) {
    RuleFlowProcessInstance processInstance = ruleFlowProcessInstance;
    processInstance.setProcess(((AbstractProcess<?>) context.get(MarshallerContextName.MARSHALLER_PROCESS)).get());
    processInstance.setId(processInstanceProtobuf.getId());
    processInstance.setProcessId(processInstanceProtobuf.getProcessId());
    processInstance.setState(processInstanceProtobuf.getState());
    processInstance.setSignalCompletion(processInstanceProtobuf.getSignalCompletion());
    processInstance.setStartDate(new Date(processInstanceProtobuf.getStartDate()));
    processInstance.setDescription(processInstanceProtobuf.getDescription());
    processInstance.setDeploymentId(processInstanceProtobuf.getDeploymentId());
    for (String completedNodeId : processInstanceProtobuf.getCompletedNodeIdsList()) {
        processInstance.addCompletedNodeId(completedNodeId);
    }
    processInstance.setCorrelationKey(processInstanceProtobuf.getBusinessKey());
    SLAContext slaContext = processInstanceProtobuf.getSla();
    if (slaContext.getSlaDueDate() > 0) {
        processInstance.internalSetSlaDueDate(new Date(slaContext.getSlaDueDate()));
    }
    processInstance.internalSetSlaTimerId(slaContext.getSlaTimerId());
    processInstance.internalSetSlaCompliance(slaContext.getSlaCompliance());
    processInstance.setParentProcessInstanceId(processInstanceProtobuf.getParentProcessInstanceId());
    processInstance.setRootProcessInstanceId(processInstanceProtobuf.getRootProcessInstanceId());
    processInstance.setRootProcessId(processInstanceProtobuf.getRootProcessId());
    processInstance.internalSetErrorNodeId(processInstanceProtobuf.getErrorNodeId());
    processInstance.internalSetErrorMessage(processInstanceProtobuf.getErrorMessage());
    processInstance.setReferenceId(processInstanceProtobuf.getReferenceId());
    if (processInstanceProtobuf.getSwimlaneContextCount() > 0) {
        SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
        for (KogitoTypesProtobuf.SwimlaneContext _swimlane : processInstanceProtobuf.getSwimlaneContextList()) {
            swimlaneContextInstance.setActorId(_swimlane.getSwimlane(), _swimlane.getActorId());
        }
    }
    WorkflowContext workflowContext = processInstanceProtobuf.getContext();
    for (KogitoTypesProtobuf.NodeInstance nodeInstanceProtobuf : workflowContext.getNodeInstanceList()) {
        NodeInstanceImpl nodeInstanceImpl = buildNodeInstance(nodeInstanceProtobuf, processInstance);
        if (nodeInstanceProtobuf.hasTriggerDate()) {
            nodeInstanceImpl.internalSetTriggerTime(new Date(nodeInstanceProtobuf.getTriggerDate()));
        }
    }
    for (KogitoTypesProtobuf.NodeInstanceGroup group : workflowContext.getExclusiveGroupList()) {
        Function<String, KogitoNodeInstance> finder = nodeInstanceId -> processInstance.getNodeInstance(nodeInstanceId, true);
        processInstance.addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, buildExclusiveGroupInstance(group, finder));
    }
    processInstance.addContextInstance(VariableScope.VARIABLE_SCOPE, new VariableScopeInstance());
    if (workflowContext.getVariableCount() > 0) {
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
        varReader.buildVariables(workflowContext.getVariableList()).forEach(v -> variableScopeInstance.internalSetVariable(v.getName(), v.getValue()));
    }
    if (workflowContext.getIterationLevelsCount() > 0) {
        processInstance.getIterationLevels().putAll(buildIterationLevels(workflowContext.getIterationLevelsList()));
    }
    return processInstance;
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) Comment(org.kie.kogito.process.workitem.Comment) ProtobufTypeRegistryFactory.protobufTypeRegistryFactoryInstance(org.kie.kogito.serialization.process.protobuf.ProtobufTypeRegistryFactory.protobufTypeRegistryFactoryInstance) Date(java.util.Date) RuleSetNodeInstance(org.jbpm.workflow.instance.node.RuleSetNodeInstance) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ExclusiveGroupInstance(org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) MarshallerContextName(org.kie.kogito.serialization.process.MarshallerContextName) HumanTaskWorkItemData(org.kie.kogito.serialization.process.protobuf.KogitoWorkItemsProtobuf.HumanTaskWorkItemData) KogitoNodeInstanceContainer(org.kie.kogito.internal.process.runtime.KogitoNodeInstanceContainer) StateNodeInstance(org.jbpm.workflow.instance.node.StateNodeInstance) TimerNodeInstance(org.jbpm.workflow.instance.node.TimerNodeInstance) MarshallerReaderContext(org.kie.kogito.serialization.process.MarshallerReaderContext) Map(java.util.Map) CompositeContextNodeInstance(org.jbpm.workflow.instance.node.CompositeContextNodeInstance) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) MilestoneNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.MilestoneNodeInstanceContent) ProcessInstanceMarshallerException(org.kie.kogito.serialization.process.ProcessInstanceMarshallerException) URI(java.net.URI) EventNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.EventNodeInstanceContent) WorkflowContext(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf.WorkflowContext) Attachment(org.kie.kogito.process.workitem.Attachment) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ForEachNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.ForEachNodeInstanceContent) DynamicNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.DynamicNodeInstanceContent) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) KogitoTypesProtobuf(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf) VariableScope(org.jbpm.process.core.context.variable.VariableScope) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) List(java.util.List) EventSubProcessNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.EventSubProcessNodeInstanceContent) JsonFormat(com.google.protobuf.util.JsonFormat) ExclusiveGroup(org.jbpm.process.core.context.exclusive.ExclusiveGroup) Any(com.google.protobuf.Any) NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) StateNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.StateNodeInstanceContent) SwimlaneContext(org.jbpm.process.core.context.swimlane.SwimlaneContext) AbstractProcess(org.kie.kogito.process.impl.AbstractProcess) CompositeContextNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.CompositeContextNodeInstanceContent) KogitoWorkItemsProtobuf(org.kie.kogito.serialization.process.protobuf.KogitoWorkItemsProtobuf) HashMap(java.util.HashMap) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) JoinNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.JoinNodeInstanceContent) Function(java.util.function.Function) ArrayList(java.util.ArrayList) AsyncEventNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.AsyncEventNodeInstanceContent) WorkItemNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.WorkItemNodeInstanceContent) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) LambdaSubProcessNodeInstance(org.jbpm.workflow.instance.node.LambdaSubProcessNodeInstance) LambdaSubProcessNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.LambdaSubProcessNodeInstanceContent) KogitoProcessInstanceProtobuf(org.kie.kogito.serialization.process.protobuf.KogitoProcessInstanceProtobuf) SubProcessNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.SubProcessNodeInstanceContent) TimerNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.TimerNodeInstanceContent) IOException(java.io.IOException) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) InputStreamReader(java.io.InputStreamReader) SwimlaneContextInstance(org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance) ForEachNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance) RuleSetNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.RuleSetNodeInstanceContent) SLAContext(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf.SLAContext) HumanTaskWorkItemImpl(org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl) AsyncEventNodeInstance(org.jbpm.workflow.core.node.AsyncEventNodeInstance) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl) MilestoneNodeInstance(org.jbpm.workflow.instance.node.MilestoneNodeInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) JoinInstance(org.jbpm.workflow.instance.node.JoinInstance) Reassignment(org.jbpm.process.instance.impl.humantask.Reassignment) InputStream(java.io.InputStream) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) SwimlaneContextInstance(org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance) WorkflowContext(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf.WorkflowContext) KogitoTypesProtobuf(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf) Date(java.util.Date) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) SLAContext(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf.SLAContext)

Example 2 with AbstractProcess

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

the class ProcessGenerationIT method testProcessGeneration.

@ParameterizedTest
@MethodSource("processesProvider")
public void testProcessGeneration(String processFile) throws Exception {
    // for some tests this needs to be set to true
    System.setProperty("jbpm.enable.multi.con", "true");
    ProcessCodegen processCodeGen = ProcessCodegen.ofCollectedResources(newContext(), Collections.singletonList(new CollectedResource(BASE_PATH, new FileSystemResource(new File(BASE_PATH.toString(), processFile)))));
    RuleFlowProcess expected = (RuleFlowProcess) processCodeGen.processes().iterator().next();
    Application app = generateCodeProcessesOnly(processFile);
    AbstractProcess<? extends Model> process = (AbstractProcess<? extends Model>) app.get(Processes.class).processById(expected.getId());
    assertThat(process).isNotNull().isSameAs(app.get(Processes.class).processById(expected.getId()));
    RuleFlowProcess current = (RuleFlowProcess) process.get();
    assertNotNull(current);
    assertEquals(expected.getId(), current.getId(), "Id");
    assertEquals(expected.getName(), current.getName(), "Name");
    assertEquals(expected.getPackageName(), current.getPackageName(), "PackageName");
    assertEquals(expected.getVisibility(), current.getVisibility(), "Visibility");
    assertEquals(expected.getType(), current.getType(), "Type");
    assertEquals(expected.isAutoComplete(), current.isAutoComplete(), "AutoComplete");
    assertEquals(expected.isDynamic(), current.isDynamic(), "Dynamic");
    if (expected.getVersion() != null) {
        assertEquals(expected.getVersion(), current.getVersion());
    } else {
        assertEquals("1.0", current.getVersion());
    }
    assertEquals(expected.getImports(), current.getImports(), "Imports");
    assertEquals(expected.getFunctionImports(), current.getFunctionImports(), "FunctionImports");
    assertMetadata(expected.getMetaData(), current.getMetaData(), IGNORED_PROCESS_META);
    assertNodes(expected.getNodes(), current.getNodes());
    System.clearProperty("jbpm.enable.multi.con");
}
Also used : CollectedResource(org.kie.kogito.codegen.api.io.CollectedResource) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) AbstractProcess(org.kie.kogito.process.impl.AbstractProcess) Model(org.kie.kogito.Model) FileSystemResource(org.drools.core.io.impl.FileSystemResource) File(java.io.File) Application(org.kie.kogito.Application) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with AbstractProcess

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

the class ProcessInstanceManagementResourceTest method setup.

@SuppressWarnings({ "rawtypes", "unchecked" })
@BeforeEach
public void setup() {
    responseBuilder = mock(ResponseBuilder.class);
    Response response = mock(Response.class);
    when((runtimeDelegate).createResponseBuilder()).thenReturn(responseBuilder);
    lenient().when((responseBuilder).status(any(StatusType.class))).thenReturn(responseBuilder);
    lenient().when((responseBuilder).entity(any())).thenReturn(responseBuilder);
    lenient().when((responseBuilder).build()).thenReturn(response);
    application = mock(Application.class);
    processes = mock(Processes.class);
    AbstractProcess process = mock(AbstractProcess.class);
    ProcessInstances instances = mock(ProcessInstances.class);
    processInstance = mock(ProcessInstance.class);
    error = mock(ProcessError.class);
    lenient().when(processes.processById(anyString())).thenReturn(process);
    lenient().when(process.instances()).thenReturn(instances);
    lenient().when(instances.findById(anyString())).thenReturn(Optional.of(processInstance));
    lenient().when(processInstance.error()).thenReturn(Optional.of(error));
    lenient().when(processInstance.id()).thenReturn("abc-def");
    lenient().when(processInstance.status()).thenReturn(KogitoProcessInstance.STATE_ACTIVE);
    lenient().when(error.failedNodeId()).thenReturn("xxxxx");
    lenient().when(error.errorMessage()).thenReturn("Test error message");
    lenient().when(process.get()).thenReturn(mock(KogitoWorkflowProcess.class));
    lenient().when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
    resource = spy(new ProcessInstanceManagementResource(processes, application));
}
Also used : AbstractProcess(org.kie.kogito.process.impl.AbstractProcess) Processes(org.kie.kogito.process.Processes) KogitoWorkflowProcess(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess) Response(javax.ws.rs.core.Response) ProcessInstances(org.kie.kogito.process.ProcessInstances) ProcessError(org.kie.kogito.process.ProcessError) StatusType(javax.ws.rs.core.Response.StatusType) CollectingUnitOfWorkFactory(org.kie.kogito.services.uow.CollectingUnitOfWorkFactory) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ProcessInstance(org.kie.kogito.process.ProcessInstance) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Application(org.kie.kogito.Application) DefaultUnitOfWorkManager(org.kie.kogito.services.uow.DefaultUnitOfWorkManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

AbstractProcess (org.kie.kogito.process.impl.AbstractProcess)3 Any (com.google.protobuf.Any)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 JsonFormat (com.google.protobuf.util.JsonFormat)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Response (javax.ws.rs.core.Response)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 StatusType (javax.ws.rs.core.Response.StatusType)1