forked from apache/incubator-kie-kogito-runtimes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix apache#3615] Moving common stuff to common addons
- Loading branch information
Showing
12 changed files
with
143 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.kie</groupId> | ||
<artifactId>kogito-addons-common-parent</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>kie-addons-process-dynamic</artifactId> | ||
<name>KIE Add-On Process Instance Dynamic Calls</name> | ||
<description>Allow performing dynamic calls for existing process instances</description> | ||
<properties> | ||
<java.module.name>org.kie.process.dynamic</java.module.name> | ||
</properties> | ||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.kie.kogito</groupId> | ||
<artifactId>kogito-rest-workitem</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
File renamed without changes.
83 changes: 83 additions & 0 deletions
83
...ynamic/src/main/java/org/kie/kogito/process/dynamic/ProcessInstanceDynamicCallHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.kie.kogito.process.dynamic; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
import org.drools.core.common.InternalKnowledgeRuntime; | ||
import org.jbpm.process.instance.InternalProcessRuntime; | ||
import org.jbpm.process.instance.KogitoProcessContextImpl; | ||
import org.jbpm.process.instance.ProcessInstance; | ||
import org.jbpm.util.ContextFactory; | ||
import org.jbpm.workflow.core.impl.WorkflowProcessImpl; | ||
import org.jbpm.workflow.instance.WorkflowProcessInstance; | ||
import org.jbpm.workflow.instance.node.DynamicUtils; | ||
import org.kie.kogito.Model; | ||
import org.kie.kogito.process.Process; | ||
import org.kie.kogito.process.expr.ExpressionHandlerFactory; | ||
import org.kie.kogito.process.impl.AbstractProcessInstance; | ||
import org.kogito.workitem.rest.RestWorkItemHandler; | ||
|
||
public class ProcessInstanceDynamicCallHelper { | ||
|
||
private ProcessInstanceDynamicCallHelper() { | ||
} | ||
|
||
public static void executeRestCall(RestWorkItemHandler handler, Stream<Process<?>> processes, String processId, String processInstanceId, RestCallInfo input) { | ||
Process<?> processDef = processes.filter(p -> p.id().equals(processId)).findAny().orElseThrow(() -> new IllegalArgumentException("Cannot find process " + processId)); | ||
WorkflowProcessInstance pi = (WorkflowProcessInstance) findProcessInstance(processDef, processInstanceId); | ||
WorkflowProcessImpl process = (WorkflowProcessImpl) pi.getProcess(); | ||
if (!process.isDynamic()) { | ||
process.setDynamic(true); | ||
} | ||
InternalKnowledgeRuntime runtime = pi.getKnowledgeRuntime(); | ||
InternalProcessRuntime.asKogitoProcessRuntime(runtime).getKogitoWorkItemManager().registerWorkItemHandler(RestWorkItemHandler.REST_TASK_TYPE, handler); | ||
Map<String, Object> parameters = input.getArguments() == null ? new HashMap<>() : new HashMap<>(input.getArguments()); | ||
if (input.getHost() != null) { | ||
parameters.put(RestWorkItemHandler.HOST, input.getHost()); | ||
} | ||
if (input.getPort() != null) { | ||
parameters.put(RestWorkItemHandler.PORT, input.getPort()); | ||
} | ||
if (input.getMethod() != null) { | ||
parameters.put(RestWorkItemHandler.METHOD, input.getMethod()); | ||
} | ||
if (input.getEndpoint() != null) { | ||
parameters.put(RestWorkItemHandler.URL, input.getEndpoint()); | ||
} | ||
parameters.put(RestWorkItemHandler.PATH_PARAM_RESOLVER, new DynamicPathParamResolver(processInstanceId)); | ||
WorkItemHandlerResultHolder holder = new WorkItemHandlerResultHolder(); | ||
parameters.put(RestWorkItemHandler.RESULT_HANDLER, holder); | ||
KogitoProcessContextImpl context = ContextFactory.fromItem(DynamicUtils.addDynamicWorkItem(pi, runtime, RestWorkItemHandler.REST_TASK_TYPE, parameters)); | ||
Model model = ((Model) processDef.createModel()); | ||
model.update(input.getOutputExpression() != null | ||
? ExpressionHandlerFactory.get(input.getOutputExpressionLang(), input.getOutputExpression()).eval(holder.getResult(), Map.class, context) | ||
: holder.getResult()); | ||
((AbstractProcessInstance) pi.unwrap()).updateVariablesPartially(model); | ||
} | ||
|
||
private static ProcessInstance findProcessInstance(Process<?> process, String processInstanceId) { | ||
return process.instances() | ||
.findById(processInstanceId).map(AbstractProcessInstance.class::cast) | ||
.map(AbstractProcessInstance::internalGetProcessInstance) | ||
.orElseThrow(() -> new IllegalArgumentException("Cannot find process instance " + processInstanceId + " for process " + process.id())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters