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

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

commit d833fcff72b6ae7228270dc404455d7607e94b9e
Author: Nicolas Adment <[email protected]>
AuthorDate: Sat Dec 10 00:57:01 2022 +0100

    Fix #1957 : Cleanup XML of action Column Exists
---
 .../actions/columnsexist/ActionColumnsExist.java   | 187 ++++++++-------------
 .../columnsexist/ActionColumnsExistDialog.java     | 108 ++++--------
 .../messages/messages_en_US.properties             |   7 +-
 .../messages/messages_fr_FR.properties             |   1 -
 .../messages/messages_it_IT.properties             |   1 -
 .../messages/messages_ja_JP.properties             |   1 -
 .../messages/messages_ko_KR.properties             |   1 -
 .../messages/messages_zh_CN.properties             |   1 -
 .../columnsexist/ActionColumnsExistTest.java       |  49 ++++++
 .../WorkflowActionColumnsExistLoadSaveTest.java    |  40 -----
 .../WorkflowActionColumnsExistTest.java            | 146 ----------------
 .../src/test/resources/columns-exist-action.xml    |  33 ++++
 12 files changed, 192 insertions(+), 383 deletions(-)

diff --git 
a/plugins/actions/columnsexist/src/main/java/org/apache/hop/workflow/actions/columnsexist/ActionColumnsExist.java
 
b/plugins/actions/columnsexist/src/main/java/org/apache/hop/workflow/actions/columnsexist/ActionColumnsExist.java
index d36ef0c09f..9a03dcbc97 100644
--- 
a/plugins/actions/columnsexist/src/main/java/org/apache/hop/workflow/actions/columnsexist/ActionColumnsExist.java
+++ 
b/plugins/actions/columnsexist/src/main/java/org/apache/hop/workflow/actions/columnsexist/ActionColumnsExist.java
@@ -17,19 +17,16 @@
 
 package org.apache.hop.workflow.actions.columnsexist;
 
-import org.apache.hop.core.Const;
 import org.apache.hop.core.ICheckResult;
 import org.apache.hop.core.Result;
 import org.apache.hop.core.annotations.Action;
 import org.apache.hop.core.database.Database;
 import org.apache.hop.core.database.DatabaseMeta;
 import org.apache.hop.core.exception.HopDatabaseException;
-import org.apache.hop.core.exception.HopException;
-import org.apache.hop.core.exception.HopXmlException;
 import org.apache.hop.core.util.Utils;
 import org.apache.hop.core.variables.IVariables;
-import org.apache.hop.core.xml.XmlHandler;
 import org.apache.hop.i18n.BaseMessages;
+import org.apache.hop.metadata.api.HopMetadataProperty;
 import org.apache.hop.metadata.api.IHopMetadataProvider;
 import org.apache.hop.resource.ResourceEntry;
 import org.apache.hop.resource.ResourceEntry.ResourceType;
@@ -39,8 +36,7 @@ import org.apache.hop.workflow.action.ActionBase;
 import org.apache.hop.workflow.action.IAction;
 import org.apache.hop.workflow.action.validator.ActionValidatorUtils;
 import org.apache.hop.workflow.action.validator.AndValidator;
-import org.w3c.dom.Node;
-
+import java.util.ArrayList;
 import java.util.List;
 
 /** This defines a column exists action. */
@@ -54,121 +50,93 @@ import java.util.List;
     documentationUrl = "/workflow/actions/columnsexist.html")
 public class ActionColumnsExist extends ActionBase implements Cloneable, 
