Skip to content

Commit

Permalink
[Fix apache#2165] Rearrange modules
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Dec 19, 2024
1 parent eb67b8e commit e85f688
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.kie.kogito</groupId>
<artifactId>data-index-service</artifactId>
<artifactId>data-index-mutations</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<artifactId>data-index-service-shared-output</artifactId>
<artifactId>data-index-shared-output-mutation</artifactId>
<dependencies>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>data-index-service-common</artifactId>
<artifactId>data-index-graphql</artifactId>
</dependency>
</dependencies>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,7 +44,7 @@ public class OutputGraphQLMutationProvider implements GraphQLMutationsProvider {

@Override
public Map<String, DataFetcher<CompletableFuture<?>>> mutations(AbstractGraphQLSchemaManager schemaManager) {
return Map.of("sharedOutput", env -> sharedOutput(schemaManager, env));
return Map.of("ExecuteAfter", env -> sharedOutput(schemaManager, env));
}

private CompletableFuture<String> sharedOutput(AbstractGraphQLSchemaManager schemaManager, DataFetchingEnvironment env) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
# specific language governing permissions and limitations
# under the License.
#
org.kie.kogito.index.service.mutations.OutputGraphQLMutationProvider

org.kie.kogito.index.mutations.OutputGraphQLMutationProvider
33 changes: 33 additions & 0 deletions data-index/data-index-mutations/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.kie.kogito</groupId>
<artifactId>data-index</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<artifactId>data-index-mutations</artifactId>
<packaging>pom</packaging>
<modules>
<module>data-index-shared-output-mutation</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>data-index-shared-output-mutation</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-graphql-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion data-index/data-index-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<module>data-index-service-postgresql</module>
<module>data-index-service-infinispan</module>
<module>data-index-service-mongodb</module>
<module>data-index-service-shared-output</module>
</modules>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,6 @@ public CompletableFuture<String> executeProcessIntance(ProcessDefinition definit
org.kie.kogito.process.ProcessInstance<? extends Model> 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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down
1 change: 1 addition & 0 deletions data-index/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<module>data-index-service</module>
<module>kogito-addons-quarkus-data-index-persistence</module>
<module>kogito-addons-quarkus-data-index</module>
<module>data-index-mutations</module>
</modules>

</project>
2 changes: 1 addition & 1 deletion kogito-apps-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>data-index-service-shared-output</artifactId>
<artifactId>data-index-shared-output-mutation</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down

0 comments on commit e85f688

Please sign in to comment.