Skip to content

Commit 733df2b

Browse files
danishjamal104dhruvsonagaraankita10rarkadasfynarfin
authored
GOV 285: Merging tt\he spring migration to master (#100)
* Migrated bulk transfer and batch transaction API (#52) * Migrated bulk transfer and batch transaction API * Reverted unnescessary changes * removed csv files * GOV-289.2 Integrated JWS (#53) * Suggested Callback Time that is Resolved by Polling (#51) * Integrated JWS --------- Co-authored-by: Ankita Ranjan <92036361+ankita10r@users.noreply.github.com> * GOV 293: Integrating /batchtransactions with 1.5.0 version of connector common (#58) * GOV-290 Enabled TLS for tomcat server (#60) * GOV 293: Integrating /batchtransactions with 1.5.0 version of connector common * X-Signature header integrated while sending callback * Fixed the version of connector-common * GOV-290 Enabled TLS for tomcat server * Deleted redundant CSV file * Updated readme with info about disabling TLS in tomcat * Added default password for keystore file * Gov 293 X-Signature header integrated while sending callback (#59) * GOV 293: Integrating /batchtransactions with 1.5.0 version of connector common * X-Signature header integrated while sending callback * Fixed the version of connector-common * Deleted redundant CSV file * Migrated bulk transfer and batch transaction API (#52) * Migrated bulk transfer and batch transaction API * Reverted unnescessary changes * removed csv files * GOV-255: Added configuration for programId/registeringInstituteId (#86) * Added configuration for programId/registeringInstituteId * Added logic to support programId and registeringInstituteId header * Updated the config for n cross n mapping b/w registeringInstituteId and program * GOV-255.2 Publishing programName, payerIdentifierType and payerIdentifierValue as zeebe variable * Addressed the comment for import fixes * remove unnecessary merge conflict text from application.yaml (#88) * Code structure fixed * APIOriginFilter bug fixed * Added commons dependency * Spring migration file stream to camel fixed * Added multipart excecption handling * Migrated /simulate api to spring * Address the PR review comments --------- Co-authored-by: Dhruv Sonagara <78945411+dhruvsonagara@users.noreply.github.com> Co-authored-by: Ankita Ranjan <92036361+ankita10r@users.noreply.github.com> Co-authored-by: Arka Das <127482132+arkadasfynarfin@users.noreply.github.com>
1 parent c631880 commit 733df2b

26 files changed

Lines changed: 623 additions & 114 deletions

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
#Auto-Trigger
22

3+
## SSL Configuration
4+
```yaml
5+
server:
6+
ssl:
7+
key-alias: "tomcat-https"
8+
key-store: "classpath:keystore.jks"
9+
key-store-type: JKS
10+
key-password: "<replace-with-password>"
11+
key-store-password: "<replace-with-password>"
12+
port: 8443
13+
```
14+
#### NOTE: For disabling TLS, change the port to "8080" and add null values for all the "ssl" related fields.
15+
316
## Checkstyle
417
Use below command to execute the checkstyle test.
518
```shell

build.gradle

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,16 @@ dependencies {
107107
// miscellaneous dependency
108108
implementation 'com.google.code.gson:gson:2.8.9'
109109
implementation 'org.json:json:20210307'
110-
implementation 'org.mifos:ph-ee-connector-common:1.4.1-SNAPSHOT'
110+
implementation 'org.mifos:ph-ee-connector-common:1.5.0-SNAPSHOT'
111+
implementation 'org.apache.camel.springboot:camel-spring-boot-starter:3.4.0'
112+
implementation 'org.apache.camel:camel-undertow:3.4.0'
113+
implementation 'org.springframework.boot:spring-boot-starter:2.5.2'
114+
implementation 'org.springframework.boot:spring-boot-starter-web:2.5.2'
115+
implementation 'org.apache.camel:camel-http:3.4.0'
116+
implementation 'org.springframework:spring-web:5.3.19'
117+
implementation 'com.amazonaws:aws-java-sdk:1.11.486'
118+
implementation 'commons-io:commons-io:2.11.0'
119+
111120
implementation 'com.amazonaws:aws-java-sdk-s3:1.11.486'
112121
//To be removed
113122
implementation 'com.amazonaws:aws-java-sdk-dynamodb:1.11.486'

src/main/java/org/mifos/processor/BulkProcessorApplication.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
88
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
99
import org.apache.camel.Processor;
10+
import org.mifos.connector.common.interceptor.annotation.EnableJsonWebSignature;
11+
import org.mifos.processor.bulk.api.ApiOriginFilter;
1012
import org.mifos.processor.bulk.camel.config.HttpClientConfigurerTrustAllCACerts;
1113
import org.springframework.boot.SpringApplication;
14+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
1215
import org.springframework.boot.autoconfigure.SpringBootApplication;
16+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
17+
import org.springframework.boot.web.servlet.FilterRegistrationBean;
1318
import org.springframework.context.annotation.Bean;
1419

1520
@SpringBootApplication
21+
@EnableJsonWebSignature
1622
public class BulkProcessorApplication {
1723

1824
public static void main(String[] args) {
@@ -44,4 +50,14 @@ public HttpClientConfigurerTrustAllCACerts httpClientConfigurer() {
4450
return new HttpClientConfigurerTrustAllCACerts();
4551
}
4652

53+
@Bean
54+
public FilterRegistrationBean<ApiOriginFilter> apiOriginFilter() {
55+
FilterRegistrationBean<ApiOriginFilter> registration = new FilterRegistrationBean<>();
56+
registration.setFilter(new ApiOriginFilter());
57+
registration.addUrlPatterns("/**");
58+
registration.setName("apiOriginFilter");
59+
registration.setOrder(Integer.MIN_VALUE+1);
60+
return registration;
61+
}
62+
4763
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.mifos.processor.bulk.api.definition;
2+
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.HttpServletResponse;
12+
13+
import java.io.IOException;
14+
15+
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.*;
16+
17+
public interface BatchTransactions {
18+
19+
@PostMapping(value = "/batchtransactions", produces="application/json")
20+
String batchTransactions(HttpServletResponse httpServletResponse, @RequestHeader(value = "X-CorrelationID") String requestId,
21+
@RequestParam("data") MultipartFile file,
22+
@RequestHeader(value = FILE_NAME) String fileName,
23+
@RequestHeader(value = PURPOSE) String purpose,
24+
@RequestHeader(value = "Type") String type,
25+
@RequestHeader(value = "Platform-TenantId") String tenant) throws IOException;
26+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.mifos.processor.bulk.api.definition;
2+
3+
import org.springframework.web.bind.annotation.PostMapping;
4+
import org.springframework.web.bind.annotation.RequestHeader;
5+
import org.springframework.web.bind.annotation.RequestParam;
6+
import org.springframework.web.multipart.MultipartFile;
7+
8+
import java.io.IOException;
9+
10+
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.FILE_NAME;
11+
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.PURPOSE;
12+
13+
public interface BulkTransfer {
14+
@PostMapping(value = "/bulk/transfer/{requestId}/{fileName}", produces = "application/json")
15+
String bulkTransfer(@RequestHeader(value = "X-CorrelationID", required = false) String requestId,
16+
@RequestParam("data") MultipartFile file,
17+
@RequestHeader(value = FILE_NAME, required = false) String fileName,
18+
@RequestHeader(value = PURPOSE, required = false) String purpose,
19+
@RequestHeader(value = "Type", required = false) String type,
20+
@RequestHeader(value = "Platform-TenantId") String tenant) throws IOException;
21+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.mifos.processor.bulk.api.definition;
2+
3+
import org.springframework.web.bind.annotation.PostMapping;
4+
import javax.servlet.http.HttpServletResponse;
5+
import java.io.IOException;
6+
7+
// from("rest:post:/simulate").log("Reached Simulation");
8+
public interface Simulate {
9+
10+
@PostMapping(value = "/simulate", produces="application/json")
11+
void simulate(HttpServletResponse httpServletResponse) throws IOException;
12+
13+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.mifos.processor.bulk.api.implementation;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import lombok.SneakyThrows;
5+
import lombok.extern.slf4j.Slf4j;
6+
import org.apache.camel.Exchange;
7+
import org.apache.camel.ProducerTemplate;
8+
import org.json.JSONObject;
9+
import org.mifos.processor.bulk.api.definition.BatchTransactions;
10+
import org.mifos.processor.bulk.file.FileStorageService;
11+
import org.mifos.processor.bulk.utility.Headers;
12+
import org.mifos.processor.bulk.utility.SpringWrapperUtil;
13+
import org.springframework.beans.factory.annotation.Autowired;
14+
import org.springframework.web.bind.annotation.ExceptionHandler;
15+
import org.springframework.web.bind.annotation.RestController;
16+
import org.springframework.web.multipart.MultipartException;
17+
import org.springframework.web.multipart.MultipartFile;
18+
import javax.servlet.http.HttpServletResponse;
19+
import java.io.IOException;
20+
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.PURPOSE;
21+
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.FILE_NAME;
22+
23+
@Slf4j
24+
@RestController
25+
public class BatchTransactionsController implements BatchTransactions {
26+
27+
@Autowired
28+
private ProducerTemplate producerTemplate;
29+
30+
@Autowired
31+
ObjectMapper objectMapper;
32+
33+
@Autowired
34+
FileStorageService fileStorageService;
35+
36+
@SneakyThrows
37+
@Override
38+
public String batchTransactions(HttpServletResponse httpServletResponse,
39+
String requestId, MultipartFile file, String fileName,
40+
String purpose, String type, String tenant) throws IOException {
41+
log.info("Inside api logic");
42+
String localFileName = fileStorageService.save(file);
43+
Headers headers = new Headers.HeaderBuilder()
44+
.addHeader("X-CorrelationID", requestId)
45+
.addHeader(PURPOSE,purpose)
46+
.addHeader(FILE_NAME,localFileName)
47+
.addHeader("Type",type)
48+
.addHeader("Platform-TenantId",tenant)
49+
.build();
50+
51+
Exchange exchange = SpringWrapperUtil.getDefaultWrappedExchange(producerTemplate.getCamelContext(),
52+
headers);
53+
exchange = producerTemplate.send("direct:post-batch-transactions", exchange);
54+
int statusCode = exchange.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class);
55+
httpServletResponse.setStatus(statusCode);
56+
return exchange.getIn().getBody(String.class);
57+
}
58+
59+
@ExceptionHandler({MultipartException.class})
60+
public String handleMultipartException(HttpServletResponse httpServletResponse) {
61+
JSONObject json = new JSONObject();
62+
json.put("Error Information: ", "File not uploaded");
63+
json.put("Error Description : ", "There was no fie uploaded with the request. " +
64+
"Please upload a file and try again.");
65+
httpServletResponse.setStatus(httpServletResponse.SC_BAD_REQUEST);
66+
return json.toString();
67+
}
68+
69+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.mifos.processor.bulk.api.implementation;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import org.apache.camel.Exchange;
5+
import org.apache.camel.ProducerTemplate;
6+
import org.mifos.processor.bulk.api.definition.BulkTransfer;
7+
import org.mifos.processor.bulk.file.FileStorageService;
8+
import org.mifos.processor.bulk.utility.Headers;
9+
import org.mifos.processor.bulk.utility.SpringWrapperUtil;
10+
import org.springframework.beans.factory.annotation.Autowired;
11+
import org.springframework.web.bind.annotation.RestController;
12+
import org.springframework.web.multipart.MultipartFile;
13+
14+
import java.io.IOException;
15+
16+
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.FILE_NAME;
17+
import static org.mifos.processor.bulk.zeebe.ZeebeVariables.PURPOSE;
18+
19+
@RestController
20+
public class BulkTransferController implements BulkTransfer {
21+
@Autowired
22+
private ProducerTemplate producerTemplate;
23+
24+
@Autowired
25+
ObjectMapper objectMapper;
26+
27+
@Autowired
28+
FileStorageService fileStorageService;
29+
30+
@Override
31+
public String bulkTransfer(String requestId, MultipartFile file, String fileName, String purpose, String type, String tenant) throws IOException {
32+
Headers headers = new Headers.HeaderBuilder()
33+
.addHeader("X-CorrelationID", requestId)
34+
.addHeader(PURPOSE,purpose)
35+
.addHeader(FILE_NAME,fileName)
36+
.addHeader("Type",type)
37+
.addHeader("Platform-TenantId",tenant)
38+
.build();
39+
Exchange exchange = SpringWrapperUtil.getDefaultWrappedExchange(producerTemplate.getCamelContext(),
40+
headers);
41+
fileStorageService.save(file);
42+
producerTemplate.send("direct:post-bulk-transfer", exchange);
43+
return exchange.getIn().getBody(String.class);
44+
}
45+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.mifos.processor.bulk.api.implementation;
2+
3+
import org.mifos.processor.bulk.api.definition.Simulate;
4+
import org.springframework.web.bind.annotation.RestController;
5+
import javax.servlet.http.HttpServletResponse;
6+
7+
@RestController
8+
public class SimulateApiController implements Simulate {
9+
10+
@Override
11+
public void simulate(HttpServletResponse httpServletResponse) {
12+
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
13+
}
14+
}

src/main/java/org/mifos/processor/bulk/api/ApiOriginFilter.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,12 @@
1111
import org.slf4j.Logger;
1212
import org.slf4j.LoggerFactory;
1313
import org.springframework.stereotype.Component;
14+
import org.springframework.web.filter.GenericFilterBean;
1415

15-
@Component
16-
public class ApiOriginFilter implements Filter {
16+
public class ApiOriginFilter extends GenericFilterBean {
1717

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

20-
@Override
21-
public void init(FilterConfig filterConfig) throws ServletException {
22-
23-
}
24-
2520
@Override
2621
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
2722
HttpServletRequest req = (HttpServletRequest) request;
@@ -30,8 +25,4 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
3025
logger.info("Client IP Address: {}",req.getRemoteHost());
3126
}
3227

33-
@Override
34-
public void destroy() {
35-
36-
}
3728
}

0 commit comments

Comments
 (0)