Skip to content

Commit

Permalink
adding annotation, description, to the process definition event
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagodolphine committed Oct 19, 2023
1 parent 1e55fc3 commit cbde742
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,40 @@
*/
package org.kie.kogito.event.process;

import java.util.List;
import java.util.Collection;
import java.util.Map;
import java.util.Set;

public class ProcessDefinitionEventBody {

private String id;
private String name;
private String description;
private String version;
private String type;
private Set<String> roles;
private Set<String> addons;
private Set<String> annotations;
private String endpoint;
private String source;
private List<NodeDefinition> nodes;
private Map<String, ?> metadata;
private Collection<NodeDefinition> nodes;

public ProcessDefinitionEventBody() {
}

public ProcessDefinitionEventBody(String id, String name, String version, String type, Set<String> roles, Set<String> addons, String endpoint, String source, List<NodeDefinition> nodes) {
public ProcessDefinitionEventBody(String id, String name, String description, String version, String type, Set<String> roles, Set<String> addons, Set<String> annotations, String endpoint,
String source, Map<String, ?> metadata, Collection<NodeDefinition> nodes) {
this.id = id;
this.name = name;
this.description = description;
this.version = version;
this.type = type;
this.roles = roles;
this.addons = addons;
this.annotations = annotations;
this.endpoint = endpoint;
this.source = source;
this.metadata = metadata;
this.nodes = nodes;
}

Expand Down Expand Up @@ -80,24 +87,39 @@ public String getSource() {
return source;
}

public List<NodeDefinition> getNodes() {
public Collection<NodeDefinition> getNodes() {
return nodes;
}

public String getDescription() {
return description;
}

public Set<String> getAnnotations() {
return annotations;
}

public Map<String, ?> getMetadata() {
return metadata;
}

public static ProcessDefinitionEventBodyBuilder builder() {
return new ProcessDefinitionEventBodyBuilder();
}

public static class ProcessDefinitionEventBodyBuilder {
private String id;
private String name;
private String description;
private String version;
private String type;
private Set<String> roles;
private Set<String> addons;
private Set<String> annotations;
private String endpoint;
private String source;
private List<NodeDefinition> nodes;
private Map<String, ?> metadata;
private Collection<NodeDefinition> nodes;

public ProcessDefinitionEventBodyBuilder setId(String id) {
this.id = id;
Expand Down Expand Up @@ -139,13 +161,28 @@ public ProcessDefinitionEventBodyBuilder setSource(String source) {
return this;
}

public ProcessDefinitionEventBodyBuilder setNodes(List<NodeDefinition> nodes) {
public ProcessDefinitionEventBodyBuilder setDescription(String description) {
this.description = description;
return this;
}

public ProcessDefinitionEventBodyBuilder setAnnotations(Set<String> annotations) {
this.annotations = annotations;
return this;
}

public ProcessDefinitionEventBodyBuilder setMetadata(Map<String, ?> metadata) {
this.metadata = metadata;
return this;
}

public ProcessDefinitionEventBodyBuilder setNodes(Collection<NodeDefinition> nodes) {
this.nodes = nodes;
return this;
}

public ProcessDefinitionEventBody build() {
return new ProcessDefinitionEventBody(id, name, version, type, roles, addons, endpoint, source, nodes);
return new ProcessDefinitionEventBody(id, name, description, version, type, roles, addons, annotations, endpoint, source, metadata, nodes);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
*/
package org.kie.kogito.services.registry;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.kie.kogito.Application;
Expand All @@ -35,6 +38,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toSet;

public class ProcessDefinitionEventRegistry {

private static final Logger LOGGER = LoggerFactory.getLogger(ProcessDefinitionEventRegistry.class);
Expand All @@ -61,16 +67,31 @@ public void register(Processes processes) {
}

private Function<Process<?>, ProcessDefinitionDataEvent> mapProcessDefinition(Set<String> addons, String endpoint) {
return p -> new ProcessDefinitionDataEvent(ProcessDefinitionEventBody.builder()
.setId(p.id())
.setName(p.name())
.setVersion(p.version())
.setType(ProcessDefinitionDataEvent.PROCESS_DEFINITION_EVENT)
.setAddons(addons)
.setEndpoint(getEndpoint(endpoint, p))
.setSource(getProcessSource())
.setNodes(getNodesDefinitions(p))
.build());

return p -> {
Map<String, Object> metadata = Collections.emptyMap();
if (p instanceof Supplier) {
org.kie.api.definition.process.Process processDefinition = ((Supplier<org.kie.api.definition.process.Process>) p).get();
if (processDefinition != null) {
metadata = processDefinition.getMetaData();
}
}
Set<String> annotations = ((List<String>) metadata.getOrDefault("annotations", emptyList())).stream().collect(toSet());
String description = (String) metadata.get("Description");
ProcessDefinitionDataEvent definitionDataEvent = new ProcessDefinitionDataEvent(ProcessDefinitionEventBody.builder()
.setId(p.id())
.setName(p.name())
.setVersion(p.version())
.setType(ProcessDefinitionDataEvent.PROCESS_DEFINITION_EVENT)
.setAddons(addons)
.setEndpoint(getEndpoint(endpoint, p))
.setNodes(getNodesDefinitions(p))
.setAnnotations(annotations)
.setDescription(description)
.setMetadata(metadata)
.build());
return definitionDataEvent;
};
}

private static String getEndpoint(String endpoint, Process<?> p) {
Expand All @@ -90,8 +111,4 @@ private List<NodeDefinition> getNodesDefinitions(Process<?> p) {
.build())
.collect(Collectors.toList());
}

private String getProcessSource() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import javax.inject.Inject;
import javax.inject.Singleton;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.smallrye.reactive.messaging.providers.locals.ContextAwareMessage;
import org.eclipse.microprofile.reactive.messaging.Channel;
import org.eclipse.microprofile.reactive.messaging.Emitter;
import org.eclipse.microprofile.reactive.messaging.Message;
Expand All @@ -39,6 +37,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.databind.ObjectMapper;

import io.smallrye.reactive.messaging.providers.locals.ContextAwareMessage;

@Singleton
public class ReactiveMessagingEventPublisher implements EventPublisher {

Expand Down

0 comments on commit cbde742

Please sign in to comment.