Skip to content

Commit

Permalink
Merge pull request #15 from ankita10r/newZeebeWorker
Browse files Browse the repository at this point in the history
Adding intl remittance worker,logs and updating the tenants
  • Loading branch information
fynmanoj authored Oct 17, 2022
2 parents b614507 + e5c188b commit d5ab3b3
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 24 deletions.
Binary file added .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

import static org.mifos.connector.ams.camel.config.CamelProperties.CLIENT_ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.apache.camel.component.cxf.common.message.CxfConstants;
import org.mifos.connector.ams.camel.cxfrs.CxfrsUtil;
import org.mifos.connector.ams.tenant.TenantService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
Expand Down Expand Up @@ -41,6 +43,8 @@ public class AmsCommonService {
@Autowired
private CxfrsUtil cxfrsUtil;

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

public void getLocalQuote(Exchange e) {
Map<String, Object> headers = new HashMap<>();
headers.put(CXF_TRACE_HEADER, true);
Expand All @@ -66,7 +70,7 @@ public void sendTransfer(Exchange e) {
headers.put(CXF_TRACE_HEADER, true);
headers.put(HTTP_METHOD, "POST");
headers.put(HTTP_PATH, amsInteropTransfersPath);

logger.info("Send Transfer Body: {}", e.getIn().getBody());
Map<String, String> queryMap = new LinkedHashMap<>();
queryMap.put("action", e.getProperty(TRANSFER_ACTION, String.class));
headers.put(CxfConstants.CAMEL_CXF_RS_QUERY_MAP, queryMap);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/mifos/connector/ams/interop/AmsService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.mifos.connector.ams.interop;

import org.apache.camel.Exchange;
import org.springframework.stereotype.Service;

@Service
public interface AmsService {

void getLocalQuote(Exchange e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public void configure() {
.log(LoggingLevel.INFO, "Get externalAccount with identifierType: ${exchangeProperty." + PARTY_ID_TYPE + "} with value: ${exchangeProperty."
+ PARTY_ID + "}")
.process(amsService::getExternalAccount)
.log("Test 1: ${body}")
.unmarshal().json(JsonLibrary.Jackson, PartyFspResponseDTO.class)
.process(e -> e.setProperty(EXTERNAL_ACCOUNT_ID, e.getIn().getBody(PartyFspResponseDTO.class).getAccountId()));

Expand All @@ -123,6 +124,7 @@ public void configure() {
.process(prepareTransferRequest)
.process(pojoToString)
.process(amsService::sendTransfer)
.log("Process type: ${exchangeProperty." + PROCESS_TYPE + "}")
.choice()
.when(exchange -> exchange.getProperty(PROCESS_TYPE)!=null && exchange.getProperty(PROCESS_TYPE).equals("api"))
.process(exchange -> {
Expand All @@ -144,8 +146,18 @@ public void configure() {

logger.error(errorMsg);
} else {
Map<String, Object> variables = new HashMap<>();
JSONObject responseJson = new JSONObject(exchange.getIn().getBody(String.class));
variables.put(TRANSFER_PREPARE_FAILED,false);
variables.put(TRANSFER_CREATE_FAILED,false);
variables.put("payeeTenantId", exchange.getProperty("payeeTenantId"));
variables.put(TRANSFER_CODE,responseJson.getString("transferCode"));
logger.info("API call successful. Response Body: " + exchange.getIn().getBody(String.class));
zeebeClient.newCompleteCommand(exchange.getProperty(ZEEBE_JOB_KEY, Long.class))
.variables(variables)
.send();
}
logger.info("End of process in send-transfers");
})
.otherwise()
.process(transfersResponseProcessor)
Expand Down Expand Up @@ -303,4 +315,4 @@ public void configure() {
.to("direct:send-transfers");

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ public class PrepareTransferRequest implements Processor {

@Override
public void process(Exchange exchange) throws Exception {
String initiator = zeebeVariable(exchange, "initiator", String.class);
String initiatorType = zeebeVariable(exchange, "initiatorType", String.class);
String scenario = zeebeVariable(exchange, "scenario", String.class);

logger.info("Preparing transfer request for initiator: {}, initiatorType: {}, scenario: {}", initiator, initiatorType, scenario);

TransactionType transactionType = new TransactionType();
transactionType.setInitiator(TransactionRole.valueOf(zeebeVariable(exchange, "initiator", String.class)));
transactionType.setInitiatorType(InitiatorType.valueOf(zeebeVariable(exchange, "initiatorType", String.class)));
transactionType.setScenario(Scenario.valueOf(zeebeVariable(exchange, "scenario", String.class)));
transactionType.setInitiator(TransactionRole.valueOf(initiator));
transactionType.setInitiatorType(InitiatorType.valueOf(initiatorType));
transactionType.setScenario(Scenario.valueOf(scenario));

String note = zeebeVariable(exchange, "note", String.class);
FspMoneyData amount = zeebeVariable(exchange, "amount", FspMoneyData.class);
Expand All @@ -52,8 +58,10 @@ public void process(Exchange exchange) throws Exception {
String existingTransferCode = exchange.getProperty(TRANSFER_CODE, String.class);
String transferCode;
if (existingTransferCode != null) {
logger.info("Existing code not null");
transferCode = existingTransferCode;
} else {
logger.info("Existing code null");
transferCode = UUID.randomUUID().toString();
exchange.setProperty(TRANSFER_CODE, transferCode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ public void process(Exchange exchange) {
zeebeClient.newCompleteCommand(exchange.getProperty(ZEEBE_JOB_KEY, Long.class))
.variables(variables)
.send();
logger.info("Completed job with key: {}", exchange.getProperty(ZEEBE_JOB_KEY, Long.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.mifos.connector.ams.properties.Tenant;
import org.mifos.connector.ams.properties.TenantProperties;
import org.mifos.connector.common.ams.dto.LoginFineractCnResponseDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
Expand All @@ -31,7 +33,9 @@ public class TenantService {
public static final String USER_HEADER = "User";
public static final String FINERACT_PLATFORM_TENANT_ID_HEADER = "Fineract-Platform-TenantId";

@Autowired

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

private ProducerTemplate producerTemplate;

@Autowired
Expand All @@ -46,6 +50,7 @@ public class TenantService {
private final Map<String, CachedTenantAuth> cachedTenantAuths = new ConcurrentHashMap<>();

public Map<String, Object> getHeaders(String tenantName) {
logger.info("Getting headers for tenant: {}", tenantName);
Tenant tenant = tenantProperties.getTenant(tenantName);
Map<String, Object> headers = new HashMap<>();

Expand Down Expand Up @@ -100,4 +105,4 @@ private boolean isAccessTokenExpired(Date accessTokenExpiration) {
Date fiveMinsFromNow = new Date(System.currentTimeMillis() + 300 * 1000);
return accessTokenExpiration.before(fiveMinsFromNow);
}
}
}
Loading

0 comments on commit d5ab3b3

Please sign in to comment.