Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package org.kie.kogito.process.dynamic;

import java.util.Collection;
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;
Expand All @@ -41,8 +41,8 @@ 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));
public static void executeRestCall(RestWorkItemHandler handler, Collection<Process<?>> processes, String processId, String processInstanceId, RestCallInfo input) {
Process<?> processDef = processes.stream().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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,29 @@
*/
package org.kie.kogito.process.expr;

import java.util.Collection;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.stream.Collectors;

public class ExpressionHandlerFactory {

private ExpressionHandlerFactory() {
}

private static final ServiceLoader<ExpressionHandler> serviceLoader = ServiceLoader.load(ExpressionHandler.class);
private static final Collection<ExpressionHandler> expressionHandlers = ServiceLoader.load(ExpressionHandler.class).stream()
.map(ServiceLoader.Provider::get).collect(Collectors.toUnmodifiableList());

public static Expression get(String lang, String expr) {
return getExpressionHandler(lang).orElseThrow(
() -> new IllegalArgumentException("Unsupported language " + lang)).get(expr);
}

public static boolean isSupported(String lang) {
return serviceLoader.stream().anyMatch(p -> p.get().lang().equals(lang));
return expressionHandlers.stream().map(ExpressionHandler::lang).anyMatch(lang::equals);
}

private static Optional<ExpressionHandler> getExpressionHandler(String lang) {
return serviceLoader.stream().filter(p -> p.get().lang().equals(lang)).findFirst().map(p -> p.get());
return expressionHandlers.stream().filter(p -> p.lang().equals(lang)).findFirst();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/
package org.kie.kogito.process.dynamic;

import java.util.Collection;
import java.util.stream.Collectors;

import org.kie.kogito.process.Process;
import org.kogito.workitem.rest.RestWorkItemHandler;

Expand All @@ -39,13 +42,17 @@
@Path("/_dynamic")
public class ProcessInstanceDynamicCallsResource {

@Inject
Instance<Process<?>> processes;
@Inject
Vertx vertx;
@Inject
WebClientOptions sslOptions;
private RestWorkItemHandler handler;
private Collection<Process<?>> processes;

@Inject
ProcessInstanceDynamicCallsResource(Instance<Process<?>> processes) {
this.processes = processes.stream().collect(Collectors.toUnmodifiableList());
}

@PostConstruct
void init() {
Expand All @@ -57,8 +64,7 @@ void init() {
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{processId}/{processInstanceId}/rest")
public Response executeRestCall(@PathParam("processId") String processId, @PathParam("processInstanceId") String processInstanceId, RestCallInfo input) {
ProcessInstanceDynamicCallHelper.executeRestCall(handler, processes.stream(), processId, processInstanceId, input);
ProcessInstanceDynamicCallHelper.executeRestCall(handler, processes, processId, processInstanceId, input);
return Response.status(200).build();
}

}
Loading