mattcasters opened a new pull request, #7368:
URL: https://github.com/apache/hop/pull/7368

   Here is a recap of the changes, ready for code reviewers:
   
   ### **Problem & Root Cause**
   * **Issue:** When importing Kettle (PDI) transformations into Apache Hop, 
the "Java expression" column in the User Defined Java Expression (UDJE / 
Janino) transform is cleared.
   * **Root Cause:** During the PDI-to-Hop conversion process, 
`KettleConst.kettleElementReplacements` globally maps the `<formula_string>` 
tag to `<formula>` (which is required by the standard `Formula` transform). 
However, in Hop's `JaninoMetaFunction`, the property tag is still expected to 
be `<formula_string>`. Consequently, the XML deserializer fails to locate 
`<formula_string>` because it was renamed to `<formula>`, leaving the java 
expression blank.
   
   ---
   
   ### **Proposed Solution & Changes**
   To handle this legacy migration mismatch locally without breaking the 
`Formula` transform, we added legacy XML conversion handling inside 
`JaninoMeta`.
   
   #### 1. 
**[JaninoMeta.java](file:///home/matt/git/mattcasters/hop/plugins/transforms/janino/src/main/java/org/apache/hop/pipeline/transforms/janino/JaninoMeta.java)**
   * Added `import org.apache.hop.core.xml.XmlHandler;`.
   * Overrode `convertLegacyXml(Node node)` to read the legacy `<formula>` 
child node from each `<formula>` item block (after the global replacement) and 
set it as the formula expression of the corresponding `JaninoMetaFunction` when 
the standard deserialized field is empty/null.
   
   ```java
     @Override
     public void convertLegacyXml(Node node) throws HopException {
       int nrCalcs = XmlHandler.countNodes(node, "formula");
       for (int i = 0; i < nrCalcs; i++) {
         Node calcnode = XmlHandler.getSubNodeByNr(node, "formula", i);
         if (calcnode != null) {
           String expression = XmlHandler.getTagValue(calcnode, "formula");
           if (expression != null && i < functions.size()) {
             JaninoMetaFunction fn = functions.get(i);
             if (Utils.isEmpty(fn.getFormula())) {
               fn.setFormula(expression);
             }
           }
         }
       }
     }
   ```
   
   #### 2. 
**[JaninoMetaTest.java](file:///home/matt/git/mattcasters/hop/plugins/transforms/janino/src/test/java/org/apache/hop/pipeline/transforms/janino/JaninoMetaTest.java)**
   * Added `testConvertLegacyXml` unit test to verify that Kettle-converted 
UDJE XML (using `<formula>` as the child node tag instead of 
`<formula_string>`) successfully deserializes the Java expressions correctly.
   
   ---
   
   ### **Verification & Tests**
   * **Code Formatting:** Formatted all modified files using:
     ```bash
     ./mvnw spotless:apply
     ```
   * **Unit Tests:** Ran and verified all 208 unit tests in the Janino plugin 
module with:
     ```bash
     ./mvnw test -pl plugins/transforms/janino
     ```
     **Results:** All tests passed successfully.


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