camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: Salesforce Composite API cleanup
Date Thu, 05 Jan 2017 14:40:55 GMT
Repository: camel
Updated Branches:
  refs/heads/master 57ca71a3e -> da4352cc1


Salesforce Composite API cleanup

This commit does not introduce any new functionality, its purpose is to
reduce technical debt by the way of simple code cleanup.

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/da4352cc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/da4352cc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/da4352cc

Branch: refs/heads/master
Commit: da4352cc1c825cbf8b6be13463b592f9af9d53ae
Parents: 57ca71a
Author: Zoran Regvart <zoran@regvart.com>
Authored: Thu Jan 5 14:53:16 2017 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Jan 5 15:39:50 2017 +0100

----------------------------------------------------------------------
 .../api/dto/composite/MapOfMapsConverter.java     | 18 +++++++++---------
 .../api/dto/composite/SObjectBatch.java           |  6 ++++--
 .../salesforce/api/dto/composite/SObjectNode.java | 12 ++++++++----
 .../salesforce/api/dto/composite/SObjectTree.java | 10 +++++-----
 .../api/dto/composite/MapOfMapsConverterTest.java |  1 -
 5 files changed, 26 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/da4352cc/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/MapOfMapsConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/MapOfMapsConverter.java
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/MapOfMapsConverter.java
index 9eeba0a..9cd9fae 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/MapOfMapsConverter.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/MapOfMapsConverter.java
@@ -28,6 +28,8 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
 
 public class MapOfMapsConverter implements Converter {
 
+    private static final String ATTRIBUTES_PROPERTY = "attributes";
+
     @Override
     public boolean canConvert(final Class type) {
         return true;
@@ -56,24 +58,22 @@ public class MapOfMapsConverter implements Converter {
 
             final Map<String, String> attributes = new HashMap<>();
             final Iterator attributeNames = reader.getAttributeNames();
-            if (attributeNames.hasNext()) {
-                while (attributeNames.hasNext()) {
-                    final String attributeName = (String) attributeNames.next();
-                    attributes.put(attributeName, reader.getAttribute(attributeName));
-                }
+            while (attributeNames.hasNext()) {
+                final String attributeName = (String)attributeNames.next();
+                attributes.put(attributeName, reader.getAttribute(attributeName));
             }
 
             Object nested = readMap(reader, new HashMap<>());
             if (!attributes.isEmpty()) {
                 if (nested instanceof String) {
-                    HashMap<Object, Object> newNested = new HashMap<>();
+                    final Map<Object, Object> newNested = new HashMap<>();
                     newNested.put(key, nested);
-                    newNested.put("attributes", attributes);
+                    newNested.put(ATTRIBUTES_PROPERTY, attributes);
                     nested = newNested;
                 } else {
                     @SuppressWarnings("unchecked")
-                    final Map<String, Object> nestedMap = (Map<String, Object>)
nested;
-                    nestedMap.put("attributes", attributes);
+                    final Map<String, Object> nestedMap = (Map<String, Object>)nested;
+                    nestedMap.put(ATTRIBUTES_PROPERTY, attributes);
                 }
             }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/da4352cc/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectBatch.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectBatch.java
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectBatch.java
index 950ce6f..8550e27 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectBatch.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectBatch.java
@@ -72,6 +72,8 @@ import static org.apache.camel.util.StringHelper.notEmpty;
 @XStreamAlias("batch")
 public final class SObjectBatch implements Serializable {
 
+    private static final String SOBJECT_TYPE_PARAM = "type";
+
     public enum Method {
         DELETE, GET, PATCH, POST
     }
@@ -406,12 +408,12 @@ public final class SObjectBatch implements Serializable {
     }
 
     String rowBaseUrl(final String type, final String id) {
-        return apiPrefix + "/sobjects/" + notEmpty(type, "type") + "/" + notEmpty(id, "id");
+        return apiPrefix + "/sobjects/" + notEmpty(type, SOBJECT_TYPE_PARAM) + "/" + notEmpty(id,
"id");
     }
 
     String rowBaseUrl(final String type, final String fieldName, final String fieldValue)
{
         try {
-            return apiPrefix + "/sobjects/" + notEmpty(type, "type") + "/" + notEmpty(fieldName,
"fieldName") + "/"
+            return apiPrefix + "/sobjects/" + notEmpty(type, SOBJECT_TYPE_PARAM) + "/" +
notEmpty(fieldName, "fieldName") + "/"
                 + URLEncoder.encode(notEmpty(fieldValue, "fieldValue"), StandardCharsets.UTF_8.name());
         } catch (final UnsupportedEncodingException e) {
             throw new IllegalStateException(e);

http://git-wip-us.apache.org/repos/asf/camel/blob/da4352cc/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectNode.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectNode.java
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectNode.java
index 9edfcfe..afa8555 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectNode.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectNode.java
@@ -63,6 +63,10 @@ import org.apache.camel.util.ObjectHelper;
 @XStreamConverter(SObjectNodeXStreamConverter.class)
 public final class SObjectNode implements Serializable {
 
+    private static final String CHILD_PARAM = "child";
+
+    private static final String SOBJECT_TYPE_PARAM = "type";
+
     private static final long serialVersionUID = 1L;
 
     @JsonProperty
@@ -113,7 +117,7 @@ public final class SObjectNode implements Serializable {
      * @return the newly created node, used in builder fashion to add more child objects
to it (on the next level)
      */
     public SObjectNode addChild(final AbstractDescribedSObjectBase child) {
-        ObjectHelper.notNull(child, "child");
+        ObjectHelper.notNull(child, CHILD_PARAM);
 
         return addChild(pluralOf(child), child);
     }
@@ -130,7 +134,7 @@ public final class SObjectNode implements Serializable {
      */
     public SObjectNode addChild(final String labelPlural, final AbstractSObjectBase child)
{
         ObjectHelper.notNull(labelPlural, "labelPlural");
-        ObjectHelper.notNull(child, "child");
+        ObjectHelper.notNull(child, CHILD_PARAM);
 
         final SObjectNode node = new SObjectNode(referenceGenerator, typeOf(child), child);
 
@@ -194,7 +198,7 @@ public final class SObjectNode implements Serializable {
      * @return children of this node of specified type
      */
     public Stream<SObjectNode> getChildNodesOfType(final String type) {
-        ObjectHelper.notNull(type, "type");
+        ObjectHelper.notNull(type, SOBJECT_TYPE_PARAM);
 
         return records.getOrDefault(type, Collections.emptyList()).stream();
     }
@@ -217,7 +221,7 @@ public final class SObjectNode implements Serializable {
      * @return child SObjects of this node
      */
     public Stream<AbstractSObjectBase> getChildrenOfType(final String type) {
-        ObjectHelper.notNull(type, "type");
+        ObjectHelper.notNull(type, SOBJECT_TYPE_PARAM);
 
         return records.getOrDefault(type, Collections.emptyList()).stream().map(SObjectNode::getObject);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/da4352cc/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectTree.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectTree.java
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectTree.java
index 8bb694c..8b99b13 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectTree.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/composite/SObjectTree.java
@@ -181,7 +181,7 @@ public final class SObjectTree implements Serializable {
     public void setErrorFor(final String referenceId, final List<RestError> errors)
{
         for (final SObjectNode node : records) {
             if (setErrorFor(node, referenceId, errors)) {
-                break;
+                return;
             }
         }
     }
@@ -197,7 +197,7 @@ public final class SObjectTree implements Serializable {
     public void setIdFor(final String referenceId, final String id) {
         for (final SObjectNode node : records) {
             if (setIdFor(node, referenceId, id)) {
-                break;
+                return;
             }
         }
     }
@@ -248,7 +248,7 @@ public final class SObjectTree implements Serializable {
             final Object object = node.getObject();
 
             if (object instanceof AbstractSObjectBase) {
-                return updateBaseObjectId(id, object);
+                return updateBaseObjectId(id, (AbstractSObjectBase) object);
             } else {
                 return updateGeneralObjectId(id, object);
             }
@@ -258,8 +258,8 @@ public final class SObjectTree implements Serializable {
             .anyMatch(n -> setIdFor(n, referenceId, id));
     }
 
-    boolean updateBaseObjectId(final String id, final Object object) {
-        ((AbstractSObjectBase) object).setId(id);
+    boolean updateBaseObjectId(final String id, final AbstractSObjectBase object) {
+        object.setId(id);
 
         return true;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/da4352cc/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/composite/MapOfMapsConverterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/composite/MapOfMapsConverterTest.java
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/composite/MapOfMapsConverterTest.java
index e47209f..3e587b6 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/composite/MapOfMapsConverterTest.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/composite/MapOfMapsConverterTest.java
@@ -44,7 +44,6 @@ public class MapOfMapsConverterTest {
     public MapOfMapsConverterTest() throws XmlPullParserException {
         final XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
         parser = factory.newPullParser();
-
     }
 
     @Test


Mime
View raw message