Skip to content

Commit 3edb8bd

Browse files
abhinavm117apurbrajabhinav
authored
[PHEE-552] Updated Sub-Batch Id assigned. (#12)
* GOV-75 * Updated the flow for BatchId in transfers table * removed test module * Updated s3 url * Updated service url * Feedback changes * deleted csv files --------- Co-authored-by: Apurb Rajdhan <[email protected]> Co-authored-by: abhinav <[email protected]>
1 parent 50f5caa commit 3edb8bd

File tree

15 files changed

+472
-419
lines changed

15 files changed

+472
-419
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ext {
2828
dependencies {
2929
implementation 'com.google.code.gson:gson:2.8.9'
3030
implementation 'org.json:json:20210307'
31-
implementation 'org.mifos:ph-ee-connector-common:1.4.1-SNAPSHOT'
31+
implementation 'org.mifos:ph-ee-connector-common:1.8.1-SNAPSHOT'
3232
implementation 'org.apache.camel.springboot:camel-spring-boot-starter:3.4.0'
3333
implementation 'org.apache.camel:camel-undertow:3.4.0'
3434
implementation 'org.springframework.boot:spring-boot-starter:2.5.2'

src/main/java/org/mifos/connector/phee/camel/routes/BatchDetailRoute.java

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package org.mifos.connector.phee.camel.routes;
22

3+
import com.fasterxml.jackson.databind.ObjectMapper;
34
import org.apache.camel.Exchange;
45
import org.apache.camel.LoggingLevel;
5-
import org.apache.camel.model.dataformat.JsonLibrary;
66
import org.mifos.connector.phee.config.MockPaymentSchemaConfig;
7-
import org.mifos.connector.phee.schema.*;
7+
import org.mifos.connector.phee.schema.BatchDetailResponse;
8+
import org.mifos.connector.phee.schema.Transaction;
9+
import org.mifos.connector.phee.schema.TransactionResult;
10+
import org.mifos.connector.phee.schema.Transfer;
11+
import org.mifos.connector.phee.schema.TransferStatus;
812
import org.mifos.connector.phee.utils.Utils;
913
import org.springframework.beans.factory.annotation.Autowired;
1014
import org.springframework.beans.factory.annotation.Value;
@@ -15,7 +19,24 @@
1519
import java.util.List;
1620
import java.util.Map;
1721

18-
import static org.mifos.connector.phee.zeebe.ZeebeVariables.*;
22+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.BATCH_DETAIL_SUCCESS;
23+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.BATCH_ID;
24+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.COMPLETED_TRANSACTION_COUNT;
25+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.CURRENT_TRANSACTION_COUNT;
26+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.ERROR_CODE;
27+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.ERROR_DESCRIPTION;
28+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.FAILED_TRANSACTION_COUNT;
29+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.FILE_NAME;
30+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.LOCAL_FILE_PATH;
31+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.ONGOING_TRANSACTION_COUNT;
32+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.OVERRIDE_HEADER;
33+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.PAGE_NO;
34+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.REQUEST_ID_STATUS_MAP;
35+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.RESULT_FILE;
36+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.RESULT_TRANSACTION_LIST;
37+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.TOTAL_TRANSACTION;
38+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.TRANSACTION_LIST;
39+
1940

2041
@Component
2142
public class BatchDetailRoute extends BaseRouteBuilder {
@@ -28,41 +49,37 @@ public class BatchDetailRoute extends BaseRouteBuilder {
2849

2950
@Autowired
3051
public MockPaymentSchemaConfig mockPaymentSchemaConfig;
52+
private ObjectMapper objectMapper = new ObjectMapper();
3153

3254
@Override
3355
public void configure() throws Exception {
3456

3557
from(RouteId.BATCH_DETAIL.getValue())
3658
.id(RouteId.BATCH_DETAIL.getValue())
3759
.log("Starting route " + RouteId.BATCH_DETAIL.name())
38-
// .to("direct:batch-detail-api-call")
60+
.to("direct:batch-detail-api-call")
3961
.to("direct:batch-detail-response-handler");
4062

41-
getBaseExternalApiRequestRouteDefinition("batch-detail-api-call", HttpRequestMethod.GET)
42-
.setHeader(
43-
Exchange.REST_HTTP_QUERY,
44-
simple(
45-
BATCH_ID + "=${exchangeProperty." + BATCH_ID + "}&" +
46-
PAGE_NO + "=${exchangeProperty." + PAGE_NO + "}&" +
47-
PAGE_SIZE + "=${exchangeProperty." + PAGE_SIZE + "}"
48-
)
49-
)
50-
.setHeader("Platform-TenantId", simple(tenant))
51-
.process(exchange -> {
52-
logger.info(exchange.getIn().getHeaders().toString());
53-
})
54-
.toD(mockPaymentSchemaConfig.batchDetailUrl + "?bridgeEndpoint=true&throwExceptionOnFailure=false")
55-
.log(LoggingLevel.DEBUG, "Batch detail API response: \n\n ${body}");
63+
from("direct:batch-detail-api-call")
64+
.routeId("direct:batch-detail-api-call")
65+
.setHeader("CamelHttpMethod", constant("GET"))
66+
.setHeader("Accept", constant("application/json"))
67+
.toD(mockPaymentSchemaConfig.mockPaymentSchemaContactPoint+"/batches/"+ "${exchangeProperty.batchId}"+"/detail"+ "?" + "pageNo" + "=${exchangeProperty.pageNo}&" + "pageSize"
68+
+ "=${exchangeProperty.pageSize}" )
69+
.log("API Response: ${body}")
70+
.setProperty("apiResponse", body()) ; // Log the API response, you can modify this according to your needs
71+
5672

5773
from("direct:batch-detail-response-handler")
5874
.id("direct:batch-detail-response-handler")
5975
.log("Starting route direct:batch-detail-response-handler")
6076
.choice()
6177
.when(header("CamelHttpResponseCode").isEqualTo("200"))
6278
.log(LoggingLevel.INFO, "Batch detail request successful")
63-
.unmarshal().json(JsonLibrary.Jackson, BatchDetailResponse.class)
6479
.process(exchange -> {
65-
BatchDetailResponse batchDetailResponse = exchange.getIn().getBody(BatchDetailResponse.class);
80+
String apiResponse = exchange.getProperty("apiResponse", String.class);
81+
logger.info(apiResponse);
82+
BatchDetailResponse batchDetailResponse = objectMapper.readValue(apiResponse, BatchDetailResponse.class);
6683
logger.info(batchDetailResponse.toString());
6784

6885
int pageNo = Integer.parseInt(exchange.getProperty(PAGE_NO, String.class));
@@ -118,7 +135,7 @@ else if(TransferStatus.IN_PROGRESS.equals(transferStatus)){
118135
exchange.setProperty(ONGOING_TRANSACTION_COUNT, ongoingTransferCount);
119136
exchange.setProperty(REQUEST_ID_STATUS_MAP, requestIdStatusMap);
120137

121-
if(currentTransferCount>=totalTransferCount){
138+
if(currentTransferCount<=totalTransferCount){
122139
exchange.setProperty(BATCH_DETAIL_SUCCESS, true);
123140
}
124141
else {
@@ -163,7 +180,7 @@ private List<TransactionResult> fetchTransactionResult(List<Transaction> transac
163180
for (Transaction transaction : transactionList) {
164181
TransactionResult transactionResult = Utils.mapToResultDTO(transaction);
165182
transactionResult.setPaymentMode("CLOSEDLOOP");
166-
transactionResult.setBatchId(batchId);
183+
transactionResult.setBatchId(transaction.getBatchId());
167184
String status = requestIdStatusMap.get(transaction.getRequestId());
168185
transactionResult.setStatus(status);
169186
transactionResultList.add(transactionResult);

src/main/java/org/mifos/connector/phee/camel/routes/BatchSummaryRoute.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,20 @@
1111

1212
import java.math.BigDecimal;
1313

14-
import static org.mifos.connector.phee.zeebe.ZeebeVariables.*;
14+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.BATCH_ID;
15+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.BATCH_SUMMARY_SUCCESS;
16+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.COMPLETED_AMOUNT;
17+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.COMPLETED_TRANSACTION;
18+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.COMPLETION_RATE;
19+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.ERROR_CODE;
20+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.ERROR_DESCRIPTION;
21+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.FAILED_AMOUNT;
22+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.FAILED_TRANSACTION;
23+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.ONGOING_AMOUNT;
24+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.ONGOING_TRANSACTION;
25+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.TOTAL_AMOUNT;
26+
import static org.mifos.connector.phee.zeebe.ZeebeVariables.TOTAL_TRANSACTION;
27+
1528

1629
@Component
1730
public class BatchSummaryRoute extends BaseRouteBuilder {
@@ -36,14 +49,21 @@ public void configure() throws Exception {
3649

3750

3851
getBaseExternalApiRequestRouteDefinition("batch-summary-api-call", HttpRequestMethod.GET)
39-
.setHeader(Exchange.REST_HTTP_QUERY, simple("batchId=${exchangeProperty." + BATCH_ID + "}"))
52+
.setHeader(Exchange.HTTP_METHOD, constant("GET"))
53+
.setHeader(Exchange.HTTP_PATH, simple("/batches/${exchangeProperty." + BATCH_ID + "}/summary"))
4054
.setHeader("Platform-TenantId", simple(tenant))
4155
.process(exchange -> {
4256
logger.info(exchange.getIn().getHeaders().toString());
4357
})
44-
.toD(mockPaymentSchemaConfig.batchSummaryUrl + "?bridgeEndpoint=true&throwExceptionOnFailure=false")
58+
.toD("direct:callBatchSummaryEndpoint") // Use a direct endpoint to call the method
59+
.log(LoggingLevel.INFO, "Batch summary API response: \n\n ${body}");
60+
61+
// Define a route to call the Spring method
62+
from("direct:callBatchSummaryEndpoint")
63+
.to(mockPaymentSchemaConfig.mockPaymentSchemaContactPoint+"/batches/${exchangeProperty." + BATCH_ID + "}/summary")
4564
.log(LoggingLevel.INFO, "Batch summary API response: \n\n ${body}");
4665

66+
4767
from("direct:batch-summary-response-handler")
4868
.id("direct:batch-summary-response-handler")
4969
.log("Starting route direct:batch-summary-response-handler")
@@ -96,4 +116,4 @@ public void configure() throws Exception {
96116
});
97117

98118
}
99-
}
119+
}

src/main/java/org/mifos/connector/phee/file/config/AwsStorageConfig.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.amazonaws.auth.AWSCredentials;
44
import com.amazonaws.auth.AWSStaticCredentialsProvider;
55
import com.amazonaws.auth.BasicAWSCredentials;
6+
import com.amazonaws.client.builder.AwsClientBuilder;
67
import com.amazonaws.services.s3.AmazonS3;
78
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
89
import org.springframework.beans.factory.annotation.Value;
@@ -23,13 +24,17 @@ public class AwsStorageConfig {
2324
@Value("${cloud.aws.region.static}")
2425
private String region;
2526

27+
@Value("${cloud.aws.s3BaseUrl}")
28+
private String endpoint;
29+
2630
@Bean
27-
@ConditionalOnProperty(value="cloud.aws.enabled", havingValue = "true")
31+
@ConditionalOnProperty(value = "cloud.aws.enabled", havingValue = "true")
2832
public AmazonS3 s3Client() {
2933
AWSCredentials credentials = new BasicAWSCredentials(accessKey, accessSecret);
30-
return AmazonS3ClientBuilder.standard()
31-
.withCredentials(new AWSStaticCredentialsProvider(credentials))
32-
.withRegion(region).build();
34+
return AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials))
35+
.withPathStyleAccessEnabled(true).withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, region))
36+
.build();
37+
3338
}
3439

3540
}

0 commit comments

Comments
 (0)