You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zr...@apache.org on 2017/11/06 10:23:37 UTC
[camel] branch master updated: CAMEL-11987: skip unknown field
types in Salesf...
This is an automated email from the ASF dual-hosted git repository.
zregvart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 2a4038c CAMEL-11987: skip unknown field types in Salesf...
2a4038c is described below
commit 2a4038c66ddc86d081e96a69eb9200f9ff498fb4
Author: Zoran Regvart <zr...@apache.org>
AuthorDate: Mon Nov 6 11:21:14 2017 +0100
CAMEL-11987: skip unknown field types in Salesf...
...orce Maven plugin
Changes the Salesforce Maven plugin to emit a warning instead of
generating an exception when an unknown field type is encountered.
---
.../apache/camel/maven/CamelSalesforceMojo.java | 30 ++++++++--------------
.../src/main/resources/sobject-pojo-optional.vm | 2 +-
.../src/main/resources/sobject-pojo.vm | 4 +--
.../camel/maven/CamelSalesforceMojoOutputTest.java | 3 ++-
4 files changed, 15 insertions(+), 24 deletions(-)
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 583a9c7..ab02d6b 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
@@ -73,6 +73,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
@@ -426,7 +427,7 @@ public class CamelSalesforceMojo extends AbstractMojo {
getLog().info("Generating Java Classes...");
// generate POJOs for every object description
- final GeneratorUtility utility = new GeneratorUtility(useStringsForPicklists);
+ final GeneratorUtility utility = new GeneratorUtility(useStringsForPicklists, getLog());
// should we provide a flag to control timestamp generation?
final String generatedDate = new Date().toString();
for (SObjectDescription description : descriptions) {
@@ -724,8 +725,6 @@ public class CamelSalesforceMojo extends AbstractMojo {
// create a type map
// using JAXB mapping, for the most part
- // uses Joda time instead of XmlGregorianCalendar
- // TODO do we need support for commented types???
final String[][] typeMap = new String[][]{
{"ID", "String"}, // mapping for tns:ID SOAP type
{"string", "String"},
@@ -738,35 +737,25 @@ public class CamelSalesforceMojo extends AbstractMojo {
{"double", "Double"},
{"boolean", "Boolean"},
{"byte", "Byte"},
-// {"QName", "javax.xml.namespace.QName"},
{"dateTime", "java.time.ZonedDateTime"},
- // the blob base64Binary type is mapped to String URL for retrieving the blob
+ // the blob base64Binary type is mapped to String URL for retrieving the blob
{"base64Binary", "String"},
-// {"hexBinary", "byte[]"},
{"unsignedInt", "Long"},
{"unsignedShort", "Integer"},
{"unsignedByte", "Short"},
-// {"time", "javax.xml.datatype.XMLGregorianCalendar"},
{"time", "java.time.ZonedDateTime"},
-// {"date", "javax.xml.datatype.XMLGregorianCalendar"},
{"date", "java.time.ZonedDateTime"},
-// {"g", "javax.xml.datatype.XMLGregorianCalendar"},
{"g", "java.time.ZonedDateTime"},
- // Salesforce maps any types like string, picklist, reference, etc. to string
+ // Salesforce maps any types like string, picklist, reference, etc. to string
{"anyType", "String"},
-/*
- {"anySimpleType", "java.lang.Object"},
- {"anySimpleType", "java.lang.String"},
- {"duration", "javax.xml.datatype.Duration"},
- {"NOTATION", "javax.xml.namespace.QName"}
-*/
{"address", "org.apache.camel.component.salesforce.api.dto.Address"},
- {"location", "org.apache.camel.component.salesforce.api.dto.GeoLocation"}
+ {"location", "org.apache.camel.component.salesforce.api.dto.GeoLocation"},
+ {"RelationshipReferenceTo", "String"}
};
LOOKUP_MAP = new HashMap<String, String>();
for (String[] entry : typeMap) {
@@ -781,8 +770,10 @@ public class CamelSalesforceMojo extends AbstractMojo {
private boolean useStringsForPicklists;
private final Map<String, AtomicInteger> varNames = new HashMap<>();
private Stack<String> stack;
+ private final Log log;
- public GeneratorUtility(Boolean useStringsForPicklists) {
+ public GeneratorUtility(Boolean useStringsForPicklists, Log log) {
+ this.log = log;
this.useStringsForPicklists = Boolean.TRUE.equals(useStringsForPicklists);
}
@@ -816,8 +807,7 @@ public class CamelSalesforceMojo extends AbstractMojo {
final String soapType = field.getSoapType();
final String type = LOOKUP_MAP.get(soapType.substring(soapType.indexOf(':') + 1));
if (type == null) {
- throw new MojoExecutionException(
- String.format("Unsupported type %s for field %s", soapType, field.getName()));
+ log.warn(String.format("Unsupported field type %s in field %s of object %s", soapType, field.getName(), description.getName()));
}
return type;
}
diff --git a/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/resources/sobject-pojo-optional.vm b/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/resources/sobject-pojo-optional.vm
index 9dcfca0..3caea04 100644
--- a/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/resources/sobject-pojo-optional.vm
+++ b/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/resources/sobject-pojo-optional.vm
@@ -61,9 +61,9 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
public class ${desc.Name}Optional extends AbstractSObjectBase {
#foreach ( $field in $desc.Fields )
+#set ( ($fieldType = $utility.getFieldType($desc, $field)) && ($fieldType) )
#if ( $utility.notBaseField($field.Name) )
#set ( $fieldName = $field.Name )
-#set ( $fieldType = $utility.getFieldType($desc, $field) )
#set ( $isMultiSelectPicklist = $utility.isMultiSelectPicklist($field) )
// $fieldName
#if ( $utility.isBlobField($field) )
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 6d8e01b..a5f69d8 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
@@ -75,9 +75,9 @@ public class $desc.Name extends AbstractDescribedSObjectBase {
private static final SObjectDescription DESCRIPTION = createSObjectDescription();
#foreach ( $field in $desc.Fields )
-#if ( $utility.notBaseField($field.Name) )
-#set ( $fieldName = $field.Name )
#set ( $fieldType = $utility.getFieldType($desc, $field) )
+#if ( ($utility.notBaseField($field.Name)) && ($fieldType) )
+#set ( $fieldName = $field.Name )
#set ( $isMultiSelectPicklist = $utility.isMultiSelectPicklist($field) )
// $fieldName
#if ( $utility.isBlobField($field) )
diff --git a/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/java/org/apache/camel/maven/CamelSalesforceMojoOutputTest.java b/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/java/org/apache/camel/maven/CamelSalesforceMojoOutputTest.java
index 8b7de57..ac300cf 100644
--- a/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/java/org/apache/camel/maven/CamelSalesforceMojoOutputTest.java
+++ b/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/java/org/apache/camel/maven/CamelSalesforceMojoOutputTest.java
@@ -29,6 +29,7 @@ import org.apache.camel.component.salesforce.api.utils.JsonUtils;
import org.apache.camel.test.junit4.TestSupport;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
+import org.apache.maven.plugin.testing.SilentLog;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
@@ -58,7 +59,7 @@ public class CamelSalesforceMojoOutputTest {
public String source;
private CamelSalesforceMojo mojo;
- private CamelSalesforceMojo.GeneratorUtility utility = new CamelSalesforceMojo.GeneratorUtility(false);
+ private CamelSalesforceMojo.GeneratorUtility utility = new CamelSalesforceMojo.GeneratorUtility(false, new SilentLog());
@Parameters(name = "json = {0}, source = {2}")
public static Iterable<Object[]> parameters() throws IOException {
--
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <co...@camel.apache.org>'].