Skip to content

Commit 0bf9e5e

Browse files
Gov 556 api (#121)
* Fixed the channel connector hostname (#117) * api compliance --------- Co-authored-by: Danish Jamal <31315800+danishjamal104@users.noreply.github.com>
1 parent f08953b commit 0bf9e5e

7 files changed

Lines changed: 48 additions & 75 deletions

File tree

src/main/java/org/mifos/processor/bulk/API/definition/BatchTransactions.java

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,23 @@
11
package org.mifos.processor.bulk.api.definition;
22

3-
import com.amazonaws.services.dynamodbv2.xspec.S;
4-
import com.fasterxml.jackson.core.JsonProcessingException;
5-
import org.apache.camel.util.json.JsonObject;
6-
import org.json.JSONObject;
7-
import org.springframework.web.bind.annotation.*;
8-
import org.springframework.web.multipart.MultipartFile;
9-
10-
import javax.mail.Multipart;
11-
import javax.servlet.http.HttpServletRequest;
12-
import javax.servlet.http.HttpServletResponse;
13-
14-
import java.io.IOException;
15-
163
import static org.mifos.processor.bulk.camel.config.CamelProperties.*;
174
import static org.mifos.processor.bulk.camel.config.CamelProperties.HEADER_CLIENT_CORRELATION_ID;
185
import static org.mifos.processor.bulk.camel.config.CamelProperties.HEADER_PLATFORM_TENANT_ID;
196
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.*;
207

8+
import java.io.IOException;
9+
import javax.servlet.http.HttpServletRequest;
10+
import javax.servlet.http.HttpServletResponse;
11+
import org.springframework.web.bind.annotation.*;
12+
2113
public interface BatchTransactions {
2214

2315
@PostMapping(value = "/batchtransactions", produces = "application/json")
24-
String batchTransactions(
25-
HttpServletRequest httpServletRequest,
26-
HttpServletResponse httpServletResponse,
16+
String batchTransactions(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
2717
@RequestHeader(value = HEADER_CLIENT_CORRELATION_ID) String requestId,
28-
@RequestHeader(value = FILE_NAME, required = false) String fileName,
29-
@RequestHeader(value = PURPOSE) String purpose,
30-
@RequestHeader(value = HEADER_TYPE) String type,
31-
@RequestHeader(value = HEADER_PLATFORM_TENANT_ID) String tenant,
18+
@RequestHeader(value = FILE_NAME, required = false) String fileName, @RequestHeader(value = PURPOSE) String purpose,
19+
@RequestParam(value = HEADER_TYPE) String type, @RequestHeader(value = HEADER_PLATFORM_TENANT_ID) String tenant,
20+
@RequestHeader(value = CALLBACK, required = false) String callbackUrl,
3221
@RequestHeader(value = HEADER_REGISTERING_INSTITUTE_ID, required = false) String registeringInstitutionId,
3322
@RequestHeader(value = HEADER_PROGRAM_ID, required = false) String programId) throws IOException;
3423

src/main/java/org/mifos/processor/bulk/API/implementation/BatchTransactionsController.java

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
package org.mifos.processor.bulk.api.implementation;
22

3+
import static org.mifos.processor.bulk.camel.config.CamelProperties.*;
4+
import static org.mifos.processor.bulk.camel.config.CamelProperties.HEADER_PROGRAM_ID;
5+
import static org.mifos.processor.bulk.camel.config.CamelProperties.HEADER_REGISTERING_INSTITUTE_ID;
6+
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.*;
7+
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.HEADER_CLIENT_CORRELATION_ID;
8+
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.HEADER_PLATFORM_TENANT_ID;
9+
310
import com.fasterxml.jackson.core.type.TypeReference;
411
import com.fasterxml.jackson.databind.ObjectMapper;
512
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
13+
import java.nio.charset.Charset;
14+
import java.util.List;
15+
import java.util.Optional;
16+
import java.util.UUID;
17+
import javax.servlet.http.HttpServletRequest;
18+
import javax.servlet.http.HttpServletResponse;
619
import lombok.SneakyThrows;
720
import lombok.extern.slf4j.Slf4j;
821
import org.apache.camel.Exchange;
@@ -22,25 +35,8 @@
2235
import org.springframework.beans.factory.annotation.Autowired;
2336
import org.springframework.beans.factory.annotation.Value;
2437
import org.springframework.web.bind.annotation.ExceptionHandler;
25-
import org.springframework.web.bind.annotation.RequestHeader;
2638
import org.springframework.web.bind.annotation.RestController;
2739
import org.springframework.web.multipart.MultipartException;
28-
import javax.servlet.http.HttpServletRequest;
29-
import javax.servlet.http.HttpServletResponse;
30-
import java.io.IOException;
31-
import static org.mifos.processor.bulk.camel.config.CamelProperties.*;
32-
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.PURPOSE;
33-
import java.nio.charset.Charset;
34-
import java.util.List;
35-
import java.util.Optional;
36-
import java.util.UUID;
37-
import static org.mifos.processor.bulk.camel.config.CamelProperties.HEADER_PROGRAM_ID;
38-
import static org.mifos.processor.bulk.camel.config.CamelProperties.HEADER_REGISTERING_INSTITUTE_ID;
39-
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.FILE_NAME;
40-
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.HEADER_CLIENT_CORRELATION_ID;
41-
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.HEADER_PLATFORM_TENANT_ID;
42-
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.HEADER_TYPE;
43-
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.PURPOSE;
4440

4541
@Slf4j
4642
@RestController
@@ -65,25 +61,17 @@ public class BatchTransactionsController implements BatchTransactions {
6561

6662
@SneakyThrows
6763
@Override
68-
public String batchTransactions(
69-
HttpServletRequest httpServletRequest,
70-
HttpServletResponse httpServletResponse,
71-
String requestId,
72-
String fileName,
73-
String purpose,
74-
String type,
75-
String tenant,
76-
String registeringInstitutionId,
64+
public String batchTransactions(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String requestId,
65+
String fileName, String purpose, String type, String tenant, String callbackUrl, String registeringInstitutionId,
7766
String programId) {
7867

7968
log.info("Inside api logic");
8069
Headers.HeaderBuilder headerBuilder = new Headers.HeaderBuilder()
8170
.addHeader(HEADER_CLIENT_CORRELATION_ID, requestId)
82-
.addHeader(PURPOSE, purpose)
83-
.addHeader(HEADER_TYPE, type)
71+
.addHeader(PURPOSE, purpose).addHeader(HEADER_TYPE, type)
8472
.addHeader(HEADER_PLATFORM_TENANT_ID, tenant)
85-
.addHeader(HEADER_REGISTERING_INSTITUTE_ID, registeringInstitutionId)
86-
.addHeader(HEADER_PROGRAM_ID, programId);
73+
.addHeader(HEADER_REGISTERING_INSTITUTE_ID, registeringInstitutionId).addHeader(HEADER_PROGRAM_ID, programId)
74+
.addHeader(CALLBACK,callbackUrl);
8775

8876
Optional<String> validationResponse = isValidRequest(httpServletRequest, fileName, type);
8977
if (validationResponse.isPresent()) {
@@ -108,9 +96,7 @@ public String batchTransactions(
10896

10997
String localFileName = UUID.randomUUID() + ".csv";
11098
CsvWriter.writeToCsv(transactionList, Transaction.class, csvMapper, true, localFileName);
111-
Headers headers = headerBuilder
112-
.addHeader(HEADER_TYPE, "csv")
113-
.addHeader(FILE_NAME, localFileName).build();
99+
Headers headers = headerBuilder.addHeader(HEADER_TYPE, "csv").addHeader(FILE_NAME, localFileName).build();
114100

115101
CamelApiResponse response = sendRequestToCamel(headers);
116102
httpServletResponse.setStatus(response.getStatus());
@@ -121,8 +107,8 @@ public String batchTransactions(
121107
@ExceptionHandler({ MultipartException.class })
122108
public String handleMultipartException(HttpServletResponse httpServletResponse) {
123109
httpServletResponse.setStatus(httpServletResponse.SC_BAD_REQUEST);
124-
return getErrorResponse("File not uploaded", "There was no fie uploaded with the request. " +
125-
"Please upload a file and try again.", 400);
110+
return getErrorResponse("File not uploaded", "There was no fie uploaded with the request. " + "Please upload a file and try again.",
111+
400);
126112
}
127113

128114
private CamelApiResponse sendRequestToCamel(Headers headers) {
@@ -142,31 +128,26 @@ private String getErrorResponse(String information, String description, int code
142128
}
143129

144130
// validates the request header, and return errorJson string if the request is invalid else an empty optional
145-
private Optional<String> isValidRequest(HttpServletRequest httpServletRequest,
146-
String fileName,
147-
String type) {
131+
private Optional<String> isValidRequest(HttpServletRequest httpServletRequest, String fileName, String type) {
148132

149-
Optional<String> response = Optional.empty();
150-
if ((JWSUtil.isMultipartRequest(httpServletRequest) && !type.equalsIgnoreCase("csv")) ||
151-
(!JWSUtil.isMultipartRequest(httpServletRequest) && !type.equalsIgnoreCase("raw"))) {
133+
Optional<String> response = Optional.empty();
134+
if ((JWSUtil.isMultipartRequest(httpServletRequest) && !type.equalsIgnoreCase("csv"))
135+
|| (!JWSUtil.isMultipartRequest(httpServletRequest) && !type.equalsIgnoreCase("raw"))) {
152136
String errorJson = getErrorResponse("Type mismatch",
153-
"The value of the header \"" + HEADER_TYPE +
154-
"\" doesn't match with the request content-type", 400);
137+
"The value of the header \"" + HEADER_TYPE + "\" doesn't match with the request content-type", 400);
155138
response = Optional.of(errorJson);
156139

157140
}
158141
if (JWSUtil.isMultipartRequest(httpServletRequest) && fileName.isEmpty()) {
159142
String errorJson = getErrorResponse("Header can't be empty",
160-
"If the request is of type csv, the header \"" +
161-
FILE_NAME + "\"can't be empty", 400);
143+
"If the request is of type csv, the header \"" + FILE_NAME + "\"can't be empty", 400);
162144
response = Optional.of(errorJson);
163145
}
164146
if (!type.equalsIgnoreCase("raw") && !type.equalsIgnoreCase("csv")) {
165147
String errorJson = getErrorResponse("Invalid TYPE header value passed",
166-
"The value of the header \"" + HEADER_TYPE +
167-
"\" can be \"[raw,csv]\" but is " + type, 400);
148+
"The value of the header \"" + HEADER_TYPE + "\" can be \"[raw,csv]\" but is " + type, 400);
168149
response = Optional.of(errorJson);
169150
}
170-
return response;
151+
return response;
171152
}
172153
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,18 @@ private void setup() {
255255
String tenantSpecificWorkflowId = workflowId.replace("{dfspid}", exchange.getProperty(TENANT_NAME).toString());
256256
String txnId = zeebeProcessStarter.startZeebeWorkflow(tenantSpecificWorkflowId, "", variables);
257257
if (txnId == null || txnId.isEmpty()) {
258+
logger.debug("error: Issue in starting the zeebe workflow, check the zeebe configuration");
258259
response.put("errorCode", 500);
259260
response.put("errorDescription", "Unable to start zeebe workflow");
260261
response.put("developerMessage", "Issue in starting the zeebe workflow, check the zeebe configuration");
261262
} else {
263+
logger.debug("successful: zeebe workflow started {}",txnId);
262264
response.put("batch_id", batchId);
263265
response.put("request_id", requestId);
264266
response.put("status", "queued");
265267
}
266268
} catch (Exception e) {
269+
logger.debug("error: Issue in starting the zeebe workflow {}", e.getLocalizedMessage());
267270
response.put("errorCode", 500);
268271
response.put("errorDescription", "Unable to start zeebe workflow");
269272
response.put("developerMessage", e.getLocalizedMessage());
@@ -363,7 +366,7 @@ private boolean verifyData(File file) throws IOException {
363366
String line;
364367
br.readLine();
365368
while ((line = br.readLine()) != null) {
366-
String[] row = line.split(",");
369+
String[] row = line.split(",", -1);
367370
if (row.length != columnNames.size()) {
368371
logger.debug("Row invalid {} {}", row.length, columnNames.size());
369372
return false;

src/main/java/org/mifos/processor/bulk/format/RestRequestConvertor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public BatchRequestDTO convertTo(Transaction object) {
3030
batchRequestDTO.setCreditParty(List.of(creditParty));
3131
batchRequestDTO.setDebitParty(List.of(debitParty));
3232
batchRequestDTO.setDescriptionText(object.getNote());
33-
batchRequestDTO.setSubType(object.getPaymentMode());
33+
batchRequestDTO.setPaymentMode(object.getPaymentMode());
3434

3535
return batchRequestDTO;
3636
}
@@ -51,7 +51,7 @@ public Transaction convertFrom(BatchRequestDTO object) {
5151
transaction.setPayeeIdentifier(object.getCreditParty().get(0).getValue());
5252
}
5353
transaction.setNote(object.getDescriptionText());
54-
transaction.setPaymentMode(object.getSubType());
54+
transaction.setPaymentMode(object.getPaymentMode());
5555

5656
return transaction;
5757
}

src/main/java/org/mifos/processor/bulk/schema/BatchRequestDTO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public class BatchRequestDTO {
1515

1616
List<Party> creditParty, debitParty;
1717

18-
String subType, amount, currency, descriptionText;
18+
String paymentMode, amount, currency, descriptionText;
1919

2020
}

src/main/java/org/mifos/processor/bulk/zeebe/ZeebeVariables.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private ZeebeVariables() {}
102102

103103
public static final String CALLBACK_SUCCESS = "callbackSuccessful";
104104

105-
public static final String CALLBACK_URL = "callbackUrl";
105+
public static final String CALLBACK_URL = "X-CallbackURL";
106106

107107
public static final String MAX_CALLBACK_RETRY = "maxCallbackRetry";
108108

@@ -130,6 +130,6 @@ private ZeebeVariables() {}
130130
public static final String PAYER_IDENTIFIER_TYPE = "payerIdentifierType";
131131
public static final String PAYER_IDENTIFIER_VALUE = "payerIdentifier";
132132
public static final String HEADER_CLIENT_CORRELATION_ID = "X-CorrelationID";
133-
public static final String HEADER_TYPE = "Type";
133+
public static final String HEADER_TYPE = "type";
134134
public static final String HEADER_PLATFORM_TENANT_ID = "Platform-TenantId";
135135
}

src/main/resources/application.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ operations-app:
3838
batch-transaction: "/api/v1/batch/transactions"
3939

4040
channel:
41-
hostname: "https://ph-ee-connector-channel"
41+
hostname: "https://ph-ee-connector-channel:8443"
4242

4343
cloud:
4444
aws:

0 commit comments

Comments
 (0)