webclient + deposit account balance fetched from ciihive

Nabeel-DG-BS
Raja Nabeel 2 years ago
parent d042a6035a
commit 06f486bc85

@ -0,0 +1,5 @@
package com.mfsys.uco.constants;
public interface UCOURI {
String GET_UCOACC_BALANCE = "/deposit/getUcoAccountBalance";
}

@ -11,5 +11,4 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
public class TransactionPinResponseModel {
private double otdTranrequestid;
private String pinCode;
}

@ -3,8 +3,11 @@ package com.mfsys.uco.repository;
import com.mfsys.uco.model.CustomerProfile;
import com.mfsys.uco.model.CustomerProfileId;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
@Repository
public interface CustomerProfileRepository extends JpaRepository<CustomerProfile, CustomerProfileId> {
@Query("SELECT c FROM BN_CS_MP_CUSTOMERPROFILE c WHERE c.porOrgacode =:porOrgacode and c.padAdrsmobphone = :phone")
CustomerProfile findProfilesByMobilePhone(String porOrgacode,String phone);
}

@ -0,0 +1,16 @@
package com.mfsys.uco.repository;
import com.mfsys.uco.model.AccountId;
import com.mfsys.uco.model.CustomerProfile;
import com.mfsys.uco.model.CustomerProfileId;
import com.mfsys.uco.model.UcoAccount;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
@Repository
public interface UCOAccountRepository extends JpaRepository<UcoAccount, AccountId> {
@Query("SELECT c FROM BN_MS_UC_UCOACCOUNT c WHERE c.id.porOrgacode =:porOrgacode and c.cmpCustcode = :cmpCustcode")
UcoAccount findUcoAccountByCmpCustcode(String porOrgacode,String cmpCustcode);
}

@ -0,0 +1,9 @@
package com.mfsys.uco.service;
import org.springframework.stereotype.Service;
@Service
public class TransactionService {
}

@ -0,0 +1,44 @@
package com.mfsys.uco.service;
import com.mfsys.uco.constants.UCOURI;
import com.mfsys.uco.model.CustomerProfile;
import com.mfsys.uco.repository.CustomerProfileRepository;
import com.mfsys.uco.repository.UCOAccountRepository;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import java.math.BigDecimal;
import java.util.Map;
@Service
public class UcoAccountService {
private final CustomerProfileRepository customerProfileRepository;
private final UCOAccountRepository ucoAccountRepository;
private final WebClientDepositService webClientDeposit;
public UcoAccountService(CustomerProfileRepository customerProfileRepository, UCOAccountRepository ucoAccountRepository, WebClientDepositService webClientDeposit) {
this.customerProfileRepository = customerProfileRepository;
this.ucoAccountRepository = ucoAccountRepository;
this.webClientDeposit = webClientDeposit;
}
public String fetchAccountTitile(String porOrgacode, String acntTypeCode, String acntTypeValue){
if(acntTypeCode.equals("01")){
CustomerProfile customerProfile = customerProfileRepository.findProfilesByMobilePhone(porOrgacode,acntTypeValue);
return ucoAccountRepository.findUcoAccountByCmpCustcode(porOrgacode,customerProfile.getCmpCustcode()).getMbmBkmstitle();
}
return null;
}
public Double fetchAccountBalance(String porOrgacode, String mbmBkmsNumber) {
return (Double) getIndvAccountDetails(porOrgacode,mbmBkmsNumber);
}
public Object getIndvAccountDetails(String porOrgacode, String mbmBkmsnumber) {
String url= UCOURI.GET_UCOACC_BALANCE+"?porOrgacode="+porOrgacode+"&mbmBkmsnumber="+mbmBkmsnumber;
return webClientDeposit.getUcoAccountBalance(url,porOrgacode);
}
}

@ -0,0 +1,64 @@
package com.mfsys.uco.service;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mfsys.comm.exception.ApplicationException;
import com.mfsys.comm.exception.ApplicationExceptionMapper;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import reactor.core.publisher.Mono;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@Service
public class WebClientDepositService {
private final WebClient webClientDeposit;
public WebClientDepositService(WebClient webClientDeposit) {
this.webClientDeposit = webClientDeposit;
}
public Object getUcoAccountBalance(String url,String porOrgacode) {
return handleResponse(webClientDeposit.get().uri(url).accept(MediaType.APPLICATION_JSON)
.header("SUS_USERCODE", porOrgacode)
.header("POR_ORGACODE", porOrgacode).retrieve().toEntity(Object.class),
null);
}
private <T> T handleResponse(Mono<ResponseEntity<T>> responseMono, String porgaCode) {
try {
ResponseEntity<T> response = responseMono.block();
return response.getBody();
} catch (WebClientResponseException e) {
ApplicationExceptionMapper.APIError errorDetails = parseErrorDetails(e);
throw new ApplicationException(porgaCode,errorDetails.getErrorCode(),errorDetails.getArguments());
}
}
private ApplicationExceptionMapper.APIError parseErrorDetails(WebClientResponseException e) {
String errorCode = null;
List<String> arguments = null;
if (e.getResponseBodyAsString() != null) {
try {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode errorNode = objectMapper.readTree(e.getResponseBodyAsString());
errorCode = errorNode.get("errorCode").asText();
arguments = Arrays.asList(objectMapper.convertValue(errorNode.get("arguments"), String[].class));
} catch (IOException ex) {
}
}
return new ApplicationExceptionMapper.APIError(errorCode, arguments.toArray());
}
}
Loading…
Cancel
Save