Skip to content

Commit

Permalink
[Fix #2171] Adding excludeProperties arg to ExecuteAfter mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Dec 30, 2024
1 parent c599ccf commit 7074552
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public interface KogitoRuntimeClient {

CompletableFuture<String> executeProcessIntance(ProcessDefinition definition, ExecuteArgs args);
CompletableFuture<String> executeProcessInstance(ProcessDefinition definition, ExecuteArgs args);

CompletableFuture<String> abortProcessInstance(String serviceURL, ProcessInstance processInstance);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,14 +63,14 @@ private CompletableFuture<String> 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> T mandatoryArgument(DataFetchingEnvironment env, String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class KogitoRuntimeClientImpl extends KogitoRuntimeCommonClient implements Kogit
private static final Logger LOGGER = LoggerFactory.getLogger(KogitoRuntimeClientImpl.class);

@Override
public CompletableFuture<String> executeProcessIntance(ProcessDefinition definition, ExecuteArgs args) {
public CompletableFuture<String> executeProcessInstance(ProcessDefinition definition, ExecuteArgs args) {
CompletableFuture<String> future = new CompletableFuture<>();
HttpRequest<Buffer> request = getWebClient(CommonUtils.getServiceUrl(definition.getEndpoint(), definition.getId())).post("/" + definition.getId());
if (args.businessKey() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> jsonCaptor = ArgumentCaptor.forClass(Object.class);
verify(httpRequestMock).sendJson(jsonCaptor.capture(), any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "\\\"";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private String executeOnProcessInstance(String processId, String processInstance
}

@Override
public CompletableFuture<String> executeProcessIntance(ProcessDefinition definition, ExecuteArgs args) {
public CompletableFuture<String> 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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 7074552

Please sign in to comment.