From cee45478d8153827f3e625f543ace2ba34d00bb8 Mon Sep 17 00:00:00 2001 From: cascode09 Date: Sat, 20 Jul 2024 08:58:41 -0500 Subject: [PATCH 1/2] Update README.md update readme --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/README.md b/README.md index 7fa60f9..00cc97a 100644 --- a/README.md +++ b/README.md @@ -78,3 +78,51 @@ Puede utilizar cualquier método para almacenar datos de transacciones, pero deb Cuando termines tu resolución, después de realizar el fork al repositorio, tú **debes** abrir una solicitud de extracción (PR) a nuestro repositorio. No hay limitaciones para la implementación, puede seguir el paradigma de programación, la modularización y el estilo que creas que es la solución más adecuada. Si tienes alguna duda, por favor ponte en contacto con nosotros. + + +# Curls usados +## caso 1: cuando el valor es mayor a 1000 + +curl --location --request POST 'http://localhost:8081/transactions' \ +--header 'Content-Type: application/json' \ +--data-raw '{ + "accountExternalIdDebit": "feae0e99-2050-4b2c-b344-4ca093ade411", + "accountExternalIdCredit": "17b67b9b-8dd8-413e-9ede-c9451ad2363d", + "transferTypeId": 1, + "value": 1200.00 +}' + +## caso 2: cuando el valor es menor a 1000 +curl --location --request POST 'http://localhost:8081/transactions' \ +--header 'Content-Type: application/json' \ +--data-raw '{ + "accountExternalIdDebit": "feae0e99-2050-4b2c-b344-4ca093ade411", + "accountExternalIdCredit": "17b67b9b-8dd8-413e-9ede-c9451ad2363d", + "transferTypeId": 1, + "value": 750.00 +}' + +## visualizar una transacción +curl --location --request GET 'http://localhost:8081/transactions/49428321-8728-4780-a114-28c5ecb97713' + + + +## captura de como llegaba la data a los topicos (se uso la herramienta Offset Explorer) +![image](https://github.com/user-attachments/assets/cd17b479-e458-40b1-830d-c4f99ce2e9f2) + +## sql - creacion de tabla transactions +
+CREATE TABLE 
+    transactions 
+    ( 
+        id                         CHARACTER VARYING NOT NULL, 
+        account_external_id_debit  CHARACTER VARYING, 
+        account_external_id_credit CHARACTER VARYING, 
+        transfer_type_id           INTEGER, 
+        value                      NUMERIC, 
+        status                     CHARACTER VARYING, 
+        created_at                 TIMESTAMP(6) WITH TIME ZONE, 
+        PRIMARY KEY (id) 
+    );
+
+
From 0dc476ac2f08bcd9cd1f1ba4b6e2c555a4fb8ec6 Mon Sep 17 00:00:00 2001 From: Carlos Sandoval Date: Sat, 20 Jul 2024 09:03:10 -0500 Subject: [PATCH 2/2] component Transaction and Antifraud --- ms-antifraud/.gitignore | 158 +++++++++++ .../.mvn/wrapper/maven-wrapper.properties | 19 ++ ms-antifraud/HELP.md | 16 ++ ms-antifraud/mvnw | 259 ++++++++++++++++++ ms-antifraud/mvnw.cmd | 149 ++++++++++ ms-antifraud/pom.xml | 49 ++++ .../com/nttdata/MsAntifraudApplication.java | 13 + .../main/java/com/nttdata/helper/Util.java | 26 ++ .../nttdata/service/TransactionService.java | 26 ++ .../topic/client/TransactionConsumer.java | 49 ++++ .../topic/client/TransactionProducer.java | 42 +++ .../message/TransactionCreatedMessage.java | 19 ++ .../src/main/resources/application.properties | 17 ++ .../nttdata/MsAntifraudApplicationTests.java | 13 + ms-transaction/.gitignore | 158 +++++++++++ .../.mvn/wrapper/maven-wrapper.properties | 19 ++ ms-transaction/HELP.md | 16 ++ ms-transaction/mvnw | 259 ++++++++++++++++++ ms-transaction/mvnw.cmd | 149 ++++++++++ ms-transaction/pom.xml | 57 ++++ .../com/nttdata/MsTransactionApplication.java | 13 + .../controller/TransactionController.java | 32 +++ .../controller/request/TransactionReq.java | 20 ++ .../response/CreateTransactionRes.java | 13 + .../controller/response/TransactionRes.java | 35 +++ .../java/com/nttdata/entity/Transaction.java | 40 +++ .../main/java/com/nttdata/helper/Util.java | 43 +++ .../repository/TransactionRepository.java | 18 ++ .../nttdata/service/TransactionService.java | 82 ++++++ .../service/mapper/TransactionMapper.java | 20 ++ .../topic/client/AntifraudConsumer.java | 29 ++ .../topic/client/AntifraudProducer.java | 40 +++ .../message/TransactionCreatedMessage.java | 15 + .../src/main/resources/application.properties | 25 ++ .../MsTransactionApplicationTests.java | 13 + 35 files changed, 1951 insertions(+) create mode 100644 ms-antifraud/.gitignore create mode 100644 ms-antifraud/.mvn/wrapper/maven-wrapper.properties create mode 100644 ms-antifraud/HELP.md create mode 100755 ms-antifraud/mvnw create mode 100644 ms-antifraud/mvnw.cmd create mode 100644 ms-antifraud/pom.xml create mode 100644 ms-antifraud/src/main/java/com/nttdata/MsAntifraudApplication.java create mode 100644 ms-antifraud/src/main/java/com/nttdata/helper/Util.java create mode 100644 ms-antifraud/src/main/java/com/nttdata/service/TransactionService.java create mode 100644 ms-antifraud/src/main/java/com/nttdata/topic/client/TransactionConsumer.java create mode 100644 ms-antifraud/src/main/java/com/nttdata/topic/client/TransactionProducer.java create mode 100644 ms-antifraud/src/main/java/com/nttdata/topic/message/TransactionCreatedMessage.java create mode 100644 ms-antifraud/src/main/resources/application.properties create mode 100644 ms-antifraud/src/test/java/com/nttdata/MsAntifraudApplicationTests.java create mode 100644 ms-transaction/.gitignore create mode 100644 ms-transaction/.mvn/wrapper/maven-wrapper.properties create mode 100644 ms-transaction/HELP.md create mode 100755 ms-transaction/mvnw create mode 100644 ms-transaction/mvnw.cmd create mode 100644 ms-transaction/pom.xml create mode 100644 ms-transaction/src/main/java/com/nttdata/MsTransactionApplication.java create mode 100644 ms-transaction/src/main/java/com/nttdata/controller/TransactionController.java create mode 100644 ms-transaction/src/main/java/com/nttdata/controller/request/TransactionReq.java create mode 100644 ms-transaction/src/main/java/com/nttdata/controller/response/CreateTransactionRes.java create mode 100644 ms-transaction/src/main/java/com/nttdata/controller/response/TransactionRes.java create mode 100644 ms-transaction/src/main/java/com/nttdata/entity/Transaction.java create mode 100644 ms-transaction/src/main/java/com/nttdata/helper/Util.java create mode 100644 ms-transaction/src/main/java/com/nttdata/repository/TransactionRepository.java create mode 100644 ms-transaction/src/main/java/com/nttdata/service/TransactionService.java create mode 100644 ms-transaction/src/main/java/com/nttdata/service/mapper/TransactionMapper.java create mode 100644 ms-transaction/src/main/java/com/nttdata/topic/client/AntifraudConsumer.java create mode 100644 ms-transaction/src/main/java/com/nttdata/topic/client/AntifraudProducer.java create mode 100644 ms-transaction/src/main/java/com/nttdata/topic/message/TransactionCreatedMessage.java create mode 100644 ms-transaction/src/main/resources/application.properties create mode 100644 ms-transaction/src/test/java/com/nttdata/MsTransactionApplicationTests.java diff --git a/ms-antifraud/.gitignore b/ms-antifraud/.gitignore new file mode 100644 index 0000000..4d618f1 --- /dev/null +++ b/ms-antifraud/.gitignore @@ -0,0 +1,158 @@ +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# Azure Toolkit for IntelliJ plugin +# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij +.idea/**/azureSettings.xml + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +# https://github.com/takari/maven-wrapper#usage-without-binary-jar +.mvn/wrapper/maven-wrapper.jar + +# Eclipse m2e generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath +/.idea/ diff --git a/ms-antifraud/.mvn/wrapper/maven-wrapper.properties b/ms-antifraud/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..8f96f52 --- /dev/null +++ b/ms-antifraud/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.7/apache-maven-3.9.7-bin.zip diff --git a/ms-antifraud/HELP.md b/ms-antifraud/HELP.md new file mode 100644 index 0000000..3910a98 --- /dev/null +++ b/ms-antifraud/HELP.md @@ -0,0 +1,16 @@ +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) +* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.3.2/maven-plugin/reference/html/) +* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.3.2/maven-plugin/reference/html/#build-image) + +### Maven Parent overrides + +Due to Maven's design, elements are inherited from the parent POM to the project POM. +While most of the inheritance is fine, it also inherits unwanted elements like `` and `` from the parent. +To prevent this, the project POM contains empty overrides for these elements. +If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides. + diff --git a/ms-antifraud/mvnw b/ms-antifraud/mvnw new file mode 100755 index 0000000..d7c358e --- /dev/null +++ b/ms-antifraud/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/ms-antifraud/mvnw.cmd b/ms-antifraud/mvnw.cmd new file mode 100644 index 0000000..6f779cf --- /dev/null +++ b/ms-antifraud/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/ms-antifraud/pom.xml b/ms-antifraud/pom.xml new file mode 100644 index 0000000..9be1208 --- /dev/null +++ b/ms-antifraud/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 3.3.2 + + + + com.nttdata + ms-antifraud + 0.0.1-SNAPSHOT + ms-antifraud + Antifraud Component + + + 17 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.kafka + spring-kafka + + + org.projectlombok + lombok + 1.18.34 + provided + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/ms-antifraud/src/main/java/com/nttdata/MsAntifraudApplication.java b/ms-antifraud/src/main/java/com/nttdata/MsAntifraudApplication.java new file mode 100644 index 0000000..3d5c45a --- /dev/null +++ b/ms-antifraud/src/main/java/com/nttdata/MsAntifraudApplication.java @@ -0,0 +1,13 @@ +package com.nttdata; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MsAntifraudApplication { + + public static void main(String[] args) { + SpringApplication.run(MsAntifraudApplication.class, args); + } + +} diff --git a/ms-antifraud/src/main/java/com/nttdata/helper/Util.java b/ms-antifraud/src/main/java/com/nttdata/helper/Util.java new file mode 100644 index 0000000..c0d4f64 --- /dev/null +++ b/ms-antifraud/src/main/java/com/nttdata/helper/Util.java @@ -0,0 +1,26 @@ +package com.nttdata.helper; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import lombok.AllArgsConstructor; +import lombok.Getter; + +public class Util { + + @Getter + @AllArgsConstructor + public enum transferType { + TRANSFER(1, "TRANSFER"), + DEPOSIT(2, "DEPOSIT"), + ITF(3, "ITF"); + + private final Integer code; + private final String name; + + } + +} diff --git a/ms-antifraud/src/main/java/com/nttdata/service/TransactionService.java b/ms-antifraud/src/main/java/com/nttdata/service/TransactionService.java new file mode 100644 index 0000000..7dcd11f --- /dev/null +++ b/ms-antifraud/src/main/java/com/nttdata/service/TransactionService.java @@ -0,0 +1,26 @@ +package com.nttdata.service; + +import com.nttdata.topic.client.TransactionProducer; +import com.nttdata.topic.message.TransactionCreatedMessage; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; + +@Service +public class TransactionService { + + private final TransactionProducer transactionProducer; + + public TransactionService(TransactionProducer transactionProducer) { + this.transactionProducer = transactionProducer; + } + + public void validate(TransactionCreatedMessage transaction) { + if (transaction.getValue().compareTo(BigDecimal.valueOf(1000)) > 0) + transactionProducer.transaccionRejectedMessage(transaction.getTransactionExternalId()); + else + transactionProducer.transactionApprovedMessage(transaction.getTransactionExternalId()); + + } + +} diff --git a/ms-antifraud/src/main/java/com/nttdata/topic/client/TransactionConsumer.java b/ms-antifraud/src/main/java/com/nttdata/topic/client/TransactionConsumer.java new file mode 100644 index 0000000..9a166db --- /dev/null +++ b/ms-antifraud/src/main/java/com/nttdata/topic/client/TransactionConsumer.java @@ -0,0 +1,49 @@ +package com.nttdata.topic.client; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.nttdata.service.TransactionService; +import com.nttdata.topic.message.TransactionCreatedMessage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.stereotype.Component; + +@Component +public class TransactionConsumer { + Logger logger = LoggerFactory.getLogger(this.getClass()); + + private final TransactionService transactionService; + + public TransactionConsumer(TransactionService transactionService) { + this.transactionService = transactionService; + } + + @KafkaListener(topics = "${kafka.topic.transactions.trx-topic-consumer}") + public void consumeTransactionCreatedMessage(String message) { + TransactionCreatedMessage transaction = jsonToTransactionCreatedMessage(message); + logger.info("Received transaction created message: {}", transaction); + transactionService.validate(transaction); + } + + public static TransactionCreatedMessage jsonToTransactionCreatedMessage(String message) { + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + mapper.registerModule(new Jdk8Module()); + mapper.registerModule(new JavaTimeModule()); + + return mapper.readValue(message, TransactionCreatedMessage.class); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } catch (Exception e) { + throw new RuntimeException(e); + } + + } +} diff --git a/ms-antifraud/src/main/java/com/nttdata/topic/client/TransactionProducer.java b/ms-antifraud/src/main/java/com/nttdata/topic/client/TransactionProducer.java new file mode 100644 index 0000000..e1a35a4 --- /dev/null +++ b/ms-antifraud/src/main/java/com/nttdata/topic/client/TransactionProducer.java @@ -0,0 +1,42 @@ +package com.nttdata.topic.client; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.stereotype.Component; + +@Component +public class TransactionProducer { + + Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Value("${kafka.topic.transactions.trx-rejected-producer}") + private String trxRejectedProducer; + + @Value("${kafka.topic.transactions.trx-approved-producer}") + private String trxApprovedProducer; + + private final KafkaTemplate kafkaTemplate; + + public TransactionProducer(KafkaTemplate kafkaTemplate) { + this.kafkaTemplate = kafkaTemplate; + } + + public void transactionApprovedMessage(String transactionId) { + try { + kafkaTemplate.send(trxApprovedProducer, transactionId); + } catch (Exception e) { + logger.info(e.getMessage()); + } + } + + public void transaccionRejectedMessage(String transactionId) { + try { + kafkaTemplate.send(trxRejectedProducer, transactionId); + } catch (Exception e) { + logger.info(e.getMessage()); + } + + } +} diff --git a/ms-antifraud/src/main/java/com/nttdata/topic/message/TransactionCreatedMessage.java b/ms-antifraud/src/main/java/com/nttdata/topic/message/TransactionCreatedMessage.java new file mode 100644 index 0000000..d560234 --- /dev/null +++ b/ms-antifraud/src/main/java/com/nttdata/topic/message/TransactionCreatedMessage.java @@ -0,0 +1,19 @@ +package com.nttdata.topic.message; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Data +public class TransactionCreatedMessage { + + private String transactionExternalId; + private BigDecimal value; + +} \ No newline at end of file diff --git a/ms-antifraud/src/main/resources/application.properties b/ms-antifraud/src/main/resources/application.properties new file mode 100644 index 0000000..c7f1525 --- /dev/null +++ b/ms-antifraud/src/main/resources/application.properties @@ -0,0 +1,17 @@ +spring.application.name=ms-antifraud +server.port=8082 + +# Configuración de Kafka +spring.kafka.bootstrap-servers=localhost:9092 +spring.kafka.consumer.group-id=transactions-group +spring.kafka.consumer.key-serializer=org.apache.kafka.common.serialization.StringSerializer +spring.kafka.consumer.value-serializer=org.apache.kafka.common.serialization.StringSerializer +spring.kafka.consumer.auto-offset-reset=earliest +spring.kafka.consumer.enable-auto-commit=true +spring.kafka.consumer.properties.max.poll.records=500 +#spring.kafka.consumer.properties.max.poll.interval.ms=500 +spring.kafka.producer.properties.compression.type=gzip + +kafka.topic.transactions.trx-topic-consumer=transactions-topic +kafka.topic.transactions.trx-rejected-producer=antifraud-trx-rejected-topic +kafka.topic.transactions.trx-approved-producer=antifraud-trx-approved-topic \ No newline at end of file diff --git a/ms-antifraud/src/test/java/com/nttdata/MsAntifraudApplicationTests.java b/ms-antifraud/src/test/java/com/nttdata/MsAntifraudApplicationTests.java new file mode 100644 index 0000000..4082262 --- /dev/null +++ b/ms-antifraud/src/test/java/com/nttdata/MsAntifraudApplicationTests.java @@ -0,0 +1,13 @@ +package com.nttdata; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class MsAntifraudApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/ms-transaction/.gitignore b/ms-transaction/.gitignore new file mode 100644 index 0000000..4d618f1 --- /dev/null +++ b/ms-transaction/.gitignore @@ -0,0 +1,158 @@ +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# Azure Toolkit for IntelliJ plugin +# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij +.idea/**/azureSettings.xml + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +# https://github.com/takari/maven-wrapper#usage-without-binary-jar +.mvn/wrapper/maven-wrapper.jar + +# Eclipse m2e generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath +/.idea/ diff --git a/ms-transaction/.mvn/wrapper/maven-wrapper.properties b/ms-transaction/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..8f96f52 --- /dev/null +++ b/ms-transaction/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.7/apache-maven-3.9.7-bin.zip diff --git a/ms-transaction/HELP.md b/ms-transaction/HELP.md new file mode 100644 index 0000000..3910a98 --- /dev/null +++ b/ms-transaction/HELP.md @@ -0,0 +1,16 @@ +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) +* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.3.2/maven-plugin/reference/html/) +* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.3.2/maven-plugin/reference/html/#build-image) + +### Maven Parent overrides + +Due to Maven's design, elements are inherited from the parent POM to the project POM. +While most of the inheritance is fine, it also inherits unwanted elements like `` and `` from the parent. +To prevent this, the project POM contains empty overrides for these elements. +If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides. + diff --git a/ms-transaction/mvnw b/ms-transaction/mvnw new file mode 100755 index 0000000..d7c358e --- /dev/null +++ b/ms-transaction/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/ms-transaction/mvnw.cmd b/ms-transaction/mvnw.cmd new file mode 100644 index 0000000..6f779cf --- /dev/null +++ b/ms-transaction/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/ms-transaction/pom.xml b/ms-transaction/pom.xml new file mode 100644 index 0000000..ca9bab2 --- /dev/null +++ b/ms-transaction/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 3.3.2 + + + + com.nttdata + ms-transaction + 0.0.1-SNAPSHOT + ms-transaction + Transaction Component + + + 17 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.postgresql + postgresql + + + org.springframework.kafka + spring-kafka + + + org.projectlombok + lombok + 1.18.34 + provided + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/ms-transaction/src/main/java/com/nttdata/MsTransactionApplication.java b/ms-transaction/src/main/java/com/nttdata/MsTransactionApplication.java new file mode 100644 index 0000000..45b1cc8 --- /dev/null +++ b/ms-transaction/src/main/java/com/nttdata/MsTransactionApplication.java @@ -0,0 +1,13 @@ +package com.nttdata; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MsTransactionApplication { + + public static void main(String[] args) { + SpringApplication.run(MsTransactionApplication.class, args); + } + +} diff --git a/ms-transaction/src/main/java/com/nttdata/controller/TransactionController.java b/ms-transaction/src/main/java/com/nttdata/controller/TransactionController.java new file mode 100644 index 0000000..7391f52 --- /dev/null +++ b/ms-transaction/src/main/java/com/nttdata/controller/TransactionController.java @@ -0,0 +1,32 @@ +package com.nttdata.controller; + +import com.nttdata.controller.request.TransactionReq; +import com.nttdata.controller.response.CreateTransactionRes; +import com.nttdata.controller.response.TransactionRes; +import com.nttdata.service.TransactionService; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/transactions") +public class TransactionController { + + private final TransactionService transactionService; + + public TransactionController(TransactionService transactionService) { + this.transactionService = transactionService; + } + + @PostMapping + public ResponseEntity createTransaction(@RequestBody TransactionReq request) { + CreateTransactionRes response = transactionService.createTransaction(request); + return ResponseEntity.ok(response); + } + + @GetMapping("/{transactionId}") + public ResponseEntity getTransaction(@PathVariable String transactionId) { + TransactionRes response = transactionService.getTransaction(transactionId); + return ResponseEntity.ok(response); + } + +} diff --git a/ms-transaction/src/main/java/com/nttdata/controller/request/TransactionReq.java b/ms-transaction/src/main/java/com/nttdata/controller/request/TransactionReq.java new file mode 100644 index 0000000..67b19f0 --- /dev/null +++ b/ms-transaction/src/main/java/com/nttdata/controller/request/TransactionReq.java @@ -0,0 +1,20 @@ +package com.nttdata.controller.request; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.math.BigDecimal; + +@Getter +@Setter +@NoArgsConstructor +@JsonSerialize +public class TransactionReq { + + private String accountExternalIdDebit; + private String accountExternalIdCredit; + private Integer transferTypeId; + private BigDecimal value; +} diff --git a/ms-transaction/src/main/java/com/nttdata/controller/response/CreateTransactionRes.java b/ms-transaction/src/main/java/com/nttdata/controller/response/CreateTransactionRes.java new file mode 100644 index 0000000..a1733b0 --- /dev/null +++ b/ms-transaction/src/main/java/com/nttdata/controller/response/CreateTransactionRes.java @@ -0,0 +1,13 @@ +package com.nttdata.controller.response; + + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class CreateTransactionRes { + String mensaje; +} diff --git a/ms-transaction/src/main/java/com/nttdata/controller/response/TransactionRes.java b/ms-transaction/src/main/java/com/nttdata/controller/response/TransactionRes.java new file mode 100644 index 0000000..beab4fd --- /dev/null +++ b/ms-transaction/src/main/java/com/nttdata/controller/response/TransactionRes.java @@ -0,0 +1,35 @@ +package com.nttdata.controller.response; + +import com.nttdata.entity.Transaction; +import jakarta.persistence.Column; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import lombok.*; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Data +public class TransactionRes { + + private String transactionExternalId; + private TransactionType transactionType; + private TransactionStatus transactionStatus; + private BigDecimal value; + private LocalDateTime createdAt; + + @Builder + @Data + public static class TransactionType { + private String name; + } + + @Builder + @Data + public static class TransactionStatus { + private String name; + } +} diff --git a/ms-transaction/src/main/java/com/nttdata/entity/Transaction.java b/ms-transaction/src/main/java/com/nttdata/entity/Transaction.java new file mode 100644 index 0000000..b970ab4 --- /dev/null +++ b/ms-transaction/src/main/java/com/nttdata/entity/Transaction.java @@ -0,0 +1,40 @@ +package com.nttdata.entity; + +import jakarta.persistence.*; +import lombok.*; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Entity +@Table(name = "transactions") +public class Transaction { + + @Id + @GeneratedValue(strategy = GenerationType.UUID) + private String id; + + @Column(name = "account_external_id_debit") + private String accountExternalIdDebit; + + @Column(name = "account_external_id_credit") + private String accountExternalIdCredit; + + @Column(name = "transfer_type_id") + private int transferTypeId; + + @Column(name = "value") + private BigDecimal value; + + @Column(name = "status") + private String status; + + @Column(name = "created_at") + private LocalDateTime createdAt; + +} \ No newline at end of file diff --git a/ms-transaction/src/main/java/com/nttdata/helper/Util.java b/ms-transaction/src/main/java/com/nttdata/helper/Util.java new file mode 100644 index 0000000..520b07f --- /dev/null +++ b/ms-transaction/src/main/java/com/nttdata/helper/Util.java @@ -0,0 +1,43 @@ +package com.nttdata.helper; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import lombok.AllArgsConstructor; +import lombok.Getter; + +public class Util { + + public static String toJsonString(Object object) throws JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + mapper.registerModule(new Jdk8Module()); + mapper.registerModule(new JavaTimeModule()); + return mapper.writeValueAsString(object); + } + + @Getter + @AllArgsConstructor + public enum transferType { + TRANSFER(1, "TRANSFER"), + DEPOSIT(2, "DEPOSIT"), + ITF(3, "ITF"); + + private final Integer code; + private final String name; + + } + + @Getter + @AllArgsConstructor + public enum TransactionStatus { + PENDING, + APPROVED, + REJECTED + } + +} diff --git a/ms-transaction/src/main/java/com/nttdata/repository/TransactionRepository.java b/ms-transaction/src/main/java/com/nttdata/repository/TransactionRepository.java new file mode 100644 index 0000000..f39e1b0 --- /dev/null +++ b/ms-transaction/src/main/java/com/nttdata/repository/TransactionRepository.java @@ -0,0 +1,18 @@ +package com.nttdata.repository; + +import com.nttdata.entity.Transaction; +import jakarta.transaction.Transactional; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +@Repository +public interface TransactionRepository extends JpaRepository { + + @Modifying + @Transactional + @Query("UPDATE Transaction e SET e.status = :status WHERE e.id = :transactionId") + int updateStatusById(String transactionId, String status); + +} \ No newline at end of file diff --git a/ms-transaction/src/main/java/com/nttdata/service/TransactionService.java b/ms-transaction/src/main/java/com/nttdata/service/TransactionService.java new file mode 100644 index 0000000..dfbd68e --- /dev/null +++ b/ms-transaction/src/main/java/com/nttdata/service/TransactionService.java @@ -0,0 +1,82 @@ +package com.nttdata.service; + +import com.nttdata.controller.request.TransactionReq; +import com.nttdata.controller.response.CreateTransactionRes; +import com.nttdata.controller.response.TransactionRes; +import com.nttdata.entity.Transaction; +import com.nttdata.helper.Util; +import com.nttdata.repository.TransactionRepository; +import com.nttdata.service.mapper.TransactionMapper; +import com.nttdata.topic.client.AntifraudProducer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import java.util.Optional; + +@Service +public class TransactionService { + + Logger logger = LoggerFactory.getLogger(this.getClass()); + + private final TransactionRepository transactionRepository; + private final AntifraudProducer antifraudProducer; + + public TransactionService(TransactionRepository transactionRepository, AntifraudProducer antifraudProducer) { + this.transactionRepository = transactionRepository; + this.antifraudProducer = antifraudProducer; + } + + public CreateTransactionRes createTransaction(TransactionReq request) { + try { + Transaction transaction = TransactionMapper.TransactionRequestMapperToTransaction(request); + Transaction transactionSaved = transactionRepository.save(transaction); + antifraudProducer.sendTransactionCreatedMessage(transactionSaved); + CreateTransactionRes response = new CreateTransactionRes(); + response.setMensaje("Transaccion creada correctamente id : " + transactionSaved.getId()); + return response; + } catch (Exception e) { + logger.info(e.getMessage()); + CreateTransactionRes response = new CreateTransactionRes(); + response.setMensaje("Transaction no pudo ser realizada"); + return response; + } + } + + public TransactionRes getTransaction(String transactionId) { + Optional optionalTransaction = transactionRepository.findById(transactionId); + Transaction transaction = optionalTransaction.orElse(null); + + return TransactionRes.builder() + .transactionExternalId(transaction.getId()) + .transactionType(TransactionRes.TransactionType.builder().name( + Util.transferType.TRANSFER.getCode().compareTo(transaction.getTransferTypeId()) == 0 + ? Util.transferType.TRANSFER.getName() : "NOTYPE" + ).build()) + .transactionStatus(TransactionRes.TransactionStatus.builder().name(transaction.getStatus()).build()) + .value(transaction.getValue()) + .createdAt(transaction.getCreatedAt()).build(); + } + + public void updateApprovedTransaction(String code) { + int filasAfectadas = transactionRepository.updateStatusById(code, Util.TransactionStatus.APPROVED.name()); + if (filasAfectadas > 0) + logger.info("Se actualizo el estado a APPROVED de la transaccion {} : ", code); + else + logger.info("No actualizo el estado a APPROVED de la transaccion {} : ", code); + } + + public void updateRejectedTransaction(String code) { + try { + int filasAfectadas = transactionRepository.updateStatusById(code, Util.TransactionStatus.REJECTED.name()); + if (filasAfectadas > 0) + logger.info("Se actualizo el estado a REJECTED de la transaccion {} : ", code); + else + logger.info("No actualizo el estado a REJECTED de la transaccion {} : ", code); + } catch (Exception e) { + logger.info(e.getMessage()); + } + + } + +} \ No newline at end of file diff --git a/ms-transaction/src/main/java/com/nttdata/service/mapper/TransactionMapper.java b/ms-transaction/src/main/java/com/nttdata/service/mapper/TransactionMapper.java new file mode 100644 index 0000000..54db4f7 --- /dev/null +++ b/ms-transaction/src/main/java/com/nttdata/service/mapper/TransactionMapper.java @@ -0,0 +1,20 @@ +package com.nttdata.service.mapper; + +import com.nttdata.controller.request.TransactionReq; +import com.nttdata.entity.Transaction; +import com.nttdata.helper.Util; + +import java.time.LocalDateTime; + +public class TransactionMapper { + + public static Transaction TransactionRequestMapperToTransaction(TransactionReq request) { + return Transaction.builder() + .accountExternalIdDebit(request.getAccountExternalIdDebit()) + .accountExternalIdCredit(request.getAccountExternalIdCredit()) + .transferTypeId(request.getTransferTypeId()) + .value(request.getValue()) + .status(Util.TransactionStatus.PENDING.name()) + .createdAt(LocalDateTime.now()).build(); + } +} diff --git a/ms-transaction/src/main/java/com/nttdata/topic/client/AntifraudConsumer.java b/ms-transaction/src/main/java/com/nttdata/topic/client/AntifraudConsumer.java new file mode 100644 index 0000000..a31f108 --- /dev/null +++ b/ms-transaction/src/main/java/com/nttdata/topic/client/AntifraudConsumer.java @@ -0,0 +1,29 @@ +package com.nttdata.topic.client; + +import com.nttdata.service.TransactionService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.stereotype.Component; + +@Component +public class AntifraudConsumer { + Logger logger = LoggerFactory.getLogger(this.getClass()); + + private final TransactionService transactionService; + + public AntifraudConsumer(TransactionService transactionService) { + this.transactionService = transactionService; + } + + @KafkaListener(topics = "${kafka.topic.transactions.trx-rejected-consumer}") + public void transactionRejectedTopic(String transactionId) { + transactionService.updateRejectedTransaction(transactionId); + } + + @KafkaListener(topics = "${kafka.topic.transactions.trx-approved-consumer}") + public void transactionApprovedTopic(String transactionId) { + transactionService.updateApprovedTransaction(transactionId); + } + +} diff --git a/ms-transaction/src/main/java/com/nttdata/topic/client/AntifraudProducer.java b/ms-transaction/src/main/java/com/nttdata/topic/client/AntifraudProducer.java new file mode 100644 index 0000000..3c76782 --- /dev/null +++ b/ms-transaction/src/main/java/com/nttdata/topic/client/AntifraudProducer.java @@ -0,0 +1,40 @@ +package com.nttdata.topic.client; + +import com.nttdata.entity.Transaction; +import com.nttdata.helper.Util; +import com.nttdata.topic.message.TransactionCreatedMessage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.stereotype.Component; + +@Component +public class AntifraudProducer { + + Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Value("${kafka.topic.transactions.trx-topic-producer}") + private String trxTopicProducer; + + private final KafkaTemplate kafkaTemplate; + + public AntifraudProducer(KafkaTemplate kafkaTemplate) { + this.kafkaTemplate = kafkaTemplate; + } + + public void sendTransactionCreatedMessage(Transaction transaction) { + try { + TransactionCreatedMessage messageDto = TransactionCreatedMessage.builder() + .transactionExternalId(transaction.getId()) + .value(transaction.getValue()).build(); + + String message = Util.toJsonString(messageDto); + + kafkaTemplate.send(trxTopicProducer, message); + } catch (Exception e) { + logger.info(e.getMessage()); + } + + } +} diff --git a/ms-transaction/src/main/java/com/nttdata/topic/message/TransactionCreatedMessage.java b/ms-transaction/src/main/java/com/nttdata/topic/message/TransactionCreatedMessage.java new file mode 100644 index 0000000..e85a220 --- /dev/null +++ b/ms-transaction/src/main/java/com/nttdata/topic/message/TransactionCreatedMessage.java @@ -0,0 +1,15 @@ +package com.nttdata.topic.message; + +import lombok.Builder; +import lombok.Data; + +import java.math.BigDecimal; + +@Builder +@Data +public class TransactionCreatedMessage { + + private String transactionExternalId; + private BigDecimal value; + +} \ No newline at end of file diff --git a/ms-transaction/src/main/resources/application.properties b/ms-transaction/src/main/resources/application.properties new file mode 100644 index 0000000..204135c --- /dev/null +++ b/ms-transaction/src/main/resources/application.properties @@ -0,0 +1,25 @@ +spring.application.name=ms-transaction +server.port=8081 + +# Configuración de base de datos PostgreSQL +spring.datasource.url=jdbc:postgresql://localhost:5432/transactions +spring.datasource.username=postgres +spring.datasource.password=postgres +spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect + + +# Configuración de Kafka +spring.kafka.bootstrap-servers=localhost:9092 +spring.kafka.consumer.group-id=transactions-group +spring.kafka.consumer.key-serializer=org.apache.kafka.common.serialization.StringSerializer +spring.kafka.consumer.value-serializer=org.apache.kafka.common.serialization.StringSerializer +spring.kafka.consumer.auto-offset-reset=earliest +spring.kafka.consumer.enable-auto-commit=true +spring.kafka.consumer.properties.max.poll.records=500 +#spring.kafka.consumer.properties.max.poll.interval.ms=500 + +spring.kafka.producer.properties.compression.type=gzip + +kafka.topic.transactions.trx-rejected-consumer=antifraud-trx-rejected-topic +kafka.topic.transactions.trx-approved-consumer=antifraud-trx-approved-topic +kafka.topic.transactions.trx-topic-producer=transactions-topic \ No newline at end of file diff --git a/ms-transaction/src/test/java/com/nttdata/MsTransactionApplicationTests.java b/ms-transaction/src/test/java/com/nttdata/MsTransactionApplicationTests.java new file mode 100644 index 0000000..dd7d2a6 --- /dev/null +++ b/ms-transaction/src/test/java/com/nttdata/MsTransactionApplicationTests.java @@ -0,0 +1,13 @@ +package com.nttdata; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class MsTransactionApplicationTests { + + @Test + void contextLoads() { + } + +}