You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2024/03/14 18:49:02 UTC

(camel) 02/10: CAMEL-17641: Generate json metadata for pojo beans in camel-core that end users can use such as AggregationStrategy implementations. And have that information in camel-catalog for tooling assistance.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch pojo-beans
in repository https://gitbox.apache.org/repos/asf/camel.git

commit cbae0027cb3630dbe4e84f220f7758062134e67a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Mar 14 15:37:05 2024 +0100

    CAMEL-17641: Generate json metadata for pojo beans in camel-core that end users can use such as AggregationStrategy implementations. And have that information in camel-catalog for tooling assistance.
---
 .../camel/bean/UseLatestAggregationStrategy.json   | 15 +++++++++++
 .../services/org/apache/camel/beans.properties     |  7 +++++
 .../aggregate/UseLatestAggregationStrategy.java    | 12 ++++-----
 .../maven/packaging/GeneratePojoBeanMojo.java      | 30 ++++++++++++++--------
 4 files changed, 47 insertions(+), 17 deletions(-)

diff --git a/core/camel-core-processor/src/generated/resources/META-INF/services/org/apache/camel/bean/UseLatestAggregationStrategy.json b/core/camel-core-processor/src/generated/resources/META-INF/services/org/apache/camel/bean/UseLatestAggregationStrategy.json
new file mode 100644
index 00000000000..5d73c66d791
--- /dev/null
+++ b/core/camel-core-processor/src/generated/resources/META-INF/services/org/apache/camel/bean/UseLatestAggregationStrategy.json
@@ -0,0 +1,15 @@
+{
+  "bean": {
+    "kind": "bean",
+    "name": "UseLatestAggregationStrategy",
+    "javaType": "org.apache.camel.processor.aggregate.UseLatestAggregationStrategy",
+    "interfaceType": "org.apache.camel.AggregationStrategy",
+    "title": "Use Latest Aggregation Strategy",
+    "description": "An AggregationStrategy which just uses the latest exchange which is useful for status messages where old status messages have no real value. Another example is things like market data prices, where old stock prices are not that relevant, only the current price is.",
+    "deprecated": false,
+    "groupId": "org.apache.camel",
+    "artifactId": "camel-core-processor",
+    "version": "4.5.0-SNAPSHOT"
+  }
+}
+
diff --git a/core/camel-core-processor/src/generated/resources/META-INF/services/org/apache/camel/beans.properties b/core/camel-core-processor/src/generated/resources/META-INF/services/org/apache/camel/beans.properties
new file mode 100644
index 00000000000..a4277ba5e66
--- /dev/null
+++ b/core/camel-core-processor/src/generated/resources/META-INF/services/org/apache/camel/beans.properties
@@ -0,0 +1,7 @@
+# Generated by camel build tools - do NOT edit this file!
+beans=org.apache.camel.processor.aggregate.UseLatestAggregationStrategy
+groupId=org.apache.camel
+artifactId=camel-core-processor
+version=4.5.0-SNAPSHOT
+projectName=Camel :: Core Processor
+projectDescription=Camel core processors
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/UseLatestAggregationStrategy.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/UseLatestAggregationStrategy.java
index eb48f844d81..0b94b2b7441 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/UseLatestAggregationStrategy.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/UseLatestAggregationStrategy.java
@@ -26,10 +26,10 @@ import org.apache.camel.spi.Metadata;
  * status messages have no real value. Another example is things like market data prices, where old stock prices are not
  * that relevant, only the current price is.
  */
-@Metadata(label = "bean",
-        description = "An AggregationStrategy which just uses the latest exchange which is useful for status messages where old"
-                      + " status messages have no real value. Another example is things like market data prices, where old stock prices are not"
-                      + " that relevant, only the current price is.")
+@Metadata(label = "bean", title = "Use Latest",
+          description = "An AggregationStrategy which just uses the latest exchange which is useful for status messages where old"
+                        + " status messages have no real value. Another example is things like market data prices, where old stock prices are not"
+                        + " that relevant, only the current price is.")
 public class UseLatestAggregationStrategy implements AggregationStrategy {
 
     @Override
@@ -77,8 +77,8 @@ public class UseLatestAggregationStrategy implements AggregationStrategy {
 
         // propagate exception from old exchange if there isn't already an exception
         if (oldExchange.isFailed() || oldExchange.isRollbackOnly() || oldExchange.isRollbackOnlyLast()
-            || oldExchange.getExchangeExtension().isErrorHandlerHandledSet()
-               && oldExchange.getExchangeExtension().isErrorHandlerHandled()) {
+                || oldExchange.getExchangeExtension().isErrorHandlerHandledSet()
+                        && oldExchange.getExchangeExtension().isErrorHandlerHandled()) {
             // propagate failure by using old exchange as the answer
             return oldExchange;
         }
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/GeneratePojoBeanMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/GeneratePojoBeanMojo.java
index 31fc4fc4ca3..879fe0df8a7 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/GeneratePojoBeanMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/GeneratePojoBeanMojo.java
@@ -61,6 +61,7 @@ public class GeneratePojoBeanMojo extends AbstractGeneratorMojo {
 
     private static class BeanPojoModel {
         private String name;
+        private String title;
         private String className;
         private String interfaceName;
         private String description;
@@ -74,6 +75,14 @@ public class GeneratePojoBeanMojo extends AbstractGeneratorMojo {
             this.name = name;
         }
 
+        public String getTitle() {
+            return title;
+        }
+
+        public void setTitle(String title) {
+            this.title = title;
+        }
+
         public String getClassName() {
             return className;
         }
@@ -134,10 +143,15 @@ public class GeneratePojoBeanMojo extends AbstractGeneratorMojo {
             String label = annotationValue(a, "label");
             if ("bean".equals(label)) {
                 BeanPojoModel model = new BeanPojoModel();
-                String currentClass = a.target().asClass().name().toString();
-                boolean deprecated = a.target().asClass().hasAnnotation(Deprecated.class);
                 model.setName(a.target().asClass().simpleName());
-                model.setClassName(currentClass);
+                boolean deprecated = a.target().asClass().hasAnnotation(Deprecated.class);
+                String title = annotationValue(a, "title");
+                if (title == null) {
+                    title = Strings.camelCaseToDash(model.getName());
+                    title = Strings.camelDashToTitle(title);
+                }
+                model.setTitle(title);
+                model.setClassName(a.target().asClass().name().toString());
                 model.setDeprecated(deprecated);
                 model.setDescription(annotationValue(a, "description"));
                 for (DotName dn : a.target().asClass().interfaceNames()) {
@@ -191,7 +205,7 @@ public class GeneratePojoBeanMojo extends AbstractGeneratorMojo {
         if (model.getInterfaceName() != null) {
             jo.put("interfaceType", model.getInterfaceName());
         }
-        jo.put("title", asTitle(model.getClassName()));
+        jo.put("title", asTitle(model.getName()));
         if (model.getDescription() != null) {
             jo.put("description", model.getDescription());
         }
@@ -209,13 +223,7 @@ public class GeneratePojoBeanMojo extends AbstractGeneratorMojo {
     }
 
     private String asTitle(String name) {
-        name = Strings.camelDashToTitle(name);
-        String part = Strings.after(name, ":");
-        if (part != null) {
-            part = Strings.capitalize(part);
-            name = Strings.before(name, ":") + " (" + part + ")";
-        }
-        return name;
+        return Strings.asTitle(name);
     }
 
 }