Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KOGITO-9673] Adding SWF annotations to process metadata #3200

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ public T doGetProcessInfo(String processId) {
data.put("version", process.version());
if (process instanceof Supplier) {
org.kie.api.definition.process.Process processDefinition = ((Supplier<org.kie.api.definition.process.Process>) process).get();
data.put("description", processDefinition.getMetaData().get(Metadata.DESCRIPTION));
Map<String, Object> metadata = processDefinition.getMetaData();
String description = (String) metadata.get(Metadata.DESCRIPTION);
if (description != null) {
data.put("description", description);
}
List<String> annotations = (List<String>) metadata.get(Metadata.ANNOTATIONS);
if (annotations != null) {
data.put("annotations", annotations);
}
if (processDefinition instanceof WorkflowProcess) {
WorkflowProcess workflowProcess = (WorkflowProcess) processDefinition;
workflowProcess.getInputValidator().flatMap(v -> v.schema(JsonNode.class)).ifPresent(s -> data.put("inputSchema", s));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void setUp() {
lenient().when(process.version()).thenReturn("1_0");
lenient().when(process.type()).thenReturn("BPMN");

lenient().when(workflowProcess.getMetaData()).thenReturn(Map.of(Metadata.DESCRIPTION, "cool"));
lenient().when(workflowProcess.getMetaData()).thenReturn(Map.of(Metadata.DESCRIPTION, "cool", Metadata.ANNOTATIONS, Arrays.asList("good")));
lenient().when(workflowValidator.schema(JsonNode.class)).thenReturn(Optional.of(NullNode.instance));
lenient().when(workflowProcess.getInputValidator()).thenReturn(Optional.of(workflowValidator));
lenient().when(workflowProcess.getOutputValidator()).thenReturn(Optional.empty());
Expand Down Expand Up @@ -210,7 +210,8 @@ void testDoGetProcessInfo() {
Object response = tested.doGetProcessInfo(PROCESS_ID);
assertThat(response).isInstanceOf(Map.class);
Map<String, Object> data = (Map<String, Object>) response;
assertThat(data).containsKey("type").containsKey("id").containsKey("version").containsKey("description").containsEntry("inputSchema", NullNode.instance).containsKey("name")
assertThat(data).containsKey("type").containsKey("id").containsKey("version").containsKey("description").containsKey("annotations").containsEntry("inputSchema", NullNode.instance)
.containsKey("name")
.doesNotContainKey("outputSchema");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Metadata {

public static final String ASSOCIATION = "association";
public static final String ACTION = "Action";
public static final String ANNOTATIONS = "annotations";
public static final String TRIGGER_REF = "TriggerRef";
public static final String REF = "Ref";
public static final String MESSAGE_TYPE = "MessageType";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.net.URL;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -128,7 +129,6 @@ private GeneratedInfo<KogitoWorkflowProcess> parseProcess() {
.type(KogitoWorkflowProcess.SW_TYPE);
ParserContext parserContext =
new ParserContext(idGenerator, factory, context, WorkflowOperationIdFactoryProvider.getFactory(context.getApplicationProperty(WorkflowOperationIdFactoryProvider.PROPERTY_NAME)));

modelValidator(parserContext, Optional.ofNullable(workflow.getDataInputSchema())).ifPresent(factory::inputValidator);
modelValidator(parserContext, ServerlessWorkflowUtils.getExtension(workflow, OutputSchema.class).map(OutputSchema::getOutputSchema)).ifPresent(factory::outputValidator);
loadConstants(factory, parserContext);
Expand All @@ -144,7 +144,6 @@ private GeneratedInfo<KogitoWorkflowProcess> parseProcess() {
factory.metaData(Metadata.COMPENSATION, true);
factory.addCompensationContext(workflow.getId());
}

TimeoutsDefinition timeouts = workflow.getTimeouts();
if (timeouts != null) {
WorkflowExecTimeout workflowTimeout = timeouts.getWorkflowExecTimeout();
Expand All @@ -161,6 +160,11 @@ private GeneratedInfo<KogitoWorkflowProcess> parseProcess() {
if (!ConversionUtils.isEmpty(description)) {
factory.metaData(Metadata.DESCRIPTION, description);
}
List<String> annotations = workflow.getAnnotations();
if (!annotations.isEmpty()) {
factory.metaData(Metadata.ANNOTATIONS, annotations);
}

return new GeneratedInfo<>(factory.validate().getProcess(), parserContext.generatedFiles());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0",
"name": "Welcome to the Parallel dimension",
"description": "Testing parallelism",
"annotations": ["Football", "Betis"],
"start": "Parallel",
"functions": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.kie.kogito.quarkus.workflows;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand All @@ -27,16 +28,23 @@

import static io.restassured.RestAssured.given;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.is;

@QuarkusIntegrationTest
class ManagementFlowIT {

@Test
void testManagementAPI() {
void testManagementAPINodes() {
assertThat(given().contentType(ContentType.JSON).accept(ContentType.JSON).get("management/processes/parallel/nodes")
.then().statusCode(200).extract().as(new TypeRef<List<Map<String, Object>>>() {
}).stream().map(m -> (Map<String, Object>) m.get("metadata")).filter(m -> m.containsKey(SWFConstants.STATE_NAME) && m.containsKey(SWFConstants.ACTION_NAME)
&& m.containsKey(SWFConstants.BRANCH_NAME))
.count()).isGreaterThanOrEqualTo(3);
}

@Test
void testManagementAPIProcess() {
given().contentType(ContentType.JSON).accept(ContentType.JSON).get("management/processes/parallel")
.then().statusCode(200).body("annotations", is(Arrays.asList("Football", "Betis")));
}
}
Loading