From e3a87ad8289788a7d8d9e5feec0b070b733e258b Mon Sep 17 00:00:00 2001 From: Cristiano Nicolai <570894+cristianonicolai@users.noreply.github.com> Date: Mon, 4 Sep 2023 17:54:29 +1000 Subject: [PATCH] KOGITO-9662 - Automatically register process definitions using Data Index addon --- .../event/ProcessInstanceEventMapper.java | 5 +- .../kogito/index/service/IndexingService.java | 4 +- .../graphql/AbstractGraphQLSchemaManager.java | 25 +- .../src/main/resources/basic.schema.graphqls | 2 + .../graphql/GraphQLSchemaManagerImpl.java | 1 + .../src/main/resources/domain.schema.graphqls | 1 + .../service/AbstractIndexingServiceIT.java | 6 +- .../kogito/index/service/GraphQLUtils.java | 8 +- .../kogito/index/model/ProcessDefinition.java | 16 +- .../index/model/ProcessInstanceMeta.java | 11 + .../ProcessDefinitionMarshaller.java | 5 + .../ProcessInstanceMarshaller.java | 3 + .../model/ProcessDefinitionEntity.java | 10 + .../model/ProcessDefinitionEntityMapper.java | 2 + .../mongodb/model/ProcessInstanceEntity.java | 10 + .../model/ProcessInstanceEntityMapper.java | 4 +- .../mapper/ProcessDefinitionEntityMapper.java | 7 + .../oracle/model/ProcessDefinitionEntity.java | 11 + .../oracle/model/ProcessInstanceEntity.java | 10 + .../migration/V1.33.0__data_index_create.sql | 382 +++++++++--------- ...ql => V1.44.0__data_index_definitions.sql} | 6 +- .../mapper/ProcessInstanceEntityMapperIT.java | 3 + .../mapper/ProcessDefinitionEntityMapper.java | 8 + .../model/ProcessDefinitionEntity.java | 11 + .../model/ProcessInstanceEntity.java | 10 + ...ql => V1.44.0__data_index_definitions.sql} | 4 + .../resources/META-INF/kogito-index.proto | 5 + data-index/data-index-test-utils/pom.xml | 4 - .../org/kie/kogito/index/test/TestUtils.java | 10 +- .../deployment/pom.xml | 4 + .../runtime/pom.xml | 12 + .../addon/ProcessDefinitionRegister.java | 78 ++++ .../api/KogitoAddonRuntimeClientImpl.java | 0 .../src/main/resources/application.properties | 1 + ...panQuarkusAddonDataIndexPersistenceIT.java | 15 + .../integration-tests-sw/pom.xml | 5 + .../src/main/resources/application.properties | 1 + ...panQuarkusAddonDataIndexPersistenceIT.java | 21 + .../src/main/resources/application.properties | 1 + ...ngoQuarkusAddonDataIndexPersistenceIT.java | 15 + .../integration-tests-sw/pom.xml | 5 + .../src/main/resources/application.properties | 1 + ...ngoQuarkusAddonDataIndexPersistenceIT.java | 21 + .../src/main/resources/application.properties | 2 + ...SQLQuarkusAddonDataIndexPersistenceIT.java | 15 + .../integration-tests-sw/pom.xml | 5 + .../src/main/resources/application.properties | 2 + ...SQLQuarkusAddonDataIndexPersistenceIT.java | 21 + .../deployment/pom.xml | 4 - .../runtime/pom.xml | 12 - .../GraphQLAddonSchemaManagerImpl.java | 1 + 51 files changed, 605 insertions(+), 221 deletions(-) rename data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/{V1.43.0__data_index_definitions.sql => V1.44.0__data_index_definitions.sql} (90%) rename data-index/data-index-storage/data-index-storage-postgresql/src/main/resources/db/migration/{V1.43.0__data_index_definitions.sql => V1.44.0__data_index_definitions.sql} (91%) create mode 100644 data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/main/java/org/kie/kogito/index/addon/ProcessDefinitionRegister.java rename data-index/{kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common => 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 (100%) diff --git a/data-index/data-index-common/src/main/java/org/kie/kogito/index/event/ProcessInstanceEventMapper.java b/data-index/data-index-common/src/main/java/org/kie/kogito/index/event/ProcessInstanceEventMapper.java index 45bc13f684..747bf0a3ff 100644 --- a/data-index/data-index-common/src/main/java/org/kie/kogito/index/event/ProcessInstanceEventMapper.java +++ b/data-index/data-index-common/src/main/java/org/kie/kogito/index/event/ProcessInstanceEventMapper.java @@ -62,11 +62,12 @@ public ProcessInstance apply(ProcessInstanceDataEvent event) { pi.setAddons(isNullOrEmpty(event.getKogitoAddons()) ? null : Set.of(event.getKogitoAddons().split(","))); pi.setEndpoint(event.getSource() == null ? null : event.getSource().toString()); pi.setLastUpdate(toZonedDateTime(event.getTime())); - pi.setDefinition(definitions().apply(event)); + pi.setVersion(event.getData().getVersion()); + pi.setDefinition(definition().apply(event)); return pi; } - private Function definitions() { + private Function definition() { return event -> { ProcessDefinition pd = new ProcessDefinition(); pd.setId(event.getData().getProcessId()); diff --git a/data-index/data-index-common/src/main/java/org/kie/kogito/index/service/IndexingService.java b/data-index/data-index-common/src/main/java/org/kie/kogito/index/service/IndexingService.java index a696309be9..ce929cfa90 100644 --- a/data-index/data-index-common/src/main/java/org/kie/kogito/index/service/IndexingService.java +++ b/data-index/data-index-common/src/main/java/org/kie/kogito/index/service/IndexingService.java @@ -58,7 +58,9 @@ public void indexProcessInstance(ProcessInstance pi) { pi.getNodes().addAll(nodes); } ProcessDefinition definition = pi.getDefinition(); - manager.getProcessDefinitionsCache().put(definition.getKey(), definition); + if (!manager.getProcessDefinitionsCache().containsKey(definition.getKey())) { + manager.getProcessDefinitionsCache().put(definition.getKey(), definition); + } manager.getProcessInstancesCache().put(pi.getId(), pi); } 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 6d50e6b2e2..91b951b027 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 @@ -122,6 +122,11 @@ public String getProcessInstanceServiceUrl(DataFetchingEnvironment env) { return getServiceUrl(source.getEndpoint(), source.getProcessId()); } + public ProcessDefinition getProcessDefinition(DataFetchingEnvironment env) { + ProcessInstance source = env.getSource(); + return cacheService.getProcessDefinitionsCache().get(ProcessDefinition.toKey(source.getProcessId(), source.getVersion())); + } + protected String getServiceUrl(String endpoint, String processId) { LOGGER.debug("Process endpoint {}", endpoint); if (endpoint.startsWith("/")) { @@ -210,7 +215,12 @@ public CompletableFuture getProcessInstanceDiagram(DataFetchingEnvironme public CompletableFuture getProcessInstanceSourceFileContent(DataFetchingEnvironment env) { ProcessInstance pi = env.getSource(); - return dataIndexApiExecutor.getProcessDefinitionSourceFileContent(getServiceUrl(pi.getEndpoint(), pi.getProcessId()), pi.getProcessId()); + ProcessDefinition pd = cacheService.getProcessDefinitionsCache().get(ProcessDefinition.toKey(pi.getProcessId(), pi.getVersion())); + if (pd == null) { + return dataIndexApiExecutor.getProcessDefinitionSourceFileContent(getServiceUrl(pi.getEndpoint(), pi.getProcessId()), pi.getProcessId()); + } else { + return getProcessDefinitionSource(pd); + } } public CompletableFuture> getProcessInstanceNodes(DataFetchingEnvironment env) { @@ -219,8 +229,17 @@ public CompletableFuture> getProcessInstanceNodes(DataFetchingEnviron } public CompletableFuture getProcessDefinitionSourceFileContent(DataFetchingEnvironment env) { - ProcessDefinition pd = env.getSource(); - return dataIndexApiExecutor.getProcessDefinitionSourceFileContent(getServiceUrl(pd.getEndpoint(), pd.getId()), pd.getId()); + return getProcessDefinitionSource(env.getSource()); + } + + private CompletableFuture getProcessDefinitionSource(ProcessDefinition pd) { + if (pd == null) { + return CompletableFuture.completedFuture(null); + } else if (pd.getSource() == null) { + return dataIndexApiExecutor.getProcessDefinitionSourceFileContent(getServiceUrl(pd.getEndpoint(), pd.getId()), pd.getId()); + } else { + return CompletableFuture.completedFuture(new String(pd.getSource())); + } } public CompletableFuture> getProcessDefinitionNodes(DataFetchingEnvironment env) { diff --git a/data-index/data-index-graphql/src/main/resources/basic.schema.graphqls b/data-index/data-index-graphql/src/main/resources/basic.schema.graphqls index 6d741242e9..e4e18cd01e 100644 --- a/data-index/data-index-graphql/src/main/resources/basic.schema.graphqls +++ b/data-index/data-index-graphql/src/main/resources/basic.schema.graphqls @@ -45,6 +45,7 @@ input ProcessDefinitionArgument { type ProcessInstance { id: String! processId: String! + version: String processName: String parentProcessInstanceId: String rootProcessInstanceId: String @@ -67,6 +68,7 @@ type ProcessInstance { nodeDefinitions: [Node!] diagram: String source: String + definition: ProcessDefinition } type ProcessInstanceError { 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 61bd69f6b5..6163159947 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 @@ -125,6 +125,7 @@ public GraphQLSchema createSchema() { builder.dataFetcher("diagram", this::getProcessInstanceDiagram); builder.dataFetcher("source", this::getProcessInstanceSourceFileContent); builder.dataFetcher("nodeDefinitions", this::getProcessInstanceNodes); + builder.dataFetcher("definition", this::getProcessDefinition); return builder; }) .type("UserTaskInstance", builder -> { diff --git a/data-index/data-index-service/data-index-service-common/src/main/resources/domain.schema.graphqls b/data-index/data-index-service/data-index-service-common/src/main/resources/domain.schema.graphqls index e50c8dc121..c3b0a28620 100644 --- a/data-index/data-index-service/data-index-service-common/src/main/resources/domain.schema.graphqls +++ b/data-index/data-index-service/data-index-service-common/src/main/resources/domain.schema.graphqls @@ -43,6 +43,7 @@ input KogitoMetadataArgument { type ProcessInstanceMeta { id: String! processId: String! + version: String processName: String parentProcessInstanceId: String rootProcessInstanceId: String diff --git a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/AbstractIndexingServiceIT.java b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/AbstractIndexingServiceIT.java index 5e2aaf58b2..67b9621f23 100644 --- a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/AbstractIndexingServiceIT.java +++ b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/AbstractIndexingServiceIT.java @@ -155,6 +155,7 @@ protected void validateProcessInstance(String query, ProcessInstanceDataEvent ev .body("data.ProcessInstances[0].id", is(event.getData().getId())) .body("data.ProcessInstances[0].processId", is(event.getData().getProcessId())) .body("data.ProcessInstances[0].processName", is(event.getData().getProcessName())) + .body("data.ProcessInstances[0].version", is(event.getData().getVersion())) .body("data.ProcessInstances[0].rootProcessId", is(event.getData().getRootProcessId())) .body("data.ProcessInstances[0].rootProcessInstanceId", is(event.getData().getRootInstanceId())) .body("data.ProcessInstances[0].parentProcessInstanceId", is(event.getData().getParentInstanceId())) @@ -183,7 +184,10 @@ protected void validateProcessInstance(String query, ProcessInstanceDataEvent ev .body("data.ProcessInstances[0].milestones.size()", is(event.getData().getMilestones().size())) .body("data.ProcessInstances[0].milestones[0].id", is(event.getData().getMilestones().stream().findFirst().get().getId())) .body("data.ProcessInstances[0].milestones[0].name", is(event.getData().getMilestones().stream().findFirst().get().getName())) - .body("data.ProcessInstances[0].milestones[0].status", is(event.getData().getMilestones().stream().findFirst().get().getStatus()))); + .body("data.ProcessInstances[0].milestones[0].status", is(event.getData().getMilestones().stream().findFirst().get().getStatus())) + .body("data.ProcessInstances[0].definition.id", is(event.getData().getProcessId())) + .body("data.ProcessInstances[0].definition.version", is(event.getData().getVersion())) + .body("data.ProcessInstances[0].definition.name", is(event.getData().getProcessName()))); } protected void validateProcessInstance(String query, ProcessInstanceDataEvent event) { diff --git a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/GraphQLUtils.java b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/GraphQLUtils.java index 99c322de0a..5c12758580 100644 --- a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/GraphQLUtils.java +++ b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/GraphQLUtils.java @@ -55,7 +55,7 @@ public class GraphQLUtils { static { QUERY_FIELDS.put(ProcessDefinition.class, getAllFieldsList(ProcessDefinition.class).map(getFieldName()).collect(joining(", "))); QUERY_FIELDS.put(UserTaskInstance.class, getAllFieldsList(UserTaskInstance.class).map(getFieldName()).collect(joining(", "))); - QUERY_FIELDS.put(ProcessInstance.class, getAllFieldsList(ProcessInstance.class).filter(field -> !field.getName().equals("definition")).map(getFieldName()).collect(joining(", "))); + QUERY_FIELDS.put(ProcessInstance.class, getAllFieldsList(ProcessInstance.class).map(getFieldName()).collect(joining(", "))); QUERY_FIELDS.put(Job.class, getAllFieldsList(Job.class).map(getFieldName()).collect(joining(", "))); QUERY_FIELDS.computeIfPresent(ProcessInstance.class, (k, v) -> v + ", serviceUrl"); QUERY_FIELDS.computeIfPresent(ProcessInstance.class, (k, v) -> v + ", childProcessInstances { id, processName }"); @@ -230,7 +230,7 @@ private static String getQuery(String name, Class clazz, String... args) { } private static Stream getAllFieldsList(Class clazz) { - return FieldUtils.getAllFieldsList(clazz).stream().filter(f -> getJacocoPredicate().test(f)); + return FieldUtils.getAllFieldsList(clazz).stream().filter(getSoourcePredicate().or(getSoourcePredicate())); } private static Function getFieldName() { @@ -263,4 +263,8 @@ private static Function getFieldName() { private static Predicate getJacocoPredicate() { return field -> !field.getName().equals("$jacocoData"); } + + private static Predicate getSoourcePredicate() { + return field -> !(field.getDeclaringClass().equals(ProcessDefinition.class) && field.getName().equals("source")); + } } diff --git a/data-index/data-index-storage/data-index-storage-api/src/main/java/org/kie/kogito/index/model/ProcessDefinition.java b/data-index/data-index-storage/data-index-storage-api/src/main/java/org/kie/kogito/index/model/ProcessDefinition.java index 79d2c2918d..6e87b76b12 100644 --- a/data-index/data-index-storage/data-index-storage-api/src/main/java/org/kie/kogito/index/model/ProcessDefinition.java +++ b/data-index/data-index-storage/data-index-storage-api/src/main/java/org/kie/kogito/index/model/ProcessDefinition.java @@ -29,6 +29,8 @@ public class ProcessDefinition { private String endpoint; + private String source; + public String getId() { return id; } @@ -85,8 +87,20 @@ public void setEndpoint(String endpoint) { this.endpoint = endpoint; } + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } + public String getKey() { - return String.format("%s-%s", id, version); + return toKey(id, version); + } + + public static String toKey(String processId, String version){ + return String.format("%s-%s", processId, version); } @Override diff --git a/data-index/data-index-storage/data-index-storage-api/src/main/java/org/kie/kogito/index/model/ProcessInstanceMeta.java b/data-index/data-index-storage/data-index-storage-api/src/main/java/org/kie/kogito/index/model/ProcessInstanceMeta.java index 2ca51c1cfc..ab2bfae1be 100644 --- a/data-index/data-index-storage/data-index-storage-api/src/main/java/org/kie/kogito/index/model/ProcessInstanceMeta.java +++ b/data-index/data-index-storage/data-index-storage-api/src/main/java/org/kie/kogito/index/model/ProcessInstanceMeta.java @@ -26,6 +26,8 @@ public class ProcessInstanceMeta { private String id; private String processId; private String processName; + + private String version; private Integer state; private String businessKey; private String endpoint; @@ -153,6 +155,14 @@ public void setLastUpdate(ZonedDateTime lastUpdate) { this.lastUpdate = lastUpdate; } + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + @Override public String toString() { return "ProcessInstanceMeta{" + @@ -169,6 +179,7 @@ public String toString() { ", rootProcessId='" + rootProcessId + '\'' + ", parentProcessInstanceId='" + parentProcessInstanceId + '\'' + ", lastUpdated=" + lastUpdate + + ", version=" + version + '}'; } diff --git a/data-index/data-index-storage/data-index-storage-infinispan/src/main/java/org/kie/kogito/index/infinispan/protostream/ProcessDefinitionMarshaller.java b/data-index/data-index-storage/data-index-storage-infinispan/src/main/java/org/kie/kogito/index/infinispan/protostream/ProcessDefinitionMarshaller.java index da5df1fb3b..661d1ed590 100644 --- a/data-index/data-index-storage/data-index-storage-infinispan/src/main/java/org/kie/kogito/index/infinispan/protostream/ProcessDefinitionMarshaller.java +++ b/data-index/data-index-storage/data-index-storage-infinispan/src/main/java/org/kie/kogito/index/infinispan/protostream/ProcessDefinitionMarshaller.java @@ -34,6 +34,8 @@ public class ProcessDefinitionMarshaller extends AbstractMarshaller implements M protected static final String TYPE = "type"; protected static final String ENDPOINT = "endpoint"; + protected static final String SOURCE = "source"; + public ProcessDefinitionMarshaller(ObjectMapper mapper) { super(mapper); } @@ -48,6 +50,8 @@ public ProcessDefinition readFrom(ProtoStreamReader reader) throws IOException { pd.setAddons(reader.readCollection(ADDONS, new HashSet<>(), String.class)); pd.setType(reader.readString(TYPE)); pd.setEndpoint(reader.readString(ENDPOINT)); + byte[] bytes = reader.readBytes(SOURCE); + pd.setSource(bytes == null ? null : new String(bytes)); return pd; } @@ -60,6 +64,7 @@ public void writeTo(ProtoStreamWriter writer, ProcessDefinition pd) throws IOExc writer.writeCollection(ADDONS, pd.getAddons(), String.class); writer.writeString(TYPE, pd.getType()); writer.writeString(ENDPOINT, pd.getEndpoint()); + writer.writeBytes(SOURCE, pd.getSource() == null ? null : pd.getSource().getBytes()); } @Override diff --git a/data-index/data-index-storage/data-index-storage-infinispan/src/main/java/org/kie/kogito/index/infinispan/protostream/ProcessInstanceMarshaller.java b/data-index/data-index-storage/data-index-storage-infinispan/src/main/java/org/kie/kogito/index/infinispan/protostream/ProcessInstanceMarshaller.java index 15a13cd24e..8a7682d090 100644 --- a/data-index/data-index-storage/data-index-storage-infinispan/src/main/java/org/kie/kogito/index/infinispan/protostream/ProcessInstanceMarshaller.java +++ b/data-index/data-index-storage/data-index-storage-infinispan/src/main/java/org/kie/kogito/index/infinispan/protostream/ProcessInstanceMarshaller.java @@ -44,6 +44,7 @@ public class ProcessInstanceMarshaller extends AbstractMarshaller implements Mes protected static final String ROOT_PROCESS_ID = "rootProcessId"; protected static final String PARENT_PROCESS_INSTANCE_ID = "parentProcessInstanceId"; protected static final String PROCESS_NAME = "processName"; + protected static final String VERSION = "version"; protected static final String ERROR = "error"; protected static final String ADDONS = "addons"; protected static final String LAST_UPDATE = "lastUpdate"; @@ -75,6 +76,7 @@ public ProcessInstance readFrom(ProtoStreamReader reader) throws IOException { pi.setLastUpdate(dateToZonedDateTime(reader.readDate(LAST_UPDATE))); pi.setBusinessKey(reader.readString(BUSINESS_KEY)); pi.setMilestones(reader.readCollection(MILESTONES, new ArrayList<>(), Milestone.class)); + pi.setVersion(reader.readString(VERSION)); return pi; } @@ -98,6 +100,7 @@ public void writeTo(ProtoStreamWriter writer, ProcessInstance pi) throws IOExcep writer.writeDate(LAST_UPDATE, zonedDateTimeToDate(pi.getLastUpdate())); writer.writeString(BUSINESS_KEY, pi.getBusinessKey()); writer.writeCollection(MILESTONES, pi.getMilestones(), Milestone.class); + writer.writeString(VERSION, pi.getVersion()); } @Override diff --git a/data-index/data-index-storage/data-index-storage-mongodb/src/main/java/org/kie/kogito/index/mongodb/model/ProcessDefinitionEntity.java b/data-index/data-index-storage/data-index-storage-mongodb/src/main/java/org/kie/kogito/index/mongodb/model/ProcessDefinitionEntity.java index ad1135dbfd..a967f2223a 100644 --- a/data-index/data-index-storage/data-index-storage-mongodb/src/main/java/org/kie/kogito/index/mongodb/model/ProcessDefinitionEntity.java +++ b/data-index/data-index-storage/data-index-storage-mongodb/src/main/java/org/kie/kogito/index/mongodb/model/ProcessDefinitionEntity.java @@ -38,6 +38,8 @@ public class ProcessDefinitionEntity { private String endpoint; + private byte[] source; + public String getId() { return id; } @@ -102,6 +104,14 @@ public void setEndpoint(String endpoint) { this.endpoint = endpoint; } + public byte[] getSource() { + return source; + } + + public void setSource(byte[] source) { + this.source = source; + } + @Override public boolean equals(Object o) { if (this == o) diff --git a/data-index/data-index-storage/data-index-storage-mongodb/src/main/java/org/kie/kogito/index/mongodb/model/ProcessDefinitionEntityMapper.java b/data-index/data-index-storage/data-index-storage-mongodb/src/main/java/org/kie/kogito/index/mongodb/model/ProcessDefinitionEntityMapper.java index fd47ddec81..eabad2fcb4 100644 --- a/data-index/data-index-storage/data-index-storage-mongodb/src/main/java/org/kie/kogito/index/mongodb/model/ProcessDefinitionEntityMapper.java +++ b/data-index/data-index-storage/data-index-storage-mongodb/src/main/java/org/kie/kogito/index/mongodb/model/ProcessDefinitionEntityMapper.java @@ -41,6 +41,7 @@ public ProcessDefinitionEntity mapToEntity(String key, ProcessDefinition pd) { entity.setAddons(pd.getAddons()); entity.setType(pd.getType()); entity.setEndpoint(pd.getEndpoint()); + entity.setSource(pd.getSource() == null ? null : pd.getSource().getBytes()); return entity; } @@ -58,6 +59,7 @@ public ProcessDefinition mapToModel(ProcessDefinitionEntity entity) { pd.setAddons(entity.getAddons()); pd.setType(entity.getType()); pd.setEndpoint(entity.getEndpoint()); + pd.setSource(entity.getSource() == null ? null : new String(entity.getSource())); return pd; } diff --git a/data-index/data-index-storage/data-index-storage-mongodb/src/main/java/org/kie/kogito/index/mongodb/model/ProcessInstanceEntity.java b/data-index/data-index-storage/data-index-storage-mongodb/src/main/java/org/kie/kogito/index/mongodb/model/ProcessInstanceEntity.java index 347a29f52b..a715da20e4 100644 --- a/data-index/data-index-storage/data-index-storage-mongodb/src/main/java/org/kie/kogito/index/mongodb/model/ProcessInstanceEntity.java +++ b/data-index/data-index-storage/data-index-storage-mongodb/src/main/java/org/kie/kogito/index/mongodb/model/ProcessInstanceEntity.java @@ -52,6 +52,8 @@ public class ProcessInstanceEntity { String processName; + String version; + ProcessInstanceErrorEntity error; Set addons; @@ -206,6 +208,14 @@ public void setMilestones(List milestones) { this.milestones = milestones; } + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + @Override public boolean equals(Object o) { if (this == o) { diff --git a/data-index/data-index-storage/data-index-storage-mongodb/src/main/java/org/kie/kogito/index/mongodb/model/ProcessInstanceEntityMapper.java b/data-index/data-index-storage/data-index-storage-mongodb/src/main/java/org/kie/kogito/index/mongodb/model/ProcessInstanceEntityMapper.java index c167809f86..cc070b7cda 100644 --- a/data-index/data-index-storage/data-index-storage-mongodb/src/main/java/org/kie/kogito/index/mongodb/model/ProcessInstanceEntityMapper.java +++ b/data-index/data-index-storage/data-index-storage-mongodb/src/main/java/org/kie/kogito/index/mongodb/model/ProcessInstanceEntityMapper.java @@ -72,6 +72,7 @@ public ProcessInstanceEntity mapToEntity(String key, ProcessInstance instance) { entity.setLastUpdate(zonedDateTimeToInstant(instance.getLastUpdate())); entity.setBusinessKey(instance.getBusinessKey()); entity.setMilestones(Optional.ofNullable(instance.getMilestones()).map(milestones -> milestones.stream().map(this::fromMilestone).collect(toList())).orElse(null)); + entity.setVersion(instance.getVersion()); return entity; } @@ -99,7 +100,8 @@ public ProcessInstance mapToModel(ProcessInstanceEntity entity) { instance.setAddons(entity.getAddons()); instance.setLastUpdate(instantToZonedDateTime(entity.getLastUpdate())); instance.setBusinessKey(entity.getBusinessKey()); - instance.setMilestones(Optional.ofNullable(entity.getMilestones()).map(milesteons -> milesteons.stream().map(this::toMilestone).collect(toList())).orElse(null)); + instance.setMilestones(Optional.ofNullable(entity.getMilestones()).map(milestones -> milestones.stream().map(this::toMilestone).collect(toList())).orElse(null)); + instance.setVersion(entity.getVersion()); return instance; } diff --git a/data-index/data-index-storage/data-index-storage-oracle/src/main/java/org/kie/kogito/index/oracle/mapper/ProcessDefinitionEntityMapper.java b/data-index/data-index-storage/data-index-storage-oracle/src/main/java/org/kie/kogito/index/oracle/mapper/ProcessDefinitionEntityMapper.java index 0243d9c301..65428b70ee 100644 --- a/data-index/data-index-storage/data-index-storage-oracle/src/main/java/org/kie/kogito/index/oracle/mapper/ProcessDefinitionEntityMapper.java +++ b/data-index/data-index-storage/data-index-storage-oracle/src/main/java/org/kie/kogito/index/oracle/mapper/ProcessDefinitionEntityMapper.java @@ -29,4 +29,11 @@ public interface ProcessDefinitionEntityMapper { @InheritInverseConfiguration ProcessDefinition mapToModel(ProcessDefinitionEntity pd); + default byte[] map(String value) { + return value == null ? null : value.getBytes(); + }; + + default String map(byte[] value) { + return value == null ? null : new String(value); + } } diff --git a/data-index/data-index-storage/data-index-storage-oracle/src/main/java/org/kie/kogito/index/oracle/model/ProcessDefinitionEntity.java b/data-index/data-index-storage/data-index-storage-oracle/src/main/java/org/kie/kogito/index/oracle/model/ProcessDefinitionEntity.java index 839dcbb3b5..a6c636ac91 100644 --- a/data-index/data-index-storage/data-index-storage-oracle/src/main/java/org/kie/kogito/index/oracle/model/ProcessDefinitionEntity.java +++ b/data-index/data-index-storage/data-index-storage-oracle/src/main/java/org/kie/kogito/index/oracle/model/ProcessDefinitionEntity.java @@ -27,6 +27,7 @@ import javax.persistence.Id; import javax.persistence.IdClass; import javax.persistence.JoinColumn; +import javax.persistence.Lob; import javax.persistence.Table; import org.hibernate.annotations.OnDelete; @@ -47,6 +48,8 @@ public class ProcessDefinitionEntity extends AbstractEntity { private String endpoint; + private byte[] source; + @ElementCollection @JoinColumn(name = "id") @CollectionTable(name = "definitions_roles", joinColumns = { @JoinColumn(name = "process_id"), @@ -120,6 +123,14 @@ public void setEndpoint(String endpoint) { this.endpoint = endpoint; } + public byte[] getSource() { + return source; + } + + public void setSource(byte[] source) { + this.source = source; + } + @Override public boolean equals(Object o) { if (this == o) diff --git a/data-index/data-index-storage/data-index-storage-oracle/src/main/java/org/kie/kogito/index/oracle/model/ProcessInstanceEntity.java b/data-index/data-index-storage/data-index-storage-oracle/src/main/java/org/kie/kogito/index/oracle/model/ProcessInstanceEntity.java index 73d1c94268..f8875af097 100644 --- a/data-index/data-index-storage/data-index-storage-oracle/src/main/java/org/kie/kogito/index/oracle/model/ProcessInstanceEntity.java +++ b/data-index/data-index-storage/data-index-storage-oracle/src/main/java/org/kie/kogito/index/oracle/model/ProcessInstanceEntity.java @@ -49,6 +49,7 @@ public class ProcessInstanceEntity extends AbstractEntity { @Id private String id; private String processId; + private String version; private String processName; private Integer state; private String businessKey; @@ -228,6 +229,14 @@ public void setError(ProcessInstanceErrorEntity error) { this.error = error; } + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -266,6 +275,7 @@ public String toString() { ", milestones=" + milestones + ", addons=" + addons + ", error=" + error + + ", version=" + version + '}'; } } diff --git a/data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.33.0__data_index_create.sql b/data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.33.0__data_index_create.sql index 0e20e416cf..4d76d3d1d3 100644 --- a/data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.33.0__data_index_create.sql +++ b/data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.33.0__data_index_create.sql @@ -1,209 +1,223 @@ -create table attachments ( - id varchar(255) not null, - content varchar(255), - name varchar(255), - updated_at timestamp, - updated_by varchar(255), - task_id varchar(255) not null, - CONSTRAINT attachment_pk PRIMARY KEY(id) +create table attachments +( + id varchar(255) not null, + content varchar(255), + name varchar(255), + updated_at timestamp, + updated_by varchar(255), + task_id varchar(255) not null, + CONSTRAINT attachment_pk PRIMARY KEY (id) ); -create table comments ( - id varchar(255) not null, - content varchar(255), - updated_at timestamp, - updated_by varchar(255), - task_id varchar(255) not null, - CONSTRAINT comment_pk PRIMARY KEY(id) +create table comments +( + id varchar(255) not null, + content varchar(255), + updated_at timestamp, + updated_by varchar(255), + task_id varchar(255) not null, + CONSTRAINT comment_pk PRIMARY KEY (id) ); -create table jobs ( - id varchar(255) not null, - callback_endpoint varchar(255), - endpoint varchar(255), - execution_counter NUMBER(10), - expiration_time timestamp, - last_update timestamp, - node_instance_id varchar(255), - priority NUMBER(10), - process_id varchar(255), - process_instance_id varchar(255), - repeat_interval NUMBER(19), - repeat_limit NUMBER(10), - retries NUMBER(10), - root_process_id varchar(255), - root_process_instance_id varchar(255), - scheduled_id varchar(255), - status varchar(255), - CONSTRAINT jobs_pk PRIMARY KEY(id) - ); - - create table milestones ( - id varchar(255) not null, - process_instance_id varchar(255) not null, - name varchar(255), - status varchar(255), - CONSTRAINT milestones_pk PRIMARY KEY(id, process_instance_id) - ); - - create table nodes ( - id varchar(255) not null, - definition_id varchar(255), - enter timestamp, - exit timestamp, - name varchar(255), - node_id varchar(255), - type varchar(255), - process_instance_id varchar(255) not null, - CONSTRAINT nodes_pk PRIMARY KEY(id) - ); - - create table processes ( - id varchar(255) not null, - business_key varchar(255), - end_time timestamp, - endpoint varchar(255), - message varchar(255), - node_definition_id varchar(255), - last_update_time timestamp, - parent_process_instance_id varchar(255), - process_id varchar(255), - process_name varchar(255), - root_process_id varchar(255), - root_process_instance_id varchar(255), - start_time timestamp, - state NUMBER(10), - variables blob, - CONSTRAINT processes_pk PRIMARY KEY(id), - CONSTRAINT processes_variables_json CHECK (variables IS JSON) - ); - - create table processes_addons ( - process_id varchar(255) not null, - addon varchar(255) not null, - CONSTRAINT processes_addons_pk PRIMARY KEY(process_id, addon) - ); - - create table processes_roles ( - process_id varchar(255) not null, - role varchar(255) not null, - CONSTRAINT processes_roles_pk PRIMARY KEY(process_id, role) - ); - - create table tasks ( - id varchar(255) not null, - actual_owner varchar(255), - completed timestamp, - description varchar(255), - endpoint varchar(255), - inputs blob, - last_update timestamp, - name varchar(255), - outputs blob, - priority varchar(255), - process_id varchar(255), - process_instance_id varchar(255), - reference_name varchar(255), - root_process_id varchar(255), - root_process_instance_id varchar(255), - started timestamp, - state varchar(255), - CONSTRAINT tasks_pk PRIMARY KEY(id), - CONSTRAINT inputs_json CHECK (inputs IS JSON), - CONSTRAINT outputs_json CHECK (outputs IS JSON) - ); - create table tasks_admin_groups ( - task_id varchar(255) not null, - group_id varchar(255) not null, - CONSTRAINT tasks_admin_groups_pk PRIMARY KEY(task_id, group_id) - ); - - create table tasks_admin_users ( - task_id varchar(255) not null, - user_id varchar(255) not null, - CONSTRAINT tasks_admin_users_pk PRIMARY KEY(task_id, user_id) - ); - - create table tasks_excluded_users ( - task_id varchar(255) not null, - user_id varchar(255) not null, - CONSTRAINT tasks_excluded_users_pk PRIMARY KEY(task_id, user_id) - ); - - create table tasks_potential_groups ( - task_id varchar(255) not null, - group_id varchar(255) not null, - CONSTRAINT tasks_potential_groups_pk PRIMARY KEY(task_id, group_id) - ); - - create table tasks_potential_users ( - task_id varchar(255) not null, - user_id varchar(255) not null, - CONSTRAINT tasks_potential_users_pk PRIMARY KEY(task_id, user_id) - ); - - ALTER TABLE attachments - ADD CONSTRAINT fk_attachments_tasks +create table jobs +( + id varchar(255) not null, + callback_endpoint varchar(255), + endpoint varchar(255), + execution_counter NUMBER(10), + expiration_time timestamp, + last_update timestamp, + node_instance_id varchar(255), + priority NUMBER(10), + process_id varchar(255), + process_instance_id varchar(255), + repeat_interval NUMBER(19), + repeat_limit NUMBER(10), + retries NUMBER(10), + root_process_id varchar(255), + root_process_instance_id varchar(255), + scheduled_id varchar(255), + status varchar(255), + CONSTRAINT jobs_pk PRIMARY KEY (id) +); + +create table milestones +( + id varchar(255) not null, + process_instance_id varchar(255) not null, + name varchar(255), + status varchar(255), + CONSTRAINT milestones_pk PRIMARY KEY (id, process_instance_id) +); + +create table nodes +( + id varchar(255) not null, + definition_id varchar(255), + enter timestamp, + exit timestamp, + name varchar(255), + node_id varchar(255), + type varchar(255), + process_instance_id varchar(255) not null, + CONSTRAINT nodes_pk PRIMARY KEY (id) +); + +create table processes +( + id varchar(255) not null, + business_key varchar(255), + end_time timestamp, + endpoint varchar(255), + message varchar(255), + node_definition_id varchar(255), + last_update_time timestamp, + parent_process_instance_id varchar(255), + process_id varchar(255), + process_name varchar(255), + root_process_id varchar(255), + root_process_instance_id varchar(255), + start_time timestamp, + state NUMBER(10), + variables blob, + CONSTRAINT processes_pk PRIMARY KEY (id), + CONSTRAINT processes_variables_json CHECK (variables IS JSON) +); + +create table processes_addons +( + process_id varchar(255) not null, + addon varchar(255) not null, + CONSTRAINT processes_addons_pk PRIMARY KEY (process_id, addon) +); + +create table processes_roles +( + process_id varchar(255) not null, + role varchar(255) not null, + CONSTRAINT processes_roles_pk PRIMARY KEY (process_id, role) +); + +create table tasks +( + id varchar(255) not null, + actual_owner varchar(255), + completed timestamp, + description varchar(255), + endpoint varchar(255), + inputs blob, + last_update timestamp, + name varchar(255), + outputs blob, + priority varchar(255), + process_id varchar(255), + process_instance_id varchar(255), + reference_name varchar(255), + root_process_id varchar(255), + root_process_instance_id varchar(255), + started timestamp, + state varchar(255), + CONSTRAINT tasks_pk PRIMARY KEY (id), + CONSTRAINT inputs_json CHECK (inputs IS JSON), + CONSTRAINT outputs_json CHECK (outputs IS JSON) +); +create table tasks_admin_groups +( + task_id varchar(255) not null, + group_id varchar(255) not null, + CONSTRAINT tasks_admin_groups_pk PRIMARY KEY (task_id, group_id) +); + +create table tasks_admin_users +( + task_id varchar(255) not null, + user_id varchar(255) not null, + CONSTRAINT tasks_admin_users_pk PRIMARY KEY (task_id, user_id) +); + +create table tasks_excluded_users +( + task_id varchar(255) not null, + user_id varchar(255) not null, + CONSTRAINT tasks_excluded_users_pk PRIMARY KEY (task_id, user_id) +); + +create table tasks_potential_groups +( + task_id varchar(255) not null, + group_id varchar(255) not null, + CONSTRAINT tasks_potential_groups_pk PRIMARY KEY (task_id, group_id) +); + +create table tasks_potential_users +( + task_id varchar(255) not null, + user_id varchar(255) not null, + CONSTRAINT tasks_potential_users_pk PRIMARY KEY (task_id, user_id) +); + +ALTER TABLE attachments + ADD CONSTRAINT fk_attachments_tasks FOREIGN KEY (task_id) - REFERENCES tasks (id) - on delete cascade; + REFERENCES tasks (id) + on delete cascade; - ALTER TABLE comments - ADD CONSTRAINT fk_comments_tasks +ALTER TABLE comments + ADD CONSTRAINT fk_comments_tasks FOREIGN KEY (task_id) - REFERENCES tasks (id) - on delete cascade; + REFERENCES tasks (id) + on delete cascade; - ALTER TABLE milestones - ADD CONSTRAINT fk_milestones_process +ALTER TABLE milestones + ADD CONSTRAINT fk_milestones_process FOREIGN KEY (process_instance_id) - REFERENCES processes (id) - on delete cascade; + REFERENCES processes (id) + on delete cascade; - ALTER TABLE nodes - ADD CONSTRAINT fk_nodes_process +ALTER TABLE nodes + ADD CONSTRAINT fk_nodes_process FOREIGN KEY (process_instance_id) - REFERENCES processes (id) - on delete cascade; + REFERENCES processes (id) + on delete cascade; - ALTER TABLE processes_addons - ADD CONSTRAINT fk_processes_addons_processes +ALTER TABLE processes_addons + ADD CONSTRAINT fk_processes_addons_processes FOREIGN KEY (process_id) - REFERENCES processes (id) - on delete cascade; + REFERENCES processes (id) + on delete cascade; - ALTER TABLE processes_roles - ADD CONSTRAINT fk_processes_roles_processes +ALTER TABLE processes_roles + ADD CONSTRAINT fk_processes_roles_processes FOREIGN KEY (process_id) - REFERENCES processes (id) - on delete cascade; + REFERENCES processes (id) + on delete cascade; - ALTER TABLE tasks_admin_groups - ADD CONSTRAINT fk_tasks_admin_groups_tasks +ALTER TABLE tasks_admin_groups + ADD CONSTRAINT fk_tasks_admin_groups_tasks FOREIGN KEY (task_id) - REFERENCES tasks (id) - on delete cascade; + REFERENCES tasks (id) + on delete cascade; - ALTER TABLE tasks_admin_users - ADD CONSTRAINT fk_tasks_admin_users_tasks +ALTER TABLE tasks_admin_users + ADD CONSTRAINT fk_tasks_admin_users_tasks FOREIGN KEY (task_id) - REFERENCES tasks (id) - on delete cascade; + REFERENCES tasks (id) + on delete cascade; - ALTER TABLE tasks_excluded_users - ADD CONSTRAINT fk_tasks_excluded_users_tasks +ALTER TABLE tasks_excluded_users + ADD CONSTRAINT fk_tasks_excluded_users_tasks FOREIGN KEY (task_id) - REFERENCES tasks (id) - on delete cascade; + REFERENCES tasks (id) + on delete cascade; - ALTER TABLE tasks_potential_groups - ADD CONSTRAINT fk_tasks_potential_groups_tasks +ALTER TABLE tasks_potential_groups + ADD CONSTRAINT fk_tasks_potential_groups_tasks FOREIGN KEY (task_id) - REFERENCES tasks (id) - on delete cascade; + REFERENCES tasks (id) + on delete cascade; - ALTER TABLE tasks_potential_users - ADD CONSTRAINT fk_tasks_potential_users_tasks +ALTER TABLE tasks_potential_users + ADD CONSTRAINT fk_tasks_potential_users_tasks FOREIGN KEY (task_id) - REFERENCES tasks (id) - on delete cascade; + REFERENCES tasks (id) + on delete cascade; diff --git a/data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.43.0__data_index_definitions.sql b/data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.44.0__data_index_definitions.sql similarity index 90% rename from data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.43.0__data_index_definitions.sql rename to data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.44.0__data_index_definitions.sql index fec8ae8896..746f02e15a 100644 --- a/data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.43.0__data_index_definitions.sql +++ b/data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.44.0__data_index_definitions.sql @@ -3,6 +3,7 @@ create table definitions id varchar2(255 char) not null, version varchar2(255 char) not null, name varchar2(255 char), + source blob, type varchar2(255 char), endpoint varchar2(255 char), primary key (id, version) @@ -34,4 +35,7 @@ alter table definitions_roles add constraint fk_definitions_roles_definitions foreign key (process_id, process_version) references definitions - on delete cascade; \ No newline at end of file + on delete cascade; + +alter table processes + add version varchar2(255 char); \ No newline at end of file diff --git a/data-index/data-index-storage/data-index-storage-oracle/src/test/java/org/kie/kogito/index/oracle/mapper/ProcessInstanceEntityMapperIT.java b/data-index/data-index-storage/data-index-storage-oracle/src/test/java/org/kie/kogito/index/oracle/mapper/ProcessInstanceEntityMapperIT.java index ee86435234..c0fff697d1 100644 --- a/data-index/data-index-storage/data-index-storage-oracle/src/test/java/org/kie/kogito/index/oracle/mapper/ProcessInstanceEntityMapperIT.java +++ b/data-index/data-index-storage/data-index-storage-oracle/src/test/java/org/kie/kogito/index/oracle/mapper/ProcessInstanceEntityMapperIT.java @@ -69,6 +69,7 @@ void setup() { String testId = "testId"; String processId = "testProcessId"; + String version = "1.0"; Set roles = singleton("testRoles"); ObjectNode variables = jsonMapper.createObjectNode(); variables.put("test", "testValue"); @@ -102,6 +103,7 @@ void setup() { processInstance.setId(testId); processInstance.setProcessId(processId); + processInstance.setVersion(version); processInstance.setRoles(roles); processInstance.setVariables(variables); processInstance.setEndpoint(endpoint); @@ -144,6 +146,7 @@ void setup() { processInstanceEntity.setId(testId); processInstanceEntity.setProcessId(processId); + processInstanceEntity.setVersion(version); processInstanceEntity.setRoles(roles); processInstanceEntity.setVariables(variables); processInstanceEntity.setEndpoint(endpoint); diff --git a/data-index/data-index-storage/data-index-storage-postgresql/src/main/java/org/kie/kogito/index/postgresql/mapper/ProcessDefinitionEntityMapper.java b/data-index/data-index-storage/data-index-storage-postgresql/src/main/java/org/kie/kogito/index/postgresql/mapper/ProcessDefinitionEntityMapper.java index 1423160198..263772aea2 100644 --- a/data-index/data-index-storage/data-index-storage-postgresql/src/main/java/org/kie/kogito/index/postgresql/mapper/ProcessDefinitionEntityMapper.java +++ b/data-index/data-index-storage/data-index-storage-postgresql/src/main/java/org/kie/kogito/index/postgresql/mapper/ProcessDefinitionEntityMapper.java @@ -29,4 +29,12 @@ public interface ProcessDefinitionEntityMapper { @InheritInverseConfiguration ProcessDefinition mapToModel(ProcessDefinitionEntity pd); + default byte[] map(String value) { + return value == null ? null : value.getBytes(); + }; + + default String map(byte[] value) { + return value == null ? null : new String(value); + } + } diff --git a/data-index/data-index-storage/data-index-storage-postgresql/src/main/java/org/kie/kogito/index/postgresql/model/ProcessDefinitionEntity.java b/data-index/data-index-storage/data-index-storage-postgresql/src/main/java/org/kie/kogito/index/postgresql/model/ProcessDefinitionEntity.java index e94e2ec0ff..14717f10ea 100644 --- a/data-index/data-index-storage/data-index-storage-postgresql/src/main/java/org/kie/kogito/index/postgresql/model/ProcessDefinitionEntity.java +++ b/data-index/data-index-storage/data-index-storage-postgresql/src/main/java/org/kie/kogito/index/postgresql/model/ProcessDefinitionEntity.java @@ -31,6 +31,7 @@ import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; +import org.hibernate.annotations.Type; @Entity(name = "definitions") @Table(name = "definitions") @@ -45,6 +46,8 @@ public class ProcessDefinitionEntity extends AbstractEntity { private String name; private String type; + private byte[] source; + @ElementCollection @JoinColumn(name = "id") @CollectionTable(name = "definitions_roles", joinColumns = { @JoinColumn(name = "process_id"), @@ -120,6 +123,14 @@ public void setEndpoint(String endpoint) { this.endpoint = endpoint; } + public byte[] getSource() { + return source; + } + + public void setSource(byte[] source) { + this.source = source; + } + @Override public boolean equals(Object o) { if (this == o) diff --git a/data-index/data-index-storage/data-index-storage-postgresql/src/main/java/org/kie/kogito/index/postgresql/model/ProcessInstanceEntity.java b/data-index/data-index-storage/data-index-storage-postgresql/src/main/java/org/kie/kogito/index/postgresql/model/ProcessInstanceEntity.java index a50ee0230e..1fb60781dd 100644 --- a/data-index/data-index-storage/data-index-storage-postgresql/src/main/java/org/kie/kogito/index/postgresql/model/ProcessInstanceEntity.java +++ b/data-index/data-index-storage/data-index-storage-postgresql/src/main/java/org/kie/kogito/index/postgresql/model/ProcessInstanceEntity.java @@ -49,6 +49,7 @@ public class ProcessInstanceEntity extends AbstractEntity { @Id private String id; private String processId; + private String version; private String processName; private Integer state; private String businessKey; @@ -229,6 +230,14 @@ public void setError(ProcessInstanceErrorEntity error) { this.error = error; } + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -267,6 +276,7 @@ public String toString() { ", milestones=" + milestones + ", addons=" + addons + ", error=" + error + + ", version=" + version + '}'; } } diff --git a/data-index/data-index-storage/data-index-storage-postgresql/src/main/resources/db/migration/V1.43.0__data_index_definitions.sql b/data-index/data-index-storage/data-index-storage-postgresql/src/main/resources/db/migration/V1.44.0__data_index_definitions.sql similarity index 91% rename from data-index/data-index-storage/data-index-storage-postgresql/src/main/resources/db/migration/V1.43.0__data_index_definitions.sql rename to data-index/data-index-storage/data-index-storage-postgresql/src/main/resources/db/migration/V1.44.0__data_index_definitions.sql index 759df2227c..407913ff70 100644 --- a/data-index/data-index-storage/data-index-storage-postgresql/src/main/resources/db/migration/V1.43.0__data_index_definitions.sql +++ b/data-index/data-index-storage/data-index-storage-postgresql/src/main/resources/db/migration/V1.44.0__data_index_definitions.sql @@ -4,6 +4,7 @@ create table definitions version varchar(255) not null, name varchar(255), type varchar(255), + source bytea, endpoint varchar(255), primary key (id, version) ); @@ -39,3 +40,6 @@ alter table if exists definitions_roles on delete cascade; + +alter table if exists processes + add column version varchar (255); diff --git a/data-index/data-index-storage/data-index-storage-protobuf/src/main/resources/META-INF/kogito-index.proto b/data-index/data-index-storage/data-index-storage-protobuf/src/main/resources/META-INF/kogito-index.proto index bfa5114034..6abc31b188 100644 --- a/data-index/data-index-storage/data-index-storage-protobuf/src/main/resources/META-INF/kogito-index.proto +++ b/data-index/data-index-storage/data-index-storage-protobuf/src/main/resources/META-INF/kogito-index.proto @@ -36,6 +36,8 @@ message ProcessInstanceMeta { optional int64 lastUpdate = 12; /* @Field(store = Store.YES) */ optional string businessKey = 13; + /* @Field(store = Store.YES) */ + optional string version = 14; } /* @Indexed */ @@ -54,6 +56,7 @@ message ProcessDefinition { optional string type = 6; /* @Field(store = Store.YES) */ optional string endpoint = 7; + optional bytes source = 8; } /* @Indexed */ @@ -91,6 +94,8 @@ message ProcessInstance { /* @Field(store = Store.YES) @SortableField */ optional string businessKey = 17; repeated Milestone milestones = 18; + /* @Field(store = Store.YES) */ + optional string version = 19; } /* @Indexed */ diff --git a/data-index/data-index-test-utils/pom.xml b/data-index/data-index-test-utils/pom.xml index caec8a78c7..09929bc2ae 100644 --- a/data-index/data-index-test-utils/pom.xml +++ b/data-index/data-index-test-utils/pom.xml @@ -17,10 +17,6 @@ org.kie.kogito data-index-common - - org.apache.commons - commons-lang3 - org.kie.kogito kogito-quarkus-test-utils 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 53accf842e..678a732b40 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 @@ -32,7 +32,6 @@ import java.util.Set; import java.util.UUID; -import org.apache.commons.lang3.RandomStringUtils; import org.eclipse.microprofile.config.ConfigProvider; import org.kie.kogito.event.process.AttachmentEventBody; import org.kie.kogito.event.process.CommentEventBody; @@ -104,11 +103,11 @@ public static ProcessInstanceDataEvent getProcessCloudEvent(String processId, St .processId(processId) .version("1.0") .rootProcessId(rootProcessId) - .processName(RandomStringUtils.randomAlphabetic(10)) + .processName(String.format("%s-name", processId)) .startDate(new Date()) .endDate(status == ProcessInstanceState.COMPLETED ? Date.from(Instant.now().plus(1, ChronoUnit.HOURS)) : null) .state(status.ordinal()) - .businessKey(RandomStringUtils.randomAlphabetic(10)) + .businessKey(String.format("%s-key", processId)) .variables(getProcessInstanceVariablesMap()) .milestones(Set.of( MilestoneEventBody.create() @@ -139,7 +138,8 @@ public static ProcessInstance getProcessInstance(String processId, String proces ProcessInstance pi = new ProcessInstance(); pi.setId(processInstanceId); pi.setProcessId(processId); - pi.setProcessName(RandomStringUtils.randomAlphabetic(10)); + pi.setVersion("1.0"); + pi.setProcessName(String.format("%s-name", processId)); pi.setRootProcessInstanceId(rootProcessInstanceId); pi.setParentProcessInstanceId(rootProcessInstanceId); pi.setRootProcessId(rootProcessId); @@ -153,7 +153,7 @@ public static ProcessInstance getProcessInstance(String processId, String proces pi.setError(new ProcessInstanceError("StartEvent_1", "Something went wrong")); } pi.setMilestones(getMilestones()); - pi.setBusinessKey(RandomStringUtils.randomAlphabetic(10)); + pi.setBusinessKey(String.format("%s-key", processId)); return pi; } diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/deployment/pom.xml b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/deployment/pom.xml index 0c5e612a37..9c0b57c0de 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/deployment/pom.xml +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/deployment/pom.xml @@ -26,5 +26,9 @@ org.kie.kogito kogito-addons-quarkus-data-index-persistence-common-runtime + + org.kie.kogito + kogito-addons-quarkus-source-files-deployment + diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/pom.xml b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/pom.xml index aac7357a84..fab7cdcf23 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/pom.xml +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/pom.xml @@ -19,6 +19,18 @@ org.kie.kogito data-index-common + + org.kie.kogito + kogito-addons-process-svg + + + org.kie.kogito + kogito-addons-quarkus-source-files + + + org.kie.kogito + jbpm-flow + org.kie.kogito 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/ProcessDefinitionRegister.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/ProcessDefinitionRegister.java new file mode 100644 index 0000000000..2e3908e5cf --- /dev/null +++ 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/ProcessDefinitionRegister.java @@ -0,0 +1,78 @@ +/* + * Copyright 2023 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.addon; + +import java.util.Optional; +import java.util.Set; +import java.util.function.Function; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; + +import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.kie.kogito.Application; +import org.kie.kogito.index.api.KogitoRuntimeClient; +import org.kie.kogito.index.model.ProcessDefinition; +import org.kie.kogito.index.service.DataIndexServiceException; +import org.kie.kogito.index.storage.DataIndexStorageService; +import org.kie.kogito.process.Process; +import org.kie.kogito.process.Processes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.quarkus.runtime.StartupEvent; + +@ApplicationScoped +public class ProcessDefinitionRegister { + + private static final Logger LOGGER = LoggerFactory.getLogger(ProcessDefinitionRegister.class); + + @ConfigProperty(name = "kogito.service.url") + Optional kogitoServiceUrl; + + void startup(@Observes StartupEvent event, Processes processes, Application app, DataIndexStorageService storage, KogitoRuntimeClient client) { + processes.processIds().stream() + .map(processes::processById) + .map(mapProcessDefinition(app.config().addons().availableAddons(), kogitoServiceUrl.orElse(null), client)) + .forEach(process -> { + LOGGER.debug("Registering process definition with id: {}", process.getId()); + storage.getProcessDefinitionsCache().put(process.getKey(), process); + }); + } + + private Function, ProcessDefinition> mapProcessDefinition(Set addons, String endpoint, KogitoRuntimeClient client) { + return p -> { + ProcessDefinition pd = new ProcessDefinition(); + pd.setId(p.id()); + pd.setName(p.name()); + pd.setVersion(p.version()); + pd.setType(pd.getType()); + pd.setAddons(addons); + // See ProcessInstanceEventBatch.buildSource + pd.setEndpoint(endpoint + "/" + (p.id().contains(".") ? p.id().substring(p.id().lastIndexOf('.') + 1) : p.id())); + try { + String content = client.getProcessDefinitionSourceFileContent(null, p.id()).get(); + pd.setSource(content); + } catch (Exception e) { + LOGGER.error("Failed to register process definition with id: {}", p.id(), e); + throw new DataIndexServiceException("Failed to register process definition", e); + } + return pd; + }; + } + +} 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/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 similarity index 100% rename from data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/runtime/src/main/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImpl.java rename to 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 diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-process/src/main/resources/application.properties b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-process/src/main/resources/application.properties index 93a21d7b59..e43686884a 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-process/src/main/resources/application.properties +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-process/src/main/resources/application.properties @@ -1,4 +1,5 @@ kogito.persistence.type=infinispan +kogito.service.url=http://localhost:8080 quarkus.devservices.enabled=false quarkus.infinispan-client.use-auth=false \ No newline at end of file diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-process/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/InfinispanQuarkusAddonDataIndexPersistenceIT.java b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-process/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/InfinispanQuarkusAddonDataIndexPersistenceIT.java index bb4c874a0a..15a8cd91fb 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-process/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/InfinispanQuarkusAddonDataIndexPersistenceIT.java +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-process/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/InfinispanQuarkusAddonDataIndexPersistenceIT.java @@ -26,8 +26,11 @@ import io.restassured.http.ContentType; import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.Matchers.emptyOrNullString; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.kie.kogito.index.test.Constants.KOGITO_DATA_INDEX_SERVICE_URL; @@ -44,6 +47,18 @@ class InfinispanQuarkusAddonDataIndexPersistenceIT { @Test void testDataIndexAddon() { + given().contentType(ContentType.JSON) + .baseUri(dataIndex) + .body("{ \"query\" : \"{ ProcessDefinitions{ id, name, version, endpoint, addons, source } }\" }") + .when().post("/graphql") + .then().log().ifValidationFails().statusCode(200) + .body("data.ProcessDefinitions[0].id", is("hello")) + .body("data.ProcessDefinitions[0].name", is("hello")) + .body("data.ProcessDefinitions[0].version", is("1.0")) + .body("data.ProcessDefinitions[0].endpoint", is("http://localhost:8080/hello")) + .body("data.ProcessDefinitions[0].addons", hasItem("infinispan-persistence")) + .body("data.ProcessDefinitions[0].source", is(not(emptyOrNullString()))); + given().contentType(ContentType.JSON) .baseUri(dataIndex) .body("{ \"query\" : \"{ProcessInstances{ id } }\" }") diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-sw/pom.xml b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-sw/pom.xml index ec3c0e98b2..78252951cb 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-sw/pom.xml +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-sw/pom.xml @@ -46,6 +46,11 @@ rest-assured test + + org.assertj + assertj-core + test + org.kie.kogito kogito-addons-quarkus-data-index-persistence-infinispan-deployment diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-sw/src/main/resources/application.properties b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-sw/src/main/resources/application.properties index 93a21d7b59..e43686884a 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-sw/src/main/resources/application.properties +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-sw/src/main/resources/application.properties @@ -1,4 +1,5 @@ kogito.persistence.type=infinispan +kogito.service.url=http://localhost:8080 quarkus.devservices.enabled=false quarkus.infinispan-client.use-auth=false \ No newline at end of file diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-sw/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/InfinispanQuarkusAddonDataIndexPersistenceIT.java b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-sw/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/InfinispanQuarkusAddonDataIndexPersistenceIT.java index d4b867c2ba..e0bf4e86e1 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-sw/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/InfinispanQuarkusAddonDataIndexPersistenceIT.java +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-infinispan/integration-tests-sw/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/InfinispanQuarkusAddonDataIndexPersistenceIT.java @@ -24,9 +24,14 @@ import io.quarkus.test.junit.QuarkusIntegrationTest; import io.restassured.RestAssured; import io.restassured.http.ContentType; +import io.restassured.path.json.JsonPath; import static io.restassured.RestAssured.given; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.emptyOrNullString; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.kie.kogito.index.test.Constants.KOGITO_DATA_INDEX_SERVICE_URL; @@ -43,6 +48,22 @@ class InfinispanQuarkusAddonDataIndexPersistenceIT { @Test void testDataIndexAddon() { + String source = given().contentType(ContentType.JSON) + .baseUri(dataIndex) + .body("{ \"query\" : \"{ ProcessDefinitions{ id, name, version, endpoint, addons, source } }\" }") + .when().post("/graphql") + .then().log().ifValidationFails().statusCode(200) + .body("data.ProcessDefinitions[0].id", is("greet")) + .body("data.ProcessDefinitions[0].name", is("Greeting workflow")) + .body("data.ProcessDefinitions[0].version", is("1.0")) + .body("data.ProcessDefinitions[0].endpoint", is("http://localhost:8080/greet")) + .body("data.ProcessDefinitions[0].addons", hasItem("infinispan-persistence")) + .body("data.ProcessDefinitions[0].source", is(not(emptyOrNullString()))) + .extract().path("data.ProcessDefinitions[0].source"); + + assertThat(JsonPath.from(source).getString("id")).isEqualTo("greet"); + assertThat(JsonPath.from(source).getString("version")).isEqualTo("1.0"); + given().contentType(ContentType.JSON) .baseUri(dataIndex) .body("{ \"query\" : \"{ProcessInstances{ id } }\" }") diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-process/src/main/resources/application.properties b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-process/src/main/resources/application.properties index 9fbe160fc4..ebf86e7b1f 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-process/src/main/resources/application.properties +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-process/src/main/resources/application.properties @@ -1,4 +1,5 @@ kogito.persistence.type=mongodb +kogito.service.url=http://localhost:8080 # MongoDB quarkus.mongodb.database=kogito diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-process/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/MongoQuarkusAddonDataIndexPersistenceIT.java b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-process/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/MongoQuarkusAddonDataIndexPersistenceIT.java index ab4cd564ba..6f1b59527a 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-process/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/MongoQuarkusAddonDataIndexPersistenceIT.java +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-process/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/MongoQuarkusAddonDataIndexPersistenceIT.java @@ -26,8 +26,11 @@ import io.restassured.http.ContentType; import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.Matchers.emptyOrNullString; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.kie.kogito.index.test.Constants.KOGITO_DATA_INDEX_SERVICE_URL; @@ -44,6 +47,18 @@ class MongoQuarkusAddonDataIndexPersistenceIT { @Test void testDataIndexAddon() { + given().contentType(ContentType.JSON) + .baseUri(dataIndex) + .body("{ \"query\" : \"{ ProcessDefinitions{ id, name, version, endpoint, addons, source } }\" }") + .when().post("/graphql") + .then().log().ifValidationFails().statusCode(200) + .body("data.ProcessDefinitions[0].id", is("hello")) + .body("data.ProcessDefinitions[0].name", is("hello")) + .body("data.ProcessDefinitions[0].version", is("1.0")) + .body("data.ProcessDefinitions[0].endpoint", is("http://localhost:8080/hello")) + .body("data.ProcessDefinitions[0].addons", hasItem("mongodb-persistence")) + .body("data.ProcessDefinitions[0].source", is(not(emptyOrNullString()))); + given().contentType(ContentType.JSON) .baseUri(dataIndex) .body("{ \"query\" : \"{ProcessInstances{ id } }\" }") diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-sw/pom.xml b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-sw/pom.xml index 06d1ebfa9b..9b3490d5fb 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-sw/pom.xml +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-sw/pom.xml @@ -36,6 +36,11 @@ data-index-test-utils test + + org.assertj + assertj-core + test + io.quarkus quarkus-junit5 diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-sw/src/main/resources/application.properties b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-sw/src/main/resources/application.properties index 9fbe160fc4..ebf86e7b1f 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-sw/src/main/resources/application.properties +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-sw/src/main/resources/application.properties @@ -1,4 +1,5 @@ kogito.persistence.type=mongodb +kogito.service.url=http://localhost:8080 # MongoDB quarkus.mongodb.database=kogito diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-sw/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/MongoQuarkusAddonDataIndexPersistenceIT.java b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-sw/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/MongoQuarkusAddonDataIndexPersistenceIT.java index 5f8e65cb9e..957e2f37b9 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-sw/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/MongoQuarkusAddonDataIndexPersistenceIT.java +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-mongodb/integration-tests-sw/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/MongoQuarkusAddonDataIndexPersistenceIT.java @@ -24,9 +24,14 @@ import io.quarkus.test.junit.QuarkusIntegrationTest; import io.restassured.RestAssured; import io.restassured.http.ContentType; +import io.restassured.path.json.JsonPath; import static io.restassured.RestAssured.given; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.emptyOrNullString; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.kie.kogito.index.test.Constants.KOGITO_DATA_INDEX_SERVICE_URL; @@ -43,6 +48,22 @@ class MongoQuarkusAddonDataIndexPersistenceIT { @Test void testDataIndexAddon() { + String source = given().contentType(ContentType.JSON) + .baseUri(dataIndex) + .body("{ \"query\" : \"{ ProcessDefinitions{ id, name, version, endpoint, addons, source } }\" }") + .when().post("/graphql") + .then().log().ifValidationFails().statusCode(200) + .body("data.ProcessDefinitions[0].id", is("greet")) + .body("data.ProcessDefinitions[0].name", is("Greeting workflow")) + .body("data.ProcessDefinitions[0].version", is("1.0")) + .body("data.ProcessDefinitions[0].endpoint", is("http://localhost:8080/greet")) + .body("data.ProcessDefinitions[0].addons", hasItem("mongodb-persistence")) + .body("data.ProcessDefinitions[0].source", is(not(emptyOrNullString()))) + .extract().path("data.ProcessDefinitions[0].source"); + + assertThat(JsonPath.from(source).getString("id")).isEqualTo("greet"); + assertThat(JsonPath.from(source).getString("version")).isEqualTo("1.0"); + given().contentType(ContentType.JSON) .baseUri(dataIndex) .body("{ \"query\" : \"{ProcessInstances{ id } }\" }") diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-process/src/main/resources/application.properties b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-process/src/main/resources/application.properties index 456f843b7a..8e8e2ecf39 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-process/src/main/resources/application.properties +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-process/src/main/resources/application.properties @@ -1,4 +1,6 @@ kogito.persistence.type=jdbc +kogito.service.url=http://localhost:8080 + quarkus.flyway.migrate-at-start=true quarkus.flyway.baseline-on-migrate=true diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-process/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/PostgreSQLQuarkusAddonDataIndexPersistenceIT.java b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-process/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/PostgreSQLQuarkusAddonDataIndexPersistenceIT.java index 4fdff8d647..13c352ba85 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-process/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/PostgreSQLQuarkusAddonDataIndexPersistenceIT.java +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-process/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/PostgreSQLQuarkusAddonDataIndexPersistenceIT.java @@ -27,8 +27,11 @@ import io.restassured.http.ContentType; import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.Matchers.emptyOrNullString; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.kie.kogito.index.test.Constants.KOGITO_DATA_INDEX_SERVICE_URL; import static org.kie.kogito.index.test.quarkus.http.DataIndexPostgreSqlHttpQuarkusTestResource.DATA_INDEX_MIGRATE_DB; @@ -46,6 +49,18 @@ class PostgreSQLQuarkusAddonDataIndexPersistenceIT { @Test void testDataIndexAddon() { + given().contentType(ContentType.JSON) + .baseUri(dataIndex) + .body("{ \"query\" : \"{ ProcessDefinitions{ id, name, version, endpoint, addons, source } }\" }") + .when().post("/graphql") + .then().log().ifValidationFails().statusCode(200) + .body("data.ProcessDefinitions[0].id", is("hello")) + .body("data.ProcessDefinitions[0].name", is("hello")) + .body("data.ProcessDefinitions[0].version", is("1.0")) + .body("data.ProcessDefinitions[0].endpoint", is("http://localhost:8080/hello")) + .body("data.ProcessDefinitions[0].addons", hasItem("jdbc-persistence")) + .body("data.ProcessDefinitions[0].source", is(not(emptyOrNullString()))); + given().contentType(ContentType.JSON) .baseUri(dataIndex) .body("{ \"query\" : \"{ProcessInstances{ id } }\" }") diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-sw/pom.xml b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-sw/pom.xml index 35903c7ffb..754362298d 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-sw/pom.xml +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-sw/pom.xml @@ -44,6 +44,11 @@ data-index-test-utils test + + org.assertj + assertj-core + test + org.kie.kogito kogito-addons-quarkus-data-index-persistence-postgresql-deployment diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-sw/src/main/resources/application.properties b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-sw/src/main/resources/application.properties index 456f843b7a..8e8e2ecf39 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-sw/src/main/resources/application.properties +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-sw/src/main/resources/application.properties @@ -1,4 +1,6 @@ kogito.persistence.type=jdbc +kogito.service.url=http://localhost:8080 + quarkus.flyway.migrate-at-start=true quarkus.flyway.baseline-on-migrate=true diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-sw/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/PostgreSQLQuarkusAddonDataIndexPersistenceIT.java b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-sw/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/PostgreSQLQuarkusAddonDataIndexPersistenceIT.java index b263290273..ec5b52c887 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-sw/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/PostgreSQLQuarkusAddonDataIndexPersistenceIT.java +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-postgresql/integration-tests-sw/src/test/java/org/kie/kogito/addons/quarkus/data/index/it/PostgreSQLQuarkusAddonDataIndexPersistenceIT.java @@ -25,9 +25,14 @@ import io.quarkus.test.junit.QuarkusIntegrationTest; import io.restassured.RestAssured; import io.restassured.http.ContentType; +import io.restassured.path.json.JsonPath; import static io.restassured.RestAssured.given; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.emptyOrNullString; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.kie.kogito.index.test.Constants.KOGITO_DATA_INDEX_SERVICE_URL; import static org.kie.kogito.index.test.quarkus.http.DataIndexPostgreSqlHttpQuarkusTestResource.DATA_INDEX_MIGRATE_DB; @@ -45,6 +50,22 @@ class PostgreSQLQuarkusAddonDataIndexPersistenceIT { @Test void testDataIndexAddon() { + String source = given().contentType(ContentType.JSON) + .baseUri(dataIndex) + .body("{ \"query\" : \"{ ProcessDefinitions{ id, name, version, endpoint, addons, source } }\" }") + .when().post("/graphql") + .then().log().ifValidationFails().statusCode(200) + .body("data.ProcessDefinitions[0].id", is("greet")) + .body("data.ProcessDefinitions[0].name", is("Greeting workflow")) + .body("data.ProcessDefinitions[0].version", is("1.0")) + .body("data.ProcessDefinitions[0].endpoint", is("http://localhost:8080/greet")) + .body("data.ProcessDefinitions[0].addons", hasItem("jdbc-persistence")) + .body("data.ProcessDefinitions[0].source", is(not(emptyOrNullString()))) + .extract().path("data.ProcessDefinitions[0].source"); + + assertThat(JsonPath.from(source).getString("id")).isEqualTo("greet"); + assertThat(JsonPath.from(source).getString("version")).isEqualTo("1.0"); + given().contentType(ContentType.JSON) .baseUri(dataIndex) .body("{ \"query\" : \"{ProcessInstances{ id } }\" }") diff --git a/data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/deployment/pom.xml b/data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/deployment/pom.xml index c8a4df768b..a21102534f 100644 --- a/data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/deployment/pom.xml +++ b/data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/deployment/pom.xml @@ -26,9 +26,5 @@ org.kie.kogito kogito-addons-quarkus-data-index-common-runtime - - org.kie.kogito - kogito-addons-quarkus-source-files-deployment - diff --git a/data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/runtime/pom.xml b/data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/runtime/pom.xml index c7e7bd5cf7..afaadc30bb 100644 --- a/data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/runtime/pom.xml +++ b/data-index/kogito-addons-quarkus-data-index/kogito-addons-quarkus-data-index-common/runtime/pom.xml @@ -23,18 +23,6 @@ org.kie.kogito kogito-addons-quarkus-data-index-persistence-common-runtime - - org.kie.kogito - jbpm-flow - - - org.kie.kogito - kogito-addons-process-svg - - - org.kie.kogito - kogito-addons-quarkus-source-files - 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 101ddf0bb5..06c6b58f47 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 @@ -54,6 +54,7 @@ public GraphQLSchema createSchema() { builder.dataFetcher("diagram", this::getProcessInstanceDiagram); builder.dataFetcher("source", this::getProcessInstanceSourceFileContent); builder.dataFetcher("nodeDefinitions", this::getProcessInstanceNodes); + builder.dataFetcher("definition", this::getProcessDefinition); return builder; }) .type("ProcessInstanceState", builder -> {