Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ dependencies {
// miscellaneous dependency
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'org.json:json:20210307'
implementation 'org.mifos:ph-ee-connector-common:1.8.1-SNAPSHOT'
implementation 'org.mifos:ph-ee-connector-common:1.9.1-SNAPSHOT'
implementation 'org.apache.camel.springboot:camel-spring-boot-starter:3.4.0'
implementation 'org.apache.camel:camel-undertow:3.4.0'
implementation 'org.springframework.boot:spring-boot-starter:2.5.2'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package org.mifos.processor.bulk;


import org.mifos.connector.common.channel.dto.PhErrorDTO;
import org.mifos.connector.common.exception.PaymentHubErrorCategory;
import org.mifos.connector.common.validation.ValidatorBuilder;
import org.mifos.processor.bulk.BatchTransactionValidatorsEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import static org.mifos.connector.common.exception.PaymentHubError.ExtValidationError;

@Component
public class BatchTransactionValidator {

private static final String RESOURCE = "batchTransactionValidator";
private static final String REQUEST_ID = "requestId";
private static final int EXPECTED_REQUEST_ID_LENGTH = 15;
private static final String FILE_NAME = "fileName";
private static final String PURPOSE = "purpose";
private static final String TYPE = "type";
private static final String TENANT = "tenant";
private static final String REGISTERING_INSTITUTION_ID = "registeringInstitutionId";
private static final String PROGRAM_ID = "programId";
private static final String CALLBACK_URL = "callbackUrl";

public Logger logger = LoggerFactory.getLogger(this.getClass());

public PhErrorDTO validateBatchTransactions(String requestId, String fileName, String purpose, String type,
String tenant, String registeringInstitutionId, String programId, String callbackUrl) {
final ValidatorBuilder validatorBuilder = new ValidatorBuilder();
logger.info("Inside validation");

// Check for requestId
validatorBuilder.reset().resource(RESOURCE).parameter(REQUEST_ID).value(requestId)
.isNullWithFailureCode(BatchTransactionValidatorsEnum.INVALID_REQUEST_ID)
.validateFieldMaxLengthWithFailureCodeAndErrorParams(EXPECTED_REQUEST_ID_LENGTH,
BatchTransactionValidatorsEnum.INVALID_REQUEST_ID_LENGTH);

// Check for fileName (optional)
if (fileName != null) {
validatorBuilder.reset().resource(RESOURCE).parameter(FILE_NAME).value(fileName)
.validateFieldMaxLengthWithFailureCodeAndErrorParams(EXPECTED_REQUEST_ID_LENGTH,
BatchTransactionValidatorsEnum.INVALID_FILE_NAME_LENGTH);
}

// Check for purpose
validatorBuilder.reset().resource(RESOURCE).parameter(PURPOSE).value(purpose)
.isNullWithFailureCode(BatchTransactionValidatorsEnum.INVALID_PURPOSE);

// Check for type
validatorBuilder.reset().resource(RESOURCE).parameter(TYPE).value(type)
.isNullOrEmpty();

// Check for tenant
validatorBuilder.reset().resource(RESOURCE).parameter(TENANT).value(tenant)
.isNullWithFailureCode(BatchTransactionValidatorsEnum.INVALID_TENANT);

// Check for registeringInstitutionId (optional)
if (registeringInstitutionId != null) {
validatorBuilder.reset().resource(RESOURCE).parameter(REGISTERING_INSTITUTION_ID).value(registeringInstitutionId)
.validateFieldMaxLengthWithFailureCodeAndErrorParams(EXPECTED_REQUEST_ID_LENGTH,
BatchTransactionValidatorsEnum.INVALID_REGISTERING_INSTITUTION_ID_LENGTH);
}

// Check for programId (optional)
if (programId != null) {
validatorBuilder.reset().resource(RESOURCE).parameter(PROGRAM_ID).value(programId)
.validateFieldMaxLengthWithFailureCodeAndErrorParams(EXPECTED_REQUEST_ID_LENGTH,
BatchTransactionValidatorsEnum.INVALID_PROGRAM_ID_LENGTH);
}

// Check for callbackUrl (optional)
if (callbackUrl != null) {
validatorBuilder.reset().resource(RESOURCE).parameter(CALLBACK_URL).value(callbackUrl)
.isNullWithFailureCode(BatchTransactionValidatorsEnum.INVALID_CALLBACK_URL)
.validateFieldMaxLengthWithFailureCodeAndErrorParams(2048, BatchTransactionValidatorsEnum.INVALID_CALLBACK_URL);
}

// If errors exist, build and return PhErrorDTO
if (validatorBuilder.hasError()) {
logger.info("Found error");
validatorBuilder.errorCategory(PaymentHubErrorCategory.Validation.toString())
.errorCode(BatchTransactionValidatorsEnum.BATCH_TRANSACTION_VALIDATION_ERROR.getCode())
.errorDescription(BatchTransactionValidatorsEnum.BATCH_TRANSACTION_VALIDATION_ERROR.getMessage())
.developerMessage(BatchTransactionValidatorsEnum.BATCH_TRANSACTION_VALIDATION_ERROR.getMessage())
.defaultUserMessage(BatchTransactionValidatorsEnum.BATCH_TRANSACTION_VALIDATION_ERROR.getMessage());

PhErrorDTO.PhErrorDTOBuilder phErrorDTOBuilder = new PhErrorDTO.PhErrorDTOBuilder(ExtValidationError.getErrorCode());
phErrorDTOBuilder.fromValidatorBuilder(validatorBuilder);
return phErrorDTOBuilder.build();
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.mifos.processor.bulk;

import org.mifos.connector.common.exception.PaymentHubErrorCategory;
import org.mifos.connector.common.validation.ValidationCodeType;
import org.springframework.stereotype.Component;

public enum BatchTransactionValidatorsEnum implements ValidationCodeType {

BATCH_TRANSACTION_VALIDATION_ERROR("error.msg.batch.transaction.validation.errors", "Batch transaction validation failed"),
INVALID_REQUEST_ID("error.msg.schema.request.id.cannot.be.null.or.empty", "Request ID cannot be null or empty"),
INVALID_REQUEST_ID_LENGTH("error.msg.schema.request.id.length.is.invalid", "Request ID length is invalid"),
INVALID_FILE_NAME_LENGTH("error.msg.schema.file.name.length.is.invalid", "File name length is invalid"),
INVALID_PURPOSE("error.msg.schema.purpose.cannot.be.null.or.empty", "Purpose cannot be null or empty"),
INVALID_TYPE("error.msg.schema.type.cannot.be.null.or.empty", "Type cannot be null or empty"),
INVALID_TENANT("error.msg.schema.tenant.cannot.be.null.or.empty", "Tenant cannot be null or empty"),
INVALID_REGISTERING_INSTITUTION_ID_LENGTH("error.msg.schema.registering.institution.id.length.is.invalid", "Registering Institution ID length is invalid"),
INVALID_PROGRAM_ID_LENGTH("error.msg.schema.program.id.length.is.invalid", "Program ID length is invalid"),
INVALID_CALLBACK_URL("error.msg.schema.callback.url.cannot.be.null.or.empty", "Callback URL cannot be null or empty"),
INVALID_CALLBACK_URL_LENGTH("error.msg.schema.callback.url.length.is.invalid", "Callback URL length is invalid");

private final String code;
private final String category;
private final String message;

BatchTransactionValidatorsEnum(String code, String message) {
this.code = code;
this.category = PaymentHubErrorCategory.Validation.toString();
this.message = message;
}

public String getCode() {
return this.code;
}

public String getCategory() {
return this.category;
}

public String getMessage() {
return message;
}
}


232 changes: 116 additions & 116 deletions src/main/java/org/mifos/processor/bulk/kafka/Consumers.java
Original file line number Diff line number Diff line change
@@ -1,116 +1,116 @@
package org.mifos.processor.bulk.kafka;

import static org.mifos.connector.common.mojaloop.type.InitiatorType.CONSUMER;
import static org.mifos.connector.common.mojaloop.type.Scenario.TRANSFER;
import static org.mifos.connector.common.mojaloop.type.TransactionRole.PAYER;
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.BATCH_ID;
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.GSMA_CHANNEL_REQUEST;
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.INITIATOR_FSPID;
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.IS_RTP_REQUEST;
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.PARTY_ID;
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.PARTY_ID_TYPE;
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.PARTY_LOOKUP_FSPID;
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.TENANT_ID;
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.TRANSACTION_TYPE;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.HashMap;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.mifos.connector.common.channel.dto.TransactionChannelRequestDTO;
import org.mifos.connector.common.gsma.dto.GSMATransaction;
import org.mifos.connector.common.gsma.dto.GsmaParty;
import org.mifos.connector.common.mojaloop.dto.MoneyData;
import org.mifos.connector.common.mojaloop.dto.Party;
import org.mifos.connector.common.mojaloop.dto.PartyIdInfo;
import org.mifos.connector.common.mojaloop.dto.TransactionType;
import org.mifos.connector.common.mojaloop.type.IdentifierType;
import org.mifos.processor.bulk.schema.TransactionOlder;
import org.mifos.processor.bulk.zeebe.ZeebeProcessStarter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class Consumers {

@Value("${bpmn.flows.international-remittance-payer}")
private String internationalRemittancePayer;

@Autowired
private ObjectMapper objectMapper;

@Autowired
private ZeebeProcessStarter zeebeProcessStarter;

@KafkaListener(topics = "${kafka.topic.gsma.name}", groupId = "group_id")
public void listenTopicGsma(String message) throws JsonProcessingException {
log.debug("Received Message in topic GSMA and group group_id: {}", message);
TransactionOlder transaction = objectMapper.readValue(message, TransactionOlder.class);
String tenantId = "ibank-usa";

GSMATransaction gsmaChannelRequest = new GSMATransaction();
gsmaChannelRequest.setAmount(transaction.getAmount());
gsmaChannelRequest.setCurrency(transaction.getCurrency());
gsmaChannelRequest.setRequestingLei("ibank-usa");
gsmaChannelRequest.setReceivingLei("ibank-india");
GsmaParty creditParty = new GsmaParty();
creditParty.setKey("msisdn");
creditParty.setValue(transaction.getAccountNumber());
GsmaParty debitParty = new GsmaParty();
debitParty.setKey("msisdn");
debitParty.setValue(transaction.getAccountNumber());
gsmaChannelRequest.setCreditParty(new GsmaParty[] { creditParty });
gsmaChannelRequest.setDebitParty(new GsmaParty[] { debitParty });
// gsmaChannelRequest.setInternationalTransferInformation().setReceivingAmount(gsmaChannelRequest.getAmount());

TransactionChannelRequestDTO channelRequest = new TransactionChannelRequestDTO(); // Fineract Object
Party payee = new Party(new PartyIdInfo(IdentifierType.MSISDN, transaction.getAccountNumber()));
Party payer = new Party(new PartyIdInfo(IdentifierType.MSISDN, "7543010"));

MoneyData moneyData = new MoneyData();
moneyData.setAmount(transaction.getAmount());
moneyData.setCurrency(transaction.getCurrency());

channelRequest.setPayer(payer);
channelRequest.setPayee(payee);
channelRequest.setAmount(moneyData);

TransactionType transactionType = new TransactionType();
transactionType.setInitiator(PAYER);
transactionType.setInitiatorType(CONSUMER);
transactionType.setScenario(TRANSFER);

Map<String, Object> extraVariables = new HashMap<>();
extraVariables.put(IS_RTP_REQUEST, false);
extraVariables.put(TRANSACTION_TYPE, "inttransfer");
extraVariables.put(TENANT_ID, tenantId);

extraVariables.put(BATCH_ID, transaction.getBatchId());

String tenantSpecificBpmn = internationalRemittancePayer.replace("{dfspid}", tenantId);
channelRequest.setTransactionType(transactionType);

PartyIdInfo requestedParty = (boolean) extraVariables.get(IS_RTP_REQUEST) ? channelRequest.getPayer().getPartyIdInfo()
: channelRequest.getPayee().getPartyIdInfo();
extraVariables.put(PARTY_ID_TYPE, requestedParty.getPartyIdType());
extraVariables.put(PARTY_ID, requestedParty.getPartyIdentifier());

extraVariables.put(GSMA_CHANNEL_REQUEST, objectMapper.writeValueAsString(gsmaChannelRequest));
extraVariables.put(PARTY_LOOKUP_FSPID, gsmaChannelRequest.getReceivingLei());
extraVariables.put(INITIATOR_FSPID, gsmaChannelRequest.getRequestingLei());

String transactionId = zeebeProcessStarter.startZeebeWorkflow(tenantSpecificBpmn, objectMapper.writeValueAsString(channelRequest),
extraVariables);

log.debug("GSMA Transaction Started with:{} ", transactionId);
}

@KafkaListener(topics = "${kafka.topic.slcb.name}", groupId = "group_id")
public void listenTopicSlcb(String message) {
log.debug("Received Message in topic SLCB and group group_id:{} ", message);
}
}
//package org.mifos.processor.bulk.kafka;
//
//import static org.mifos.connector.common.mojaloop.type.InitiatorType.CONSUMER;
//import static org.mifos.connector.common.mojaloop.type.Scenario.TRANSFER;
//import static org.mifos.connector.common.mojaloop.type.TransactionRole.PAYER;
//import static org.mifos.processor.bulk.zeebe.ZeebeVariables.BATCH_ID;
//import static org.mifos.processor.bulk.zeebe.ZeebeVariables.GSMA_CHANNEL_REQUEST;
//import static org.mifos.processor.bulk.zeebe.ZeebeVariables.INITIATOR_FSPID;
//import static org.mifos.processor.bulk.zeebe.ZeebeVariables.IS_RTP_REQUEST;
//import static org.mifos.processor.bulk.zeebe.ZeebeVariables.PARTY_ID;
//import static org.mifos.processor.bulk.zeebe.ZeebeVariables.PARTY_ID_TYPE;
//import static org.mifos.processor.bulk.zeebe.ZeebeVariables.PARTY_LOOKUP_FSPID;
//import static org.mifos.processor.bulk.zeebe.ZeebeVariables.TENANT_ID;
//import static org.mifos.processor.bulk.zeebe.ZeebeVariables.TRANSACTION_TYPE;
//
//import com.fasterxml.jackson.core.JsonProcessingException;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import java.util.HashMap;
//import java.util.Map;
//import lombok.extern.slf4j.Slf4j;
//import org.mifos.connector.common.channel.dto.TransactionChannelRequestDTO;
//import org.mifos.connector.common.gsma.dto.GSMATransaction;
//import org.mifos.connector.common.gsma.dto.GsmaParty;
//import org.mifos.connector.common.mojaloop.dto.MoneyData;
//import org.mifos.connector.common.mojaloop.dto.Party;
//import org.mifos.connector.common.mojaloop.dto.PartyIdInfo;
//import org.mifos.connector.common.mojaloop.dto.TransactionType;
//import org.mifos.connector.common.mojaloop.type.IdentifierType;
//import org.mifos.processor.bulk.schema.TransactionOlder;
//import org.mifos.processor.bulk.zeebe.ZeebeProcessStarter;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.kafka.annotation.KafkaListener;
//import org.springframework.stereotype.Service;
//
//@Service
//@Slf4j
//public class Consumers {
//
// @Value("${bpmn.flows.international-remittance-payer}")
// private String internationalRemittancePayer;
//
// @Autowired
// private ObjectMapper objectMapper;
//
// @Autowired
// private ZeebeProcessStarter zeebeProcessStarter;
//
// @KafkaListener(topics = "${kafka.topic.gsma.name}", groupId = "group_id")
// public void listenTopicGsma(String message) throws JsonProcessingException {
// log.debug("Received Message in topic GSMA and group group_id: {}", message);
// TransactionOlder transaction = objectMapper.readValue(message, TransactionOlder.class);
// String tenantId = "ibank-usa";
//
// GSMATransaction gsmaChannelRequest = new GSMATransaction();
// gsmaChannelRequest.setAmount(transaction.getAmount());
// gsmaChannelRequest.setCurrency(transaction.getCurrency());
// gsmaChannelRequest.setRequestingLei("ibank-usa");
// gsmaChannelRequest.setReceivingLei("ibank-india");
// GsmaParty creditParty = new GsmaParty();
// creditParty.setKey("msisdn");
// creditParty.setValue(transaction.getAccountNumber());
// GsmaParty debitParty = new GsmaParty();
// debitParty.setKey("msisdn");
// debitParty.setValue(transaction.getAccountNumber());
// gsmaChannelRequest.setCreditParty(new GsmaParty[] { creditParty });
// gsmaChannelRequest.setDebitParty(new GsmaParty[] { debitParty });
// // gsmaChannelRequest.setInternationalTransferInformation().setReceivingAmount(gsmaChannelRequest.getAmount());
//
// TransactionChannelRequestDTO channelRequest = new TransactionChannelRequestDTO(); // Fineract Object
// Party payee = new Party(new PartyIdInfo(IdentifierType.MSISDN, transaction.getAccountNumber()));
// Party payer = new Party(new PartyIdInfo(IdentifierType.MSISDN, "7543010"));
//
// MoneyData moneyData = new MoneyData();
// moneyData.setAmount(transaction.getAmount());
// moneyData.setCurrency(transaction.getCurrency());
//
// channelRequest.setPayer(payer);
// channelRequest.setPayee(payee);
// channelRequest.setAmount(moneyData);
//
// TransactionType transactionType = new TransactionType();
// transactionType.setInitiator(PAYER);
// transactionType.setInitiatorType(CONSUMER);
// transactionType.setScenario(TRANSFER);
//
// Map<String, Object> extraVariables = new HashMap<>();
// extraVariables.put(IS_RTP_REQUEST, false);
// extraVariables.put(TRANSACTION_TYPE, "inttransfer");
// extraVariables.put(TENANT_ID, tenantId);
//
// extraVariables.put(BATCH_ID, transaction.getBatchId());
//
// String tenantSpecificBpmn = internationalRemittancePayer.replace("{dfspid}", tenantId);
// channelRequest.setTransactionType(transactionType);
//
// PartyIdInfo requestedParty = (boolean) extraVariables.get(IS_RTP_REQUEST) ? channelRequest.getPayer().getPartyIdInfo()
// : channelRequest.getPayee().getPartyIdInfo();
// extraVariables.put(PARTY_ID_TYPE, requestedParty.getPartyIdType());
// extraVariables.put(PARTY_ID, requestedParty.getPartyIdentifier());
//
// extraVariables.put(GSMA_CHANNEL_REQUEST, objectMapper.writeValueAsString(gsmaChannelRequest));
// extraVariables.put(PARTY_LOOKUP_FSPID, gsmaChannelRequest.getReceivingLei());
// extraVariables.put(INITIATOR_FSPID, gsmaChannelRequest.getRequestingLei());
//
// String transactionId = zeebeProcessStarter.startZeebeWorkflow(tenantSpecificBpmn, objectMapper.writeValueAsString(channelRequest),
// extraVariables);
//
// log.debug("GSMA Transaction Started with:{} ", transactionId);
// }
//
// @KafkaListener(topics = "${kafka.topic.slcb.name}", groupId = "group_id")
// public void listenTopicSlcb(String message) {
// log.debug("Received Message in topic SLCB and group group_id:{} ", message);
// }
//}
Loading