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

hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/main by this push:
     new f78925f42f Fix result handling for SNMP trap, delete execution 
information, and set password encoder (#9281)
f78925f42f is described below

commit f78925f42ff145b7f6b633b7ac1f67560d5560da
Author: Lance <[email protected]>
AuthorDate: Thu Nov 5 22:16:05 2026 +0800

    Fix result handling for SNMP trap, delete execution information, and set 
password encoder (#9281)
    
    Signed-off-by: leehaut <[email protected]>
---
 .../workflow/actions/deleteexecutioninfo.adoc      |  6 +-
 .../pages/workflow/actions/setpasswordencoder.adoc |  6 +-
 .../ROOT/pages/workflow/actions/snmptrap.adoc      |  2 -
 .../ActionDeleteExecutionInfo.java                 |  5 ++
 .../ActionDeleteExecutionInfoTest.java             |  6 ++
 .../ActionSetPasswordEncoder.java                  | 10 +++
 .../messages/messages_en_US.properties             |  1 +
 .../ActionSetPasswordEncoderTest.java              | 72 ++++++++++++++++++++++
 .../workflow/actions/snmptrap/ActionSNMPTrap.java  |  8 +--
 .../actions/snmptrap/ActionSNMPTrapTest.java       | 49 ++++++++++++---
 10 files changed, 141 insertions(+), 24 deletions(-)

diff --git 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/deleteexecutioninfo.adoc
 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/deleteexecutioninfo.adoc
index a51c1c845c..d95e39a7f2 100644
--- 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/deleteexecutioninfo.adoc
+++ 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/deleteexecutioninfo.adoc
@@ -57,13 +57,11 @@ What this action passes on to the next action. See 
xref:workflow/action-results.
 [options="header", width="90%", cols="1,3"]
 |===
 |Result|Value
-|True|The executions were deleted, with 0 errors. No execution to delete, or a 
root folder that doesn't exist yet, is also true. The result is not used for 
hops: see the WARNING.
-|False|The number of errors is 1. *Execution information location* is empty or 
doesn't exist, *Older than* is empty, 0, negative or not a number while *Delete 
all executions in this location* is unchecked, or an execution can't be deleted 
(for example a read-only folder).
+|True|The executions were deleted, with 0 errors. No execution to delete, or a 
root folder that doesn't exist yet, is also true. A success hop is followed.
+|False|The number of errors is 1. *Execution information location* is empty or 
doesn't exist, *Older than* is empty, 0, negative or not a number while *Delete 
all executions in this location* is unchecked, or an execution can't be deleted 
(for example a read-only folder). A failure hop is followed.
 |Result files|Passed on unchanged.
 |Result rows|Passed on unchanged.
 |Lines deleted|The number of executions deleted. A File location counts each 
run once, with everything it ran (child pipelines, actions, transforms). A 
Caching file location counts the workflow and each pipeline it ran separately. 
When the action is false, the value of the previous action is passed on.
 |===
 
-WARNING: A success or failure hop from this action is never followed, whatever 
the result: only an unconditional hop is. The result and the metrics are still 
passed on to the next action.
-
 NOTE: A Caching file location only deletes the executions of the project the 
workflow runs in, when both have a project id: an execution stored without 
project id is deleted from any project, and a workflow that runs in a project 
without project id deletes the executions of every project. A File location 
deletes the executions of every project that writes to it.
diff --git 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/setpasswordencoder.adoc
 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/setpasswordencoder.adoc
index 44069e0b23..8a1f1739f7 100644
--- 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/setpasswordencoder.adoc
+++ 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/setpasswordencoder.adoc
@@ -58,10 +58,8 @@ What this action passes on to the next action. See 
xref:workflow/action-results.
 [options="header", width="90%", cols="1,3"]
 |===
 |Result|Value
-|True|The encoder was initialized, with 0 errors. An empty *Encoder plugin ID* 
initializes `Hop`. An *Encoder plugin ID* that doesn't exist is also true: see 
the NOTE.
-|False|The number of errors is 1. *Encoder plugin ID* resolves to an empty 
value (for example an empty variable), or `AES` or `AES2` finds no key: the 
variable named in *Key variable name* is empty, `HOP_AES_ENCODER_KEY` is not 
set either, and *Key file path* is empty or the file doesn't exist.
+|True|The encoder was initialized, with 0 errors. An empty *Encoder plugin ID* 
initializes `Hop`.
+|False|The number of errors is 1. *Encoder plugin ID* resolves to an empty 
value (for example an empty variable), the plugin ID is not registered (for 
example `Nope`), or `AES` or `AES2` finds no key: the variable named in *Key 
variable name* is empty, `HOP_AES_ENCODER_KEY` is not set either, and *Key file 
path* is empty or the file doesn't exist.
 |Result files|Passed on unchanged.
 |Result rows|Passed on unchanged.
 |===
-
-NOTE: An *Encoder plugin ID* that doesn't exist only logs an error (`Unable to 
find two-way password encoder plugin with ID ...`): the `Hop` encoder is used 
instead, and the action is true and logs that it initialized the ID it was 
given.
diff --git 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/snmptrap.adoc 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/snmptrap.adoc
index 49bdd33008..8c65150e60 100644
--- a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/snmptrap.adoc
+++ b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/snmptrap.adoc
@@ -59,5 +59,3 @@ What this action passes on to the next action. See 
xref:workflow/action-results.
 |Result files|Passed on unchanged.
 |Result rows|Passed on unchanged.
 |===
-
-WARNING: *User (SNMP V3)* is not kept. When the workflow is loaded from its 
file, the target type is read back as *Community (SNMP V1)*, so the action 
sends an SNMP V1 trap with *Community string*, and *User*, *Passphrase* and 
*Engine ID* are not used.
diff --git 
a/plugins/actions/deleteexecutioninfo/src/main/java/org/apache/hop/workflow/actions/deleteexecutioninfo/ActionDeleteExecutionInfo.java
 
b/plugins/actions/deleteexecutioninfo/src/main/java/org/apache/hop/workflow/actions/deleteexecutioninfo/ActionDeleteExecutionInfo.java
index bfb50e129d..902b501ea8 100644
--- 
a/plugins/actions/deleteexecutioninfo/src/main/java/org/apache/hop/workflow/actions/deleteexecutioninfo/ActionDeleteExecutionInfo.java
+++ 
b/plugins/actions/deleteexecutioninfo/src/main/java/org/apache/hop/workflow/actions/deleteexecutioninfo/ActionDeleteExecutionInfo.java
@@ -172,6 +172,11 @@ public class ActionDeleteExecutionInfo extends ActionBase 
implements IAction {
     return result;
   }
 
+  @Override
+  public boolean isEvaluation() {
+    return true;
+  }
+
   /** Start dates strictly before this instant are deleted. */
   Date cutoff() throws HopException {
     String resolved = resolve(age);
diff --git 
a/plugins/actions/deleteexecutioninfo/src/test/java/org/apache/hop/workflow/actions/deleteexecutioninfo/ActionDeleteExecutionInfoTest.java
 
b/plugins/actions/deleteexecutioninfo/src/test/java/org/apache/hop/workflow/actions/deleteexecutioninfo/ActionDeleteExecutionInfoTest.java
index 2e64457cb9..d90a5a820d 100644
--- 
a/plugins/actions/deleteexecutioninfo/src/test/java/org/apache/hop/workflow/actions/deleteexecutioninfo/ActionDeleteExecutionInfoTest.java
+++ 
b/plugins/actions/deleteexecutioninfo/src/test/java/org/apache/hop/workflow/actions/deleteexecutioninfo/ActionDeleteExecutionInfoTest.java
@@ -39,6 +39,7 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+/** Unit test for {@link ActionDeleteExecutionInfo} */
 class ActionDeleteExecutionInfoTest {
 
   private Path tempDir;
@@ -97,6 +98,11 @@ class ActionDeleteExecutionInfoTest {
     
assertNotNull(provider.getSerializer(ExecutionInfoLocation.class).load("exec-loc"));
   }
 
+  @Test
+  void evaluatesSuccessAndFailureHops() {
+    assertTrue(new ActionDeleteExecutionInfo().isEvaluation());
+  }
+
   private MemoryMetadataProvider provider() {
     return new MemoryMetadataProvider();
   }
diff --git 
a/plugins/actions/setpasswordencoder/src/main/java/org/apache/hop/workflow/actions/setpasswordencoder/ActionSetPasswordEncoder.java
 
b/plugins/actions/setpasswordencoder/src/main/java/org/apache/hop/workflow/actions/setpasswordencoder/ActionSetPasswordEncoder.java
index 4b5716b66e..b1b1d3f083 100644
--- 
a/plugins/actions/setpasswordencoder/src/main/java/org/apache/hop/workflow/actions/setpasswordencoder/ActionSetPasswordEncoder.java
+++ 
b/plugins/actions/setpasswordencoder/src/main/java/org/apache/hop/workflow/actions/setpasswordencoder/ActionSetPasswordEncoder.java
@@ -23,7 +23,10 @@ import org.apache.hop.core.Result;
 import org.apache.hop.core.annotations.Action;
 import org.apache.hop.core.encryption.Encr;
 import org.apache.hop.core.encryption.ITwoWayPasswordEncoder;
+import org.apache.hop.core.encryption.TwoWayPasswordEncoderPluginType;
 import org.apache.hop.core.exception.HopException;
+import org.apache.hop.core.plugins.IPlugin;
+import org.apache.hop.core.plugins.PluginRegistry;
 import org.apache.hop.core.util.Utils;
 import org.apache.hop.i18n.BaseMessages;
 import org.apache.hop.metadata.api.HopMetadataProperty;
@@ -90,6 +93,13 @@ public class ActionSetPasswordEncoder extends ActionBase 
implements Cloneable, I
         throw new HopException(
             BaseMessages.getString(PKG, 
"ActionSetPasswordEncoder.Error.PluginIdMissing"));
       }
+      IPlugin plugin =
+          PluginRegistry.getInstance()
+              .findPluginWithId(TwoWayPasswordEncoderPluginType.class, 
pluginId);
+      if (plugin == null) {
+        throw new HopException(
+            BaseMessages.getString(PKG, 
"ActionSetPasswordEncoder.Error.PluginNotFound", pluginId));
+      }
 
       // Optionally promote a named variable's value into HOP_AES_ENCODER_KEY 
for the encoder.
       // Only set workflow variables — do not write key material into JVM 
system properties so
diff --git 
a/plugins/actions/setpasswordencoder/src/main/resources/org/apache/hop/workflow/actions/setpasswordencoder/messages/messages_en_US.properties
 
b/plugins/actions/setpasswordencoder/src/main/resources/org/apache/hop/workflow/actions/setpasswordencoder/messages/messages_en_US.properties
index 33e527601d..a128777de5 100644
--- 
a/plugins/actions/setpasswordencoder/src/main/resources/org/apache/hop/workflow/actions/setpasswordencoder/messages/messages_en_US.properties
+++ 
b/plugins/actions/setpasswordencoder/src/main/resources/org/apache/hop/workflow/actions/setpasswordencoder/messages/messages_en_US.properties
@@ -29,4 +29,5 @@ ActionSetPasswordEncoder.KeyFile.Label=Key file path
 ActionSetPasswordEncoder.KeyFile.Tooltip=Optional path to a file containing 
the AES/AES2 key (supports variables). Used when the key variable is empty.
 ActionSetPasswordEncoder.Log.EncoderInitialized=Two-way password encoder 
initialized with plugin ID ''{0}'' (process-global)
 ActionSetPasswordEncoder.Error.PluginIdMissing=Encoder plugin ID is required
+ActionSetPasswordEncoder.Error.PluginNotFound=Unable to find two-way password 
encoder plugin with ID ''{0}''
 ActionSetPasswordEncoder.Error.Failed=Error initializing the two-way password 
encoder
diff --git 
a/plugins/actions/setpasswordencoder/src/test/java/org/apache/hop/workflow/actions/setpasswordencoder/ActionSetPasswordEncoderTest.java
 
b/plugins/actions/setpasswordencoder/src/test/java/org/apache/hop/workflow/actions/setpasswordencoder/ActionSetPasswordEncoderTest.java
new file mode 100644
index 0000000000..9d8597424b
--- /dev/null
+++ 
b/plugins/actions/setpasswordencoder/src/test/java/org/apache/hop/workflow/actions/setpasswordencoder/ActionSetPasswordEncoderTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.hop.workflow.actions.setpasswordencoder;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+
+import org.apache.hop.core.Const;
+import org.apache.hop.core.Result;
+import org.apache.hop.core.encryption.Encr;
+import org.apache.hop.core.encryption.HopTwoWayPasswordEncoder;
+import org.apache.hop.core.encryption.TwoWayPasswordEncoderPlugin;
+import org.apache.hop.core.encryption.TwoWayPasswordEncoderPluginType;
+import org.apache.hop.core.logging.HopLogStore;
+import org.apache.hop.core.plugins.PluginRegistry;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+/** Unit test for {@link ActionSetPasswordEncoder} */
+class ActionSetPasswordEncoderTest {
+
+  @BeforeAll
+  static void setUpBeforeClass() throws Exception {
+    HopLogStore.init();
+    PluginRegistry.getInstance()
+        .registerPluginClass(
+            HopTwoWayPasswordEncoder.class.getName(),
+            TwoWayPasswordEncoderPluginType.class,
+            TwoWayPasswordEncoderPlugin.class);
+    Encr.init("Hop");
+  }
+
+  @Test
+  void unknownPluginIdFailsWithoutChangingTheEncoder() throws Exception {
+    ActionSetPasswordEncoder action = new ActionSetPasswordEncoder("encoder");
+    action.setEncoderPluginId("Nope");
+    action.setVariable(Const.HOP_PASSWORD_ENCODER_PLUGIN, "Hop");
+
+    Result result = action.execute(new Result(), 0);
+
+    assertEquals(1, result.getNrErrors());
+    assertEquals("Hop", action.getVariable(Const.HOP_PASSWORD_ENCODER_PLUGIN));
+    assertInstanceOf(HopTwoWayPasswordEncoder.class, Encr.getEncoder());
+  }
+
+  @Test
+  void registeredPluginIdInitializesTheEncoder() throws Exception {
+    ActionSetPasswordEncoder action = new ActionSetPasswordEncoder("encoder");
+    action.setEncoderPluginId("Hop");
+
+    Result result = action.execute(new Result(), 0);
+
+    assertEquals(0, result.getNrErrors());
+    assertEquals("Hop", action.getVariable(Const.HOP_PASSWORD_ENCODER_PLUGIN));
+    assertInstanceOf(HopTwoWayPasswordEncoder.class, Encr.getEncoder());
+  }
+}
diff --git 
a/plugins/actions/snmptrap/src/main/java/org/apache/hop/workflow/actions/snmptrap/ActionSNMPTrap.java
 
b/plugins/actions/snmptrap/src/main/java/org/apache/hop/workflow/actions/snmptrap/ActionSNMPTrap.java
index fc2816ba77..3126a17d22 100644
--- 
a/plugins/actions/snmptrap/src/main/java/org/apache/hop/workflow/actions/snmptrap/ActionSNMPTrap.java
+++ 
b/plugins/actions/snmptrap/src/main/java/org/apache/hop/workflow/actions/snmptrap/ActionSNMPTrap.java
@@ -141,14 +141,14 @@ public class ActionSNMPTrap extends ActionBase implements 
Cloneable, IAction {
   }
 
   public String getTargetTypeCode(String tt) {
-    if (tt == null) {
+    if (Utils.isEmpty(tt)) {
       return targetTypeCode[0];
     }
-    if (tt.equals(targetTypeDesc[1])) {
+    // The dialog passes the localized description. Metadata load passes the 
stored code.
+    if (tt.equalsIgnoreCase(targetTypeCode[1]) || 
tt.equalsIgnoreCase(targetTypeDesc[1])) {
       return targetTypeCode[1];
-    } else {
-      return targetTypeCode[0];
     }
+    return targetTypeCode[0];
   }
 
   /**
diff --git 
a/plugins/actions/snmptrap/src/test/java/org/apache/hop/workflow/actions/snmptrap/ActionSNMPTrapTest.java
 
b/plugins/actions/snmptrap/src/test/java/org/apache/hop/workflow/actions/snmptrap/ActionSNMPTrapTest.java
index 4c17e98baf..6c0d81fcf3 100644
--- 
a/plugins/actions/snmptrap/src/test/java/org/apache/hop/workflow/actions/snmptrap/ActionSNMPTrapTest.java
+++ 
b/plugins/actions/snmptrap/src/test/java/org/apache/hop/workflow/actions/snmptrap/ActionSNMPTrapTest.java
@@ -21,6 +21,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import org.apache.hop.core.HopClientEnvironment;
 import org.apache.hop.core.logging.HopLogStore;
+import org.apache.hop.core.xml.XmlHandler;
+import org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider;
+import org.apache.hop.metadata.serializer.xml.XmlMetadataUtil;
 import org.apache.hop.workflow.WorkflowMeta;
 import org.apache.hop.workflow.action.ActionMeta;
 import org.apache.hop.workflow.action.ActionSerializationTestUtil;
@@ -29,10 +32,12 @@ import 
org.apache.hop.workflow.engines.local.LocalWorkflowEngine;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
 
+/** Unit test for {@link ActionSNMPTrap} */
 class ActionSNMPTrapTest {
 
-  private IWorkflowEngine<WorkflowMeta> workflow;
   private ActionSNMPTrap action;
 
   @BeforeAll
@@ -42,7 +47,7 @@ class ActionSNMPTrapTest {
 
   @BeforeEach
   void setUp() {
-    workflow = new LocalWorkflowEngine(new WorkflowMeta());
+    IWorkflowEngine<WorkflowMeta> workflow = new LocalWorkflowEngine(new 
WorkflowMeta());
     action = new ActionSNMPTrap();
     workflow.getWorkflowMeta().addAction(new ActionMeta(action));
     action.setParentWorkflow(workflow);
@@ -53,16 +58,40 @@ class ActionSNMPTrapTest {
   void testSerialization() throws Exception {
     HopClientEnvironment.init();
 
-    ActionSNMPTrap action =
+    ActionSNMPTrap trap =
         ActionSerializationTestUtil.testSerialization(
             "/snmp-trap-action.xml", ActionSNMPTrap.class);
 
-    assertEquals("awesomeserver", action.getServerName());
-    assertEquals("5000", action.getTimeout());
-    assertEquals("162", action.getPort());
-    assertEquals("2", action.getNrretry());
-    assertEquals("13131", action.getOid());
-    assertEquals("averynicemessage", action.getMessage());
-    assertEquals("community", action.getTargettype());
+    assertEquals("awesomeserver", trap.getServerName());
+    assertEquals("5000", trap.getTimeout());
+    assertEquals("162", trap.getPort());
+    assertEquals("2", trap.getNrretry());
+    assertEquals("13131", trap.getOid());
+    assertEquals("averynicemessage", trap.getMessage());
+    assertEquals("community", trap.getTargettype());
+  }
+
+  @Test
+  void userTargetTypeCodeIsKeptWhenLoaded() throws Exception {
+    HopClientEnvironment.init();
+
+    action.setTargettype("user");
+    assertEquals("user", action.getTargettype());
+    action.setTargettype("USER");
+    assertEquals("user", action.getTargettype());
+    action.setTargettype(ActionSNMPTrap.targetTypeDesc[1]);
+    assertEquals("user", action.getTargettype());
+
+    String xml =
+        XmlHandler.openTag(ActionMeta.XML_TAG)
+            + "<name>Send v3 trap</name><targettype>user</targettype>"
+            + XmlHandler.closeTag(ActionMeta.XML_TAG);
+    Document document = XmlHandler.loadXmlString(xml);
+    Node node = XmlHandler.getSubNode(document, ActionMeta.XML_TAG);
+    ActionSNMPTrap loaded =
+        XmlMetadataUtil.deSerializeFromXml(
+            node, ActionSNMPTrap.class, new MemoryMetadataProvider());
+
+    assertEquals("user", loaded.getTargettype());
   }
 }

Reply via email to