This is an automated email from the ASF dual-hosted git repository.
davsclaus 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 6c68c1f CAMEL-14480: camel-salesforce: Conflicting relationship
names. (#4611)
6c68c1f is described below
commit 6c68c1f3e388254d61b92ccf4fe86880d0f717a2
Author: Jeremy Ross <[email protected]>
AuthorDate: Mon Nov 16 15:24:01 2020 -0600
CAMEL-14480: camel-salesforce: Conflicting relationship names. (#4611)
In salesforce, if a relationship field has the same field name as the
child relationship name, the generated DTOs end up with invalid Java
code. This commit allows the user to specify a child relationship name
suffix in order to disambiguate the field name and child relationship
name.
---
.../camel-salesforce/camel-salesforce-maven-plugin/README.md | 3 +++
.../src/main/java/org/apache/camel/maven/GenerateMojo.java | 11 +++++++++++
.../src/main/resources/sobject-pojo.vm | 10 +++++-----
3 files changed, 19 insertions(+), 5 deletions(-)
diff --git
a/components/camel-salesforce/camel-salesforce-maven-plugin/README.md
b/components/camel-salesforce/camel-salesforce-maven-plugin/README.md
index 17ba1fc..b3b4c35 100644
--- a/components/camel-salesforce/camel-salesforce-maven-plugin/README.md
+++ b/components/camel-salesforce/camel-salesforce-maven-plugin/README.md
@@ -20,6 +20,9 @@ The plugin configuration has the following properties.
* packageName - Java package name for generated DTOs, defaults to
org.apache.camel.salesforce.dto.
* customTypes - override default types in generated DTOs
* useStringsForPicklists - Use strings instead of enumerations for picklists.
Default is false.
+* childRelationshipNameSuffix - Suffix for child relationship property name.
Necessary if an SObject
+has a lookup field with the same name as its Child Relationship Name. If
setting to something other
+than default, "List" is a sensible value.
Additonal properties to provide proxy information, if behind a firewall.
diff --git
a/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
b/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
index 05f1c64..79938f9 100644
---
a/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
+++
b/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
@@ -348,6 +348,13 @@ public class GenerateMojo extends AbstractSalesforceMojo {
String packageName;
/**
+ * Suffix for child relationship property name. Necessary if an SObject
has a lookup field with the same name as its
+ * Child Relationship Name. If setting to something other than default,
"List" is a sensible value.
+ */
+ @Parameter(property = "camelSalesforce.childRelationshipNameSuffix")
+ String childRelationshipNameSuffix;
+
+ /**
* Names of specific picklist/multipicklist fields, which should be
converted to Enum (default case) if property
* {@link this#useStringsForPicklists} is set to true. Format:
SObjectApiName.FieldApiName (e.g. Account.DataSource)
*/
@@ -409,6 +416,9 @@ public class GenerateMojo extends AbstractSalesforceMojo {
parsePicklistToEnums();
parsePicklistToStrings();
+ childRelationshipNameSuffix = childRelationshipNameSuffix != null
+ ? childRelationshipNameSuffix : "";
+
// generate a source file for SObject
final VelocityContext context = new VelocityContext();
context.put("packageName", packageName);
@@ -416,6 +426,7 @@ public class GenerateMojo extends AbstractSalesforceMojo {
context.put("esc", StringEscapeUtils.class);
context.put("desc", description);
context.put("useStringsForPicklists", useStringsForPicklists);
+ context.put("childRelationshipNameSuffix",
childRelationshipNameSuffix);
final String pojoFileName = description.getName() + JAVA_EXT;
final File pojoFile = new File(pkgDir, pojoFileName);
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 40cc915..9655491 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
@@ -162,16 +162,16 @@ public class $desc.Name extends
AbstractDescribedSObjectBase {
#foreach ( $rel in $desc.childRelationships )
#set ( $hasDescription = $sObjectNames.contains($rel.childSObject) )
#if ( $utility.notNull($rel.relationshipName) && $hasDescription )
- private QueryRecords${rel.childSObject} $rel.relationshipName;
+ private QueryRecords${rel.childSObject}
${rel.relationshipName}${childRelationshipNameSuffix};
@JsonProperty("$rel.relationshipName")
- public QueryRecords${rel.childSObject} get${rel.relationshipName}() {
- return $rel.relationshipName;
+ public QueryRecords${rel.childSObject}
get${rel.relationshipName}${childRelationshipNameSuffix}() {
+ return ${rel.relationshipName}${childRelationshipNameSuffix};
}
@JsonProperty("$rel.relationshipName")
- public void set${rel.relationshipName}(QueryRecords${rel.childSObject}
${rel.relationshipName}) {
- this.${rel.relationshipName} = ${rel.relationshipName};
+ public void
set${rel.relationshipName}${childRelationshipNameSuffix}(QueryRecords${rel.childSObject}
${rel.relationshipName}) {
+ this.${rel.relationshipName}${childRelationshipNameSuffix} =
${rel.relationshipName};
}
#end
#end