From 99f3ab35cd24dbbe3e55176db3791498afe3f12b Mon Sep 17 00:00:00 2001 From: Jayendra Date: Tue, 16 Jul 2019 17:42:28 +0530 Subject: [PATCH 1/2] Updated grpc configuration code for auth service and account service --- src/main/java/biz/nynja/airdrop/Config.java | 7 +- .../airdrop/controller/AirdropController.java | 184 +++++++++++------- .../airdrop/grpc/AccountServiceClientOld.java | 10 +- .../nynja/airdrop/grpc/AuthServiceClient.java | 37 +++- .../nynja/airdrop/kafka/KafkaConsumer.java | 50 +++-- .../repository/OtpSessionsRepository.java | 2 + .../nynja/airdrop/util/RestTemplateUtil.java | 22 +++ src/main/resources/application.yml | 8 +- 8 files changed, 222 insertions(+), 98 deletions(-) diff --git a/src/main/java/biz/nynja/airdrop/Config.java b/src/main/java/biz/nynja/airdrop/Config.java index 31ca8f5..6c38661 100644 --- a/src/main/java/biz/nynja/airdrop/Config.java +++ b/src/main/java/biz/nynja/airdrop/Config.java @@ -4,6 +4,7 @@ import biz.nynja.airdrop.kafka.KafkaMessageTemplate; import com.datastax.driver.core.Cluster; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; +import io.grpc.netty.NettyChannelBuilder; import io.micrometer.core.instrument.MeterRegistry; import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.kafka.clients.producer.ProducerConfig; @@ -239,14 +240,16 @@ public class Config implements WebMvcConfigurer { @Bean(name = "accountServiceManagedChannel") public ManagedChannel accountServiceManagedChannel() { - ManagedChannel managedChannel = ManagedChannelBuilder.forAddress(GRPC_ACCOUNT_SERVICE_HOST, GRPC_ACCOUNT_SERVICE_PORT).usePlaintext().build(); + // ManagedChannel managedChannel = ManagedChannelBuilder.forAddress(GRPC_ACCOUNT_SERVICE_HOST, GRPC_ACCOUNT_SERVICE_PORT).usePlaintext().build(); + ManagedChannel managedChannel = NettyChannelBuilder.forAddress(GRPC_ACCOUNT_SERVICE_HOST, GRPC_ACCOUNT_SERVICE_PORT).usePlaintext().build(); logger.info("Account Service grpc channel is established"); return managedChannel; } @Bean(name = "authServiceManagedChannel") public ManagedChannel authServiceManagedChannel() { - ManagedChannel managedChannel = ManagedChannelBuilder.forAddress(GRPC_AUTH_SERVICE_HOST, GRPC_AUTH_SERVICE_PORT).usePlaintext().build(); + // ManagedChannel managedChannel = ManagedChannelBuilder.forAddress(GRPC_AUTH_SERVICE_HOST, GRPC_AUTH_SERVICE_PORT).usePlaintext().build(); + ManagedChannel managedChannel = NettyChannelBuilder.forAddress(GRPC_AUTH_SERVICE_HOST, GRPC_AUTH_SERVICE_PORT).usePlaintext().build(); logger.info("Auth Service grpc channel is established"); return managedChannel; } diff --git a/src/main/java/biz/nynja/airdrop/controller/AirdropController.java b/src/main/java/biz/nynja/airdrop/controller/AirdropController.java index 5c03e6a..ec6fc29 100644 --- a/src/main/java/biz/nynja/airdrop/controller/AirdropController.java +++ b/src/main/java/biz/nynja/airdrop/controller/AirdropController.java @@ -7,6 +7,7 @@ import biz.nynja.airdrop.entity.AirdropActions; import biz.nynja.airdrop.entity.AirdropProfiles; import biz.nynja.airdrop.entity.OtpSessions; import biz.nynja.airdrop.grpc.AccountServiceClient; + import biz.nynja.airdrop.grpc.AuthServiceClient; import biz.nynja.airdrop.kafka.KafkaMessageTemplate; import biz.nynja.airdrop.kafka.KafkaProducer; @@ -87,6 +88,18 @@ public class AirdropController { @Qualifier("kafkaTopic") private String kafkaTopic; + + @Value("${grpc.accountService.host}") + private String GRPC_ACCOUNT_SERVICE_HOST; + @Value("${grpc.accountService.port}") + private int GRPC_ACCOUNT_SERVICE_PORT; + + @Value("${grpc.authService.host}") + private String GRPC_AUTH_SERVICE_HOST; + @Value("${grpc.authService.port}") + private int GRPC_AUTH_SERVICE_PORT; + + private static final Logger logger = LoggerFactory.getLogger(AirdropController.class); @GetMapping("/") @@ -96,6 +109,24 @@ public class AirdropController { } + @GetMapping("/rest/exchangeRefreshToken") + public String restExchangeRefreshToken(@RequestHeader(value = "Authorization") String token) { + + System.out.println(""); + System.out.println("-----------"); + System.out.println("Rest Exchange Refresh Token"); + System.out.println("-----------"); + System.out.println(""); + + Object response = restTemplateUtil.exchangeRefreshToken(token); + + System.out.println("Response : "); + System.out.println(response); + System.out.println(""); + + return response.toString(); + } + @GetMapping("/test/1") public String testEndpoint1() { @@ -145,6 +176,9 @@ public class AirdropController { System.out.println(""); System.out.println("--------------"); System.out.println(""); + System.out.println("GRPC_ACCOUNT_SERVICE_HOST : " + GRPC_ACCOUNT_SERVICE_HOST); + System.out.println("GRPC_ACCOUNT_SERVICE_PORT : " + GRPC_ACCOUNT_SERVICE_PORT); + System.out.println(""); SearchResponse searchResponse; @@ -179,7 +213,7 @@ public class AirdropController { @GetMapping("/test/exchangeToken") - public String test2(@RequestHeader(value = "Authorization", required = false) String refreshToken) throws IOException { + public String exchangeTokenTest(@RequestHeader(value = "Authorization", required = false) String refreshToken) throws IOException { System.out.println(""); System.out.println("--------------"); @@ -191,6 +225,10 @@ public class AirdropController { System.out.println(""); System.out.println("--------------"); System.out.println(""); + System.out.println("GRPC_AUTH_SERVICE_HOST : " + GRPC_AUTH_SERVICE_HOST); + System.out.println("GRPC_AUTH_SERVICE_PORT : " + GRPC_AUTH_SERVICE_PORT); + System.out.println(""); + GenerateTokenResponse tokenResponse; @@ -224,20 +262,18 @@ public class AirdropController { } - @GetMapping("/test/exchangeTokenRefreshToken/{refreshToken}") - public String test3(@PathVariable("refreshToken") String refreshToken) throws IOException { + @GetMapping("/test/exchangeToken2") + public boolean exchangeTokenTest2() throws IOException { System.out.println(""); System.out.println("--------------"); System.out.println(""); System.out.println("Testing Exchange-Token Endpoint By Manual Refresh-Token"); System.out.println(""); - System.out.println("GivenRefreshToken : " + refreshToken); - System.out.println(""); System.out.println("--------------"); System.out.println(""); - return authServiceClient.exchangeRefreshTokenManual(refreshToken).toString(); + return authServiceClient.exchangeRefreshToken(); } @@ -280,7 +316,7 @@ public class AirdropController { logger.info("username: " + username); - /*System.out.println(""); + System.out.println(""); System.out.println("----------------"); System.out.println(""); System.out.println("VERIFY USER CONTROLLER"); @@ -288,14 +324,14 @@ public class AirdropController { System.out.println("username : " + username); System.out.println(""); System.out.println("----------------"); - System.out.println("");*/ + System.out.println(""); if (username.equals("")) { - /*System.out.println(""); + System.out.println(""); System.out.println("Username is blank"); - System.out.println("");*/ + System.out.println(""); logger.warn("Username is blank"); @@ -319,15 +355,15 @@ public class AirdropController { logger.info("accountId:"); logger.debug("{}", accountId); - /*System.out.println(""); + System.out.println(""); System.out.println("accountId : " + accountId); - System.out.println("");*/ + System.out.println(""); if (accountId == null) { - /* System.out.println(""); + System.out.println(""); System.out.println("Account Service Validation Failed. No User with username : " + username); - System.out.println("");*/ + System.out.println(""); logger.warn("Account Service Validation Failed. No User with username : " + username); @@ -342,10 +378,10 @@ public class AirdropController { List airdropProfilesList = airdropProfilesService.getAirdropProfiles(accountId, null); - /*System.out.println(""); + System.out.println(""); System.out.println("Airdrop Profile List"); System.out.println(airdropProfilesList); - System.out.println("");*/ + System.out.println(""); logger.info("Airdrop Profile List:"); logger.debug("{}", airdropProfilesList); @@ -355,12 +391,12 @@ public class AirdropController { AirdropProfiles airdropProfiles = airdropProfilesList.get(0); - /*System.out.println(""); + System.out.println(""); System.out.println("Profile already exists"); System.out.println(""); System.out.println("airdropProfiles :"); System.out.println(airdropProfiles); - System.out.println("");*/ + System.out.println(""); logger.warn("Profile already exists"); logger.warn("airdropProfiles: "); @@ -368,9 +404,9 @@ public class AirdropController { if (airdropProfiles.getIs_verified() == Constants.VerificationStatus.VERIFIED) { - /*System.out.println(""); + System.out.println(""); System.out.println("Airdrop Profile is already Verified"); - System.out.println("");*/ + System.out.println(""); logger.warn("Airdrop Profile is already Verified"); @@ -385,8 +421,8 @@ public class AirdropController { if (airdropProfilesList == null || airdropProfilesList.isEmpty()) { - /*System.out.println(""); - System.out.println("Adding New Airbase Profile");*/ + System.out.println(""); + System.out.println("Adding New Airbase Profile"); logger.info("Adding New Airbase Profile"); @@ -402,16 +438,16 @@ public class AirdropController { airdropProfilesService.addAirdropProfile(airdropProfilesObj); - /*System.out.println(""); - System.out.println("New Airbase Profile is Added");*/ + System.out.println(""); + System.out.println("New Airbase Profile is Added"); logger.info("New Airbase Profile is Added"); } int otp = AirdropUtil.generateOtpNumber(); -/* System.out.println(""); + System.out.println(""); System.out.println("OTP Generated : " + otp); - System.out.println("");*/ + System.out.println(""); logger.info("OTP generated: " + otp); @@ -441,7 +477,11 @@ public class AirdropController { */ - restTemplateUtil.sendPushNotification(accountId.toString(), otp); + System.out.println(""); + System.out.println("SEND PUSH NOTIFICATION API CALLED HERE"); + System.out.println(""); + + // restTemplateUtil.sendPushNotification(accountId.toString(), otp); return HttpResponse.getResponse(SUCCESS_STATUS_CODE, responseData, null); } @@ -486,7 +526,7 @@ public class AirdropController { @RequestParam("session_id") UUID sessionId // OTP SESSION-ID ) { - /*System.out.println(""); + System.out.println(""); System.out.println("-------------------"); System.out.println(""); System.out.println("VERIFY OTP CONTROLLER"); @@ -496,7 +536,7 @@ public class AirdropController { System.out.println("sessionId : " + sessionId); System.out.println(""); System.out.println("-------------------"); - System.out.println("");*/ + System.out.println(""); logger.info("Verify Otp API"); logger.info("Parameters: "); @@ -510,11 +550,11 @@ public class AirdropController { otp = Integer.valueOf(otpString); } catch (NumberFormatException exception) { - /*System.out.println(""); + System.out.println(""); System.out.println("OTP is not valid"); System.out.println(""); System.out.println("Exception : " + exception.getMessage()); - System.out.println("");*/ + System.out.println(""); logger.warn("OTP is not valid"); logger.warn("Exception in reading otp, message:{}, cause:{}", exception.getMessage(), exception.getCause()); @@ -524,9 +564,9 @@ public class AirdropController { if (username.equals("")) { - /*System.out.println(""); + System.out.println(""); System.out.println("Username is blank"); - System.out.println("");*/ + System.out.println(""); logger.warn("username is blank"); @@ -551,11 +591,9 @@ public class AirdropController { if (accountId == null) { -/* System.out.println(""); System.out.println("Account Service Validation Failed. No User with username : " + username); System.out.println(""); -*/ logger.warn("Account Service validation failed. No user with username: " + username); @@ -572,9 +610,9 @@ public class AirdropController { if (airdropProfilesList.isEmpty()) { - /*System.out.println(""); + System.out.println(""); System.out.println("No, such Airdrop Profile exists"); - System.out.println("");*/ + System.out.println(""); logger.warn("No, such Airdrop Profile exists"); @@ -587,24 +625,24 @@ public class AirdropController { AirdropProfiles airdropProfiles = airdropProfilesList.get(0); - /*System.out.println(""); + System.out.println(""); System.out.println("Airdrop Profile"); System.out.println(airdropProfiles); - System.out.println("");*/ + System.out.println(""); OtpSessions otpSession = otpSessionsService.getOtpSessions(sessionId); - /*System.out.println(""); + System.out.println(""); System.out.println("otpSession"); System.out.println(otpSession); - System.out.println("");*/ + System.out.println(""); if (otpSession == null) { - /* System.out.println(""); + System.out.println(""); System.out.println("OTP Session doesn't exists"); - System.out.println("");*/ + System.out.println(""); logger.info("Otp session doesn't exists"); @@ -616,9 +654,9 @@ public class AirdropController { } else if (!airdropProfiles.getAccount_id().equals(otpSession.getAccount_id())) { - /*System.out.println(""); + System.out.println(""); System.out.println("AccountId of OTPSession and Airdrop Profile doesn't matches"); - System.out.println("");*/ + System.out.println(""); logger.warn("AccountId of OTPSession and Airdrop Profile doesn't matches"); @@ -629,9 +667,9 @@ public class AirdropController { } else if (otpSession.getOtp() != otp) { - /*System.out.println(""); + System.out.println(""); System.out.println("OTP not matched"); - System.out.println("");*/ + System.out.println(""); logger.warn("OTP is not matched"); @@ -643,9 +681,9 @@ public class AirdropController { return HttpResponse.getResponse(BAD_REQUEST_STATUS_CODE, responseData, HttpConstants.MessageTags.OTP_NOT_MATCHED); } else if (otpSession.getExpired_ts() < AirdropUtil.generateCurrentEpochTimeStamp()) { - /*System.out.println(""); + System.out.println(""); System.out.println("OTP is Expired"); - System.out.println("");*/ + System.out.println(""); logger.warn("OTP is not matched"); @@ -660,9 +698,9 @@ public class AirdropController { // Check If already verified in Account - /*System.out.println(""); + System.out.println(""); System.out.println("Airdrop profile is already verified"); - System.out.println("");*/ + System.out.println(""); logger.info("Airdrop profile is already verified"); @@ -682,10 +720,10 @@ public class AirdropController { updationMap.put("modified_ts", AirdropUtil.generateCurrentEpochTimeStamp()); boolean airdropProfileUpdate = airdropProfilesService.updateAirdropProfile(airdropProfiles.getId(), airdropProfiles.getAccount_id(), updationMap); - /*System.out.println(""); + System.out.println(""); System.out.println("otpSessionUpdate : " + otpSessionUpdate); System.out.println("airdropProfileUpdate : " + airdropProfileUpdate); - System.out.println("");*/ + System.out.println(""); logger.info("Airdrop profile is already verified"); @@ -693,9 +731,9 @@ public class AirdropController { kafkaMessageTemplate.setAccount_id(airdropProfiles.getAccount_id().toString()); kafkaMessageTemplate.setAction_type(Constants.KafkaActionType.JOIN); - /* System.out.println(""); + System.out.println(""); System.out.println("Message Pushed to Kafka Producer"); - System.out.println("");*/ + System.out.println(""); logger.info("Message is pushed to kafka"); kafkaProducer.sendKafkaMessage(kafkaMessageTemplate); @@ -742,11 +780,11 @@ public class AirdropController { public Map resendOtp(@RequestParam("session_id") UUID sessionId) // OTP SESSION-ID { - /*System.out.println(""); + System.out.println(""); System.out.println("RESEND OTP CONTROLLER"); System.out.println(""); System.out.println("otpSession : " + sessionId); - System.out.println("");*/ + System.out.println(""); logger.info("Resend OTP API"); logger.info("Parameters: "); @@ -754,16 +792,16 @@ public class AirdropController { OtpSessions otpSessions = otpSessionsService.getOtpSessions(sessionId); - /*System.out.println(""); + System.out.println(""); System.out.println("OTP Sessions"); System.out.println(otpSessions); - System.out.println("");*/ + System.out.println(""); if (otpSessions == null) { - /* System.out.println(""); + System.out.println(""); System.out.println("OTP Sessions doesn't exists"); - System.out.println("");*/ + System.out.println(""); logger.warn("OTP sessions doesn't exists"); @@ -773,9 +811,9 @@ public class AirdropController { if (otpSessions.getIs_verified() == Constants.VerificationStatus.VERIFIED) { - /*System.out.println(""); + System.out.println(""); System.out.println("OTP is already Verified"); - System.out.println("");*/ + System.out.println(""); logger.info("OTP is already Verified"); @@ -788,9 +826,9 @@ public class AirdropController { if (airdropProfilesService.getAirdropProfiles(otpSessions.getAccount_id(), null).get(0).getIs_verified() == Constants.VerificationStatus.VERIFIED) { - /*System.out.println(""); + System.out.println(""); System.out.println("Airdrop Profile is already Verified"); - System.out.println("");*/ + System.out.println(""); logger.info("Airdrop Profile is already Verified"); @@ -813,6 +851,12 @@ public class AirdropController { UUID newOtpSessionId = UUID.randomUUID(); int otp = AirdropUtil.generateOtpNumber(); + System.out.println(""); + System.out.println("---------------------------"); + System.out.println("New generated otp : " + otp); + System.out.println("---------------------------"); + System.out.println(""); + OtpSessions otpSessionsObj = new OtpSessions(); otpSessionsObj.setAccount_id(otpSessions.getAccount_id()); otpSessionsObj.setId(newOtpSessionId); @@ -823,9 +867,9 @@ public class AirdropController { otpSessionsObj.setExpired_ts((epochCreationTimeStamp + OTP_EXPIRE_TIME)); - /*System.out.println(""); + System.out.println(""); System.out.println("New Otp Session Created"); - System.out.println("");*/ + System.out.println(""); logger.info("New Otp Session Created"); @@ -847,7 +891,11 @@ public class AirdropController { // HERE, NYNJA PUSH SERVICE WILL BE CALLED TO SEND NOTIFICATION TO USER */ - restTemplateUtil.sendPushNotification(otpSessions.getAccount_id().toString(), otp); + System.out.println(""); + System.out.println("SEND PUSH NOTIFICATION API CALLED HERE"); + System.out.println(""); + + // restTemplateUtil.sendPushNotification(otpSessions.getAccount_id().toString(), otp); return HttpResponse.getResponse(SUCCESS_STATUS_CODE, responseData, null); } diff --git a/src/main/java/biz/nynja/airdrop/grpc/AccountServiceClientOld.java b/src/main/java/biz/nynja/airdrop/grpc/AccountServiceClientOld.java index f2069cc..9366c6d 100644 --- a/src/main/java/biz/nynja/airdrop/grpc/AccountServiceClientOld.java +++ b/src/main/java/biz/nynja/airdrop/grpc/AccountServiceClientOld.java @@ -1,22 +1,26 @@ -/*package biz.nynja.airdrop.grpc; +/* +package biz.nynja.airdrop.grpc; import io.grpc.ManagedChannel; import org.grpc.service.verifyAccountRequest; import org.grpc.service.verifyAccountResponse; import org.grpc.service.verifyAccountServiceGrpc; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; -import java.util.UUID;*/ - +import java.util.UUID; +*/ /* @Component public class AccountServiceClientOld { @Autowired + @Qualifier("accountServiceManagedChannel") private ManagedChannel managedChannel; + private verifyAccountServiceGrpc.verifyAccountServiceBlockingStub verifyAccountServiceBlockingStub; diff --git a/src/main/java/biz/nynja/airdrop/grpc/AuthServiceClient.java b/src/main/java/biz/nynja/airdrop/grpc/AuthServiceClient.java index ac8015f..6723ee6 100644 --- a/src/main/java/biz/nynja/airdrop/grpc/AuthServiceClient.java +++ b/src/main/java/biz/nynja/airdrop/grpc/AuthServiceClient.java @@ -17,7 +17,6 @@ import java.util.Map; @Component public class AuthServiceClient extends AuthenticationServiceGrpc.AuthenticationServiceImplBase { - @Autowired @Qualifier("authServiceManagedChannel") private ManagedChannel managedChannel; @@ -136,7 +135,15 @@ public class AuthServiceClient extends AuthenticationServiceGrpc.AuthenticationS System.out.println(""); - if (accessToken.equals(tokens.get("accessToken")) || refreshToken.equals(tokens.get("refreshToken"))) { + if (accessToken == null && refreshToken == null) { + + System.out.println(""); + System.out.println("New access token and new refreshToken are null"); + System.out.println(""); + System.out.println("So, file token won't be updated"); + System.out.println(""); + + } else if ((accessToken.equals(tokens.get("accessToken"))) || refreshToken.equals(tokens.get("refreshToken"))) { System.out.println(""); System.out.println("Old and New accessTokens are same"); @@ -155,8 +162,30 @@ public class AuthServiceClient extends AuthenticationServiceGrpc.AuthenticationS File outputDirectory = new File(AuthServiceClient.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/token/token.json"); Map newTokenDetails = new HashMap<>(2); - newTokenDetails.put("accessToken", accessToken); - newTokenDetails.put("refreshToken", refreshToken); + if (accessToken != null && !accessToken.equals("")) { + System.out.println(""); + System.out.println("Updating New Access Token in Tokens File"); + System.out.println(""); + newTokenDetails.put("accessToken", accessToken); + } else { + + System.out.println(""); + System.out.println("Access Token would not update in Tokens File"); + System.out.println(""); + newTokenDetails.put("accessToken", tokens.get("accessToken")); + } + + if (refreshToken != null && !refreshToken.equals("")) { + System.out.println(""); + System.out.println("Updating New Refresh Token in Tokens File"); + System.out.println(""); + newTokenDetails.put("refreshToken", refreshToken); + } else { + System.out.println(""); + System.out.println("Refresh Token would not update in Tokens File"); + System.out.println(""); + newTokenDetails.put("refreshToken", tokens.get("refreshToken")); + } objectMapper.writeValue(outputDirectory, newTokenDetails); diff --git a/src/main/java/biz/nynja/airdrop/kafka/KafkaConsumer.java b/src/main/java/biz/nynja/airdrop/kafka/KafkaConsumer.java index 5e64f62..fa88cf7 100644 --- a/src/main/java/biz/nynja/airdrop/kafka/KafkaConsumer.java +++ b/src/main/java/biz/nynja/airdrop/kafka/KafkaConsumer.java @@ -51,8 +51,8 @@ public class KafkaConsumer { public void kafkaConsumer(KafkaMessageTemplate kafkaMessageTemplate, Acknowledgment acknowledgment) { - /*System.out.println("KAFKA-MESSAGE"); - System.out.println(kafkaMessageTemplate);*/ + System.out.println("KAFKA-MESSAGE"); + System.out.println(kafkaMessageTemplate); logger.info("New Kafka Messsage Consumed: "); logger.info(kafkaMessageTemplate.toString()); @@ -60,29 +60,29 @@ public class KafkaConsumer { UUID accountId = UUID.fromString(kafkaMessageTemplate.getAccount_id()); List airdropProfilesList = airdropProfilesService.getAirdropProfiles(accountId, null); - /*System.out.println(""); + System.out.println(""); System.out.println("airdropProfilesList : "); - System.out.println(airdropProfilesList);*/ + System.out.println(airdropProfilesList); ActionsSummary actionsSummary = actionSummaryService.getActionsSummary(kafkaMessageTemplate.getAction_type()); - /*System.out.println(""); + System.out.println(""); System.out.println("actionsSummary : "); - System.out.println(actionsSummary);*/ + System.out.println(actionsSummary); if (airdropProfilesList.isEmpty() || actionsSummary == null) { - /*System.out.println(""); + System.out.println(""); System.out.println("No Action Summary Exists"); - System.out.println("No, Action will be performed on this Kafka Message");*/ + System.out.println("No, Action will be performed on this Kafka Message"); logger.warn("No Action Summary Exists for consumed kafkaMessage"); logger.warn("No, Action will be performed on this Kafka Message"); } else if (actionsSummary.getIs_active() == Constants.KafkaActionTypeActivationStatus.UNACTIVE) { - /*System.out.println(""); + System.out.println(""); System.out.println("ACTION TYPE IS NOT ACTIVE"); - System.out.println("No, Action will be performed on this Kafka Message");*/ + System.out.println("No, Action will be performed on this Kafka Message"); logger.warn("Action type is not active"); logger.warn("No, Action will be performed on this Kafka Message"); @@ -98,8 +98,24 @@ public class KafkaConsumer { if (airdropActionsList != null && !airdropActionsList.isEmpty() && airdropActionsList.get(0).getAction_type().equals(Constants.KafkaActionType.JOIN)) { logger.info("" + Constants.KafkaActionType.JOIN + " Action is already consumed. So, It won't be notified to QuionPro again"); } else { - String response = restTemplateUtil.qoinProChannelEngagementAPI(airdropProfilesList.get(0).getAccount_id().toString(), airdropProfilesList.get(0).getUsername(), kafkaMessageTemplate.getAction_type(), actionsSummary.getAction_description()); - notifiedQoinPro = (response.equals("Success")) ? true : false; + + + System.out.println(""); + System.out.println("======================"); + System.out.println("QOIN-PRO API IS CALLED HERE, "); + System.out.println("======================"); + System.out.println(""); + + + // UNCOMMENT IT LATER + // String response = restTemplateUtil.qoinProChannelEngagementAPI(airdropProfilesList.get(0).getAccount_id().toString(), airdropProfilesList.get(0).getUsername(), kafkaMessageTemplate.getAction_type(), actionsSummary.getAction_description()); + // notifiedQoinPro = (response.equals("Success")) ? true : false; + + System.out.println(""); + System.out.println("QOIN-PRO API Response is : SUCCESS"); + System.out.println(""); + + notifiedQoinPro = true; } // If qoinPro response message is "Success" than data will be added in AirdropActions Table @@ -136,14 +152,14 @@ public class KafkaConsumer { airdropActionsService.updateAirdropActions(accountId, airdropActionsList.get(0).getId(), kafkaMessageTemplate.getAction_type(), updateMap); } else { - /* System.out.println(""); - System.out.println("SignUp Action is already consumed. So, It won't be consumed again"); - System.out.println("");*/ + System.out.println(""); + System.out.println("" + Constants.KafkaActionType.JOIN + " Action is already consumed. So, It won't be consumed again"); + System.out.println(""); logger.info("" + Constants.KafkaActionType.JOIN + " Action is already consumed. So, It won't be consumed again"); } - } else if(notifiedQoinPro == false){ + } else if (notifiedQoinPro == false) { // Response of qoinPro message is not "Success" So, this notification would be added in ActionsFailed Table @@ -161,7 +177,7 @@ public class KafkaConsumer { actionsFailedService.addActionsFailed(actionsFailed); - }else{ + } else { logger.info("QoinPro API is not called"); } diff --git a/src/main/java/biz/nynja/airdrop/repository/OtpSessionsRepository.java b/src/main/java/biz/nynja/airdrop/repository/OtpSessionsRepository.java index e38559b..52fa119 100644 --- a/src/main/java/biz/nynja/airdrop/repository/OtpSessionsRepository.java +++ b/src/main/java/biz/nynja/airdrop/repository/OtpSessionsRepository.java @@ -28,6 +28,8 @@ public class OtpSessionsRepository { public OtpSessions getOtpSessions(UUID id) { Query query = Query.query(Criteria.where("id").is(id)); return (OtpSessions) cassandraTemplate.selectOne(query, ENTITY_CLASS); + + } public boolean updateOtpSessions(UUID id, UUID accountId, Map updateMap) { diff --git a/src/main/java/biz/nynja/airdrop/util/RestTemplateUtil.java b/src/main/java/biz/nynja/airdrop/util/RestTemplateUtil.java index d06aafc..4f0f387 100644 --- a/src/main/java/biz/nynja/airdrop/util/RestTemplateUtil.java +++ b/src/main/java/biz/nynja/airdrop/util/RestTemplateUtil.java @@ -7,10 +7,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; import org.springframework.stereotype.Component; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; @Component public class RestTemplateUtil { @@ -33,6 +35,26 @@ public class RestTemplateUtil { @Autowired private RestTemplate restTemplate; + + public Object exchangeRefreshToken(String refreshToken) { + + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8085/tokens/refresh") + .queryParam("refreshToken", refreshToken); + + Object response = restTemplate.exchange(builder.toString(), HttpMethod.GET, new HttpEntity<>(new HttpHeaders()), Object.class); + + System.out.println(""); + System.out.println("--------------------------------"); + System.out.println(""); + System.out.println("ExchangeRefreshToken Response : "); + System.out.println(response); + System.out.println(""); + System.out.println("--------------------------------"); + System.out.println(""); + + return response; + } + public String qoinProChannelEngagementAPI(String userId, String username, String actionType, String actionDescription) { MultiValueMap params = new LinkedMultiValueMap<>(5); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 0eed936..b760753 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -28,11 +28,11 @@ otp: # GRPC PROPERTIES grpc: accountService: - host: localhost - port: 6565 + host: 127.0.0.1 + port: 6566 authService: - host: localhost - port: 6565 + host: 127.0.0.1 + port: 6566 # REST PROPERTIES rest: -- GitLab From 6eac5a4b3ff699776e14186b95bc3bd7ec865ea6 Mon Sep 17 00:00:00 2001 From: jitender Date: Wed, 17 Jul 2019 10:01:54 +0530 Subject: [PATCH 2/2] fixed syntax issue with release files. --- releases/dev/airdrop-service.yaml | 2 +- releases/staging/airdrop-service.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/releases/dev/airdrop-service.yaml b/releases/dev/airdrop-service.yaml index f5140f1..84cce59 100644 --- a/releases/dev/airdrop-service.yaml +++ b/releases/dev/airdrop-service.yaml @@ -104,4 +104,4 @@ spec: failureThreshold: 10 initialDelaySeconds: 120 periodSeconds: 10 - timeoutSeconds: 10 \ No newline at end of file + timeoutSeconds: 10 diff --git a/releases/staging/airdrop-service.yaml b/releases/staging/airdrop-service.yaml index 86577e4..493d90b 100644 --- a/releases/staging/airdrop-service.yaml +++ b/releases/staging/airdrop-service.yaml @@ -104,4 +104,4 @@ spec: failureThreshold: 10 initialDelaySeconds: 120 periodSeconds: 10 - timeoutSeconds: 10 \ No newline at end of file + timeoutSeconds: 10 -- GitLab