11package org .mifos .connector .phee .camel .routes ;
22
3+ import com .fasterxml .jackson .databind .ObjectMapper ;
34import org .apache .camel .Exchange ;
45import org .apache .camel .LoggingLevel ;
5- import org .apache .camel .model .dataformat .JsonLibrary ;
66import 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 ;
812import org .mifos .connector .phee .utils .Utils ;
913import org .springframework .beans .factory .annotation .Autowired ;
1014import org .springframework .beans .factory .annotation .Value ;
1519import java .util .List ;
1620import 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
2142public 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 );
0 commit comments