-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://fusion.mastercard.int/stash/scm/ppct…
- Loading branch information
Showing
11 changed files
with
270 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/com/mastercard/developers/carbontracker/service/UpdateUserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.mastercard.developers.carbontracker.service; | ||
|
||
import com.mastercard.developers.carbontracker.exception.ServiceException; | ||
import org.openapitools.client.model.UpdateUserProfile; | ||
import org.openapitools.client.model.UserReference; | ||
|
||
public interface UpdateUserService { | ||
|
||
UserReference updateUser(String userId, UpdateUserProfile updateUserProfile) throws ServiceException; | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...main/java/com/mastercard/developers/carbontracker/service/impl/UpdateUserServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.mastercard.developers.carbontracker.service.impl; | ||
|
||
import com.mastercard.developer.interceptors.OkHttpFieldLevelEncryptionInterceptor; | ||
import com.mastercard.developer.interceptors.OkHttpOAuth1Interceptor; | ||
import com.mastercard.developers.carbontracker.configuration.ApiConfiguration; | ||
import com.mastercard.developers.carbontracker.exception.ServiceException; | ||
import com.mastercard.developers.carbontracker.service.UpdateUserService; | ||
import com.mastercard.developers.carbontracker.util.EncryptionHelper; | ||
import lombok.extern.slf4j.Slf4j; | ||
import okhttp3.OkHttpClient; | ||
import org.openapitools.client.ApiClient; | ||
import org.openapitools.client.ApiException; | ||
import org.openapitools.client.api.IssuerApi; | ||
import org.openapitools.client.model.UpdateUserProfile; | ||
import org.openapitools.client.model.UserReference; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import static com.mastercard.developers.carbontracker.util.JSON.deserializeErrors; | ||
|
||
@Slf4j | ||
@Service | ||
public class UpdateUserServiceImpl implements UpdateUserService { | ||
|
||
private final IssuerApi issuerApiForEncryptedPayload; | ||
|
||
@Autowired | ||
public UpdateUserServiceImpl(ApiConfiguration apiConfiguration) throws ServiceException { | ||
log.info("Initializing User Registration Service"); | ||
issuerApiForEncryptedPayload = new IssuerApi(setupForEncryptedPayload(apiConfiguration)); | ||
} | ||
|
||
private ApiClient setupForEncryptedPayload(ApiConfiguration apiConfiguration) throws ServiceException { | ||
OkHttpClient client = new OkHttpClient().newBuilder(). | ||
addInterceptor( | ||
new OkHttpFieldLevelEncryptionInterceptor( | ||
EncryptionHelper.encryptionConfig(apiConfiguration.getEncryptionKeyFile()))). | ||
addInterceptor( | ||
new OkHttpOAuth1Interceptor(apiConfiguration.getConsumerKey(), apiConfiguration.getSigningKey())) | ||
.build(); | ||
|
||
return new ApiClient().setHttpClient(client).setBasePath(apiConfiguration.getBasePath()); | ||
} | ||
|
||
@Override | ||
public UserReference updateUser(String userId, UpdateUserProfile updateUserProfile) throws ServiceException { | ||
UserReference userReference; | ||
try { | ||
userReference = issuerApiForEncryptedPayload.updateUser(userId, updateUserProfile); | ||
} catch (ApiException e) { | ||
log.error("Exception occurred while registering new user {}", e.getResponseBody()); | ||
|
||
throw new ServiceException(e.getMessage(), deserializeErrors(e.getResponseBody())); | ||
} | ||
|
||
return userReference; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.