diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..d40ca01 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..90b9660 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,18 @@ + + + + + postgresql + true + org.postgresql.Driver + jdbc:postgresql://localhost:5432/antifraudedb + + + + + + + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..63e9001 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4731638 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 0000000..f6ae847 --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HELP.md b/HELP.md new file mode 100644 index 0000000..4aeac8b --- /dev/null +++ b/HELP.md @@ -0,0 +1,33 @@ +# 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.1/maven-plugin/reference/html/) +* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.3.1/maven-plugin/reference/html/#build-image) +* [Spring Web](https://docs.spring.io/spring-boot/docs/3.3.1/reference/htmlsingle/index.html#web) +* [Spring Data R2DBC](https://docs.spring.io/spring-boot/docs/3.3.1/reference/htmlsingle/index.html#data.sql.r2dbc) +* [Spring Reactive Web](https://docs.spring.io/spring-boot/docs/3.3.1/reference/htmlsingle/index.html#web.reactive) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) +* [Accessing data with R2DBC](https://spring.io/guides/gs/accessing-data-r2dbc/) +* [Building a Reactive RESTful Web Service](https://spring.io/guides/gs/reactive-rest-service/) + +### Additional Links +These additional references should also help you: + +* [R2DBC Homepage](https://r2dbc.io) + +### 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/mvnw b/mvnw new file mode 100755 index 0000000..d7c358e --- /dev/null +++ b/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/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..6f779cf --- /dev/null +++ b/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/pom.xml b/pom.xml new file mode 100644 index 0000000..21cc749 --- /dev/null +++ b/pom.xml @@ -0,0 +1,110 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.3.1 + + + com.ibk + antifraude + 1.0.0 + antifraude + Microservicio de antifraude + + + + + + + + + + + + + + + 17 + + + + org.springframework.boot + spring-boot-starter-data-r2dbc + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.postgresql + postgresql + runtime + + + org.springframework.boot + spring-boot-starter-validation + + + org.postgresql + r2dbc-postgresql + runtime + + + org.projectlombok + lombok + true + + + io.r2dbc + r2dbc-pool + + + org.liquibase + liquibase-core + + + org.springframework.kafka + spring-kafka + + + + org.springframework.boot + spring-boot-starter-test + test + + + io.projectreactor + reactor-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/src/main/java/com/ibk/antifraude/AntifraudeApplication.java b/src/main/java/com/ibk/antifraude/AntifraudeApplication.java new file mode 100644 index 0000000..7fb590a --- /dev/null +++ b/src/main/java/com/ibk/antifraude/AntifraudeApplication.java @@ -0,0 +1,13 @@ +package com.ibk.antifraude; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class AntifraudeApplication { + + public static void main(String[] args) { + SpringApplication.run(AntifraudeApplication.class, args); + } + +} diff --git a/src/main/java/com/ibk/antifraude/application/ports/in/FinancialTransactionUseCase.java b/src/main/java/com/ibk/antifraude/application/ports/in/FinancialTransactionUseCase.java new file mode 100644 index 0000000..2ddc329 --- /dev/null +++ b/src/main/java/com/ibk/antifraude/application/ports/in/FinancialTransactionUseCase.java @@ -0,0 +1,13 @@ +package com.ibk.antifraude.application.ports.in; + +import com.ibk.antifraude.domain.dto.FinancialTransactionDTO; +import com.ibk.antifraude.domain.model.FinancialTransaction; +import reactor.core.publisher.Mono; + +public interface FinancialTransactionUseCase { + Mono createFinancialTransaction(FinancialTransaction financialTransaction); + + Mono findFinancialTransactionByID(Long id); + + Mono updateFinancialTransactionByID(Long id); +} diff --git a/src/main/java/com/ibk/antifraude/application/ports/in/KafkaUseCase.java b/src/main/java/com/ibk/antifraude/application/ports/in/KafkaUseCase.java new file mode 100644 index 0000000..51d3f70 --- /dev/null +++ b/src/main/java/com/ibk/antifraude/application/ports/in/KafkaUseCase.java @@ -0,0 +1,5 @@ +package com.ibk.antifraude.application.ports.in; + +public interface KafkaUseCase { + void sendMessage(String topic, String message); +} diff --git a/src/main/java/com/ibk/antifraude/application/ports/out/LoadFinancialTransactionPort.java b/src/main/java/com/ibk/antifraude/application/ports/out/LoadFinancialTransactionPort.java new file mode 100644 index 0000000..f62e661 --- /dev/null +++ b/src/main/java/com/ibk/antifraude/application/ports/out/LoadFinancialTransactionPort.java @@ -0,0 +1,13 @@ +package com.ibk.antifraude.application.ports.out; + +import com.ibk.antifraude.domain.dto.FinancialTransactionDTO; +import com.ibk.antifraude.domain.model.FinancialTransaction; +import reactor.core.publisher.Mono; + +public interface LoadFinancialTransactionPort { + Mono save(FinancialTransaction financialTransaction); + + Mono findByID(Long id); + + Mono update(Long id); +} diff --git a/src/main/java/com/ibk/antifraude/application/ports/out/LoadKafkaPort.java b/src/main/java/com/ibk/antifraude/application/ports/out/LoadKafkaPort.java new file mode 100644 index 0000000..cc7bb2d --- /dev/null +++ b/src/main/java/com/ibk/antifraude/application/ports/out/LoadKafkaPort.java @@ -0,0 +1,5 @@ +package com.ibk.antifraude.application.ports.out; + +public interface LoadKafkaPort { + void send(String topic, String message); +} diff --git a/src/main/java/com/ibk/antifraude/application/service/FinancialTransactionService.java b/src/main/java/com/ibk/antifraude/application/service/FinancialTransactionService.java new file mode 100644 index 0000000..366ffba --- /dev/null +++ b/src/main/java/com/ibk/antifraude/application/service/FinancialTransactionService.java @@ -0,0 +1,37 @@ +package com.ibk.antifraude.application.service; + +import com.ibk.antifraude.application.ports.in.FinancialTransactionUseCase; +import com.ibk.antifraude.application.ports.out.LoadFinancialTransactionPort; +import com.ibk.antifraude.domain.dto.FinancialTransactionDTO; +import com.ibk.antifraude.domain.model.FinancialTransaction; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +@Slf4j +@Service +public class FinancialTransactionService implements FinancialTransactionUseCase { + + private final LoadFinancialTransactionPort loadFinancialTransactionPort; + + public FinancialTransactionService(LoadFinancialTransactionPort loadFinancialTransactionPort) { + this.loadFinancialTransactionPort = loadFinancialTransactionPort; + } + + @Override + public Mono createFinancialTransaction(FinancialTransaction financialTransaction) { + return loadFinancialTransactionPort.save(financialTransaction); + } + + @Override + public Mono findFinancialTransactionByID(Long id) { + return loadFinancialTransactionPort.findByID(id); + } + + @Override + public Mono updateFinancialTransactionByID(Long id) { + return loadFinancialTransactionPort.update(id); + } + + +} diff --git a/src/main/java/com/ibk/antifraude/application/service/KafkaService.java b/src/main/java/com/ibk/antifraude/application/service/KafkaService.java new file mode 100644 index 0000000..bcf5a4b --- /dev/null +++ b/src/main/java/com/ibk/antifraude/application/service/KafkaService.java @@ -0,0 +1,22 @@ +package com.ibk.antifraude.application.service; + +import com.ibk.antifraude.application.ports.in.KafkaUseCase; +import com.ibk.antifraude.application.ports.out.LoadKafkaPort; +import org.springframework.stereotype.Service; + + +@Service +public class KafkaService implements KafkaUseCase { + + + private final LoadKafkaPort loadKafkaPort; + + public KafkaService(LoadKafkaPort loadKafkaPort) { + this.loadKafkaPort = loadKafkaPort; + } + + @Override + public void sendMessage(String topic, String message) { + loadKafkaPort.send(topic, message); + } +} diff --git a/src/main/java/com/ibk/antifraude/domain/dto/FinancialTransactionDTO.java b/src/main/java/com/ibk/antifraude/domain/dto/FinancialTransactionDTO.java new file mode 100644 index 0000000..0d2ab9f --- /dev/null +++ b/src/main/java/com/ibk/antifraude/domain/dto/FinancialTransactionDTO.java @@ -0,0 +1,47 @@ +package com.ibk.antifraude.domain.dto; + +import lombok.*; + +import java.time.LocalDateTime; +import java.util.UUID; + +@Getter +@Setter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class FinancialTransactionDTO { + + private UUID transactionExternalId; + private TransactionType transactionType; + private TransactionStatus transactionStatus; + private double value; + private LocalDateTime createdAt; + + @Setter + @Getter + @AllArgsConstructor(access = AccessLevel.PRIVATE) + public static class TransactionType { + private String name; + + public static TransactionType of(String name) { + return new TransactionType(name); + } + } + + @Setter + @Getter + @AllArgsConstructor(access = AccessLevel.PRIVATE) + public static class TransactionStatus { + private String name; + + public static TransactionStatus of(String name) { + return new TransactionStatus(name); + } + } + +} + + + + diff --git a/src/main/java/com/ibk/antifraude/domain/kafka/model/AntifraudeGroup.java b/src/main/java/com/ibk/antifraude/domain/kafka/model/AntifraudeGroup.java new file mode 100644 index 0000000..529c736 --- /dev/null +++ b/src/main/java/com/ibk/antifraude/domain/kafka/model/AntifraudeGroup.java @@ -0,0 +1,17 @@ +package com.ibk.antifraude.domain.kafka.model; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +import java.time.LocalDateTime; + +@Getter +@Setter +@AllArgsConstructor +public class AntifraudeGroup { + private Long id; + private String name; + private int value; + private LocalDateTime createdAt; +} diff --git a/src/main/java/com/ibk/antifraude/domain/model/FinancialTransaction.java b/src/main/java/com/ibk/antifraude/domain/model/FinancialTransaction.java new file mode 100644 index 0000000..c4708b2 --- /dev/null +++ b/src/main/java/com/ibk/antifraude/domain/model/FinancialTransaction.java @@ -0,0 +1,25 @@ +package com.ibk.antifraude.domain.model; + +import lombok.*; +import org.springframework.data.annotation.Id; + +import java.time.LocalDateTime; +import java.util.UUID; + +@Getter +@Setter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class FinancialTransaction { + @Id + private Long id; + private String accountExternalIdDebit; + private String accountExternalIdCredit; + private int transactionStatusId; + private UUID transactionExternalId; + private LocalDateTime createdAt; + private short transferTypeId; + private short value; +} + diff --git a/src/main/java/com/ibk/antifraude/domain/model/StatusTransfer.java b/src/main/java/com/ibk/antifraude/domain/model/StatusTransfer.java new file mode 100644 index 0000000..f68aa37 --- /dev/null +++ b/src/main/java/com/ibk/antifraude/domain/model/StatusTransfer.java @@ -0,0 +1,26 @@ +package com.ibk.antifraude.domain.model; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public enum StatusTransfer { + + PENDING(1, "pendiente"), + APPROVED(2, "aprobado"), + REFUSED(3, "rechazado"); + + final int id; + final String name; + + public static String getValueByID(int id) { + for (StatusTransfer status : StatusTransfer.values()) { + if (status.getId() == id) { + return status.getName(); + } + } + return ""; + } + +} diff --git a/src/main/java/com/ibk/antifraude/domain/model/TransferType.java b/src/main/java/com/ibk/antifraude/domain/model/TransferType.java new file mode 100644 index 0000000..deca7e7 --- /dev/null +++ b/src/main/java/com/ibk/antifraude/domain/model/TransferType.java @@ -0,0 +1,25 @@ +package com.ibk.antifraude.domain.model; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum TransferType { + OWN_ACCOUNT(1, "cuenta propia"), + OTHER_ACCOUNT_IBK(2, "otras cuentas IBK"), + THIRD_PARTY_ACCOUNT(3, "cuenta de terceros"); + + private final int id; + private final String description; + + public static String getValueByID(int id) { + for (TransferType type : TransferType.values()) { + if (type.getId() == id) { + return type.getDescription(); + } + } + return ""; + } + +} diff --git a/src/main/java/com/ibk/antifraude/infrastructure/adapters/config/KafkaConsumerConfig.java b/src/main/java/com/ibk/antifraude/infrastructure/adapters/config/KafkaConsumerConfig.java new file mode 100644 index 0000000..618df10 --- /dev/null +++ b/src/main/java/com/ibk/antifraude/infrastructure/adapters/config/KafkaConsumerConfig.java @@ -0,0 +1,34 @@ +package com.ibk.antifraude.infrastructure.adapters.config; + +import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.kafka.common.serialization.StringDeserializer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; +import org.springframework.kafka.core.ConsumerFactory; +import org.springframework.kafka.core.DefaultKafkaConsumerFactory; + +import java.util.HashMap; +import java.util.Map; + +@Configuration +public class KafkaConsumerConfig { + + @Bean + public ConsumerFactory consumerFactory() { + Map configProps = new HashMap<>(); + configProps.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); + configProps.put(ConsumerConfig.GROUP_ID_CONFIG, "antifraudeGroup"); + configProps.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); + configProps.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); + return new DefaultKafkaConsumerFactory<>(configProps); + } + + @Bean + public ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory() { + ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>(); + factory.setConsumerFactory(consumerFactory()); + return factory; + } + +} \ No newline at end of file diff --git a/src/main/java/com/ibk/antifraude/infrastructure/adapters/config/KafkaProducerConfig.java b/src/main/java/com/ibk/antifraude/infrastructure/adapters/config/KafkaProducerConfig.java new file mode 100644 index 0000000..df5f562 --- /dev/null +++ b/src/main/java/com/ibk/antifraude/infrastructure/adapters/config/KafkaProducerConfig.java @@ -0,0 +1,29 @@ +package com.ibk.antifraude.infrastructure.adapters.config; + +import org.apache.kafka.clients.producer.ProducerConfig; +import org.apache.kafka.common.serialization.StringSerializer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.kafka.core.DefaultKafkaProducerFactory; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.core.ProducerFactory; + +import java.util.HashMap; +import java.util.Map; + +@Configuration +public class KafkaProducerConfig { + @Bean + public ProducerFactory producerFactory() { + Map configProps = new HashMap<>(); + configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); + configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); + configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class); + return new DefaultKafkaProducerFactory<>(configProps); + } + + @Bean + public KafkaTemplate kafkaTemplate() { + return new KafkaTemplate<>(producerFactory()); + } +} \ No newline at end of file diff --git a/src/main/java/com/ibk/antifraude/infrastructure/adapters/in/rest/FinancialTransactionController.java b/src/main/java/com/ibk/antifraude/infrastructure/adapters/in/rest/FinancialTransactionController.java new file mode 100644 index 0000000..23ade4f --- /dev/null +++ b/src/main/java/com/ibk/antifraude/infrastructure/adapters/in/rest/FinancialTransactionController.java @@ -0,0 +1,47 @@ +package com.ibk.antifraude.infrastructure.adapters.in.rest; + +import com.ibk.antifraude.application.ports.in.FinancialTransactionUseCase; +import com.ibk.antifraude.application.ports.in.KafkaUseCase; +import com.ibk.antifraude.domain.dto.FinancialTransactionDTO; +import com.ibk.antifraude.domain.model.FinancialTransaction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import reactor.core.publisher.Mono; + +import java.util.Objects; + + +@RestController +@RequestMapping("/api/financial-transaction") +public class FinancialTransactionController { + + private static final Logger logger = LoggerFactory.getLogger(FinancialTransactionController.class.getName()); + private final FinancialTransactionUseCase financialTransactionUseCase; + private final KafkaUseCase kafkaUseCase; + + public FinancialTransactionController(FinancialTransactionUseCase financialTransactionUseCase, KafkaUseCase kafkaUseCase) { + this.financialTransactionUseCase = financialTransactionUseCase; + this.kafkaUseCase = kafkaUseCase; + } + + @PostMapping + public Mono> create(@RequestBody FinancialTransaction financialTransaction) { + return financialTransactionUseCase.createFinancialTransaction(financialTransaction) + .map(createdFinancial -> new ResponseEntity<>(createdFinancial, HttpStatus.CREATED)) + .doOnSuccess(createdFinancial -> + kafkaUseCase.sendMessage("antifraude-topic" + , String.valueOf(Objects.requireNonNull(createdFinancial.getBody()).getId()))); + } + + @GetMapping(value = "/{id}") + public Mono> findID(@PathVariable("id") Long financialTransactionId) { + logger.info("FinancialTransactionController findID {}", financialTransactionId); + return financialTransactionUseCase.findFinancialTransactionByID(financialTransactionId) + .map(createdFinancial -> new ResponseEntity<>(createdFinancial, HttpStatus.OK)) + .defaultIfEmpty(new ResponseEntity<>(HttpStatus.NOT_FOUND)); + } + +} diff --git a/src/main/java/com/ibk/antifraude/infrastructure/adapters/in/rest/MessageConsumer.java b/src/main/java/com/ibk/antifraude/infrastructure/adapters/in/rest/MessageConsumer.java new file mode 100644 index 0000000..651e3a1 --- /dev/null +++ b/src/main/java/com/ibk/antifraude/infrastructure/adapters/in/rest/MessageConsumer.java @@ -0,0 +1,21 @@ +package com.ibk.antifraude.infrastructure.adapters.in.rest; + +import com.ibk.antifraude.application.ports.in.FinancialTransactionUseCase; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.stereotype.Component; +import reactor.core.publisher.Mono; + +@Slf4j +@Component +@AllArgsConstructor +public class MessageConsumer { + + private final FinancialTransactionUseCase financialTransactionUseCase; + + @KafkaListener(topics = "antifraude-topic", groupId = "antifraudeGroup") + public Mono listen(String message) { + return financialTransactionUseCase.updateFinancialTransactionByID(Long.valueOf(message)); + } +} diff --git a/src/main/java/com/ibk/antifraude/infrastructure/adapters/out/persistence/FinancialTransactionAdapter.java b/src/main/java/com/ibk/antifraude/infrastructure/adapters/out/persistence/FinancialTransactionAdapter.java new file mode 100644 index 0000000..eb21231 --- /dev/null +++ b/src/main/java/com/ibk/antifraude/infrastructure/adapters/out/persistence/FinancialTransactionAdapter.java @@ -0,0 +1,55 @@ +package com.ibk.antifraude.infrastructure.adapters.out.persistence; + +import com.ibk.antifraude.application.ports.out.LoadFinancialTransactionPort; +import com.ibk.antifraude.domain.dto.FinancialTransactionDTO; +import com.ibk.antifraude.domain.model.FinancialTransaction; +import com.ibk.antifraude.domain.model.StatusTransfer; +import com.ibk.antifraude.domain.model.TransferType; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import reactor.core.publisher.Mono; + +import java.util.UUID; + +@Slf4j +@Component +public class FinancialTransactionAdapter implements LoadFinancialTransactionPort { + + private final FinancialTransactionRepository financialTransactionRepository; + + public FinancialTransactionAdapter(FinancialTransactionRepository financialTransactionRepository) { + this.financialTransactionRepository = financialTransactionRepository; + } + + @Override + public Mono save(FinancialTransaction financialTransaction) { + financialTransaction.setTransactionExternalId(UUID.randomUUID()); + financialTransaction.setTransactionStatusId(StatusTransfer.PENDING.getId()); + return financialTransactionRepository.save(financialTransaction); + } + + @Override + public Mono findByID(Long id) { + return financialTransactionRepository.findById(id) + .map(ft -> FinancialTransactionDTO.builder() + .transactionExternalId(ft.getTransactionExternalId()) + .value(ft.getValue()) + .createdAt(ft.getCreatedAt()) + .transactionType(FinancialTransactionDTO.TransactionType.of( + TransferType.getValueByID(ft.getTransferTypeId()))) + .transactionStatus(FinancialTransactionDTO.TransactionStatus.of(StatusTransfer.getValueByID(ft.getTransactionStatusId()))) + .build()); + } + + @Override + public Mono update(Long id) { + return financialTransactionRepository.findById(id).flatMap(financialTransaction -> { + if (financialTransaction.getValue() > 1000) { + financialTransaction.setTransactionStatusId(StatusTransfer.REFUSED.getId()); + } else { + financialTransaction.setTransactionStatusId(StatusTransfer.APPROVED.getId()); + } + return financialTransactionRepository.save(financialTransaction); + }).then(); + } +} diff --git a/src/main/java/com/ibk/antifraude/infrastructure/adapters/out/persistence/FinancialTransactionRepository.java b/src/main/java/com/ibk/antifraude/infrastructure/adapters/out/persistence/FinancialTransactionRepository.java new file mode 100644 index 0000000..596e63e --- /dev/null +++ b/src/main/java/com/ibk/antifraude/infrastructure/adapters/out/persistence/FinancialTransactionRepository.java @@ -0,0 +1,10 @@ +package com.ibk.antifraude.infrastructure.adapters.out.persistence; + +import com.ibk.antifraude.domain.model.FinancialTransaction; +import org.springframework.data.repository.reactive.ReactiveCrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface FinancialTransactionRepository extends ReactiveCrudRepository { + +} diff --git a/src/main/java/com/ibk/antifraude/infrastructure/adapters/out/persistence/KafkaAdapter.java b/src/main/java/com/ibk/antifraude/infrastructure/adapters/out/persistence/KafkaAdapter.java new file mode 100644 index 0000000..affc68e --- /dev/null +++ b/src/main/java/com/ibk/antifraude/infrastructure/adapters/out/persistence/KafkaAdapter.java @@ -0,0 +1,21 @@ +package com.ibk.antifraude.infrastructure.adapters.out.persistence; + +import com.ibk.antifraude.application.ports.out.LoadKafkaPort; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +@AllArgsConstructor +public class KafkaAdapter implements LoadKafkaPort { + + private KafkaTemplate kafkaTemplate; + + @Override + public void send(String topic, String message) { + log.info("Sending message to topic {}:{}", topic, message); + kafkaTemplate.send(topic, message); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..20b221f --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,19 @@ +spring: + application: + name: antifraude + r2dbc: + url: r2dbc:postgresql://localhost:5432/antifraudedb + username: postgres + password: postgres + pool: + enabled: true + kafka: + bootstrap-servers: localhost:9092 + consumer: + group-id: antifraudeGroup + auto-offset-reset: earliest +# datasource: +# driver-class-name: org.postgresql.Driver +# url: jdbc:postgresql://localhost:5432/antifraudedb +# username: postgres +# password: postgres diff --git a/src/main/resources/db/initquery.sql b/src/main/resources/db/initquery.sql new file mode 100644 index 0000000..d5761e9 --- /dev/null +++ b/src/main/resources/db/initquery.sql @@ -0,0 +1,65 @@ +-- Primero crear la base de datos + +create database antifraudedb; + +-- Luego seleccionar la base de datos y ejecutar las siguientes queries: + +-- drop table financial_transaction; + +CREATE TABLE financial_transaction +( + id serial primary key, + account_external_id_debit character varying(100) NOT NULL, + account_external_id_credit character varying(100) NOT NULL, + transaction_external_id character varying(100) NOT NULL, + transaction_status_id smallint default 1, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + transfer_type_id smallint, + value smallint +); + +insert +into financial_transaction (account_external_id_debit, + account_external_id_credit, + transaction_status_id, + transaction_external_id, + transfer_type_id, + value) +values ('3109aeb4-ee23-43a9-994b-3f9af5a0d00e', + '4995c6a9-447b-444d-a040-f356c920a2fd', + 1, + '464c5eb9-ee12-4b6c-b354-a839aa54d5f9', + 1, + 130); + +insert +into financial_transaction (account_external_id_debit, + account_external_id_credit, + transaction_status_id, + transaction_external_id, + transfer_type_id, + value) +values ('3119aeb4-ee23-43a9-994b-3f9af5a0d00e', + '4985c6a9-447b-444d-a040-f356c920a2fd', + 2, + '465c5eb9-ee12-4b6c-b354-a839aa54d5f9', + 2, + 150); + +insert +into financial_transaction (account_external_id_debit, + account_external_id_credit, + transaction_status_id, + transaction_external_id, + transfer_type_id, + value) +values ('3129aeb4-ee23-43a9-994b-3f9af5a0d00e', + '4285c6a9-447b-444d-a040-f356c920a2fd', + 3, + '435c5eb9-ee12-4b6c-b354-a839aa54d5f9', + 3, + 1001); + + +select * +from financial_transaction; diff --git a/src/main/resources/liquibase.yml b/src/main/resources/liquibase.yml new file mode 100644 index 0000000..cab1bee --- /dev/null +++ b/src/main/resources/liquibase.yml @@ -0,0 +1,7 @@ +changeLogFile: src/main/resources/db/changelog/master.xml +logging: debug +driver: org.postgresql.Driver +url: jdbc:postgresql://127.0.0.1:5432/example-sbl + +username: postgres +password: postgres \ No newline at end of file diff --git a/src/test/java/com/ibk/antifraude/AntifraudeApplicationTests.java b/src/test/java/com/ibk/antifraude/AntifraudeApplicationTests.java new file mode 100644 index 0000000..6b2b59d --- /dev/null +++ b/src/test/java/com/ibk/antifraude/AntifraudeApplicationTests.java @@ -0,0 +1,13 @@ +package com.ibk.antifraude; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class AntifraudeApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/target/antifraude-1.0.0.jar b/target/antifraude-1.0.0.jar new file mode 100644 index 0000000..0d3645b Binary files /dev/null and b/target/antifraude-1.0.0.jar differ diff --git a/target/antifraude-1.0.0.jar.original b/target/antifraude-1.0.0.jar.original new file mode 100644 index 0000000..f6ed9ac Binary files /dev/null and b/target/antifraude-1.0.0.jar.original differ diff --git a/target/classes/application.yml b/target/classes/application.yml new file mode 100644 index 0000000..20b221f --- /dev/null +++ b/target/classes/application.yml @@ -0,0 +1,19 @@ +spring: + application: + name: antifraude + r2dbc: + url: r2dbc:postgresql://localhost:5432/antifraudedb + username: postgres + password: postgres + pool: + enabled: true + kafka: + bootstrap-servers: localhost:9092 + consumer: + group-id: antifraudeGroup + auto-offset-reset: earliest +# datasource: +# driver-class-name: org.postgresql.Driver +# url: jdbc:postgresql://localhost:5432/antifraudedb +# username: postgres +# password: postgres diff --git a/target/classes/com/ibk/antifraude/AntifraudeApplication.class b/target/classes/com/ibk/antifraude/AntifraudeApplication.class new file mode 100644 index 0000000..bbd9486 Binary files /dev/null and b/target/classes/com/ibk/antifraude/AntifraudeApplication.class differ diff --git a/target/classes/com/ibk/antifraude/application/ports/in/FinancialTransactionUseCase.class b/target/classes/com/ibk/antifraude/application/ports/in/FinancialTransactionUseCase.class new file mode 100644 index 0000000..00bfd20 Binary files /dev/null and b/target/classes/com/ibk/antifraude/application/ports/in/FinancialTransactionUseCase.class differ diff --git a/target/classes/com/ibk/antifraude/application/ports/in/KafkaUseCase.class b/target/classes/com/ibk/antifraude/application/ports/in/KafkaUseCase.class new file mode 100644 index 0000000..2e872fc Binary files /dev/null and b/target/classes/com/ibk/antifraude/application/ports/in/KafkaUseCase.class differ diff --git a/target/classes/com/ibk/antifraude/application/ports/out/LoadFinancialTransactionPort.class b/target/classes/com/ibk/antifraude/application/ports/out/LoadFinancialTransactionPort.class new file mode 100644 index 0000000..2bd1f33 Binary files /dev/null and b/target/classes/com/ibk/antifraude/application/ports/out/LoadFinancialTransactionPort.class differ diff --git a/target/classes/com/ibk/antifraude/application/ports/out/LoadKafkaPort.class b/target/classes/com/ibk/antifraude/application/ports/out/LoadKafkaPort.class new file mode 100644 index 0000000..05fc94a Binary files /dev/null and b/target/classes/com/ibk/antifraude/application/ports/out/LoadKafkaPort.class differ diff --git a/target/classes/com/ibk/antifraude/application/service/FinancialTransactionService.class b/target/classes/com/ibk/antifraude/application/service/FinancialTransactionService.class new file mode 100644 index 0000000..959ddc6 Binary files /dev/null and b/target/classes/com/ibk/antifraude/application/service/FinancialTransactionService.class differ diff --git a/target/classes/com/ibk/antifraude/application/service/KafkaService.class b/target/classes/com/ibk/antifraude/application/service/KafkaService.class new file mode 100644 index 0000000..357a1da Binary files /dev/null and b/target/classes/com/ibk/antifraude/application/service/KafkaService.class differ diff --git a/target/classes/com/ibk/antifraude/domain/dto/FinancialTransactionDTO$FinancialTransactionDTOBuilder.class b/target/classes/com/ibk/antifraude/domain/dto/FinancialTransactionDTO$FinancialTransactionDTOBuilder.class new file mode 100644 index 0000000..07e5b54 Binary files /dev/null and b/target/classes/com/ibk/antifraude/domain/dto/FinancialTransactionDTO$FinancialTransactionDTOBuilder.class differ diff --git a/target/classes/com/ibk/antifraude/domain/dto/FinancialTransactionDTO$TransactionStatus.class b/target/classes/com/ibk/antifraude/domain/dto/FinancialTransactionDTO$TransactionStatus.class new file mode 100644 index 0000000..1f943ca Binary files /dev/null and b/target/classes/com/ibk/antifraude/domain/dto/FinancialTransactionDTO$TransactionStatus.class differ diff --git a/target/classes/com/ibk/antifraude/domain/dto/FinancialTransactionDTO$TransactionType.class b/target/classes/com/ibk/antifraude/domain/dto/FinancialTransactionDTO$TransactionType.class new file mode 100644 index 0000000..29d3d87 Binary files /dev/null and b/target/classes/com/ibk/antifraude/domain/dto/FinancialTransactionDTO$TransactionType.class differ diff --git a/target/classes/com/ibk/antifraude/domain/dto/FinancialTransactionDTO.class b/target/classes/com/ibk/antifraude/domain/dto/FinancialTransactionDTO.class new file mode 100644 index 0000000..d0f6949 Binary files /dev/null and b/target/classes/com/ibk/antifraude/domain/dto/FinancialTransactionDTO.class differ diff --git a/target/classes/com/ibk/antifraude/domain/kafka/model/AntifraudeGroup.class b/target/classes/com/ibk/antifraude/domain/kafka/model/AntifraudeGroup.class new file mode 100644 index 0000000..5e2a49d Binary files /dev/null and b/target/classes/com/ibk/antifraude/domain/kafka/model/AntifraudeGroup.class differ diff --git a/target/classes/com/ibk/antifraude/domain/model/FinancialTransaction$FinancialTransactionBuilder.class b/target/classes/com/ibk/antifraude/domain/model/FinancialTransaction$FinancialTransactionBuilder.class new file mode 100644 index 0000000..6028657 Binary files /dev/null and b/target/classes/com/ibk/antifraude/domain/model/FinancialTransaction$FinancialTransactionBuilder.class differ diff --git a/target/classes/com/ibk/antifraude/domain/model/FinancialTransaction.class b/target/classes/com/ibk/antifraude/domain/model/FinancialTransaction.class new file mode 100644 index 0000000..9204b25 Binary files /dev/null and b/target/classes/com/ibk/antifraude/domain/model/FinancialTransaction.class differ diff --git a/target/classes/com/ibk/antifraude/domain/model/StatusTransfer.class b/target/classes/com/ibk/antifraude/domain/model/StatusTransfer.class new file mode 100644 index 0000000..7216c9b Binary files /dev/null and b/target/classes/com/ibk/antifraude/domain/model/StatusTransfer.class differ diff --git a/target/classes/com/ibk/antifraude/domain/model/TransferType.class b/target/classes/com/ibk/antifraude/domain/model/TransferType.class new file mode 100644 index 0000000..0670728 Binary files /dev/null and b/target/classes/com/ibk/antifraude/domain/model/TransferType.class differ diff --git a/target/classes/com/ibk/antifraude/infrastructure/adapters/config/KafkaConsumerConfig.class b/target/classes/com/ibk/antifraude/infrastructure/adapters/config/KafkaConsumerConfig.class new file mode 100644 index 0000000..8b0b415 Binary files /dev/null and b/target/classes/com/ibk/antifraude/infrastructure/adapters/config/KafkaConsumerConfig.class differ diff --git a/target/classes/com/ibk/antifraude/infrastructure/adapters/config/KafkaProducerConfig.class b/target/classes/com/ibk/antifraude/infrastructure/adapters/config/KafkaProducerConfig.class new file mode 100644 index 0000000..7e65b6b Binary files /dev/null and b/target/classes/com/ibk/antifraude/infrastructure/adapters/config/KafkaProducerConfig.class differ diff --git a/target/classes/com/ibk/antifraude/infrastructure/adapters/in/rest/FinancialTransactionController.class b/target/classes/com/ibk/antifraude/infrastructure/adapters/in/rest/FinancialTransactionController.class new file mode 100644 index 0000000..1674952 Binary files /dev/null and b/target/classes/com/ibk/antifraude/infrastructure/adapters/in/rest/FinancialTransactionController.class differ diff --git a/target/classes/com/ibk/antifraude/infrastructure/adapters/in/rest/MessageConsumer.class b/target/classes/com/ibk/antifraude/infrastructure/adapters/in/rest/MessageConsumer.class new file mode 100644 index 0000000..99d589a Binary files /dev/null and b/target/classes/com/ibk/antifraude/infrastructure/adapters/in/rest/MessageConsumer.class differ diff --git a/target/classes/com/ibk/antifraude/infrastructure/adapters/out/persistence/FinancialTransactionAdapter.class b/target/classes/com/ibk/antifraude/infrastructure/adapters/out/persistence/FinancialTransactionAdapter.class new file mode 100644 index 0000000..e633b24 Binary files /dev/null and b/target/classes/com/ibk/antifraude/infrastructure/adapters/out/persistence/FinancialTransactionAdapter.class differ diff --git a/target/classes/com/ibk/antifraude/infrastructure/adapters/out/persistence/FinancialTransactionRepository.class b/target/classes/com/ibk/antifraude/infrastructure/adapters/out/persistence/FinancialTransactionRepository.class new file mode 100644 index 0000000..3a41019 Binary files /dev/null and b/target/classes/com/ibk/antifraude/infrastructure/adapters/out/persistence/FinancialTransactionRepository.class differ diff --git a/target/classes/com/ibk/antifraude/infrastructure/adapters/out/persistence/KafkaAdapter.class b/target/classes/com/ibk/antifraude/infrastructure/adapters/out/persistence/KafkaAdapter.class new file mode 100644 index 0000000..a39e58f Binary files /dev/null and b/target/classes/com/ibk/antifraude/infrastructure/adapters/out/persistence/KafkaAdapter.class differ diff --git a/target/classes/db/initquery.sql b/target/classes/db/initquery.sql new file mode 100644 index 0000000..d5761e9 --- /dev/null +++ b/target/classes/db/initquery.sql @@ -0,0 +1,65 @@ +-- Primero crear la base de datos + +create database antifraudedb; + +-- Luego seleccionar la base de datos y ejecutar las siguientes queries: + +-- drop table financial_transaction; + +CREATE TABLE financial_transaction +( + id serial primary key, + account_external_id_debit character varying(100) NOT NULL, + account_external_id_credit character varying(100) NOT NULL, + transaction_external_id character varying(100) NOT NULL, + transaction_status_id smallint default 1, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + transfer_type_id smallint, + value smallint +); + +insert +into financial_transaction (account_external_id_debit, + account_external_id_credit, + transaction_status_id, + transaction_external_id, + transfer_type_id, + value) +values ('3109aeb4-ee23-43a9-994b-3f9af5a0d00e', + '4995c6a9-447b-444d-a040-f356c920a2fd', + 1, + '464c5eb9-ee12-4b6c-b354-a839aa54d5f9', + 1, + 130); + +insert +into financial_transaction (account_external_id_debit, + account_external_id_credit, + transaction_status_id, + transaction_external_id, + transfer_type_id, + value) +values ('3119aeb4-ee23-43a9-994b-3f9af5a0d00e', + '4985c6a9-447b-444d-a040-f356c920a2fd', + 2, + '465c5eb9-ee12-4b6c-b354-a839aa54d5f9', + 2, + 150); + +insert +into financial_transaction (account_external_id_debit, + account_external_id_credit, + transaction_status_id, + transaction_external_id, + transfer_type_id, + value) +values ('3129aeb4-ee23-43a9-994b-3f9af5a0d00e', + '4285c6a9-447b-444d-a040-f356c920a2fd', + 3, + '435c5eb9-ee12-4b6c-b354-a839aa54d5f9', + 3, + 1001); + + +select * +from financial_transaction; diff --git a/target/classes/liquibase.yml b/target/classes/liquibase.yml new file mode 100644 index 0000000..cab1bee --- /dev/null +++ b/target/classes/liquibase.yml @@ -0,0 +1,7 @@ +changeLogFile: src/main/resources/db/changelog/master.xml +logging: debug +driver: org.postgresql.Driver +url: jdbc:postgresql://127.0.0.1:5432/example-sbl + +username: postgres +password: postgres \ No newline at end of file diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100644 index 0000000..5f3e3d4 --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=antifraude +groupId=com.ibk +version=1.0.0 diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..02ee3e7 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,13 @@ +com/ibk/antifraude/infrastructure/adapters/in/rest/FinancialTransactionController.class +com/ibk/antifraude/domain/model/FinancialTransaction.class +com/ibk/antifraude/AntifraudeApplication.class +com/ibk/antifraude/application/ports/out/LoadFinancialTransactionPort.class +com/ibk/antifraude/domain/dto/FinancialTransactionDTO$TransactionType.class +com/ibk/antifraude/domain/dto/FinancialTransactionDTO.class +com/ibk/antifraude/application/ports/in/FinancialTransactionUseCase.class +com/ibk/antifraude/domain/dto/FinancialTransactionDTO$TransactionStatus.class +com/ibk/antifraude/application/service/FinancialTransactionService.class +com/ibk/antifraude/domain/dto/FinancialTransactionDTO$FinancialTransactionDTOBuilder.class +com/ibk/antifraude/domain/model/FinancialTransaction$FinancialTransactionBuilder.class +com/ibk/antifraude/infrastructure/adapters/out/persistence/FinancialTransactionAdapter.class +com/ibk/antifraude/infrastructure/adapters/out/persistence/FinancialTransactionRepository.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..eba47a9 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,9 @@ +/Users/jpachecc/Documents/IBK/java-code-challenge/src/main/java/com/ibk/antifraude/AntifraudeApplication.java +/Users/jpachecc/Documents/IBK/java-code-challenge/src/main/java/com/ibk/antifraude/application/ports/in/FinancialTransactionUseCase.java +/Users/jpachecc/Documents/IBK/java-code-challenge/src/main/java/com/ibk/antifraude/application/ports/out/LoadFinancialTransactionPort.java +/Users/jpachecc/Documents/IBK/java-code-challenge/src/main/java/com/ibk/antifraude/application/service/FinancialTransactionService.java +/Users/jpachecc/Documents/IBK/java-code-challenge/src/main/java/com/ibk/antifraude/domain/dto/FinancialTransactionDTO.java +/Users/jpachecc/Documents/IBK/java-code-challenge/src/main/java/com/ibk/antifraude/domain/model/FinancialTransaction.java +/Users/jpachecc/Documents/IBK/java-code-challenge/src/main/java/com/ibk/antifraude/infrastructure/adapters/in/rest/FinancialTransactionController.java +/Users/jpachecc/Documents/IBK/java-code-challenge/src/main/java/com/ibk/antifraude/infrastructure/adapters/out/persistence/FinancialTransactionAdapter.java +/Users/jpachecc/Documents/IBK/java-code-challenge/src/main/java/com/ibk/antifraude/infrastructure/adapters/out/persistence/FinancialTransactionRepository.java diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..032e675 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +com/ibk/antifraude/AntifraudeApplicationTests.class diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..89fbfe5 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +/Users/jpachecc/Documents/IBK/java-code-challenge/src/test/java/com/ibk/antifraude/AntifraudeApplicationTests.java diff --git a/target/surefire-reports/TEST-com.ibk.antifraude.AntifraudeApplicationTests.xml b/target/surefire-reports/TEST-com.ibk.antifraude.AntifraudeApplicationTests.xml new file mode 100644 index 0000000..1e2b54c --- /dev/null +++ b/target/surefire-reports/TEST-com.ibk.antifraude.AntifraudeApplicationTests.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/surefire-reports/com.ibk.antifraude.AntifraudeApplicationTests.txt b/target/surefire-reports/com.ibk.antifraude.AntifraudeApplicationTests.txt new file mode 100644 index 0000000..d06539e --- /dev/null +++ b/target/surefire-reports/com.ibk.antifraude.AntifraudeApplicationTests.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: com.ibk.antifraude.AntifraudeApplicationTests +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.364 s -- in com.ibk.antifraude.AntifraudeApplicationTests diff --git a/target/test-classes/com/ibk/antifraude/AntifraudeApplicationTests.class b/target/test-classes/com/ibk/antifraude/AntifraudeApplicationTests.class new file mode 100644 index 0000000..6791dc4 Binary files /dev/null and b/target/test-classes/com/ibk/antifraude/AntifraudeApplicationTests.class differ