Skip to content

Commit 975624b

Browse files
Fixed the regression in bulk (#110)
1 parent d5d8f87 commit 975624b

8 files changed

Lines changed: 64 additions & 8 deletions

File tree

src/main/java/org/mifos/processor/bulk/camel/routes/ExternalApiCallRoute.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import org.apache.camel.builder.RouteBuilder;
88
import org.springframework.stereotype.Component;
99

10-
@Component
10+
//@Component
1111
public class ExternalApiCallRoute extends RouteBuilder {
1212

1313
@Override

src/main/java/org/mifos/processor/bulk/camel/routes/FileRoute.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ public void configure() throws Exception {
3232
from("direct:download-file").id("direct:download-file").log("Started download-file route").process(exchange -> {
3333
String filename = exchange.getProperty(SERVER_FILE_NAME, String.class);
3434

35-
InputStream csvFileInputStream = fileTransferService.streamFile(filename, bucketName);
35+
byte[] csvFile = fileTransferService.downloadFile(filename, bucketName);
3636
File file = new File(filename);
3737
try (FileOutputStream fos = new FileOutputStream(file)) {
38-
fos.write(csvFileInputStream.read());
38+
fos.write(csvFile);
3939
}
4040
exchange.setProperty(LOCAL_FILE_PATH, file.getAbsolutePath());
4141
logger.info("File downloaded");

src/main/java/org/mifos/processor/bulk/camel/routes/InitSubBatchRoute.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.mifos.processor.bulk.camel.config.CamelProperties.BATCH_ID_HEADER;
44
import static org.mifos.processor.bulk.camel.config.CamelProperties.EXTERNAL_ENDPOINT;
55
import static org.mifos.processor.bulk.camel.config.CamelProperties.EXTERNAL_ENDPOINT_FAILED;
6+
import static org.mifos.processor.bulk.camel.config.CamelProperties.HEADER_CLIENT_CORRELATION_ID;
67
import static org.mifos.processor.bulk.camel.config.CamelProperties.IS_PAYMENT_MODE_VALID;
78
import static org.mifos.processor.bulk.camel.config.CamelProperties.LOCAL_FILE_PATH;
89
import static org.mifos.processor.bulk.camel.config.CamelProperties.OVERRIDE_HEADER;
@@ -132,7 +133,6 @@ public void configure() throws Exception {
132133
logger.info("REQUEST_ID: {}", transaction.getRequestId());
133134
exchange.setProperty(TRANSACTION_LIST_ELEMENT, transaction);
134135
}).setHeader("Platform-TenantId", exchangeProperty(TENANT_NAME))
135-
.setHeader("X-CorrelationID", exchangeProperty(REQUEST_ID))
136136
.to("direct:dynamic-payload-setter")
137137
.to("direct:external-api-call").to("direct:external-api-response-handler").end() // end loop block
138138
.endChoice();
@@ -152,9 +152,10 @@ public void configure() throws Exception {
152152
from("direct:external-api-response-handler").id("direct:external-api-response-handler")
153153
.log("Starting route direct:external-api-response-handler").choice().when(header("CamelHttpResponseCode").isEqualTo(200))
154154
.process(exchange -> {
155-
logger.info("reached here");
155+
logger.info("INIT_SUB_BATCH_FAILED is false");
156156
exchange.setProperty(INIT_SUB_BATCH_FAILED, false);
157157
}).otherwise().process(exchange -> {
158+
logger.info("INIT_SUB_BATCH_FAILED is false");
158159
exchange.setProperty(INIT_SUB_BATCH_FAILED, true);
159160
}).endChoice();
160161

@@ -191,8 +192,13 @@ public void configure() throws Exception {
191192
.log(LoggingLevel.DEBUG, "Making API call to endpoint ${exchangeProperty.extEndpoint} and body: ${body}")
192193
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
193194
.setHeader(BATCH_ID_HEADER, simple("${exchangeProperty." + BATCH_ID + "}"))
195+
.setHeader(HEADER_CLIENT_CORRELATION_ID, simple("${exchangeProperty." + REQUEST_ID + "}"))
196+
.process(exchange -> {
197+
log.debug("Variables: {}", exchange.getProperties());
198+
log.debug("Emergency: {}", exchange.getIn().getHeaders());
199+
})
194200
.toD(ChannelURL + "${exchangeProperty.extEndpoint}" + "?bridgeEndpoint=true&throwExceptionOnFailure=false")
195-
.log(LoggingLevel.DEBUG, "Response body: ${body}").otherwise().endChoice();
201+
.log(LoggingLevel.INFO, "Response body: ${body}").otherwise().endChoice();
196202

197203
from("direct:validate-payment-mode").id("direct:validate-payment-mode").log("Starting route direct:validate-payment-mode")
198204
.process(exchange -> {

src/main/java/org/mifos/processor/bulk/camel/routes/ProcessorStartRoute.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static org.mifos.processor.bulk.camel.config.CamelProperties.*;
44
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.*;
5-
65
import java.io.BufferedReader;
76
import java.io.File;
87
import java.io.FileInputStream;
@@ -203,7 +202,7 @@ private void setup() {
203202
.setProperty(OVERRIDE_HEADER, constant(true)) // default header in CSV file will be used
204203
.to("direct:update-file-v2")
205204
.otherwise()
206-
.log(LoggingLevel.DEBUG, "No update");
205+
.log(LoggingLevel.INFO, "No update");
207206

208207
from("direct:start-batch-process-csv")
209208
.id("direct:start-batch-process-csv")
@@ -261,7 +260,10 @@ private void setup() {
261260
variables.put(REGISTERING_INSTITUTE_ID, exchange.getProperty(REGISTERING_INSTITUTE_ID));
262261
variables.put(IS_FILE_VALID, true);
263262
setConfigProperties(variables);
263+
264264
logger.debug("Zeebe variables published: {}", variables);
265+
log.debug("Variables published to zeebe: {}", variables);
266+
265267
JSONObject response = new JSONObject();
266268

267269
try {

src/main/java/org/mifos/processor/bulk/file/AwsFileTransferImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.FileOutputStream;
99
import java.io.IOException;
1010
import java.io.InputStream;
11+
import com.amazonaws.util.IOUtils;
1112
import org.slf4j.Logger;
1213
import org.slf4j.LoggerFactory;
1314
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,6 +25,19 @@ public class AwsFileTransferImpl implements FileTransferService {
2425
@Autowired
2526
private AmazonS3 s3Client;
2627

28+
@Override
29+
public byte[] downloadFile(String fileName, String bucketName) {
30+
S3Object s3Object = s3Client.getObject(bucketName, fileName);
31+
S3ObjectInputStream inputStream = s3Object.getObjectContent();
32+
try {
33+
byte[] content = IOUtils.toByteArray(inputStream);
34+
return content;
35+
} catch (IOException e) {
36+
e.printStackTrace();
37+
}
38+
return null;
39+
}
40+
2741
@Override
2842
public String uploadFile(MultipartFile file, String bucketName) {
2943

src/main/java/org/mifos/processor/bulk/file/AzureFileTransferImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import java.io.IOException;
66
import java.io.InputStream;
77
import java.nio.file.Files;
8+
import java.nio.file.Paths;
89

10+
import com.azure.storage.blob.models.BlobProperties;
911
import com.azure.storage.blob.specialized.BlobInputStream;
1012
import org.slf4j.Logger;
1113
import org.slf4j.LoggerFactory;
@@ -25,6 +27,20 @@ public class AzureFileTransferImpl implements FileTransferService {
2527
@Autowired
2628
BlobClientBuilder client;
2729

30+
@Override
31+
public byte[] downloadFile(String fileName, String bucketName) {
32+
try {
33+
File temp = new File("/temp/" + fileName);
34+
BlobProperties properties = client.containerName(bucketName).blobName(fileName).buildClient().downloadToFile(temp.getPath());
35+
byte[] content = Files.readAllBytes(Paths.get(temp.getPath()));
36+
temp.delete();
37+
return content;
38+
} catch (Exception e) {
39+
e.printStackTrace();
40+
}
41+
return null;
42+
}
43+
2844
@Override
2945
public String uploadFile(MultipartFile file, String bucketName) {
3046

src/main/java/org/mifos/processor/bulk/file/FileTransferService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
@Service
99
public interface FileTransferService {
1010

11+
byte[] downloadFile(String fileName, String bucketName);
12+
1113
String uploadFile(MultipartFile file, String bucketName);
1214

1315
String uploadFile(File file, String bucketName);

src/main/resources/application.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,19 @@ management:
163163
enabled: true
164164
readiness:
165165
enabled: true
166+
167+
payment-mode:
168+
mappings:
169+
- id: "GSMA"
170+
type: "PAYMENT"
171+
endpoint: "/channel/gsma/transfer"
172+
- id: "MOJALOOP"
173+
type: "PAYMENT"
174+
endpoint: "/channel/transfer"
175+
- id: "SLCB"
176+
type: "BULK"
177+
endpoint: "bulk_connector_{MODE}-{dfspid}"
178+
- id: "CLOSEDLOOP"
179+
type: "BULK"
180+
endpoint: "bulk_connector_{MODE}-{dfspid}"
181+
debulkingDfspid: "lion"

0 commit comments

Comments
 (0)