diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 3fa89eb1..00000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java deleted file mode 100644 index a45eb6ba..00000000 --- a/.mvn/wrapper/MavenWrapperDownloader.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2007-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.net.*; -import java.io.*; -import java.nio.channels.*; -import java.util.Properties; - -public class MavenWrapperDownloader { - - private static final String WRAPPER_VERSION = "0.5.6"; - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" - + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; - - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; - - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; - - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if (mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if (mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: " + url); - - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if (!outputFile.getParentFile().exists()) { - if (!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } - - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { - String username = System.getenv("MVNW_USERNAME"); - char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); - Authenticator.setDefault(new Authenticator() { - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(username, password); - } - }); - } - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } - -} diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar deleted file mode 100644 index 2cc7d4a5..00000000 Binary files a/.mvn/wrapper/maven-wrapper.jar and /dev/null differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties deleted file mode 100644 index ffdc10e5..00000000 --- a/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1,2 +0,0 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/build.gradle b/build.gradle index f7a584de..1dc7465e 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ repositories { url = uri('https://repo.maven.apache.org/maven2') } - maven { + maven { url "https://fynarfin.jfrog.io/artifactory/fyn-libs-release-local" } diff --git a/src/.DS_Store b/src/.DS_Store deleted file mode 100644 index eeb17bb1..00000000 Binary files a/src/.DS_Store and /dev/null differ diff --git a/src/main/.DS_Store b/src/main/.DS_Store deleted file mode 100644 index 6b3d8da9..00000000 Binary files a/src/main/.DS_Store and /dev/null differ diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store deleted file mode 100644 index 298f56fa..00000000 Binary files a/src/main/java/.DS_Store and /dev/null differ diff --git a/src/main/java/org/.DS_Store b/src/main/java/org/.DS_Store deleted file mode 100644 index 57e5982b..00000000 Binary files a/src/main/java/org/.DS_Store and /dev/null differ diff --git a/src/main/java/org/mifos/.DS_Store b/src/main/java/org/mifos/.DS_Store deleted file mode 100644 index 83e9905c..00000000 Binary files a/src/main/java/org/mifos/.DS_Store and /dev/null differ diff --git a/src/main/java/org/mifos/processor/bulk/OperationsAppConfig.java b/src/main/java/org/mifos/processor/bulk/OperationsAppConfig.java new file mode 100644 index 00000000..4ac5c5ac --- /dev/null +++ b/src/main/java/org/mifos/processor/bulk/OperationsAppConfig.java @@ -0,0 +1,23 @@ +package org.mifos.processor.bulk; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; + +@Component +public class OperationsAppConfig { + + @Value("${operations-app.contactpoint}") + public String operationAppContactPoint; + + @Value("${operations-app.endpoints.batch-transaction}") + public String batchTransactionEndpoint; + + public String batchTransactionUrl; + + @PostConstruct + private void setup() { + batchTransactionUrl = operationAppContactPoint + batchTransactionEndpoint; + } +} diff --git a/src/main/java/org/mifos/processor/bulk/camel/routes/BaseRouteBuilder.java b/src/main/java/org/mifos/processor/bulk/camel/routes/BaseRouteBuilder.java new file mode 100644 index 00000000..30574a00 --- /dev/null +++ b/src/main/java/org/mifos/processor/bulk/camel/routes/BaseRouteBuilder.java @@ -0,0 +1,57 @@ +package org.mifos.processor.bulk.camel.routes; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.camunda.zeebe.client.ZeebeClient; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.RouteDefinition; +import org.mifos.processor.bulk.OperationsAppConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +public abstract class BaseRouteBuilder extends RouteBuilder { + + @Autowired + public ObjectMapper objectMapper; + + @Autowired + public OperationsAppConfig operationsAppConfig; + + @Autowired + ZeebeClient zeebeClient; + + public Logger logger = LoggerFactory.getLogger(this.getClass()); + + public RouteDefinition getBaseExternalApiRequestRouteDefinition(String routeId, HttpRequestMethod httpMethod) { + return from(String.format("direct:%s", routeId)) + .id(routeId) + .log("Starting external API request route: " + routeId) + .removeHeader("*") + .setHeader(Exchange.HTTP_METHOD, constant(httpMethod.text)) + .setHeader("X-Date", simple(ZonedDateTime.now( ZoneOffset.UTC ).format( DateTimeFormatter.ISO_INSTANT ))) + .setHeader("Content-Type", constant("application/json")); + } + + protected enum HttpRequestMethod { + GET("GET"), + POST("POST"), + PUT("PUT"), + DELETE("DELETE") + ; + + private final String text; + + HttpRequestMethod(String text) { + this.text = text; + } + + @Override + public String toString() { + return text; + } + } +} diff --git a/src/main/java/org/mifos/processor/bulk/camel/routes/ProcessorStartRoute.java b/src/main/java/org/mifos/processor/bulk/camel/routes/ProcessorStartRoute.java new file mode 100644 index 00000000..fd5fa607 --- /dev/null +++ b/src/main/java/org/mifos/processor/bulk/camel/routes/ProcessorStartRoute.java @@ -0,0 +1,50 @@ +package org.mifos.processor.bulk.camel.routes; + +import org.mifos.processor.bulk.zeebe.ZeebeProcessStarter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import static org.mifos.processor.bulk.zeebe.ZeebeVariables.BATCH_ID; + +@Component +public class ProcessorStartRoute extends BaseRouteBuilder{ + + @Autowired + private ZeebeProcessStarter zeebeProcessStarter; + + @Value("${bpmn.flows.bulk-processor}") + private String workflowId; + + private Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Override + public void configure() throws Exception { + setup(); + } + + private void setup() { + from("rest:POST:/bulk/transfer/{requestId}/{fileName}") + .process(exchange -> { + String fileName = exchange.getIn().getHeader("fileName", String.class); + String requestId = exchange.getIn().getHeader("requestId", String.class); + String batchId = UUID.randomUUID().toString(); + + logger.info("\n\n Filename: " + fileName + " \n\n"); + logger.info("\n\n BatchId: " + batchId + " \n\n"); + + Map variables = new HashMap<>(); + variables.put(BATCH_ID, batchId); + variables.put("fileName", fileName); + variables.put("requestId", requestId); + + zeebeProcessStarter.startZeebeWorkflow(workflowId, "", variables); + }); + } +} diff --git a/src/main/java/org/mifos/processor/bulk/camel/routes/Routes.java b/src/main/java/org/mifos/processor/bulk/camel/routes/Routes.java index 7d1f6476..4a594f55 100644 --- a/src/main/java/org/mifos/processor/bulk/camel/routes/Routes.java +++ b/src/main/java/org/mifos/processor/bulk/camel/routes/Routes.java @@ -19,13 +19,7 @@ import static org.mifos.processor.bulk.zeebe.ZeebeVariables.*; @Component -public class Routes extends RouteBuilder { - - @Autowired - ZeebeClient zeebeClient; - - @Value("${operations-app-config.host}") - String operationsAppHost; +public class Routes extends BaseRouteBuilder { @Value("${config.minimum-successful-tx-ratio}") double minimumSuccessfulTxRatio; @@ -42,7 +36,7 @@ private void routeCheckTransactions() { .id(id) .log("Fetching transaction details") //set request params - .to(operationsAppHost+ "/api/v1/batch/transactions") + .toD(operationsAppConfig.batchTransactionEndpoint) .process(exchange -> { // get response body JSONObject transfers = new JSONObject(exchange.getIn().getBody(String.class)); @@ -80,7 +74,7 @@ private void routeSampleTransactions() { .process(exchange -> { exchange.getIn().setHeader("batchId", exchange.getProperty(BATCH_ID)); }) - .toD(operationsAppHost + "/api/v1/batch/transactions") + .toD(operationsAppConfig.batchTransactionEndpoint) .process(exchange -> { // get response body diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index e6a4407b..ea862742 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -27,12 +27,17 @@ zeebe: broker: contactpoint: "zeebe-zeebe-gateway:26500" +operations-app: + contactpoint: "https://ops-bk.ibank.financial" + endpoints: + batch-transaction: "/api/v1/batch/transactions" + cloud: aws: enabled: true credentials: - access-key: ${AWS_ACCESS_KEY:AKIAX32JM37TYOG3QUJU} - secret-key: ${AWS_SECRET_KEY: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} + access-key: ${AWS_ACCESS_KEY:AKIAX32JM37TZOJ5AKFB} + secret-key: ${AWS_SECRET_KEY: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} region: static: us-east-2 stack: @@ -58,9 +63,7 @@ bpmn: international-remittance-payee: "international_remittance_payee_process-{dfspid}" international-remittance-payer: "international_remittance_payer_process-{dfspid}" debit-party-process: "debit_party_process-{dfspid}" - -operations-app-config: - host: "" + bulk-processor: "bulk_processor-ibank-usa" config: - minimum-successful-tx-ratio: 0.90 \ No newline at end of file + minimum-successful-tx-ratio: 0.90 diff --git a/src/test/java/org/mifos/pheeprocessorbulk/BulkProcessorApplicationTests.java b/src/test/java/org/mifos/processor/BulkProcessorApplicationTests.java similarity index 88% rename from src/test/java/org/mifos/pheeprocessorbulk/BulkProcessorApplicationTests.java rename to src/test/java/org/mifos/processor/BulkProcessorApplicationTests.java index 9c62bd7b..db5ed70a 100644 --- a/src/test/java/org/mifos/pheeprocessorbulk/BulkProcessorApplicationTests.java +++ b/src/test/java/org/mifos/processor/BulkProcessorApplicationTests.java @@ -1,4 +1,4 @@ -package org.mifos.pheeprocessorbulk; +package org.mifos.processor; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest;