Skip to content

Commit

Permalink
KOGITO-8940: Creator/owner field at process
Browse files Browse the repository at this point in the history
  • Loading branch information
nmirasch committed Aug 9, 2023
1 parent 758d864 commit 094c9d8
Show file tree
Hide file tree
Showing 32 changed files with 133 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ 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.setIdentity(event.getData().getIdentity());
return pi;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ private ObjectNode getProcessJson(ProcessInstanceDataEvent event) {
if (!isNullOrEmpty(event.getData().getBusinessKey())) {
json.put("businessKey", event.getData().getBusinessKey());
}
if (!isNullOrEmpty(event.getData().getIdentity())) {
json.put("identity", event.getData().getIdentity());
}
return json;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type ProcessInstance {
nodeDefinitions: [Node!]
diagram: String
source: String
identity: String
}

type ProcessInstanceError {
Expand Down Expand Up @@ -93,6 +94,7 @@ input ProcessInstanceOrderBy {
error: ProcessInstanceErrorOrderBy
lastUpdate: OrderBy
businessKey: OrderBy
identity: OrderBy
}

input ProcessInstanceErrorOrderBy {
Expand Down Expand Up @@ -121,6 +123,7 @@ input ProcessInstanceArgument {
addons: StringArrayArgument
lastUpdate: DateArgument
businessKey: StringArgument
identity: StringArgument
}

input ProcessInstanceErrorArgument {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,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)
Expand All @@ -109,6 +109,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(RandomStringUtils.randomAlphabetic(10))
.identity(identity)
.variables(getProcessInstanceVariablesMap())
.milestones(Set.of(
MilestoneEventBody.create()
Expand All @@ -132,7 +133,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) {
Expand All @@ -154,6 +155,7 @@ public static ProcessInstance getProcessInstance(String processId, String proces
}
pi.setMilestones(getMilestones());
pi.setBusinessKey(RandomStringUtils.randomAlphabetic(10));
pi.setIdentity("currentUser");
return pi;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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].identity").isEqualTo(event.getData().getIdentity().toString()),
a -> a.node(piPrefix + "[0].lastUpdate").isEqualTo(event.getTime().toInstant().toEpochMilli()));
}

Expand All @@ -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();
Expand All @@ -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].identity").isEqualTo(event.getData().getIdentity().toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type ProcessInstanceMeta {
end: DateTime
lastUpdate: DateTime!
businessKey: String
identity: String
}

input ProcessInstanceMetaArgument {
Expand All @@ -70,6 +71,7 @@ input ProcessInstanceMetaArgument {
start: DateArgument
end: DateArgument
businessKey: StringArgument
identity: StringArgument
}

extend type UserTaskInstance {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,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);
Expand Down Expand Up @@ -203,7 +203,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<String, Object> travellerMap = new HashMap<>();
travellerMap.put("firstName", "Maciej");
travellerMap.put("email", "[email protected]");
Expand Down Expand Up @@ -269,7 +269,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);
Expand Down Expand Up @@ -418,7 +418,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)
Expand Down Expand Up @@ -464,7 +464,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)
Expand Down Expand Up @@ -533,7 +533,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(
Expand Down Expand Up @@ -583,7 +583,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);
Expand Down Expand Up @@ -611,7 +611,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<String, Object> variablesMap = getProcessInstanceVariablesMap();
((Map<String, Object>) variablesMap.get("hotel")).put("name", "Ibis");
Expand Down Expand Up @@ -645,13 +645,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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,7 @@
import static org.kie.kogito.index.model.ProcessInstanceState.ACTIVE;
import static org.kie.kogito.index.model.ProcessInstanceState.COMPLETED;
import static org.kie.kogito.index.model.ProcessInstanceState.ERROR;
import static org.kie.kogito.index.service.GraphQLUtils.getJobById;
import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceByBusinessKey;
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;
import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceByIdAndMilestoneName;
import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceByIdAndMilestoneStatus;
import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceByIdAndNullParentProcessInstanceId;
import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceByIdAndNullRootProcessInstanceId;
import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceByIdAndParentProcessInstanceId;
import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceByIdAndProcessId;
import static org.kie.kogito.index.service.GraphQLUtils.getProcessInstanceByIdAndStart;
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.getUserTaskInstanceById;
import static org.kie.kogito.index.service.GraphQLUtils.getUserTaskInstanceByIdAndActualOwner;
import static org.kie.kogito.index.service.GraphQLUtils.getUserTaskInstanceByIdAndCompleted;
import static org.kie.kogito.index.service.GraphQLUtils.getUserTaskInstanceByIdAndPotentialGroups;
import static org.kie.kogito.index.service.GraphQLUtils.getUserTaskInstanceByIdAndPotentialUsers;
import static org.kie.kogito.index.service.GraphQLUtils.getUserTaskInstanceByIdAndProcessId;
import static org.kie.kogito.index.service.GraphQLUtils.getUserTaskInstanceByIdAndStarted;
import static org.kie.kogito.index.service.GraphQLUtils.getUserTaskInstanceByIdAndState;
import static org.kie.kogito.index.service.GraphQLUtils.getUserTaskInstanceByIdNoActualOwner;
import static org.kie.kogito.index.service.GraphQLUtils.*;

public abstract class AbstractIndexingServiceIT extends AbstractIndexingIT {

Expand Down Expand Up @@ -176,7 +153,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()
Expand Down Expand Up @@ -269,7 +246,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);

validateProcessInstance(getProcessInstanceById(processInstanceId), startEvent);
Expand All @@ -283,8 +260,9 @@ void testProcessInstanceIndex() throws Exception {
validateProcessInstance(getProcessInstanceByIdAndMilestoneStatus(processInstanceId, MilestoneStatus.AVAILABLE.name()),
startEvent);
validateProcessInstance(getProcessInstanceByBusinessKey(startEvent.getData().getBusinessKey()), startEvent);
validateProcessInstance(getProcessInstanceByIdentity(startEvent.getKogitoIdentity()), 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<String, Object> variablesMap = getProcessInstanceVariablesMap();
((Map<String, Object>) variablesMap.get("hotel")).put("name", "Ibis");
Expand All @@ -297,7 +275,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);
Expand All @@ -311,7 +289,7 @@ void testProcessInstanceIndex() throws Exception {
event);

ProcessInstanceDataEvent errorEvent = getProcessCloudEvent(subProcessId, subProcessInstanceId, ERROR, processInstanceId,
processId, processInstanceId);
processId, processInstanceId, "currentUser");
indexProcessCloudEvent(errorEvent);

validateProcessInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public static String getProcessInstanceByBusinessKey(String businessKeys) {
return getProcessInstanceQuery("ProcessInstanceByBusinessKey", businessKeys);
}

public static String getProcessInstanceByIdentity(String identity) {
return getProcessInstanceQuery("ProcessInstanceByIdentity", identity);
}

public static String getUserTaskInstanceById(String id) {
return getUserTaskInstanceQuery("UserTaskInstanceById", id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,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);
Expand All @@ -167,7 +167,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);
Expand Down
Loading

0 comments on commit 094c9d8

Please sign in to comment.