gnodet-bot commented on code in PR #28724:
URL: https://github.com/apache/camel/pull/28724#discussion_r4421786524


##########
dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/TextBodyFlow.java:
##########
@@ -1625,6 +1692,112 @@ private static Error error(NodePath at, String routeId, 
String read, Text text)
                 .build();
     }
 
+    /** The key of the JSON data in the directory a file consumer reads, or 
null for any other consumer. */
+    private static String directoryKey(String uri, JsonNode from) {
+        if (!"file".equals(scheme(uri))) {
+            return null;
+        }
+        String path = uri.indexOf(':') > 0 ? 
normalize(uri).substring(uri.indexOf(':') + 1) : null;
+        if ((path == null || path.isBlank()) && from != null && 
from.isObject() && from.get("parameters") != null
+                && from.get("parameters").get("directoryName") != null) {
+            path = from.get("parameters").get("directoryName").asText();
+        }
+        return path != null && !path.isBlank() ? 
ProjectFacts.directoryKey(path) : null;
+    }
+
+    /** Remembers the body a step sends to a direct: or seda: endpoint, for 
the route of the file that consumes it. */
+    private static void recordSend(String name, JsonNode value, Body body, 
Walk w) {
+        if (!SENDS_THE_BODY.contains(name) && !"toD".equals(name)) {

Review Comment:
   💡 **Nit:** The `!\"toD\".equals(name)` guard is redundant — `SENDS_THE_BODY` 
is defined as `Set.of("to", "toD", "wireTap", "enrich")`, so 
`SENDS_THE_BODY.contains(name)` already returns `true` when `name` is `"toD"`. 
The first operand of `&&` short-circuits to `false` before the second is ever 
evaluated.
   
   ```suggestion
           if (!SENDS_THE_BODY.contains(name)) {
   ```



##########
dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/ProjectFacts.java:
##########
@@ -68,13 +71,49 @@ public record Observed(List<String> types, List<String> 
kinds) {
     public record KameletDataTypes(String in, String out) {
     }
 
+    /**
+     * The fields of JSON data, as the files of the project have them: the 
keys of its objects (of the elements, for a
+     * list), and of each field that holds a list of objects, the keys of 
those objects. Where says in words where the
+     * data is ("the files in orders/"); outer has the fields of the data an 
element was split from, and is empty
+     * otherwise.
+     */
+    public record JsonFields(String where, Set<String> fields, Map<String, 
Set<String>> elementFields, boolean list,
+            Set<String> outer) {
+
+        public JsonFields {
+            fields = fields != null ? Set.copyOf(fields) : Set.of();
+            elementFields = elementFields != null ? Map.copyOf(elementFields) 
: Map.of();

Review Comment:
   💡 **Nit:** `Map.copyOf(elementFields)` is a shallow copy — the map itself 
becomes unmodifiable, but the `Set<String>` values remain whatever mutable type 
was passed in (here: `TreeSet` instances, as seen in `TextBodyFlow`). Callers 
could still mutate an individual set via `elementFields().get(key).add(...)`. 
Consider wrapping each value too, e.g.:
   
   ```suggestion
               elementFields = elementFields != null
                       ? elementFields.entrySet().stream().collect(
                               Collectors.toUnmodifiableMap(Map.Entry::getKey, 
e -> Set.copyOf(e.getValue())))
                       : Map.of();
   ```



-- 
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