Skip to content

Commit

Permalink
KOGITO-9662 - Index node metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianonicolai committed Aug 31, 2023
1 parent 0d221d7 commit 62716a9
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
Expand Down Expand Up @@ -107,7 +108,7 @@ public void testProcessInstanceEvents() throws IOException {
.get("/approvals/{processId}/tasks")
.then()
.statusCode(200)
.body("$.size", is(1))
.body("$.size()", is(1))
.body("[0].name", is("firstLineApproval"))
.body("[0].id", notNullValue())
.extract()
Expand Down Expand Up @@ -189,7 +190,7 @@ public void testProcessInstanceEvents() throws IOException {
.get("/approvals/{processId}/tasks")
.then()
.statusCode(200)
.body("$.size", is(1))
.body("$.size()", is(1))
.body("[0].name", is("secondLineApproval"))
.body("[0].id", notNullValue())
.extract()
Expand Down Expand Up @@ -279,13 +280,21 @@ public void testProcessGatewayAPI() throws IOException {
await()
.atMost(TIMEOUT)
.untilAsserted(() -> given().spec(dataIndexSpec()).contentType(ContentType.JSON)
.body("{ \"query\" : \"{ ProcessInstances (where: { id: {equal: \\\"" + pId2 + "\\\"}}) { nodeDefinitions {id} nodes {id}} }\"}")
.body("{ \"query\" : \"{ ProcessInstances (where: { id: {equal: \\\"" + pId2
+ "\\\"}}) { nodeDefinitions { id, name, type, uniqueId, metadata { UniqueId } } nodes { name, definitionId }} }\"}")
.when().post("/graphql")
.then()
.statusCode(200)
.body("data.ProcessInstances[0].nodeDefinitions", notNullValue())
.body("data.ProcessInstances[0].nodeDefinitions.size()", is(4))
.body("data.ProcessInstances[0].nodes.size()", is(2)));
.body("data.ProcessInstances[0].nodeDefinitions[0].id", is("1"))
.body("data.ProcessInstances[0].nodeDefinitions[0].name", is("First Line Approval"))
.body("data.ProcessInstances[0].nodeDefinitions[0].type", is("HumanTaskNode"))
.body("data.ProcessInstances[0].nodeDefinitions[0].uniqueId", is("1"))
.body("data.ProcessInstances[0].nodeDefinitions[0].metadata.UniqueId", is("_8B62D3CA-5D03-4B2B-832B-126469288BB4"))
.body("data.ProcessInstances[0].nodes.size()", is(2))
.body("data.ProcessInstances[0].nodes.name", hasItem("First Line Approval"))
.body("data.ProcessInstances[0].nodes.definitionId", hasItem("_8B62D3CA-5D03-4B2B-832B-126469288BB4")));

final String taskId = given().spec(dataIndexSpec()).contentType(ContentType.JSON)
.body("{ \"query\" : \"{ UserTaskInstances (where: { processInstanceId: {equal: \\\"" + pId2 + "\\\"}}) { id description potentialGroups } }\"}")
Expand Down Expand Up @@ -447,7 +456,7 @@ public void testProcessGatewayAPIComments(String taskId, String processInstanceI
.get("/approvals/{id}/firstLineApproval/{taskId}/comments")
.then()
.statusCode(200)
.body("$.size", is(1))
.body("$.size()", is(1))
.body("[0].content", is(commentContent)));

Map<String, String> commentMap = given().spec(dataIndexSpec()).contentType(ContentType.JSON)
Expand Down Expand Up @@ -545,7 +554,7 @@ public void testProcessGatewayAPIAttachments(String taskId, String processInstan
.get("/approvals/{id}/firstLineApproval/{taskId}/attachments")
.then()
.statusCode(200)
.body("$.size", is(1))
.body("$.size()", is(1))
.body("[0].name", is(attachmentName)));

Map<String, String> attachmentMap = given().spec(dataIndexSpec()).contentType(ContentType.JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,19 @@ enum ProcessInstanceState {

type Node {
id: String!
nodeDefinitionId: String!
metadata: NodeMetadata!
name: String!
type: String!
uniqueId: String!
}

type NodeMetadata {
UniqueId: String!
state: String
branch: String
action: String
}

type NodeInstance {
id: String!
name: String!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.kie.kogito.index.model;

import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;

public class Node {
Expand All @@ -26,8 +28,7 @@ public class Node {
private String type;
@JsonProperty("uniqueId")
private String nodeId;
@JsonProperty("nodeDefinitionId")
private String definitionId;
private Map<String, Object> metadata;

public String getId() {
return id;
Expand Down Expand Up @@ -61,12 +62,12 @@ public void setNodeId(String nodeId) {
this.nodeId = nodeId;
}

public String getDefinitionId() {
return definitionId;
public Map<String, Object> getMetadata() {
return metadata;
}

public void setDefinitionId(String definitionId) {
this.definitionId = definitionId;
public void setMetadata(Map<String, Object> metadata) {
this.metadata = metadata;
}

@Override
Expand All @@ -90,12 +91,12 @@ public int hashCode() {

@Override
public String toString() {
return "Node {" +
return "Node{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", nodeId='" + nodeId + '\'' +
", type='" + type + '\'' +
", definitionId='" + definitionId + '\'' +
", nodeId='" + nodeId + '\'' +
", metadata=" + metadata +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,25 @@

import com.fasterxml.jackson.annotation.JsonProperty;

public class NodeInstance extends Node {
public class NodeInstance {

private String id;
private String nodeId;

@JsonProperty("nodeName")
private String name;

@JsonProperty("nodeType")
private String type;

@JsonProperty("triggerTime")
private ZonedDateTime enter;
@JsonProperty("leaveTime")
private ZonedDateTime exit;

@JsonProperty("nodeDefinitionId")
private String definitionId;

public String getId() {
return id;
}
Expand Down Expand Up @@ -61,6 +70,30 @@ public void setNodeId(String nodeId) {
this.nodeId = nodeId;
}

public String getDefinitionId() {
return definitionId;
}

public void setDefinitionId(String definitionId) {
this.definitionId = definitionId;
}

public String getType() {
return type;
}

public String getName() {
return name;
}

public void setType(String type) {
this.type = type;
}

public void setName(String name) {
this.name = name;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -84,12 +117,12 @@ public int hashCode() {
public String toString() {
return "NodeInstance{" +
"id='" + id + '\'' +
", name='" + getName() + '\'' +
", name='" + name + '\'' +
", nodeId='" + nodeId + '\'' +
", type='" + getType() + '\'' +
", type='" + type + '\'' +
", enter=" + enter +
", exit=" + exit +
", definitionId='" + getDefinitionId() + '\'' +
", definitionId='" + definitionId + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
import org.kie.kogito.process.impl.AbstractProcess;
import org.kie.kogito.svg.ProcessSvgService;

import static org.jbpm.ruleflow.core.Metadata.UNIQUE_ID;

@ApplicationScoped
public class KogitoAddonRuntimeClientImpl implements KogitoRuntimeClient {

Expand Down Expand Up @@ -122,7 +120,7 @@ public CompletableFuture<List<Node>> getProcessInstanceNodeDefinitions(String se
Node data = new Node();
data.setId(String.valueOf(n.getId()));
data.setNodeId(((org.jbpm.workflow.core.Node) n).getUniqueId());
data.setDefinitionId((String) n.getMetaData().get(UNIQUE_ID));
data.setMetadata(n.getMetaData());
data.setType(n.getClass().getSimpleName());
data.setName(n.getName());
return data;
Expand Down

0 comments on commit 62716a9

Please sign in to comment.