Skip to content

Commit

Permalink
adding configuration for channel connector (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankita10r authored Apr 10, 2022
1 parent 98ac7a6 commit ff68731
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.json.JSONObject;
import org.mifos.connector.channel.camel.config.Client;
import org.mifos.connector.channel.camel.config.ClientProperties;
import org.mifos.connector.channel.camel.utils.AMSProps;
import org.mifos.connector.channel.camel.utils.AMSUtils;
import org.mifos.connector.channel.zeebe.ZeebeProcessStarter;
import org.mifos.connector.common.camel.AuthProcessor;
import org.mifos.connector.common.camel.AuthProperties;
Expand All @@ -25,6 +27,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
Expand Down Expand Up @@ -57,10 +60,15 @@
import static org.mifos.connector.common.mojaloop.type.TransactionRole.PAYER;

@Component

public class ChannelRouteBuilder extends ErrorHandlerRouteBuilder {


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

@Autowired
private AMSUtils amsUtils;

private String paymentTransferFlow;
private String specialPaymentTransferFlow;
private String transactionRequestFlow;
Expand All @@ -78,6 +86,7 @@ public class ChannelRouteBuilder extends ErrorHandlerRouteBuilder {
private RestTemplate restTemplate;
private String timer;


public ChannelRouteBuilder(@Value("#{'${dfspids}'.split(',')}") List<String> dfspIds,
@Value("${bpmn.flows.payment-transfer}") String paymentTransferFlow,
@Value("${bpmn.flows.special-payment-transfer}") String specialPaymentTransferFlow,
Expand Down Expand Up @@ -277,6 +286,8 @@ private void collectionRoutes(){
.to("bean-validator:request")
.process(exchange -> {

amsUtils.postConstruct();

Map<String, Object> extraVariables = new HashMap<>();
extraVariables.put("initiator", "PAYEE");
extraVariables.put("initiatorType", "BUSINESS");
Expand All @@ -287,34 +298,57 @@ private void collectionRoutes(){
throw new RuntimeException("Requested tenant " + tenantId + " not configured in the connector!");
}
extraVariables.put(TENANT_ID, tenantId);
String tenantSpecificBpmn;

String channelRequestBodyString = exchange.getIn().getBody(String.class);
JSONObject body = new JSONObject(channelRequestBodyString);
JSONArray payer = body.getJSONArray("payer");
String phoneNumber = "";
String accountId = "";
if (((JSONObject) payer.get(0)).getString("key").equals("MSISDN")) {
// case where 1st array element is MSISDN
phoneNumber = ((JSONObject) payer.get(0)).getString("value");
accountId = ((JSONObject) payer.get(1)).getString("value");
} else {
// case where 1st array element is ACCOUNTID
phoneNumber = ((JSONObject) payer.get(1)).getString("value");
accountId = ((JSONObject) payer.get(0)).getString("value");
String primaryIdentifierVal = "";
String secondaryIdentifierVal = "";
String primaryIdentifierName = "";
String secondaryIdentifierName = "";
String ams = "";
primaryIdentifierName= ((JSONObject) payer.get(0)).getString("key");
secondaryIdentifierName = ((JSONObject) payer.get(1)).getString("key");
primaryIdentifierVal = ((JSONObject) payer.get(0)).getString("value");
secondaryIdentifierVal = ((JSONObject) payer.get(1)).getString("value");
for ( AMSProps.AMS amsIdentifier : amsUtils.postConstruct()) {
String identifier = amsIdentifier.getIdentifier();
if (identifier.equalsIgnoreCase(secondaryIdentifierName)) {
ams = amsIdentifier.getValue();
break;
} else {
ams = amsIdentifier.getDefaultValue();
}
}//end for loop
for ( AMSProps.AMS amsIdentifier : amsUtils.postConstruct()) {
String identifier = amsIdentifier.getIdentifier();
if(identifier.equalsIgnoreCase(primaryIdentifierName)){
ams = amsIdentifier.getValue();
// logic to keep correct primary/secondary identifier for line 345-346
String temp = primaryIdentifierVal;
primaryIdentifierVal = secondaryIdentifierVal;
secondaryIdentifierVal = temp;
break;
}
else {
ams = amsIdentifier.getDefaultValue();
}

}
tenantSpecificBpmn = mpesaFlow.replace("{dfspid}", tenantId)
.replace("{ams}",ams);

String amount = body.getJSONObject("amount").getString("amount");

extraVariables.put("accountId", accountId);
extraVariables.put("phoneNumber", phoneNumber);
extraVariables.put("accountId", secondaryIdentifierVal);
extraVariables.put("phoneNumber", primaryIdentifierVal);
extraVariables.put("amount", amount);
extraVariables.put("isNotificationsSuccessEnabled", isNotificationSuccessServiceEnabled);
extraVariables.put("isNotificationsFailureEnabled", isNotificationFailureServiceEnabled);
extraVariables.put("timer",timer);


String tenantSpecificBpmn = mpesaFlow.replace("{dfspid}", tenantId);


String transactionId = zeebeProcessStarter.startMpesaZeebeWorkflow(tenantSpecificBpmn,
channelRequestBodyString,
extraVariables);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.mifos.connector.channel.camel.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
@ConfigurationProperties(prefix = "ams")
public class AMSProps {


private List<AMS> groups;


public List<AMS> getGroups() {
return groups;
}

public void setGroups(List<AMS> groups) {
this.groups = groups;
}
public static class AMS{
private String identifier;
private String value;

public String getIdentifier() {
return identifier;
}

public void setIdentifier(String identifier) {
this.identifier = identifier;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
public String getDefaultValue(){
String value = null;
if(getIdentifier().equals("default")){
value = getValue();
}
return value;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.mifos.connector.channel.camel.utils;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;


@Component
public class AMSUtils {

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

@Autowired
private AMSProps amsProps;

List<AMSProps.AMS> ams;

public AMSUtils(){
}

@PostConstruct
public List<AMSProps.AMS> postConstruct(){
ams = amsProps.getGroups();
return ams;
}


}




17 changes: 16 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,22 @@ bpmn:
gsma-link-based-payment: "gsma_link_transfer"
international-remittance-payee: "international-remittance-payee-process-{dfspid}"
international-remittance-payer: "international-remittance-payer-process-{dfspid}"
mpesa-flow: "mpesa_flow-{dfspid}"
mpesa-flow: "mpesa_flow-{ams}-{dfspid}"


ams:
groups:
-
identifier: "accountid"
value: "roster"
-
identifier: "foundationalid"
value: "paygops"
-
identifier: "default"
value : "paygops"



zeebe:
client:
Expand Down

0 comments on commit ff68731

Please sign in to comment.