IAction {
   private static final Class<?> PKG = ActionColumnsExist.class; // For 
Translator
-  private String schemaname;
+  
+  public static final class ColumnExist {
+    public ColumnExist() {  
+    }
+    
+    public ColumnExist(String name) {
+      this.name = name;
+    }
+
+    @HopMetadataProperty(key = "name")
+    private String name;
+
+    public String getName() {
+      return name;
+    }
+
+    public void setName(String name) {
+      this.name = name;
+    }       
+  }
+  
+  @HopMetadataProperty(key = "schemaname")
+  private String schemaName;
+  @HopMetadataProperty(key = "tablename")
   private String tableName;
-  private DatabaseMeta connection;
-  private String[] arguments;
+  @HopMetadataProperty(key = "connection", storeWithName = true)
+  private DatabaseMeta databaseMeta;
+  @HopMetadataProperty(groupKey = "fields", key = "field")
+  private List<ColumnExist> columns;
 
   public ActionColumnsExist(String n) {
     super(n, "");
-    schemaname = null;
-    tableName = null;
-    connection = null;
+    this.schemaName = null;
+    this.tableName = null;
+    this.databaseMeta = null;
+    this.columns = new ArrayList<>();
   }
 
   public ActionColumnsExist() {
     this("");
   }
 
-  public void allocate(int nrFields) {
-    arguments = new String[nrFields];
-  }
-
-  @Override
-  public Object clone() {
-    ActionColumnsExist je = (ActionColumnsExist) super.clone();
-    if (arguments != null) {
-      int nrFields = arguments.length;
-      je.allocate(nrFields);
-      System.arraycopy(arguments, 0, je.arguments, 0, nrFields);
-    }
-    return je;
-  }
-
-  @Override
-  public String getXml() {
-    StringBuilder xml = new StringBuilder(200);
-
-    xml.append(super.getXml());
-
-    xml.append("      ").append(XmlHandler.addTagValue("tablename", 
tableName));
-    xml.append("      ").append(XmlHandler.addTagValue("schemaname", 
schemaname));
-    xml.append("      ")
-        .append(
-            XmlHandler.addTagValue("connection", connection == null ? null : 
connection.getName()));
-
-    xml.append("      <fields>").append(Const.CR);
-    if (arguments != null) {
-      for (int i = 0; i < arguments.length; i++) {
-        xml.append("        <field>").append(Const.CR);
-        xml.append("          ").append(XmlHandler.addTagValue("name", 
arguments[i]));
-        xml.append("        </field>").append(Const.CR);
-      }
+  public ActionColumnsExist(ActionColumnsExist meta) {
+    this("");
+    this.schemaName = meta.schemaName;
+    this.tableName = meta.tableName;
+    this.databaseMeta = meta.databaseMeta;
+    for (ColumnExist column: meta.columns) {
+      columns.add(new ColumnExist(column.getName()));
     }
-    xml.append("      </fields>").append(Const.CR);
-
-    return xml.toString();
   }
-
+  
   @Override
-  public void loadXml(Node entrynode, IHopMetadataProvider metadataProvider, 
IVariables variables)
-      throws HopXmlException {
-    try {
-      super.loadXml(entrynode);
-      tableName = XmlHandler.getTagValue(entrynode, "tablename");
-      schemaname = XmlHandler.getTagValue(entrynode, "schemaname");
-
-      String dbname = XmlHandler.getTagValue(entrynode, "connection");
-      connection = DatabaseMeta.loadDatabase(metadataProvider, dbname);
-
-      Node fields = XmlHandler.getSubNode(entrynode, "fields");
-
-      // How many field arguments?
-      int nrFields = XmlHandler.countNodes(fields, "field");
-      allocate(nrFields);
-
-      // Read them all...
-      for (int i = 0; i < nrFields; i++) {
-        Node fnode = XmlHandler.getSubNodeByNr(fields, "field", i);
-        arguments[i] = XmlHandler.getTagValue(fnode, "name");
-      }
-
-    } catch (HopException e) {
-      throw new HopXmlException(
-          BaseMessages.getString(PKG, 
"ActionColumnsExist.Meta.UnableLoadXml"), e);
-    }
+  public Object clone() {
+    return new ActionColumnsExist(this);
   }
 
-  public void setTablename(String tableName) {
+  public void setTableName(String tableName) {
     this.tableName = tableName;
   }
 
-  public String getTablename() {
+  public String getTableName() {
     return tableName;
   }
 
-  public void setSchemaname(String schemaname) {
-    this.schemaname = schemaname;
+  public void setSchemaName(String schemaname) {
+    this.schemaName = schemaname;
   }
 
-  public String getSchemaname() {
-    return schemaname;
+  public String getSchemaName() {
+    return schemaName;
   }
 
-  public String[] getArguments() {
-    return arguments;
+  public List<ColumnExist> getColumns() {
+    return columns;
   }
 
-  public void setArguments(String[] arguments) {
-    this.arguments = arguments;
+  public void setColumns(List<ColumnExist> columns) {
+    this.columns = columns;
   }
 
-  public void setDatabase(DatabaseMeta database) {
-    this.connection = database;
+  public void setDatabaseMeta(DatabaseMeta database) {
+    this.databaseMeta = database;
   }
 
-  public DatabaseMeta getDatabase() {
-    return connection;
+  public DatabaseMeta getDatabaseMeta() {
+    return databaseMeta;
   }
 
   @Override
@@ -194,14 +162,13 @@ public class ActionColumnsExist extends ActionBase 
implements Cloneable, IAction
       logError(BaseMessages.getString(PKG, 
"ActionColumnsExist.Error.TablenameEmpty"));
       return result;
     }
-    if (arguments == null) {
+    if (columns == null) {
       logError(BaseMessages.getString(PKG, 
"ActionColumnsExist.Error.ColumnameEmpty"));
       return result;
     }
-    if (connection != null) {
-      Database db = getNewDatabaseFromMeta();
-      try {
-        String realSchemaname = resolve(schemaname);
+    if (databaseMeta != null) {
+      try (Database db = new Database(this, this, databaseMeta)) {
+        String realSchemaname = resolve(schemaName);
         String realTablename = resolve(tableName);
 
         db.connect();
@@ -212,8 +179,12 @@ public class ActionColumnsExist extends ActionBase 
implements Cloneable, IAction
                 BaseMessages.getString(PKG, 
"ActionColumnsExist.Log.TableExists", realTablename));
           }
 
-          for (int i = 0; i < arguments.length && !parentWorkflow.isStopped(); 
i++) {
-            String realColumnname = resolve(arguments[i]);
+          for (ColumnExist column: columns) {            
+            if ( parentWorkflow.isStopped() ) {
+                break;
+            }
+            
+            String realColumnname = resolve(column.getName());
 
             if (db.checkColumnExists(realSchemaname, realTablename, 
realColumnname)) {
               if (isDetailed()) {
@@ -240,14 +211,6 @@ public class ActionColumnsExist extends ActionBase 
implements Cloneable, IAction
         logError(
             BaseMessages.getString(
                 PKG, "ActionColumnsExist.Error.UnexpectedError", 
dbe.getMessage()));
-      } finally {
-        if (db != null) {
-          try {
-            db.disconnect();
-          } catch (Exception e) {
-            /* Ignore */
-          }
-        }
       }
     } else {
       logError(BaseMessages.getString(PKG, 
"ActionColumnsExist.Error.NoDbConnection"));
@@ -256,21 +219,17 @@ public class ActionColumnsExist extends ActionBase 
implements Cloneable, IAction
     result.setEntryNr(nrnotexistcolums);
     result.setNrLinesWritten(nrexistcolums);
     // result is true only if all columns found
-    if (nrexistcolums == arguments.length) {
+    if (nrexistcolums == columns.size()) {
       result.setNrErrors(0);
       result.setResult(true);
     }
     return result;
   }
 
-  Database getNewDatabaseFromMeta() {
-    return new Database(this, this, connection);
-  }
-
   @Override
   public DatabaseMeta[] getUsedDatabaseConnections() {
     return new DatabaseMeta[] {
-      connection,
+      databaseMeta,
     };
   }
 
@@ -278,12 +237,12 @@ public class ActionColumnsExist extends ActionBase 
implements Cloneable, IAction
   public List<ResourceReference> getResourceDependencies(
       IVariables variables, WorkflowMeta workflowMeta) {
     List<ResourceReference> references = 
super.getResourceDependencies(variables, workflowMeta);
-    if (connection != null) {
+    if (databaseMeta != null) {
       ResourceReference reference = new ResourceReference(this);
-      reference.getEntries().add(new ResourceEntry(connection.getHostname(), 
ResourceType.SERVER));
+      reference.getEntries().add(new ResourceEntry(databaseMeta.getHostname(), 
ResourceType.SERVER));
       reference
           .getEntries()
-          .add(new ResourceEntry(connection.getDatabaseName(), 
ResourceType.DATABASENAME));
+          .add(new ResourceEntry(databaseMeta.getDatabaseName(), 
ResourceType.DATABASENAME));
       references.add(reference);
     }
     return references;
diff --git 
a/plugins/actions/columnsexist/src/main/java/org/apache/hop/workflow/actions/columnsexist/ActionColumnsExistDialog.java
 
b/plugins/actions/columnsexist/src/main/java/org/apache/hop/workflow/actions/columnsexist/ActionColumnsExistDialog.java
index ea3c56d9c8..c4ed93af42 100644
--- 
a/plugins/actions/columnsexist/src/main/java/org/apache/hop/workflow/actions/columnsexist/ActionColumnsExistDialog.java
+++ 
b/plugins/actions/columnsexist/src/main/java/org/apache/hop/workflow/actions/columnsexist/ActionColumnsExistDialog.java
@@ -41,6 +41,7 @@ import org.apache.hop.ui.workflow.dialog.WorkflowDialog;
 import org.apache.hop.workflow.WorkflowMeta;
 import org.apache.hop.workflow.action.IAction;
 import org.apache.hop.workflow.action.IActionDialog;
+import 
org.apache.hop.workflow.actions.columnsexist.ActionColumnsExist.ColumnExist;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
@@ -55,6 +56,8 @@ import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.TableItem;
 import org.eclipse.swt.widgets.Text;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * This dialog allows you to edit the Column Exists action settings. (select 
the connection and the
@@ -115,13 +118,13 @@ public class ActionColumnsExistDialog extends 
ActionDialog implements IActionDia
     wCancel.addListener(SWT.Selection, (Event e) -> cancel());
     BaseTransformDialog.positionBottomButtons(shell, new Button[] {wOk, 
wCancel}, margin, null);
 
-    // Filename line
+    // Action name line
     Label wlName = new Label(shell, SWT.RIGHT);
     wlName.setText(BaseMessages.getString(PKG, 
"ActionColumnsExist.Name.Label"));
     PropsUi.setLook(wlName);
     FormData fdlName = new FormData();
     fdlName.left = new FormAttachment(0, 0);
-    fdlName.right = new FormAttachment(middle, 0);
+    fdlName.right = new FormAttachment(middle, -margin);
     fdlName.top = new FormAttachment(0, margin);
     wlName.setLayoutData(fdlName);
     wName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
@@ -134,7 +137,7 @@ public class ActionColumnsExistDialog extends ActionDialog 
implements IActionDia
     wName.setLayoutData(fdName);
 
     // Connection line
-    wConnection = addConnectionLine(shell, wName, action.getDatabase(), lsMod);
+    wConnection = addConnectionLine(shell, wName, action.getDatabaseMeta(), 
lsMod);
 
     // Schema name line
     // Schema name
@@ -228,23 +231,7 @@ public class ActionColumnsExistDialog extends ActionDialog 
implements IActionDia
     fdbGetColumns.top = new FormAttachment(wlFields, margin);
     wbGetColumns.setLayoutData(fdbGetColumns);
 
-    // Buttons to the right of the screen...
-    // Delete
-    Button wbdFilename = new Button(shell, SWT.PUSH | SWT.CENTER);
-    PropsUi.setLook(wbdFilename);
-    wbdFilename.setText(BaseMessages.getString(PKG, 
"ActionColumnsExist.FilenameDelete.Button"));
-    wbdFilename.setToolTipText(
-        BaseMessages.getString(PKG, 
"ActionColumnsExist.FilenameDelete.Tooltip"));
-    FormData fdbdFilename = new FormData();
-    fdbdFilename.right = new FormAttachment(100, 0);
-    fdbdFilename.left = new FormAttachment(wbGetColumns, 0, SWT.LEFT);
-    fdbdFilename.top = new FormAttachment(wbGetColumns, margin);
-    wbdFilename.setLayoutData(fdbdFilename);
-
-    int rows =
-        action.getArguments() == null
-            ? 1
-            : (action.getArguments().length == 0 ? 0 : 
action.getArguments().length);
+    int rows = action.getColumns().size();
 
     final int FieldsRows = rows;
 
@@ -276,17 +263,7 @@ public class ActionColumnsExistDialog extends ActionDialog 
implements IActionDia
     fdFields.bottom = new FormAttachment(wOk, -2 * margin);
     wFields.setLayoutData(fdFields);
 
-    // Delete files from the list of files...
-    wbdFilename.addListener(
-        SWT.Selection,
-        e -> {
-          int[] idx = wFields.getSelectionIndices();
-          wFields.remove(idx);
-          wFields.removeEmptyRows();
-          wFields.setRowNums();
-        });
-
-    // Delete files from the list of files...
+    // Get list of columns name from the table...
     wbGetColumns.addListener(SWT.Selection, e -> getListColumns());
 
     getData();
@@ -299,7 +276,7 @@ public class ActionColumnsExistDialog extends ActionDialog 
implements IActionDia
   private void getTableName() {
     String databaseName = wConnection.getText();
     if (StringUtils.isNotEmpty(databaseName)) {
-      DatabaseMeta databaseMeta = 
this.getWorkflowMeta().findDatabase(databaseName);
+      DatabaseMeta databaseMeta = wConnection.loadSelectedElement();
       if (databaseMeta != null) {
         DatabaseExplorerDialog std =
             new DatabaseExplorerDialog(
@@ -324,24 +301,23 @@ public class ActionColumnsExistDialog extends 
ActionDialog implements IActionDia
     if (action.getName() != null) {
       wName.setText(action.getName());
     }
-    if (action.getTablename() != null) {
-      wTablename.setText(action.getTablename());
+    if (action.getTableName() != null) {
+      wTablename.setText(action.getTableName());
     }
 
-    if (action.getSchemaname() != null) {
-      wSchemaname.setText(action.getSchemaname());
+    if (action.getSchemaName() != null) {
+      wSchemaname.setText(action.getSchemaName());
     }
 
-    if (action.getDatabase() != null) {
-      wConnection.setText(action.getDatabase().getName());
+    if (action.getDatabaseMeta() != null) {
+      wConnection.setText(action.getDatabaseMeta().getName());
     }
 
-    if (action.getArguments() != null) {
-      for (int i = 0; i < action.getArguments().length; i++) {
+    if (action.getColumns() != null) {
+      for (int i = 0; i < action.getColumns().size(); i++) {
+        ColumnExist column  = action.getColumns().get(i);
         TableItem ti = wFields.table.getItem(i);
-        if (action.getArguments()[i] != null) {
-          ti.setText(1, action.getArguments()[i]);
-        }
+        ti.setText(1, column.getName());
       }
       wFields.setRowNums();
       wFields.optWidth(true);
@@ -365,29 +341,22 @@ public class ActionColumnsExistDialog extends 
ActionDialog implements IActionDia
       mb.open();
       return;
     }
+    
     action.setName(wName.getText());
-    action.setDatabase(getWorkflowMeta().findDatabase(wConnection.getText()));
-    action.setTablename(wTablename.getText());
-    action.setSchemaname(wSchemaname.getText());
+    action.setDatabaseMeta(wConnection.loadSelectedElement());
+    action.setTableName(wTablename.getText());
+    action.setSchemaName(wSchemaname.getText());
 
+    List<ColumnExist> columns = new ArrayList<>();
+    
     int nrItems = wFields.nrNonEmpty();
-    int nr = 0;
     for (int i = 0; i < nrItems; i++) {
-      String arg = wFields.getNonEmpty(i).getText(1);
-      if (arg != null && arg.length() != 0) {
-        nr++;
+      String name = wFields.getNonEmpty(i).getText(1);
+      if (name != null && name.length() != 0) {
+        columns.add(new ColumnExist(name));
       }
     }
-    String[] args = new String[nr];
-    nr = 0;
-    for (int i = 0; i < nrItems; i++) {
-      String arg = wFields.getNonEmpty(i).getText(1);
-      if (arg != null && arg.length() != 0) {
-        args[nr] = arg;
-        nr++;
-      }
-    }
-    action.setArguments(args);
+    action.setColumns(columns);
 
     dispose();
   }
@@ -395,10 +364,9 @@ public class ActionColumnsExistDialog extends ActionDialog 
implements IActionDia
   /** Get a list of columns */
   private void getListColumns() {
     if (!Utils.isEmpty(wTablename.getText())) {
-      DatabaseMeta databaseMeta = 
getWorkflowMeta().findDatabase(wConnection.getText());
+      DatabaseMeta databaseMeta = wConnection.loadSelectedElement();
       if (databaseMeta != null) {
-        Database database = new Database(loggingObject, variables, 
databaseMeta);
-        try {
+        try (Database database = new Database(loggingObject, variables, 
databaseMeta)) {
           database.connect();
           IRowMeta row =
               database.getTableFieldsMeta(
@@ -427,8 +395,6 @@ public class ActionColumnsExistDialog extends ActionDialog 
implements IActionDia
               BaseMessages.getString(
                   PKG, "ActionColumnsExist.ConnectionError2.DialogMessage", 
wTablename.getText()),
               e);
-        } finally {
-          database.disconnect();
         }
       }
     }
@@ -438,10 +404,9 @@ public class ActionColumnsExistDialog extends ActionDialog 
implements IActionDia
     if (wSchemaname.isDisposed()) {
       return;
     }
-    DatabaseMeta databaseMeta = 
getWorkflowMeta().findDatabase(wConnection.getText());
-    if (databaseMeta != null) {
-      Database database = new Database(loggingObject, variables, databaseMeta);
-      try {
+    DatabaseMeta databaseMeta = wConnection.loadSelectedElement();
+    if (databaseMeta != null) {      
+      try (Database database = new Database(loggingObject, variables, 
databaseMeta)) {
         database.connect();
         String[] schemas = database.getSchemas();
 
@@ -472,11 +437,6 @@ public class ActionColumnsExistDialog extends ActionDialog 
implements IActionDia
             BaseMessages.getString(PKG, "System.Dialog.Error.Title"),
             BaseMessages.getString(PKG, 
"System.Dialog.AvailableSchemas.ConnectionError"),
             e);
-      } finally {
-        if (database != null) {
-          database.disconnect();
-          database = null;
-        }
       }
     }
   }
diff --git 
a/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_en_US.properties
 
b/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_en_US.properties
index 124bbf0f74..73a5571acc 100644
--- 
a/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_en_US.properties
+++ 
b/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_en_US.properties
@@ -21,12 +21,12 @@ ActionColumnsExist.Name=Columns exist in a table
 ActionColumnsExist.Description=Check if one or several columns exist in a 
table on a specified connection
 ActionColumnsExist.Title=Columns exist in a table
 ActionColumnsExist.Name.Default=Columns exists
-ActionColumnsExist.Name.Label=Action name:
-ActionColumnsExist.Tablename.Label=Table name: 
+ActionColumnsExist.Name.Label=Action name
+ActionColumnsExist.Tablename.Label=Table name
 ActionColumnsExist.Fields.Column=Columns
 ActionColumnsExist.Fields.Argument.Label=Column
 ActionColumnsExist.Fields.Label=Colums
-ActionColumnsExist.Schemaname.Label=Schema name:
+ActionColumnsExist.Schemaname.Label=Schema name
 ActionColumnsExist.Schemaname.Tooltip=Schema name
 ActionColumnsExist.Log.TableExists=Table [{0}] exists.
 ActionColumnsExist.Log.TableNotExists=Table [{0}] doesn''t  exists.
@@ -37,7 +37,6 @@ ActionColumnsExist.Error.NoDbConnection=No database 
connection is defined.
 ActionColumnsExist.ConnectionError.DialogMessage=Please select a valid 
database connection first\!
 ActionColumnsExist.Error.TablenameEmpty=Tablename is empty. You must specify a 
tablename.
 ActionColumnsExist.Error.ColumnameEmpty=Columnname list is empty. You must 
specify a columnname.
-ActionColumnsExist.Meta.UnableLoadXml=Unable to load action of type 'column 
exists' from XML node
 ActionColumnsExist.FilenameDelete.Button=Delete
 ActionColumnsExist.FilenameDelete.Tooltip=Remove selected entries from grid
 ActionColumnsExist.GetColums.Button=Get columns
diff --git 
a/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_fr_FR.properties
 
b/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_fr_FR.properties
index 9c6e292152..132d606755 100644
--- 
a/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_fr_FR.properties
+++ 
b/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_fr_FR.properties
@@ -27,7 +27,6 @@ ActionColumnsExist.Error.ColumnameEmpty=Le nom de la colonne 
n''a pas \u00E9t\u0
 ActionColumnsExist.FilenameDelete.Tooltip=Supprimer les entr\u00E9es 
s\u00E9lectionn\u00E9es de la liste
 ActionColumnsExist.Log.ColumnExists=La colonne [{0}] existe dans la table [{1}]
 ActionColumnsExist.Schemaname.Tooltip=Nom sch\u00E9ma
-ActionColumnsExist.Meta.UnableLoadXml=Impossible de charger depuis le fichier 
XML, les informations de l''action de type 'v\u00E9rification existance colonne'
 ActionColumnsExist.Name.Label=Nom de l''action 
 ActionColumnsExist.Title=V\u00e9rification existance colonnes
 ActionColumnsExist.Fields.Column=Colonnes
diff --git 
a/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_it_IT.properties
 
b/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_it_IT.properties
index a0360a0ab2..ca9034b267 100644
--- 
a/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_it_IT.properties
+++ 
b/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_it_IT.properties
@@ -27,7 +27,6 @@ ActionColumnsExist.Fields.Column=Colonne
 ActionColumnsExist.Fields.Label=Colonne
 ActionColumnsExist.Name.Default=Le colonne esistono.
 ActionColumnsExist.Schemaname.Tooltip=Nome dello schema
-ActionColumnsExist.Meta.UnableLoadXml=Impossibile caricare la action di tipo 
'colonna esiste' dal nodo XML
 ActionColumnsExist.GetColums.Button=Preleva colonne
 ActionColumnsExist.Title=Le colonne esistono in una tabella
 ActionColumnsExist.Tablename.Label=Nome della tabella\: 
diff --git 
a/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_ja_JP.properties
 
b/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_ja_JP.properties
index 55f8b180a7..9ce285b41c 100644
--- 
a/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_ja_JP.properties
+++ 
b/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_ja_JP.properties
@@ -37,7 +37,6 @@ ActionColumnsExist.Error.NoDbConnection=No database 
connection is defined.
 ActionColumnsExist.ConnectionError.DialogMessage=Please select a valid 
database connection first\!
 ActionColumnsExist.Error.TablenameEmpty=Tablename is empty. You must specify a 
tablename.
 ActionColumnsExist.Error.ColumnameEmpty=Columnname list is empty. You must 
specify a columnname.
-ActionColumnsExist.Meta.UnableLoadXml=Unable to load action of type 'column 
exists' from XML node
 ActionColumnsExist.FilenameDelete.Button=\u5217\u306E\u524A\u9664
 
ActionColumnsExist.FilenameDelete.Tooltip=\u9078\u629E\u3057\u305F\u5217\u3092\u30EA\u30B9\u30C8\u304B\u3089\u524A\u9664\u3057\u307E\u3059\u3002
 ActionColumnsExist.GetColums.Button=\u5217\u3092\u53D6\u5F97
diff --git 
a/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_ko_KR.properties
 
b/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_ko_KR.properties
index 3f810e383c..175ea9b994 100644
--- 
a/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_ko_KR.properties
+++ 
b/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_ko_KR.properties
@@ -34,7 +34,6 @@ ActionColumnsExist.Log.ColumnExists=\uD14C\uC774\uBE14 [{1}] 
\uC5D0 \uCEEC\uB7FC
 ActionColumnsExist.Log.ColumnNotExists=\uD14C\uC774\uBE14 [{1}]\uC5D0 
\uCEEC\uB7FC [{0}] \uC774 \uC874\uC7AC\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.
 ActionColumnsExist.Log.TableExists=\uD14C\uC774\uBE14 [{0}] \uC774 
\uC874\uC7AC\uD569\uB2C8\uB2E4.
 ActionColumnsExist.Log.TableNotExists=\uD14C\uC774\uBE14 [{0}]\uC774 
\uC874\uC7AC\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.
-ActionColumnsExist.Meta.UnableLoadXml=JXML \uB178\uB4DC\uC5D0\uC11C 'column 
exists' \uD615\uC2DD\uC758 Workflow \uC5D4\uD2B8\uB9AC\uB97C \uB85C\uB4DC\uD560 
\uC218 \uC5C6\uC2B5\uB2C8\uB2E4
 ActionColumnsExist.Name.Default=\uCEEC\uB7FC\uC774 
\uC874\uC7AC\uD569\uB2C8\uB2E4
 ActionColumnsExist.Name.Label=Workflow \uC5D4\uD2B8\uB9AC \uC774\uB984: 
 ActionColumnsExist.Schemaname.Label=\uC2A4\uD0A4\uB9C8 \uC774\uB984:
diff --git 
a/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_zh_CN.properties
 
b/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_zh_CN.properties
index e2cc9020f8..5052a47233 100644
--- 
a/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_zh_CN.properties
+++ 
b/plugins/actions/columnsexist/src/main/resources/org/apache/hop/workflow/actions/columnsexist/messages/messages_zh_CN.properties
@@ -35,7 +35,6 @@ ActionColumnsExist.Log.ColumnExists=\u5217 [{0}] 
\u5B58\u5728\u4E8E\u8868 [{1}]
 ActionColumnsExist.Log.ColumnNotExists=\u5217 [{0}] 
\u4E0D\u5B58\u5728\u4E8E\u8868[{1}] \u4E2D
 ActionColumnsExist.Log.TableExists=\u8868 [{0}] \u5B58\u5728.
 ActionColumnsExist.Log.TableNotExists=\u8868 [{0}] \u4E0D\u5B58\u5728
-ActionColumnsExist.Meta.UnableLoadXml=\u4E0D\u80FD\u4ECEXML\u6587\u4EF6\u4E2D\u52A0\u8F7D
 '\u5217\u5B58\u5728' Action
 ActionColumnsExist.Name=\u8868\u5B57\u6BB5\u5B58\u5728
 ActionColumnsExist.Name.Default=\u5217\u5B58\u5728
 ActionColumnsExist.Name.Label=Action \u540D\u79F0:
diff --git 
a/plugins/actions/columnsexist/src/test/java/org/apache/hop/workflow/actions/columnsexist/ActionColumnsExistTest.java
 
b/plugins/actions/columnsexist/src/test/java/org/apache/hop/workflow/actions/columnsexist/ActionColumnsExistTest.java
new file mode 100644
index 0000000000..ba8a78d4a3
--- /dev/null
+++ 
b/plugins/actions/columnsexist/src/test/java/org/apache/hop/workflow/actions/columnsexist/ActionColumnsExistTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.columnsexist;
+
+import static org.junit.Assert.assertEquals;
+import org.apache.hop.core.HopClientEnvironment;
+import org.apache.hop.core.database.DatabaseMeta;
+import org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider;
+import org.apache.hop.workflow.action.ActionSerializationTestUtil;
+import org.junit.Test;
+
+/** Unit tests for column exist action. */
+public class ActionColumnsExistTest {
+ 
+  @Test
+  public void testSerialization() throws Exception {
+    HopClientEnvironment.init();
+    DatabaseMeta databaseMeta = new DatabaseMeta();
+    databaseMeta.setName("unit-test-db");
+    databaseMeta.setDatabaseType("NONE");
+    MemoryMetadataProvider provider = new MemoryMetadataProvider();
+    provider.getSerializer(DatabaseMeta.class).save(databaseMeta);
+
+    ActionColumnsExist action =
+        ActionSerializationTestUtil.testSerialization(
+            "/columns-exist-action.xml", ActionColumnsExist.class, provider);
+
+    assertEquals("unit-test-db", action.getDatabaseMeta().getName());
+    assertEquals("SCHEMA", action.getSchemaName());
+    assertEquals("TABLE", action.getTableName());
+    assertEquals(2, action.getColumns().size());
+    assertEquals("F2", action.getColumns().get(0).getName());
+  }
+}
diff --git 
a/plugins/actions/columnsexist/src/test/java/org/apache/hop/workflow/actions/columnsexist/WorkflowActionColumnsExistLoadSaveTest.java
 
b/plugins/actions/columnsexist/src/test/java/org/apache/hop/workflow/actions/columnsexist/WorkflowActionColumnsExistLoadSaveTest.java
deleted file mode 100644
index 9869d5a75e..0000000000
--- 
a/plugins/actions/columnsexist/src/test/java/org/apache/hop/workflow/actions/columnsexist/WorkflowActionColumnsExistLoadSaveTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.columnsexist;
-
-import org.apache.hop.junit.rules.RestoreHopEngineEnvironment;
-import 
org.apache.hop.workflow.action.loadsave.WorkflowActionLoadSaveTestSupport;
-import org.junit.ClassRule;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class WorkflowActionColumnsExistLoadSaveTest
-    extends WorkflowActionLoadSaveTestSupport<ActionColumnsExist> {
-  @ClassRule public static RestoreHopEngineEnvironment env = new 
RestoreHopEngineEnvironment();
-
-  @Override
-  protected Class<ActionColumnsExist> getActionClass() {
-    return ActionColumnsExist.class;
-  }
-
-  @Override
-  protected List<String> listAttributes() {
-    return Arrays.asList(new String[] {"database", "tablename", "schemaname", 
"arguments"});
-  }
-}
diff --git 
a/plugins/actions/columnsexist/src/test/java/org/apache/hop/workflow/actions/columnsexist/WorkflowActionColumnsExistTest.java
 
b/plugins/actions/columnsexist/src/test/java/org/apache/hop/workflow/actions/columnsexist/WorkflowActionColumnsExistTest.java
deleted file mode 100644
index 07ddec2b0c..0000000000
--- 
a/plugins/actions/columnsexist/src/test/java/org/apache/hop/workflow/actions/columnsexist/WorkflowActionColumnsExistTest.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * 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.columnsexist;
-
-import org.apache.hop.core.HopEnvironment;
-import org.apache.hop.core.Result;
-import org.apache.hop.core.database.Database;
-import org.apache.hop.core.database.DatabaseMeta;
-import org.apache.hop.core.exception.HopException;
-import org.apache.hop.core.logging.LogLevel;
-import org.apache.hop.junit.rules.RestoreHopEngineEnvironment;
-import org.apache.hop.workflow.WorkflowMeta;
-import org.apache.hop.workflow.action.ActionMeta;
-import org.apache.hop.workflow.engine.IWorkflowEngine;
-import org.apache.hop.workflow.engines.local.LocalWorkflowEngine;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-
-import static junit.framework.Assert.assertTrue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.mockito.Mockito.anyString;
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-/** Unit tests for column exist action. */
-public class WorkflowActionColumnsExistTest {
-  @ClassRule public static RestoreHopEngineEnvironment env = new 
RestoreHopEngineEnvironment();
-
-  private static final String TABLENAME = "TABLE";
-  private static final String SCHEMANAME = "SCHEMA";
-  private static final String[] COLUMNS = new String[] {"COLUMN1", "COLUMN2"};
-  private ActionColumnsExist action;
-  private Database db;
-
-  @BeforeClass
-  public static void setUpBeforeClass() throws HopException {
-    HopEnvironment.init();
-  }
-
-  @AfterClass
-  public static void tearDown() {
-    HopEnvironment.reset();
-  }
-
-  @Before
-  public void setUp() {
-    IWorkflowEngine<WorkflowMeta> parentWorkflow = new LocalWorkflowEngine(new 
WorkflowMeta());
-    action = spy(new ActionColumnsExist(""));
-    parentWorkflow.getWorkflowMeta().addAction(new ActionMeta(action));
-    parentWorkflow.setStopped(false);
-    action.setParentWorkflow(parentWorkflow);
-    parentWorkflow.setLogLevel(LogLevel.NOTHING);
-    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
-    action.setDatabase(dbMeta);
-    db = spy(new Database(action, action, dbMeta));
-    action.setParentWorkflow(parentWorkflow);
-    action.setTablename(TABLENAME);
-    action.setArguments(COLUMNS);
-    action.setSchemaname(SCHEMANAME);
-  }
-
-  @Test
-  public void jobFail_tableNameIsEmpty() throws HopException {
-    action.setTablename(null);
-    final Result result = action.execute(new Result(), 0);
-    assertEquals("Should be error", 1, result.getNrErrors());
-    assertFalse("Result should be false", result.getResult());
-  }
-
-  @Test
-  public void jobFail_columnsArrayIsEmpty() throws HopException {
-    action.setArguments(null);
-    final Result result = action.execute(new Result(), 0);
-    assertEquals("Should be error", 1, result.getNrErrors());
-    assertFalse("Result should be false", result.getResult());
-  }
-
-  @Test
-  public void jobFail_connectionIsNull() throws HopException {
-    action.setDatabase(null);
-    final Result result = action.execute(new Result(), 0);
-    assertEquals("Should be error", 1, result.getNrErrors());
-    assertFalse("Result should be false", result.getResult());
-  }
-
-  @Test
-  public void jobFail_tableNotExist() throws HopException {
-    when(action.getNewDatabaseFromMeta()).thenReturn(db);
-    doNothing().when(db).connect();
-    doReturn(false).when(db).checkTableExists(anyString(), anyString());
-
-    final Result result = action.execute(new Result(), 0);
-    assertEquals("Should be error", 1, result.getNrErrors());
-    assertFalse("Result should be false", result.getResult());
-    verify(db, atLeastOnce()).disconnect();
-  }
-
-  @Test
-  public void jobFail_columnNotExist() throws HopException {
-    doReturn(db).when(action).getNewDatabaseFromMeta();
-    doNothing().when(db).connect();
-    doReturn(true).when(db).checkTableExists(anyString(), anyString());
-    doReturn(false).when(db).checkColumnExists(anyString(), anyString(), 
anyString());
-    final Result result = action.execute(new Result(), 0);
-    assertEquals("Should be some errors", 1, result.getNrErrors());
-    assertFalse("Result should be false", result.getResult());
-    verify(db, atLeastOnce()).disconnect();
-  }
-
-  @Test
-  public void jobSuccess() throws HopException {
-    doReturn(db).when(action).getNewDatabaseFromMeta();
-    doNothing().when(db).connect();
-    doReturn(true).when(db).checkColumnExists(anyString(), anyString(), 
anyString());
-    doReturn(true).when(db).checkTableExists(anyString(), anyString());
-    final Result result = action.execute(new Result(), 0);
-    assertEquals("Should be no error", 0, result.getNrErrors());
-    assertTrue("Result should be true", result.getResult());
-    assertEquals("Lines written", COLUMNS.length, result.getNrLinesWritten());
-    verify(db, atLeastOnce()).disconnect();
-  }
-}
diff --git 
a/plugins/actions/columnsexist/src/test/resources/columns-exist-action.xml 
b/plugins/actions/columnsexist/src/test/resources/columns-exist-action.xml
new file mode 100644
index 0000000000..72d3bb808f
--- /dev/null
+++ b/plugins/actions/columnsexist/src/test/resources/columns-exist-action.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- ~ 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. ~ -->
+<action>
+       <name>Columns exist in a table</name>
+       <description />
+       <type>COLUMNS_EXIST</type>
+       <attributes />
+       <tablename>TABLE</tablename>
+       <schemaname>SCHEMA</schemaname>
+       <connection>unit-test-db</connection>
+       <fields>
+               <field>
+                       <name>F1</name>
+               </field>
+               <field>
+                       <name>F2</name>
+               </field>
+       </fields>
+       <parallel>N</parallel>
+       <xloc>224</xloc>
+       <yloc>48</yloc>
+       <attributes_hac />
+</action>
\ No newline at end of file


Reply via email to