├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── pom.xml └── src ├── main ├── java │ └── org │ │ └── springframework │ │ └── social │ │ ├── connect │ │ └── support │ │ │ ├── RefreshingOAuth2Connection.java │ │ │ └── RefreshingOAuth2ConnectionFactory.java │ │ └── salesforce │ │ ├── api │ │ ├── AbstractLimits.java │ │ ├── ApiOperations.java │ │ ├── ApiVersion.java │ │ ├── ChatterOperations.java │ │ ├── Community.java │ │ ├── CommunityUser.java │ │ ├── ConnectOperations.java │ │ ├── CustomApiOperations.java │ │ ├── Field.java │ │ ├── InvalidIDException.java │ │ ├── InvalidSalesforceApiVersionException.java │ │ ├── LimitResult.java │ │ ├── LimitsOperations.java │ │ ├── LimitsResults.java │ │ ├── Photo.java │ │ ├── PickListEntry.java │ │ ├── QueryOperations.java │ │ ├── QueryResult.java │ │ ├── RecentOperations.java │ │ ├── RecordTypeInfo.java │ │ ├── Relationship.java │ │ ├── ResultItem.java │ │ ├── SObjectDetail.java │ │ ├── SObjectOperations.java │ │ ├── SObjectSummary.java │ │ ├── Salesforce.java │ │ ├── SalesforceProfile.java │ │ ├── SalesforceRequestException.java │ │ ├── SalesforceUserDetails.java │ │ ├── SearchOperations.java │ │ ├── Status.java │ │ ├── UserOperations.java │ │ └── impl │ │ │ ├── AbstractSalesForceOperations.java │ │ │ ├── ApiRequestInterceptor.java │ │ │ ├── ApiTemplate.java │ │ │ ├── ChatterTemplate.java │ │ │ ├── ConnectTemplate.java │ │ │ ├── CustomApiTemplate.java │ │ │ ├── HeaderAddingInterceptor.java │ │ │ ├── LimitsOperationsTemplate.java │ │ │ ├── QueryTemplate.java │ │ │ ├── RecentTemplate.java │ │ │ ├── SObjectsTemplate.java │ │ │ ├── SalesforceErrorHandler.java │ │ │ ├── SalesforceTemplate.java │ │ │ ├── SearchTemplate.java │ │ │ ├── UserOperationsTemplate.java │ │ │ └── json │ │ │ ├── ApiVersionMixin.java │ │ │ ├── FieldMixin.java │ │ │ ├── PhotoMixin.java │ │ │ ├── PickListEntryMixin.java │ │ │ ├── QueryResultMixin.java │ │ │ ├── RecordTypeInfoMixin.java │ │ │ ├── RelationshipMixin.java │ │ │ ├── ResultItemDeserializer.java │ │ │ ├── ResultItemMixin.java │ │ │ ├── SObjectDetailMixin.java │ │ │ ├── SObjectSummaryMixin.java │ │ │ ├── SalesforceModule.java │ │ │ ├── SalesforceProfileMixin.java │ │ │ ├── SalesforceUserDetailsMixin.java │ │ │ └── StatusMixin.java │ │ ├── client │ │ ├── BaseSalesforceFactory.java │ │ ├── ErrorHandler.java │ │ ├── SalesforceFactory.java │ │ └── SimpleCachingSalesforceFactory.java │ │ ├── config │ │ ├── support │ │ │ └── SalesforceApiHelper.java │ │ └── xml │ │ │ ├── SalesforceConfigBeanDefinitionParser.java │ │ │ └── SalesforceNamespaceHandler.java │ │ ├── connect │ │ ├── SalesforceAdapter.java │ │ ├── SalesforceConnectionFactory.java │ │ ├── SalesforceOAuth2Template.java │ │ └── SalesforceServiceProvider.java │ │ └── security │ │ └── SalesforceAuthenticationService.java └── resources │ ├── META-INF │ ├── spring.handlers │ └── spring.schemas │ └── org │ └── springframework │ └── social │ └── salesforce │ └── config │ └── xml │ └── spring-social-salesforce-1.0.xsd └── test ├── java └── org │ └── springframework │ └── social │ └── salesforce │ └── api │ ├── client │ └── BaseSalesforceFactoryTest.java │ └── impl │ ├── AbstractSalesforceTest.java │ ├── ApiTest.java │ ├── ChatterTemplateTest.java │ ├── ConnectOperationsTest.java │ ├── CustomApiOperationTest.java │ ├── LimitsTemplateTest.java │ ├── MetaApiTemplateTest.java │ ├── QueryTemplateTest.java │ ├── RecentTemplateTest.java │ ├── SObjectsTemplateTest.java │ ├── SearchTemplateTest.java │ └── UserOperationsTemplateTest.java └── resources ├── account.json ├── account2.json ├── account_desc.json ├── chatter-status.json ├── client-token.json ├── communities.json ├── community-users.json ├── customApi1.json ├── limits.json ├── logback-test.xml ├── profile.json ├── query-child2parent.json ├── query-count.json ├── query-groupby.json ├── query-parent2child.json ├── query-simple.json ├── query-where.json ├── recent.json ├── search.json ├── services.json ├── services2.json ├── sobjects.json ├── userDetails.json └── versions.json /.gitignore: -------------------------------------------------------------------------------- 1 | ApiTestLocal.java 2 | target 3 | *.iml 4 | *.ipr 5 | .idea 6 | .project 7 | .settings 8 | .classpath 9 | .vscode/settings.json 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spring Social Salesforce [![Build Status](https://travis-ci.org/jottley/spring-social-salesforce.svg?branch=master)](https://travis-ci.org/jottley/spring-social-salesforce) [![](https://img.shields.io/static/v1?label=Download&message=1.2.3.RELEASE&color=green)](https://repo.repsy.io/mvn/jottley/spring-social-salesforce/org/springframework/social/spring-social-salesforce/1.2.3.RELEASE) 2 | 3 | Spring Social Salesforce is a Spring Social extension that provides connection support and API binding for the Salesforce 4 | REST API. 5 | 6 | To check out the project and build from source, do the following: 7 | 8 | git clone git://github.com/jottley/spring-social-salesforce.git 9 | cd spring-social-salesforce 10 | mvn clean install 11 | 12 | ## Maven 13 | To include in your maven project, use the following repository and dependency 14 | 15 | 16 | ... 17 | 18 | repsy 19 | https://repo.repsy.io/mvn/jottley/spring-social-salesforce 20 | 21 | ... 22 | 23 | 24 | 25 | ... 26 | 27 | org.springframework.social 28 | spring-social-salesforce 29 | 1.2.3.RELEASE 30 | 31 | ... 32 | 33 | 34 | ## Quickstart 35 | There is a spring boot quickstart app available at https://github.com/jottley/spring-social-salesforce-quickstart 36 | 37 | ## Supported Operations 38 | - Retrieve all available API versions 39 | - Retrieve services supported by a specific version of the API 40 | - Retrieve the list of sObjects 41 | - Retrieve summary-metadata of a sObject 42 | - Retrieve full-metadata of a sObject 43 | - Retrieve a row from a sObject 44 | - Retrieve a blob from a row in a sObject 45 | - Create a new sObject 46 | - Update an existing sObject 47 | - Retrieve recent changes feed 48 | - Execute a SOSL search and retrieve the results (with paging or all) 49 | - Run a SOQL query and retrieve the results (with paging or all) 50 | - query results can optionally include deleted records 51 | - Retrieve user profile 52 | - Retrieve user status 53 | - Update user status 54 | - List the limits of an org 55 | - Check the current API limit and usage 56 | - Get a list of Communities (Digitial Experience) 57 | - Get a list of Community (Digitial Experience) users 58 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/connect/support/RefreshingOAuth2Connection.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.connect.support; 17 | 18 | import org.springframework.social.connect.ApiAdapter; 19 | import org.springframework.social.connect.ConnectionData; 20 | import org.springframework.social.oauth2.OAuth2ServiceProvider; 21 | 22 | /** 23 | * @author Umut Utkan 24 | */ 25 | public class RefreshingOAuth2Connection extends OAuth2Connection { 26 | 27 | public RefreshingOAuth2Connection(String providerId, String providerUserId, String accessToken, String refreshToken, Long expireTime, OAuth2ServiceProvider aoAuth2ServiceProvider, ApiAdapter aApiAdapter) { 28 | super(providerId, providerUserId, accessToken, refreshToken, expireTime, aoAuth2ServiceProvider, aApiAdapter); 29 | } 30 | 31 | public RefreshingOAuth2Connection(ConnectionData data, OAuth2ServiceProvider aoAuth2ServiceProvider, ApiAdapter aApiAdapter) { 32 | super(data, aoAuth2ServiceProvider, aApiAdapter); 33 | } 34 | 35 | 36 | 37 | @Override 38 | public A getApi() { 39 | if (hasExpired()) { 40 | refresh(); 41 | } 42 | return super.getApi(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/connect/support/RefreshingOAuth2ConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.connect.support; 17 | 18 | import org.springframework.social.connect.ApiAdapter; 19 | import org.springframework.social.connect.Connection; 20 | import org.springframework.social.connect.ConnectionData; 21 | import org.springframework.social.oauth2.AccessGrant; 22 | import org.springframework.social.oauth2.OAuth2ServiceProvider; 23 | 24 | /** 25 | * @author Umut Utkan 26 | */ 27 | public class RefreshingOAuth2ConnectionFactory extends OAuth2ConnectionFactory { 28 | 29 | public RefreshingOAuth2ConnectionFactory(String providerId, OAuth2ServiceProvider soAuth2ServiceProvider, ApiAdapter sApiAdapter) { 30 | super(providerId, soAuth2ServiceProvider, sApiAdapter); 31 | } 32 | 33 | 34 | @Override 35 | public Connection createConnection(AccessGrant accessGrant) { 36 | return new RefreshingOAuth2Connection(getProviderId(), extractProviderUserId(accessGrant), accessGrant.getAccessToken(), 37 | accessGrant.getRefreshToken(), accessGrant.getExpireTime(), (OAuth2ServiceProvider) getServiceProvider(), getApiAdapter()); 38 | } 39 | 40 | @Override 41 | public Connection createConnection(ConnectionData data) { 42 | return new RefreshingOAuth2Connection(data, (OAuth2ServiceProvider) getServiceProvider(), getApiAdapter()); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/AbstractLimits.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import java.io.Serializable; 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | import com.fasterxml.jackson.annotation.JsonAnyGetter; 23 | import com.fasterxml.jackson.annotation.JsonAnySetter; 24 | import com.fasterxml.jackson.annotation.JsonIgnore; 25 | import com.fasterxml.jackson.annotation.JsonInclude; 26 | import com.fasterxml.jackson.annotation.JsonProperty; 27 | 28 | @JsonInclude(JsonInclude.Include.NON_NULL) 29 | /** 30 | * The core limits properties. Any additional limits for connected apps can call 31 | * be found in the additional properties 32 | * 33 | * @author Jared Ottley 34 | */ 35 | public class AbstractLimits implements Serializable { 36 | 37 | private static final long serialVersionUID = 6213553807904726408L; 38 | 39 | @JsonProperty("Max") 40 | private int max; 41 | 42 | @JsonProperty("Remaining") 43 | private int remaining; 44 | 45 | @JsonIgnore 46 | private Map additionalProperties = new HashMap(); 47 | 48 | /** 49 | * NOOP 50 | */ 51 | public AbstractLimits() { 52 | 53 | } 54 | 55 | /** 56 | * 57 | * @param remaining 58 | * @param max 59 | */ 60 | public AbstractLimits(int max, int remaining) { 61 | this.max = max; 62 | this.remaining = remaining; 63 | } 64 | 65 | @JsonProperty("Max") 66 | public int getMax() { 67 | return max; 68 | } 69 | 70 | @JsonProperty("Remaining") 71 | public int getRemaining() { 72 | return remaining; 73 | } 74 | 75 | @JsonAnyGetter 76 | public Map getAdditionalProperties() { 77 | return this.additionalProperties; 78 | } 79 | 80 | @JsonAnySetter 81 | public void setAdditionalProperty(String name, Object value) { 82 | this.additionalProperties.put(name, value); 83 | } 84 | 85 | } -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/ApiOperations.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | /** 22 | * Defines operations for getting info on the API. 23 | * 24 | * @author Umut Utkan 25 | * @author Jared Ottley 26 | */ 27 | public interface ApiOperations { 28 | 29 | static final String DEFAULT_API_VERSION = "v37.0"; 30 | 31 | List getVersions(); 32 | 33 | Map getServices(String version); 34 | 35 | Map getServices(); 36 | 37 | void setVersion(String version) 38 | throws InvalidSalesforceApiVersionException; 39 | 40 | String getVersion(); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/ApiVersion.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * @author Umut Utkan 22 | */ 23 | public class ApiVersion implements Serializable { 24 | 25 | private String label; 26 | 27 | private String version; 28 | 29 | private String url; 30 | 31 | 32 | public ApiVersion(String version, String label, String url) { 33 | this.version = version; 34 | this.label = label; 35 | this.url = url; 36 | } 37 | 38 | 39 | public String getLabel() { 40 | return label; 41 | } 42 | 43 | public String getVersion() { 44 | return version; 45 | } 46 | 47 | public String getUrl() { 48 | return url; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return "ApiVersion{" + 54 | "label='" + label + '\'' + 55 | ", version='" + version + '\'' + 56 | ", url='" + url + '\'' + 57 | '}'; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/ChatterOperations.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | /** 19 | * Defines operations for interacting with the Chatter API. 20 | * 21 | * @author Umut Utkan 22 | */ 23 | public interface ChatterOperations { 24 | 25 | /** 26 | * Retrieves current users's profile 27 | * 28 | * @return user profile 29 | */ 30 | public SalesforceProfile getUserProfile(); 31 | 32 | /** 33 | * Retrieves the given user's profile 34 | * 35 | * @param userId The salesforce Id of the user 36 | * @return user profile 37 | */ 38 | public SalesforceProfile getUserProfile(String userId); 39 | 40 | /** 41 | * Retrieves current user's status 42 | * 43 | * @return status 44 | */ 45 | public Status getStatus(); 46 | 47 | /** 48 | * Retrieves the given user's status 49 | * 50 | * @param userId The salesforce Id of the user 51 | * @return status 52 | */ 53 | public Status getStatus(String userId); 54 | 55 | /** 56 | * Updates current user's status with the given message 57 | * 58 | * @param message The message to be posted as the current user's status 59 | * @return status 60 | */ 61 | public Status updateStatus(String message); 62 | 63 | /** 64 | * Updates the given user's status with the given message 65 | * 66 | * @param userId The salesforce Id of the user 67 | * @param message The message to be posted as the current user's status 68 | * @return status 69 | */ 70 | public Status updateStatus(String userId, String message); 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/CommunityUser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2021 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 19 | 20 | @JsonIgnoreProperties(ignoreUnknown = true) 21 | public class CommunityUser { 22 | 23 | private String communityNickname; 24 | 25 | private String companyName; 26 | 27 | private String displayName; 28 | 29 | private String email; 30 | 31 | private String firstName; 32 | 33 | private boolean hasChatter; 34 | 35 | private String id; 36 | 37 | private boolean isInThisCommunity; 38 | 39 | private String lastName; 40 | 41 | private String name; 42 | 43 | private String username; 44 | 45 | private String aboutMe; 46 | 47 | private String contactName; 48 | 49 | public String getCommunityNickname() { 50 | return communityNickname; 51 | } 52 | 53 | public void setCommunityNickname(String communityNickname) { 54 | this.communityNickname = communityNickname; 55 | } 56 | 57 | public String getCompanyName() { 58 | return companyName; 59 | } 60 | 61 | public void setCompanyName(String companyName) { 62 | this.companyName = companyName; 63 | } 64 | 65 | public String getDisplayName() { 66 | return displayName; 67 | } 68 | 69 | public void setDisplayName(String displayName) { 70 | this.displayName = displayName; 71 | } 72 | 73 | public String getEmail() { 74 | return email; 75 | } 76 | 77 | public void setEmail(String email) { 78 | this.email = email; 79 | } 80 | 81 | public String getFirstName() { 82 | return firstName; 83 | } 84 | 85 | public void setFirstName(String firstName) { 86 | this.firstName = firstName; 87 | } 88 | 89 | public boolean isHasChatter() { 90 | return hasChatter; 91 | } 92 | 93 | public void setHasChatter(boolean hasChatter) { 94 | this.hasChatter = hasChatter; 95 | } 96 | 97 | public String getId() { 98 | return id; 99 | } 100 | 101 | public void setId(String id) { 102 | this.id = id; 103 | } 104 | 105 | public boolean isInThisCommunity() { 106 | return isInThisCommunity; 107 | } 108 | 109 | public void setInThisCommunity(boolean inThisCommunity) { 110 | isInThisCommunity = inThisCommunity; 111 | } 112 | 113 | public String getLastName() { 114 | return lastName; 115 | } 116 | 117 | public void setLastName(String lastName) { 118 | this.lastName = lastName; 119 | } 120 | 121 | public String getName() { 122 | return name; 123 | } 124 | 125 | public void setName(String name) { 126 | this.name = name; 127 | } 128 | 129 | public String getUsername() { 130 | return username; 131 | } 132 | 133 | public void setUsername(String username) { 134 | this.username = username; 135 | } 136 | 137 | public String getAboutMe() { 138 | return aboutMe; 139 | } 140 | 141 | public void setAboutMe(String aboutMe) { 142 | this.aboutMe = aboutMe; 143 | } 144 | 145 | public String getContactName() { 146 | return contactName; 147 | } 148 | 149 | public void setContactName(String contactName) { 150 | this.contactName = contactName; 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/ConnectOperations.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2021 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import java.util.List; 19 | 20 | public interface ConnectOperations { 21 | 22 | List getCommunities(); 23 | 24 | List getCommunityUsers(String communityId); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/CustomApiOperations.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2021 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import java.util.Map; 19 | 20 | import org.springframework.http.HttpEntity; 21 | import org.springframework.http.HttpMethod; 22 | import org.springframework.http.ResponseEntity; 23 | 24 | /** 25 | * Defines operations for calling custom apex exposed rest apis. 26 | * 27 | * @author Sanchit Agarwal 28 | * 29 | */ 30 | public interface CustomApiOperations { 31 | 32 | T postForApexObject(String uriPath, Object request, Class responseType); 33 | 34 | T postForApexObject(String uriPath, Object request, Class responseType, Map uriVariables); 35 | 36 | T getForApexObject(String uriPath, Class responseType); 37 | 38 | T getForApexObject(String uriPath, Class responseType, Map uriVariables); 39 | 40 | T putForApexObject(String uriPath, Object request, Class responseType); 41 | 42 | T putForApexObject(String uriPath, Object request, Class responseType, Map uriVariables); 43 | 44 | T patchForApexObject(String uriPath, Object request, Class responseType); 45 | 46 | T patchForApexObject(String uriPath, Object request, Class responseType, Map uriVariables); 47 | 48 | T deleteForApexObject(String uriPath, Class responseType); 49 | 50 | T deleteForApexObject(String uriPath, Class responseType, Map uriVariablesMap); 51 | 52 | // for custom api - (to get headers and body) 53 | ResponseEntity executeApexApi(String uriPath, HttpMethod method, HttpEntity request, Class responseType, Map uriVariables); 54 | 55 | ResponseEntity executeApexApi(String uriPath, HttpMethod method, HttpEntity request, Class responseType); 56 | } -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/InvalidIDException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import org.springframework.social.ApiException; 19 | import org.springframework.social.salesforce.connect.SalesforceServiceProvider; 20 | 21 | /** 22 | * @author Umut Utkan 23 | * @author Jared Ottley 24 | */ 25 | public class InvalidIDException extends ApiException { 26 | 27 | public InvalidIDException(String message) { 28 | super(SalesforceServiceProvider.ID, message); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/InvalidSalesforceApiVersionException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | /** 19 | * 20 | * @author Jared Ottley 21 | * 22 | */ 23 | public class InvalidSalesforceApiVersionException 24 | extends Throwable 25 | { 26 | public InvalidSalesforceApiVersionException() 27 | { 28 | //NOOP 29 | } 30 | 31 | public InvalidSalesforceApiVersionException(String version) 32 | { 33 | super(version + " is not a valid Salesforce Api version."); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/LimitResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 19 | import com.fasterxml.jackson.annotation.JsonInclude; 20 | 21 | import org.springframework.social.salesforce.api.AbstractLimits; 22 | 23 | @JsonInclude(JsonInclude.Include.NON_NULL) 24 | @JsonIgnoreProperties(ignoreUnknown = true) 25 | /** 26 | * @author Jared Ottley 27 | */ 28 | public class LimitResult extends AbstractLimits { 29 | 30 | private static final long serialVersionUID = 1L; 31 | 32 | /** 33 | * No args constructor for use in serialization 34 | * 35 | */ 36 | public LimitResult() { 37 | super(); 38 | } 39 | 40 | /** 41 | * 42 | * @param remaining 43 | * @param max 44 | */ 45 | public LimitResult(Integer max, Integer remaining) { 46 | super(max, remaining); 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/LimitsOperations.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | /** 19 | * Defines operations for interacting with the Limits API. 20 | * 21 | * @author Jared Ottley 22 | */ 23 | public interface LimitsOperations { 24 | 25 | 26 | /** 27 | * Retrieve the organization limits 28 | * 29 | * @return LimitsResults 30 | */ 31 | public LimitsResults getLimits(); 32 | 33 | /** 34 | * Get the current Daily API limit. This value is returned in a header from Salesforce. The value is persisted here after each API call. 35 | * @return 36 | */ 37 | public int getDailyApiLimit(); 38 | 39 | 40 | /** 41 | * Get the current Daily API usage. This value is returned in a header from Salesforce. The value is persisted here after each API call. 42 | * @return 43 | */ 44 | public int getDailyApiUsed(); 45 | 46 | } -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/Photo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | 21 | 22 | /** 23 | * @author Umut Utkan 24 | */ 25 | @JsonIgnoreProperties(ignoreUnknown = true) 26 | public class Photo { 27 | 28 | private String smallPhotoUrl; 29 | 30 | private String largePhotoUrl; 31 | 32 | 33 | public Photo() { 34 | 35 | } 36 | 37 | 38 | public String getSmallPhotoUrl() { 39 | return smallPhotoUrl; 40 | } 41 | 42 | public void setSmallPhotoUrl(String smallPhotoUrl) { 43 | this.smallPhotoUrl = smallPhotoUrl; 44 | } 45 | 46 | public String getLargePhotoUrl() { 47 | return largePhotoUrl; 48 | } 49 | 50 | public void setLargePhotoUrl(String largePhotoUrl) { 51 | this.largePhotoUrl = largePhotoUrl; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/PickListEntry.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | /** 19 | * @author Umut Utkan 20 | */ 21 | public class PickListEntry { 22 | 23 | private String value; 24 | 25 | private boolean active; 26 | 27 | private String label; 28 | 29 | private boolean defaultValue; 30 | 31 | //TODO: find how to deserialize. 32 | //private String validFor; 33 | 34 | 35 | public PickListEntry(String value, String label, boolean active, boolean defaultValue) { 36 | this.value = value; 37 | this.active = active; 38 | this.label = label; 39 | this.defaultValue = defaultValue; 40 | } 41 | 42 | 43 | public String getValue() { 44 | return value; 45 | } 46 | 47 | public boolean isActive() { 48 | return active; 49 | } 50 | 51 | public String getLabel() { 52 | return label; 53 | } 54 | 55 | public boolean isDefaultValue() { 56 | return defaultValue; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/QueryOperations.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | /** 19 | * Defines operations for executing SOQL queries. 20 | * 21 | * @author Umut Utkan 22 | */ 23 | public interface QueryOperations { 24 | 25 | /** 26 | * Execute SOQL query and return the first page of results 27 | * 28 | * @param query The SOQL query to execute 29 | * @return QueryResult 30 | */ 31 | QueryResult query(String query); 32 | 33 | /** 34 | * Execute SOQL query and return the first page of results 35 | * 36 | * @param query The SOQL query to execute 37 | * @param includeDeletedItems if result should include deleted items 38 | * documentation https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_queryall.htm 39 | * @return QueryResult 40 | */ 41 | QueryResult query(String query, boolean includeDeletedItems); 42 | 43 | /* 44 | * Retrieve next page of results based on argument from url (usually from query result "nextRecordsUrl") 45 | */ 46 | QueryResult nextPage(String urlOrToken); 47 | 48 | /** 49 | * Execute SOQL query and return all results. 50 | * 51 | * @param query The SOQL query to execute 52 | * @return QueryResult 53 | */ 54 | QueryResult queryAll(String query); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/QueryResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * @author Umut Utkan 22 | */ 23 | public class QueryResult { 24 | 25 | private int totalSize; 26 | 27 | private boolean done; 28 | 29 | private String nextRecordsUrl; 30 | 31 | private List records; 32 | 33 | 34 | public QueryResult(int totalSize, boolean done) { 35 | this.totalSize = totalSize; 36 | this.done = done; 37 | } 38 | 39 | 40 | public int getTotalSize() { 41 | return totalSize; 42 | } 43 | 44 | public boolean isDone() { 45 | return done; 46 | } 47 | 48 | public List getRecords() { 49 | return records; 50 | } 51 | 52 | public void setRecords(List records) { 53 | this.records = records; 54 | } 55 | 56 | public String getNextRecordsUrl() { 57 | return nextRecordsUrl; 58 | } 59 | 60 | public void setNextRecordsUrl(String nextRecordsUrl) { 61 | this.nextRecordsUrl = nextRecordsUrl; 62 | } 63 | 64 | public String getNextRecordsToken() { 65 | if (this.nextRecordsUrl != null) { 66 | return this.nextRecordsUrl.substring(this.nextRecordsUrl.lastIndexOf('/') + 1, this.nextRecordsUrl.length()); 67 | } 68 | return null; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/RecentOperations.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * Defines operations for interacting with Recent API. 22 | * 23 | * @author Umut Utkan 24 | */ 25 | public interface RecentOperations { 26 | 27 | List recent(); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/RecordTypeInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | /** 19 | * @author Umut Utkan 20 | */ 21 | public class RecordTypeInfo { 22 | 23 | private String name; 24 | 25 | private boolean available; 26 | 27 | private String recordTypeId; 28 | 29 | private boolean defaultRecordTypeMapping; 30 | 31 | 32 | public RecordTypeInfo(String name, boolean available, String recordTypeId, boolean defaultRecordTypeMapping) { 33 | this.name = name; 34 | this.available = available; 35 | this.recordTypeId = recordTypeId; 36 | this.defaultRecordTypeMapping = defaultRecordTypeMapping; 37 | } 38 | 39 | 40 | public String getName() { 41 | return name; 42 | } 43 | 44 | public boolean isAvailable() { 45 | return available; 46 | } 47 | 48 | public String getRecordTypeId() { 49 | return recordTypeId; 50 | } 51 | 52 | public boolean isDefaultRecordTypeMapping() { 53 | return defaultRecordTypeMapping; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/Relationship.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | /** 19 | * @author Umut Utkan 20 | */ 21 | public class Relationship { 22 | 23 | private String field; 24 | 25 | private boolean deprecatedAndHidden; 26 | 27 | private String relationshipName; 28 | 29 | private boolean cascadeDelete; 30 | 31 | private boolean restrictedDelete; 32 | 33 | private String childSObject; 34 | 35 | 36 | public Relationship(String field, String relationshipName, String childObject) { 37 | this.field = field; 38 | this.relationshipName = relationshipName; 39 | this.childSObject = childObject; 40 | } 41 | 42 | 43 | public String getField() { 44 | return field; 45 | } 46 | 47 | public String getRelationshipName() { 48 | return relationshipName; 49 | } 50 | 51 | public String getChildSObject() { 52 | return childSObject; 53 | } 54 | 55 | public boolean isDeprecatedAndHidden() { 56 | return deprecatedAndHidden; 57 | } 58 | 59 | public void setDeprecatedAndHidden(boolean deprecatedAndHidden) { 60 | this.deprecatedAndHidden = deprecatedAndHidden; 61 | } 62 | 63 | public boolean isCascadeDelete() { 64 | return cascadeDelete; 65 | } 66 | 67 | public void setCascadeDelete(boolean cascadeDelete) { 68 | this.cascadeDelete = cascadeDelete; 69 | } 70 | 71 | public boolean isRestrictedDelete() { 72 | return restrictedDelete; 73 | } 74 | 75 | public void setRestrictedDelete(boolean restrictedDelete) { 76 | this.restrictedDelete = restrictedDelete; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/ResultItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import java.io.Serializable; 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | /** 23 | * @author Umut Utkan 24 | */ 25 | public class ResultItem implements Serializable { 26 | 27 | private String type; 28 | 29 | private String url; 30 | 31 | private Map attributes; 32 | 33 | 34 | public ResultItem(String type, String url) { 35 | this.type = type; 36 | this.url = url; 37 | this.attributes = new HashMap(); 38 | } 39 | 40 | 41 | public String getType() { 42 | return this.type; 43 | } 44 | 45 | public void setType(String type) { 46 | this.type = type; 47 | } 48 | 49 | public String getUrl() { 50 | return this.url; 51 | } 52 | 53 | public void setUrl(String url) { 54 | this.url = url; 55 | } 56 | 57 | public Map getAttributes() { 58 | return attributes; 59 | } 60 | 61 | public void setAttributes(Map attributes) { 62 | this.attributes = attributes; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/SObjectDetail.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * @author Umut Utkan 22 | */ 23 | public class SObjectDetail extends SObjectSummary { 24 | 25 | private List fields; 26 | 27 | private List childRelationships; 28 | 29 | private boolean listviewable; 30 | 31 | private boolean lookupLayoutable; 32 | 33 | private List recordTypeInfos; 34 | 35 | private boolean searchLayoutable; 36 | 37 | 38 | public SObjectDetail() { 39 | 40 | } 41 | 42 | 43 | public List getFields() { 44 | return fields; 45 | } 46 | 47 | public void setFields(List fields) { 48 | this.fields = fields; 49 | } 50 | 51 | public List getChildRelationships() { 52 | return childRelationships; 53 | } 54 | 55 | public void setChildRelationships(List childRelationships) { 56 | this.childRelationships = childRelationships; 57 | } 58 | 59 | public boolean isListviewable() { 60 | return listviewable; 61 | } 62 | 63 | public void setListviewable(boolean listviewable) { 64 | this.listviewable = listviewable; 65 | } 66 | 67 | public boolean isLookupLayoutable() { 68 | return lookupLayoutable; 69 | } 70 | 71 | public void setLookupLayoutable(boolean lookupLayoutable) { 72 | this.lookupLayoutable = lookupLayoutable; 73 | } 74 | 75 | public List getRecordTypeInfos() { 76 | return recordTypeInfos; 77 | } 78 | 79 | public void setRecordTypeInfos(List recordTypeInfos) { 80 | this.recordTypeInfos = recordTypeInfos; 81 | } 82 | 83 | public boolean isSearchLayoutable() { 84 | return searchLayoutable; 85 | } 86 | 87 | public void setSearchLayoutable(boolean searchLayoutable) { 88 | this.searchLayoutable = searchLayoutable; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/SObjectOperations.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import java.io.InputStream; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | /** 23 | * Defines operations for interacting with the sObjects API. 24 | * 25 | * @author Umut Utkan 26 | */ 27 | public interface SObjectOperations { 28 | 29 | public List getSObjects(); 30 | 31 | public SObjectSummary getSObjectSummary(String name); 32 | 33 | public SObjectDetail describeSObject(String name); 34 | 35 | public Map getRow(String name, String id, String... fields); 36 | 37 | public InputStream getBlob(String name, String id, String field); 38 | 39 | Map create(String name, Map fields); 40 | 41 | Map update(String sObjectName, String sObjectId, Map fields); 42 | 43 | public void delete(String sObjectName, String sObjectId); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/Salesforce.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import com.fasterxml.jackson.databind.JsonNode; 19 | import org.springframework.social.ApiBinding; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * Specifies operations performed on Salesforce. 25 | * 26 | * @author Umut Utkan 27 | * @author Jared Ottley 28 | */ 29 | public interface Salesforce extends ApiBinding { 30 | 31 | public ApiOperations apiOperations(); 32 | 33 | public ApiOperations apiOperations(String instanceUrl); 34 | 35 | public ChatterOperations chatterOperations(); 36 | 37 | public ChatterOperations chatterOperations(String instanceUrl); 38 | 39 | public QueryOperations queryOperations(); 40 | 41 | public QueryOperations queryOperations(String instanceUrl); 42 | 43 | public RecentOperations recentOperations(); 44 | 45 | public RecentOperations recentOperations(String instanceUrl); 46 | 47 | public SearchOperations searchOperations(); 48 | 49 | public SearchOperations searchOperations(String instanceUrl); 50 | 51 | public SObjectOperations sObjectsOperations(); 52 | 53 | public SObjectOperations sObjectsOperations(String instanceUrl); 54 | 55 | public UserOperations userOperations(); 56 | 57 | public UserOperations userOperations(String gatewayUrl); 58 | 59 | public LimitsOperations limitsOperations(); 60 | 61 | public LimitsOperations limitsOperations(String instanceUrl); 62 | 63 | public List readList(JsonNode jsonNode, Class type); 64 | 65 | public T readObject(JsonNode jsonNode, Class type); 66 | 67 | public String getBaseUrl(); 68 | 69 | public String getInstanceUrl(); 70 | 71 | public void setInstanceUrl(String instanceUrl); 72 | 73 | public String getUserInfoUrl(); 74 | 75 | public String getAuthGatewayUrl(); 76 | 77 | public void setAuthGatewayBaseUrl(String gatewayUrl); 78 | 79 | public ConnectOperations connectOperations(); 80 | 81 | public ConnectOperations connectOperations(String instanceUrl); 82 | 83 | public CustomApiOperations customApiOperations(); 84 | 85 | public CustomApiOperations customApiOperations(String instanceUrl); 86 | } -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/SalesforceProfile.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import java.io.Serializable; 19 | 20 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 21 | 22 | /** 23 | * @author Umut Utkan 24 | * @author Alexandra Leahu 25 | * @author Jared ottley 26 | */ 27 | @JsonIgnoreProperties(ignoreUnknown = true) 28 | public class SalesforceProfile implements Serializable { 29 | protected String id; 30 | 31 | protected String email; 32 | 33 | protected String firstName; 34 | 35 | protected String lastName; 36 | 37 | protected Photo photo; 38 | 39 | protected String name; 40 | 41 | 42 | /*public SalesforceProfile(String id, String firstName, String lastName, String email) { 43 | this.id = id; 44 | this.firstName = firstName; 45 | this.lastName = lastName; 46 | this.email = email; 47 | }*/ 48 | 49 | 50 | public String getId() { 51 | return id; 52 | } 53 | 54 | public String getEmail() { 55 | return email; 56 | } 57 | 58 | public String getFirstName() { 59 | return firstName; 60 | } 61 | 62 | public String getLastName() { 63 | return lastName; 64 | } 65 | 66 | public Photo getPhoto() { 67 | return this.photo; 68 | } 69 | 70 | public String getName() { 71 | return this.name; 72 | } 73 | 74 | public String getUsername() { 75 | return this.id; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/SalesforceRequestException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | import org.apache.commons.lang3.StringUtils; 22 | import org.springframework.social.ApiException; 23 | import org.springframework.social.salesforce.connect.SalesforceServiceProvider; 24 | 25 | /** 26 | * Encapsulates the error response sent by Salesforce. 27 | *
28 | * 29 | * @see
31 | * Salesforce API Core Datatypes 32 | * 33 | * @author Umut Utkan 34 | * @author Jared Ottley 35 | */ 36 | public class SalesforceRequestException extends ApiException { 37 | 38 | private static final long serialVersionUID = 7047374539651371668L; 39 | 40 | private final List fields; 41 | private final String code; 42 | 43 | public SalesforceRequestException(String message) { 44 | super(SalesforceServiceProvider.ID, message); 45 | this.code = null; 46 | this.fields = null; 47 | } 48 | 49 | public SalesforceRequestException(String providerId, String message) { 50 | super(providerId, message); 51 | this.code = null; 52 | this.fields = null; 53 | } 54 | 55 | @SuppressWarnings("unchecked") 56 | public SalesforceRequestException(Map errorDetails) { 57 | super(SalesforceServiceProvider.ID, (String)errorDetails.get("message")); 58 | 59 | this.code = StringUtils.defaultString((String)errorDetails.get("errorCode"), "UNKNOWN"); 60 | this.fields = (List) errorDetails.get("fields"); 61 | } 62 | 63 | @SuppressWarnings("unchecked") 64 | public SalesforceRequestException(String providerId, Map errorDetails) { 65 | super(providerId, (String)errorDetails.get("message")); 66 | 67 | this.code = StringUtils.defaultString((String)errorDetails.get("errorCode"), "UNKNOWN"); 68 | this.fields = (List) errorDetails.get("fields"); 69 | } 70 | 71 | public List getFields() { 72 | return fields; 73 | } 74 | 75 | public String getCode() { 76 | return code; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/SalesforceUserDetails.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 19 | 20 | /** 21 | * 22 | * @author Alexandra Leahu 23 | * 24 | */ 25 | @JsonIgnoreProperties(ignoreUnknown = true) 26 | public class SalesforceUserDetails extends SalesforceProfile { 27 | private String organizationId; 28 | 29 | private String nickname; 30 | 31 | private String preferredUsername; 32 | 33 | public SalesforceUserDetails(String id, String firstName, String lastName, 34 | String email, String name, String organizationId, String nickname, 35 | String preferredUsername) { 36 | super(); 37 | this.id = id; 38 | this.firstName = firstName; 39 | this.lastName = lastName; 40 | this.email = email; 41 | this.name = name; 42 | this.organizationId = organizationId; 43 | this.nickname = nickname; 44 | this.preferredUsername = preferredUsername; 45 | } 46 | 47 | public String getOrganizationId() { 48 | return organizationId; 49 | } 50 | 51 | public String getNickname() { 52 | return nickname; 53 | } 54 | 55 | public String getPreferredUsername() { 56 | return preferredUsername; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/SearchOperations.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * Defines operations to execute SOSL search queries. 22 | * 23 | * @author Umut Utkan 24 | */ 25 | public interface SearchOperations { 26 | 27 | /** 28 | * Execute SOSL Query and retrieve results 29 | * 30 | * @param soslQuery The SOSL Query to execute 31 | * @return List of ResultItem 32 | */ 33 | List search(String soslQuery); 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/Status.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | /** 22 | * @author Umut Utkan 23 | */ 24 | public class Status { 25 | 26 | private String text; 27 | 28 | private List> segments; 29 | 30 | 31 | public Status(String text) { 32 | this.text = text; 33 | } 34 | 35 | 36 | public String getText() { 37 | return text; 38 | } 39 | 40 | public void setText(String text) { 41 | this.text = text; 42 | } 43 | 44 | public List> getSegments() { 45 | return segments; 46 | } 47 | 48 | public void setSegments(List> segments) { 49 | this.segments = segments; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "Status{" + 55 | "text='" + text + '\'' + 56 | ", segments=" + segments + 57 | '}'; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/UserOperations.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api; 17 | import org.springframework.social.salesforce.api.SalesforceUserDetails; 18 | 19 | /** 20 | * Defines operations for retrieving user related info. 21 | * 22 | * @author Alexandra Leahu 23 | */ 24 | public interface UserOperations { 25 | 26 | /** 27 | * Retrieves the details for the current logged in user. 28 | * @return user details 29 | */ 30 | SalesforceUserDetails getSalesforceUserDetails(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/AbstractSalesForceOperations.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import org.springframework.social.ApiBinding; 19 | import org.springframework.social.MissingAuthorizationException; 20 | import org.springframework.social.salesforce.api.Salesforce; 21 | import org.springframework.social.salesforce.connect.SalesforceServiceProvider; 22 | 23 | /** 24 | * @author Umut Utkan 25 | * @author Jared Ottley 26 | */ 27 | public class AbstractSalesForceOperations { 28 | 29 | protected T api; 30 | 31 | 32 | public AbstractSalesForceOperations(T api) { 33 | this.api = api; 34 | } 35 | 36 | protected void requireAuthorization() { 37 | if (!api.isAuthorized()) { 38 | throw new MissingAuthorizationException(SalesforceServiceProvider.ID); 39 | } 40 | } 41 | 42 | protected static String BASE_URL = "https://na7.salesforce.com/services/data"; 43 | 44 | 45 | public String getVersion() 46 | { 47 | return ((Salesforce)api).apiOperations().getVersion(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/ApiRequestInterceptor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import java.io.IOException; 19 | 20 | import org.springframework.http.HttpRequest; 21 | import org.springframework.http.client.ClientHttpRequestExecution; 22 | import org.springframework.http.client.ClientHttpRequestInterceptor; 23 | import org.springframework.http.client.ClientHttpResponse; 24 | import org.springframework.social.salesforce.api.impl.LimitsOperationsTemplate; 25 | import org.springframework.social.salesforce.api.impl.SalesforceTemplate; 26 | 27 | /** 28 | * This class can be used to inspect and use the any request or response to the 29 | * Salesforce API. 30 | * 31 | * This class currently inspects the Sforce-Limit-Info header from Salesforce to 32 | * capture the current Daily API call usage after each API call. 33 | * 34 | * @author Jared Ottley 35 | * 36 | */ 37 | public class ApiRequestInterceptor implements ClientHttpRequestInterceptor { 38 | 39 | // The header will look like -> Sforce-Limit-Info: api-usage=39/15000 40 | private final static String SFORCE_LIMIT_INFO = "Sforce-Limit-Info"; 41 | 42 | private SalesforceTemplate salesforceTemplate; 43 | 44 | public ApiRequestInterceptor(SalesforceTemplate salesforceTemplate) { 45 | this.salesforceTemplate = salesforceTemplate; 46 | } 47 | 48 | @Override 49 | public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) 50 | throws IOException { 51 | ClientHttpResponse response = execution.execute(request, body); 52 | processSForceLimitInfoHeader(response); 53 | return response; 54 | } 55 | 56 | /** 57 | * Check response for the Sforce-Limit-Info header. Update the Limits Operations 58 | * with the currently API usage 59 | * 60 | * @param response 61 | */ 62 | private void processSForceLimitInfoHeader(ClientHttpResponse response) { 63 | if (response.getHeaders().containsKey(SFORCE_LIMIT_INFO)) { 64 | ((LimitsOperationsTemplate) salesforceTemplate.limitsOperations()) 65 | .setCurrentDailyApiLimits(response.getHeaders().getFirst(SFORCE_LIMIT_INFO)); 66 | } 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/ApiTemplate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import com.fasterxml.jackson.databind.JsonNode; 19 | 20 | import org.apache.commons.lang3.StringUtils; 21 | import org.springframework.social.salesforce.api.ApiOperations; 22 | import org.springframework.social.salesforce.api.ApiVersion; 23 | import org.springframework.social.salesforce.api.InvalidSalesforceApiVersionException; 24 | import org.springframework.social.salesforce.api.Salesforce; 25 | import org.springframework.social.support.URIBuilder; 26 | import org.springframework.web.client.RestTemplate; 27 | 28 | import java.net.URI; 29 | import java.util.List; 30 | import java.util.Map; 31 | import java.util.regex.Matcher; 32 | import java.util.regex.Pattern; 33 | 34 | /** 35 | * Default implementation of ApiOperations. 36 | * 37 | * @author Umut Utkan 38 | * @author Jared Ottley 39 | */ 40 | public class ApiTemplate extends AbstractSalesForceOperations implements ApiOperations { 41 | 42 | private RestTemplate restTemplate; 43 | private String version; 44 | 45 | 46 | String versionRegEx = "v[0-9][0-9]\\.[0-9]"; 47 | 48 | 49 | public ApiTemplate(Salesforce api, RestTemplate restTemplate) { 50 | super(api); 51 | this.restTemplate = restTemplate; 52 | } 53 | 54 | 55 | public List getVersions() { 56 | URI uri = URIBuilder.fromUri(api.getBaseUrl()).build(); 57 | JsonNode dataNode = restTemplate.getForObject(uri, JsonNode.class); 58 | return api.readList(dataNode, ApiVersion.class); 59 | } 60 | 61 | @SuppressWarnings("unchecked") 62 | public Map getServices(String version) { 63 | requireAuthorization(); 64 | return restTemplate.getForObject(api.getBaseUrl() + "/{version}", Map.class, version); 65 | } 66 | 67 | 68 | @SuppressWarnings("unchecked") 69 | public Map getServices() { 70 | requireAuthorization(); 71 | return this.getServices(getVersion()); 72 | } 73 | 74 | 75 | public void setVersion(String version) 76 | throws InvalidSalesforceApiVersionException 77 | { 78 | if (StringUtils.isNotBlank(version) && validateVersionString(version)) 79 | { 80 | this.version = version; 81 | } 82 | else 83 | { 84 | throw new InvalidSalesforceApiVersionException(version); 85 | } 86 | } 87 | 88 | 89 | public String getVersion() 90 | { 91 | if (StringUtils.isNotBlank(version)) 92 | { 93 | return version; 94 | } 95 | else 96 | { 97 | return DEFAULT_API_VERSION; 98 | } 99 | } 100 | 101 | 102 | private boolean validateVersionString(String version) 103 | { 104 | if (StringUtils.isNotBlank(version)) 105 | { 106 | Pattern pattern = Pattern.compile(versionRegEx); 107 | Matcher matcher = pattern.matcher(version); 108 | 109 | return matcher.find(); 110 | } 111 | 112 | return false; 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/ChatterTemplate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import com.fasterxml.jackson.databind.JsonNode; 19 | import org.springframework.http.HttpEntity; 20 | import org.springframework.http.HttpHeaders; 21 | import org.springframework.http.HttpMethod; 22 | import org.springframework.social.salesforce.api.ChatterOperations; 23 | import org.springframework.social.salesforce.api.Salesforce; 24 | import org.springframework.social.salesforce.api.SalesforceProfile; 25 | import org.springframework.social.salesforce.api.Status; 26 | import org.springframework.util.LinkedMultiValueMap; 27 | import org.springframework.util.MultiValueMap; 28 | import org.springframework.web.client.RestTemplate; 29 | 30 | 31 | /** 32 | * Default implementation of ChatterOperations. 33 | * 34 | * @author Umut Utkan 35 | * @author Jared Ottley 36 | */ 37 | public class ChatterTemplate extends AbstractSalesForceOperations implements ChatterOperations { 38 | 39 | private RestTemplate restTemplate; 40 | 41 | public ChatterTemplate(Salesforce api, RestTemplate restTemplate) { 42 | super(api); 43 | this.restTemplate = restTemplate; 44 | 45 | //TODO Back rev'd spring social/spring web dependencies to work with Alfresco provided versions 46 | // adds interceptor to rest template for adding 47 | // X-Chatter-Entity-Encoding=false header 48 | // this header informs Salesforce not to encode special characters and 49 | // to return as is. 50 | //this.restTemplate = addInterceptors(restTemplate); 51 | } 52 | 53 | @Override 54 | public SalesforceProfile getUserProfile() { 55 | return getUserProfile("me"); 56 | } 57 | 58 | @Override 59 | public SalesforceProfile getUserProfile(String userId) { 60 | requireAuthorization(); 61 | 62 | return restTemplate.exchange(api.getBaseUrl() + "/{version}/chatter/users/{id}", HttpMethod.GET, new HttpEntity("",getChatterHeader()), SalesforceProfile.class, getVersion(), userId).getBody(); 63 | 64 | //TODO back rev'd 65 | //return restTemplate.getForObject(api.getBaseUrl() + "/{version}/chatter/users/{id}", SalesforceProfile.class, "v23.0", userId); 66 | } 67 | 68 | @Override 69 | public Status getStatus() { 70 | return getStatus("me"); 71 | } 72 | 73 | @Override 74 | public Status getStatus(String userId) { 75 | requireAuthorization(); 76 | 77 | JsonNode node = restTemplate.exchange(api.getBaseUrl() + "/{version}/chatter/users/{userId}/status", HttpMethod.GET, new HttpEntity("", getChatterHeader()), JsonNode.class, getVersion(), userId).getBody(); 78 | //TODO back rev'd 79 | //JsonNode node = restTemplate.getForObject(api.getBaseUrl() + "/{version}/chatter/users/{userId}/status", 80 | // JsonNode.class, "v23.0", userId); 81 | return api.readObject(node.get("body"), Status.class); 82 | } 83 | 84 | public Status updateStatus(String message) { 85 | return updateStatus("me", message); 86 | } 87 | 88 | @Override 89 | public Status updateStatus(String userId, String message) { 90 | requireAuthorization(); 91 | 92 | MultiValueMap post = new LinkedMultiValueMap(); 93 | post.add("text", message); 94 | 95 | JsonNode node = restTemplate.exchange(api.getBaseUrl() + "/{version}/chatter/users/{userId}/status", HttpMethod.POST, new HttpEntity>(post, getChatterHeader()), JsonNode.class, getVersion(), userId).getBody(); 96 | 97 | //TODO back rev'd 98 | //JsonNode node = restTemplate.postForObject(api.getBaseUrl() + "/{version}/chatter/users/{userId}/status", 99 | // post, JsonNode.class, "v23.0", userId); 100 | return api.readObject(node.get("body"), Status.class); 101 | } 102 | 103 | /*TODO Removed for back rev 104 | * 105 | * private RestTemplate addInterceptors(RestTemplate restTemplate) { 106 | Map headers = new HashMap(); 107 | headers.put("X-Chatter-Entity-Encoding", "false"); 108 | 109 | restTemplate.getInterceptors().add(new HeaderAddingInterceptor(headers)); 110 | 111 | 112 | return restTemplate; 113 | }*/ 114 | 115 | //TODO added for back rev 116 | public HttpHeaders getChatterHeader() 117 | { 118 | HttpHeaders headers = new HttpHeaders(); 119 | headers.set("X-Chatter-Entity-Encoding", "false"); 120 | 121 | return headers; 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/ConnectTemplate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2021 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import com.fasterxml.jackson.databind.JsonNode; 19 | import org.springframework.social.salesforce.api.Community; 20 | import org.springframework.social.salesforce.api.CommunityUser; 21 | import org.springframework.social.salesforce.api.ConnectOperations; 22 | import org.springframework.social.salesforce.api.Salesforce; 23 | import org.springframework.social.salesforce.api.QueryResult; 24 | import org.springframework.social.salesforce.api.ResultItem; 25 | import org.springframework.web.client.RestTemplate; 26 | 27 | import java.util.List; 28 | 29 | public class ConnectTemplate extends AbstractSalesForceOperations implements ConnectOperations { 30 | 31 | private RestTemplate restTemplate; 32 | 33 | private static String CONNECT_URI = "/connect/communities/"; 34 | 35 | private static String CHATTER_USERS = "/chatter/users"; 36 | 37 | public ConnectTemplate(Salesforce api, RestTemplate restTemplate) { 38 | super(api); 39 | this.restTemplate = restTemplate; 40 | } 41 | 42 | @Override 43 | public List getCommunities() { 44 | 45 | requireAuthorization(); 46 | 47 | JsonNode dataNode = restTemplate.getForObject(api.getBaseUrl() + "/" + getVersion() + CONNECT_URI, JsonNode.class, getVersion()); 48 | 49 | return api.readList(dataNode.get("communities"), Community.class); 50 | } 51 | 52 | @Override 53 | public List getCommunityUsers(String communityId) { 54 | 55 | requireAuthorization(); 56 | 57 | JsonNode dataNode = restTemplate.getForObject(api.getBaseUrl() + "/" + getVersion() + CONNECT_URI + communityId + CHATTER_USERS, JsonNode.class, getVersion()); 58 | 59 | List users = api.readList(dataNode.get("users"), CommunityUser.class); 60 | 61 | return users; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/CustomApiTemplate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2021 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import java.util.Map; 19 | 20 | import org.springframework.http.HttpEntity; 21 | import org.springframework.http.HttpMethod; 22 | import org.springframework.http.ResponseEntity; 23 | import org.springframework.social.salesforce.api.CustomApiOperations; 24 | import org.springframework.social.salesforce.api.Salesforce; 25 | import org.springframework.web.client.RestTemplate; 26 | 27 | /** 28 | * Defines operations for calling Apex based custom rest apis. 29 | * 30 | * @author Sanchit Agarwal 31 | * 32 | */ 33 | public class CustomApiTemplate extends AbstractSalesForceOperations implements CustomApiOperations { 34 | 35 | private RestTemplate restTemplate; 36 | 37 | public CustomApiTemplate(Salesforce api, RestTemplate restTemplate) { 38 | super(api); 39 | this.restTemplate = restTemplate; 40 | } 41 | 42 | protected String createUriPath(String uriPath) { 43 | return this.api.getInstanceUrl() + "/services/apexrest" + uriPath; 44 | } 45 | 46 | @Override 47 | public T postForApexObject(String uriPath, Object request, Class responseType) { 48 | requireAuthorization(); 49 | return this.restTemplate.postForObject(this.createUriPath(uriPath), request, responseType); 50 | } 51 | 52 | @Override 53 | public T postForApexObject(String uriPath, Object request, Class responseType, Map uriVariables) { 54 | requireAuthorization(); 55 | return this.restTemplate.postForObject(this.createUriPath(uriPath), request, responseType, uriVariables); 56 | } 57 | 58 | @Override 59 | public T getForApexObject(String uriPath, Class responseType) { 60 | requireAuthorization(); 61 | return this.restTemplate.getForObject(this.createUriPath(uriPath), responseType); 62 | } 63 | 64 | @Override 65 | public T getForApexObject(String uriPath, Class responseType, Map uriVariables) { 66 | requireAuthorization(); 67 | return this.restTemplate.getForObject(this.createUriPath(uriPath), responseType, uriVariables); 68 | } 69 | 70 | @Override 71 | public T putForApexObject(String uriPath, Object request, Class responseType) { 72 | requireAuthorization(); 73 | ResponseEntity entity = this.restTemplate.exchange(this.createUriPath(uriPath), HttpMethod.PUT, new HttpEntity(request), responseType); 74 | return entity.getBody(); 75 | } 76 | 77 | @Override 78 | public T putForApexObject(String uriPath, Object request, Class responseType, Map uriVariables) { 79 | requireAuthorization(); 80 | ResponseEntity entity = this.restTemplate.exchange(this.createUriPath(uriPath), HttpMethod.PUT, new HttpEntity(request), responseType, uriVariables); 81 | return entity.getBody(); 82 | } 83 | 84 | @Override 85 | public T patchForApexObject(String uriPath, Object request, Class responseType) { 86 | requireAuthorization(); 87 | return this.restTemplate.patchForObject(this.createUriPath(uriPath), request, responseType); 88 | } 89 | 90 | @Override 91 | public T patchForApexObject(String uriPath, Object request, Class responseType, Map uriVariables) { 92 | requireAuthorization(); 93 | return this.restTemplate.patchForObject(this.createUriPath(uriPath), request, responseType, uriVariables); 94 | } 95 | 96 | @Override 97 | public T deleteForApexObject(String uriPath, Class responseType) { 98 | requireAuthorization(); 99 | ResponseEntity entity = this.restTemplate.exchange(this.createUriPath(uriPath), HttpMethod.DELETE, HttpEntity.EMPTY, responseType); 100 | return entity.getBody(); 101 | } 102 | 103 | @Override 104 | public T deleteForApexObject(String uriPath, Class responseType, Map uriVariables) { 105 | requireAuthorization(); 106 | ResponseEntity entity = this.restTemplate.exchange(this.createUriPath(uriPath), HttpMethod.DELETE, HttpEntity.EMPTY, responseType, uriVariables); 107 | return entity.getBody(); 108 | } 109 | 110 | @Override 111 | public ResponseEntity executeApexApi(String uriPath, HttpMethod method, HttpEntity request, Class responseType) { 112 | requireAuthorization(); 113 | return this.restTemplate.exchange(this.createUriPath(uriPath), method, request, responseType); 114 | } 115 | 116 | @Override 117 | public ResponseEntity executeApexApi(String uriPath, HttpMethod method, HttpEntity request, Class responseType, Map uriVariables) { 118 | requireAuthorization(); 119 | return this.restTemplate.exchange(this.createUriPath(uriPath), method, request, responseType, uriVariables); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/HeaderAddingInterceptor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import org.springframework.http.HttpRequest; 19 | import org.springframework.http.client.ClientHttpRequestExecution; 20 | import org.springframework.http.client.ClientHttpRequestInterceptor; 21 | import org.springframework.http.client.ClientHttpResponse; 22 | 23 | import java.io.IOException; 24 | import java.util.Map; 25 | 26 | /** 27 | * Interceptor for adding headers 28 | * 29 | * @author Umut Utkan 30 | */ 31 | public class HeaderAddingInterceptor implements ClientHttpRequestInterceptor { 32 | 33 | private Map headers; 34 | 35 | public HeaderAddingInterceptor(Map headers) { 36 | this.headers = headers; 37 | } 38 | 39 | @Override 40 | public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, 41 | ClientHttpRequestExecution clientHttpRequestExecution) throws IOException { 42 | for (Map.Entry header : this.headers.entrySet()) { 43 | httpRequest.getHeaders().add(header.getKey(), header.getValue()); 44 | } 45 | return clientHttpRequestExecution.execute(httpRequest, bytes); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/LimitsOperationsTemplate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import org.apache.commons.lang3.StringUtils; 19 | import org.springframework.social.salesforce.api.LimitsOperations; 20 | import org.springframework.social.salesforce.api.LimitsResults; 21 | import org.springframework.social.salesforce.api.Salesforce; 22 | import org.springframework.web.client.RestTemplate; 23 | 24 | /** 25 | * Default implementation of the Limits API. Also includes tracking of the 26 | * current API usage as returned from salesforce in each API call in the 27 | * Sforce-Limit-Info header 28 | * 29 | * @author Jared Ottley 30 | */ 31 | public class LimitsOperationsTemplate extends AbstractSalesForceOperations implements LimitsOperations { 32 | 33 | private RestTemplate restTemplate; 34 | private int currentMax = 0; 35 | private int currentUsed = 0; 36 | 37 | private final static String API_USAGE = "api-usage"; 38 | 39 | public LimitsOperationsTemplate(Salesforce api, RestTemplate restTemplate) { 40 | super(api); 41 | this.restTemplate = restTemplate; 42 | } 43 | 44 | @Override 45 | public LimitsResults getLimits() { 46 | requireAuthorization(); 47 | LimitsResults limitResults = restTemplate.getForObject(api.getBaseUrl() + "/{version}/limits", 48 | LimitsResults.class, getVersion()); 49 | return limitResults; 50 | } 51 | 52 | @Override 53 | public int getDailyApiLimit() { 54 | return currentMax; 55 | } 56 | 57 | @Override 58 | public int getDailyApiUsed() { 59 | return currentUsed; 60 | } 61 | 62 | public void setCurrentDailyApiLimits(String currentUsage) { 63 | if (StringUtils.isNotBlank(currentUsage) && currentUsage.startsWith(API_USAGE)) { 64 | String rates = currentUsage.split("=")[1]; 65 | String[] ratesSplit = rates.split("/"); 66 | 67 | this.currentUsed = Integer.parseInt(ratesSplit[0]); 68 | this.currentMax = Integer.parseInt(ratesSplit[1]); 69 | } 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/QueryTemplate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import java.net.URI; 19 | 20 | import org.apache.commons.lang3.StringUtils; 21 | import org.springframework.social.salesforce.api.QueryOperations; 22 | import org.springframework.social.salesforce.api.QueryResult; 23 | import org.springframework.social.salesforce.api.Salesforce; 24 | import org.springframework.social.support.URIBuilder; 25 | import org.springframework.web.client.RestTemplate; 26 | 27 | /** 28 | * Default implementation of QueryOperations. 29 | * 30 | * @author Umut Utkan 31 | * @author Jared Ottley 32 | */ 33 | public class QueryTemplate extends AbstractSalesForceOperations implements QueryOperations { 34 | 35 | private RestTemplate restTemplate; 36 | 37 | public QueryTemplate(Salesforce api, RestTemplate restTemplate) { 38 | super(api); 39 | this.restTemplate = restTemplate; 40 | } 41 | 42 | @Override 43 | public QueryResult query(String query) { 44 | return query(query, false); 45 | } 46 | 47 | @Override 48 | public QueryResult query(String query, boolean includeDeletedItems) { 49 | String queryType = includeDeletedItems ? "/queryAll" : "/query"; 50 | requireAuthorization(); 51 | URI uri = URIBuilder.fromUri(api.getBaseUrl() + "/" + getVersion() + queryType).queryParam("q", query).build(); 52 | return restTemplate.getForObject(uri, QueryResult.class); 53 | } 54 | 55 | @Override 56 | public QueryResult nextPage(String pathOrToken) { 57 | requireAuthorization(); 58 | if (pathOrToken.contains("/")) { 59 | return restTemplate.getForObject(api.getInstanceUrl() + pathOrToken, QueryResult.class); 60 | } else { 61 | return restTemplate.getForObject(api.getBaseUrl() + "/" + getVersion() + "/query/{token}", QueryResult.class, pathOrToken); 62 | } 63 | } 64 | 65 | /** 66 | * Pages through the result set and aggregates all sObjects into the single result set.
67 | * USUAL WARNINGS ABOUT RESULT SET SIZE APPLY 68 | * @see org.springframework.social.salesforce.api.QueryOperations#queryAll(java.lang.String) 69 | */ 70 | @Override 71 | public QueryResult queryAll(String query) { 72 | 73 | QueryResult page = query(query); 74 | // set up the final result set. (mostly to get the done flag set properly) 75 | QueryResult results = new QueryResult(page.getTotalSize(), true); 76 | results.setRecords(page.getRecords()); 77 | 78 | while (StringUtils.isNotBlank(page.getNextRecordsUrl())) { 79 | page = nextPage(page.getNextRecordsUrl()); 80 | results.getRecords().addAll(page.getRecords()); 81 | } 82 | return results; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/RecentTemplate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import com.fasterxml.jackson.databind.JsonNode; 19 | import org.springframework.social.salesforce.api.RecentOperations; 20 | import org.springframework.social.salesforce.api.ResultItem; 21 | import org.springframework.social.salesforce.api.Salesforce; 22 | import org.springframework.web.client.RestTemplate; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Default implementation of RecentOperations. 28 | * 29 | * @author Umut Utkan 30 | * @author Jared Ottley 31 | */ 32 | public class RecentTemplate extends AbstractSalesForceOperations implements RecentOperations { 33 | 34 | private RestTemplate restTemplate; 35 | 36 | public RecentTemplate(Salesforce api, RestTemplate restTemplate) { 37 | super(api); 38 | this.restTemplate = restTemplate; 39 | } 40 | 41 | @Override 42 | public List recent() { 43 | return api.readList(restTemplate.getForObject(api.getBaseUrl() + "/" + getVersion() + "/recent", JsonNode.class), ResultItem.class); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/SObjectsTemplate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import com.fasterxml.jackson.databind.JsonNode; 19 | import org.springframework.http.HttpEntity; 20 | import org.springframework.http.HttpHeaders; 21 | import org.springframework.http.HttpMethod; 22 | import org.springframework.http.MediaType; 23 | import org.springframework.http.ResponseEntity; 24 | import org.springframework.social.salesforce.api.SObjectDetail; 25 | import org.springframework.social.salesforce.api.SObjectOperations; 26 | import org.springframework.social.salesforce.api.SObjectSummary; 27 | import org.springframework.social.salesforce.api.Salesforce; 28 | import org.springframework.social.support.URIBuilder; 29 | import org.springframework.util.StringUtils; 30 | import org.springframework.web.client.RestTemplate; 31 | 32 | import java.io.ByteArrayInputStream; 33 | import java.io.InputStream; 34 | import java.util.ArrayList; 35 | import java.util.HashMap; 36 | import java.util.List; 37 | import java.util.Map; 38 | 39 | /** 40 | * Default implementation of SObjectOperations. 41 | * 42 | * @author Umut Utkan 43 | * @author Jared ottley 44 | */ 45 | public class SObjectsTemplate extends AbstractSalesForceOperations implements SObjectOperations { 46 | 47 | private RestTemplate restTemplate; 48 | 49 | public SObjectsTemplate(Salesforce api, RestTemplate restTemplate) { 50 | super(api); 51 | this.restTemplate = restTemplate; 52 | } 53 | 54 | @Override 55 | public List getSObjects() { 56 | requireAuthorization(); 57 | JsonNode dataNode = restTemplate.getForObject(api.getBaseUrl() + "/{version}/sobjects", JsonNode.class, getVersion()); 58 | return api.readList(dataNode.get("sobjects"), Map.class); 59 | } 60 | 61 | @Override 62 | public SObjectSummary getSObjectSummary(String name) { 63 | requireAuthorization(); 64 | JsonNode node = restTemplate.getForObject(api.getBaseUrl() + "/{version}/sobjects/{name}", JsonNode.class, getVersion(), name); 65 | return api.readObject(node.get("objectDescribe"), SObjectSummary.class); 66 | } 67 | 68 | @Override 69 | public SObjectDetail describeSObject(String name) { 70 | requireAuthorization(); 71 | return restTemplate.getForObject(api.getBaseUrl() + "/{version}/sobjects/{name}/describe", SObjectDetail.class, getVersion(), name); 72 | } 73 | 74 | @Override 75 | public Map getRow(String name, String id, String... fields) { 76 | requireAuthorization(); 77 | URIBuilder builder = URIBuilder.fromUri(api.getBaseUrl() + "/" + getVersion() + "/sobjects/" + name + "/" + id); 78 | if (fields.length > 0) { 79 | builder.queryParam("fields", StringUtils.arrayToCommaDelimitedString(fields)); 80 | } 81 | return restTemplate.getForObject(builder.build(), Map.class); 82 | } 83 | 84 | @Override 85 | public InputStream getBlob(String name, String id, String field) { 86 | requireAuthorization(); 87 | HttpHeaders headers = new HttpHeaders(); 88 | HttpEntity entity = new HttpEntity<>(headers); 89 | ResponseEntity response = restTemplate.exchange( 90 | api.getBaseUrl() + "/{version}/sobjects/{name}/{id}/{field}", HttpMethod.GET, entity, byte[].class, 91 | getVersion(), name, id, field); 92 | return new ByteArrayInputStream(response.getBody()); 93 | 94 | } 95 | 96 | @Override 97 | @SuppressWarnings("rawtypes") 98 | public Map create(String name, Map fields) { 99 | requireAuthorization(); 100 | HttpHeaders headers = new HttpHeaders(); 101 | headers.setContentType(MediaType.APPLICATION_JSON); 102 | HttpEntity entity = new HttpEntity(fields, headers); 103 | return restTemplate.postForObject(api.getBaseUrl() + "/{version}/sobjects/{name}", entity, Map.class, getVersion(), name); 104 | } 105 | 106 | @Override 107 | public Map update(String sObjectName, String sObjectId, Map fields) { 108 | requireAuthorization(); 109 | HttpHeaders headers = new HttpHeaders(); 110 | headers.setContentType(MediaType.APPLICATION_JSON); 111 | HttpEntity> entity = new HttpEntity>(fields, headers); 112 | Map result = restTemplate.postForObject(api.getBaseUrl() + "/{version}/sobjects/{sObjectName}/{sObjectId}?_HttpMethod=PATCH", 113 | entity, Map.class, getVersion(), sObjectName, sObjectId); 114 | // SF returns an empty body on success, so mimic the same update you'd get from a create success for consistency 115 | if (result == null) { 116 | result = new HashMap(); 117 | result.put("id", sObjectId); 118 | result.put("success", true); 119 | result.put("errors", new ArrayList()); 120 | } 121 | return result; 122 | } 123 | 124 | 125 | @Override 126 | public void delete(String sObjectName, String sObjectId) 127 | { 128 | requireAuthorization(); 129 | restTemplate.delete(api.getBaseUrl() + "/{version}/sobjects/{sObjectName}/{sObjectId}", getVersion(), sObjectName, sObjectId); 130 | } 131 | 132 | 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/SearchTemplate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import com.fasterxml.jackson.databind.JsonNode; 19 | import org.springframework.social.salesforce.api.ResultItem; 20 | import org.springframework.social.salesforce.api.Salesforce; 21 | import org.springframework.social.salesforce.api.SearchOperations; 22 | import org.springframework.social.support.URIBuilder; 23 | import org.springframework.web.client.RestTemplate; 24 | 25 | import java.net.URI; 26 | import java.util.List; 27 | 28 | /** 29 | * Default implementation of SearchOperations. 30 | * 31 | * @author Umut Utkan 32 | * @author Jared Ottley 33 | */ 34 | public class SearchTemplate extends AbstractSalesForceOperations implements SearchOperations { 35 | 36 | private RestTemplate restTemplate; 37 | 38 | public SearchTemplate(Salesforce api, RestTemplate restTemplate) { 39 | super(api); 40 | this.restTemplate = restTemplate; 41 | } 42 | 43 | /** 44 | * @see org.springframework.social.salesforce.api.SearchOperations#search(java.lang.String) 45 | */ 46 | @Override 47 | public List search(String soslQuery) { 48 | requireAuthorization(); 49 | URI uri = URIBuilder.fromUri(api.getBaseUrl() + "/" + getVersion() + "/search").queryParam("q", soslQuery).build(); 50 | JsonNode arr = restTemplate.getForObject(uri, JsonNode.class); 51 | return api.readList(arr, ResultItem.class); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/UserOperationsTemplate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import org.springframework.http.HttpEntity; 19 | import org.springframework.http.HttpMethod; 20 | import org.springframework.social.salesforce.api.Salesforce; 21 | import org.springframework.social.salesforce.api.SalesforceUserDetails; 22 | import org.springframework.social.salesforce.api.UserOperations; 23 | import org.springframework.web.client.RestTemplate; 24 | 25 | /** 26 | * Default implementation of UserOperations. 27 | * 28 | * @author Alexandra Leahu 29 | * @author Jared Ottley 30 | */ 31 | public class UserOperationsTemplate extends AbstractSalesForceOperations implements UserOperations { 32 | 33 | private RestTemplate restTemplate; 34 | 35 | public UserOperationsTemplate(Salesforce api, RestTemplate restTemplate) { 36 | super(api); 37 | this.restTemplate = restTemplate; 38 | } 39 | 40 | @Override 41 | public SalesforceUserDetails getSalesforceUserDetails() { 42 | requireAuthorization(); 43 | return restTemplate.exchange(api.getUserInfoUrl(), HttpMethod.GET, new HttpEntity<>(""), SalesforceUserDetails.class, getVersion()).getBody(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/json/ApiVersionMixin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl.json; 17 | 18 | import org.springframework.social.salesforce.api.ApiVersion; 19 | 20 | import com.fasterxml.jackson.annotation.JsonCreator; 21 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | 24 | /** 25 | * {@link ApiVersion} 26 | * 27 | * @author Umut Utkan 28 | * @author Jared Ottley 29 | */ 30 | @JsonIgnoreProperties(ignoreUnknown = true) 31 | public class ApiVersionMixin { 32 | 33 | @JsonCreator 34 | ApiVersionMixin( 35 | @JsonProperty("version") String version, 36 | @JsonProperty("label") String label, 37 | @JsonProperty("url") String url) { 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/json/FieldMixin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl.json; 17 | 18 | import com.fasterxml.jackson.annotation.JsonCreator; 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | 22 | import org.springframework.social.salesforce.api.Field; 23 | import org.springframework.social.salesforce.api.PickListEntry; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * {@link Field} 29 | * 30 | * @author Umut Utkan 31 | */ 32 | @JsonIgnoreProperties(ignoreUnknown = true) 33 | public class FieldMixin { 34 | 35 | @JsonCreator 36 | FieldMixin( 37 | @JsonProperty("name") String name, 38 | @JsonProperty("type") String type, 39 | @JsonProperty("label") String label) { 40 | } 41 | 42 | 43 | @JsonProperty("length") 44 | int length; 45 | 46 | @JsonProperty("defaultValue") 47 | String defaultValue; 48 | 49 | @JsonProperty("updateable") 50 | boolean updateable; 51 | 52 | @JsonProperty("calculated") 53 | boolean calculated; 54 | 55 | @JsonProperty("filterable") 56 | boolean filterable; 57 | 58 | @JsonProperty("sortable") 59 | boolean sortable; 60 | 61 | @JsonProperty("controllerName") 62 | String controllerName; 63 | 64 | @JsonProperty("unique") 65 | boolean unique; 66 | 67 | @JsonProperty("nillable") 68 | boolean nillable; 69 | 70 | @JsonProperty("precision") 71 | int precision; 72 | 73 | @JsonProperty("scale") 74 | int scale; 75 | 76 | @JsonProperty("caseSensitive") 77 | boolean caseSensitive; 78 | 79 | @JsonProperty("byteLength") 80 | int byteLength; 81 | 82 | @JsonProperty("nameField") 83 | boolean nameField; 84 | 85 | @JsonProperty("externalId") 86 | boolean externalId; 87 | 88 | @JsonProperty("idLookup") 89 | boolean idLookup; 90 | 91 | @JsonProperty("inlineHelpText") 92 | String inlineHelpText; 93 | 94 | @JsonProperty("createable") 95 | boolean createable; 96 | 97 | @JsonProperty("soapType") 98 | String soapType; 99 | 100 | @JsonProperty("autoNumber") 101 | boolean autoNumber; 102 | 103 | @JsonProperty("namePointing") 104 | boolean namePointing; 105 | 106 | @JsonProperty("custom") 107 | boolean custom; 108 | 109 | @JsonProperty("defaultedOnCreate") 110 | boolean defaultedOnCreate; 111 | 112 | @JsonProperty("deprecatedAndHidden") 113 | boolean deprecatedAndHidden; 114 | 115 | @JsonProperty("htmlFormatted") 116 | boolean htmlFormatted; 117 | 118 | @JsonProperty("defaultValueFormula") 119 | String defaultValueFormula; 120 | 121 | @JsonProperty("calculatedFormula") 122 | String calculatedFormula; 123 | 124 | @JsonProperty("restrictedPicklist") 125 | boolean restrictedPicklist; 126 | 127 | @JsonProperty("picklistValues") 128 | List picklistValues; 129 | 130 | @JsonProperty("dependentPicklist") 131 | boolean dependentPicklist; 132 | 133 | @JsonProperty("referenceTo") 134 | String[] referenceTo; 135 | 136 | @JsonProperty("relationshipName") 137 | String relationshipName; 138 | 139 | @JsonProperty("relationshipOrder") 140 | int relationshipOrder; 141 | 142 | @JsonProperty("writeRequiresMasterRead") 143 | boolean writeRequiresMasterRead; 144 | 145 | @JsonProperty("cascadeDelete") 146 | boolean cascadeDelete; 147 | 148 | @JsonProperty("restrictedDelete") 149 | boolean restrictedDelete; 150 | 151 | @JsonProperty("digits") 152 | int digits; 153 | 154 | @JsonProperty("groupable") 155 | boolean groupable; 156 | 157 | } 158 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/json/PhotoMixin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl.json; 17 | 18 | 19 | import org.springframework.social.salesforce.api.Photo; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 23 | import com.fasterxml.jackson.annotation.JsonProperty; 24 | 25 | 26 | /** 27 | * {@link Photo} 28 | * 29 | * @author Umut Utkan 30 | */ 31 | @JsonIgnoreProperties(ignoreUnknown = true) 32 | public class PhotoMixin { 33 | 34 | @JsonCreator 35 | PhotoMixin( 36 | @JsonProperty String smallPhotoUrl, 37 | @JsonProperty String largePhotoUrl) { 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/json/PickListEntryMixin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl.json; 17 | 18 | 19 | import org.springframework.social.salesforce.api.PickListEntry; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 23 | import com.fasterxml.jackson.annotation.JsonProperty; 24 | 25 | 26 | /** 27 | * {@link PickListEntry} 28 | * 29 | * @author Umut Utkan 30 | */ 31 | @JsonIgnoreProperties(ignoreUnknown = true) 32 | public class PickListEntryMixin { 33 | 34 | @JsonCreator 35 | PickListEntryMixin( 36 | @JsonProperty("value") String value, 37 | @JsonProperty("label") String label, 38 | @JsonProperty("active") boolean active, 39 | @JsonProperty("defaultValue") boolean defaultValue) { 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/json/QueryResultMixin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl.json; 17 | 18 | import com.fasterxml.jackson.annotation.JsonCreator; 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | 22 | import org.springframework.social.salesforce.api.QueryResult; 23 | import org.springframework.social.salesforce.api.ResultItem; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * {@link QueryResult} 29 | * 30 | * @author Umut Utkan 31 | */ 32 | @JsonIgnoreProperties(ignoreUnknown = true) 33 | public class QueryResultMixin { 34 | 35 | @JsonCreator 36 | QueryResultMixin( 37 | @JsonProperty("totalSize") int totalSize, 38 | @JsonProperty("done") boolean done) { 39 | } 40 | 41 | @JsonProperty("nextRecordsUrl") 42 | String nextRecordsUrl; 43 | 44 | @JsonProperty("records") 45 | List records; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/json/RecordTypeInfoMixin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl.json; 17 | 18 | 19 | import org.springframework.social.salesforce.api.RecordTypeInfo; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 23 | import com.fasterxml.jackson.annotation.JsonProperty; 24 | 25 | 26 | /** 27 | * {@link RecordTypeInfo} 28 | * 29 | * @author Umut Utkan 30 | */ 31 | @JsonIgnoreProperties(ignoreUnknown = true) 32 | public class RecordTypeInfoMixin { 33 | 34 | @JsonCreator 35 | RecordTypeInfoMixin( 36 | @JsonProperty("name") String name, 37 | @JsonProperty("available") boolean available, 38 | @JsonProperty("recordTypeId") String recordTypeId, 39 | @JsonProperty("defaultRecordTypeMapping") boolean defaultRecordTypeMapping) { 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/json/RelationshipMixin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl.json; 17 | 18 | 19 | import org.springframework.social.salesforce.api.Relationship; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 23 | import com.fasterxml.jackson.annotation.JsonProperty; 24 | 25 | 26 | /** 27 | * {@link Relationship} 28 | * 29 | * @author Umut Utkan 30 | */ 31 | @JsonIgnoreProperties(ignoreUnknown = true) 32 | public class RelationshipMixin { 33 | 34 | @JsonCreator 35 | RelationshipMixin( 36 | @JsonProperty("field") String field, 37 | @JsonProperty("relationshipName") String relationshipName, 38 | @JsonProperty("childObject") String childObject) { 39 | } 40 | 41 | @JsonProperty("deprecatedAndHidden") 42 | boolean deprecatedAndHidden; 43 | 44 | @JsonProperty("cascadeDelete") 45 | boolean cascadeDelete; 46 | 47 | @JsonProperty("restrictedDelete") 48 | boolean restrictedDelete; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/json/ResultItemDeserializer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl.json; 17 | 18 | import com.fasterxml.jackson.core.JsonParser; 19 | import com.fasterxml.jackson.core.JsonProcessingException; 20 | import com.fasterxml.jackson.databind.DeserializationContext; 21 | import com.fasterxml.jackson.databind.JsonDeserializer; 22 | import com.fasterxml.jackson.databind.JsonNode; 23 | import com.fasterxml.jackson.databind.ObjectMapper; 24 | import org.joor.Reflect; 25 | import org.springframework.social.salesforce.api.QueryResult; 26 | import org.springframework.social.salesforce.api.ResultItem; 27 | 28 | import java.io.IOException; 29 | import java.util.Map; 30 | 31 | /** 32 | * Deserializer for {@link ResultItem} 33 | * 34 | * @author Umut Utkan 35 | */ 36 | public class ResultItemDeserializer extends JsonDeserializer 37 | { 38 | 39 | @SuppressWarnings({ "unchecked", "rawtypes" }) 40 | @Override 41 | public ResultItem deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException 42 | { 43 | ObjectMapper mapper = new ObjectMapper(); 44 | Reflect.on(mapper).set("_deserializationConfig", ctxt.getConfig()); 45 | jp.setCodec(mapper); 46 | 47 | JsonNode jsonNode = jp.readValueAsTree(); 48 | Map map = mapper.convertValue(jsonNode, Map.class); 49 | ResultItem item = new ResultItem((String) ((Map) map.get("attributes")).get("type"), 50 | (String) ((Map) map.get("attributes")).get("url")); 51 | map.remove("attributes"); 52 | //item.setAttributes(map); 53 | 54 | for(Map.Entry entry : map.entrySet()) { 55 | if(entry.getValue() instanceof Map) { 56 | Map inner = (Map) entry.getValue(); 57 | if(inner.get("records") != null) { 58 | item.getAttributes().put(entry.getKey(), mapper.convertValue(jsonNode.get(entry.getKey()), QueryResult.class)); 59 | } else { 60 | item.getAttributes().put(entry.getKey(), mapper.convertValue(jsonNode.get(entry.getKey()), ResultItem.class)); 61 | } 62 | } else { 63 | item.getAttributes().put(entry.getKey(), entry.getValue()); 64 | } 65 | } 66 | 67 | return item; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/json/ResultItemMixin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl.json; 17 | 18 | 19 | import org.springframework.social.salesforce.api.ResultItem; 20 | 21 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 22 | 23 | 24 | /** 25 | * {@link ResultItem} 26 | * 27 | * @author Umut Utkan 28 | */ 29 | @JsonDeserialize(using = ResultItemDeserializer.class) 30 | public class ResultItemMixin { 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/json/SObjectDetailMixin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl.json; 17 | 18 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 19 | import com.fasterxml.jackson.annotation.JsonProperty; 20 | import org.springframework.social.salesforce.api.Field; 21 | import org.springframework.social.salesforce.api.RecordTypeInfo; 22 | import org.springframework.social.salesforce.api.Relationship; 23 | import org.springframework.social.salesforce.api.SObjectDetail; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * {@link SObjectDetail} 29 | * 30 | * @author Umut Utkan 31 | */ 32 | @JsonIgnoreProperties(ignoreUnknown = true) 33 | public class SObjectDetailMixin extends SObjectSummaryMixin { 34 | 35 | @JsonProperty("fields") 36 | List fields; 37 | 38 | @JsonProperty("childRelationships") 39 | List childRelationships; 40 | 41 | @JsonProperty("listviewable") 42 | boolean listviewable; 43 | 44 | @JsonProperty("lookupLayoutable") 45 | boolean lookupLayoutable; 46 | 47 | @JsonProperty("recordTypeInfos") 48 | List recordTypeInfos; 49 | 50 | @JsonProperty("searchLayoutable") 51 | boolean searchLayoutable; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/json/SObjectSummaryMixin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl.json; 17 | 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | 22 | import java.util.Map; 23 | 24 | import org.springframework.social.salesforce.api.SObjectSummary; 25 | 26 | /** 27 | * {@link SObjectSummary} 28 | * 29 | * @author Umut Utkan 30 | */ 31 | @JsonIgnoreProperties(ignoreUnknown = true) 32 | public class SObjectSummaryMixin { 33 | 34 | @JsonProperty("name") 35 | String name; 36 | 37 | @JsonProperty("label") 38 | String label; 39 | 40 | @JsonProperty("updateable") 41 | boolean updateable; 42 | 43 | @JsonProperty("keyPrefix") 44 | String keyPrefix; 45 | 46 | @JsonProperty("custom") 47 | boolean custom; 48 | 49 | @JsonProperty("urls") 50 | Map urls; 51 | 52 | @JsonProperty("searchable") 53 | boolean searchable; 54 | 55 | @JsonProperty("labelPlural") 56 | String labelPlural; 57 | 58 | @JsonProperty("layaoutable") 59 | boolean layoutable; 60 | 61 | @JsonProperty("activateable") 62 | boolean activateable; 63 | 64 | @JsonProperty("createable") 65 | boolean createable; 66 | 67 | @JsonProperty("deprecatedAndHidded") 68 | boolean deprecatedAndHidden; 69 | 70 | @JsonProperty("customSetting") 71 | boolean customSetting; 72 | 73 | @JsonProperty("deletable") 74 | boolean deletable; 75 | 76 | @JsonProperty("feedEnabled") 77 | boolean feedEnabled; 78 | 79 | @JsonProperty("mergeable") 80 | boolean mergeable; 81 | 82 | @JsonProperty("queryable") 83 | boolean queryable; 84 | 85 | @JsonProperty("replicateable") 86 | boolean replicateable; 87 | 88 | @JsonProperty("retriveable") 89 | boolean retrieveable; 90 | 91 | @JsonProperty("undeletable") 92 | boolean undeletable; 93 | 94 | @JsonProperty("triggerable") 95 | boolean triggerable; 96 | 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/json/SalesforceModule.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl.json; 17 | 18 | import com.fasterxml.jackson.databind.Module; 19 | import com.fasterxml.jackson.databind.module.SimpleModule; 20 | import org.springframework.social.salesforce.api.ApiVersion; 21 | import org.springframework.social.salesforce.api.Field; 22 | import org.springframework.social.salesforce.api.Photo; 23 | import org.springframework.social.salesforce.api.PickListEntry; 24 | import org.springframework.social.salesforce.api.QueryResult; 25 | import org.springframework.social.salesforce.api.RecordTypeInfo; 26 | import org.springframework.social.salesforce.api.Relationship; 27 | import org.springframework.social.salesforce.api.ResultItem; 28 | import org.springframework.social.salesforce.api.SObjectDetail; 29 | import org.springframework.social.salesforce.api.SObjectSummary; 30 | import org.springframework.social.salesforce.api.SalesforceProfile; 31 | import org.springframework.social.salesforce.api.Status; 32 | import org.springframework.social.salesforce.api.SalesforceUserDetails; 33 | 34 | 35 | /** 36 | * Jackson module for api version v23.0. 37 | * 38 | * @author Umut Utkan 39 | * @author Jared Ottley 40 | * @author Alexandra Leahu 41 | */ 42 | public class SalesforceModule extends SimpleModule 43 | { 44 | 45 | public SalesforceModule() { 46 | super("SalesforceModule"); 47 | } 48 | 49 | @Override 50 | public void setupModule(Module.SetupContext context) { 51 | super.setupModule(context); 52 | 53 | context.setMixInAnnotations(ApiVersion.class, ApiVersionMixin.class); 54 | context.setMixInAnnotations(SalesforceProfile.class, SalesforceProfileMixin.class); 55 | context.setMixInAnnotations(SalesforceUserDetails.class, SalesforceUserDetailsMixin.class); 56 | context.setMixInAnnotations(Photo.class, PhotoMixin.class); 57 | context.setMixInAnnotations(Status.class, StatusMixin.class); 58 | context.setMixInAnnotations(SObjectSummary.class, SObjectSummaryMixin.class); 59 | context.setMixInAnnotations(RecordTypeInfo.class, RecordTypeInfoMixin.class); 60 | context.setMixInAnnotations(Relationship.class, RelationshipMixin.class); 61 | context.setMixInAnnotations(PickListEntry.class, PickListEntryMixin.class); 62 | context.setMixInAnnotations(Field.class, FieldMixin.class); 63 | context.setMixInAnnotations(SObjectDetail.class, SObjectDetailMixin.class); 64 | context.setMixInAnnotations(QueryResult.class, QueryResultMixin.class); 65 | context.setMixInAnnotations(ResultItem.class, ResultItemMixin.class); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/json/SalesforceProfileMixin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl.json; 17 | 18 | import com.fasterxml.jackson.annotation.JsonCreator; 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import org.springframework.social.salesforce.api.Photo; 22 | import org.springframework.social.salesforce.api.SalesforceProfile; 23 | 24 | /** 25 | * {@link SalesforceProfile} 26 | * 27 | * @author Umut Utkan 28 | * @author Alexandra Leahu 29 | */ 30 | @JsonIgnoreProperties(ignoreUnknown = true) 31 | public class SalesforceProfileMixin { 32 | 33 | @JsonCreator 34 | SalesforceProfileMixin( 35 | @JsonProperty("id") String id, 36 | @JsonProperty("firstName") String firstName, 37 | @JsonProperty("lastName") String lastName, 38 | @JsonProperty("email") String email, 39 | @JsonProperty("name") String name) { 40 | } 41 | 42 | @JsonProperty("photo") 43 | Photo photo; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/json/SalesforceUserDetailsMixin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl.json; 17 | 18 | 19 | import org.springframework.social.salesforce.api.SalesforceUserDetails; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 23 | import com.fasterxml.jackson.annotation.JsonProperty; 24 | 25 | /** 26 | * {@link SalesforceUserDetails} 27 | * @author Alexandra Leahu 28 | */ 29 | @JsonIgnoreProperties(ignoreUnknown = true) 30 | public class SalesforceUserDetailsMixin { 31 | 32 | @JsonCreator 33 | SalesforceUserDetailsMixin( 34 | @JsonProperty("user_id") String id, 35 | @JsonProperty("given_name") String firstName, 36 | @JsonProperty("family_name") String lastName, 37 | @JsonProperty("email") String email, 38 | @JsonProperty("name") String name, 39 | @JsonProperty("organization_id") String organizationId, 40 | @JsonProperty("nickname") String nickname, 41 | @JsonProperty("preferred_username") String preferredUsername) { 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/api/impl/json/StatusMixin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl.json; 17 | 18 | 19 | import com.fasterxml.jackson.annotation.JsonCreator; 20 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | import org.springframework.social.salesforce.api.Status; 27 | 28 | /** 29 | * {@link Status} 30 | * 31 | * @author Umut Utkan 32 | */ 33 | @JsonIgnoreProperties(ignoreUnknown = true) 34 | public class StatusMixin { 35 | 36 | @JsonCreator 37 | StatusMixin( 38 | @JsonProperty("text") String text) { 39 | } 40 | 41 | @JsonProperty("messageSegments") 42 | List> segments; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/client/BaseSalesforceFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.client; 17 | 18 | import java.util.Map; 19 | 20 | import org.springframework.social.salesforce.api.Salesforce; 21 | import org.springframework.social.salesforce.api.impl.SalesforceTemplate; 22 | import org.springframework.social.salesforce.connect.SalesforceServiceProvider; 23 | import org.springframework.social.support.ClientHttpRequestFactorySelector; 24 | import org.springframework.util.LinkedMultiValueMap; 25 | import org.springframework.util.MultiValueMap; 26 | import org.springframework.web.client.RestTemplate; 27 | 28 | /** 29 | * Default implementation of SalesforceFactory. 30 | * 31 | * @author Umut Utkan 32 | * @author Jared Ottley 33 | */ 34 | public class BaseSalesforceFactory implements SalesforceFactory { 35 | 36 | private final static String DEFAULT_AUTH_URL = SalesforceServiceProvider.PRODUCTION_GATEWAY_URL + SalesforceServiceProvider.TOKEN_PATH; 37 | 38 | 39 | private String clientId; 40 | 41 | private String clientSecret; 42 | 43 | private String authorizeUrl = DEFAULT_AUTH_URL; 44 | 45 | private RestTemplate restTemplate; 46 | 47 | 48 | public BaseSalesforceFactory(String clientId, String clientSecret) { 49 | this(clientId, clientSecret, createRestTemplate()); 50 | } 51 | 52 | public BaseSalesforceFactory(String clientId, String clientSecret, RestTemplate restTemplate) { 53 | this.clientId = clientId; 54 | this.clientSecret = clientSecret; 55 | this.restTemplate = restTemplate; 56 | } 57 | 58 | 59 | public void setAuthorizeUrl(String authorizeUrl) { 60 | this.authorizeUrl = authorizeUrl; 61 | } 62 | 63 | public String getAuthorizeUrl() { 64 | return (this.authorizeUrl == null) ? DEFAULT_AUTH_URL : this.authorizeUrl; 65 | } 66 | 67 | @Override 68 | @SuppressWarnings("unchecked") 69 | public Salesforce create(String username, String password, String securityToken) { 70 | MultiValueMap map = new LinkedMultiValueMap(); 71 | map.add("grant_type", "password"); 72 | map.add("client_id", this.clientId); 73 | map.add("client_secret", this.clientSecret); 74 | map.add("username", username); 75 | map.add("password", password + (securityToken == null ? "" : securityToken)); 76 | 77 | Map token = restTemplate.postForObject(this.authorizeUrl, map, Map.class); 78 | SalesforceTemplate template = new SalesforceTemplate(token.get("access_token")); 79 | String instanceUrl = token.get("instance_url"); 80 | if (instanceUrl != null) { 81 | template.setInstanceUrl(instanceUrl); 82 | } 83 | return template; 84 | } 85 | 86 | private static RestTemplate createRestTemplate() { 87 | RestTemplate restTemplate = new RestTemplate(); 88 | restTemplate.setRequestFactory(ClientHttpRequestFactorySelector.getRequestFactory()); 89 | restTemplate.setErrorHandler(new ErrorHandler()); 90 | return restTemplate; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/client/ErrorHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.client; 17 | 18 | import com.fasterxml.jackson.core.JsonFactory; 19 | import com.fasterxml.jackson.core.JsonParseException; 20 | import com.fasterxml.jackson.databind.ObjectMapper; 21 | import org.springframework.http.HttpStatus; 22 | import org.springframework.http.client.ClientHttpResponse; 23 | import org.springframework.social.InvalidAuthorizationException; 24 | import org.springframework.social.OperationNotPermittedException; 25 | import org.springframework.social.RateLimitExceededException; 26 | import org.springframework.social.salesforce.connect.SalesforceServiceProvider; 27 | import org.springframework.web.client.DefaultResponseErrorHandler; 28 | 29 | import java.io.IOException; 30 | import java.util.Map; 31 | 32 | /** 33 | * Custom error handler for handling Salesforce API specific error responses. 34 | * 35 | * @author Umut Utkan 36 | * @author Jared Ottley 37 | */ 38 | public class ErrorHandler extends DefaultResponseErrorHandler { 39 | 40 | @Override 41 | public void handleError(ClientHttpResponse response) throws IOException { 42 | if (response.getStatusCode().equals(HttpStatus.BAD_REQUEST)) { 43 | Map error = extractErrorDetailsFromResponse(response); 44 | if ("unsupported_response_type".equals(error.get("error"))) { 45 | throw new OperationNotPermittedException(SalesforceServiceProvider.ID, error.get("error_description")); 46 | } else if ("invalid_client_id".equals(error.get("error"))) { 47 | throw new InvalidAuthorizationException(SalesforceServiceProvider.ID, error.get("error_description")); 48 | } else if ("invalid_request".equals(error.get("error"))) { 49 | throw new OperationNotPermittedException(SalesforceServiceProvider.ID, error.get("error_description")); 50 | } else if ("invalid_client_credentials".equals(error.get("error"))) { 51 | throw new InvalidAuthorizationException(SalesforceServiceProvider.ID, error.get("error_description")); 52 | } else if ("invalid_grant".equals(error.get("error"))) { 53 | if ("invalid user credentials".equals(error.get("error_description"))) { 54 | throw new InvalidAuthorizationException(SalesforceServiceProvider.ID, error.get("error_description")); 55 | } else if ("IP restricted or invalid login hours".equals(error.get("error_description"))) { 56 | throw new OperationNotPermittedException(SalesforceServiceProvider.ID, error.get("error_description")); 57 | } 58 | throw new InvalidAuthorizationException(SalesforceServiceProvider.ID, error.get("error_description")); 59 | } else if ("inactive_user".equals(error.get("error"))) { 60 | throw new OperationNotPermittedException(SalesforceServiceProvider.ID, error.get("error_description")); 61 | } else if ("inactive_org".equals(error.get("error"))) { 62 | throw new OperationNotPermittedException(SalesforceServiceProvider.ID, error.get("error_description")); 63 | } else if ("rate_limit_exceeded".equals(error.get("error"))) { 64 | throw new RateLimitExceededException(SalesforceServiceProvider.ID); 65 | } else if ("invalid_scope".equals(error.get("error"))) { 66 | throw new InvalidAuthorizationException(SalesforceServiceProvider.ID, error.get("error_description")); 67 | } 68 | } 69 | 70 | super.handleError(response); 71 | } 72 | 73 | @SuppressWarnings("unchecked") 74 | private Map extractErrorDetailsFromResponse(ClientHttpResponse response) throws IOException { 75 | ObjectMapper mapper = new ObjectMapper(new JsonFactory()); 76 | try { 77 | return (Map) mapper.readValue(response.getBody(), Map.class); 78 | } catch (JsonParseException e) { 79 | return null; 80 | } 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/client/SalesforceFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.client; 17 | 18 | import org.springframework.social.salesforce.api.Salesforce; 19 | 20 | /** 21 | * Salesforce template factory for those who want to use salesforce with client login. 22 | * 23 | * @author Umut Utkan 24 | */ 25 | public interface SalesforceFactory { 26 | 27 | Salesforce create(String username, String password, String securityToken); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/client/SimpleCachingSalesforceFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.client; 17 | 18 | import org.springframework.social.salesforce.api.Salesforce; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | /** 24 | * Simple caching wrapper for SalesforceFactory. 25 | * 26 | * @author Umut Utkan 27 | */ 28 | public class SimpleCachingSalesforceFactory implements SalesforceFactory { 29 | 30 | private SalesforceFactory delegate; 31 | 32 | private final Map cache = new HashMap(); 33 | 34 | 35 | public SimpleCachingSalesforceFactory(SalesforceFactory delegate) { 36 | this.delegate = delegate; 37 | } 38 | 39 | 40 | @Override 41 | public Salesforce create(String username, String password, String securityToken) { 42 | synchronized (this.cache) { 43 | Salesforce template = cache.get(username); 44 | if (template == null) { 45 | this.cache.put(username, this.delegate.create(username, password, securityToken)); 46 | } 47 | return this.cache.get(username); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/config/support/SalesforceApiHelper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.config.support; 17 | 18 | import org.apache.commons.logging.Log; 19 | import org.apache.commons.logging.LogFactory; 20 | import org.springframework.social.UserIdSource; 21 | import org.springframework.social.config.xml.ApiHelper; 22 | import org.springframework.social.connect.Connection; 23 | import org.springframework.social.connect.UsersConnectionRepository; 24 | import org.springframework.social.salesforce.api.Salesforce; 25 | 26 | /** 27 | * 28 | * @author Jared Ottley 29 | * 30 | */ 31 | public class SalesforceApiHelper implements ApiHelper 32 | { 33 | private final UsersConnectionRepository usersConnectionRepository; 34 | 35 | private final UserIdSource userIdSource; 36 | 37 | private SalesforceApiHelper(UsersConnectionRepository usersConnectionRepository, UserIdSource userIdSource) { 38 | this.usersConnectionRepository = usersConnectionRepository; 39 | this.userIdSource = userIdSource; 40 | } 41 | 42 | 43 | @Override 44 | public Salesforce getApi() 45 | { 46 | Connection connection = usersConnectionRepository.createConnectionRepository(userIdSource.getUserId()).findPrimaryConnection(Salesforce.class); 47 | if (logger.isDebugEnabled() && connection == null) { 48 | logger.debug("No current connection; Returning default TwitterTemplate instance."); 49 | } 50 | return connection != null ? connection.getApi() : null; 51 | } 52 | 53 | private final static Log logger = LogFactory.getLog(SalesforceApiHelper.class); 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/config/xml/SalesforceConfigBeanDefinitionParser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.config.xml; 17 | 18 | import org.springframework.social.config.xml.AbstractProviderConfigBeanDefinitionParser; 19 | import org.springframework.social.salesforce.config.support.SalesforceApiHelper; 20 | import org.springframework.social.salesforce.connect.SalesforceConnectionFactory; 21 | import org.springframework.social.salesforce.security.SalesforceAuthenticationService; 22 | import org.springframework.social.security.provider.SocialAuthenticationService; 23 | 24 | /** 25 | * 26 | * @author Jared Ottley 27 | * 28 | */ 29 | public class SalesforceConfigBeanDefinitionParser extends AbstractProviderConfigBeanDefinitionParser 30 | { 31 | public SalesforceConfigBeanDefinitionParser() { 32 | super(SalesforceConnectionFactory.class, SalesforceApiHelper.class); 33 | } 34 | 35 | @Override 36 | protected Class> getAuthenticationServiceClass() { 37 | return SalesforceAuthenticationService.class; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/config/xml/SalesforceNamespaceHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.config.xml; 17 | 18 | import org.springframework.social.config.xml.AbstractProviderConfigBeanDefinitionParser; 19 | import org.springframework.social.config.xml.AbstractProviderConfigNamespaceHandler; 20 | 21 | /** 22 | * 23 | * @author Jared Ottley 24 | * 25 | */ 26 | public class SalesforceNamespaceHandler extends AbstractProviderConfigNamespaceHandler 27 | { 28 | @Override 29 | protected AbstractProviderConfigBeanDefinitionParser getProviderConfigBeanDefinitionParser() 30 | { 31 | return new SalesforceConfigBeanDefinitionParser(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/connect/SalesforceAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.connect; 17 | 18 | import org.springframework.social.ApiException; 19 | import org.springframework.social.connect.ApiAdapter; 20 | import org.springframework.social.connect.ConnectionValues; 21 | import org.springframework.social.connect.UserProfile; 22 | import org.springframework.social.connect.UserProfileBuilder; 23 | import org.springframework.social.salesforce.api.Salesforce; 24 | import org.springframework.social.salesforce.api.SalesforceProfile; 25 | import org.springframework.social.salesforce.api.SalesforceUserDetails; 26 | import org.springframework.util.StringUtils; 27 | 28 | 29 | /** 30 | * Salesforce ApiAdapter implementation. 31 | * 32 | * @author Umut Utkan 33 | * @author Jared Ottley 34 | * @author Alexandra Leahu 35 | */ 36 | public class SalesforceAdapter implements ApiAdapter { 37 | 38 | private String instanceUrl = null; 39 | private String gatewayUrl = null; 40 | 41 | public SalesforceAdapter() 42 | { 43 | //NOOP 44 | } 45 | 46 | public SalesforceAdapter(String instanceUrl) 47 | { 48 | this.instanceUrl = instanceUrl; 49 | } 50 | 51 | public SalesforceAdapter(String instanceUrl, boolean sandbox) 52 | { 53 | this.instanceUrl = instanceUrl; 54 | 55 | if (sandbox) 56 | { 57 | this.gatewayUrl = SalesforceServiceProvider.SANDBOX_GATEWAY_URL; 58 | } 59 | } 60 | 61 | @Deprecated 62 | public SalesforceAdapter(String instanceUrl, String gatewayUrl) 63 | { 64 | this.instanceUrl = instanceUrl; 65 | this.gatewayUrl = gatewayUrl; 66 | } 67 | 68 | public SalesforceAdapter(boolean sandbox) 69 | { 70 | if (sandbox) 71 | { 72 | this.gatewayUrl = SalesforceServiceProvider.SANDBOX_GATEWAY_URL; 73 | } 74 | } 75 | 76 | public boolean test(Salesforce salesForce) 77 | { 78 | try 79 | { 80 | if (StringUtils.isEmpty(instanceUrl)) 81 | { 82 | salesForce.chatterOperations().getUserProfile(); 83 | } 84 | else 85 | { 86 | salesForce.chatterOperations(instanceUrl).getUserProfile(); 87 | } 88 | return true; 89 | } 90 | catch (ApiException e) 91 | { 92 | return false; 93 | } 94 | } 95 | 96 | public void setConnectionValues(Salesforce salesforce, ConnectionValues values) { 97 | SalesforceUserDetails userDetails; 98 | if (StringUtils.isEmpty(gatewayUrl)) 99 | { 100 | userDetails = salesforce.userOperations().getSalesforceUserDetails(); 101 | } 102 | else 103 | { 104 | userDetails = salesforce.userOperations(gatewayUrl).getSalesforceUserDetails(); 105 | } 106 | values.setProviderUserId(userDetails.getId()); 107 | values.setDisplayName(userDetails.getName()); 108 | } 109 | 110 | public UserProfile fetchUserProfile(Salesforce salesforce) { 111 | SalesforceProfile profile; 112 | 113 | if (StringUtils.isEmpty(instanceUrl)) 114 | { 115 | profile = salesforce.chatterOperations().getUserProfile(); 116 | } 117 | else 118 | { 119 | profile = salesforce.chatterOperations(instanceUrl).getUserProfile(); 120 | } 121 | return new UserProfileBuilder().setName(profile.getFirstName()).setFirstName(profile.getFirstName()) 122 | .setLastName(profile.getLastName()).setEmail(profile.getEmail()) 123 | .setUsername(profile.getEmail()).build(); 124 | } 125 | 126 | 127 | public void updateStatus(Salesforce salesforce, String message) { 128 | if (StringUtils.isEmpty(instanceUrl)) 129 | { 130 | salesforce.chatterOperations().updateStatus(message); 131 | } 132 | else 133 | { 134 | salesforce.chatterOperations(instanceUrl).updateStatus(message); 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/connect/SalesforceConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.connect; 17 | 18 | import org.springframework.social.connect.support.OAuth2ConnectionFactory; 19 | import org.springframework.social.salesforce.api.Salesforce; 20 | 21 | /** 22 | * @author Umut Utkan 23 | * @author Jared Ottley 24 | */ 25 | public class SalesforceConnectionFactory extends OAuth2ConnectionFactory { 26 | 27 | public SalesforceConnectionFactory(String clientId, String clientSecret) { 28 | super(SalesforceServiceProvider.ID, new SalesforceServiceProvider(clientId, clientSecret), 29 | new SalesforceAdapter()); 30 | } 31 | 32 | public SalesforceConnectionFactory(String clientId, String clientSecret, boolean sandbox) { 33 | super(SalesforceServiceProvider.ID, new SalesforceServiceProvider(clientId, clientSecret, sandbox), 34 | sandbox ? new SalesforceAdapter(sandbox) : new SalesforceAdapter()); 35 | } 36 | 37 | public SalesforceConnectionFactory(String clientId, String clientSecret, String instanceUrl) { 38 | super(SalesforceServiceProvider.ID, new SalesforceServiceProvider(clientId, clientSecret), 39 | new SalesforceAdapter(instanceUrl)); 40 | } 41 | 42 | public SalesforceConnectionFactory(String clientId, String clientSecret, String instanceUrl, boolean sandbox) { 43 | super(SalesforceServiceProvider.ID, new SalesforceServiceProvider(clientId, clientSecret, sandbox), 44 | sandbox ? new SalesforceAdapter(instanceUrl, sandbox) : new SalesforceAdapter(instanceUrl)); 45 | } 46 | 47 | @Deprecated 48 | public SalesforceConnectionFactory(String clientId, String clientSecret, String authorizeUrl, String tokenUrl) { 49 | super(SalesforceServiceProvider.ID, new SalesforceServiceProvider(clientId, clientSecret, 50 | authorizeUrl, tokenUrl), new SalesforceAdapter()); 51 | } 52 | 53 | @Deprecated 54 | public SalesforceConnectionFactory(String clientId, String clientSecret, String authorizeUrl, String tokenUrl, String instanceUrl) { 55 | super(SalesforceServiceProvider.ID, new SalesforceServiceProvider(clientId, clientSecret, 56 | authorizeUrl, tokenUrl), new SalesforceAdapter(instanceUrl)); 57 | } 58 | 59 | @Deprecated 60 | public SalesforceConnectionFactory(String clientId, String clientSecret, String authorizeUrl, String tokenUrl, String instanceUrl, String gatewayUrl) { 61 | super("salesforce", new SalesforceServiceProvider(clientId, clientSecret, 62 | authorizeUrl, tokenUrl), new SalesforceAdapter(instanceUrl, gatewayUrl)); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/connect/SalesforceOAuth2Template.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.connect; 17 | 18 | import org.springframework.social.oauth2.AccessGrant; 19 | import org.springframework.social.oauth2.OAuth2Template; 20 | import org.springframework.util.MultiValueMap; 21 | 22 | import com.fasterxml.jackson.databind.JsonNode; 23 | import com.fasterxml.jackson.databind.ObjectMapper; 24 | 25 | import java.util.Map; 26 | 27 | /** 28 | * Salesforce OAuth2Template implementation. 29 | * 30 | * The reason to extend is to extract non-standard instance_url from Salesforce's oauth token response. 31 | * 32 | * @author Umut Utkan 33 | * @author Jared Ottley 34 | */ 35 | public class SalesforceOAuth2Template extends OAuth2Template { 36 | 37 | private String instanceUrl = null; 38 | 39 | 40 | public SalesforceOAuth2Template(String clientId, String clientSecret, String authorizeUrl, String accessTokenUrl) { 41 | this(clientId, clientSecret, authorizeUrl, null, accessTokenUrl); 42 | } 43 | 44 | public SalesforceOAuth2Template(String clientId, String clientSecret, String authorizeUrl, String authenticateUrl, String accessTokenUrl) { 45 | super(clientId, clientSecret, authorizeUrl, authenticateUrl, accessTokenUrl); 46 | setUseParametersForClientAuthentication(true); 47 | } 48 | 49 | 50 | @Override 51 | protected AccessGrant createAccessGrant(String accessToken, String scope, String refreshToken, Long expiresIn, Map response) { 52 | this.instanceUrl = (String) response.get("instance_url"); 53 | 54 | return super.createAccessGrant(accessToken, scope, refreshToken, expiresIn, response); 55 | } 56 | 57 | public String getInstanceUrl() { 58 | return instanceUrl; 59 | } 60 | 61 | 62 | /** 63 | * The default method from OAuth2Template is unable to handle the repsonse from Salesforce for an AccessGrant. The Response is returned with a 64 | * content type of application/octet-stream. Spring-social-core's OAuth2Template does not have a HttpMessageConverter registered that is able to 65 | * covert the response to a map even though it is Json but with a non-Json content type. 66 | */ 67 | @Override 68 | protected AccessGrant postForAccessGrant(String accessTokenUrl, MultiValueMap parameters) { 69 | JsonNode response = getRestTemplate().postForObject(accessTokenUrl, parameters, JsonNode.class); 70 | 71 | ObjectMapper mapper = new ObjectMapper(); 72 | @SuppressWarnings("unchecked") 73 | Map result = mapper.convertValue(response, Map.class); 74 | 75 | return this.createAccessGrant((String) result.get("access_token"), (String) result.get("scope"), (String) result.get("refresh_token"), getIntegerValue(result, "expires_in"), result); 76 | } 77 | 78 | 79 | // Retrieves object from map into an Integer, regardless of the object's actual type. Allows for flexibility in object type (eg, "3600" vs 3600). 80 | // Private Method from OAuth2Template 81 | private Long getIntegerValue(Map map, String key) { 82 | try { 83 | return Long.valueOf(String.valueOf(map.get(key))); // normalize to String before creating integer value; 84 | } catch (NumberFormatException e) { 85 | return null; 86 | } 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/connect/SalesforceServiceProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.connect; 17 | 18 | import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider; 19 | import org.springframework.social.salesforce.api.Salesforce; 20 | import org.springframework.social.salesforce.api.impl.SalesforceTemplate; 21 | 22 | /** 23 | * Salesforce ServiceProvider implementation. 24 | * 25 | * @author Umut Utkan 26 | * @author Jared Ottley 27 | */ 28 | public class SalesforceServiceProvider extends AbstractOAuth2ServiceProvider { 29 | 30 | //Provider ID 31 | public final static String ID = "salesforce"; 32 | 33 | public final static String PRODUCTION_GATEWAY_URL = "https://login.salesforce.com"; 34 | public final static String SANDBOX_GATEWAY_URL = "https://test.salesforce.com"; 35 | 36 | public final static String TOKEN_PATH = "/services/oauth2/token"; 37 | public final static String AUTHORIZE_PATH = "/services/oauth2/authorize"; 38 | 39 | public SalesforceServiceProvider(String clientId, String clientSecret) { 40 | this(clientId, clientSecret, 41 | PRODUCTION_GATEWAY_URL + AUTHORIZE_PATH, 42 | PRODUCTION_GATEWAY_URL + TOKEN_PATH); 43 | } 44 | 45 | public SalesforceServiceProvider(String clientId, String clientSecret, boolean sandbox) 46 | { 47 | super(new SalesforceOAuth2Template(clientId, clientSecret, (sandbox ? SANDBOX_GATEWAY_URL : PRODUCTION_GATEWAY_URL) + AUTHORIZE_PATH, (sandbox ? SANDBOX_GATEWAY_URL : PRODUCTION_GATEWAY_URL) + TOKEN_PATH)); 48 | } 49 | 50 | public SalesforceServiceProvider(String clientId, String clientSecret, String authorizeUrl, String tokenUrl) { 51 | super(new SalesforceOAuth2Template(clientId, clientSecret, authorizeUrl, tokenUrl)); 52 | } 53 | 54 | 55 | public Salesforce getApi(String accessToken) { 56 | SalesforceTemplate template = new SalesforceTemplate(accessToken); 57 | 58 | // gets the returned instance url and sets to Salesforce template as base url. 59 | String instanceUrl = ((SalesforceOAuth2Template) getOAuthOperations()).getInstanceUrl(); 60 | if (instanceUrl != null) { 61 | template.setInstanceUrl(instanceUrl); 62 | } 63 | 64 | return template; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/social/salesforce/security/SalesforceAuthenticationService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.security; 17 | 18 | import org.springframework.social.salesforce.api.Salesforce; 19 | import org.springframework.social.salesforce.connect.SalesforceConnectionFactory; 20 | import org.springframework.social.security.provider.OAuth2AuthenticationService; 21 | 22 | /** 23 | * 24 | * @author Jared Ottley 25 | * 26 | */ 27 | public class SalesforceAuthenticationService extends OAuth2AuthenticationService 28 | { 29 | public SalesforceAuthenticationService(String consumerKey, String consumerSecret) 30 | { 31 | super(new SalesforceConnectionFactory(consumerKey, consumerSecret)); 32 | } 33 | 34 | public SalesforceAuthenticationService(String consumerKey, String consumerSecret, boolean sandbox) 35 | { 36 | super(new SalesforceConnectionFactory(consumerKey, consumerSecret, sandbox)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/spring.handlers: -------------------------------------------------------------------------------- 1 | http\://www.springframework.org/schema/social/salesforce=org.springframework.social.salesforce.config.xml.SalesforceNamespaceHandler -------------------------------------------------------------------------------- /src/main/resources/META-INF/spring.schemas: -------------------------------------------------------------------------------- 1 | http\://www.springframework.org/schema/social/spring-social-salesforce.xsd=org/springframework/social/salesforce/config/xml/spring-social-salesforce-1.0.xsd 2 | http\://www.springframework.org/schema/social/spring-social-salesforce-1.0.xsd=org/springframework/social/salesforce/config/xml/spring-social-salesforce-1.0.xsd 3 | -------------------------------------------------------------------------------- /src/main/resources/org/springframework/social/salesforce/config/xml/spring-social-salesforce-1.0.xsd: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/social/salesforce/api/client/BaseSalesforceFactoryTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.client; 17 | 18 | import org.junit.Test; 19 | import org.springframework.core.io.ClassPathResource; 20 | import org.springframework.core.io.Resource; 21 | import org.springframework.http.HttpHeaders; 22 | import org.springframework.http.HttpStatus; 23 | import org.springframework.http.MediaType; 24 | import org.springframework.social.salesforce.api.Salesforce; 25 | import org.springframework.social.salesforce.client.BaseSalesforceFactory; 26 | import org.springframework.test.web.client.MockRestServiceServer; 27 | import org.springframework.web.client.RestTemplate; 28 | 29 | import static org.junit.Assert.assertNotNull; 30 | import static org.springframework.http.HttpMethod.POST; 31 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.content; 32 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; 33 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; 34 | import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; 35 | 36 | /** 37 | * @author Umut Utkan 38 | * @author Jared Ottley 39 | */ 40 | public class BaseSalesforceFactoryTest { 41 | 42 | @Test 43 | public void testClientLogin() { 44 | RestTemplate restTemplate = new RestTemplate(); 45 | MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate); 46 | HttpHeaders responseHeaders = new HttpHeaders(); 47 | responseHeaders.setContentType(MediaType.APPLICATION_JSON); 48 | 49 | mockServer.expect(requestTo("https://login.salesforce.com/services/oauth2/token")) 50 | .andExpect(method(POST)) 51 | .andExpect(content().string("grant_type=password&client_id=client-id&client_secret=client-secret&username=my-username&password=my-passwordsecurity-token")) 52 | .andRespond(withStatus(HttpStatus.OK).body(loadResource("client-token.json")).headers(responseHeaders)); 53 | 54 | Salesforce template = new BaseSalesforceFactory("client-id", "client-secret", restTemplate) 55 | .create("my-username", "my-password", "security-token"); 56 | assertNotNull(template); 57 | } 58 | 59 | protected Resource loadResource(String name) { 60 | return new ClassPathResource("/" + name, getClass()); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/social/salesforce/api/impl/AbstractSalesforceTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import org.junit.Before; 19 | import org.springframework.core.io.ClassPathResource; 20 | import org.springframework.core.io.Resource; 21 | import org.springframework.http.HttpHeaders; 22 | import org.springframework.http.MediaType; 23 | import org.springframework.test.web.client.MockRestServiceServer; 24 | 25 | 26 | /** 27 | * @author Umut Utkan 28 | * @author Jared Ottley 29 | */ 30 | abstract public class AbstractSalesforceTest { 31 | 32 | protected SalesforceTemplate salesforce; 33 | 34 | protected SalesforceTemplate unauthorizedSalesforce; 35 | 36 | protected org.springframework.test.web.client.MockRestServiceServer mockServer; 37 | 38 | protected HttpHeaders responseHeaders; 39 | 40 | 41 | @Before 42 | public void setup() { 43 | salesforce = new SalesforceTemplate("ACCESS_TOKEN"); 44 | salesforce.setInstanceUrl("https://na7.salesforce.com"); 45 | mockServer = MockRestServiceServer.createServer(salesforce.getRestTemplate()); 46 | responseHeaders = new HttpHeaders(); 47 | responseHeaders.setContentType(MediaType.APPLICATION_JSON); 48 | responseHeaders.add("Sforce-Limit-Info", "api-usage=39/15000"); 49 | unauthorizedSalesforce = new SalesforceTemplate(); 50 | // create a mock server just to avoid hitting real twitter if something gets past the authorization check 51 | MockRestServiceServer.createServer(unauthorizedSalesforce.getRestTemplate()); 52 | } 53 | 54 | protected Resource loadResource(String name) { 55 | return new ClassPathResource("/" + name, getClass()); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/social/salesforce/api/impl/ChatterTemplateTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | import static org.junit.Assert.assertNotNull; 20 | import static org.springframework.http.HttpMethod.GET; 21 | import static org.springframework.http.HttpMethod.POST; 22 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.content; 23 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; 24 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; 25 | import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; 26 | 27 | import org.junit.Test; 28 | import org.springframework.http.HttpStatus; 29 | import org.springframework.social.salesforce.api.SalesforceProfile; 30 | import org.springframework.social.salesforce.api.Status; 31 | 32 | 33 | /** 34 | * @author Umut Utkan 35 | * @author Jared Ottley 36 | * @author Alexandru Leahu 37 | */ 38 | public class ChatterTemplateTest extends AbstractSalesforceTest { 39 | 40 | @Test 41 | public void getProfile() { 42 | mockServer.expect(requestTo("https://na7.salesforce.com/services/data/" + salesforce.apiOperations().getVersion() + "/chatter/users/me")) 43 | .andExpect(method(GET)) 44 | .andRespond(withStatus(HttpStatus.OK).body(loadResource("profile.json")).headers(responseHeaders)); 45 | SalesforceProfile profile = salesforce.chatterOperations().getUserProfile(); 46 | assertEquals("Umut Utkan", profile.getName()); 47 | assertEquals("umut.utkan@foo.com", profile.getEmail()); 48 | assertEquals("005A0000001cRuvIAE", profile.getId()); 49 | assertEquals("005A0000001cRuvIAE", profile.getUsername()); 50 | assertEquals("Umut Utkan", profile.getName()); 51 | assertEquals("https://c.na7.content.force.com/profilephoto/005/F", profile.getPhoto().getLargePhotoUrl()); 52 | assertEquals("https://c.na7.content.force.com/profilephoto/005/T", profile.getPhoto().getSmallPhotoUrl()); 53 | } 54 | 55 | @Test 56 | public void getStatus() { 57 | mockServer.expect(requestTo("https://na7.salesforce.com/services/data/" + salesforce.apiOperations().getVersion() + "/chatter/users/me/status")) 58 | .andExpect(method(GET)) 59 | .andRespond(withStatus(HttpStatus.OK).body(loadResource("chatter-status.json")).headers(responseHeaders)); 60 | 61 | Status status = salesforce.chatterOperations().getStatus(); 62 | assertNotNull(status); 63 | assertEquals("I am also working on #hede", status.getText()); 64 | } 65 | 66 | @Test 67 | public void updateStatus() { 68 | mockServer.expect(requestTo("https://na7.salesforce.com/services/data/" + salesforce.apiOperations().getVersion() + "/chatter/users/me/status")) 69 | .andExpect(method(POST)) 70 | .andExpect(content().string("text=Updating+status+via+%23spring-social-salesforce%21")) 71 | 72 | .andRespond(withStatus(HttpStatus.OK).body(loadResource("chatter-status.json")).headers(responseHeaders)); 73 | 74 | Status status = salesforce.chatterOperations().updateStatus("Updating status via #spring-social-salesforce!"); 75 | assertNotNull(status); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/social/salesforce/api/impl/ConnectOperationsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.social.salesforce.api.impl; 18 | 19 | import org.junit.Test; 20 | import org.springframework.http.HttpStatus; 21 | import org.springframework.social.salesforce.api.Community; 22 | import org.springframework.social.salesforce.api.CommunityUser; 23 | 24 | import java.util.List; 25 | 26 | import static org.junit.Assert.assertEquals; 27 | import static org.springframework.http.HttpMethod.GET; 28 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; 29 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; 30 | import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; 31 | 32 | public class ConnectOperationsTest extends AbstractSalesforceTest { 33 | 34 | @Test 35 | public void getCommunitiesList() { 36 | mockServer.expect(requestTo("https://na7.salesforce.com/services/data/" + salesforce.apiOperations().getVersion() + "/connect/communities/")) 37 | .andExpect(method(GET)) 38 | .andRespond(withStatus(HttpStatus.OK).body(loadResource("communities.json")).headers(responseHeaders)); 39 | 40 | List community = salesforce.connectOperations().getCommunities(); 41 | 42 | assertEquals("leia-community1", community.get(0).getName()); 43 | assertEquals("leia-community2", community.get(1).getName()); 44 | assertEquals("leia-community3", community.get(2).getName()); 45 | 46 | assertEquals("commId1", community.get(0).getId()); 47 | assertEquals("commId2", community.get(1).getId()); 48 | assertEquals("commId3", community.get(2).getId()); 49 | } 50 | 51 | @Test 52 | public void getCommunityUsersList() { 53 | mockServer.expect(requestTo("https://na7.salesforce.com/services/data/" + salesforce.apiOperations().getVersion() + "/connect/communities/commId1/chatter/users")) 54 | .andExpect(method(GET)) 55 | .andRespond(withStatus(HttpStatus.OK).body(loadResource("community-users.json")).headers(responseHeaders)); 56 | 57 | List communityUsers = salesforce.connectOperations().getCommunityUsers("commId1"); 58 | 59 | assertEquals("commUserId1", communityUsers.get(0).getId()); 60 | assertEquals("UserABCDEF", communityUsers.get(0).getCommunityNickname()); 61 | assertEquals("mock-user@test.com", communityUsers.get(0).getUsername()); 62 | assertEquals("MockUser1", communityUsers.get(0).getDisplayName()); 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/social/salesforce/api/impl/LimitsTemplateTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import org.junit.Test; 19 | import org.springframework.http.HttpStatus; 20 | import org.springframework.social.salesforce.api.LimitsResults; 21 | 22 | import static org.junit.Assert.assertEquals; 23 | import static org.springframework.http.HttpMethod.GET; 24 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; 25 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; 26 | import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; 27 | 28 | /** 29 | * @author Jared Ottley 30 | */ 31 | public class LimitsTemplateTest extends AbstractSalesforceTest { 32 | 33 | @Test 34 | public void getLimits() { 35 | mockServer.expect(requestTo("https://na7.salesforce.com/services/data/" + salesforce.apiOperations().getVersion() + "/limits")) 36 | .andExpect(method(GET)) 37 | .andRespond(withStatus(HttpStatus.OK).body(loadResource("limits.json")).headers(responseHeaders)); 38 | LimitsResults results = salesforce.limitsOperations().getLimits(); 39 | 40 | assertEquals(9, results.getDailyApiRequests().getAdditionalProperties().size()); 41 | assertEquals(500, results.getHourlySyncReportRuns().getMax()); 42 | assertEquals(500, results.getHourlySyncReportRuns().getRemaining()); 43 | } 44 | 45 | @Test 46 | public void SforceLimitInfoCheck() { 47 | mockServer.expect(requestTo("https://na7.salesforce.com/services/data/" + salesforce.apiOperations().getVersion() + "/limits")) 48 | .andExpect(method(GET)) 49 | .andRespond(withStatus(HttpStatus.OK).body(loadResource("limits.json")).headers(responseHeaders)); 50 | salesforce.limitsOperations().getLimits(); 51 | 52 | assertEquals(39, salesforce.limitsOperations().getDailyApiUsed()); 53 | assertEquals(15000, salesforce.limitsOperations().getDailyApiLimit()); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/social/salesforce/api/impl/MetaApiTemplateTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.social.salesforce.api.impl; 18 | 19 | import org.junit.Test; 20 | import org.springframework.http.HttpStatus; 21 | import org.springframework.social.salesforce.api.ApiVersion; 22 | import org.springframework.social.salesforce.api.InvalidSalesforceApiVersionException; 23 | 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | import static org.junit.Assert.assertEquals; 28 | import static org.junit.Assert.fail; 29 | import static org.springframework.http.HttpMethod.GET; 30 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; 31 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; 32 | import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; 33 | 34 | /** 35 | * @author Umut Utkan 36 | * @author Jared Ottley 37 | */ 38 | public class MetaApiTemplateTest extends AbstractSalesforceTest 39 | { 40 | 41 | @Test 42 | public void getApiVersions() 43 | { 44 | mockServer.expect(requestTo("https://na7.salesforce.com/services/data")) 45 | .andExpect(method(GET)) 46 | .andRespond(withStatus(HttpStatus.OK).body(loadResource("versions.json")).headers(responseHeaders)); 47 | List versions = salesforce.apiOperations().getVersions(); 48 | assertEquals(4, versions.size()); 49 | assertEquals("Winter '12", versions.get(3).getLabel()); 50 | assertEquals("23.0", versions.get(3).getVersion()); 51 | assertEquals("/services/data/v23.0", versions.get(3).getUrl()); 52 | } 53 | 54 | @Test 55 | public void getServices() 56 | { 57 | mockServer.expect(requestTo("https://na7.salesforce.com/services/data/v23.0")) 58 | .andExpect(method(GET)) 59 | .andRespond(withStatus(HttpStatus.OK).body(loadResource("services.json")).headers(responseHeaders)); 60 | Map services = salesforce.apiOperations().getServices("v23.0"); 61 | assertEquals(6, services.size()); 62 | assertEquals("/services/data/v37.0/sobjects", services.get("sobjects")); 63 | assertEquals("/services/data/v37.0/chatter", services.get("chatter")); 64 | } 65 | 66 | @Test 67 | public void getServices2() 68 | { 69 | mockServer.expect(requestTo("https://na7.salesforce.com/services/data/v37.0")) 70 | .andExpect(method(GET)) 71 | .andRespond(withStatus(HttpStatus.OK).body(loadResource("services2.json")).headers(responseHeaders)); 72 | Map services = salesforce.apiOperations().getServices(); 73 | assertEquals(6, services.size()); 74 | assertEquals("/services/data/v37.0/sobjects", services.get("sobjects")); 75 | assertEquals("/services/data/v37.0/chatter", services.get("chatter")); 76 | } 77 | 78 | @Test 79 | public void getVersion() 80 | { 81 | String version = salesforce.apiOperations().getVersion(); 82 | assertEquals("v37.0", version); 83 | } 84 | 85 | @Test 86 | public void setVersion() 87 | { 88 | try 89 | { 90 | salesforce.apiOperations().setVersion("v38.0"); 91 | String version = salesforce.apiOperations().getVersion(); 92 | assertEquals("v38.0", version); 93 | } 94 | catch (InvalidSalesforceApiVersionException e) 95 | { 96 | fail("InvalidSalesforceApiVersionException thrown"); 97 | } 98 | } 99 | 100 | @Test 101 | public void setVersion2() 102 | { 103 | try 104 | { 105 | salesforce.apiOperations().setVersion("38.0"); 106 | fail("InvalidSalesforceApiVersionException not thrown"); 107 | } 108 | catch (InvalidSalesforceApiVersionException e) 109 | { 110 | assertEquals("38.0 is not a valid Salesforce Api version.", e.getMessage()); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/social/salesforce/api/impl/RecentTemplateTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import org.junit.Test; 19 | import org.springframework.http.HttpStatus; 20 | import org.springframework.social.salesforce.api.ResultItem; 21 | 22 | import java.util.List; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.springframework.http.HttpMethod.GET; 26 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; 27 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; 28 | import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; 29 | 30 | 31 | /** 32 | * @author Umut Utkan 33 | * @author Jared Ottley 34 | */ 35 | public class RecentTemplateTest extends AbstractSalesforceTest { 36 | 37 | @Test 38 | public void search() { 39 | mockServer.expect(requestTo("https://na7.salesforce.com/services/data/" + salesforce.apiOperations().getVersion() + "/recent")) 40 | .andExpect(method(GET)) 41 | .andRespond(withStatus(HttpStatus.OK).body(loadResource("recent.json")).headers(responseHeaders)); 42 | List items = salesforce.recentOperations().recent(); 43 | assertEquals(9, items.size()); 44 | assertEquals("User", items.get(0).getType()); 45 | assertEquals("/services/data/" + salesforce.apiOperations().getVersion() + "/sobjects/User/005A0000001cRuvIAE", items.get(0).getUrl()); 46 | assertEquals("005A0000001cRuvIAE", items.get(0).getAttributes().get("Id")); 47 | assertEquals("Umut Utkan", items.get(0).getAttributes().get("Name")); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/social/salesforce/api/impl/SearchTemplateTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import org.junit.Test; 19 | import org.springframework.http.HttpStatus; 20 | import org.springframework.social.salesforce.api.ResultItem; 21 | 22 | import java.util.List; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.springframework.http.HttpMethod.GET; 26 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; 27 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; 28 | import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; 29 | 30 | 31 | /** 32 | * @author Umut Utkan 33 | * @author Jared Ottley 34 | */ 35 | public class SearchTemplateTest extends AbstractSalesforceTest { 36 | 37 | @Test 38 | public void search() { 39 | mockServer.expect(requestTo("https://na7.salesforce.com/services/data/" + salesforce.apiOperations().getVersion() + "/search?q=FIND+%7Bxxx*%7D+IN+ALL+FIELDS+RETURNING+Contact%2C+Account")) 40 | .andExpect(method(GET)) 41 | .andRespond(withStatus(HttpStatus.OK).body(loadResource("search.json")).headers(responseHeaders)); 42 | List results = salesforce.searchOperations().search("FIND {xxx*} IN ALL FIELDS RETURNING Contact, Account"); 43 | assertEquals(4, results.size()); 44 | assertEquals("Contact", results.get(0).getType()); 45 | assertEquals("Contact", results.get(1).getType()); 46 | assertEquals("Account", results.get(2).getType()); 47 | assertEquals("Account", results.get(3).getType()); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/social/salesforce/api/impl/UserOperationsTemplateTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 https://github.com/jottley/spring-social-salesforce 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.social.salesforce.api.impl; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | import static org.springframework.http.HttpMethod.GET; 20 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; 21 | import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; 22 | import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; 23 | 24 | import org.junit.Test; 25 | import org.springframework.http.HttpStatus; 26 | import org.springframework.social.salesforce.api.SalesforceUserDetails; 27 | 28 | /** 29 | * @author Alexandra Leahu 30 | * @author Jared Ottley 31 | */ 32 | public class UserOperationsTemplateTest extends AbstractSalesforceTest { 33 | 34 | @Test 35 | public void getUserDetails() { 36 | mockServer.expect(requestTo("https://login.salesforce.com/services/oauth2/userinfo")) 37 | .andExpect(method(GET)) 38 | .andRespond(withStatus(HttpStatus.OK).body(loadResource("userDetails.json")).headers(responseHeaders)); 39 | SalesforceUserDetails userDetails = salesforce.userOperations().getSalesforceUserDetails(); 40 | assertEquals("John Doe", userDetails.getName()); 41 | assertEquals("john@doe.com", userDetails.getEmail()); 42 | assertEquals("12345", userDetails.getId()); 43 | assertEquals("johnny", userDetails.getPreferredUsername()); 44 | assertEquals("John", userDetails.getFirstName()); 45 | assertEquals("Doe", userDetails.getLastName()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/resources/account.json: -------------------------------------------------------------------------------- 1 | { 2 | "objectDescribe":{ 3 | "name":"Account", 4 | "label":"Account", 5 | "updateable":true, 6 | "keyPrefix":"001", 7 | "custom":false, 8 | "urls":{ 9 | "sobject":"/services/data/v37.0/sobjects/Account", 10 | "describe":"/services/data/v37.0/sobjects/Account/describe", 11 | "rowTemplate":"/services/data/v37.0/sobjects/Account/{ID}" 12 | }, 13 | "searchable":true, 14 | "labelPlural":"Accounts", 15 | "layoutable":true, 16 | "activateable":false, 17 | "createable":true, 18 | "deprecatedAndHidden":false, 19 | "customSetting":false, 20 | "deletable":true, 21 | "feedEnabled":true, 22 | "mergeable":true, 23 | "queryable":true, 24 | "replicateable":true, 25 | "retrieveable":true, 26 | "undeletable":true, 27 | "triggerable":true 28 | }, 29 | "recentItems":[] 30 | } -------------------------------------------------------------------------------- /src/test/resources/account2.json: -------------------------------------------------------------------------------- 1 | { 2 | "objectDescribe":{ 3 | "name":"Account", 4 | "label":"Account", 5 | "updateable":true, 6 | "keyPrefix":"001", 7 | "custom":false, 8 | "urls":{ 9 | "sobject":"/services/data/v38.0/sobjects/Account", 10 | "describe":"/services/data/v38.0/sobjects/Account/describe", 11 | "rowTemplate":"/services/data/v38.0/sobjects/Account/{ID}" 12 | }, 13 | "searchable":true, 14 | "labelPlural":"Accounts", 15 | "layoutable":true, 16 | "activateable":false, 17 | "createable":true, 18 | "deprecatedAndHidden":false, 19 | "customSetting":false, 20 | "deletable":true, 21 | "feedEnabled":true, 22 | "mergeable":true, 23 | "queryable":true, 24 | "replicateable":true, 25 | "retrieveable":true, 26 | "undeletable":true, 27 | "triggerable":true 28 | }, 29 | "recentItems":[] 30 | } -------------------------------------------------------------------------------- /src/test/resources/chatter-status.json: -------------------------------------------------------------------------------- 1 | { 2 | "url":"/services/data/v37.0/chatter/users/005A0000001cRuvIAE/status", 3 | "body":{ 4 | "text":"I am also working on #hede", 5 | "messageSegments":[ 6 | { 7 | "type":"Text", 8 | "text":"I am also working on " 9 | }, 10 | { 11 | "url":"/services/data/v37.0/chatter/feed-items?q=%23hede", 12 | "tag":"hede", 13 | "type":"Hashtag", 14 | "text":"#hede" 15 | } 16 | ] 17 | }, 18 | "parentId":"005A0000001cRuvIAE" 19 | } -------------------------------------------------------------------------------- /src/test/resources/client-token.json: -------------------------------------------------------------------------------- 1 | { 2 | "id":"https://login.salesforce.com/id/00Dx0000000BV7z/005x00000012Q9P", 3 | "issued_at":"1278448832702", 4 | "instance_url":"https://na1.salesforce.com", 5 | "signature":"0CmxinKir53Yed7nE0TD+zMpvIWYGb/bdJj5XfOH6EQ=", 6 | "access_token":"00Dx0000000BV7z!AR8AQAxo9UfVkh8AlV0Gomt9Czx9LjHnSSpwBMmbRcgKFmxOtvxjTrKW19ye6PE3Ds1eQz3z8jr3W7_VbWmEu4Q8TVGSTHxs" 7 | } -------------------------------------------------------------------------------- /src/test/resources/communities.json: -------------------------------------------------------------------------------- 1 | { 2 | "communities" : [ { 3 | "allowChatterAccessWithoutLogin" : false, 4 | "allowMembersToFlag" : false, 5 | "description" : null, 6 | "guestMemberVisibilityEnabled" : false, 7 | "id" : "commId1", 8 | "invitationsEnabled" : false, 9 | "knowledgeableEnabled" : false, 10 | "loginUrl" : "https://na7.salesforce.com/leiacommunity/s/login", 11 | "memberVisibilityEnabled" : false, 12 | "name" : "leia-community1", 13 | "nicknameDisplayEnabled" : true, 14 | "privateMessagesEnabled" : false, 15 | "reputationEnabled" : false, 16 | "sendWelcomeEmail" : true, 17 | "siteAsContainerEnabled" : true, 18 | "siteUrl" : "https://na7.salesforce.com/leiacommunity", 19 | "status" : "Live", 20 | "templateName" : "Customer Account Portal", 21 | "url" : "/services/data/v37.0/connect/communities/commId1", 22 | "urlPathPrefix" : "leiacommunity" 23 | }, { 24 | "allowChatterAccessWithoutLogin" : false, 25 | "allowMembersToFlag" : false, 26 | "description" : null, 27 | "guestMemberVisibilityEnabled" : false, 28 | "id" : "commId2", 29 | "invitationsEnabled" : false, 30 | "knowledgeableEnabled" : false, 31 | "loginUrl" : "https://na7.salesforce.com/leiacommunity2/s/login", 32 | "memberVisibilityEnabled" : false, 33 | "name" : "leia-community2", 34 | "nicknameDisplayEnabled" : true, 35 | "privateMessagesEnabled" : false, 36 | "reputationEnabled" : false, 37 | "sendWelcomeEmail" : true, 38 | "siteAsContainerEnabled" : true, 39 | "siteUrl" : "https://na7.salesforce.com/leiacommunity2", 40 | "status" : "Live", 41 | "templateName" : "Customer Account Portal", 42 | "url" : "/services/data/v37.0/connect/communities/commId2", 43 | "urlPathPrefix" : "leiacommunity2" 44 | }, { 45 | "allowChatterAccessWithoutLogin" : false, 46 | "allowMembersToFlag" : false, 47 | "description" : null, 48 | "guestMemberVisibilityEnabled" : false, 49 | "id" : "commId3", 50 | "invitationsEnabled" : false, 51 | "knowledgeableEnabled" : false, 52 | "loginUrl" : "https://na7.salesforce.com/leiacommunity3/login", 53 | "memberVisibilityEnabled" : false, 54 | "name" : "leia-community3", 55 | "nicknameDisplayEnabled" : true, 56 | "privateMessagesEnabled" : false, 57 | "reputationEnabled" : false, 58 | "sendWelcomeEmail" : true, 59 | "siteAsContainerEnabled" : true, 60 | "siteUrl" : "https://na7.salesforce.com/leiacommunity3", 61 | "status" : "Live", 62 | "templateName" : "Customer Account Portal", 63 | "url" : "/services/data/v37.0/connect/communities/commId3", 64 | "urlPathPrefix" : "leiacommunity3" 65 | } ], 66 | "total" : 3 67 | } -------------------------------------------------------------------------------- /src/test/resources/community-users.json: -------------------------------------------------------------------------------- 1 | { 2 | "currentPageToken" : 0, 3 | "currentPageUrl" : "/services/data/v37.0/connect/communities/commId1/chatter/users", 4 | "nextPageToken" : null, 5 | "nextPageUrl" : null, 6 | "previousPageToken" : null, 7 | "previousPageUrl" : null, 8 | "users" : [ { 9 | "aboutMe" : null, 10 | "additionalLabel" : null, 11 | "address" : { 12 | "city" : null, 13 | "country" : "EU", 14 | "formattedAddress" : "EU", 15 | "state" : null, 16 | "street" : null, 17 | "zip" : null 18 | }, 19 | "bannerPhoto" : { 20 | "bannerPhotoUrl" : "https://na7.salesforce.com/profilephoto/003/C", 21 | "bannerPhotoVersionId" : null, 22 | "url" : "/services/data/v37.0/connect/communities/commId1/user-profiles/commUserId1/banner-photo" 23 | }, 24 | "chatterActivity" : { 25 | "commentCount" : 0, 26 | "commentReceivedCount" : 0, 27 | "likeReceivedCount" : 0, 28 | "postCount" : 0 29 | }, 30 | "chatterInfluence" : { 31 | "percentile" : "0.0", 32 | "rank" : 1 33 | }, 34 | "communityNickname" : "UserABCDEF", 35 | "companyName" : "Company Name", 36 | "displayName" : "MockUser1", 37 | "email" : "mock-user@test.com", 38 | "firstName" : null, 39 | "followersCount" : 0, 40 | "followingCounts" : { 41 | "people" : 0, 42 | "records" : 0, 43 | "total" : 0 44 | }, 45 | "groupCount" : 0, 46 | "hasChatter" : true, 47 | "id" : "commUserId1", 48 | "isActive" : true, 49 | "isInThisCommunity" : true, 50 | "lastName" : null, 51 | "managerId" : null, 52 | "managerName" : null, 53 | "motif" : { 54 | "color" : "65CAE4", 55 | "largeIconUrl" : "/img/icon/profile64.png", 56 | "mediumIconUrl" : "/img/icon/profile32.png", 57 | "smallIconUrl" : "/img/icon/profile16.png", 58 | "svgIconUrl" : null 59 | }, 60 | "mySubscription" : null, 61 | "name" : "UserABCDEF", 62 | "outOfOffice" : { 63 | "message" : "" 64 | }, 65 | "phoneNumbers" : [ ], 66 | "photo" : { 67 | "fullEmailPhotoUrl" : "https://na7.salesforce.com/img/userprofile/default_profile_200_v2.png?fromEmail=1", 68 | "largePhotoUrl" : "https://na7.salesforce.com/profilephoto/005/F", 69 | "mediumPhotoUrl" : "https://na7.salesforce.com/profilephoto/005/M", 70 | "photoVersionId" : null, 71 | "smallPhotoUrl" : "https://na7.salesforce.com/profilephoto/005/T", 72 | "standardEmailPhotoUrl" : "https://na7.salesforce.com/img/userprofile/default_profile_31_v1.png?fromEmail=1", 73 | "url" : "/services/data/v37.0/connect/communities/commId1/user-profiles/commUserId1/photo" 74 | }, 75 | "reputation" : null, 76 | "thanksReceived" : null, 77 | "title" : null, 78 | "type" : "User", 79 | "url" : "/services/data/v37.0/connect/communities/commId1/chatter/users/commUserId1", 80 | "userType" : "Internal", 81 | "username" : "mock-user@test.com" 82 | }] 83 | } -------------------------------------------------------------------------------- /src/test/resources/customApi1.json: -------------------------------------------------------------------------------- 1 | { 2 | "allowChatterAccessWithoutLogin" : false, 3 | "allowMembersToFlag" : false, 4 | "description" : null, 5 | "guestMemberVisibilityEnabled" : false, 6 | "id" : "commId3", 7 | "invitationsEnabled" : false 8 | } -------------------------------------------------------------------------------- /src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/test/resources/profile.json: -------------------------------------------------------------------------------- 1 | { 2 | "address":{ 3 | "state":"Istanbul", 4 | "country":"TR", 5 | "street":null, 6 | "city":null, 7 | "zip":"34457" 8 | }, 9 | "email":"umut.utkan@foo.com", 10 | "currentStatus":{ 11 | "url":"/services/data/v37.0/chatter/users/005A0000001cRuvIAE/status", 12 | "body":{ 13 | "text":"", 14 | "messageSegments":[] 15 | }, 16 | "parentId":"005A0000001cRuvIAE" 17 | }, 18 | "managerId":null, 19 | "followingCounts":{ 20 | "total":0, 21 | "records":0, 22 | "people":0 23 | }, 24 | "isActive":true, 25 | "phoneNumbers":[], 26 | "groupCount":1, 27 | "followersCount":0, 28 | "managerName":null, 29 | "aboutMe":null, 30 | "chatterActivity":{ 31 | "commentCount":0, 32 | "commentReceivedCount":0, 33 | "likeReceivedCount":0, 34 | "postCount":0 35 | },"name":"Umut Utkan", 36 | "title":null, 37 | "firstName":"Umut", 38 | "lastName":"Utkan", 39 | "companyName":"Foo Org", 40 | "mySubscription":null, 41 | "photo":{ 42 | "smallPhotoUrl":"https://c.na7.content.force.com/profilephoto/005/T", 43 | "largePhotoUrl":"https://c.na7.content.force.com/profilephoto/005/F" 44 | }, 45 | "isChatterGuest":false, 46 | "id":"005A0000001cRuvIAE", 47 | "type":"User", 48 | "url":"/services/data/v37.0/chatter/users/005A0000001cRuvIAE" 49 | } -------------------------------------------------------------------------------- /src/test/resources/query-count.json: -------------------------------------------------------------------------------- 1 | { 2 | "query":"SELECT COUNT() FROM Contact", 3 | "totalSize":22, 4 | "done":true, 5 | "records":[] 6 | } -------------------------------------------------------------------------------- /src/test/resources/query-groupby.json: -------------------------------------------------------------------------------- 1 | { 2 | "debug":"SELECT LeadSource, COUNT(Name) FROM Lead GROUP BY LeadSource", 3 | "totalSize":4, 4 | "done":true, 5 | "records":[ 6 | { 7 | "attributes":{ 8 | "type":"AggregateResult" 9 | }, 10 | "LeadSource":"Web", 11 | "expr0":7 12 | }, 13 | { 14 | "attributes":{ 15 | "type":"AggregateResult" 16 | }, 17 | "LeadSource":"Phone Inquiry", 18 | "expr0":4 19 | }, 20 | { 21 | "attributes":{ 22 | "type":"AggregateResult" 23 | }, 24 | "LeadSource":"Partner Referral", 25 | "expr0":4 26 | }, 27 | { 28 | "attributes":{ 29 | "type":"AggregateResult" 30 | }, 31 | "LeadSource":"Purchased List", 32 | "expr0":7 33 | } 34 | ] 35 | } -------------------------------------------------------------------------------- /src/test/resources/query-simple.json: -------------------------------------------------------------------------------- 1 | { 2 | "debug":"SELECT Id, Name, BillingCity FROM Account", 3 | "totalSize":12, 4 | "done":true, 5 | "nextRecordsUrl":"/services/data/v37.0/query/01gD0000002HU6KIAW-2000", 6 | "records":[ 7 | { 8 | "attributes":{ 9 | "type":"Account", 10 | "url":"/services/data/v37.0/sobjects/Account/001A000000df63xIAA" 11 | }, 12 | "Id":"001A000000df63xIAA", 13 | "Name":"GenePoint", 14 | "BillingCity":"Mountain View" 15 | }, 16 | { 17 | "attributes":{ 18 | "type":"Account", 19 | "url":"/services/data/v37.0/sobjects/Account/001A000000df63yIAA" 20 | }, 21 | "Id":"001A000000df63yIAA", 22 | "Name":"United Oil & Gas, UK", 23 | "BillingCity":null 24 | }, 25 | { 26 | "attributes":{ 27 | "type":"Account", 28 | "url":"/services/data/v37.0/sobjects/Account/001A000000df63zIAA" 29 | }, 30 | "Id":"001A000000df63zIAA", 31 | "Name":"United Oil & Gas, Singapore", 32 | "BillingCity":"Singapore" 33 | }, 34 | { 35 | "attributes":{ 36 | "type":"Account", 37 | "url":"/services/data/v37.0/sobjects/Account/001A000000df640IAA" 38 | }, 39 | "Id":"001A000000df640IAA", 40 | "Name":"Edge Communications", 41 | "BillingCity":"Austin" 42 | }, 43 | { 44 | "attributes":{ 45 | "type":"Account", 46 | "url":"/services/data/v37.0/sobjects/Account/001A000000df641IAA" 47 | }, 48 | "Id":"001A000000df641IAA", 49 | "Name":"Burlington Textiles Corp of America", 50 | "BillingCity":"Burlington" 51 | }, 52 | { 53 | "attributes":{ 54 | "type":"Account", 55 | "url":"/services/data/v37.0/sobjects/Account/001A000000df642IAA" 56 | }, 57 | "Id":"001A000000df642IAA", 58 | "Name":"Pyramid Construction Inc.", 59 | "BillingCity":"Paris" 60 | }, 61 | { 62 | "attributes":{ 63 | "type":"Account", 64 | "url":"/services/data/v37.0/sobjects/Account/001A000000df643IAA" 65 | }, 66 | "Id":"001A000000df643IAA", 67 | "Name":"Dickenson plc", 68 | "BillingCity":"Lawrence" 69 | }, 70 | { 71 | "attributes":{ 72 | "type":"Account", 73 | "url":"/services/data/v37.0/sobjects/Account/001A000000df644IAA" 74 | }, 75 | "Id":"001A000000df644IAA", 76 | "Name":"Grand Hotels & Resorts Ltd", 77 | "BillingCity":"Chicago" 78 | }, 79 | { 80 | "attributes":{ 81 | "type":"Account", 82 | "url":"/services/data/v37.0/sobjects/Account/001A000000df645IAA" 83 | }, 84 | "Id":"001A000000df645IAA", 85 | "Name":"Express Logistics and Transport", 86 | "BillingCity":"Portland" 87 | }, 88 | { 89 | "attributes":{ 90 | "type":"Account", 91 | "url":"/services/data/v37.0/sobjects/Account/001A000000df646IAA" 92 | }, 93 | "Id":"001A000000df646IAA", 94 | "Name":"University of Arizona", 95 | "BillingCity":"Tucson" 96 | }, 97 | { 98 | "attributes":{ 99 | "type":"Account", 100 | "url":"/services/data/v37.0/sobjects/Account/001A000000df647IAA" 101 | }, 102 | "Id":"001A000000df647IAA", 103 | "Name":"United Oil & Gas Corp.", 104 | "BillingCity":"New York" 105 | }, 106 | { 107 | "attributes":{ 108 | "type":"Account", 109 | "url":"/services/data/v37.0/sobjects/Account/001A000000df648IAA" 110 | }, 111 | "Id":"001A000000df648IAA", 112 | "Name":"sForce", 113 | "BillingCity":"San Francisco" 114 | } 115 | ] 116 | } -------------------------------------------------------------------------------- /src/test/resources/query-where.json: -------------------------------------------------------------------------------- 1 | { 2 | "debug":"SELECT Id FROM Contact WHERE Name LIKE 'U%' AND MailingCity = 'Istanbul'", 3 | "totalSize":2, 4 | "done":true, 5 | "records":[ 6 | { 7 | "attributes":{ 8 | "type":"Contact", 9 | "url":"/services/data/v37.0/sobjects/Contact/003A000000vF6QSIA0" 10 | }, 11 | "Id":"003A000000vF6QSIA0" 12 | }, 13 | { 14 | "attributes":{ 15 | "type":"Contact", 16 | "url":"/services/data/v37.0/sobjects/Contact/003A000000vF6QXIA0" 17 | }, 18 | "Id":"003A000000vF6QXIA0" 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /src/test/resources/recent.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "attributes":{ 4 | "type":"User", 5 | "url":"/services/data/v37.0/sobjects/User/005A0000001cRuvIAE" 6 | }, 7 | "Id":"005A0000001cRuvIAE", 8 | "Name":"Umut Utkan" 9 | }, 10 | { 11 | "attributes":{ 12 | "type":"Solution", 13 | "url":"/services/data/v37.0/sobjects/Solution/501A0000000FrMzIAK" 14 | }, 15 | "Id":"501A0000000FrMzIAK", 16 | "SolutionName":"GC1020 Portable Generator Switch Malfunctioning" 17 | }, 18 | { 19 | "attributes":{ 20 | "type":"Opportunity", 21 | "url":"/services/data/v37.0/sobjects/Opportunity/006A000000E6W3uIAF" 22 | }, 23 | "Id":"006A000000E6W3uIAF", 24 | "Name":"Edge SLA" 25 | }, 26 | { 27 | "attributes":{ 28 | "type":"Lead", 29 | "url":"/services/data/v37.0/sobjects/Lead/00QA000000KI4FQMA1" 30 | }, 31 | "Id":"00QA000000KI4FQMA1", 32 | "Name":"Bertha Boxer" 33 | }, 34 | { 35 | "attributes":{ 36 | "type":"Hedere__c", 37 | "url":"/services/data/v37.0/sobjects/Hedere__c/a01A000000BANsBIAX" 38 | }, 39 | "Id":"a01A000000BANsBIAX", 40 | "Name":"bizzz" 41 | }, 42 | { 43 | "attributes":{ 44 | "type":"Contact", 45 | "url":"/services/data/v37.0/sobjects/Contact/003A000000lGE0iIAG" 46 | }, 47 | "Id":"003A000000lGE0iIAG", 48 | "Name":"Rose Gonzalez" 49 | }, 50 | { 51 | "attributes":{ 52 | "type":"Case", 53 | "url":"/services/data/v37.0/sobjects/Case/500A00000077a57IAA" 54 | }, 55 | "Id":"500A00000077a57IAA", 56 | "CaseNumber":"00001006" 57 | }, 58 | { 59 | "attributes":{ 60 | "type":"Campaign", 61 | "url":"/services/data/v37.0/sobjects/Campaign/701A0000000AlJ5IAK" 62 | }, 63 | "Id":"701A0000000AlJ5IAK", 64 | "Name":"GC Product Webinar - Jan 7, 2002" 65 | }, 66 | { 67 | "attributes":{ 68 | "type":"Account", 69 | "url":"/services/data/v37.0/sobjects/Account/001A000000df63xIAA" 70 | }, 71 | "Id":"001A000000df63xIAA", 72 | "Name":"GenePoint" 73 | } 74 | ] -------------------------------------------------------------------------------- /src/test/resources/search.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "attributes":{ 4 | "type":"Contact", 5 | "url":"/services/data/v37.0/sobjects/Contact/003A000000vF6QXIA0" 6 | }, 7 | "Id":"003A000000vF6QXIA0" 8 | }, 9 | { 10 | "attributes":{ 11 | "type":"Contact", 12 | "url":"/services/data/v37.0/sobjects/Contact/003A000000vF6QSIA0" 13 | }, 14 | "Id":"003A000000vF6QSIA0" 15 | }, 16 | { 17 | "attributes":{ 18 | "type":"Account", 19 | "url":"/services/data/v37.0/sobjects/Account/a01A000000BANsaIAH" 20 | }, 21 | "Id":"a01A000000BANsaIAH" 22 | }, 23 | { 24 | "attributes":{ 25 | "type":"Account", 26 | "url":"/services/data/v37.0/sobjects/Account/a01A000000BANsVIAX" 27 | }, 28 | "Id":"a01A000000BANsVIAX" 29 | } 30 | ] -------------------------------------------------------------------------------- /src/test/resources/services.json: -------------------------------------------------------------------------------- 1 | { 2 | "sobjects":"/services/data/v37.0/sobjects", 3 | "identity":"https://login.salesforce.com/id/00DA0000000BjjPMAS/005A0000001cRuvIAE", 4 | "search":"/services/data/v37.0/search", 5 | "query":"/services/data/v37.0/query", 6 | "chatter":"/services/data/v37.0/chatter", 7 | "recent":"/services/data/v37.0/recent" 8 | } -------------------------------------------------------------------------------- /src/test/resources/services2.json: -------------------------------------------------------------------------------- 1 | { 2 | "sobjects":"/services/data/v37.0/sobjects", 3 | "identity":"https://login.salesforce.com/id/00DA0000000BjjPMAS/005A0000001cRuvIAE", 4 | "search":"/services/data/v37.0/search", 5 | "query":"/services/data/v37.0/query", 6 | "chatter":"/services/data/v37.0/chatter", 7 | "recent":"/services/data/v37.0/recent" 8 | } -------------------------------------------------------------------------------- /src/test/resources/userDetails.json: -------------------------------------------------------------------------------- 1 | { 2 | "sub":"http://login.salesforce.com/id/6789/12345", 3 | "user_id":"12345", 4 | "organization_id":"6789", 5 | "preferred_username":"johnny", 6 | "nickname":"johnny_doe", 7 | "name":"John Doe", 8 | "email":"john@doe.com", 9 | "email_verified":true, 10 | "given_name":"John", 11 | "family_name":"Doe", 12 | "zoneinfo":"America/Los_Angeles", 13 | "photos":{ 14 | "picture":"https://c.na7.content.force.com/profilephoto/005/F", 15 | "thumbnail":"https://c.na7.content.force.com/profilephoto/005/T" 16 | }, 17 | "profile":"https://yourInstance.salesforce.com/005x000...", 18 | "picture":"https://yourInstance.salesforce.com/profilephoto/005/F", 19 | "address":{ 20 | "country":"us" 21 | }, 22 | "urls":{ 23 | "enterprise":"https://yourInstance.salesforce.com/services/Soap/c/{version}/00Dx00...", 24 | "partner":"https://yourInstance.salesforce.com/services/Soap/u/{version}/00Dx00...", 25 | "rest":"https://yourInstance.salesforce.com/services/data/v{version}/", 26 | "sobjects":"https://yourInstance.salesforce.com/services/data/v{version}/sobjects/", 27 | "search":"https://yourInstance.salesforce.com/services/data/v{version}/search/", 28 | "query":"https://yourInstance.salesforce.com/services/data/v{version}/query/", 29 | "recent":"https://yourInstance.salesforce.com/services/data/v{version}/recent/", 30 | "profile":"https://yourInstance.salesforce.com/005x000...", 31 | "feeds":"https://yourInstance.salesforce.com/services/data/v{version}/chatter/feeds", 32 | "groups":"https://yourInstance.salesforce.com/services/data/v{version}/chatter/groups", 33 | "users":"https://yourInstance.salesforce.com/services/data/v{version}/chatter/users", 34 | "feed_items":"https://yourInstance.salesforce.com/services/data/v{version}/chatter/feed-items" 35 | }, 36 | "active":true, 37 | "user_type":"STANDARD", 38 | "language":"en_US", 39 | "locale":"en_US", 40 | "utcOffset":-28800000, 41 | "updated_at":"2013-12-02T18:46:42.000+0000" 42 | } -------------------------------------------------------------------------------- /src/test/resources/versions.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "label":"Winter '11", 4 | "url":"/services/data/v20.0", 5 | "version":"20.0" 6 | }, 7 | { 8 | "label":"Spring '11", 9 | "url":"/services/data/v21.0", 10 | "version":"21.0" 11 | }, 12 | { 13 | "label":"Summer '11", 14 | "url":"/services/data/v22.0", 15 | "version":"22.0" 16 | }, 17 | { 18 | "label":"Winter '12", 19 | "url":"/services/data/v23.0", 20 | "version":"23.0" 21 | } 22 | ] --------------------------------------------------------------------------------