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;
}
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");
}
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));
}
Aggregations