Skip to content

Commit

Permalink
[KOGITO-9525] Add tag if description is null (#3101)
Browse files Browse the repository at this point in the history
* [KOGITO-9525] Add tag if description is null

* [KOGITO-9525] Adding tag import to springboot

Probably it wont work, but worth trying

* [KOGITO-9525] Disable tag aggregration for springboot

* [KOGITO-9525] Using codegen

Also failed

* Revert "[KOGITO-9525] Using codegen"

This reverts commit 8e4a392.

* Revert "[KOGITO-9525] Disable tag aggregration for springboot"

This reverts commit 5d3a9a9.

* Revert "[KOGITO-9525] Adding tag import to springboot"

This reverts commit 287c9e3.

* [KOGITO-9525] Dependency annotator approach

* [KOGITO-8525] Making plain Java test work
  • Loading branch information
fjtirado authored and web-flow committed Jul 6, 2023
1 parent c2f47d4 commit 6b9889d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.expr.ArrayInitializerExpr;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.MemberValuePair;
import com.github.javaparser.ast.expr.MethodCallExpr;
import com.github.javaparser.ast.expr.Name;
import com.github.javaparser.ast.expr.NameExpr;
Expand Down Expand Up @@ -259,4 +260,8 @@ default Expression getOptionalInstance(String fieldName) {
* @param node node to be annotated
*/
<T extends NodeWithAnnotations<?>> T withFactoryMethod(T node);

default <T extends NodeWithAnnotations<?>> T withTagAnnotation(T node, NodeList<MemberValuePair> attributes) {
return node;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,10 @@ public <T extends NodeWithAnnotations<?>> T withFactoryMethod(T node) {
node.addAnnotation("javax.enterprise.inject.Produces");
return node;
}

@Override
public <T extends NodeWithAnnotations<?>> T withTagAnnotation(T node, NodeList<MemberValuePair> attributes) {
node.addAnnotation(new NormalAnnotationExpr(new Name("org.eclipse.microprofile.openapi.annotations.tags.Tag"), attributes));
return node;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public String generate() {
template.findAll(StringLiteralExpr.class).forEach(this::interpolateStrings);
template.findAll(ClassOrInterfaceType.class).forEach(cls -> interpolateTypes(cls, typeInterpolations));

TagResourceGenerator.addTags(clazz, process);
TagResourceGenerator.addTags(clazz, process, context);

template.findAll(MethodDeclaration.class).forEach(this::interpolateMethods);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
import java.util.Set;

import org.jbpm.ruleflow.core.Metadata;
import org.kie.kogito.codegen.api.context.KogitoBuildContext;
import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.expr.MemberValuePair;
import com.github.javaparser.ast.expr.Name;
import com.github.javaparser.ast.expr.NormalAnnotationExpr;
import com.github.javaparser.ast.expr.StringLiteralExpr;

/**
Expand All @@ -44,30 +43,32 @@ private TagResourceGenerator() {
* @param compilationUnit the compilation unit to add the {@code org.eclipse.microprofile.openapi.annotations.tags.Tag} annotations to
* @param process the {@link KogitoWorkflowProcess} to get the tags from
*/
static void addTags(CompilationUnit compilationUnit, KogitoWorkflowProcess process) {
Map<String, Object> metadata = process.getMetaData();
@SuppressWarnings("unchecked")
Collection<String> tags = (Collection<String>) metadata.getOrDefault(Metadata.TAGS, Set.of());
String description = (String) metadata.get(Metadata.DESCRIPTION);
compilationUnit.findAll(ClassOrInterfaceDeclaration.class)
.forEach(cls -> addTags(process, tags, description, cls));
static void addTags(CompilationUnit compilationUnit, KogitoWorkflowProcess process, KogitoBuildContext context) {
if (context.hasDI()) {
Map<String, Object> metadata = process.getMetaData();
@SuppressWarnings("unchecked")
Collection<String> tags = (Collection<String>) metadata.getOrDefault(Metadata.TAGS, Set.of());
String description = (String) metadata.get(Metadata.DESCRIPTION);
compilationUnit.findAll(ClassOrInterfaceDeclaration.class)
.forEach(cls -> addTags(process, tags, description, cls, context));
}
}

private static void addTags(KogitoWorkflowProcess process, Collection<String> tags, String description, ClassOrInterfaceDeclaration cls) {
tags.forEach(tag -> addTag(cls, tag));
if (description != null) {
addDescription(process, description, cls);
}
private static void addTags(KogitoWorkflowProcess process, Collection<String> tags, String description, ClassOrInterfaceDeclaration cls, KogitoBuildContext context) {
tags.forEach(tag -> addTag(cls, tag, context));
addDescription(process, description, cls, context);
}

private static void addDescription(KogitoWorkflowProcess process, String description, ClassOrInterfaceDeclaration cls) {
private static void addDescription(KogitoWorkflowProcess process, String description, ClassOrInterfaceDeclaration cls, KogitoBuildContext context) {
NodeList<MemberValuePair> attributes = attributes(process.getId());
attributes.add(new MemberValuePair("description", new StringLiteralExpr(description)));
cls.addAnnotation(new NormalAnnotationExpr(new Name("Tag"), attributes));
if (description != null) {
attributes.add(new MemberValuePair("description", new StringLiteralExpr(description)));
}
context.getDependencyInjectionAnnotator().withTagAnnotation(cls, attributes);
}

private static void addTag(ClassOrInterfaceDeclaration cls, String tag) {
cls.addAnnotation(new NormalAnnotationExpr(new Name("Tag"), attributes(tag)));
private static void addTag(ClassOrInterfaceDeclaration cls, String tag, KogitoBuildContext context) {
context.getDependencyInjectionAnnotator().withTagAnnotation(cls, attributes(tag));
}

private static NodeList<MemberValuePair> attributes(String tag) {
Expand Down

0 comments on commit 6b9889d

Please sign in to comment.