diff --git a/apps-integration-tests/integration-tests-data-index-service/integration-tests-data-index-service-common/src/test/java/org/kie/kogito/index/AbstractProcessDataIndexIT.java b/apps-integration-tests/integration-tests-data-index-service/integration-tests-data-index-service-common/src/test/java/org/kie/kogito/index/AbstractProcessDataIndexIT.java index 2edebf340e..82341e8ff4 100644 --- a/apps-integration-tests/integration-tests-data-index-service/integration-tests-data-index-service-common/src/test/java/org/kie/kogito/index/AbstractProcessDataIndexIT.java +++ b/apps-integration-tests/integration-tests-data-index-service/integration-tests-data-index-service-common/src/test/java/org/kie/kogito/index/AbstractProcessDataIndexIT.java @@ -148,13 +148,14 @@ public void testProcessInstanceEvents() throws IOException { await() .atMost(TIMEOUT) .untilAsserted(() -> given().spec(dataIndexSpec()).contentType(ContentType.JSON) - .body("{ \"query\" : \"{ProcessInstances{ id, processId, state } }\" }") + .body("{ \"query\" : \"{ProcessInstances{ id, processId, state, createdBy} }\" }") .when().post("/graphql") .then().statusCode(200) .body("data.ProcessInstances.size()", is(1)) .body("data.ProcessInstances[0].id", is(pId)) .body("data.ProcessInstances[0].processId", is("approvals")) - .body("data.ProcessInstances[0].state", is("ACTIVE"))); + .body("data.ProcessInstances[0].state", is("ACTIVE")) + .body("data.ProcessInstances[0].createdBy", nullValue())); await() .atMost(TIMEOUT) diff --git a/apps-integration-tests/integration-tests-data-index-service/integration-tests-data-index-service-quarkus-devservice/src/test/java/org/kie/kogito/index/inmemory/KogitoDevServiceTest.java b/apps-integration-tests/integration-tests-data-index-service/integration-tests-data-index-service-quarkus-devservice/src/test/java/org/kie/kogito/index/inmemory/KogitoDevServiceTest.java index 4b4acb5492..401ecbc1a0 100644 --- a/apps-integration-tests/integration-tests-data-index-service/integration-tests-data-index-service-quarkus-devservice/src/test/java/org/kie/kogito/index/inmemory/KogitoDevServiceTest.java +++ b/apps-integration-tests/integration-tests-data-index-service/integration-tests-data-index-service-quarkus-devservice/src/test/java/org/kie/kogito/index/inmemory/KogitoDevServiceTest.java @@ -31,8 +31,7 @@ import static io.restassured.RestAssured.given; import static org.awaitility.Awaitility.await; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.*; public class KogitoDevServiceTest { @@ -88,13 +87,14 @@ public void testDataIndexDevService() { .baseUri("http://localhost:" + dataIndexHttpPort) .contentType(ContentType.JSON) .accept(ContentType.JSON) - .body("{ \"query\" : \"{ ProcessInstances (where: { id: {equal: \\\"" + processId + "\\\"}}) { id, processId, processName } }\"}") + .body("{ \"query\" : \"{ ProcessInstances (where: { id: {equal: \\\"" + processId + "\\\"}}) { id, processId, processName, createdBy } }\"}") .when().post("/graphql") .then() .statusCode(200) .body("data.ProcessInstances[0].id", is(processId)) .body("data.ProcessInstances[0].processId", is("greet")) - .body("data.ProcessInstances[0].processName", is("Greeting workflow"))); + .body("data.ProcessInstances[0].processName", is("Greeting workflow")) + .body("data.ProcessInstances[0].createdBy", nullValue())); given().contentType(ContentType.JSON) .baseUri("http://localhost:" + dataIndexHttpPort) 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 747bf0a3ff..01b70c56a2 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 @@ -64,6 +64,7 @@ public ProcessInstance apply(ProcessInstanceDataEvent event) { pi.setLastUpdate(toZonedDateTime(event.getTime())); pi.setVersion(event.getData().getVersion()); pi.setDefinition(definition().apply(event)); + pi.setUpdatedBy(event.getData().getIdentity()); return pi; } 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 ce929cfa90..828a5adbc5 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 @@ -56,6 +56,8 @@ public void indexProcessInstance(ProcessInstance pi) { if (previousPI != null) { List nodes = previousPI.getNodes().stream().filter(n -> !pi.getNodes().contains(n)).collect(toList()); pi.getNodes().addAll(nodes); + } else { + pi.setCreatedBy(pi.getUpdatedBy()); } ProcessDefinition definition = pi.getDefinition(); if (!manager.getProcessDefinitionsCache().containsKey(definition.getKey())) { 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 e4e18cd01e..566a439fc7 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 @@ -69,6 +69,9 @@ type ProcessInstance { diagram: String source: String definition: ProcessDefinition + identity: String + createdBy: String + updatedBy: String } type ProcessInstanceError { @@ -132,6 +135,8 @@ input ProcessInstanceOrderBy { error: ProcessInstanceErrorOrderBy lastUpdate: OrderBy businessKey: OrderBy + createdBy: OrderBy + updatedBy: OrderBy } input ProcessInstanceErrorOrderBy { @@ -160,6 +165,8 @@ input ProcessInstanceArgument { addons: StringArrayArgument lastUpdate: DateArgument businessKey: StringArgument + createdBy: StringArgument + updatedBy: StringArgument } input ProcessInstanceErrorArgument { diff --git a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/json/ProcessInstanceMetaMapper.java b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/json/ProcessInstanceMetaMapper.java index 1a6c106401..3caa719024 100644 --- a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/json/ProcessInstanceMetaMapper.java +++ b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/json/ProcessInstanceMetaMapper.java @@ -77,6 +77,9 @@ private ObjectNode getProcessJson(ProcessInstanceDataEvent event) { if (!isNullOrEmpty(event.getData().getBusinessKey())) { json.put("businessKey", event.getData().getBusinessKey()); } + if (!isNullOrEmpty(event.getData().getIdentity())) { + json.put("updatedBy", event.getData().getIdentity()); + } return json; } } 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 c3b0a28620..708b44593a 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 @@ -56,6 +56,8 @@ type ProcessInstanceMeta { end: DateTime lastUpdate: DateTime! businessKey: String + createdBy: String + updatedBy: String } input ProcessInstanceMetaArgument { @@ -71,6 +73,8 @@ input ProcessInstanceMetaArgument { start: DateArgument end: DateArgument businessKey: StringArgument + createdBy: StringArgument + updatedBy: StringArgument } extend type UserTaskInstance { diff --git a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/AbstractDomainIndexingServiceIT.java b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/AbstractDomainIndexingServiceIT.java index 20fcc7b6f0..c0ae3af80e 100644 --- a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/AbstractDomainIndexingServiceIT.java +++ b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/AbstractDomainIndexingServiceIT.java @@ -176,7 +176,7 @@ void testAddProtoFile() throws Exception { .when().post("/graphql") .then().log().ifValidationFails().statusCode(200).body("data.Travels", isA(Collection.class)); - ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); indexProcessCloudEvent(startEvent); validateProcessInstance(getProcessInstanceByIdAndState(processInstanceId, ACTIVE), startEvent); @@ -205,7 +205,7 @@ void testAddProtoFile() throws Exception { .body("data.Travels[0].flight.flightNumber", is("MX555")); ProcessInstanceDataEvent subProcessStartEvent = getProcessCloudEvent(subProcessId, subProcessInstanceId, ACTIVE, - processInstanceId, processId, processInstanceId); + processInstanceId, processId, processInstanceId, "currentUser"); Map travellerMap = new HashMap<>(); travellerMap.put("firstName", "Maciej"); travellerMap.put("email", "mail@mail.com"); @@ -271,7 +271,7 @@ void testAddProtoFile() throws Exception { .body("data.Travels[0].flight.arrival", is("2019-08-20T22:12:57.34Z")) .body("data.Travels[0].flight.departure", is("2019-08-20T07:12:57.34Z")); - ProcessInstanceDataEvent endEvent = getProcessCloudEvent(processId, processInstanceId, COMPLETED, null, null, null); + ProcessInstanceDataEvent endEvent = getProcessCloudEvent(processId, processInstanceId, COMPLETED, null, null, null, "currentUser"); indexProcessCloudEvent(endEvent); validateProcessInstance(getProcessInstanceByIdAndState(processInstanceId, COMPLETED), endEvent, subProcessInstanceId); @@ -420,7 +420,7 @@ void testIndexingDomainUsingUserTaskEventFirst() throws Exception { .body("data.Travels[0].metadata.userTasks[0].lastUpdate", is(formatOffsetDateTime(userTaskEvent.getTime()))) .body("data.Travels[0].metadata.processInstances", is(nullValue())); - ProcessInstanceDataEvent processEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent processEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); indexProcessCloudEvent(processEvent); given().contentType(ContentType.JSON) @@ -466,7 +466,7 @@ void testIndexingDomainUsingProcessEventFirst() throws Exception { .when().post("/graphql") .then().log().ifValidationFails().statusCode(200).body("data.Travels", isA(Collection.class)); - ProcessInstanceDataEvent processEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent processEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); indexProcessCloudEvent(processEvent); given().contentType(ContentType.JSON) @@ -535,7 +535,7 @@ void testIndexingDomainParallelEvents() throws Exception { .when().post("/graphql") .then().log().ifValidationFails().statusCode(200).body("data.Travels", isA(Collection.class)); - ProcessInstanceDataEvent processEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent processEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); UserTaskInstanceDataEvent userTaskEvent = getUserTaskCloudEvent(taskId, processId, processInstanceId, null, null, state); CompletableFuture.allOf( @@ -585,7 +585,7 @@ void testProcessInstanceDomainIndex() throws Exception { .when().post("/graphql") .then().log().ifValidationFails().statusCode(200).body("data.Travels", isA(Collection.class)); - ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); indexProcessCloudEvent(startEvent); validateProcessInstance(getProcessInstanceById(processInstanceId), startEvent); @@ -613,7 +613,7 @@ void testProcessInstanceDomainIndex() throws Exception { .body("data.Travels[0].hotel.name", is("Meriton")) .body("data.Travels[0].traveller.firstName", is("Maciej")); - ProcessInstanceDataEvent endEvent = getProcessCloudEvent(processId, processInstanceId, COMPLETED, null, null, null); + ProcessInstanceDataEvent endEvent = getProcessCloudEvent(processId, processInstanceId, COMPLETED, null, null, null, "currentUser"); endEvent.getData().update().endDate(new Date()); Map variablesMap = getProcessInstanceVariablesMap(); ((Map) variablesMap.get("hotel")).put("name", "Ibis"); @@ -647,13 +647,13 @@ void testProcessInstanceDomainIndex() throws Exception { .body("data.Travels[0].traveller.firstName", is("Maciej")); ProcessInstanceDataEvent event = getProcessCloudEvent(subProcessId, subProcessInstanceId, ACTIVE, processInstanceId, - processId, processInstanceId); + processId, processInstanceId, "currentUser"); indexProcessCloudEvent(event); validateProcessInstance(getProcessInstanceByParentProcessInstanceId(processInstanceId), event); ProcessInstanceDataEvent errorEvent = getProcessCloudEvent(subProcessId, subProcessInstanceId, ERROR, processInstanceId, - processId, processInstanceId); + processId, processInstanceId, "currentUser"); indexProcessCloudEvent(errorEvent); validateProcessInstance( 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 67b9621f23..29f212218b 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 @@ -59,6 +59,7 @@ import static org.kie.kogito.index.service.GraphQLUtils.getJobById; import static org.kie.kogito.index.service.GraphQLUtils.getProcessDefinitionByIdAndVersion; import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceByBusinessKey; +import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceByCreatedBy; import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceById; import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceByIdAndAddon; import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceByIdAndErrorNode; @@ -72,6 +73,7 @@ import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceByIdAndState; import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceByParentProcessInstanceId; import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceByRootProcessInstanceId; +import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceByUpdatedBy; import static org.kie.kogito.index.service.GraphQLUtils.getUserTaskInstanceById; import static org.kie.kogito.index.service.GraphQLUtils.getUserTaskInstanceByIdAndActualOwner; import static org.kie.kogito.index.service.GraphQLUtils.getUserTaskInstanceByIdAndCompleted; @@ -201,7 +203,7 @@ void testProcessInstancePagination() { IntStream.range(0, 100).forEach(i -> { String pId = UUID.randomUUID().toString(); - ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, pId, ACTIVE, null, null, null); + ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, pId, ACTIVE, null, null, null, "currentUser"); indexProcessCloudEvent(startEvent); pIds.add(pId); await() @@ -294,7 +296,7 @@ void testProcessInstanceIndex() throws Exception { String subProcessId = processId + "_sub"; String subProcessInstanceId = UUID.randomUUID().toString(); - ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); indexProcessCloudEvent(startEvent); validateProcessDefinition(getProcessDefinitionByIdAndVersion(startEvent.getKogitoProcessId(), startEvent.getData().getVersion()), startEvent); @@ -309,8 +311,10 @@ void testProcessInstanceIndex() throws Exception { validateProcessInstance(getProcessInstanceByIdAndMilestoneStatus(processInstanceId, MilestoneStatus.AVAILABLE.name()), startEvent); validateProcessInstance(getProcessInstanceByBusinessKey(startEvent.getData().getBusinessKey()), startEvent); + validateProcessInstance(getProcessInstanceByCreatedBy(startEvent.getData().getIdentity()), startEvent); + validateProcessInstance(getProcessInstanceByUpdatedBy(startEvent.getData().getIdentity()), startEvent); - ProcessInstanceDataEvent endEvent = getProcessCloudEvent(processId, processInstanceId, COMPLETED, null, null, null); + ProcessInstanceDataEvent endEvent = getProcessCloudEvent(processId, processInstanceId, COMPLETED, null, null, null, "currentUser"); endEvent.getData().update().endDate(new Date()); Map variablesMap = getProcessInstanceVariablesMap(); ((Map) variablesMap.get("hotel")).put("name", "Ibis"); @@ -323,7 +327,7 @@ void testProcessInstanceIndex() throws Exception { validateProcessInstance(getProcessInstanceByIdAndMilestoneStatus(processInstanceId, MilestoneStatus.COMPLETED.name()), endEvent); ProcessInstanceDataEvent event = getProcessCloudEvent(subProcessId, subProcessInstanceId, ACTIVE, processInstanceId, - processId, processInstanceId); + processId, processInstanceId, "currentUser"); indexProcessCloudEvent(event); validateProcessInstance(getProcessInstanceByParentProcessInstanceId(processInstanceId), event); @@ -337,7 +341,7 @@ void testProcessInstanceIndex() throws Exception { event); ProcessInstanceDataEvent errorEvent = getProcessCloudEvent(subProcessId, subProcessInstanceId, ERROR, processInstanceId, - processId, processInstanceId); + processId, processInstanceId, "currentUser"); indexProcessCloudEvent(errorEvent); validateProcessInstance( 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 a12c24b594..eb7eb4c0dd 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 @@ -133,6 +133,14 @@ public static String getProcessInstanceByBusinessKey(String businessKeys) { return getProcessInstanceQuery("ProcessInstanceByBusinessKey", businessKeys); } + public static String getProcessInstanceByCreatedBy(String identity) { + return getProcessInstanceQuery("ProcessInstanceByCreatedBy", identity); + } + + public static String getProcessInstanceByUpdatedBy(String identity) { + return getProcessInstanceQuery("ProcessInstanceByUpdatedBy", identity); + } + public static String getUserTaskInstanceById(String id) { return getUserTaskInstanceQuery("UserTaskInstanceById", id); } diff --git a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/AbstractWebSocketSubscriptionIT.java b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/AbstractWebSocketSubscriptionIT.java index 0f2bf8b604..3b46cc2381 100644 --- a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/AbstractWebSocketSubscriptionIT.java +++ b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/AbstractWebSocketSubscriptionIT.java @@ -149,7 +149,7 @@ private void assertDomainSubscription(String processId, String processInstanceId .when().post("/graphql") .then().log().ifValidationFails().statusCode(200).body("data.Travels", isA(Collection.class)); - ProcessInstanceDataEvent event = getProcessCloudEvent(processId, processInstanceId, state, null, null, null); + ProcessInstanceDataEvent event = getProcessCloudEvent(processId, processInstanceId, state, null, null, null, "currentUser"); indexProcessCloudEvent(event); JsonObject json = cf.get(1, TimeUnit.MINUTES); @@ -168,7 +168,7 @@ private void assertProcessInstanceSubscription(String processId, String processI .when().post("/graphql") .then().log().ifValidationFails().statusCode(200).body("data.Travels", isA(Collection.class)); - ProcessInstanceDataEvent event = getProcessCloudEvent(processId, processInstanceId, state, null, null, null); + ProcessInstanceDataEvent event = getProcessCloudEvent(processId, processInstanceId, state, null, null, null, "currentUser"); indexProcessCloudEvent(event); JsonObject json = cf.get(1, TimeUnit.MINUTES); diff --git a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/query/AbstractGraphQLRuntimesQueriesIT.java b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/query/AbstractGraphQLRuntimesQueriesIT.java index 3d7a4823aa..5121ae0a48 100644 --- a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/query/AbstractGraphQLRuntimesQueriesIT.java +++ b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/graphql/query/AbstractGraphQLRuntimesQueriesIT.java @@ -78,7 +78,7 @@ public void setup() throws Exception { @Test void testProcessInstanceAbort() { String processInstanceId = UUID.randomUUID().toString(); - ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); indexProcessCloudEvent(startEvent); checkOkResponse("{ \"query\" : \"mutation{ ProcessInstanceAbort ( id: \\\"" + processInstanceId + "\\\")}\"}"); @@ -90,7 +90,7 @@ void testProcessInstanceAbort() { @Test void testProcessInstanceRetry() { String processInstanceId = UUID.randomUUID().toString(); - ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); indexProcessCloudEvent(startEvent); checkOkResponse("{ \"query\" : \"mutation{ ProcessInstanceRetry ( id: \\\"" + processInstanceId + "\\\")}\"}"); @@ -102,7 +102,7 @@ void testProcessInstanceRetry() { @Test void testProcessInstanceSkip() { String processInstanceId = UUID.randomUUID().toString(); - ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); indexProcessCloudEvent(startEvent); checkOkResponse("{ \"query\" : \"mutation{ ProcessInstanceSkip ( id: \\\"" + processInstanceId + "\\\")}\"}"); @@ -116,7 +116,7 @@ void testProcessInstanceUpdateVariables() { String variablesUpdated = "variablesUpdated"; String processInstanceId = UUID.randomUUID().toString(); - ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); indexProcessCloudEvent(startEvent); checkOkResponse("{ \"query\" : \"mutation{ ProcessInstanceUpdateVariables ( id: \\\"" + processInstanceId + "\\\", variables: \\\"" + variablesUpdated + "\\\")}\"}"); @@ -128,7 +128,7 @@ void testProcessInstanceUpdateVariables() { @Test void testProcessDefinitionNodes() { String processInstanceId = UUID.randomUUID().toString(); - ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); indexProcessCloudEvent(startEvent); checkOkResponse("{ \"query\" : \"query { ProcessInstances (where: { id: {equal: \\\"" + processInstanceId + "\\\"}}) { nodeDefinitions { id }} }\" }"); @@ -138,7 +138,7 @@ void testProcessDefinitionNodes() { @Test void testProcessInstanceDiagram() { String processInstanceId = UUID.randomUUID().toString(); - ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); indexProcessCloudEvent(startEvent); checkOkResponse("{ \"query\" : \"query { ProcessInstances (where: { id: {equal: \\\"" + processInstanceId + "\\\"}}) {diagram} }\" }"); @@ -150,7 +150,7 @@ void testProcessInstanceDiagram() { @Test void testProcessDefinitionSource() { String processInstanceId = UUID.randomUUID().toString(); - ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); indexProcessCloudEvent(startEvent); checkOkResponse("{ \"query\" : \"query { ProcessInstances (where: { id: {equal: \\\"" + processInstanceId + "\\\"}}) {source} }\" }"); @@ -162,7 +162,7 @@ void testProcessDefinitionSource() { void testNodeInstanceTrigger() { String nodeId = "nodeIdToTrigger"; String processInstanceId = UUID.randomUUID().toString(); - ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); indexProcessCloudEvent(startEvent); checkOkResponse("{ \"query\" : \"mutation{ NodeInstanceTrigger ( id: \\\"" + processInstanceId + "\\\", nodeId: \\\"" + nodeId + "\\\")}\"}"); @@ -175,7 +175,7 @@ void testNodeInstanceTrigger() { void testNodeInstanceRetrigger() { String nodeInstanceId = "nodeInstanceIdToRetrigger"; String processInstanceId = UUID.randomUUID().toString(); - ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); indexProcessCloudEvent(startEvent); checkOkResponse("{ \"query\" : \"mutation{ NodeInstanceRetrigger ( id: \\\"" + processInstanceId + "\\\", nodeInstanceId: \\\"" + nodeInstanceId + "\\\")}\"}"); @@ -188,7 +188,7 @@ void testNodeInstanceRetrigger() { void testNodeInstanceCancel() { String nodeInstanceId = "nodeInstanceIdToCancel"; String processInstanceId = UUID.randomUUID().toString(); - ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); indexProcessCloudEvent(startEvent); checkOkResponse("{ \"query\" : \"mutation{ NodeInstanceCancel ( id: \\\"" + processInstanceId + "\\\", nodeInstanceId: \\\"" + nodeInstanceId + "\\\")}\"}"); diff --git a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/json/ProcessInstanceMetaMapperTest.java b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/json/ProcessInstanceMetaMapperTest.java index ee507c9a85..0899cf7680 100644 --- a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/json/ProcessInstanceMetaMapperTest.java +++ b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/json/ProcessInstanceMetaMapperTest.java @@ -38,7 +38,7 @@ public void testProcessInstanceMapper() { String processInstanceId = UUID.randomUUID().toString(); String rootProcessInstanceId = UUID.randomUUID().toString(); String piPrefix = KOGITO_DOMAIN_ATTRIBUTE + "." + PROCESS_INSTANCES_DOMAIN_ATTRIBUTE; - ProcessInstanceDataEvent event = getProcessCloudEvent(processId, processInstanceId, ProcessInstanceState.COMPLETED, rootProcessInstanceId, rootProcessId, rootProcessInstanceId); + ProcessInstanceDataEvent event = getProcessCloudEvent(processId, processInstanceId, ProcessInstanceState.COMPLETED, rootProcessInstanceId, rootProcessId, rootProcessInstanceId, "currentUser"); ObjectNode json = new ProcessInstanceMetaMapper().apply(event); assertThat(json).isNotNull(); assertThatJson(json.toString()).and( @@ -59,6 +59,7 @@ public void testProcessInstanceMapper() { a -> a.node(piPrefix + "[0].endpoint").isEqualTo(event.getSource().toString()), a -> a.node(piPrefix + "[0].start").isEqualTo(event.getData().getStartDate().toInstant().toEpochMilli()), a -> a.node(piPrefix + "[0].end").isEqualTo(event.getData().getEndDate().toInstant().toEpochMilli()), + a -> a.node(piPrefix + "[0].updatedBy").isEqualTo(event.getData().getIdentity().toString()), a -> a.node(piPrefix + "[0].lastUpdate").isEqualTo(event.getTime().toInstant().toEpochMilli())); } @@ -69,7 +70,7 @@ public void testProcessInstanceMapperWithBusinessKey() { String processInstanceId = UUID.randomUUID().toString(); String rootProcessInstanceId = UUID.randomUUID().toString(); String piPrefix = KOGITO_DOMAIN_ATTRIBUTE + "." + PROCESS_INSTANCES_DOMAIN_ATTRIBUTE; - ProcessInstanceDataEvent event = getProcessCloudEvent(processId, processInstanceId, ProcessInstanceState.COMPLETED, rootProcessInstanceId, rootProcessId, rootProcessInstanceId); + ProcessInstanceDataEvent event = getProcessCloudEvent(processId, processInstanceId, ProcessInstanceState.COMPLETED, rootProcessInstanceId, rootProcessId, rootProcessInstanceId, "currentUser"); event.getData().update().businessKey("custom-key"); ObjectNode json = new ProcessInstanceMetaMapper().apply(event); assertThat(json).isNotNull(); @@ -92,6 +93,7 @@ public void testProcessInstanceMapperWithBusinessKey() { a -> a.node(piPrefix + "[0].start").isEqualTo(event.getData().getStartDate().toInstant().toEpochMilli()), a -> a.node(piPrefix + "[0].end").isEqualTo(event.getData().getEndDate().toInstant().toEpochMilli()), a -> a.node(piPrefix + "[0].lastUpdate").isEqualTo(event.getTime().toInstant().toEpochMilli()), - a -> a.node(piPrefix + "[0].businessKey").isEqualTo(event.getData().getBusinessKey())); + a -> a.node(piPrefix + "[0].businessKey").isEqualTo(event.getData().getBusinessKey()), + a -> a.node(piPrefix + "[0].updatedBy").isEqualTo(event.getData().getIdentity().toString())); } } diff --git a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/AbstractDomainMessagingHttpConsumerIT.java b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/AbstractDomainMessagingHttpConsumerIT.java index f80c8c2cf2..6c5f27e9cf 100644 --- a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/AbstractDomainMessagingHttpConsumerIT.java +++ b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/AbstractDomainMessagingHttpConsumerIT.java @@ -45,7 +45,7 @@ protected void sendUserTaskInstanceEvent() throws Exception { protected void sendProcessInstanceEvent() throws Exception { ProcessInstanceDataEvent event = getProcessCloudEvent("travels", "2308e23d-9998-47e9-a772-a078cf5b891b", ProcessInstanceState.ACTIVE, null, - null, null); + null, null, "currentUser"); connector.source(KOGITO_PROCESSINSTANCES_EVENTS).send(event); } diff --git a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/AbstractMessagingHttpConsumerIT.java b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/AbstractMessagingHttpConsumerIT.java index baeeeb9a51..62212149ea 100644 --- a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/AbstractMessagingHttpConsumerIT.java +++ b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/AbstractMessagingHttpConsumerIT.java @@ -44,7 +44,7 @@ protected void sendUserTaskInstanceEvent() throws Exception { protected void sendProcessInstanceEvent() throws Exception { ProcessInstanceDataEvent event = getProcessCloudEvent("travels", "2308e23d-9998-47e9-a772-a078cf5b891b", ProcessInstanceState.ACTIVE, null, - null, null); + null, null, "currentUser"); connector.source(KOGITO_PROCESSINSTANCES_EVENTS).send(event); } diff --git a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/AbstractMessagingLoadKafkaIT.java b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/AbstractMessagingLoadKafkaIT.java index 34b83ea61e..dcab0f098f 100644 --- a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/AbstractMessagingLoadKafkaIT.java +++ b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/AbstractMessagingLoadKafkaIT.java @@ -107,7 +107,7 @@ void testMessagingEvents() { String processInstanceId = UUID.randomUUID().toString(); String taskId = UUID.randomUUID().toString(); - ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null); + ProcessInstanceDataEvent startEvent = getProcessCloudEvent(processId, processInstanceId, ACTIVE, null, null, null, "currentUser"); sendProcessInstanceEvent(client, startEvent); @@ -117,7 +117,7 @@ void testMessagingEvents() { userTaskEvent = getUserTaskCloudEvent(taskId, processId, processInstanceId, null, null, "Completed"); sendUserTaskEvent(client, userTaskEvent); - ProcessInstanceDataEvent endEvent = getProcessCloudEvent(processId, processInstanceId, COMPLETED, null, null, null); + ProcessInstanceDataEvent endEvent = getProcessCloudEvent(processId, processInstanceId, COMPLETED, null, null, null, "currentUser"); sendProcessInstanceEvent(client, endEvent); return processInstanceId; diff --git a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/DomainEventConsumerTest.java b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/DomainEventConsumerTest.java index 4d4dfd42d7..4f3385b0cc 100644 --- a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/DomainEventConsumerTest.java +++ b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/DomainEventConsumerTest.java @@ -115,7 +115,7 @@ public void testOnProcessInstanceDomainEventIndexingException() { String processInstanceId = UUID.randomUUID().toString(); ProcessInstanceDataEvent event = getProcessCloudEvent(processId, processInstanceId, ProcessInstanceState.ACTIVE, null, - null, null); + null, null, "currentUser"); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> consumer.onDomainEvent(event)); verify(service).indexModel(any()); diff --git a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/ReactiveMessagingEventConsumerTest.java b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/ReactiveMessagingEventConsumerTest.java index d2592c9b4b..7fc8e7dd61 100644 --- a/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/ReactiveMessagingEventConsumerTest.java +++ b/data-index/data-index-service/data-index-service-common/src/test/java/org/kie/kogito/index/service/messaging/ReactiveMessagingEventConsumerTest.java @@ -61,7 +61,7 @@ public void testOnProcessInstanceEvent() { String processInstanceId = UUID.randomUUID().toString(); ProcessInstanceDataEvent event = getProcessCloudEvent(processId, processInstanceId, ProcessInstanceState.ACTIVE, null, - null, null); + null, null, "currentUser"); UniAssertSubscriber future = consumer.onProcessInstanceEvent(event).subscribe() .withSubscriber(UniAssertSubscriber.create()); diff --git a/data-index/data-index-service/data-index-service-common/src/test/resources/graphql_queries.json b/data-index/data-index-service/data-index-service-common/src/test/resources/graphql_queries.json index 8da0f683d7..afc269c6e5 100644 --- a/data-index/data-index-service/data-index-service-common/src/test/resources/graphql_queries.json +++ b/data-index/data-index-service/data-index-service-common/src/test/resources/graphql_queries.json @@ -100,6 +100,18 @@ "bk": "%s" } }, + "ProcessInstanceByCreatedBy": { + "query": "query ( $ident: String ) { ProcessInstances(where: { createdBy : { equal : $ident } }) { %s } }", + "variables": { + "ident": "%s" + } + }, + "ProcessInstanceByUpdatedBy": { + "query": "query ( $ident: String ) { ProcessInstances(where: { updatedBy : { equal : $ident } }) { %s } }", + "variables": { + "ident": "%s" + } + }, "UserTaskInstanceById": { "query": "query ( $id: String ) { UserTaskInstances( where: { id: { equal : $id } } ){ %s } }", "variables": { 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 ab2bfae1be..9a1172a196 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 @@ -41,6 +41,10 @@ public class ProcessInstanceMeta { private String rootProcessId; @JsonProperty("parentInstanceId") private String parentProcessInstanceId; + @JsonProperty("createdBy") + private String createdBy; + @JsonProperty("updatedBy") + private String updatedBy; private ZonedDateTime lastUpdate; public String getId() { @@ -163,6 +167,22 @@ public void setVersion(String version) { this.version = version; } + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + @Override public String toString() { return "ProcessInstanceMeta{" + @@ -180,6 +200,8 @@ public String toString() { ", parentProcessInstanceId='" + parentProcessInstanceId + '\'' + ", lastUpdated=" + lastUpdate + ", version=" + version + + ", createdBy=" + createdBy + + ", updatedBy=" + updatedBy + '}'; } 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 8a7682d090..01f3cabed4 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 @@ -50,6 +50,8 @@ public class ProcessInstanceMarshaller extends AbstractMarshaller implements Mes protected static final String LAST_UPDATE = "lastUpdate"; protected static final String BUSINESS_KEY = "businessKey"; protected static final String MILESTONES = "milestones"; + protected static final String CREATED_BY = "createdBy"; + protected static final String UPDATED_BY = "updatedBy"; public ProcessInstanceMarshaller(ObjectMapper mapper) { super(mapper); @@ -77,6 +79,8 @@ public ProcessInstance readFrom(ProtoStreamReader reader) throws IOException { pi.setBusinessKey(reader.readString(BUSINESS_KEY)); pi.setMilestones(reader.readCollection(MILESTONES, new ArrayList<>(), Milestone.class)); pi.setVersion(reader.readString(VERSION)); + pi.setCreatedBy(reader.readString(CREATED_BY)); + pi.setUpdatedBy(reader.readString(UPDATED_BY)); return pi; } @@ -101,6 +105,8 @@ public void writeTo(ProtoStreamWriter writer, ProcessInstance pi) throws IOExcep writer.writeString(BUSINESS_KEY, pi.getBusinessKey()); writer.writeCollection(MILESTONES, pi.getMilestones(), Milestone.class); writer.writeString(VERSION, pi.getVersion()); + writer.writeString(CREATED_BY, pi.getCreatedBy()); + writer.writeString(UPDATED_BY, pi.getCreatedBy()); } @Override diff --git a/data-index/data-index-storage/data-index-storage-infinispan/src/test/java/org/kie/kogito/index/infinispan/protostream/ProcessInstanceMarshallerTest.java b/data-index/data-index-storage/data-index-storage-infinispan/src/test/java/org/kie/kogito/index/infinispan/protostream/ProcessInstanceMarshallerTest.java index 6c8a59f5f9..8198a00de0 100644 --- a/data-index/data-index-storage/data-index-storage-infinispan/src/test/java/org/kie/kogito/index/infinispan/protostream/ProcessInstanceMarshallerTest.java +++ b/data-index/data-index-storage/data-index-storage-infinispan/src/test/java/org/kie/kogito/index/infinispan/protostream/ProcessInstanceMarshallerTest.java @@ -36,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.kie.kogito.index.infinispan.protostream.ProcessInstanceMarshaller.ADDONS; import static org.kie.kogito.index.infinispan.protostream.ProcessInstanceMarshaller.BUSINESS_KEY; +import static org.kie.kogito.index.infinispan.protostream.ProcessInstanceMarshaller.CREATED_BY; import static org.kie.kogito.index.infinispan.protostream.ProcessInstanceMarshaller.END; import static org.kie.kogito.index.infinispan.protostream.ProcessInstanceMarshaller.ENDPOINT; import static org.kie.kogito.index.infinispan.protostream.ProcessInstanceMarshaller.ERROR; @@ -82,6 +83,7 @@ void testReadFrom() throws IOException { when(reader.readDate(LAST_UPDATE)).thenReturn(now); when(reader.readString(BUSINESS_KEY)).thenReturn("businessKey"); when(reader.readCollection(eq(MILESTONES), any(), eq(Milestone.class))).thenReturn(new ArrayList<>()); + when(reader.readString(CREATED_BY)).thenReturn("currentUser"); ProcessInstanceMarshaller marshaller = new ProcessInstanceMarshaller(null); ProcessInstance pi = marshaller.readFrom(reader); @@ -105,7 +107,8 @@ void testReadFrom() throws IOException { .hasFieldOrPropertyWithValue(ERROR, null) .hasFieldOrPropertyWithValue(LAST_UPDATE, marshaller.dateToZonedDateTime(now)) .hasFieldOrPropertyWithValue(BUSINESS_KEY, "businessKey") - .hasFieldOrPropertyWithValue(MILESTONES, emptyList()); + .hasFieldOrPropertyWithValue(MILESTONES, emptyList()) + .hasFieldOrPropertyWithValue(CREATED_BY, "currentUser"); InOrder inOrder = inOrder(reader); inOrder.verify(reader).readString(ID); @@ -126,6 +129,7 @@ void testReadFrom() throws IOException { inOrder.verify(reader).readDate(LAST_UPDATE); inOrder.verify(reader).readString(BUSINESS_KEY); inOrder.verify(reader).readCollection(MILESTONES, new ArrayList<>(), Milestone.class); + inOrder.verify(reader).readString(CREATED_BY); } @Test @@ -145,6 +149,7 @@ void testWriteTo() throws IOException { pi.setStart(ZonedDateTime.now()); pi.setError(new ProcessInstanceError("StartEvent_1", "Something went wrong")); pi.setMilestones(emptyList()); + pi.setCreatedBy("currentUser"); MessageMarshaller.ProtoStreamWriter writer = mock(MessageMarshaller.ProtoStreamWriter.class); @@ -170,5 +175,6 @@ void testWriteTo() throws IOException { inOrder.verify(writer).writeDate(LAST_UPDATE, marshaller.zonedDateTimeToDate(pi.getLastUpdate())); inOrder.verify(writer).writeString(BUSINESS_KEY, pi.getBusinessKey()); inOrder.verify(writer).writeCollection(MILESTONES, pi.getMilestones(), Milestone.class); + inOrder.verify(writer).writeString(CREATED_BY, pi.getCreatedBy()); } } 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 a715da20e4..b2d2b53ad0 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 @@ -64,6 +64,10 @@ public class ProcessInstanceEntity { List milestones; + String createdBy; + + String updatedBy; + public String getId() { return id; } @@ -216,6 +220,22 @@ public void setVersion(String version) { this.version = version; } + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + @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 cc070b7cda..141871f46d 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 @@ -73,6 +73,8 @@ public ProcessInstanceEntity mapToEntity(String key, ProcessInstance instance) { 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()); + entity.setCreatedBy(instance.getCreatedBy()); + entity.setUpdatedBy(instance.getUpdatedBy()); return entity; } @@ -102,6 +104,8 @@ public ProcessInstance mapToModel(ProcessInstanceEntity entity) { instance.setBusinessKey(entity.getBusinessKey()); instance.setMilestones(Optional.ofNullable(entity.getMilestones()).map(milestones -> milestones.stream().map(this::toMilestone).collect(toList())).orElse(null)); instance.setVersion(entity.getVersion()); + instance.setCreatedBy(entity.getCreatedBy()); + instance.setUpdatedBy(entity.getCreatedBy()); return instance; } diff --git a/data-index/data-index-storage/data-index-storage-mongodb/src/test/java/org/kie/kogito/index/mongodb/model/ProcessInstanceEntityMapperTest.java b/data-index/data-index-storage/data-index-storage-mongodb/src/test/java/org/kie/kogito/index/mongodb/model/ProcessInstanceEntityMapperTest.java index 4d63c4673e..9a24a2ed4f 100644 --- a/data-index/data-index-storage/data-index-storage-mongodb/src/test/java/org/kie/kogito/index/mongodb/model/ProcessInstanceEntityMapperTest.java +++ b/data-index/data-index-storage/data-index-storage-mongodb/src/test/java/org/kie/kogito/index/mongodb/model/ProcessInstanceEntityMapperTest.java @@ -73,6 +73,8 @@ static void setup() { String processName = "testProcessName"; Set addons = Set.of("testAddons"); String businessKey = "testBusinessKey"; + String createdBy = "testCreatedBy"; + String updatedBy = "testUpdatedBy"; NodeInstance nodeInstance = new NodeInstance(); nodeInstance.setId(nodeInstanceId); @@ -111,6 +113,8 @@ static void setup() { processInstance.setLastUpdate(time); processInstance.setBusinessKey(businessKey); processInstance.setMilestones(List.of(milestone)); + processInstance.setCreatedBy(createdBy); + processInstance.setUpdatedBy(updatedBy); ProcessInstanceEntity.NodeInstanceEntity nodeInstanceEntity = new ProcessInstanceEntity.NodeInstanceEntity(); nodeInstanceEntity.setId(nodeInstanceId); @@ -149,6 +153,8 @@ static void setup() { processInstanceEntity.setLastUpdate(zonedDateTimeToInstant(time)); processInstanceEntity.setBusinessKey(businessKey); processInstanceEntity.setMilestones(List.of(milestoneEntity)); + processInstanceEntity.setCreatedBy(createdBy); + processInstanceEntity.setUpdatedBy(updatedBy); } @Test 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 f8875af097..f57178d54b 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 @@ -69,6 +69,10 @@ public class ProcessInstanceEntity extends AbstractEntity { private String parentProcessInstanceId; @Column(name = "lastUpdateTime") private ZonedDateTime lastUpdate; + @Column(name = "created_by") + private String createdBy; + @Column(name = "updated_by") + private String updatedBy; @Type(type = "jsonb") private ObjectNode variables; @OneToMany(cascade = CascadeType.ALL, mappedBy = "processInstance") @@ -189,6 +193,22 @@ public void setLastUpdate(ZonedDateTime lastUpdate) { this.lastUpdate = lastUpdate; } + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String identity) { + this.createdBy = identity; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + public ObjectNode getVariables() { return variables; } @@ -270,6 +290,8 @@ public String toString() { ", rootProcessId='" + rootProcessId + '\'' + ", parentProcessInstanceId='" + parentProcessInstanceId + '\'' + ", lastUpdate=" + lastUpdate + + ", createdBy=" + createdBy + + ", updatedBy=" + updatedBy + ", variables=" + variables + ", nodes=" + nodes + ", milestones=" + milestones + diff --git a/data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.45.0__data_index_node_definitions.sql b/data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.45.0.0__data_index_node_definitions.sql similarity index 100% rename from data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.45.0__data_index_node_definitions.sql rename to data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.45.0.0__data_index_node_definitions.sql diff --git a/data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.45.0.1__add_identity_to_process_instance.sql b/data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.45.0.1__add_identity_to_process_instance.sql new file mode 100644 index 0000000000..a37888e041 --- /dev/null +++ b/data-index/data-index-storage/data-index-storage-oracle/src/main/resources/db/migration/V1.45.0.1__add_identity_to_process_instance.sql @@ -0,0 +1,3 @@ +ALTER TABLE processes + ADD (created_by varchar(255), + updated_by varchar(255)); 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 c0fff697d1..0f03c13933 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 @@ -82,6 +82,8 @@ void setup() { String processName = "testProcessName"; Set addons = singleton("testAddons"); String businessKey = "testBusinessKey"; + String createdBy = "initiatorUser"; + String updatedBy = "currentUser"; NodeInstance nodeInstance = new NodeInstance(); nodeInstance.setId(nodeInstanceId); @@ -120,6 +122,8 @@ void setup() { processInstance.setLastUpdate(time); processInstance.setBusinessKey(businessKey); processInstance.setMilestones(singletonList(milestone)); + processInstance.setCreatedBy(createdBy); + processInstance.setUpdatedBy(updatedBy); NodeInstanceEntity nodeInstanceEntity = new NodeInstanceEntity(); nodeInstanceEntity.setId(nodeInstanceId); @@ -162,6 +166,8 @@ void setup() { processInstanceEntity.setAddons(addons); processInstanceEntity.setLastUpdate(time); processInstanceEntity.setBusinessKey(businessKey); + processInstanceEntity.setCreatedBy(createdBy); + processInstanceEntity.setUpdatedBy(updatedBy); processInstanceEntity.setMilestones(singletonList(milestoneEntity)); } 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 1fb60781dd..bedc0c6851 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 @@ -69,6 +69,9 @@ public class ProcessInstanceEntity extends AbstractEntity { private String parentProcessInstanceId; @Column(name = "lastUpdateTime") private ZonedDateTime lastUpdate; + private String createdBy; + + private String updatedBy; @Type(type = "jsonb") @Column(columnDefinition = "jsonb") private ObjectNode variables; @@ -190,6 +193,22 @@ public void setLastUpdate(ZonedDateTime lastUpdate) { this.lastUpdate = lastUpdate; } + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String identity) { + this.createdBy = identity; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + public ObjectNode getVariables() { return variables; } @@ -271,6 +290,8 @@ public String toString() { ", rootProcessId='" + rootProcessId + '\'' + ", parentProcessInstanceId='" + parentProcessInstanceId + '\'' + ", lastUpdate=" + lastUpdate + + ", createdBy=" + createdBy + + ", updatedBy=" + updatedBy + ", variables=" + variables + ", nodes=" + nodes + ", milestones=" + milestones + diff --git a/data-index/data-index-storage/data-index-storage-postgresql/src/main/resources/db/migration/V1.45.0__data_index_node_definitions.sql b/data-index/data-index-storage/data-index-storage-postgresql/src/main/resources/db/migration/V1.45.0.0__data_index_node_definitions.sql similarity index 100% rename from data-index/data-index-storage/data-index-storage-postgresql/src/main/resources/db/migration/V1.45.0__data_index_node_definitions.sql rename to data-index/data-index-storage/data-index-storage-postgresql/src/main/resources/db/migration/V1.45.0.0__data_index_node_definitions.sql diff --git a/data-index/data-index-storage/data-index-storage-postgresql/src/main/resources/db/migration/V1.45.0.1__add_identity_to_process_instance.sql b/data-index/data-index-storage/data-index-storage-postgresql/src/main/resources/db/migration/V1.45.0.1__add_identity_to_process_instance.sql new file mode 100644 index 0000000000..c942bfeb96 --- /dev/null +++ b/data-index/data-index-storage/data-index-storage-postgresql/src/main/resources/db/migration/V1.45.0.1__add_identity_to_process_instance.sql @@ -0,0 +1,3 @@ +ALTER TABLE processes + ADD COLUMN created_by character varying, + ADD COLUMN updated_by character varying; \ No newline at end of file diff --git a/data-index/data-index-storage/data-index-storage-postgresql/src/test/java/org/kie/kogito/index/postgresql/mapper/ProcessInstanceEntityMapperIT.java b/data-index/data-index-storage/data-index-storage-postgresql/src/test/java/org/kie/kogito/index/postgresql/mapper/ProcessInstanceEntityMapperIT.java index b76c8823df..fdcfdab19e 100644 --- a/data-index/data-index-storage/data-index-storage-postgresql/src/test/java/org/kie/kogito/index/postgresql/mapper/ProcessInstanceEntityMapperIT.java +++ b/data-index/data-index-storage/data-index-storage-postgresql/src/test/java/org/kie/kogito/index/postgresql/mapper/ProcessInstanceEntityMapperIT.java @@ -81,6 +81,8 @@ void setup() { String processName = "testProcessName"; Set addons = singleton("testAddons"); String businessKey = "testBusinessKey"; + String createdBy = "initiatorUser"; + String updatedBy = "currentUser"; NodeInstance nodeInstance = new NodeInstance(); nodeInstance.setId(nodeInstanceId); @@ -118,6 +120,8 @@ void setup() { processInstance.setLastUpdate(time); processInstance.setBusinessKey(businessKey); processInstance.setMilestones(singletonList(milestone)); + processInstance.setCreatedBy(createdBy); + processInstance.setUpdatedBy(updatedBy); NodeInstanceEntity nodeInstanceEntity = new NodeInstanceEntity(); nodeInstanceEntity.setId(nodeInstanceId); @@ -160,6 +164,8 @@ void setup() { processInstanceEntity.setLastUpdate(time); processInstanceEntity.setBusinessKey(businessKey); processInstanceEntity.setMilestones(singletonList(milestoneEntity)); + processInstanceEntity.setCreatedBy(createdBy); + processInstanceEntity.setUpdatedBy(updatedBy); } @Test 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 5d5d097f24..e8b7eed338 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 @@ -38,6 +38,10 @@ message ProcessInstanceMeta { optional string businessKey = 13; /* @Field(store = Store.YES) */ optional string version = 14; + /* @Field(store = Store.YES) */ + optional string createdBy = 15; + /* @Field(store = Store.YES) */ + optional string updatedBy = 16; } /* @Indexed */ @@ -116,6 +120,10 @@ message ProcessInstance { repeated Milestone milestones = 18; /* @Field(store = Store.YES) */ optional string version = 19; + /* @Field(store = Store.YES) */ + optional string createdBy = 20; + /* @Field(store = Store.YES) */ + optional string updatedBy = 21; } /* @Indexed */ 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 678a732b40..95ee2eb5ba 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 @@ -94,7 +94,7 @@ public static String readFileContent(String file) throws IOException { } public static ProcessInstanceDataEvent getProcessCloudEvent(String processId, String processInstanceId, ProcessInstanceState status, String rootProcessInstanceId, String rootProcessId, - String parentProcessInstanceId) { + String parentProcessInstanceId, String identity) { ProcessInstanceEventBody body = ProcessInstanceEventBody.create() .id(processInstanceId) @@ -108,6 +108,7 @@ public static ProcessInstanceDataEvent getProcessCloudEvent(String processId, St .endDate(status == ProcessInstanceState.COMPLETED ? Date.from(Instant.now().plus(1, ChronoUnit.HOURS)) : null) .state(status.ordinal()) .businessKey(String.format("%s-key", processId)) + .identity(identity) .variables(getProcessInstanceVariablesMap()) .milestones(Set.of( MilestoneEventBody.create() @@ -131,7 +132,7 @@ public static ProcessInstanceDataEvent getProcessCloudEvent(String processId, St .build() : null) .build(); - return new ProcessInstanceDataEvent(URI.create("http://localhost:8080/" + processId).toString(), "jobs-management,prometheus-monitoring,process-management", null, body.metaData(), body); + return new ProcessInstanceDataEvent(URI.create("http://localhost:8080/" + processId).toString(), "jobs-management,prometheus-monitoring,process-management", identity, body.metaData(), body); } public static ProcessInstance getProcessInstance(String processId, String processInstanceId, Integer status, String rootProcessInstanceId, String rootProcessId) { @@ -154,6 +155,8 @@ public static ProcessInstance getProcessInstance(String processId, String proces } pi.setMilestones(getMilestones()); pi.setBusinessKey(String.format("%s-key", processId)); + pi.setCreatedBy("currentUser"); + pi.setUpdatedBy("currentUser"); return pi; } diff --git a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/test/java/org/kie/kogito/index/addon/DataIndexEventPublisherTest.java b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/test/java/org/kie/kogito/index/addon/DataIndexEventPublisherTest.java index 687e7a0d7a..bbe9867547 100644 --- a/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/test/java/org/kie/kogito/index/addon/DataIndexEventPublisherTest.java +++ b/data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/test/java/org/kie/kogito/index/addon/DataIndexEventPublisherTest.java @@ -72,7 +72,7 @@ public void setup() { void onProcessInstanceEvent() { ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(ProcessInstance.class); ProcessInstanceDataEvent event = getProcessCloudEvent(PROCESS_ID, PROCESS_INSTANCE_ID, COMPLETED, - ROOT_PROCESS_INSTANCE_ID, ROOT_PROCESS_ID, ROOT_PROCESS_INSTANCE_ID); + ROOT_PROCESS_INSTANCE_ID, ROOT_PROCESS_ID, ROOT_PROCESS_INSTANCE_ID, "currentUser"); dataIndexEventPublisher.publish(event);