You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/05/23 08:02:54 UTC

[camel-spring-boot-examples] branch main updated: Update twitter-salesforce example (#60)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot-examples.git


The following commit(s) were added to refs/heads/main by this push:
     new 7279cb4  Update twitter-salesforce example (#60)
7279cb4 is described below

commit 7279cb41e00ff051c1a64e8b30e29038e34cea0f
Author: smongiar <63...@users.noreply.github.com>
AuthorDate: Mon May 23 10:02:49 2022 +0200

    Update twitter-salesforce example (#60)
---
 twitter-salesforce/README.adoc                     |  35 +++----
 twitter-salesforce/pom.xml                         | 105 +++++++++++++++++----
 .../org/apache/camel/example/mention/Contact.java  |  61 ------------
 .../example/mention/TwitterSalesforceRoute.java    |  19 +++-
 .../apache/camel/salesforce/draftdto/Contact.java  |   6 ++
 .../src/main/resources/application.properties      |   2 +-
 6 files changed, 126 insertions(+), 102 deletions(-)

diff --git a/twitter-salesforce/README.adoc b/twitter-salesforce/README.adoc
index bb53a85..3af2817 100644
--- a/twitter-salesforce/README.adoc
+++ b/twitter-salesforce/README.adoc
@@ -72,26 +72,18 @@ Allow access to the application, and you’ll end up on a page with
 ==== How to generate Salesforce Data Transfer Objects (DTOs)
 
 The best way to generate Java representation of Salesforce SObjects is
-to use the `+camel-salesforce-maven-plugin+`, for example:
+to use the `+camel-salesforce-maven-plugin+` and specify the desired DTO in <configuration> section, for example:
 
 ....
-$ mvn org.apache.camel.maven:camel-salesforce-maven-plugin:generate \
-  -DcamelSalesforce.clientId=<client id> \
-  -DcamelSalesforce.clientSecret=<client secret> \
-  -DcamelSalesforce.userName=<username> \
-  -DcamelSalesforce.password=<password>
-....
-
-You can specify the only the SObjects you’ll integrate with using
-`+camelSalesforce.includePattern+` parameter, like:
-
-....
-$ mvn org.apache.camel.maven:camel-salesforce-maven-plugin:generate \
-  -DcamelSalesforce.clientId=<client id> \
-  -DcamelSalesforce.clientSecret=<client secret> \
-  -DcamelSalesforce.userName=<username> \
-  -DcamelSalesforce.password=<password> \
-  -DcamelSalesforce.includePattern=Contact
+        <configuration>
+            <clientId>${camelSalesforce.clientId}</clientId>
+            <clientSecret>${camelSalesforce.clientSecret}</clientSecret>
+            <userName>${camelSalesforce.userName}</userName>
+            <password>${camelSalesforce.password}</password>
+            <includes>
+                <include>Contact</include>
+            </includes>
+        </configuration>
 ....
 
 To generate only DTOs needed for Contact, but the parameter value can be
@@ -107,10 +99,13 @@ mvn compile
 
 === Run
 
-To run the example type
+To run the example type using _generate.dto_ profile
 
 ....
-mvn spring-boot:run
+mvn -DcamelSalesforce.clientId=3<client id> \
+    -DcamelSalesforce.clientSecret=<client secret> \
+    -DcamelSalesforce.userName=<username> \
+    -DcamelSalesforce.password=<password> -Dgenerate.dto spring-boot:run
 ....
 
 To stop the example hit ctrl+c
diff --git a/twitter-salesforce/pom.xml b/twitter-salesforce/pom.xml
index eb7f6e3..5f88d26 100644
--- a/twitter-salesforce/pom.xml
+++ b/twitter-salesforce/pom.xml
@@ -32,9 +32,14 @@
     <name>Camel SB Examples :: Twitter Salesforce</name>
     <description>Twitter mentions is created as contacts in Salesforce</description>
 
-    <properties>
-        <category>Social</category>
-    </properties>
+	<properties>
+		<category>Social</category>
+		<spring.boot-version>${spring-boot-version}</spring.boot-version>
+		<camelSalesforce.clientId>3MVG9szVa2RxsqBZXHfqsW3hf9HQp_N6qdSmpjKMzSJaEL4UP161JlDkE32EigL82ra_jM1WuQgF4rYDgzL3u</camelSalesforce.clientId>
+		<camelSalesforce.clientSecret>1039611643161946846</camelSalesforce.clientSecret>
+		<camelSalesforce.userName>testUser@gmail.com</camelSalesforce.userName>
+		<camelSalesforce.password>testPassword</camelSalesforce.password>
+	</properties>
 
     <dependencyManagement>
         <dependencies>
@@ -104,20 +109,84 @@
         <!-- we do not want version in the JAR name -->
         <finalName>${project.artifactId}</finalName>
 
-        <plugins>
-            <plugin>
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-maven-plugin</artifactId>
-                <version>${spring-boot-version}</version>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>repackage</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
+		<plugins>
+			<plugin>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-maven-plugin</artifactId>
+				<version>${spring.boot-version}</version>
+				<configuration>
+					<systemPropertyVariables>
+						<camel.component.salesforce.clientId>${camelSalesforce.clientId}</camel.component.salesforce.clientId>
+						<camel.component.salesforce.clientSecret>${camelSalesforce.clientSecret}</camel.component.salesforce.clientSecret>
+						<camel.component.salesforce.userName>${camelSalesforce.userName}</camel.component.salesforce.userName>
+						<camel.component.salesforce.password>${camelSalesforce.password}</camel.component.salesforce.password>
+						<camel.component.salesforce.loginUrl>https://login.salesforce.com</camel.component.salesforce.loginUrl>
+					</systemPropertyVariables>
+				</configuration>
+				<executions>
+					<execution>
+						<goals>
+							<goal>repackage</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.codehaus.mojo</groupId>
+				<artifactId>build-helper-maven-plugin</artifactId>
+				<executions>
+					<execution>
+						<id>add-source</id>
+						<phase>generate-sources</phase>
+						<goals>
+							<goal>add-source</goal>
+						</goals>
+						<configuration>
+							<sources>
+								<source>${project.build.directory}/generated-sources/camel-salesforce</source>
+							</sources>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+
+	<profiles>
+		<profile>
+			<id>generate-salesforce-dto</id>
+			<activation>
+				<property>
+					<name>generate.dto</name>
+					<value>true</value>
+				</property>
+			</activation>
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>org.apache.camel.maven</groupId>
+						<artifactId>camel-salesforce-maven-plugin</artifactId>
+						<executions>
+							<execution>
+								<goals>
+									<goal>generate</goal>
+								</goals>
+								<configuration>
+									<clientId>${camelSalesforce.clientId}</clientId>
+									<clientSecret>${camelSalesforce.clientSecret}</clientSecret>
+									<userName>${camelSalesforce.userName}</userName>
+									<password>${camelSalesforce.password}</password>
+									<includes>
+										<include>Contact</include>
+									</includes>
+								</configuration>
+							</execution>
+						</executions>
+					</plugin>
+
+				</plugins>
+			</build>
+		</profile>
+	</profiles>
 
 </project>
diff --git a/twitter-salesforce/src/main/java/org/apache/camel/example/mention/Contact.java b/twitter-salesforce/src/main/java/org/apache/camel/example/mention/Contact.java
deleted file mode 100644
index f8aa6fd..0000000
--- a/twitter-salesforce/src/main/java/org/apache/camel/example/mention/Contact.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * Salesforce DTO generated by camel-salesforce-maven-plugin
- * Generated on: Mon Apr 06 17:56:36 PDT 2015
- */
-package org.apache.camel.example.mention;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import org.apache.camel.component.salesforce.api.dto.AbstractDescribedSObjectBase;
-import org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase;
-
-/**
- * Contact Data Transfer Object (DTO) needed for Salesforce component.
- *<p>
- * This is a trivial, hand coded, example of DTO for Contact SObject,
- * for production use you would most likely want to generate these
- * using {@code camel-salesforce-maven-plugin} as it adds all fields
- * and generates {@link AbstractDescribedSObjectBase} based classes,
- * which are needed for some of the operations (like composite API).
- */
-// CHECKSTYLE:OFF
-public class Contact extends AbstractSObjectBase {
-
-    @JsonProperty("LastName")
-    private final String lastName;
-
-    @JsonProperty("TwitterScreenName__c")
-    private String screenName;
-
-    @JsonCreator
-    public Contact(@JsonProperty("LastName") String lastName,
-                   @JsonProperty("TwitterScreenName__c") String screenName) {
-        this.lastName = lastName;
-        this.screenName = screenName;
-    }
-
-    public String getTwitterScreenName__c() {
-        return screenName;
-    }
-
-    public void setTwitterScreenName__c(String screenName) {
-        this.screenName = screenName;
-    }
-}
-// CHECKSTYLE:ON
diff --git a/twitter-salesforce/src/main/java/org/apache/camel/example/mention/TwitterSalesforceRoute.java b/twitter-salesforce/src/main/java/org/apache/camel/example/mention/TwitterSalesforceRoute.java
index 471210e..2f1f6a9 100644
--- a/twitter-salesforce/src/main/java/org/apache/camel/example/mention/TwitterSalesforceRoute.java
+++ b/twitter-salesforce/src/main/java/org/apache/camel/example/mention/TwitterSalesforceRoute.java
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.example.mention;
 
+import java.lang.Class;
+import java.lang.reflect.Method;
+import org.apache.camel.salesforce.draftdto.Contact;
 import org.apache.camel.builder.RouteBuilder;
 import org.springframework.stereotype.Component;
 import twitter4j.Status;
@@ -33,8 +36,20 @@ public class TwitterSalesforceRoute extends RouteBuilder {
                 User user = status.getUser();
                 String name = user.getName();
                 String screenName = user.getScreenName();
-                Contact contact = new Contact(name, screenName);
-                exchange.getIn().setBody(contact);
+                Class contact = null;
+                if (Class.forName("org.apache.camel.salesforce.dto.Contact") != null) {
+                    contact = Class.forName("org.apache.camel.salesforce.dto.Contact");
+                } else {
+                    contact = Contact.class;
+                }
+
+                Object contactObject = contact.newInstance();
+                Method setLastName = contact.getMethod("setLastName", String.class);
+                Method setTwitterScreenName__c = contact.getMethod("setTwitterScreenName__c", String.class);
+                setLastName.invoke(contactObject, name);
+                setTwitterScreenName__c.invoke(contactObject, screenName);
+                exchange.getIn().setBody(contactObject);
+
             })
             .to("salesforce:upsertSObject?sObjectIdName=TwitterScreenName__c")
             .log("SObject ID: ${body?.id}");
diff --git a/twitter-salesforce/src/main/java/org/apache/camel/salesforce/draftdto/Contact.java b/twitter-salesforce/src/main/java/org/apache/camel/salesforce/draftdto/Contact.java
new file mode 100644
index 0000000..4d46cf3
--- /dev/null
+++ b/twitter-salesforce/src/main/java/org/apache/camel/salesforce/draftdto/Contact.java
@@ -0,0 +1,6 @@
+package org.apache.camel.salesforce.draftdto;
+
+public abstract class Contact {
+    public abstract void setLastName(String LastName);
+    public abstract void setTwitterScreenName__c(String TwitterScreenName__c);
+}
diff --git a/twitter-salesforce/src/main/resources/application.properties b/twitter-salesforce/src/main/resources/application.properties
index 411da3a..41d23f1 100644
--- a/twitter-salesforce/src/main/resources/application.properties
+++ b/twitter-salesforce/src/main/resources/application.properties
@@ -33,7 +33,7 @@ camel.component.salesforce.clientId=3MVG9szVa2RxsqBZXHfqsW3hf9HQp_N6qdSmpjKMzSJa
 ## Consumer Secret of the connected application
 camel.component.salesforce.clientSecret=1039611643161946846
 ## refresh_token from OAuth flow
-camel.component.salesforce.refreshToken=5Aep861HDR3iASSXIX6hI7M1qMWSCs1Ym57WUH1ftjE7RvnM7MvnAXx9EZaw_HIoNCKktNsuhx.xwjLThofuJH4
+#camel.component.salesforce.refreshToken=5Aep861HDR3iASSXIX6hI7M1qMWSCs1Ym57WUH1ftjE7RvnM7MvnAXx9EZaw_HIoNCKktNsuhx.xwjLThofuJH4
 ## you can also use:
 #camel.component.salesforce.userName=<Salesforce username>
 #camel.component.salesforce.password=<Salesforce password>