FAQ
Add option to use String fields for picklists instead of enums

Signed-off-by: Sune Keller <absukl@almbrand.dk>


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

Branch: refs/heads/camel-2.17.x
Commit: 80809179f592ae1a24679a5c343ddc94ea23b59f
Parents: d8726e7
Author: Sune Keller <absukl@almbrand.dk>
Authored: Mon Feb 15 14:49:21 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Jun 14 09:30:47 2016 +0200

----------------------------------------------------------------------
  .../apache/camel/maven/CamelSalesforceMojo.java | 27 ++++++++++++++++----
  .../src/main/resources/sobject-pojo.vm | 10 +++++---
  2 files changed, 29 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/80809179/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 2787ff9..c58e56a 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
@@ -247,6 +247,9 @@ public class CamelSalesforceMojo extends AbstractMojo {
      @Parameter(property = "camelSalesforce.packageName", defaultValue = "org.apache.camel.salesforce.dto")
      protected String packageName;

+ @Parameter(property = "camelSalesforce.useStringsForPicklists", defaultValue = "false")
+ protected Boolean useStringsForPicklists;
+
      private VelocityEngine engine;
      private long responseTimeout;

@@ -372,7 +375,7 @@ public class CamelSalesforceMojo extends AbstractMojo {

              getLog().info("Generating Java Classes...");
              // generate POJOs for every object description
- final GeneratorUtility utility = new GeneratorUtility();
+ final GeneratorUtility utility = new GeneratorUtility(useStringsForPicklists);
              // should we provide a flag to control timestamp generation?
              final String generatedDate = new Date().toString();
              for (SObjectDescription description : descriptions) {
@@ -562,6 +565,7 @@ public class CamelSalesforceMojo extends AbstractMojo {
              context.put("utility", utility);
              context.put("desc", description);
              context.put("generatedDate", generatedDate);
+ context.put("useStringsForPicklists", useStringsForPicklists);

              Template pojoTemplate = engine.getTemplate(SOBJECT_POJO_VM);
              pojoTemplate.merge(context, writer);
@@ -687,6 +691,11 @@ public class CamelSalesforceMojo extends AbstractMojo {
          private static final String BASE64BINARY = "base64Binary";
          private static final String MULTIPICKLIST = "multipicklist";
          private static final String PICKLIST = "picklist";
+ private Boolean useStringsForPicklists;
+
+ public GeneratorUtility(Boolean useStringsForPicklists) {
+ this.useStringsForPicklists = useStringsForPicklists;
+ }

          public boolean isBlobField(SObjectField field) {
              final String soapType = field.getSoapType();
@@ -700,11 +709,19 @@ public class CamelSalesforceMojo extends AbstractMojo {
          public String getFieldType(SObjectDescription description, SObjectField field) throws MojoExecutionException {
              // check if this is a picklist
              if (isPicklist(field)) {
- // use a pick list enum, which will be created after generating the SObject class
- return description.getName() + "_" + enumTypeName(field.getName());
+ if (useStringsForPicklists) {
+ return String.class.getName();
+ } else {
+ // use a pick list enum, which will be created after generating the SObject class
+ return description.getName() + "_" + enumTypeName(field.getName());
+ }
              } else if (isMultiSelectPicklist(field)) {
- // use a pick list enum array, enum will be created after generating the SObject class
- return description.getName() + "_" + enumTypeName(field.getName()) + "[]";
+ if (useStringsForPicklists) {
+ return description.getName() + "_" + enumTypeName(field.getName()) + "[]";
+ } else {
+ // use a pick list enum array, enum will be created after generating the SObject class
+ return enumTypeName(field.getName()) + "[]";
+ }
              } else {
                  // map field to Java type
                  final String soapType = field.getSoapType();

http://git-wip-us.apache.org/repos/asf/camel/blob/80809179/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 0e3cfa1..438d7f5 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
@@ -21,10 +21,13 @@
   */
  package $packageName;

+#if ( !$useStringsForPicklists )
  ## add imports for XStreamConverter and PicklistEnumConverter if needed
  #set ( $hasPicklists = $utility.hasPicklists($desc) )
  #set ( $hasMultiSelectPicklists = $utility.hasMultiSelectPicklists($desc) )
+#end
  import com.thoughtworks.xstream.annotations.XStreamAlias;
+#if ( !$useStringsForPicklists )
  #if ( $hasPicklists || $hasMultiSelectPicklists )
  import com.thoughtworks.xstream.annotations.XStreamConverter;
  #end
@@ -36,9 +39,10 @@ import org.apache.camel.component.salesforce.api.MultiSelectPicklistConverter;
  import org.apache.camel.component.salesforce.api.MultiSelectPicklistDeserializer;
  import org.apache.camel.component.salesforce.api.MultiSelectPicklistSerializer;
  #end
+#end
  import org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase;
  import org.codehaus.jackson.annotate.JsonProperty;
-#if ( $hasMultiSelectPicklists )
+#if ( !$useStringsForPicklists && $hasMultiSelectPicklists )
  import org.codehaus.jackson.map.annotate.JsonDeserialize;
  import org.codehaus.jackson.map.annotate.JsonSerialize;
  #end
@@ -61,9 +65,9 @@ public class $desc.Name extends AbstractSObjectBase {
  #set ( $propertyName = $fieldName )
  #end
  ## add a converter annotation if needed
-#if ( !$isMultiSelectPicklist && $utility.isPicklist($field) )
+#if ( !$useStringsForPicklists && !$isMultiSelectPicklist && $utility.isPicklist($field) )
      @XStreamConverter(PicklistEnumConverter.class)
-#elseif ( $isMultiSelectPicklist )
+#elseif ( !$useStringsForPicklists && $isMultiSelectPicklist )
      @XStreamConverter(MultiSelectPicklistConverter.class)
  #else
  ## add an alias for blob field url if needed

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 2 | next ›
Discussion Overview
groupcommits @
categoriescamel
postedJun 14, '16 at 7:31a
activeJun 14, '16 at 7:31a
posts2
users1
websitecamel.apache.org

1 user in discussion

Davsclaus: 2 posts

People

Translate

site design / logo © 2017 Grokbase