You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hop.apache.org by ha...@apache.org on 2021/02/10 06:20:47 UTC

[incubator-hop] branch master updated: Hop-2508 Fix some smell codes (#616)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new fbad114  Hop-2508 Fix some smell codes (#616)
fbad114 is described below

commit fbad114c338534bd95fd17e8d58e26f08ed0f360
Author: Nicolas Adment <39...@users.noreply.github.com>
AuthorDate: Wed Feb 10 07:20:38 2021 +0100

    Hop-2508 Fix some smell codes (#616)
    
    * Hop-2508 Fix some smell codes
    
    * Fix transform plugins category
---
 .../hop/pipeline/transforms/coalesce/Coalesce.java | 22 ++++++++++------
 .../pipeline/transforms/coalesce/CoalesceMeta.java | 29 ++++++++++++++--------
 .../transforms/coalesce/CoalesceTransform.java     |  6 ++---
 .../jsonoutputenhanced/JsonOutputMeta.java         |  2 +-
 .../transforms/mongodbinput/MongoDbInputMeta.java  |  2 +-
 .../mongodboutput/MongoDbOutputMeta.java           |  2 +-
 6 files changed, 38 insertions(+), 25 deletions(-)

diff --git a/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/Coalesce.java b/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/Coalesce.java
index ed949d3..60fd844 100644
--- a/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/Coalesce.java
+++ b/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/Coalesce.java
@@ -18,6 +18,7 @@
 package org.apache.hop.pipeline.transforms.coalesce;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.commons.lang.StringUtils;
@@ -66,15 +67,22 @@ public class Coalesce implements Cloneable {
 		super();
 	}
 
+    public Coalesce(Coalesce cloned) {
+      super();
+      this.name = cloned.name;
+      this.type = cloned.type;
+      this.removeFields = cloned.removeFields;
+      
+      Iterator<String> iterator = cloned.fields.iterator();   
+      while(iterator.hasNext())
+      {
+        fields.add(iterator.next());  
+      }
+    }
+		
 	@Override
 	public Object clone() {
-		Coalesce clone;
-		try {
-			clone = (Coalesce) super.clone();
-		} catch (CloneNotSupportedException e) {
-			return null;
-		}
-		return clone;
+		return new Coalesce(this);
 	}
 
 	public String getName() {
diff --git a/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceMeta.java b/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceMeta.java
index 06c0019..068cbb0 100644
--- a/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceMeta.java
+++ b/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceMeta.java
@@ -20,6 +20,7 @@ package org.apache.hop.pipeline.transforms.coalesce;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -83,8 +84,19 @@ public class CoalesceMeta extends BaseTransformMeta
 
   public CoalesceMeta() {
     super();
+    
   }
 
+  public CoalesceMeta(CoalesceMeta cloned) {
+    super();
+    this.emptyStringsAsNulls = cloned.emptyStringsAsNulls;    
+    Iterator<Coalesce> iterator = cloned.coalesces.iterator();   
+    while(iterator.hasNext())
+    {
+      coalesces.add(new Coalesce(iterator.next()));  
+    }
+  }
+  
   @Override
   public CoalesceTransform createTransform(
       TransformMeta transformMeta,
@@ -116,11 +128,7 @@ public class CoalesceMeta extends BaseTransformMeta
 
   @Override
   public Object clone() {
-    CoalesceMeta clone = (CoalesceMeta) super.clone();
-
-    clone.coalesces = new ArrayList<>(coalesces);
-
-    return clone;
+    return new CoalesceMeta(this);
   }
 
   @Override
@@ -291,9 +299,9 @@ public class CoalesceMeta extends BaseTransformMeta
     boolean missing = false;
     for (Coalesce coalesce : this.getCoalesces()) {
 
-      Set<String> fields = new HashSet<String>();
-      List<String> missingFields = new ArrayList<String>();
-      List<String> duplicateFields = new ArrayList<String>();
+      Set<String> fields = new HashSet<>();
+      List<String> missingFields = new ArrayList<>();
+      List<String> duplicateFields = new ArrayList<>();
 
       for (String fieldName : coalesce.getInputFields()) {
 
@@ -324,7 +332,7 @@ public class CoalesceMeta extends BaseTransformMeta
                 StringUtils.join(duplicateFields, ','));
         remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, transformMeta));
         missing = true;
-      } else if (fields.size() == 0) {
+      } else if (fields.isEmpty()) {
         String message =
             BaseMessages.getString(
                 PKG, "CoalesceMeta.CheckResult.EmptyInputFields", coalesce.getName());
@@ -358,8 +366,7 @@ public class CoalesceMeta extends BaseTransformMeta
    * If all fields are of the same data type then the output field should mirror this otherwise
    * return a more generic String type
    */
-  private int findDefaultValueType(final IRowMeta inputRowMeta, final Coalesce coalesce)
-      throws Exception {
+  private int findDefaultValueType(final IRowMeta inputRowMeta, final Coalesce coalesce) {
 
     int type = IValueMeta.TYPE_NONE;
     boolean first = true;
diff --git a/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceTransform.java b/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceTransform.java
index 77222f4..e010f2c 100644
--- a/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceTransform.java
+++ b/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceTransform.java
@@ -156,7 +156,7 @@ public class CoalesceTransform extends BaseTransform<CoalesceMeta, CoalesceData>
     IRowMeta prev = getInputRowMeta();
 
     for (Coalesce coalesce : meta.getCoalesces()) {
-      List<String> missingFields = new ArrayList<String>();
+      List<String> missingFields = new ArrayList<>();
 
       for (String field : coalesce.getInputFields()) {
 
@@ -190,9 +190,7 @@ public class CoalesceTransform extends BaseTransform<CoalesceMeta, CoalesceData>
           return index;
         } else if (meta.isTreatEmptyStringsAsNulls()
             && row[index] != null
-            && !Utils.isEmpty(row[index].toString())) {
-          return index;
-        }
+            && !Utils.isEmpty(row[index].toString())) return index;
       }
     }
 
diff --git a/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/jsonoutputenhanced/JsonOutputMeta.java b/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/jsonoutputenhanced/JsonOutputMeta.java
index 52c3642..f789f50 100644
--- a/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/jsonoutputenhanced/JsonOutputMeta.java
+++ b/plugins/transforms/json/src/main/java/org/apache/hop/pipeline/transforms/jsonoutputenhanced/JsonOutputMeta.java
@@ -50,7 +50,7 @@ import java.util.List;
         name = "EnhancedJsonOutput.name",
         i18nPackageName = "org.apache.hop.pipeline.transforms.jsonoutput.enhanced",
         description = "EnhancedJsonOutput.description",
-        categoryDescription = "EnhancedJsonOutput.category",
+        categoryDescription = "i18n:org.apache.hop.pipeline.transform:BaseTransform.Category.Output",
         keywords = { "json", "javascript", "object", "notation" },
         documentationUrl = "https://hop.apache.org/manual/latest/plugins/transforms/enhancedjsonoutput.html")
 @InjectionSupported(localizationPrefix = "JsonOutput.Injection.", groups = {"GENERAL", "FIELDS"})
diff --git a/plugins/transforms/mongodb/src/main/java/org/apache/hop/pipeline/transforms/mongodbinput/MongoDbInputMeta.java b/plugins/transforms/mongodb/src/main/java/org/apache/hop/pipeline/transforms/mongodbinput/MongoDbInputMeta.java
index c8287da..c73cc24 100644
--- a/plugins/transforms/mongodb/src/main/java/org/apache/hop/pipeline/transforms/mongodbinput/MongoDbInputMeta.java
+++ b/plugins/transforms/mongodb/src/main/java/org/apache/hop/pipeline/transforms/mongodbinput/MongoDbInputMeta.java
@@ -57,7 +57,7 @@ import java.util.List;
     name = "MongoDB input",
     description = "Reads from a Mongo DB collection",
     documentationUrl = "https://hop.apache.org/manual/latest/plugins/transforms/mongodbinput.html",
-    categoryDescription = "Input")
+    categoryDescription = "i18n:org.apache.hop.pipeline.transform:BaseTransform.Category.Input")
 @InjectionSupported(localizationPrefix = "MongoDbInput.Injection.", groups = ("FIELDS"))
 public class MongoDbInputMeta extends MongoDbMeta<MongoDbInput, MongoDbInputData>
     implements ITransformMeta<MongoDbInput, MongoDbInputData> {
diff --git a/plugins/transforms/mongodb/src/main/java/org/apache/hop/pipeline/transforms/mongodboutput/MongoDbOutputMeta.java b/plugins/transforms/mongodb/src/main/java/org/apache/hop/pipeline/transforms/mongodboutput/MongoDbOutputMeta.java
index c23c554..3541783 100644
--- a/plugins/transforms/mongodb/src/main/java/org/apache/hop/pipeline/transforms/mongodboutput/MongoDbOutputMeta.java
+++ b/plugins/transforms/mongodb/src/main/java/org/apache/hop/pipeline/transforms/mongodboutput/MongoDbOutputMeta.java
@@ -53,7 +53,7 @@ import java.util.List;
     name = "MongoDB output",
     description = "Writes to a Mongo DB collection",
     documentationUrl = "https://hop.apache.org/manual/latest/plugins/transforms/mongodboutput.html",
-    categoryDescription = "Output")
+    categoryDescription = "i18n:org.apache.hop.pipeline.transform:BaseTransform.Category.Output")
 @InjectionSupported(
     localizationPrefix = "MongoDbOutput.Injection.",
     groups = {"FIELDS", "INDEXES"})