From 7074552c1e0c5c75da26029d495228b0fc95bc10 Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Mon, 30 Dec 2024 12:25:27 +0100 Subject: [PATCH] [Fix #2171] Adding excludeProperties arg to ExecuteAfter mutation --- .../kogito/index/api/KogitoRuntimeClient.java | 2 +- .../OutputGraphQLMutationProvider.java | 5 +++-- .../main/resources/mutation.schema.graphqls | 2 +- .../service/api/KogitoRuntimeClientImpl.java | 2 +- .../service/api/KogitoRuntimeClientTest.java | 2 +- .../AbstractGraphQLRuntimesQueriesIT.java | 22 +++++++++++++------ .../api/KogitoAddonRuntimeClientImpl.java | 2 +- .../api/KogitoAddonRuntimeClientImplTest.java | 2 +- 8 files changed, 24 insertions(+), 15 deletions(-) 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 c6e42dd9d4..57641bb884 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 @@ -30,7 +30,7 @@ public interface KogitoRuntimeClient { - CompletableFuture executeProcessIntance(ProcessDefinition definition, ExecuteArgs args); + CompletableFuture executeProcessInstance(ProcessDefinition definition, ExecuteArgs args); CompletableFuture abortProcessInstance(String serviceURL, ProcessInstance processInstance); 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 6532ae43a4..4930d65857 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 @@ -19,6 +19,7 @@ package org.kie.kogito.index.mutations; import java.util.Map; +import java.util.Set; import java.util.concurrent.CompletableFuture; import org.kie.kogito.index.CommonUtils; @@ -62,14 +63,14 @@ private CompletableFuture sharedOutput(AbstractGraphQLSchemaManager sche if (completedInstanceId != null) { ProcessInstance processInstance = cacheService.getProcessInstanceStorage().get(completedInstanceId); if (processInstance != null) { - input = MergeUtils.merge(input, processInstance.getVariables()); + input = MergeUtils.merge(input, processInstance.getVariables().remove(env.getArgumentOrDefault("excludeProperties", Set.of("workflowdatainput")))); } 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)); + return schemaManager.getDataIndexApiExecutor().executeProcessInstance(processDefinition, ExecuteArgs.of(input)); } private static T mandatoryArgument(DataFetchingEnvironment env, String name) { 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 index 120b44dc52..a434086dca 100644 --- 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 @@ -1,3 +1,3 @@ extend type Mutation { - ExecuteAfter(completedInstanceId: String, processId: String, processVersion: String, input: JSON): String + ExecuteAfter(completedInstanceId: String, processId: String!, processVersion: String!, input: JSON, excludeProperties: [String]): String } 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 500d7ad0d9..a3e5c303a5 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 @@ -76,7 +76,7 @@ class KogitoRuntimeClientImpl extends KogitoRuntimeCommonClient implements Kogit private static final Logger LOGGER = LoggerFactory.getLogger(KogitoRuntimeClientImpl.class); @Override - public CompletableFuture executeProcessIntance(ProcessDefinition definition, ExecuteArgs args) { + public CompletableFuture executeProcessInstance(ProcessDefinition definition, ExecuteArgs args) { CompletableFuture future = new CompletableFuture<>(); HttpRequest request = getWebClient(CommonUtils.getServiceUrl(definition.getEndpoint(), definition.getId())).post("/" + definition.getId()); if (args.businessKey() != null) { 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 9d61de4fe6..88ae694305 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 @@ -129,7 +129,7 @@ public void textExecuteAfter() { ProcessDefinition definition = TestUtils.getProcessDefinition(processId); definition.setEndpoint(SERVICE_URL + "/" + processId); JsonNode body = ObjectMapperFactory.get().createObjectNode().put("name", "javierito"); - client.executeProcessIntance(definition, ExecuteArgs.of(body)); + client.executeProcessInstance(definition, ExecuteArgs.of(body)); verify(webClientMock).post("/" + processId); ArgumentCaptor jsonCaptor = ArgumentCaptor.forClass(Object.class); verify(httpRequestMock).sendJson(jsonCaptor.capture(), any()); 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 6f9915a1eb..bfc1a4041d 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 @@ -111,22 +111,30 @@ void testProcessExecuteInstance() { 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 excludedKey = "notUsedKey"; + final String excludedValue = "irrelevant"; + indexProcessCloudEvent(buildVariableEvent(assesmentInstanceId, assesmentVarName, assesmentVarValue)); + indexProcessCloudEvent(buildVariableEvent(assesmentInstanceId, excludedKey, excludedValue)); final String infraProcessId = "infra"; ProcessDefinitionDataEvent definitionEvent = TestUtils.getProcessDefinitionDataEvent(infraProcessId); indexProcessCloudEvent(definitionEvent); checkOkResponse("{ \"query\" : \"mutation{ ExecuteAfter ( " + fragment("completedInstanceId", assesmentInstanceId) + "," + fragment("processId", infraProcessId) + + ",excludeProperties: [\\\"" + excludedKey + "\\\"]" + "," + fragment("processVersion", TestUtils.PROCESS_VERSION) + "," + "input: {" + fragment(infraVarName, infraVarValue) + "})}\"}"); - verify(dataIndexApiClient).executeProcessIntance(TestUtils.getProcessDefinition(infraProcessId), + verify(dataIndexApiClient).executeProcessInstance(TestUtils.getProcessDefinition(infraProcessId), ExecuteArgs.of(ObjectMapperFactory.get().createObjectNode().put(assesmentVarName, assesmentVarValue) .put(infraVarName, infraVarValue))); } + private ProcessInstanceVariableDataEvent buildVariableEvent(String processInstanceId, String key, String name) { + ProcessInstanceVariableDataEvent variableEvent = new ProcessInstanceVariableDataEvent(); + variableEvent.setKogitoProcessId(processId); + variableEvent.setKogitoProcessInstanceId(processInstanceId); + variableEvent.setData(ProcessInstanceVariableEventBody.create().processId(processId).processInstanceId(processInstanceId) + .variableName(key).variableValue(name).build()); + return variableEvent; + } + private String fragment(String name, String value) { return name + ": \\\"" + value + "\\\""; } 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 f681f39d18..d3bb8df3ff 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 @@ -279,7 +279,7 @@ private String executeOnProcessInstance(String processId, String processInstance } @Override - public CompletableFuture executeProcessIntance(ProcessDefinition definition, ExecuteArgs args) { + public CompletableFuture executeProcessInstance(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())); 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 7830460a87..910a673071 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 @@ -190,7 +190,7 @@ void testExecuteAfterSuccess() { ProcessDefinition definition = new ProcessDefinition(); definition.setId("infra"); JsonNode body = ObjectMapperFactory.get().createObjectNode().put("name", "javierito"); - client.executeProcessIntance(definition, ExecuteArgs.of(body)); + client.executeProcessInstance(definition, ExecuteArgs.of(body)); verify(model).update(Map.of("name", "javierito")); verify(processInstance).start(); }