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

[1.40.x-prod] [KOGITO-9525] Add tag if description is null #3108

Merged
merged 1 commit into from
Jul 11, 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 @@ -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