luigidemasi commented on code in PR #27082:
URL: https://github.com/apache/camel/pull/27082#discussion_r4134884627


##########
core/camel-core-model/src/main/java/org/apache/camel/model/app/SemanticQuestionDefinition.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.apache.camel.model.app;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import jakarta.xml.bind.annotation.XmlAccessType;
+import jakarta.xml.bind.annotation.XmlAccessorType;
+import jakarta.xml.bind.annotation.XmlAttribute;
+import jakarta.xml.bind.annotation.XmlElement;
+import jakarta.xml.bind.annotation.XmlType;
+
+import org.apache.camel.model.PropertyDefinition;
+import org.apache.camel.spi.Metadata;
+
+/** A semantic question with the same fields and policies as a YAML 
declaration. */
+@Metadata(label = "configuration")
+@XmlType(name = "semanticQuestionDefinition", propOrder = { "instructions", 
"criteria", "levels" })
+@XmlAccessorType(XmlAccessType.FIELD)
+public class SemanticQuestionDefinition {
+    @XmlAttribute(required = true)
+    @Metadata(required = true, description = "The context-wide question name.")
+    private String name;
+    @XmlAttribute(required = true)
+    @Metadata(required = true, enums = "boolean,choice,score", description = 
"The question type.")
+    private String type;
+    @XmlAttribute
+    @Metadata(description = "The Simple expression selecting the message 
state.")
+    private String state;
+    @XmlAttribute
+    @Metadata(description = "The boolean decision threshold.")
+    private String threshold;
+    @XmlAttribute
+    @Metadata(description = "The boolean uncertainty band.")
+    private String uncertainty;
+    @XmlAttribute
+    @Metadata(enums = "fail,non-match", description = "The boolean uncertainty 
policy.")
+    private String uncertaintyPolicy;

Review Comment:
   Fixed in 
[02f4ad4b4f46](https://github.com/apache/camel/pull/27082/commits/02f4ad4b4f46ceaa0efaf0521b92832ddc29e7e9).
 Added numeric Java types and defaults of `0.5` / `0`, plus the `fail` policy 
default, and regenerated the model/catalog metadata and XML writer. The model 
fields remain strings so they can preserve property placeholders.
   
   _Generated by Codex via /oss-address-review on behalf of 
[luigidemasi](https://github.com/luigidemasi)._



##########
dsl/camel-xml-io-dsl/src/main/java/org/apache/camel/dsl/xml/io/XmlRoutesBuilderLoader.java:
##########
@@ -95,19 +97,50 @@ public void preParseRoute(Resource resource) throws 
Exception {
         if (preparseDone.getOrDefault(resource.getLocation(), false)) {
             return;
         }
-        XmlStreamInfo xmlInfo = xmlInfo(resource);
-        if (xmlInfo.isValid()) {
-            String root = xmlInfo.getRootElementName();
-            if ("beans".equals(root) || "blueprint".equals(root) || 
"camel".equals(root)) {
-                new XmlModelParser(resource, xmlInfo.getRootElementNamespace())
-                        .parseBeansDefinition()
-                        .ifPresent(bd -> {
-                            registerBeans(resource, bd);
-                            camelAppCache.put(resource.getLocation(), bd);
-                        });
+        try {
+            XmlStreamInfo xmlInfo = xmlInfo(resource);
+            if (xmlInfo.isValid()) {
+                String root = xmlInfo.getRootElementName();
+                SemanticDefinition semantic = null;
+                if ("beans".equals(root) || "blueprint".equals(root) || 
"camel".equals(root)) {
+                    new XmlModelParser(resource, 
xmlInfo.getRootElementNamespace())
+                            .parseBeansDefinition()
+                            .ifPresent(bd -> {
+                                registerBeans(resource, bd);
+                                camelAppCache.put(resource.getLocation(), bd);
+                            });
+                    BeansDefinition app = 
camelAppCache.get(resource.getLocation());
+                    if (app != null) {
+                        semantic = app.getSemantic();
+                    }
+                } else if ("routes".equals(root) || "route".equals(root)) {
+                    RoutesDefinition routes = new 
XmlModelParser(resource(resource), xmlInfo.getRootElementNamespace())
+                            .parseRoutesDefinition().orElse(null);
+                    if (routes != null) {
+                        routesCache.put(resource.getLocation(), routes);

Review Comment:
   Fixed in 
[02f4ad4b4f46](https://github.com/apache/camel/pull/27082/commits/02f4ad4b4f46ceaa0efaf0521b92832ddc29e7e9).
 Preparse reuses cached models only when the current resource content matches 
the cached snapshot. Changed resources invalidate their parsed models and 
pending bean registrations, while unchanged repeated preparse remains 
idempotent. Regression tests cover both external failure paths for `<routes>` 
and `<camel>`, edited files reused through the same Resource instance, 
unchanged bean registration, and deferred beans retaining their original 
resource during retry.
   
   _Generated by Codex via /oss-address-review on behalf of 
[luigidemasi](https://github.com/luigidemasi)._



##########
core/camel-java-io/src/main/java/org/apache/camel/java/out/JavaDslModelWriterSupport.java:
##########
@@ -1131,6 +1133,43 @@ protected String indent() {
         return "    ".repeat(indentLevel);
     }
 
+    public String writeSemanticDefinition(SemanticDefinition definition) {
+        StringBuilder result = new StringBuilder();
+        doWriteSemanticDefinition(result, definition);
+        return result.toString();
+    }
+
+    protected void doWriteSemanticDefinition(StringBuilder result, 
SemanticDefinition definition) {
+        for (SemanticQuestionDefinition question : definition.getQuestions()) {
+            if (!result.isEmpty()) {
+                result.append(NL);
+            }
+            
result.append("semanticQuestions().question(").append(quote(question.getName())).append(")")
+                    
.append(".type(").append(quote(question.getType())).append(")")
+                    
.append(".instructions(").append(quote(question.getInstructions())).append(")");
+            if (question.getState() != null) {
+                
result.append(".state(").append(quote(question.getState())).append(")");
+            }
+            if (question.getThreshold() != null) {
+                
result.append(".threshold(").append(Double.parseDouble(question.getThreshold())).append(")");

Review Comment:
   Fixed in 
[02f4ad4b4f46](https://github.com/apache/camel/pull/27082/commits/02f4ad4b4f46ceaa0efaf0521b92832ddc29e7e9).
 Added String overloads for `threshold` and `uncertainty`; the Java writer now 
quotes the original values without parsing them. Numeric placeholders are 
resolved before runtime validation in Java/XML and YAML. Tests compile exports 
containing placeholders and verify resolved values and invalid-number 
diagnostics.
   
   _Generated by Codex via /oss-address-review on behalf of 
[luigidemasi](https://github.com/luigidemasi)._



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to