Skip to content

Commit

Permalink
[KOGITO-9886] Add the support for the ProcessDefinitionDataEvent at r…
Browse files Browse the repository at this point in the history
…untime (apache#3252)

* KOGITO-9886 Add the support for the ProcessDefinitionDataEvent at runtime
  • Loading branch information
tiagodolphine authored and fjtirado committed Jan 10, 2024
1 parent ec581f7 commit 70f2665
Show file tree
Hide file tree
Showing 27 changed files with 792 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
*/
public interface EventPublisher {

String PROCESS_INSTANCES_TOPIC_NAME = "kogito-processinstances-events";
String USER_TASK_INSTANCES_TOPIC_NAME = "kogito-usertaskinstances-events";
String PROCESS_DEFINITIONS_TOPIC_NAME = "kogito-processdefinitions-events";

/**
* Publishes individual event
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@
public interface KogitoNode extends Node {

NodeContainer getParentContainer();

String getUniqueId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,17 @@ public static String sanitizeJavaName(String name, boolean capitalize) {
}
return sb.toString();
}

/**
* Receives a String possibly with FQDN org.acme.ProcessTest1 and returns a simple name like ProcessTest1
*
* @param processId a possible FQDN
* @return simple name
*/
public static String sanitizeToSimpleName(String processId) {
if (Objects.isNull(processId)) {
return null;
}
return processId.substring(processId.lastIndexOf('.') + 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.kie.kogito.internal.utils.ConversionUtils.concatPaths;
import static org.kie.kogito.internal.utils.ConversionUtils.convert;
import static org.kie.kogito.internal.utils.ConversionUtils.convertToCollection;
import static org.kie.kogito.internal.utils.ConversionUtils.sanitizeToSimpleName;
import static org.kie.kogito.internal.utils.ConversionUtils.toCamelCase;

class ConversionUtilsTest {
Expand Down Expand Up @@ -138,4 +139,15 @@ public void testConcatPaths() {
public void testConvertToCollection() {
assertThat(convertToCollection("1,2,3", Integer.class)).isEqualTo(Arrays.asList(1, 2, 3));
}

@Test
public void testSanitizeToSimpleName() {
String nameFull = "org.acme.ProcessTest1";
String nameSimple = "ProcessTest2";
String nameEmpty = "";
assertThat(sanitizeToSimpleName(nameFull)).isEqualTo("ProcessTest1");
assertThat(sanitizeToSimpleName(nameSimple)).isEqualTo("ProcessTest2");
assertThat(sanitizeToSimpleName(nameEmpty)).isEqualTo("");
assertThat(sanitizeToSimpleName(null)).isNull();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.kie.kogito.event.process;

import java.util.Map;

public class NodeDefinition {
private String id;
private String name;
private String type;
private String uniqueId;
private Map<String, ?> metadata;

public NodeDefinition() {
}

public NodeDefinition(String id, String name, String type, String uniqueId, Map<String, ?> metadata) {
this.id = id;
this.name = name;
this.type = type;
this.uniqueId = uniqueId;
this.metadata = metadata;
}

public String getId() {
return id;
}

public String getName() {
return name;
}

public String getType() {
return type;
}

public String getUniqueId() {
return uniqueId;
}

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

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

public static class NodeDefinitionEventBodyBuilder {
private String id;
private String name;
private String type;
private String uniqueId;
private Map<String, ?> metadata;

public NodeDefinitionEventBodyBuilder setId(String id) {
this.id = id;
return this;
}

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

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

public NodeDefinitionEventBodyBuilder setUniqueId(String uniqueId) {
this.uniqueId = uniqueId;
return this;
}

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

public NodeDefinition build() {
return new NodeDefinition(id, name, type, uniqueId, metadata);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.kie.kogito.event.process;

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 Map<String, ?> metadata;
private Collection<NodeDefinition> nodes;

public ProcessDefinitionEventBody() {
}

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;
}

public String getId() {
return id;
}

public String getName() {
return name;
}

public String getVersion() {
return version;
}

public String getType() {
return type;
}

public Set<String> getRoles() {
return roles;
}

public Set<String> getAddons() {
return addons;
}

public String getEndpoint() {
return endpoint;
}

public String getSource() {
return source;
}

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 Map<String, ?> metadata;
private Collection<NodeDefinition> nodes;

public ProcessDefinitionEventBodyBuilder setId(String id) {
this.id = id;
return this;
}

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

public ProcessDefinitionEventBodyBuilder setVersion(String version) {
this.version = version;
return this;
}

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

public ProcessDefinitionEventBodyBuilder setRoles(Set<String> roles) {
this.roles = roles;
return this;
}

public ProcessDefinitionEventBodyBuilder setAddons(Set<String> addons) {
this.addons = addons;
return this;
}

public ProcessDefinitionEventBodyBuilder setEndpoint(String endpoint) {
this.endpoint = endpoint;
return this;
}

public ProcessDefinitionEventBodyBuilder setSource(String source) {
this.source = source;
return this;
}

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, description, version, type, roles, addons, annotations, endpoint, source, metadata, nodes);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@
import io.cloudevents.core.v03.CloudEventV03;
import io.cloudevents.core.v1.CloudEventV1;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;

/**
* This is an implementation of the {@link DataEvent} that contains basic common attributes referring to
* kogito processes metadata.
*
* @param <T> the payload class type
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(NON_NULL)
public abstract class AbstractDataEvent<T> implements DataEvent<T> {

/**
Expand Down
Loading

0 comments on commit 70f2665

Please sign in to comment.