Skip to content

Commit

Permalink
Refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
Raj-Shah1 committed Sep 13, 2023
1 parent 7dbee79 commit fb5d026
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/salessparrow/api/config/CoreConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public static String defaultTestUserPassword() {
return SecretConstants.defaultTestUserPassword();
}

public static String defaultTestUserCode() {
return "test_12341234";
}

/**
* This method returns the memcached address that is going to be used for locals
* @return String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@
@Component
public class CacheConstants {

public static final String CACHE_SUFFIX;
public static final String CACHE_SUFFIX = getCacheSuffix();

static {
public static final String SALESFORCE_USER_CACHE = "sf_user";

public static final Integer SALESFORCE_USER_CACHE_EXP = 30 * 24 * 60 * 60; // 30
// days

public static final String SALESFORCE_OAUTH_TOKEN_CACHE = "sf_oauth_token";

public static final Integer SALESFORCE_OAUTH_TOKEN_CACHE_EXP = 30 * 24 * 60 * 60; // 30
// days

public static String getCacheSuffix() {
if (CoreConstants.isProductionEnvironment()) {
CACHE_SUFFIX = "_prod";
return "_prod";
}
else if (CoreConstants.isStagingEnvironment()) {
CACHE_SUFFIX = "_stag";
return "_stag";
}
else if (CoreConstants.isTestEnvironment()) {
CACHE_SUFFIX = "_test";
return "_test";
}
else if (CoreConstants.isLocalTestEnvironment()) {
CACHE_SUFFIX = "_ltest";
return "_ltest";
}
else {
CACHE_SUFFIX = "_dev";
return "_dev";
}
}

public static final String SALESFORCE_USER_CACHE = "sf_user";

public static final Integer SALESFORCE_USER_CACHE_EXP = 30 * 24 * 60 * 60; // 30
// days

public static final String SALESFORCE_OAUTH_TOKEN_CACHE = "sf_oauth_token";

public static final Integer SALESFORCE_OAUTH_TOKEN_CACHE_EXP = 30 * 24 * 60 * 60; // 30
// days

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.salessparrow.api.domain.SalesforceOauthToken;
import com.salessparrow.api.exception.CustomException;
import com.salessparrow.api.lib.errorLib.ErrorObject;
import com.salessparrow.api.lib.httpLib.HttpClient;
import com.salessparrow.api.repositories.SalesforceOauthTokenRepository;

import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ public HttpResponse getTokens(String code, String redirectUri, Boolean isTestUse
String requestBody;

if (!isTestUser) {
requestBody = "grant_type=" + salesforceConstants.authorizationCodeGrantType() + "&client_id="
+ CoreConstants.salesforceClientId() + "&client_secret=" + CoreConstants.salesforceClientSecret()
+ "&code=" + code + "&redirect_uri=" + redirectUri;
requestBody = String.format("grant_type=%s&client_id=%s&client_secret=%s&code=%s&redirect_uri=%s",
salesforceConstants.authorizationCodeGrantType(), CoreConstants.salesforceClientId(),
CoreConstants.salesforceClientSecret(), code, redirectUri);
}
else {
requestBody = "grant_type=" + salesforceConstants.passwordGrantType() + "&client_id="
+ CoreConstants.salesforceClientId() + "&client_secret=" + CoreConstants.salesforceClientSecret()
+ "&username=" + CoreConstants.defaultTestUser() + "&password="
+ CoreConstants.defaultTestUserPassword() + "&redirect_uri=" + redirectUri;
requestBody = String.format(
"grant_type=%s&client_id=%s&client_secret=%s&username=%s&password=%s&redirect_uri=%s",
salesforceConstants.passwordGrantType(), CoreConstants.salesforceClientId(),
CoreConstants.salesforceClientSecret(), CoreConstants.defaultTestUser(),
CoreConstants.defaultTestUserPassword(), redirectUri);
}

Map<String, String> headers = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.salessparrow.api.repositories.SalesforceOrganizationRepository;
import com.salessparrow.api.repositories.SalesforceUserRepository;
import jakarta.servlet.http.HttpServletRequest;
import software.amazon.awssdk.services.secretsmanager.endpoints.internal.Value.Bool;

@Service
public class AuthService {
Expand Down Expand Up @@ -94,7 +93,7 @@ public AuthServiceDto connectToSalesforce(SalesforceConnectDto params, HttpServl
this.isNewUser = true; // setting default value true to this variable, this will
// be updated based on conditions in further processing

String testUserCode = "test_12341234";
String testUserCode = CoreConstants.defaultTestUserCode();
Boolean isTestUser = false;

code = params.getCode();
Expand Down

0 comments on commit fb5d026

Please sign in to comment.