From eb67b8eac9a10266014a89fd3234887008414f3c Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Tue, 17 Dec 2024 16:21:19 +0100 Subject: [PATCH 1/6] [Fix #2165] Adding custom mutations --- .../org/kie/kogito/index/CommonUtils.java | 25 ++++++ .../org/kie/kogito/index/api/ExecuteArgs.java | 61 ++++++++++++++ .../kogito/index/api/KogitoRuntimeClient.java | 3 + .../graphql/AbstractGraphQLSchemaManager.java | 21 +---- .../service/api/KogitoRuntimeClientImpl.java | 15 +++- .../graphql/GraphQLMutationsProvider.java | 30 +++++++ .../graphql/GraphQLSchemaManagerImpl.java | 6 ++ .../data-index-service-shared-output/pom.xml | 38 +++++++++ .../OutputGraphQLMutationProvider.java | 79 +++++++++++++++++++ ...x.service.graphql.GraphQLMutationsProvider | 19 +++++ data-index/data-index-service/pom.xml | 1 + .../api/KogitoAddonRuntimeClientImpl.java | 18 +++++ kogito-apps-bom/pom.xml | 5 ++ 13 files changed, 301 insertions(+), 20 deletions(-) create mode 100644 data-index/data-index-common/src/main/java/org/kie/kogito/index/api/ExecuteArgs.java create mode 100644 data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLMutationsProvider.java create mode 100644 data-index/data-index-service/data-index-service-shared-output/pom.xml create mode 100644 data-index/data-index-service/data-index-service-shared-output/src/main/java/org/kie/kogito/index/service/mutations/OutputGraphQLMutationProvider.java create mode 100644 data-index/data-index-service/data-index-service-shared-output/src/main/resources/META-INF/services/org.kie.kogito.index.service.graphql.GraphQLMutationsProvider diff --git a/data-index/data-index-common/src/main/java/org/kie/kogito/index/CommonUtils.java b/data-index/data-index-common/src/main/java/org/kie/kogito/index/CommonUtils.java index 3bc4b724db..047080e35a 100644 --- a/data-index/data-index-common/src/main/java/org/kie/kogito/index/CommonUtils.java +++ b/data-index/data-index-common/src/main/java/org/kie/kogito/index/CommonUtils.java @@ -20,13 +20,38 @@ import java.util.Set; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class CommonUtils { public static final int ERROR_STATE = 5; private static final Set finalStates = Set.of("Completed", "Aborted"); + private static final Logger logger = LoggerFactory.getLogger(CommonUtils.class); public static boolean isTaskCompleted(String status) { return finalStates.contains(status); } + public static String getServiceUrl(String endpoint, String processId) { + logger.debug("Process endpoint {}", endpoint); + if (endpoint == null) { + return null; + } + if (endpoint.startsWith("/")) { + logger.warn("Process '{}' endpoint '{}', does not contain full URL, please review the kogito.service.url system property to point the public URL for this runtime.", + processId, endpoint); + } + String context = getContext(processId); + logger.debug("Process context {}", context); + if (context.equals(endpoint) || endpoint.equals("/" + context)) { + return null; + } else { + return endpoint.contains("/" + context) ? endpoint.substring(0, endpoint.lastIndexOf("/" + context)) : null; + } + } + + private static String getContext(String processId) { + return processId != null && processId.contains(".") ? processId.substring(processId.lastIndexOf('.') + 1) : processId; + } } diff --git a/data-index/data-index-common/src/main/java/org/kie/kogito/index/api/ExecuteArgs.java b/data-index/data-index-common/src/main/java/org/kie/kogito/index/api/ExecuteArgs.java new file mode 100644 index 0000000000..6049104c2b --- /dev/null +++ b/data-index/data-index-common/src/main/java/org/kie/kogito/index/api/ExecuteArgs.java @@ -0,0 +1,61 @@ +/* + * 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.index.api; + +import com.fasterxml.jackson.databind.JsonNode; + +public record ExecuteArgs(JsonNode input, String businessKey, String referenceId) { + + public static ExecuteArgs of(JsonNode input) { + return new Builder().withInput(input).build(); + } + + public static Builder builder(JsonNode modelInput) { + return new Builder(); + } + + public static class Builder { + + private JsonNode input; + private String businessKey; + private String referenceId; + + private Builder() { + } + + public Builder withInput(JsonNode input) { + this.input = input; + return this; + } + + public Builder withBusinessKey(String businessKey) { + this.businessKey = businessKey; + return this; + } + + public Builder withReferenceId(String referenceId) { + this.referenceId = referenceId; + return this; + } + + public ExecuteArgs build() { + return new ExecuteArgs(input, businessKey, referenceId); + } + } +} diff --git a/data-index/data-index-common/src/main/java/org/kie/kogito/index/api/KogitoRuntimeClient.java b/data-index/data-index-common/src/main/java/org/kie/kogito/index/api/KogitoRuntimeClient.java index 50b94365ee..c6e42dd9d4 100644 --- a/data-index/data-index-common/src/main/java/org/kie/kogito/index/api/KogitoRuntimeClient.java +++ b/data-index/data-index-common/src/main/java/org/kie/kogito/index/api/KogitoRuntimeClient.java @@ -24,11 +24,14 @@ import org.kie.kogito.index.model.Job; import org.kie.kogito.index.model.Node; +import org.kie.kogito.index.model.ProcessDefinition; import org.kie.kogito.index.model.ProcessInstance; import org.kie.kogito.index.model.UserTaskInstance; public interface KogitoRuntimeClient { + CompletableFuture executeProcessIntance(ProcessDefinition definition, ExecuteArgs args); + CompletableFuture abortProcessInstance(String serviceURL, ProcessInstance processInstance); CompletableFuture retryProcessInstance(String serviceURL, ProcessInstance processInstance); diff --git a/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/AbstractGraphQLSchemaManager.java b/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/AbstractGraphQLSchemaManager.java index 6dd81262b1..960496d4da 100644 --- a/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/AbstractGraphQLSchemaManager.java +++ b/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/AbstractGraphQLSchemaManager.java @@ -28,6 +28,7 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; +import org.kie.kogito.index.CommonUtils; import org.kie.kogito.index.api.KogitoRuntimeClient; import org.kie.kogito.index.graphql.query.GraphQLQueryOrderByParser; import org.kie.kogito.index.graphql.query.GraphQLQueryParserRegistry; @@ -142,25 +143,7 @@ public ProcessDefinition getProcessDefinition(DataFetchingEnvironment env) { } protected String getServiceUrl(String endpoint, String processId) { - LOGGER.debug("Process endpoint {}", endpoint); - if (endpoint == null) { - return null; - } - if (endpoint.startsWith("/")) { - LOGGER.warn("Process '{}' endpoint '{}', does not contain full URL, please review the kogito.service.url system property to point the public URL for this runtime.", - processId, endpoint); - } - String context = getContext(processId); - LOGGER.debug("Process context {}", context); - if (context.equals(endpoint) || endpoint.equals("/" + context)) { - return null; - } else { - return endpoint.contains("/" + context) ? endpoint.substring(0, endpoint.lastIndexOf("/" + context)) : null; - } - } - - private String getContext(String processId) { - return processId != null && processId.contains(".") ? processId.substring(processId.lastIndexOf('.') + 1) : processId; + return CommonUtils.getServiceUrl(endpoint, processId); } protected Collection getChildProcessInstancesValues(DataFetchingEnvironment env) { diff --git a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/api/KogitoRuntimeClientImpl.java b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/api/KogitoRuntimeClientImpl.java index badbe77b24..500d7ad0d9 100644 --- a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/api/KogitoRuntimeClientImpl.java +++ b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/api/KogitoRuntimeClientImpl.java @@ -22,9 +22,12 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; +import org.kie.kogito.index.CommonUtils; +import org.kie.kogito.index.api.ExecuteArgs; import org.kie.kogito.index.api.KogitoRuntimeClient; import org.kie.kogito.index.api.KogitoRuntimeCommonClient; import org.kie.kogito.index.model.Node; +import org.kie.kogito.index.model.ProcessDefinition; import org.kie.kogito.index.model.ProcessInstance; import org.kie.kogito.index.model.UserTaskInstance; import org.kie.kogito.index.service.DataIndexServiceException; @@ -72,6 +75,17 @@ class KogitoRuntimeClientImpl extends KogitoRuntimeCommonClient implements Kogit private static final Logger LOGGER = LoggerFactory.getLogger(KogitoRuntimeClientImpl.class); + @Override + public CompletableFuture executeProcessIntance(ProcessDefinition definition, ExecuteArgs args) { + CompletableFuture future = new CompletableFuture<>(); + HttpRequest request = getWebClient(CommonUtils.getServiceUrl(definition.getEndpoint(), definition.getId())).post("/" + definition.getId()); + if (args.businessKey() != null) { + request.addQueryParam("businessKey", args.businessKey()); + } + request.sendJson(args.input(), res -> asyncHttpResponseTreatment(res, future, "START ProcessInstance of type " + definition.getId())); + return future; + } + @Override public CompletableFuture abortProcessInstance(String serviceURL, ProcessInstance processInstance) { String requestURI = format(ABORT_PROCESS_INSTANCE_PATH, processInstance.getProcessId(), processInstance.getId()); @@ -282,5 +296,4 @@ protected void send(String logMessage, Class type, CompletableFuture future, Asy future.completeExceptionally(new DataIndexServiceException(getErrorMessage(logMessage, res.result()), res.cause())); } } - } diff --git a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLMutationsProvider.java b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLMutationsProvider.java new file mode 100644 index 0000000000..cda1b2ce7f --- /dev/null +++ b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLMutationsProvider.java @@ -0,0 +1,30 @@ +/* + * 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.index.service.graphql; + +import java.util.Map; +import java.util.concurrent.CompletableFuture; + +import org.kie.kogito.index.graphql.AbstractGraphQLSchemaManager; + +import graphql.schema.DataFetcher; + +public interface GraphQLMutationsProvider { + Map>> mutations(AbstractGraphQLSchemaManager schemaManager); +} diff --git a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLSchemaManagerImpl.java b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLSchemaManagerImpl.java index 2acaf539ab..7d7de3de9b 100644 --- a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLSchemaManagerImpl.java +++ b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLSchemaManagerImpl.java @@ -21,8 +21,12 @@ import java.io.IOException; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Optional; +import java.util.ServiceLoader; +import java.util.ServiceLoader.Provider; import java.util.function.Supplier; +import java.util.stream.Collectors; import org.kie.kogito.index.graphql.AbstractGraphQLSchemaManager; import org.kie.kogito.index.graphql.query.GraphQLQueryParserRegistry; @@ -101,6 +105,8 @@ public GraphQLSchema createSchema() { builder.dataFetcher("UserTaskInstanceCommentDelete", this::deleteUserTaskComment); builder.dataFetcher("UserTaskInstanceAttachmentUpdate", this::updateUserTaskAttachment); builder.dataFetcher("UserTaskInstanceAttachmentDelete", this::deleteUserTaskAttachment); + ServiceLoader.load(GraphQLMutationsProvider.class).stream().map(Provider::get).map(m -> m.mutations(this)).flatMap(map -> map.entrySet().stream()) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v2)).forEach(builder::dataFetcher); return builder; }) .type("ProcessDefinition", builder -> { diff --git a/data-index/data-index-service/data-index-service-shared-output/pom.xml b/data-index/data-index-service/data-index-service-shared-output/pom.xml new file mode 100644 index 0000000000..a97483374a --- /dev/null +++ b/data-index/data-index-service/data-index-service-shared-output/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + org.kie.kogito + data-index-service + 999-SNAPSHOT + + data-index-service-shared-output + + + org.kie.kogito + data-index-service-common + + + + org.kie.kogito.index.service.mutations + + \ No newline at end of file diff --git a/data-index/data-index-service/data-index-service-shared-output/src/main/java/org/kie/kogito/index/service/mutations/OutputGraphQLMutationProvider.java b/data-index/data-index-service/data-index-service-shared-output/src/main/java/org/kie/kogito/index/service/mutations/OutputGraphQLMutationProvider.java new file mode 100644 index 0000000000..b865775cba --- /dev/null +++ b/data-index/data-index-service/data-index-service-shared-output/src/main/java/org/kie/kogito/index/service/mutations/OutputGraphQLMutationProvider.java @@ -0,0 +1,79 @@ +/* + * 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.index.service.mutations; + +import java.util.Map; +import java.util.concurrent.CompletableFuture; + +import org.kie.kogito.index.api.ExecuteArgs; +import org.kie.kogito.index.graphql.AbstractGraphQLSchemaManager; +import org.kie.kogito.index.model.ProcessDefinition; +import org.kie.kogito.index.model.ProcessDefinitionKey; +import org.kie.kogito.index.model.ProcessInstance; +import org.kie.kogito.index.service.graphql.GraphQLMutationsProvider; +import org.kie.kogito.index.storage.DataIndexStorageService; +import org.kie.kogito.jackson.utils.MergeUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.JsonNode; + +import graphql.schema.DataFetcher; +import graphql.schema.DataFetchingEnvironment; + +public class OutputGraphQLMutationProvider implements GraphQLMutationsProvider { + + private static Logger logger = LoggerFactory.getLogger(OutputGraphQLMutationProvider.class); + private static final String COMPLETED_INSTANCE_ID = "completedInstanceId"; + + @Override + public Map>> mutations(AbstractGraphQLSchemaManager schemaManager) { + return Map.of("sharedOutput", env -> sharedOutput(schemaManager, env)); + } + + private CompletableFuture sharedOutput(AbstractGraphQLSchemaManager schemaManager, DataFetchingEnvironment env) { + DataIndexStorageService cacheService = schemaManager.getCacheService(); + ProcessDefinitionKey key = new ProcessDefinitionKey(mandatoryArgument(env, "processId"), mandatoryArgument(env, "processVersion")); + ProcessDefinition processDefinition = cacheService.getProcessDefinitionStorage().get(key); + if (processDefinition == null) { + throw new IllegalArgumentException(key + "does not correspond to any existing process definition"); + } + JsonNode input = env.getArgument("input"); + String completedInstanceId = env.getArgument(COMPLETED_INSTANCE_ID); + if (completedInstanceId != null) { + ProcessInstance processInstance = cacheService.getProcessInstanceStorage().get(completedInstanceId); + if (processInstance != null) { + input = MergeUtils.merge(input, processInstance.getVariables()); + } else { + logger.warn("Completed Instance Id {} cannot be found, using user input as it is", completedInstanceId); + } + } else { + logger.warn("Missing " + COMPLETED_INSTANCE_ID + " parameter, using user input as it is"); + } + return schemaManager.getDataIndexApiExecutor().executeProcessIntance(processDefinition, ExecuteArgs.of(input)); + } + + private static T mandatoryArgument(DataFetchingEnvironment env, String name) { + T result = env.getArgument(name); + if (result == null) { + throw new IllegalArgumentException("Missing " + name + " mandatory parameter"); + } + return result; + } +} diff --git a/data-index/data-index-service/data-index-service-shared-output/src/main/resources/META-INF/services/org.kie.kogito.index.service.graphql.GraphQLMutationsProvider b/data-index/data-index-service/data-index-service-shared-output/src/main/resources/META-INF/services/org.kie.kogito.index.service.graphql.GraphQLMutationsProvider new file mode 100644 index 0000000000..a06562efb8 --- /dev/null +++ b/data-index/data-index-service/data-index-service-shared-output/src/main/resources/META-INF/services/org.kie.kogito.index.service.graphql.GraphQLMutationsProvider @@ -0,0 +1,19 @@ +# +# 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. +# +org.kie.kogito.index.service.mutations.OutputGraphQLMutationProvider \ No newline at end of file diff --git a/data-index/data-index-service/pom.xml b/data-index/data-index-service/pom.xml index cdc2c04d47..236e069267 100644 --- a/data-index/data-index-service/pom.xml +++ b/data-index/data-index-service/pom.xml @@ -37,6 +37,7 @@ data-index-service-postgresql data-index-service-infinispan data-index-service-mongodb + data-index-service-shared-output diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/main/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImpl.java b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/main/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImpl.java index 1f9b64d91d..22a394f18b 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/main/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImpl.java +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/main/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImpl.java @@ -29,13 +29,17 @@ import org.eclipse.microprofile.context.ManagedExecutor; import org.kie.kogito.Application; +import org.kie.kogito.Model; +import org.kie.kogito.index.api.ExecuteArgs; import org.kie.kogito.index.api.KogitoRuntimeClient; import org.kie.kogito.index.api.KogitoRuntimeCommonClient; import org.kie.kogito.index.model.Node; +import org.kie.kogito.index.model.ProcessDefinition; import org.kie.kogito.index.model.ProcessInstance; import org.kie.kogito.index.model.UserTaskInstance; import org.kie.kogito.index.service.DataIndexServiceException; import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess; +import org.kie.kogito.jackson.utils.JsonObjectUtils; import org.kie.kogito.process.Process; import org.kie.kogito.process.ProcessInstanceExecutionException; import org.kie.kogito.process.Processes; @@ -273,4 +277,18 @@ private String executeOnProcessInstance(String processId, String processInstance } }); } + + @Override + public CompletableFuture executeProcessIntance(ProcessDefinition definition, ExecuteArgs args) { + Process process = processes != null ? processes.processById(definition.getId()) : null; + if (process == null) { + throw new DataIndexServiceException(String.format("Unable to find Process with id %s to perform the operation requested", definition.getId())); + } + Model m = (Model) process.createModel(); + m.update(JsonObjectUtils.convertValue(args.input(), Map.class)); + org.kie.kogito.process.ProcessInstance pi = process.createInstance(m); + pi.start(); + return CompletableFuture.completedFuture( + String.format(SUCCESSFULLY_OPERATION_MESSAGE, "Started ProcessInstance with id: " + pi.id())); + } } diff --git a/kogito-apps-bom/pom.xml b/kogito-apps-bom/pom.xml index 774cd46967..37e90676fa 100644 --- a/kogito-apps-bom/pom.xml +++ b/kogito-apps-bom/pom.xml @@ -250,6 +250,11 @@ data-index-service ${project.version} + + org.kie.kogito + data-index-service-shared-output + ${project.version} + org.kie.kogito data-index-storage-api From e85f6882671a01d1084ab25211425874ba4e4385 Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Wed, 18 Dec 2024 16:33:52 +0100 Subject: [PATCH 2/6] [Fix #2165] Rearrange modules --- .../org/kie/kogito/index/api/ExecuteArgs.java | 4 +- .../graphql/AbstractGraphQLSchemaManager.java | 13 ++++-- .../graphql/GraphQLMutationsProvider.java | 4 +- .../pom.xml | 6 +-- .../OutputGraphQLMutationProvider.java | 6 +-- ...to.index.graphql.GraphQLMutationsProvider} | 3 +- data-index/data-index-mutations/pom.xml | 33 +++++++++++++++ .../data-index-service-common/pom.xml | 4 ++ .../graphql/GraphQLSchemaManagerImpl.java | 7 +--- .../AbstractGraphQLRuntimesQueriesIT.java | 42 +++++++++++++++++++ data-index/data-index-service/pom.xml | 1 - .../api/KogitoAddonRuntimeClientImpl.java | 2 +- .../GraphQLAddonSchemaManagerImpl.java | 1 + data-index/pom.xml | 1 + kogito-apps-bom/pom.xml | 2 +- 15 files changed, 104 insertions(+), 25 deletions(-) rename data-index/{data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service => data-index-graphql/src/main/java/org/kie/kogito/index}/graphql/GraphQLMutationsProvider.java (90%) rename data-index/{data-index-service/data-index-service-shared-output => data-index-mutations/data-index-shared-output-mutation}/pom.xml (89%) rename data-index/{data-index-service/data-index-service-shared-output/src/main/java/org/kie/kogito/index/service => data-index-mutations/data-index-shared-output-mutation/src/main/java/org/kie/kogito/index}/mutations/OutputGraphQLMutationProvider.java (95%) rename data-index/{data-index-service/data-index-service-shared-output/src/main/resources/META-INF/services/org.kie.kogito.index.service.graphql.GraphQLMutationsProvider => data-index-mutations/data-index-shared-output-mutation/src/main/resources/META-INF/services/org.kie.kogito.index.graphql.GraphQLMutationsProvider} (92%) create mode 100644 data-index/data-index-mutations/pom.xml diff --git a/data-index/data-index-common/src/main/java/org/kie/kogito/index/api/ExecuteArgs.java b/data-index/data-index-common/src/main/java/org/kie/kogito/index/api/ExecuteArgs.java index 6049104c2b..1e8c3a3656 100644 --- a/data-index/data-index-common/src/main/java/org/kie/kogito/index/api/ExecuteArgs.java +++ b/data-index/data-index-common/src/main/java/org/kie/kogito/index/api/ExecuteArgs.java @@ -23,10 +23,10 @@ public record ExecuteArgs(JsonNode input, String businessKey, String referenceId) { public static ExecuteArgs of(JsonNode input) { - return new Builder().withInput(input).build(); + return builder().withInput(input).build(); } - public static Builder builder(JsonNode modelInput) { + public static Builder builder() { return new Builder(); } diff --git a/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/AbstractGraphQLSchemaManager.java b/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/AbstractGraphQLSchemaManager.java index 960496d4da..f1cb5604d4 100644 --- a/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/AbstractGraphQLSchemaManager.java +++ b/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/AbstractGraphQLSchemaManager.java @@ -25,8 +25,11 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.ServiceLoader; +import java.util.ServiceLoader.Provider; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; +import java.util.stream.Collectors; import org.kie.kogito.index.CommonUtils; import org.kie.kogito.index.api.KogitoRuntimeClient; @@ -42,8 +45,6 @@ import org.kie.kogito.index.storage.DataIndexStorageService; import org.kie.kogito.persistence.api.StorageFetcher; import org.kie.kogito.persistence.api.query.Query; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import graphql.schema.DataFetchingEnvironment; import graphql.schema.GraphQLInputObjectType; @@ -52,6 +53,7 @@ import graphql.schema.GraphQLSchema; import graphql.schema.idl.SchemaParser; import graphql.schema.idl.TypeDefinitionRegistry; +import graphql.schema.idl.TypeRuntimeWiring.Builder; import jakarta.annotation.PostConstruct; import jakarta.inject.Inject; @@ -70,8 +72,6 @@ public abstract class AbstractGraphQLSchemaManager implements GraphQLSchemaManag private static final String UNABLE_TO_FIND_ERROR_MSG = "Unable to find the instance with %s %s"; - private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGraphQLSchemaManager.class); - @Inject DataIndexStorageService cacheService; @@ -93,6 +93,11 @@ public void setup() { (GraphQLInputObjectType) schema.getType("JobArgument")); } + protected final void loadAdditionalMutations(Builder builder) { + ServiceLoader.load(GraphQLMutationsProvider.class).stream().map(Provider::get).map(m -> m.mutations(this)).flatMap(map -> map.entrySet().stream()) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v2)).forEach(builder::dataFetcher); + } + protected TypeDefinitionRegistry loadSchemaDefinitionFile(String fileName) { SchemaParser schemaParser = new SchemaParser(); try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); diff --git a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLMutationsProvider.java b/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/GraphQLMutationsProvider.java similarity index 90% rename from data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLMutationsProvider.java rename to data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/GraphQLMutationsProvider.java index cda1b2ce7f..c4b30c186d 100644 --- a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLMutationsProvider.java +++ b/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/GraphQLMutationsProvider.java @@ -16,13 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.kogito.index.service.graphql; +package org.kie.kogito.index.graphql; import java.util.Map; import java.util.concurrent.CompletableFuture; -import org.kie.kogito.index.graphql.AbstractGraphQLSchemaManager; - import graphql.schema.DataFetcher; public interface GraphQLMutationsProvider { diff --git a/data-index/data-index-service/data-index-service-shared-output/pom.xml b/data-index/data-index-mutations/data-index-shared-output-mutation/pom.xml similarity index 89% rename from data-index/data-index-service/data-index-service-shared-output/pom.xml rename to data-index/data-index-mutations/data-index-shared-output-mutation/pom.xml index a97483374a..9f73334975 100644 --- a/data-index/data-index-service/data-index-service-shared-output/pom.xml +++ b/data-index/data-index-mutations/data-index-shared-output-mutation/pom.xml @@ -22,14 +22,14 @@ 4.0.0 org.kie.kogito - data-index-service + data-index-mutations 999-SNAPSHOT - data-index-service-shared-output + data-index-shared-output-mutation org.kie.kogito - data-index-service-common + data-index-graphql diff --git a/data-index/data-index-service/data-index-service-shared-output/src/main/java/org/kie/kogito/index/service/mutations/OutputGraphQLMutationProvider.java b/data-index/data-index-mutations/data-index-shared-output-mutation/src/main/java/org/kie/kogito/index/mutations/OutputGraphQLMutationProvider.java similarity index 95% rename from data-index/data-index-service/data-index-service-shared-output/src/main/java/org/kie/kogito/index/service/mutations/OutputGraphQLMutationProvider.java rename to data-index/data-index-mutations/data-index-shared-output-mutation/src/main/java/org/kie/kogito/index/mutations/OutputGraphQLMutationProvider.java index b865775cba..43289c96d5 100644 --- a/data-index/data-index-service/data-index-service-shared-output/src/main/java/org/kie/kogito/index/service/mutations/OutputGraphQLMutationProvider.java +++ b/data-index/data-index-mutations/data-index-shared-output-mutation/src/main/java/org/kie/kogito/index/mutations/OutputGraphQLMutationProvider.java @@ -16,17 +16,17 @@ * specific language governing permissions and limitations * under the License. */ -package org.kie.kogito.index.service.mutations; +package org.kie.kogito.index.mutations; import java.util.Map; import java.util.concurrent.CompletableFuture; import org.kie.kogito.index.api.ExecuteArgs; import org.kie.kogito.index.graphql.AbstractGraphQLSchemaManager; +import org.kie.kogito.index.graphql.GraphQLMutationsProvider; import org.kie.kogito.index.model.ProcessDefinition; import org.kie.kogito.index.model.ProcessDefinitionKey; import org.kie.kogito.index.model.ProcessInstance; -import org.kie.kogito.index.service.graphql.GraphQLMutationsProvider; import org.kie.kogito.index.storage.DataIndexStorageService; import org.kie.kogito.jackson.utils.MergeUtils; import org.slf4j.Logger; @@ -44,7 +44,7 @@ public class OutputGraphQLMutationProvider implements GraphQLMutationsProvider { @Override public Map>> mutations(AbstractGraphQLSchemaManager schemaManager) { - return Map.of("sharedOutput", env -> sharedOutput(schemaManager, env)); + return Map.of("ExecuteAfter", env -> sharedOutput(schemaManager, env)); } private CompletableFuture sharedOutput(AbstractGraphQLSchemaManager schemaManager, DataFetchingEnvironment env) { diff --git a/data-index/data-index-service/data-index-service-shared-output/src/main/resources/META-INF/services/org.kie.kogito.index.service.graphql.GraphQLMutationsProvider b/data-index/data-index-mutations/data-index-shared-output-mutation/src/main/resources/META-INF/services/org.kie.kogito.index.graphql.GraphQLMutationsProvider similarity index 92% rename from data-index/data-index-service/data-index-service-shared-output/src/main/resources/META-INF/services/org.kie.kogito.index.service.graphql.GraphQLMutationsProvider rename to data-index/data-index-mutations/data-index-shared-output-mutation/src/main/resources/META-INF/services/org.kie.kogito.index.graphql.GraphQLMutationsProvider index a06562efb8..7800b9085c 100644 --- a/data-index/data-index-service/data-index-service-shared-output/src/main/resources/META-INF/services/org.kie.kogito.index.service.graphql.GraphQLMutationsProvider +++ b/data-index/data-index-mutations/data-index-shared-output-mutation/src/main/resources/META-INF/services/org.kie.kogito.index.graphql.GraphQLMutationsProvider @@ -16,4 +16,5 @@ # specific language governing permissions and limitations # under the License. # -org.kie.kogito.index.service.mutations.OutputGraphQLMutationProvider \ No newline at end of file + +org.kie.kogito.index.mutations.OutputGraphQLMutationProvider \ No newline at end of file diff --git a/data-index/data-index-mutations/pom.xml b/data-index/data-index-mutations/pom.xml new file mode 100644 index 0000000000..4e7eed80c1 --- /dev/null +++ b/data-index/data-index-mutations/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + org.kie.kogito + data-index + 999-SNAPSHOT + + data-index-mutations + pom + + data-index-shared-output-mutation + + \ No newline at end of file diff --git a/data-index/data-index-service/data-index-service-common/pom.xml b/data-index/data-index-service/data-index-service-common/pom.xml index 4abb945f17..7b8d09c534 100644 --- a/data-index/data-index-service/data-index-service-common/pom.xml +++ b/data-index/data-index-service/data-index-service-common/pom.xml @@ -91,6 +91,10 @@ io.quarkus quarkus-rest-client-reactive-jackson + + org.kie.kogito + data-index-shared-output-mutation + io.quarkus quarkus-smallrye-graphql-client diff --git a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLSchemaManagerImpl.java b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLSchemaManagerImpl.java index 7d7de3de9b..3320ede2e6 100644 --- a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLSchemaManagerImpl.java +++ b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLSchemaManagerImpl.java @@ -21,12 +21,8 @@ import java.io.IOException; import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.Optional; -import java.util.ServiceLoader; -import java.util.ServiceLoader.Provider; import java.util.function.Supplier; -import java.util.stream.Collectors; import org.kie.kogito.index.graphql.AbstractGraphQLSchemaManager; import org.kie.kogito.index.graphql.query.GraphQLQueryParserRegistry; @@ -105,8 +101,7 @@ public GraphQLSchema createSchema() { builder.dataFetcher("UserTaskInstanceCommentDelete", this::deleteUserTaskComment); builder.dataFetcher("UserTaskInstanceAttachmentUpdate", this::updateUserTaskAttachment); builder.dataFetcher("UserTaskInstanceAttachmentDelete", this::deleteUserTaskAttachment); - ServiceLoader.load(GraphQLMutationsProvider.class).stream().map(Provider::get).map(m -> m.mutations(this)).flatMap(map -> map.entrySet().stream()) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v2)).forEach(builder::dataFetcher); + loadAdditionalMutations(builder); return builder; }) .type("ProcessDefinition", builder -> { diff --git a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/query/AbstractGraphQLRuntimesQueriesIT.java b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/query/AbstractGraphQLRuntimesQueriesIT.java index 04df4542e4..eed2b8cd8a 100644 --- a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/query/AbstractGraphQLRuntimesQueriesIT.java +++ b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/query/AbstractGraphQLRuntimesQueriesIT.java @@ -27,17 +27,24 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.kie.kogito.event.process.ProcessDefinitionDataEvent; import org.kie.kogito.event.process.ProcessInstanceStateDataEvent; +import org.kie.kogito.event.process.ProcessInstanceVariableDataEvent; +import org.kie.kogito.event.process.ProcessInstanceVariableEventBody; import org.kie.kogito.event.usertask.UserTaskInstanceAttachmentDataEvent; import org.kie.kogito.event.usertask.UserTaskInstanceAttachmentEventBody; import org.kie.kogito.event.usertask.UserTaskInstanceCommentDataEvent; import org.kie.kogito.event.usertask.UserTaskInstanceCommentEventBody; import org.kie.kogito.event.usertask.UserTaskInstanceStateDataEvent; +import org.kie.kogito.index.api.ExecuteArgs; import org.kie.kogito.index.api.KogitoRuntimeClient; import org.kie.kogito.index.event.KogitoJobCloudEvent; +import org.kie.kogito.index.model.ProcessDefinition; import org.kie.kogito.index.model.UserTaskInstance; import org.kie.kogito.index.service.AbstractIndexingIT; import org.kie.kogito.index.service.graphql.GraphQLSchemaManagerImpl; +import org.kie.kogito.index.test.TestUtils; +import org.kie.kogito.jackson.utils.ObjectMapperFactory; import org.kie.kogito.persistence.protobuf.ProtobufService; import org.mockito.ArgumentCaptor; import org.mockito.junit.jupiter.MockitoExtension; @@ -96,6 +103,41 @@ void testProcessInstanceAbort() { eq(getProcessInstance(processId, processInstanceId, 1, null, null))); } + @Test + void testProcessExecuteInstance() { + String assesmentInstanceId = UUID.randomUUID().toString(); + ProcessInstanceStateDataEvent assesmentEvent = getProcessCloudEvent(processId, assesmentInstanceId, ACTIVE, null, null, null, "currentUser"); + indexProcessCloudEvent(assesmentEvent); + final String assesmentVarName = "assesmentVar"; + final String assesmentVarValue = "assesmentValue"; + final String infraVarName = "clientVar"; + final String infraVarValue = "clientValue"; + ProcessInstanceVariableDataEvent variableEvent = new ProcessInstanceVariableDataEvent(); + variableEvent.setKogitoProcessId(processId); + variableEvent.setKogitoProcessInstanceId(assesmentInstanceId); + variableEvent.setData(ProcessInstanceVariableEventBody.create().processId(processId).processInstanceId(assesmentInstanceId) + .variableName(assesmentVarName).variableValue(assesmentVarValue).build()); + indexProcessCloudEvent(variableEvent); + final String infraProcessId = "infra"; + ProcessDefinitionDataEvent definitionEvent = TestUtils.getProcessDefinitionDataEvent(infraProcessId); + indexProcessCloudEvent(definitionEvent); + checkOkResponse("{ \"query\" : \"mutation{ ExecuteAfter ( " + fragment("completedProcessId", assesmentInstanceId) + "," + fragment("processId", infraProcessId) + + "," + fragment("processVersion", TestUtils.PROCESS_VERSION) + "," + "input: {" + fragment(assesmentVarName, assesmentVarValue) + "})}\"}"); + verify(dataIndexApiClient).executeProcessIntance(getProcessDefinition(infraProcessId), ExecuteArgs.of(ObjectMapperFactory.get().createObjectNode().put(assesmentVarName, assesmentVarValue) + .put(infraVarName,infraVarValue))); + } + + private String fragment(String name, String value) { + return name + ": \\\"" + value + "\\\""; + } + + private ProcessDefinition getProcessDefinition(String processId) { + ProcessDefinition def = new ProcessDefinition(); + def.setId(processId); + def.setVersion(TestUtils.PROCESS_VERSION); + return def; + } + @Test void testProcessInstanceRetry() { String processInstanceId = UUID.randomUUID().toString(); diff --git a/data-index/data-index-service/pom.xml b/data-index/data-index-service/pom.xml index 236e069267..cdc2c04d47 100644 --- a/data-index/data-index-service/pom.xml +++ b/data-index/data-index-service/pom.xml @@ -37,7 +37,6 @@ data-index-service-postgresql data-index-service-infinispan data-index-service-mongodb - data-index-service-shared-output diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/main/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImpl.java b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/main/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImpl.java index 22a394f18b..f681f39d18 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/main/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImpl.java +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/main/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImpl.java @@ -289,6 +289,6 @@ public CompletableFuture executeProcessIntance(ProcessDefinition definit org.kie.kogito.process.ProcessInstance pi = process.createInstance(m); pi.start(); return CompletableFuture.completedFuture( - String.format(SUCCESSFULLY_OPERATION_MESSAGE, "Started ProcessInstance with id: " + pi.id())); + String.format(SUCCESSFULLY_OPERATION_MESSAGE, "Started Process Instance with id: " + pi.id())); } } diff --git a/data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/runtime/src/main/java/org/kie/kogito/index/addon/graphql/GraphQLAddonSchemaManagerImpl.java b/data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/runtime/src/main/java/org/kie/kogito/index/addon/graphql/GraphQLAddonSchemaManagerImpl.java index d9c853bbd8..4f44a1b5ec 100644 --- a/data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/runtime/src/main/java/org/kie/kogito/index/addon/graphql/GraphQLAddonSchemaManagerImpl.java +++ b/data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/runtime/src/main/java/org/kie/kogito/index/addon/graphql/GraphQLAddonSchemaManagerImpl.java @@ -53,6 +53,7 @@ public GraphQLSchema createSchema() { builder.dataFetcher("NodeInstanceCancel", this::cancelNodeInstance); builder.dataFetcher("JobCancel", this::cancelJob); builder.dataFetcher("JobReschedule", this::rescheduleJob); + loadAdditionalMutations(builder); return builder; }) .type("ProcessDefinition", builder -> { diff --git a/data-index/pom.xml b/data-index/pom.xml index 4b2801bbd9..0de3d898b3 100644 --- a/data-index/pom.xml +++ b/data-index/pom.xml @@ -42,6 +42,7 @@ data-index-service kogito-addons-quarkus-data-index-persistence kogito-addons-quarkus-data-index + data-index-mutations diff --git a/kogito-apps-bom/pom.xml b/kogito-apps-bom/pom.xml index 37e90676fa..e28ce31371 100644 --- a/kogito-apps-bom/pom.xml +++ b/kogito-apps-bom/pom.xml @@ -252,7 +252,7 @@ org.kie.kogito - data-index-service-shared-output + data-index-shared-output-mutation ${project.version} From 8c13cca3d4ae5ee2467481deaf63a73df3393c3c Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Fri, 20 Dec 2024 00:52:34 +0100 Subject: [PATCH 3/6] [Fix #2165] Adding IT test --- .../org/kie/kogito/index/CommonUtils.java | 16 ++++++++++++++ .../graphql/AbstractGraphQLSchemaManager.java | 21 ++++++++----------- .../graphql/GraphQLMutationsProvider.java | 3 +++ .../OutputGraphQLMutationProvider.java | 10 ++++++++- .../main/resources/mutation.schema.graphqls | 3 +++ .../graphql/GraphQLSchemaManagerImpl.java | 1 + .../AbstractGraphQLRuntimesQueriesIT.java | 6 +++--- .../GraphQLAddonSchemaManagerImpl.java | 1 + 8 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 data-index/data-index-mutations/data-index-shared-output-mutation/src/main/resources/mutation.schema.graphqls diff --git a/data-index/data-index-common/src/main/java/org/kie/kogito/index/CommonUtils.java b/data-index/data-index-common/src/main/java/org/kie/kogito/index/CommonUtils.java index 047080e35a..47e70d8f7b 100644 --- a/data-index/data-index-common/src/main/java/org/kie/kogito/index/CommonUtils.java +++ b/data-index/data-index-common/src/main/java/org/kie/kogito/index/CommonUtils.java @@ -18,11 +18,17 @@ */ package org.kie.kogito.index; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import graphql.schema.idl.SchemaParser; +import graphql.schema.idl.TypeDefinitionRegistry; + public class CommonUtils { public static final int ERROR_STATE = 5; @@ -51,6 +57,16 @@ public static String getServiceUrl(String endpoint, String processId) { } } + public static TypeDefinitionRegistry loadSchemaDefinitionFile(String fileName) { + SchemaParser schemaParser = new SchemaParser(); + try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); + InputStreamReader reader = new InputStreamReader(stream)) { + return schemaParser.parse(reader); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + private static String getContext(String processId) { return processId != null && processId.contains(".") ? processId.substring(processId.lastIndexOf('.') + 1) : processId; } diff --git a/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/AbstractGraphQLSchemaManager.java b/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/AbstractGraphQLSchemaManager.java index f1cb5604d4..2b86012b77 100644 --- a/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/AbstractGraphQLSchemaManager.java +++ b/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/AbstractGraphQLSchemaManager.java @@ -18,9 +18,6 @@ */ package org.kie.kogito.index.graphql; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.util.Collection; import java.util.List; import java.util.Map; @@ -51,7 +48,6 @@ import graphql.schema.GraphQLNamedType; import graphql.schema.GraphQLScalarType; import graphql.schema.GraphQLSchema; -import graphql.schema.idl.SchemaParser; import graphql.schema.idl.TypeDefinitionRegistry; import graphql.schema.idl.TypeRuntimeWiring.Builder; import jakarta.annotation.PostConstruct; @@ -83,8 +79,11 @@ public abstract class AbstractGraphQLSchemaManager implements GraphQLSchemaManag private GraphQLSchema schema; + private Collection mutations; + @PostConstruct public void setup() { + mutations = ServiceLoader.load(GraphQLMutationsProvider.class).stream().map(Provider::get).collect(Collectors.toList()); schema = createSchema(); GraphQLQueryParserRegistry.get().registerParsers( (GraphQLInputObjectType) schema.getType("ProcessDefinitionArgument"), @@ -94,18 +93,16 @@ public void setup() { } protected final void loadAdditionalMutations(Builder builder) { - ServiceLoader.load(GraphQLMutationsProvider.class).stream().map(Provider::get).map(m -> m.mutations(this)).flatMap(map -> map.entrySet().stream()) + mutations.stream().map(m -> m.mutations(this)).flatMap(map -> map.entrySet().stream()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v2)).forEach(builder::dataFetcher); } + protected final void loadAdditionalMutations(TypeDefinitionRegistry typeRegistry) { + mutations.stream().map(GraphQLMutationsProvider::registry).forEach(typeRegistry::merge); + } + protected TypeDefinitionRegistry loadSchemaDefinitionFile(String fileName) { - SchemaParser schemaParser = new SchemaParser(); - try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); - InputStreamReader reader = new InputStreamReader(stream)) { - return schemaParser.parse(reader); - } catch (IOException e) { - throw new RuntimeException(e); - } + return CommonUtils.loadSchemaDefinitionFile(fileName); } public abstract GraphQLSchema createSchema(); diff --git a/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/GraphQLMutationsProvider.java b/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/GraphQLMutationsProvider.java index c4b30c186d..6457ee47f4 100644 --- a/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/GraphQLMutationsProvider.java +++ b/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/GraphQLMutationsProvider.java @@ -22,7 +22,10 @@ import java.util.concurrent.CompletableFuture; import graphql.schema.DataFetcher; +import graphql.schema.idl.TypeDefinitionRegistry; public interface GraphQLMutationsProvider { Map>> mutations(AbstractGraphQLSchemaManager schemaManager); + + TypeDefinitionRegistry registry(); } diff --git a/data-index/data-index-mutations/data-index-shared-output-mutation/src/main/java/org/kie/kogito/index/mutations/OutputGraphQLMutationProvider.java b/data-index/data-index-mutations/data-index-shared-output-mutation/src/main/java/org/kie/kogito/index/mutations/OutputGraphQLMutationProvider.java index 43289c96d5..6532ae43a4 100644 --- a/data-index/data-index-mutations/data-index-shared-output-mutation/src/main/java/org/kie/kogito/index/mutations/OutputGraphQLMutationProvider.java +++ b/data-index/data-index-mutations/data-index-shared-output-mutation/src/main/java/org/kie/kogito/index/mutations/OutputGraphQLMutationProvider.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; +import org.kie.kogito.index.CommonUtils; import org.kie.kogito.index.api.ExecuteArgs; import org.kie.kogito.index.graphql.AbstractGraphQLSchemaManager; import org.kie.kogito.index.graphql.GraphQLMutationsProvider; @@ -28,6 +29,7 @@ import org.kie.kogito.index.model.ProcessDefinitionKey; import org.kie.kogito.index.model.ProcessInstance; import org.kie.kogito.index.storage.DataIndexStorageService; +import org.kie.kogito.jackson.utils.JsonObjectUtils; import org.kie.kogito.jackson.utils.MergeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,6 +38,7 @@ import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; +import graphql.schema.idl.TypeDefinitionRegistry; public class OutputGraphQLMutationProvider implements GraphQLMutationsProvider { @@ -54,7 +57,7 @@ private CompletableFuture sharedOutput(AbstractGraphQLSchemaManager sche if (processDefinition == null) { throw new IllegalArgumentException(key + "does not correspond to any existing process definition"); } - JsonNode input = env.getArgument("input"); + JsonNode input = JsonObjectUtils.fromValue(env.getArgument("input")); String completedInstanceId = env.getArgument(COMPLETED_INSTANCE_ID); if (completedInstanceId != null) { ProcessInstance processInstance = cacheService.getProcessInstanceStorage().get(completedInstanceId); @@ -76,4 +79,9 @@ private static T mandatoryArgument(DataFetchingEnvironment env, String name) } return result; } + + @Override + public TypeDefinitionRegistry registry() { + return CommonUtils.loadSchemaDefinitionFile("mutation.schema.graphqls"); + } } diff --git a/data-index/data-index-mutations/data-index-shared-output-mutation/src/main/resources/mutation.schema.graphqls b/data-index/data-index-mutations/data-index-shared-output-mutation/src/main/resources/mutation.schema.graphqls new file mode 100644 index 0000000000..120b44dc52 --- /dev/null +++ b/data-index/data-index-mutations/data-index-shared-output-mutation/src/main/resources/mutation.schema.graphqls @@ -0,0 +1,3 @@ +extend type Mutation { + ExecuteAfter(completedInstanceId: String, processId: String, processVersion: String, input: JSON): String +} diff --git a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLSchemaManagerImpl.java b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLSchemaManagerImpl.java index 3320ede2e6..cadff87c60 100644 --- a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLSchemaManagerImpl.java +++ b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/graphql/GraphQLSchemaManagerImpl.java @@ -74,6 +74,7 @@ public GraphQLSchema createSchema() { TypeDefinitionRegistry typeDefinitionRegistry = new TypeDefinitionRegistry(); typeDefinitionRegistry.merge(loadSchemaDefinitionFile("basic.schema.graphqls")); typeDefinitionRegistry.merge(loadSchemaDefinitionFile("domain.schema.graphqls")); + loadAdditionalMutations(typeDefinitionRegistry); RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring() .scalar(ExtendedScalars.Json) diff --git a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/query/AbstractGraphQLRuntimesQueriesIT.java b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/query/AbstractGraphQLRuntimesQueriesIT.java index eed2b8cd8a..ef87828453 100644 --- a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/query/AbstractGraphQLRuntimesQueriesIT.java +++ b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/query/AbstractGraphQLRuntimesQueriesIT.java @@ -121,10 +121,10 @@ void testProcessExecuteInstance() { final String infraProcessId = "infra"; ProcessDefinitionDataEvent definitionEvent = TestUtils.getProcessDefinitionDataEvent(infraProcessId); indexProcessCloudEvent(definitionEvent); - checkOkResponse("{ \"query\" : \"mutation{ ExecuteAfter ( " + fragment("completedProcessId", assesmentInstanceId) + "," + fragment("processId", infraProcessId) + - "," + fragment("processVersion", TestUtils.PROCESS_VERSION) + "," + "input: {" + fragment(assesmentVarName, assesmentVarValue) + "})}\"}"); + checkOkResponse("{ \"query\" : \"mutation{ ExecuteAfter ( " + fragment("completedInstanceId", assesmentInstanceId) + "," + fragment("processId", infraProcessId) + + "," + fragment("processVersion", TestUtils.PROCESS_VERSION) + "," + "input: {" + fragment(infraVarName, infraVarValue) + "})}\"}"); verify(dataIndexApiClient).executeProcessIntance(getProcessDefinition(infraProcessId), ExecuteArgs.of(ObjectMapperFactory.get().createObjectNode().put(assesmentVarName, assesmentVarValue) - .put(infraVarName,infraVarValue))); + .put(infraVarName, infraVarValue))); } private String fragment(String name, String value) { diff --git a/data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/runtime/src/main/java/org/kie/kogito/index/addon/graphql/GraphQLAddonSchemaManagerImpl.java b/data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/runtime/src/main/java/org/kie/kogito/index/addon/graphql/GraphQLAddonSchemaManagerImpl.java index 4f44a1b5ec..ca8a07eb32 100644 --- a/data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/runtime/src/main/java/org/kie/kogito/index/addon/graphql/GraphQLAddonSchemaManagerImpl.java +++ b/data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/runtime/src/main/java/org/kie/kogito/index/addon/graphql/GraphQLAddonSchemaManagerImpl.java @@ -34,6 +34,7 @@ public class GraphQLAddonSchemaManagerImpl extends AbstractGraphQLSchemaManager public GraphQLSchema createSchema() { TypeDefinitionRegistry typeDefinitionRegistry = new TypeDefinitionRegistry(); typeDefinitionRegistry.merge(loadSchemaDefinitionFile("basic.schema.graphqls")); + loadAdditionalMutations(typeDefinitionRegistry); RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring() .type("Query", builder -> { From 09705448cecb178cf6cd55ed0ec4954cc6b8008c Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Fri, 20 Dec 2024 12:24:28 +0100 Subject: [PATCH 4/6] [Fix #2165] Adding license check exclusion --- .rat-excludes | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.rat-excludes b/.rat-excludes index 6473bd705a..7ed9b60ce9 100644 --- a/.rat-excludes +++ b/.rat-excludes @@ -42,6 +42,8 @@ application.properties basic.schema.graphqls # data-index/data-index-service/data-index-service-common/src/main/resources/domain.schema.graphqls domain.schema.graphqls +# /data-index/data-index-mutations/data-index-shared-output-mutation/src/main/resources/mutation.schema.graphqls +mutation.schema.graphqls # data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-infinispan/integration-tests-process/src/main/resources/hello.bpmn hello.bpmn # data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-infinispan/integration-tests-process/src/main/resources/META-INF/processSVG/hello.svg @@ -97,4 +99,4 @@ application.properties # jobs-service/kogito-addons-jobs-service/kogito-addons-quarkus-jobs-service-embedded/runtime/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource org.eclipse.microprofile.config.spi.ConfigSource # trusty/trusty-service/trusty-service-common/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker -org.mockito.plugins.MockMaker \ No newline at end of file +org.mockito.plugins.MockMaker From 9af8228854daddb6e4c46ea7185b832736bfbdab Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Fri, 20 Dec 2024 13:57:16 +0100 Subject: [PATCH 5/6] [Fix #2165] Walters comments --- .../index/graphql/AbstractGraphQLSchemaManager.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/AbstractGraphQLSchemaManager.java b/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/AbstractGraphQLSchemaManager.java index 2b86012b77..142f2c02a4 100644 --- a/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/AbstractGraphQLSchemaManager.java +++ b/data-index/data-index-graphql/src/main/java/org/kie/kogito/index/graphql/AbstractGraphQLSchemaManager.java @@ -42,7 +42,10 @@ import org.kie.kogito.index.storage.DataIndexStorageService; import org.kie.kogito.persistence.api.StorageFetcher; import org.kie.kogito.persistence.api.query.Query; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; import graphql.schema.GraphQLInputObjectType; import graphql.schema.GraphQLNamedType; @@ -68,6 +71,8 @@ public abstract class AbstractGraphQLSchemaManager implements GraphQLSchemaManag private static final String UNABLE_TO_FIND_ERROR_MSG = "Unable to find the instance with %s %s"; + private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGraphQLSchemaManager.class); + @Inject DataIndexStorageService cacheService; @@ -84,6 +89,7 @@ public abstract class AbstractGraphQLSchemaManager implements GraphQLSchemaManag @PostConstruct public void setup() { mutations = ServiceLoader.load(GraphQLMutationsProvider.class).stream().map(Provider::get).collect(Collectors.toList()); + schema = createSchema(); GraphQLQueryParserRegistry.get().registerParsers( (GraphQLInputObjectType) schema.getType("ProcessDefinitionArgument"), @@ -93,8 +99,10 @@ public void setup() { } protected final void loadAdditionalMutations(Builder builder) { - mutations.stream().map(m -> m.mutations(this)).flatMap(map -> map.entrySet().stream()) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v2)).forEach(builder::dataFetcher); + Map>> mutationMap = mutations.stream().map(m -> m.mutations(this)).flatMap(map -> map.entrySet().stream()) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v2)); + LOGGER.info("Custom mutations are {}", mutationMap); + mutationMap.forEach(builder::dataFetcher); } protected final void loadAdditionalMutations(TypeDefinitionRegistry typeRegistry) { From 106f98f65816cbfd153b4e7712743fd747bd8536 Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Fri, 20 Dec 2024 15:17:22 +0100 Subject: [PATCH 6/6] [Fix #2165] Adding unit test for executeAfter post call --- .../service/api/KogitoRuntimeClientTest.java | 19 ++++++++++++++++ .../AbstractGraphQLRuntimesQueriesIT.java | 13 +++-------- .../org/kie/kogito/index/test/TestUtils.java | 8 +++++++ .../api/KogitoAddonRuntimeClientImplTest.java | 22 +++++++++++++++++++ 4 files changed, 52 insertions(+), 10 deletions(-) diff --git a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/api/KogitoRuntimeClientTest.java b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/api/KogitoRuntimeClientTest.java index 28acb2caf3..9d61de4fe6 100644 --- a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/api/KogitoRuntimeClientTest.java +++ b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/api/KogitoRuntimeClientTest.java @@ -29,17 +29,22 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.kie.kogito.index.api.ExecuteArgs; import org.kie.kogito.index.api.KogitoRuntimeCommonClient; import org.kie.kogito.index.model.Job; +import org.kie.kogito.index.model.ProcessDefinition; import org.kie.kogito.index.model.ProcessInstance; import org.kie.kogito.index.model.UserTaskInstance; import org.kie.kogito.index.service.DataIndexServiceException; import org.kie.kogito.index.test.TestUtils; +import org.kie.kogito.jackson.utils.ObjectMapperFactory; import org.kie.kogito.usertask.model.CommentInfo; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import com.fasterxml.jackson.databind.JsonNode; + import io.quarkus.security.credential.TokenCredential; import io.quarkus.security.identity.SecurityIdentity; import io.vertx.core.AsyncResult; @@ -117,6 +122,20 @@ public void setup() { client.setIdentity(identityMock); } + @Test + public void textExecuteAfter() { + when(webClientMock.post(anyString())).thenReturn(httpRequestMock); + final String processId = "infra"; + ProcessDefinition definition = TestUtils.getProcessDefinition(processId); + definition.setEndpoint(SERVICE_URL + "/" + processId); + JsonNode body = ObjectMapperFactory.get().createObjectNode().put("name", "javierito"); + client.executeProcessIntance(definition, ExecuteArgs.of(body)); + verify(webClientMock).post("/" + processId); + ArgumentCaptor jsonCaptor = ArgumentCaptor.forClass(Object.class); + verify(httpRequestMock).sendJson(jsonCaptor.capture(), any()); + assertThat(jsonCaptor.getValue()).isEqualTo(body); + } + @Test public void testAbortProcessInstance() { setupIdentityMock(); diff --git a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/query/AbstractGraphQLRuntimesQueriesIT.java b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/query/AbstractGraphQLRuntimesQueriesIT.java index ef87828453..6f9915a1eb 100644 --- a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/query/AbstractGraphQLRuntimesQueriesIT.java +++ b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/query/AbstractGraphQLRuntimesQueriesIT.java @@ -39,7 +39,6 @@ import org.kie.kogito.index.api.ExecuteArgs; import org.kie.kogito.index.api.KogitoRuntimeClient; import org.kie.kogito.index.event.KogitoJobCloudEvent; -import org.kie.kogito.index.model.ProcessDefinition; import org.kie.kogito.index.model.UserTaskInstance; import org.kie.kogito.index.service.AbstractIndexingIT; import org.kie.kogito.index.service.graphql.GraphQLSchemaManagerImpl; @@ -123,21 +122,15 @@ void testProcessExecuteInstance() { indexProcessCloudEvent(definitionEvent); checkOkResponse("{ \"query\" : \"mutation{ ExecuteAfter ( " + fragment("completedInstanceId", assesmentInstanceId) + "," + fragment("processId", infraProcessId) + "," + fragment("processVersion", TestUtils.PROCESS_VERSION) + "," + "input: {" + fragment(infraVarName, infraVarValue) + "})}\"}"); - verify(dataIndexApiClient).executeProcessIntance(getProcessDefinition(infraProcessId), ExecuteArgs.of(ObjectMapperFactory.get().createObjectNode().put(assesmentVarName, assesmentVarValue) - .put(infraVarName, infraVarValue))); + verify(dataIndexApiClient).executeProcessIntance(TestUtils.getProcessDefinition(infraProcessId), + ExecuteArgs.of(ObjectMapperFactory.get().createObjectNode().put(assesmentVarName, assesmentVarValue) + .put(infraVarName, infraVarValue))); } private String fragment(String name, String value) { return name + ": \\\"" + value + "\\\""; } - private ProcessDefinition getProcessDefinition(String processId) { - ProcessDefinition def = new ProcessDefinition(); - def.setId(processId); - def.setVersion(TestUtils.PROCESS_VERSION); - return def; - } - @Test void testProcessInstanceRetry() { String processInstanceId = UUID.randomUUID().toString(); diff --git a/data-index/data-index-test-utils/src/main/java/org/kie/kogito/index/test/TestUtils.java b/data-index/data-index-test-utils/src/main/java/org/kie/kogito/index/test/TestUtils.java index 600d52824e..ad42f25eee 100644 --- a/data-index/data-index-test-utils/src/main/java/org/kie/kogito/index/test/TestUtils.java +++ b/data-index/data-index-test-utils/src/main/java/org/kie/kogito/index/test/TestUtils.java @@ -59,6 +59,7 @@ import org.kie.kogito.index.model.Milestone; import org.kie.kogito.index.model.MilestoneStatus; import org.kie.kogito.index.model.NodeInstance; +import org.kie.kogito.index.model.ProcessDefinition; import org.kie.kogito.index.model.ProcessInstance; import org.kie.kogito.index.model.ProcessInstanceError; import org.kie.kogito.index.model.ProcessInstanceState; @@ -121,6 +122,13 @@ public static ProcessDefinitionDataEvent getProcessDefinitionDataEvent(String pr return new ProcessDefinitionDataEvent(body); } + public static ProcessDefinition getProcessDefinition(String processId) { + ProcessDefinition def = new ProcessDefinition(); + def.setId(processId); + def.setVersion(TestUtils.PROCESS_VERSION); + return def; + } + public static ProcessInstanceStateDataEvent getProcessCloudEvent(String processId, String processInstanceId, ProcessInstanceState status, String rootProcessInstanceId, String rootProcessId, String parentProcessInstanceId, String identity) { diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/test/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImplTest.java b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/test/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImplTest.java index 6392cd4941..7830460a87 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/test/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImplTest.java +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/test/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImplTest.java @@ -19,16 +19,21 @@ package org.kie.kogito.index.addon.api; import java.nio.Buffer; +import java.util.Map; import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.kie.kogito.Application; +import org.kie.kogito.Model; +import org.kie.kogito.index.api.ExecuteArgs; import org.kie.kogito.index.api.KogitoRuntimeCommonClient; import org.kie.kogito.index.model.Job; +import org.kie.kogito.index.model.ProcessDefinition; import org.kie.kogito.index.model.ProcessInstance; import org.kie.kogito.index.test.TestUtils; +import org.kie.kogito.jackson.utils.ObjectMapperFactory; import org.kie.kogito.process.ProcessError; import org.kie.kogito.process.ProcessInstanceExecutionException; import org.kie.kogito.process.ProcessInstances; @@ -42,6 +47,8 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import com.fasterxml.jackson.databind.JsonNode; + import io.quarkus.security.credential.TokenCredential; import io.quarkus.security.identity.SecurityIdentity; import io.vertx.core.AsyncResult; @@ -123,6 +130,9 @@ public class KogitoAddonRuntimeClientImplTest { @Mock Instance applicationInstance; + @Mock + Model model; + @Mock private Application application; @@ -133,6 +143,8 @@ public void setup() { lenient().when(processesInstance.isResolvable()).thenReturn(true); lenient().when(processesInstance.get()).thenReturn(processes); lenient().when(processes.processById(anyString())).thenReturn(process); + lenient().when(process.createModel()).thenReturn(model); + lenient().when(process.createInstance(model)).thenReturn(processInstance); lenient().when(process.instances()).thenReturn(instances); lenient().when(instances.findById(anyString())).thenReturn(Optional.of(processInstance)); lenient().when(processInstance.error()).thenReturn(Optional.of(error)); @@ -173,6 +185,16 @@ private ProcessError mockProcessInstanceStatusActiveOnError() { }).when(error); } + @Test + void testExecuteAfterSuccess() { + ProcessDefinition definition = new ProcessDefinition(); + definition.setId("infra"); + JsonNode body = ObjectMapperFactory.get().createObjectNode().put("name", "javierito"); + client.executeProcessIntance(definition, ExecuteArgs.of(body)); + verify(model).update(Map.of("name", "javierito")); + verify(processInstance).start(); + } + @Test void testAbortProcessInstanceSuccess() { ProcessInstance pI = createProcessInstance(PROCESS_INSTANCE_ID, ACTIVE);