camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zregv...@apache.org
Subject camel git commit: CAMEL-11310 "code too large" when generating Sa...
Date Wed, 24 May 2017 11:38:03 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.19.x c0d70f609 -> 8e40c74c6


CAMEL-11310 "code too large" when generating Sa...

...lesforce DTOs

This changes the DTO generation by limiting the number of properties
contained in the `SObjectDescription` and as a result limiting the
length of the `createSObjectDescription` method. A static helper method
was added to `AbstractDescribedSObjectBase` for the bulk of the code
generation (generation of field descriptions) that generates field
descriptions with reduced number of properties.

Tested against a custom object with 500 custom fields (maximum).

# Conflicts:
#	components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/Case.java-Java9
#	components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/ComplexCalculatedFormula.java-Java9


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

Branch: refs/heads/camel-2.19.x
Commit: 8e40c74c63d928c277b4d400bab059e16f39f22b
Parents: c0d70f6
Author: Zoran Regvart <zregvart@apache.org>
Authored: Wed May 24 13:33:10 2017 +0200
Committer: Zoran Regvart <zregvart@apache.org>
Committed: Wed May 24 13:35:22 2017 +0200

----------------------------------------------------------------------
 .../api/dto/AbstractDescribedSObjectBase.java   |  21 ++++
 .../salesforce/api/dto/SObjectDescription.java  |  15 +++
 .../apache/camel/maven/CamelSalesforceMojo.java |  14 ++-
 .../src/main/resources/sobject-pojo.vm          |   5 +
 .../src/test/resources/generated/Case.java      | 126 +------------------
 .../generated/ComplexCalculatedFormula.java     |  42 +------
 6 files changed, 58 insertions(+), 165 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8e40c74c/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/AbstractDescribedSObjectBase.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/AbstractDescribedSObjectBase.java
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/AbstractDescribedSObjectBase.java
index cfcd260..9195276 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/AbstractDescribedSObjectBase.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/AbstractDescribedSObjectBase.java
@@ -33,4 +33,25 @@ public abstract class AbstractDescribedSObjectBase extends AbstractSObjectBase
{
      */
     public abstract SObjectDescription description();
 
+    @SuppressWarnings("boxing")
+    protected static SObjectField createField(String name, String label, String type, String
soapType, int length,
+        boolean unique, boolean nillable, boolean nameField, boolean externalId, boolean
custom, boolean caseSensitive,
+        boolean idLookup) {
+        final SObjectField field = new SObjectField();
+
+        field.setName(name);
+        field.setLabel(label);
+        field.setType(type);
+        field.setSoapType(soapType);
+        field.setLength(length);
+        field.setUnique(unique);
+        field.setNillable(nillable);
+        field.setNameField(nameField);
+        field.setExternalId(externalId);
+        field.setCustom(custom);
+        field.setCaseSensitive(caseSensitive);
+        field.setIdLookup(idLookup);
+
+        return field;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/8e40c74c/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/SObjectDescription.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/SObjectDescription.java
b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/SObjectDescription.java
index 4fb5a29..b388b7a 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/SObjectDescription.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/SObjectDescription.java
@@ -81,4 +81,19 @@ public class SObjectDescription extends SObject {
     public void setNamedLayoutInfos(List<NamedLayoutInfo> namedLayoutInfos) {
         this.namedLayoutInfos = namedLayoutInfos;
     }
+
+    /**
+     * Removes some of the less used properties from this object. Useful to reduce serialized
form or for code
+     * generation that relies on reflection.
+     */
+    public SObjectDescription prune() {
+        final SObjectDescription pruned = new SObjectDescription();
+        pruned.setName(getName());
+        pruned.setLabel(getLabel());
+        pruned.setLabelPlural(getLabelPlural());
+        pruned.fields = fields;
+        pruned.urls = urls;
+
+        return pruned;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/8e40c74c/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/CamelSalesforceMojo.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/CamelSalesforceMojo.java
b/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/CamelSalesforceMojo.java
index e9151f3..a169047 100644
--- a/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/CamelSalesforceMojo.java
+++ b/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/CamelSalesforceMojo.java
@@ -110,6 +110,8 @@ public class CamelSalesforceMojo extends AbstractMojo {
     private static final String SOBJECT_QUERY_RECORDS_OPTIONAL_VM = "/sobject-query-records-optional.vm";
     private static final String SOBJECT_PICKLIST_VM = "/sobject-picklist.vm";
 
+    private static final List<String> IGNORED_OBJECTS = Arrays.asList("FieldDefinition");
+
     // used for velocity logging, to avoid creating velocity.log
     private static final Logger LOG = Logger.getLogger(CamelSalesforceMojo.class.getName());
 
@@ -371,7 +373,14 @@ public class CamelSalesforceMojo extends AbstractMojo {
                     if (ex != null) {
                         throw ex;
                     }
-                    descriptions.add(mapper.readValue(callback.getResponse(), SObjectDescription.class));
+                    final SObjectDescription description = mapper.readValue(callback.getResponse(),
SObjectDescription.class);
+
+                    // remove some of the unused used metadata
+                    // properties in order to minimize the code size
+                    // for CAMEL-11310
+                    final SObjectDescription descriptionToAdd = description.prune();
+
+                    descriptions.add(descriptionToAdd);
                 } catch (Exception e) {
                     String msg = "Error getting SObject description for '" + name + "': "
+ e.getMessage();
                     throw new MojoExecutionException(msg, e);
@@ -399,6 +408,9 @@ public class CamelSalesforceMojo extends AbstractMojo {
             // should we provide a flag to control timestamp generation?
             final String generatedDate = new Date().toString();
             for (SObjectDescription description : descriptions) {
+                if (IGNORED_OBJECTS.contains(description.getName())) {
+                    continue;
+                }
                 try {
                     processDescription(pkgDir, description, utility, generatedDate);
                 } catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/camel/blob/8e40c74c/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/resources/sobject-pojo.vm
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/resources/sobject-pojo.vm
b/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/resources/sobject-pojo.vm
index 9087f47..6d8e01b 100644
--- a/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/resources/sobject-pojo.vm
+++ b/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/resources/sobject-pojo.vm
@@ -156,11 +156,16 @@ ${utility.pop()}
 #else
 #foreach ( $i in ${p.value} )## BEAN LIST LOOP
 #set ( $var = ${utility.variableName(${i.class.simpleName})} )
+#if ( ${i.class.simpleName} == "SObjectField" )
+        final ${i.class.simpleName} $var = createField("${i.name}", "${i.label}", "${i.type}",
"${i.soapType}", ${i.length}, ${i.unique}, ${i.nillable}, ${i.nameField}, ${i.externalId},
${i.custom}, ${i.caseSensitive}, ${i.idLookup});
+        ${utility.current()}.add(${var});
+#else
         final ${i.class.simpleName} $var = new ${i.class.simpleName}();
         ${utility.current()}.add(${var});
 ${utility.push($var)}
 #generateSource( ${i} )
 ${utility.pop()}
+#end## SObjectField CONDITION
 #end## END BEAN LIST LOOP
 ${utility.pop()}
 #end## END STRING LIST ELEMENTS

http://git-wip-us.apache.org/repos/asf/camel/blob/8e40c74c/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/Case.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/Case.java
b/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/Case.java
index af37bd1..e7f4e12 100644
--- a/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/Case.java
+++ b/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/Case.java
@@ -118,133 +118,13 @@ public class Case extends AbstractDescribedSObjectBase {
         final List<SObjectField> fields1 = new ArrayList<>();
         description.setFields(fields1);
 
-        final SObjectField sObjectField1 = new SObjectField();
+        final SObjectField sObjectField1 = createField("PickListAccentMark", "Accent Mark",
"picklist", "xsd:string", 40, false, true, false, false, false, false, false);
         fields1.add(sObjectField1);
-
-        sObjectField1.setWriteRequiresMasterRead(false);
-        sObjectField1.setNillable(true);
-        sObjectField1.setCreateable(true);
-        sObjectField1.setEncrypted(false);
-        sObjectField1.setDigits("0");
-        sObjectField1.setDependentPicklist(false);
-        sObjectField1.setInlineHelpText("This is a picklist accent mark test \u00F3");
-        sObjectField1.setLabel("Accent Mark");
-        sObjectField1.setHighScaleNumber(false);
-        sObjectField1.setDisplayLocationInDecimal(false);
-        sObjectField1.setName("PickListAccentMark");
-        sObjectField1.setHtmlFormatted(false);
-        sObjectField1.setDeprecatedAndHidden(false);
-        sObjectField1.setRestrictedPicklist(false);
-        sObjectField1.setNameField(false);
-        sObjectField1.setCaseSensitive(false);
-        sObjectField1.setPermissionable(true);
-        sObjectField1.setCascadeDelete(false);
-        sObjectField1.setDefaultedOnCreate(false);
-        sObjectField1.setExternalId(false);
-        sObjectField1.setSoapType("xsd:string");
-        sObjectField1.setGroupable(true);
-        sObjectField1.setCustom(false);
-        sObjectField1.setScale(0);
-        sObjectField1.setCalculated(false);
-        sObjectField1.setRestrictedDelete(false);
-        sObjectField1.setNamePointing(false);
-        sObjectField1.setIdLookup(false);
-        sObjectField1.setType("picklist");
-        sObjectField1.setSortable(true);
-        sObjectField1.setLength(40);
-        sObjectField1.setPrecision(0);
-        sObjectField1.setByteLength(120);
-        sObjectField1.setQueryByDistance(false);
-        sObjectField1.setFilterable(true);
-        sObjectField1.setUpdateable(true);
-        sObjectField1.setUnique(false);
-        sObjectField1.setAutoNumber(false);
-
-        final SObjectField sObjectField2 = new SObjectField();
+        final SObjectField sObjectField2 = createField("PickListSlash", "Slash", "picklist",
"xsd:string", 255, false, true, false, false, true, false, false);
         fields1.add(sObjectField2);
-
-        sObjectField2.setWriteRequiresMasterRead(false);
-        sObjectField2.setNillable(true);
-        sObjectField2.setCreateable(true);
-        sObjectField2.setEncrypted(false);
-        sObjectField2.setDigits("0");
-        sObjectField2.setDependentPicklist(false);
-        sObjectField2.setInlineHelpText("This is a picklist slash test /");
-        sObjectField2.setLabel("Slash");
-        sObjectField2.setHighScaleNumber(false);
-        sObjectField2.setDisplayLocationInDecimal(false);
-        sObjectField2.setName("PickListSlash");
-        sObjectField2.setHtmlFormatted(false);
-        sObjectField2.setDeprecatedAndHidden(false);
-        sObjectField2.setRestrictedPicklist(false);
-        sObjectField2.setNameField(false);
-        sObjectField2.setCaseSensitive(false);
-        sObjectField2.setPermissionable(true);
-        sObjectField2.setCascadeDelete(false);
-        sObjectField2.setDefaultedOnCreate(false);
-        sObjectField2.setExternalId(false);
-        sObjectField2.setSoapType("xsd:string");
-        sObjectField2.setGroupable(true);
-        sObjectField2.setCustom(true);
-        sObjectField2.setScale(0);
-        sObjectField2.setCalculated(false);
-        sObjectField2.setRestrictedDelete(false);
-        sObjectField2.setNamePointing(false);
-        sObjectField2.setIdLookup(false);
-        sObjectField2.setType("picklist");
-        sObjectField2.setSortable(true);
-        sObjectField2.setLength(255);
-        sObjectField2.setPrecision(0);
-        sObjectField2.setByteLength(765);
-        sObjectField2.setQueryByDistance(false);
-        sObjectField2.setFilterable(true);
-        sObjectField2.setUpdateable(true);
-        sObjectField2.setUnique(false);
-        sObjectField2.setAutoNumber(false);
-
-        final SObjectField sObjectField3 = new SObjectField();
+        final SObjectField sObjectField3 = createField("PickListQuotationMark", "QuotationMark",
"picklist", "xsd:string", 255, false, true, false, false, true, false, false);
         fields1.add(sObjectField3);
 
-        sObjectField3.setWriteRequiresMasterRead(false);
-        sObjectField3.setNillable(true);
-        sObjectField3.setCreateable(true);
-        sObjectField3.setEncrypted(false);
-        sObjectField3.setDigits("0");
-        sObjectField3.setDependentPicklist(false);
-        sObjectField3.setInlineHelpText("This is a picklist quotation mark test \"");
-        sObjectField3.setLabel("QuotationMark");
-        sObjectField3.setHighScaleNumber(false);
-        sObjectField3.setDisplayLocationInDecimal(false);
-        sObjectField3.setName("PickListQuotationMark");
-        sObjectField3.setHtmlFormatted(false);
-        sObjectField3.setDeprecatedAndHidden(false);
-        sObjectField3.setRestrictedPicklist(false);
-        sObjectField3.setNameField(false);
-        sObjectField3.setCaseSensitive(false);
-        sObjectField3.setPermissionable(true);
-        sObjectField3.setCascadeDelete(false);
-        sObjectField3.setDefaultedOnCreate(false);
-        sObjectField3.setExternalId(false);
-        sObjectField3.setSoapType("xsd:string");
-        sObjectField3.setGroupable(true);
-        sObjectField3.setCustom(true);
-        sObjectField3.setScale(0);
-        sObjectField3.setCalculated(false);
-        sObjectField3.setRestrictedDelete(false);
-        sObjectField3.setNamePointing(false);
-        sObjectField3.setIdLookup(false);
-        sObjectField3.setType("picklist");
-        sObjectField3.setSortable(true);
-        sObjectField3.setLength(255);
-        sObjectField3.setPrecision(0);
-        sObjectField3.setByteLength(765);
-        sObjectField3.setQueryByDistance(false);
-        sObjectField3.setFilterable(true);
-        sObjectField3.setUpdateable(true);
-        sObjectField3.setUnique(false);
-        sObjectField3.setAutoNumber(false);
-
-
         description.setActivateable(false);
         description.setLabelPlural("Casos");
         description.setDeletable(true);

http://git-wip-us.apache.org/repos/asf/camel/blob/8e40c74c/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/ComplexCalculatedFormula.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/ComplexCalculatedFormula.java
b/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/ComplexCalculatedFormula.java
index 4e550d9..fd6da8a 100644
--- a/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/ComplexCalculatedFormula.java
+++ b/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/ComplexCalculatedFormula.java
@@ -87,49 +87,9 @@ public class ComplexCalculatedFormula extends AbstractDescribedSObjectBase
{
         final List<SObjectField> fields1 = new ArrayList<>();
         description.setFields(fields1);
 
-        final SObjectField sObjectField1 = new SObjectField();
+        final SObjectField sObjectField1 = createField("ComplexCalculatedFormula", "A complex
calculated formula", "string", "xsd:string", 1300, false, true, false, false, true, false,
false);
         fields1.add(sObjectField1);
 
-        sObjectField1.setWriteRequiresMasterRead(false);
-        sObjectField1.setNillable(true);
-        sObjectField1.setCreateable(false);
-        sObjectField1.setEncrypted(false);
-        sObjectField1.setDigits("0");
-        sObjectField1.setDependentPicklist(false);
-        sObjectField1.setLabel("A complex calculated formula");
-        sObjectField1.setHighScaleNumber(false);
-        sObjectField1.setDisplayLocationInDecimal(false);
-        sObjectField1.setName("ComplexCalculatedFormula");
-        sObjectField1.setHtmlFormatted(true);
-        sObjectField1.setDeprecatedAndHidden(false);
-        sObjectField1.setRestrictedPicklist(false);
-        sObjectField1.setNameField(false);
-        sObjectField1.setCaseSensitive(false);
-        sObjectField1.setPermissionable(true);
-        sObjectField1.setCascadeDelete(false);
-        sObjectField1.setDefaultedOnCreate(false);
-        sObjectField1.setExternalId(false);
-        sObjectField1.setSoapType("xsd:string");
-        sObjectField1.setGroupable(false);
-        sObjectField1.setCustom(true);
-        sObjectField1.setScale(0);
-        sObjectField1.setCalculated(true);
-        sObjectField1.setRestrictedDelete(false);
-        sObjectField1.setNamePointing(false);
-        sObjectField1.setIdLookup(false);
-        sObjectField1.setType("string");
-        sObjectField1.setSortable(true);
-        sObjectField1.setLength(1300);
-        sObjectField1.setPrecision(0);
-        sObjectField1.setByteLength(3900);
-        sObjectField1.setQueryByDistance(false);
-        sObjectField1.setFilterable(true);
-        sObjectField1.setCalculatedFormula("IF( RecordType.Id  = \"012F0000000rmbC\", \r\n\r\nIF(Case_Age__c
> 30, \r\nIMAGE(\"/img/samples/color_red.gif\", \"red\", 30, 30),\r\nIF( Case_Age__c >
15,\r\nIMAGE(\"/img/samples/color_yellow.gif\", \"yellow\", 30, 30),\r\nIMAGE(\"/img/samples/color_green.gif\",
\"green\", 30, 30)\r\n)),\r\n\r\n\r\nIF(Case_Age__c > 10, \r\nIMAGE(\"/img/samples/color_red.gif\",
\"red\", 30, 30),\r\nIF( Case_Age__c > 5,\r\nIMAGE(\"/img/samples/color_yellow.gif\", \"yellow\",
30, 30),\r\nIMAGE(\"/img/samples/color_green.gif\", \"green\", 30, 30)\r\n))\r\n)");
-        sObjectField1.setUpdateable(false);
-        sObjectField1.setUnique(false);
-        sObjectField1.setAutoNumber(false);
-
-
         description.setActivateable(false);
         description.setLabelPlural("ComplexCalculatedFormulas");
         description.setDeletable(true);


Mime
View raw message