diff --git a/build.gradle b/build.gradle index 71b4d8fa..105a1607 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,8 @@ plugins { } repositories { - // mavenLocal() + mavenLocal() + maven { url = uri('https://repo.maven.apache.org/maven2') } @@ -21,7 +22,7 @@ repositories { } dependencies { - implementation 'org.mifos:ph-ee-connector-common:1.2.1-SNAPSHOT' + implementation 'org.mifos:ph-ee-connector-common:1.2.2-SNAPSHOT' implementation 'com.sun.xml.ws:jaxws-ri:2.3.2' implementation 'org.apache.camel.springboot:camel-spring-boot-starter:3.4.0' implementation 'org.apache.camel:camel-endpointdsl:3.4.0' diff --git a/src/main/java/org/mifos/connector/ams/interop/AmsCommonService.java b/src/main/java/org/mifos/connector/ams/interop/AmsCommonService.java index 70e8e032..47a497ba 100644 --- a/src/main/java/org/mifos/connector/ams/interop/AmsCommonService.java +++ b/src/main/java/org/mifos/connector/ams/interop/AmsCommonService.java @@ -20,6 +20,7 @@ import static org.apache.camel.Exchange.HTTP_PATH; import static org.mifos.connector.ams.camel.config.CamelProperties.TRANSFER_ACTION; import static org.mifos.connector.ams.camel.cxfrs.HeaderBasedInterceptor.CXF_TRACE_HEADER; +import static org.mifos.connector.ams.zeebe.ZeebeVariables.ACCOUNT_NUMBER; import static org.mifos.connector.ams.zeebe.ZeebeVariables.PARTY_ID; import static org.mifos.connector.ams.zeebe.ZeebeVariables.PARTY_ID_TYPE; import static org.mifos.connector.ams.zeebe.ZeebeVariables.TENANT_ID; @@ -37,6 +38,9 @@ public class AmsCommonService { @Value("${ams.local.interop.transfers-path}") private String amsInteropTransfersPath; + @Value("${ams.local.loan.repayment-path}") + private String amsLoanRepaymentPath; + @Autowired private TenantService tenantService; @@ -45,6 +49,7 @@ public class AmsCommonService { private Logger logger = LoggerFactory.getLogger(this.getClass()); + private static final String APPLICATION_TYPE = "application/json"; public void getLocalQuote(Exchange e) { Map headers = new HashMap<>(); headers.put(CXF_TRACE_HEADER, true); @@ -78,6 +83,17 @@ public void sendTransfer(Exchange e) { headers.putAll(tenantService.getHeaders(e.getProperty(TENANT_ID, String.class))); cxfrsUtil.sendInOut("cxfrs:bean:ams.local.interop", e, headers, e.getIn().getBody()); } + public void repayLoan(Exchange e) { + Map headers = new HashMap<>(); + headers.put(CXF_TRACE_HEADER, true); + headers.put(HTTP_METHOD, "POST"); + headers.put(HTTP_PATH, amsLoanRepaymentPath.replace("{accountNumber}", e.getProperty(ACCOUNT_NUMBER, String.class))); + logger.debug("Loan Repayment Body: {}", e.getIn().getBody()); + headers.put("Content-Type", APPLICATION_TYPE); + headers.putAll(tenantService.getHeaders(e.getProperty(TENANT_ID, String.class))); + cxfrsUtil.sendInOut("cxfrs:bean:ams.local.loan", e, headers, e.getIn().getBody()); + } + public void registerInteropIdentifier(Exchange e) { Map headers = new HashMap<>(); diff --git a/src/main/java/org/mifos/connector/ams/interop/AmsService.java b/src/main/java/org/mifos/connector/ams/interop/AmsService.java index 6ff1bc21..2fb721d4 100644 --- a/src/main/java/org/mifos/connector/ams/interop/AmsService.java +++ b/src/main/java/org/mifos/connector/ams/interop/AmsService.java @@ -16,6 +16,8 @@ public interface AmsService { void sendTransfer(Exchange e); + void repayLoan(Exchange e); + void login(Exchange e); void getSavingsAccount(Exchange e); @@ -29,7 +31,6 @@ public interface AmsService { void getClientByMobileNo(Exchange e); void getSavingsAccountsTransactions(Exchange e) ; - default void getClientImage(Exchange e){} } diff --git a/src/main/java/org/mifos/connector/ams/interop/InteroperationRouteBuilder.java b/src/main/java/org/mifos/connector/ams/interop/InteroperationRouteBuilder.java index f694bd1a..bc6d7779 100644 --- a/src/main/java/org/mifos/connector/ams/interop/InteroperationRouteBuilder.java +++ b/src/main/java/org/mifos/connector/ams/interop/InteroperationRouteBuilder.java @@ -10,9 +10,11 @@ import org.mifos.connector.ams.errorhandler.ErrorTranslator; import org.mifos.connector.ams.tenant.TenantNotExistException; import org.mifos.connector.ams.utils.Utils; +import org.mifos.connector.ams.zeebe.ZeebeUtil; import org.mifos.connector.common.ams.dto.ClientData; import org.mifos.connector.common.ams.dto.Customer; import org.mifos.connector.common.ams.dto.InteropAccountDTO; +import org.mifos.connector.common.ams.dto.LoanRepaymentDTO; import org.mifos.connector.common.ams.dto.LoginFineractCnResponseDTO; import org.mifos.connector.common.ams.dto.PartyFspResponseDTO; import org.mifos.connector.common.ams.dto.ProductDefinition; @@ -187,6 +189,21 @@ public void configure() { .process(transfersResponseProcessor) .end(); + from("direct:send-transfers-loan") + .id("send-transfers-loan") + .log(LoggingLevel.DEBUG, "Sending transfer with action: ${exchangeProperty." + TRANSFER_ACTION + "} " + + " for transaction: ${exchangeProperty." + TRANSACTION_ID + "}") + .log("Process type: ${exchangeProperty." + PROCESS_TYPE + "}") + .process(exchange -> { + LoanRepaymentDTO loanRepaymentDTO=ZeebeUtil.setLoanRepaymentBody(exchange); + String requestBody = objectMapper.writeValueAsString(loanRepaymentDTO); + logger.debug("Request Body : {}", requestBody); + exchange.getIn().setBody(requestBody); + exchange.setProperty("accountNumber",exchange.getProperty(ACCOUNT_NUMBER)); + }) + .process(amsService::repayLoan); + + from("direct:fincn-oauth") .id("fincn-oauth") .log(LoggingLevel.INFO, "Fineract CN oauth request for tenant: ${exchangeProperty." + TENANT_ID + "}") @@ -342,6 +359,5 @@ public void configure() { exchange.setProperty(PARTY_ID, transactionRequest.getPayee().getPartyIdInfo().getPartyIdentifier()); }) .to("direct:send-transfers"); - } } diff --git a/src/main/java/org/mifos/connector/ams/interop/PrepareTransferRequest.java b/src/main/java/org/mifos/connector/ams/interop/PrepareTransferRequest.java index 922003df..dffadadd 100644 --- a/src/main/java/org/mifos/connector/ams/interop/PrepareTransferRequest.java +++ b/src/main/java/org/mifos/connector/ams/interop/PrepareTransferRequest.java @@ -3,10 +3,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.camel.Exchange; import org.apache.camel.Processor; -import org.mifos.connector.ams.zeebe.ZeebeUtil; import org.mifos.connector.common.ams.dto.TransferFspRequestDTO; -import org.mifos.connector.common.mojaloop.dto.Extension; -import org.mifos.connector.common.mojaloop.dto.ExtensionList; import org.mifos.connector.common.mojaloop.dto.FspMoneyData; import org.mifos.connector.common.mojaloop.dto.TransactionType; import org.mifos.connector.common.mojaloop.type.InitiatorType; @@ -17,9 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; -import java.util.Map; import java.util.UUID; import static org.mifos.connector.ams.camel.config.CamelProperties.TRANSACTION_ROLE; @@ -75,22 +70,22 @@ public void process(Exchange exchange) throws Exception { if (fspFee != null || fspCommission != null) { transferRequestDTO = new TransferFspRequestDTO( - transactionCode, - transferCode, - exchange.getProperty(EXTERNAL_ACCOUNT_ID, String.class), - amount, - fspFee, - fspCommission, - TransactionRole.valueOf(exchange.getProperty(TRANSACTION_ROLE, String.class)), - transactionType, - note); + transactionCode, + transferCode, + exchange.getProperty(EXTERNAL_ACCOUNT_ID, String.class), + amount, + fspFee, + fspCommission, + TransactionRole.valueOf(exchange.getProperty(TRANSACTION_ROLE, String.class)), + transactionType, + note); } else { transferRequestDTO = new TransferFspRequestDTO( - transactionCode, - transferCode, - exchange.getProperty(EXTERNAL_ACCOUNT_ID, String.class), - amount, - TransactionRole.valueOf(exchange.getProperty(TRANSACTION_ROLE, String.class))); + transactionCode, + transferCode, + exchange.getProperty(EXTERNAL_ACCOUNT_ID, String.class), + amount, + TransactionRole.valueOf(exchange.getProperty(TRANSACTION_ROLE, String.class))); } logger.debug("prepared transferRequestDTO: {}", objectMapper.writeValueAsString(transferRequestDTO)); diff --git a/src/main/java/org/mifos/connector/ams/zeebe/ZeebeUtil.java b/src/main/java/org/mifos/connector/ams/zeebe/ZeebeUtil.java index 05b558d5..f548022c 100644 --- a/src/main/java/org/mifos/connector/ams/zeebe/ZeebeUtil.java +++ b/src/main/java/org/mifos/connector/ams/zeebe/ZeebeUtil.java @@ -1,19 +1,46 @@ package org.mifos.connector.ams.zeebe; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.camel.Exchange; -import org.json.JSONObject; +import org.mifos.connector.common.ams.dto.LoanRepaymentDTO; +import org.mifos.connector.common.channel.dto.TransactionChannelRequestDTO; +import org.mifos.connector.common.gsma.dto.CustomData; +import org.mifos.connector.common.gsma.dto.GsmaTransfer; +import org.mifos.connector.common.mojaloop.dto.*; +import org.mifos.connector.common.mojaloop.type.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; -import java.util.LinkedHashMap; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; import java.util.Map; +import java.util.UUID; +import static org.mifos.connector.ams.camel.config.CamelProperties.TRANSACTION_ROLE; +import static org.mifos.connector.ams.camel.config.CamelProperties.TRANSFER_ACTION; +import static org.mifos.connector.ams.zeebe.ZeebeVariables.ACCOUNT_IDENTIFIER; +import static org.mifos.connector.ams.zeebe.ZeebeVariables.ACCOUNT_NUMBER; +import static org.mifos.connector.ams.zeebe.ZeebeVariables.CHANNEL_REQUEST; +import static org.mifos.connector.ams.zeebe.ZeebeVariables.EXTERNAL_ACCOUNT_ID; +import static org.mifos.connector.ams.zeebe.ZeebeVariables.PARTY_ID; +import static org.mifos.connector.ams.zeebe.ZeebeVariables.PARTY_ID_TYPE; +import static org.mifos.connector.ams.zeebe.ZeebeVariables.REQUESTED_DATE; +import static org.mifos.connector.ams.zeebe.ZeebeVariables.TENANT_ID; +import static org.mifos.connector.ams.zeebe.ZeebeVariables.TRANSACTION_ID; +import static org.mifos.connector.common.ams.dto.TransferActionType.CREATE; +@Component public class ZeebeUtil { + private static Logger logger = LoggerFactory.getLogger(ZeebeUtil.class); private static ObjectMapper objectMapper = new ObjectMapper(); + @Value("#{'${accountPrefixes}'.split(',')}") + public List accountPrefixes; public static void zeebeVariablesToCamelProperties(Map variables, Exchange exchange, String... names) { exchange.setProperty("zeebeVariables", variables); @@ -34,9 +61,114 @@ public static Map zeebeVariablesFrom(Exchange exchange) { public static T zeebeVariable(Exchange exchange, String name, Class clazz) throws Exception { Object content = zeebeVariablesFrom(exchange).get(name); - if (content instanceof Map){ + if (content instanceof Map) { return objectMapper.readValue(objectMapper.writeValueAsString(content), clazz); } return (T) content; } + + public static String getCurrentDate(String requestedDate,String dateFormat) { + LocalDateTime datetime = LocalDateTime.parse(requestedDate, DateTimeFormatter.ofPattern(dateFormat)); + return datetime.format(DateTimeFormatter.ofPattern(dateFormat)); + } + + public static LoanRepaymentDTO setLoanRepaymentBody(Exchange exchange) { + String dateFormat = "dd MMMM yyyy"; + LoanRepaymentDTO loanRepaymentDTO = new LoanRepaymentDTO(); + loanRepaymentDTO.setDateFormat(dateFormat); + loanRepaymentDTO.setLocale("en"); + loanRepaymentDTO.setTransactionAmount(exchange.getProperty("amount").toString()); + String currDate = getCurrentDate(exchange.getProperty("requestedDate").toString(),dateFormat); + loanRepaymentDTO.setTransactionDate(currDate); + return loanRepaymentDTO; + } + + public static void setZeebeVariables(Exchange e, Map variables, String requestDate, String accountHoldingInstitutionId, String transactionChannelRequestDTO) { + variables.put(ACCOUNT_IDENTIFIER,e.getProperty(ACCOUNT_IDENTIFIER)); + variables.put(ACCOUNT_NUMBER,e.getProperty(ACCOUNT_NUMBER)); + variables.put(TRANSACTION_ID, UUID.randomUUID().toString()); + variables.put(TENANT_ID,accountHoldingInstitutionId); + variables.put(TRANSFER_ACTION,CREATE.name()); + variables.put(CHANNEL_REQUEST,transactionChannelRequestDTO); + variables.put(REQUESTED_DATE,requestDate); + variables.put(EXTERNAL_ACCOUNT_ID,e.getProperty(ACCOUNT_NUMBER)); + variables.put("payeeTenantId", accountHoldingInstitutionId); + } + + public static void setZeebeVariablesLoanWorker(Map variables, TransactionChannelRequestDTO transactionRequest) { + TransactionType transactionType = new TransactionType(); + transactionType.setInitiator(TransactionRole.PAYEE); + transactionType.setInitiatorType(InitiatorType.CONSUMER); + transactionType.setScenario(Scenario.PAYMENT); + transactionRequest.setTransactionType(transactionType); + variables.put("initiator", transactionType.getInitiator().name()); + variables.put("initiatorType", transactionType.getInitiatorType().name()); + variables.put("scenario", transactionType.getScenario().name()); + variables.put("amount", new FspMoneyData(transactionRequest.getAmount().getAmountDecimal(), + transactionRequest.getAmount().getCurrency())); + variables.put("processType", "api"); + } + + public static void setExchangePropertyLoan(Exchange ex, String partyId, String partyIdType, TransactionChannelRequestDTO transactionRequest, Map existingVariables) throws JsonProcessingException { + ex.setProperty(PARTY_ID_TYPE, partyIdType); + ex.setProperty(PARTY_ID, partyId); + + ex.setProperty(CHANNEL_REQUEST, objectMapper.writeValueAsString(transactionRequest)); + ex.setProperty(TRANSACTION_ROLE, TransactionRole.PAYEE.name()); + ex.setProperty("amount",transactionRequest.getAmount().getAmountDecimal()); + ex.setProperty(ACCOUNT_NUMBER,existingVariables.get(ACCOUNT_NUMBER)); + ex.setProperty(EXTERNAL_ACCOUNT_ID,"L"); + ex.setProperty(REQUESTED_DATE,existingVariables.get("requestedDate")); + } + + public Exchange setAccountTypeAndNumber(Exchange e, String accountNo) { + String accountTypeIdentifier = ""; + String accountNumber = ""; + int accountNoLength = accountNo.length(); + // Separating account id and prefix + for (String accountPrefix : accountPrefixes) { + if (accountNo.startsWith(accountPrefix)) { + accountNumber = accountNo.substring(accountPrefix.length(), accountNoLength); + accountTypeIdentifier = accountNo.substring(0, accountPrefix.length()); + break; + } + } + logger.debug("Accout number:{}, Identifier:{}", accountNumber, accountTypeIdentifier); + e.setProperty(ACCOUNT_NUMBER, accountNumber); + e.setProperty(ACCOUNT_IDENTIFIER, accountTypeIdentifier); + return e; + } + + public static String getValueofKey(List customData, String key) { + for (CustomData obj : customData) { + String keyString = obj.getKey(); + if (keyString.equalsIgnoreCase(key)) { + return obj.getValue().toString(); + } + } + return null; + } + + public static String convertGsmaTransfertoTransactionChannel(GsmaTransfer gsmaTransfer, Object property) throws JsonProcessingException { + TransactionChannelRequestDTO transactionChannelRequestDTO = new TransactionChannelRequestDTO(); + String msisdn = gsmaTransfer.getPayer().get(0).getPartyIdIdentifier(); + String accountId = property.toString(); + + String amount = gsmaTransfer.getAmount().trim(); + List customData = gsmaTransfer.getCustomData(); + String currency = gsmaTransfer.getCurrency(); + + PartyIdInfo partyIdInfopayee = new PartyIdInfo(IdentifierType.ACCOUNT_ID, accountId); + PartyIdInfo partyIdInfopayer = new PartyIdInfo(IdentifierType.MSISDN, msisdn); + Party partyPayee = new Party(partyIdInfopayee); + Party partyPayer = new Party(partyIdInfopayer); + + MoneyData moneyData = new MoneyData(amount, currency); + + transactionChannelRequestDTO.setAmount(moneyData); + transactionChannelRequestDTO.setPayee(partyPayee); + transactionChannelRequestDTO.setPayer(partyPayer); + + return objectMapper.writeValueAsString(transactionChannelRequestDTO); + } } diff --git a/src/main/java/org/mifos/connector/ams/zeebe/ZeebeVariables.java b/src/main/java/org/mifos/connector/ams/zeebe/ZeebeVariables.java index 600e2514..138b4941 100644 --- a/src/main/java/org/mifos/connector/ams/zeebe/ZeebeVariables.java +++ b/src/main/java/org/mifos/connector/ams/zeebe/ZeebeVariables.java @@ -32,11 +32,14 @@ public class ZeebeVariables { public static final String TRANSFER_PREPARE_FAILED = "transferPrepareFailed"; public static final String TRANSFER_RELEASE_FAILED = "transferReleaseFailed"; public static final String TRANSFER_RESPONSE_PREFIX = "transferResponse"; + public static final String ACCOUNT_IDENTIFIER="accountIdentifier"; + public static final String ACCOUNT_NUMBER="accountNumber"; public static final String ERROR_CODE = "errorCode"; public static final String ERROR_PAYLOAD = "errorPayload"; public static final String IS_ERROR_HANDLED = "isErrorHandled"; public static final String NOTE = "note"; + public static final String REQUESTED_DATE = "requestedDate"; static { ACTION_FAILURE_MAP.put(TransferActionType.PREPARE.name(), TRANSFER_PREPARE_FAILED); diff --git a/src/main/java/org/mifos/connector/ams/zeebe/ZeebeeWorkers.java b/src/main/java/org/mifos/connector/ams/zeebe/ZeebeeWorkers.java index d0f6e899..5723c88f 100644 --- a/src/main/java/org/mifos/connector/ams/zeebe/ZeebeeWorkers.java +++ b/src/main/java/org/mifos/connector/ams/zeebe/ZeebeeWorkers.java @@ -11,6 +11,7 @@ import org.mifos.connector.ams.properties.TenantProperties; import org.mifos.connector.common.ams.dto.QuoteFspResponseDTO; import org.mifos.connector.common.channel.dto.TransactionChannelRequestDTO; +import org.mifos.connector.common.gsma.dto.GsmaTransfer; import org.mifos.connector.common.mojaloop.dto.FspMoneyData; import org.mifos.connector.common.mojaloop.dto.MoneyData; import org.mifos.connector.common.mojaloop.dto.Party; @@ -33,15 +34,19 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; import static org.mifos.connector.ams.camel.config.CamelProperties.*; import static org.mifos.connector.ams.zeebe.ZeebeUtil.zeebeVariable; import static org.mifos.connector.ams.zeebe.ZeebeUtil.zeebeVariablesToCamelProperties; import static org.mifos.connector.ams.zeebe.ZeebeVariables.ACCOUNT; import static org.mifos.connector.ams.zeebe.ZeebeVariables.ACCOUNT_CURRENCY; +import static org.mifos.connector.ams.zeebe.ZeebeVariables.ACCOUNT_IDENTIFIER; +import static org.mifos.connector.ams.zeebe.ZeebeVariables.ACCOUNT_NUMBER; import static org.mifos.connector.ams.zeebe.ZeebeVariables.BOOK_TRANSACTION_ID; import static org.mifos.connector.ams.zeebe.ZeebeVariables.CHANNEL_REQUEST; import static org.mifos.connector.ams.zeebe.ZeebeVariables.EXTERNAL_ACCOUNT_ID; +import static org.mifos.connector.ams.zeebe.ZeebeVariables.INTEROP_REGISTRATION_FAILED; import static org.mifos.connector.ams.zeebe.ZeebeVariables.LOCAL_QUOTE_FAILED; import static org.mifos.connector.ams.zeebe.ZeebeVariables.LOCAL_QUOTE_RESPONSE; import static org.mifos.connector.ams.zeebe.ZeebeVariables.PARTY_ID; @@ -50,6 +55,7 @@ import static org.mifos.connector.ams.zeebe.ZeebeVariables.QUOTE_FAILED; import static org.mifos.connector.ams.zeebe.ZeebeVariables.QUOTE_SWITCH_REQUEST; import static org.mifos.connector.ams.zeebe.ZeebeVariables.QUOTE_SWITCH_REQUEST_AMOUNT; +import static org.mifos.connector.ams.zeebe.ZeebeVariables.REQUESTED_DATE; import static org.mifos.connector.ams.zeebe.ZeebeVariables.TENANT_ID; import static org.mifos.connector.ams.zeebe.ZeebeVariables.TRANSACTION_ID; import static org.mifos.connector.ams.zeebe.ZeebeVariables.TRANSFER_CODE; @@ -68,6 +74,8 @@ public class ZeebeeWorkers { public static final String WORKER_PAYER_LOCAL_QUOTE = "payer-local-quote-"; public static final String WORKER_INTEROP_PARTY_REGISTRATION = "interop-party-registration-"; public static final String WORKER_PAYEE_DEPOSIT_TRANSFER = "payee-deposit-transfer-"; + public static final String WORKER_PAYEE_LOAN_TRANSFER = "payee-loan-transfer-"; + public static final String WORKER_ACCOUNT_IDENTIFIER = "account-identifier-"; private Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -80,6 +88,9 @@ public class ZeebeeWorkers { @Autowired private CamelContext camelContext; + @Autowired + private ZeebeUtil zeebeUtil; + @Autowired private ObjectMapper objectMapper; @@ -124,7 +135,7 @@ public void setupWorkers() { ex.setProperty(ZEEBE_JOB_KEY, job.getKey()); ex.setProperty(TRANSACTION_ROLE, TransactionRole.PAYER.name()); ex.setProperty("payeeTenantId", job.getVariablesAsMap().get("payeeTenantId")); - logger.info("Payee Id before block funds {}",job.getVariablesAsMap().get("payeeTenantId")); + logger.debug("Payee Id before block funds {}", job.getVariablesAsMap().get("payeeTenantId")); producerTemplate.send("direct:send-transfers", ex); logger.info("Zeebe variable {}", job.getVariablesAsMap()); } else { @@ -346,13 +357,12 @@ public void setupWorkers() { ex.setProperty(PARTY_ID_TYPE, partyIdType); ex.setProperty(PARTY_ID, partyId); ex.setProperty(ZEEBE_JOB_KEY, job.getKey()); - if(dfspid.equalsIgnoreCase(existingVariables.get("payeeTenantId").toString())) - { + if (dfspid.equalsIgnoreCase(existingVariables.get("payeeTenantId").toString())) { ex.setProperty(TENANT_ID, existingVariables.get("payeeTenantId")); + } else { + ex.setProperty(TENANT_ID, tenantId); } - else { - ex.setProperty(TENANT_ID, tenantId);} - ex.setProperty("payeeTenantId",existingVariables.get("payeeTenantId")); + ex.setProperty("payeeTenantId", existingVariables.get("payeeTenantId")); producerTemplate.send("direct:get-party", ex); @@ -379,7 +389,7 @@ public void setupWorkers() { null); variables.put(PAYEE_PARTY_RESPONSE, objectMapper.writeValueAsString(party)); - variables.put("payeeTenantId",existingVariables.get("payeeTenantId")); + variables.put("payeeTenantId", existingVariables.get("payeeTenantId")); client.newCompleteCommand(job.getKey()) .variables(variables) .send() @@ -448,7 +458,7 @@ public void setupWorkers() { EXTERNAL_ACCOUNT_ID, CHANNEL_REQUEST); ex.setProperty(TRANSFER_ACTION, CREATE.name()); - ex.setProperty("payeeTenantId",existingVariables.get("payeeTenantId")); + ex.setProperty("payeeTenantId", existingVariables.get("payeeTenantId")); ex.setProperty(ZEEBE_JOB_KEY, job.getKey()); TransactionChannelRequestDTO transactionRequest = objectMapper.readValue((String) variables.get(CHANNEL_REQUEST), TransactionChannelRequestDTO.class); @@ -475,7 +485,7 @@ public void setupWorkers() { ex.setProperty(TRANSACTION_ROLE, TransactionRole.PAYEE.name()); producerTemplate.send("direct:send-transfers", ex); variables.put("transferCreateFailed", false); - variables.put("payeeTenantId",existingVariables.get("payeeTenantId")); + variables.put("payeeTenantId", existingVariables.get("payeeTenantId")); zeebeClient.newCompleteCommand(job.getKey()) .variables(variables) .send(); @@ -490,9 +500,93 @@ public void setupWorkers() { .name(WORKER_PAYEE_DEPOSIT_TRANSFER + dfspid) .maxJobsActive(workerMaxJobs) .open(); + + logger.info("## generating {}" + "{} worker",WORKER_PAYEE_LOAN_TRANSFER, dfspid); + zeebeClient.newWorker() + .jobType(WORKER_PAYEE_LOAN_TRANSFER + dfspid) + .handler((client, job) -> { + logWorkerDetails(job); + Map existingVariables = job.getVariablesAsMap(); + logger.debug("Exisiting variables {}", existingVariables); + + String tenantId = (String) existingVariables.get(TENANT_ID); + + if (isAmsLocalEnabled) { + Exchange ex = new DefaultExchange(camelContext); + Map variables = job.getVariablesAsMap(); + zeebeVariablesToCamelProperties(variables, ex, + TRANSACTION_ID, + TENANT_ID, + CHANNEL_REQUEST); + ex.setProperty(TRANSFER_ACTION, CREATE.name()); + ex.setProperty("payeeTenantId", existingVariables.get("payeeTenantId")); + ex.setProperty(ZEEBE_JOB_KEY, job.getKey()); + + TransactionChannelRequestDTO transactionRequest = objectMapper.readValue((String) variables.get(CHANNEL_REQUEST), TransactionChannelRequestDTO.class); + + ZeebeUtil.setZeebeVariablesLoanWorker(variables,transactionRequest); + + String partyIdType = transactionRequest.getPayee().getPartyIdInfo().getPartyIdType().name(); + String partyId = transactionRequest.getPayee().getPartyIdInfo().getPartyIdentifier(); + + ZeebeUtil.setExchangePropertyLoan(ex,partyId,partyIdType,transactionRequest,existingVariables); + + producerTemplate.send("direct:send-transfers-loan", ex); + variables.put("transferCreateFailed", false); + variables.put("payeeTenantId", existingVariables.get("payeeTenantId")); + zeebeClient.newCompleteCommand(job.getKey()) + .variables(variables) + .send(); + } else { + Map variables = new HashMap<>(); + variables.put("transferCreateFailed", false); + zeebeClient.newCompleteCommand(job.getKey()) + .variables(variables) + .send(); + } + }) + .name(WORKER_PAYEE_LOAN_TRANSFER + dfspid) + .maxJobsActive(workerMaxJobs) + .open(); + + logger.info("## generating " + WORKER_ACCOUNT_IDENTIFIER + "{} worker", dfspid); + zeebeClient.newWorker() + .jobType(WORKER_ACCOUNT_IDENTIFIER + dfspid) + .handler((client, job) -> { + logWorkerDetails(job); + Map existingVariables = job.getVariablesAsMap(); + logger.debug("Exisiting variables {}", existingVariables); + String accountHoldingInstitutionId = (String) existingVariables.get(TENANT_ID); + if (isAmsLocalEnabled) { + Exchange ex = new DefaultExchange(camelContext); + Map variables = job.getVariablesAsMap(); + GsmaTransfer gsmaTransfer = objectMapper.readValue((String) variables.get(CHANNEL_REQUEST), GsmaTransfer.class); + logger.debug("GSMA Transfer Body:{}",gsmaTransfer); + String accountNo = gsmaTransfer.getPayee().get(0).getPartyIdIdentifier(); + Exchange e = zeebeUtil.setAccountTypeAndNumber(ex, accountNo); + String transactionChannelRequestDTO = ZeebeUtil.convertGsmaTransfertoTransactionChannel(gsmaTransfer,e.getProperty(ACCOUNT_NUMBER)); + logger.debug("Transaction Channel Request DTO:{}",transactionChannelRequestDTO); + logger.debug("Account Identifier:{}",ACCOUNT_IDENTIFIER); + + ZeebeUtil.setZeebeVariables(e,variables,gsmaTransfer.getRequestDate(),accountHoldingInstitutionId,transactionChannelRequestDTO); + + zeebeClient.newCompleteCommand(job.getKey()) + .variables(variables) + .send(); + } else { + Map variables = new HashMap<>(); + variables.put("accountIdentificationFailed", true); + zeebeClient.newCompleteCommand(job.getKey()) + .variables(variables) + .send(); + } + }) + .name(WORKER_ACCOUNT_IDENTIFIER + dfspid) + .maxJobsActive(workerMaxJobs) + .open(); } } - } + } private void logWorkerDetails(ActivatedJob job) { JSONObject jsonJob = new JSONObject(); diff --git a/src/main/resources/application-bb.yml b/src/main/resources/application-bb.yml index f92d3fdb..7e9bc196 100644 --- a/src/main/resources/application-bb.yml +++ b/src/main/resources/application-bb.yml @@ -19,3 +19,6 @@ ams: password: password authtype: basic fspId: in02tn04 + +# Savings : S , Loan : L +accountPrefixes: "S,L" \ No newline at end of file diff --git a/src/main/resources/application-fin12.yml b/src/main/resources/application-fin12.yml index f93723ea..d338315a 100644 --- a/src/main/resources/application-fin12.yml +++ b/src/main/resources/application-fin12.yml @@ -36,3 +36,10 @@ ams: savingsaccounts-path: ${ams.local.account.base-url}/savingsaccounts auth: host: https://localhost:8443 + loan: + host: https://localhost:8443 + repayment-path: /fineract-provider/api/v1/interoperation/transactions/{accountNumber}/loanrepayment + + +# Savings : S , Loan : L +accountPrefixes: "S,L" \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 87ff2277..e2f65efb 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -18,6 +18,11 @@ zeebe: broker: contactpoint: "127.0.0.1:26500" +#ams: +# local: +# server-cert-check: false +# enabled: true + ams: local: server-cert-check: false diff --git a/src/main/resources/endpoints.xml b/src/main/resources/endpoints.xml index c74b261c..53a23d3f 100644 --- a/src/main/resources/endpoints.xml +++ b/src/main/resources/endpoints.xml @@ -70,6 +70,16 @@ + + + + + + + + + +