diff --git a/.gitignore b/RMI/.gitignore similarity index 100% rename from .gitignore rename to RMI/.gitignore diff --git a/README.md b/RMI/README.md similarity index 100% rename from README.md rename to RMI/README.md diff --git a/banking-client/pom.xml b/RMI/banking-client/pom.xml similarity index 100% rename from banking-client/pom.xml rename to RMI/banking-client/pom.xml diff --git a/banking-client/src/main/java/ufrn/imd/BankingClientApp.java b/RMI/banking-client/src/main/java/ufrn/imd/BankingClientApp.java similarity index 100% rename from banking-client/src/main/java/ufrn/imd/BankingClientApp.java rename to RMI/banking-client/src/main/java/ufrn/imd/BankingClientApp.java diff --git a/banking-client/src/main/java/ufrn/imd/controller/Controller.java b/RMI/banking-client/src/main/java/ufrn/imd/controller/Controller.java similarity index 100% rename from banking-client/src/main/java/ufrn/imd/controller/Controller.java rename to RMI/banking-client/src/main/java/ufrn/imd/controller/Controller.java diff --git a/banking-client/src/main/java/ufrn/imd/domain/Account.java b/RMI/banking-client/src/main/java/ufrn/imd/domain/Account.java similarity index 100% rename from banking-client/src/main/java/ufrn/imd/domain/Account.java rename to RMI/banking-client/src/main/java/ufrn/imd/domain/Account.java diff --git a/banking-client/src/main/java/ufrn/imd/domain/Client.java b/RMI/banking-client/src/main/java/ufrn/imd/domain/Client.java similarity index 100% rename from banking-client/src/main/java/ufrn/imd/domain/Client.java rename to RMI/banking-client/src/main/java/ufrn/imd/domain/Client.java diff --git a/banking-client/src/main/java/ufrn/imd/utils/MachineState.java b/RMI/banking-client/src/main/java/ufrn/imd/utils/MachineState.java similarity index 100% rename from banking-client/src/main/java/ufrn/imd/utils/MachineState.java rename to RMI/banking-client/src/main/java/ufrn/imd/utils/MachineState.java diff --git a/banking-client/src/main/java/ufrn/imd/utils/NameSpace.java b/RMI/banking-client/src/main/java/ufrn/imd/utils/NameSpace.java similarity index 100% rename from banking-client/src/main/java/ufrn/imd/utils/NameSpace.java rename to RMI/banking-client/src/main/java/ufrn/imd/utils/NameSpace.java diff --git a/banking-client/src/main/java/ufrn/imd/utils/ServerResponse.java b/RMI/banking-client/src/main/java/ufrn/imd/utils/ServerResponse.java similarity index 100% rename from banking-client/src/main/java/ufrn/imd/utils/ServerResponse.java rename to RMI/banking-client/src/main/java/ufrn/imd/utils/ServerResponse.java diff --git a/banking-client/src/main/java/ufrn/imd/utils/message/DepositMessage.java b/RMI/banking-client/src/main/java/ufrn/imd/utils/message/DepositMessage.java similarity index 100% rename from banking-client/src/main/java/ufrn/imd/utils/message/DepositMessage.java rename to RMI/banking-client/src/main/java/ufrn/imd/utils/message/DepositMessage.java diff --git a/banking-client/src/main/java/ufrn/imd/utils/message/TransferMessage.java b/RMI/banking-client/src/main/java/ufrn/imd/utils/message/TransferMessage.java similarity index 100% rename from banking-client/src/main/java/ufrn/imd/utils/message/TransferMessage.java rename to RMI/banking-client/src/main/java/ufrn/imd/utils/message/TransferMessage.java diff --git a/banking-client/src/main/java/ufrn/imd/utils/message/WithdrawalMessage.java b/RMI/banking-client/src/main/java/ufrn/imd/utils/message/WithdrawalMessage.java similarity index 100% rename from banking-client/src/main/java/ufrn/imd/utils/message/WithdrawalMessage.java rename to RMI/banking-client/src/main/java/ufrn/imd/utils/message/WithdrawalMessage.java diff --git a/banking-server/.idea/.gitignore b/RMI/banking-server/.idea/.gitignore similarity index 100% rename from banking-server/.idea/.gitignore rename to RMI/banking-server/.idea/.gitignore diff --git a/banking-server/.idea/compiler.xml b/RMI/banking-server/.idea/compiler.xml similarity index 100% rename from banking-server/.idea/compiler.xml rename to RMI/banking-server/.idea/compiler.xml diff --git a/banking-server/.idea/dbnavigator.xml b/RMI/banking-server/.idea/dbnavigator.xml similarity index 100% rename from banking-server/.idea/dbnavigator.xml rename to RMI/banking-server/.idea/dbnavigator.xml diff --git a/banking-server/.idea/jarRepositories.xml b/RMI/banking-server/.idea/jarRepositories.xml similarity index 100% rename from banking-server/.idea/jarRepositories.xml rename to RMI/banking-server/.idea/jarRepositories.xml diff --git a/banking-server/.idea/misc.xml b/RMI/banking-server/.idea/misc.xml similarity index 100% rename from banking-server/.idea/misc.xml rename to RMI/banking-server/.idea/misc.xml diff --git a/banking-server/.idea/uiDesigner.xml b/RMI/banking-server/.idea/uiDesigner.xml similarity index 100% rename from banking-server/.idea/uiDesigner.xml rename to RMI/banking-server/.idea/uiDesigner.xml diff --git a/banking-server/.idea/vcs.xml b/RMI/banking-server/.idea/vcs.xml similarity index 100% rename from banking-server/.idea/vcs.xml rename to RMI/banking-server/.idea/vcs.xml diff --git a/banking-server/pom.xml b/RMI/banking-server/pom.xml similarity index 100% rename from banking-server/pom.xml rename to RMI/banking-server/pom.xml diff --git a/banking-server/src/main/java/ufrn/imd/BankingServerApp.java b/RMI/banking-server/src/main/java/ufrn/imd/BankingServerApp.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/BankingServerApp.java rename to RMI/banking-server/src/main/java/ufrn/imd/BankingServerApp.java diff --git a/banking-server/src/main/java/ufrn/imd/controller/Controller.java b/RMI/banking-server/src/main/java/ufrn/imd/controller/Controller.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/controller/Controller.java rename to RMI/banking-server/src/main/java/ufrn/imd/controller/Controller.java diff --git a/banking-server/src/main/java/ufrn/imd/controller/impl/AuthenticatorControllerImpl.java b/RMI/banking-server/src/main/java/ufrn/imd/controller/impl/AuthenticatorControllerImpl.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/controller/impl/AuthenticatorControllerImpl.java rename to RMI/banking-server/src/main/java/ufrn/imd/controller/impl/AuthenticatorControllerImpl.java diff --git a/banking-server/src/main/java/ufrn/imd/controller/impl/BalanceControllerImpl.java b/RMI/banking-server/src/main/java/ufrn/imd/controller/impl/BalanceControllerImpl.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/controller/impl/BalanceControllerImpl.java rename to RMI/banking-server/src/main/java/ufrn/imd/controller/impl/BalanceControllerImpl.java diff --git a/banking-server/src/main/java/ufrn/imd/controller/impl/DepositControllerImpl.java b/RMI/banking-server/src/main/java/ufrn/imd/controller/impl/DepositControllerImpl.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/controller/impl/DepositControllerImpl.java rename to RMI/banking-server/src/main/java/ufrn/imd/controller/impl/DepositControllerImpl.java diff --git a/banking-server/src/main/java/ufrn/imd/controller/impl/TransferControllerImpl.java b/RMI/banking-server/src/main/java/ufrn/imd/controller/impl/TransferControllerImpl.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/controller/impl/TransferControllerImpl.java rename to RMI/banking-server/src/main/java/ufrn/imd/controller/impl/TransferControllerImpl.java diff --git a/banking-server/src/main/java/ufrn/imd/controller/impl/WithdrawalControllerImpl.java b/RMI/banking-server/src/main/java/ufrn/imd/controller/impl/WithdrawalControllerImpl.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/controller/impl/WithdrawalControllerImpl.java rename to RMI/banking-server/src/main/java/ufrn/imd/controller/impl/WithdrawalControllerImpl.java diff --git a/banking-server/src/main/java/ufrn/imd/domain/Account.java b/RMI/banking-server/src/main/java/ufrn/imd/domain/Account.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/domain/Account.java rename to RMI/banking-server/src/main/java/ufrn/imd/domain/Account.java diff --git a/banking-server/src/main/java/ufrn/imd/domain/Client.java b/RMI/banking-server/src/main/java/ufrn/imd/domain/Client.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/domain/Client.java rename to RMI/banking-server/src/main/java/ufrn/imd/domain/Client.java diff --git a/banking-server/src/main/java/ufrn/imd/repository/Repository.java b/RMI/banking-server/src/main/java/ufrn/imd/repository/Repository.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/repository/Repository.java rename to RMI/banking-server/src/main/java/ufrn/imd/repository/Repository.java diff --git a/banking-server/src/main/java/ufrn/imd/repository/impl/ClientRepository.java b/RMI/banking-server/src/main/java/ufrn/imd/repository/impl/ClientRepository.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/repository/impl/ClientRepository.java rename to RMI/banking-server/src/main/java/ufrn/imd/repository/impl/ClientRepository.java diff --git a/banking-server/src/main/java/ufrn/imd/service/Service.java b/RMI/banking-server/src/main/java/ufrn/imd/service/Service.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/service/Service.java rename to RMI/banking-server/src/main/java/ufrn/imd/service/Service.java diff --git a/banking-server/src/main/java/ufrn/imd/service/impl/AuthenticatorServiceImpl.java b/RMI/banking-server/src/main/java/ufrn/imd/service/impl/AuthenticatorServiceImpl.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/service/impl/AuthenticatorServiceImpl.java rename to RMI/banking-server/src/main/java/ufrn/imd/service/impl/AuthenticatorServiceImpl.java diff --git a/banking-server/src/main/java/ufrn/imd/service/impl/BalanceServiceImpl.java b/RMI/banking-server/src/main/java/ufrn/imd/service/impl/BalanceServiceImpl.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/service/impl/BalanceServiceImpl.java rename to RMI/banking-server/src/main/java/ufrn/imd/service/impl/BalanceServiceImpl.java diff --git a/banking-server/src/main/java/ufrn/imd/service/impl/DepositServiceImpl.java b/RMI/banking-server/src/main/java/ufrn/imd/service/impl/DepositServiceImpl.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/service/impl/DepositServiceImpl.java rename to RMI/banking-server/src/main/java/ufrn/imd/service/impl/DepositServiceImpl.java diff --git a/banking-server/src/main/java/ufrn/imd/service/impl/TransferServiceImpl.java b/RMI/banking-server/src/main/java/ufrn/imd/service/impl/TransferServiceImpl.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/service/impl/TransferServiceImpl.java rename to RMI/banking-server/src/main/java/ufrn/imd/service/impl/TransferServiceImpl.java diff --git a/banking-server/src/main/java/ufrn/imd/service/impl/WithdrawalServiceImpl.java b/RMI/banking-server/src/main/java/ufrn/imd/service/impl/WithdrawalServiceImpl.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/service/impl/WithdrawalServiceImpl.java rename to RMI/banking-server/src/main/java/ufrn/imd/service/impl/WithdrawalServiceImpl.java diff --git a/banking-server/src/main/java/ufrn/imd/utils/NameSpace.java b/RMI/banking-server/src/main/java/ufrn/imd/utils/NameSpace.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/utils/NameSpace.java rename to RMI/banking-server/src/main/java/ufrn/imd/utils/NameSpace.java diff --git a/banking-server/src/main/java/ufrn/imd/utils/ServerResponse.java b/RMI/banking-server/src/main/java/ufrn/imd/utils/ServerResponse.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/utils/ServerResponse.java rename to RMI/banking-server/src/main/java/ufrn/imd/utils/ServerResponse.java diff --git a/banking-server/src/main/java/ufrn/imd/utils/message/DepositMessage.java b/RMI/banking-server/src/main/java/ufrn/imd/utils/message/DepositMessage.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/utils/message/DepositMessage.java rename to RMI/banking-server/src/main/java/ufrn/imd/utils/message/DepositMessage.java diff --git a/banking-server/src/main/java/ufrn/imd/utils/message/TransferMessage.java b/RMI/banking-server/src/main/java/ufrn/imd/utils/message/TransferMessage.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/utils/message/TransferMessage.java rename to RMI/banking-server/src/main/java/ufrn/imd/utils/message/TransferMessage.java diff --git a/banking-server/src/main/java/ufrn/imd/utils/message/WithdrawalMessage.java b/RMI/banking-server/src/main/java/ufrn/imd/utils/message/WithdrawalMessage.java similarity index 100% rename from banking-server/src/main/java/ufrn/imd/utils/message/WithdrawalMessage.java rename to RMI/banking-server/src/main/java/ufrn/imd/utils/message/WithdrawalMessage.java diff --git a/WebServices/.DS_Store b/WebServices/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b88d9b4006e41c048d0b45c2c90453053ee92062 Binary files /dev/null and b/WebServices/.DS_Store differ diff --git a/WebServices/.gitignore b/WebServices/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ba5cb5cca8766c8b2403d25de25b1c880c5ef64a --- /dev/null +++ b/WebServices/.gitignore @@ -0,0 +1,26 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ diff --git a/WebServices/README.MD b/WebServices/README.MD new file mode 100644 index 0000000000000000000000000000000000000000..980f9571be036f73b8b3f4ddc75a984030e72f00 --- /dev/null +++ b/WebServices/README.MD @@ -0,0 +1,22 @@ +# Banquin rest # + +## How to run ## + +First you need in your machine the programs: +- maven +- docker +- docker compose + +Second in the root of the project execute the command: +``` +mvn clean install -DskipTests +``` + +After that execute this commands in the root: + +``` +docker-compose build +docker-compose up -d +``` + +and vuala! the docker will start each service for you. diff --git a/WebServices/authenticator/.gitignore b/WebServices/authenticator/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ba5cb5cca8766c8b2403d25de25b1c880c5ef64a --- /dev/null +++ b/WebServices/authenticator/.gitignore @@ -0,0 +1,26 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ diff --git a/WebServices/authenticator/.mvn/wrapper/maven-wrapper.jar b/WebServices/authenticator/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..c1dd12f17644411d6e840bd5a10c6ecda0175f18 Binary files /dev/null and b/WebServices/authenticator/.mvn/wrapper/maven-wrapper.jar differ diff --git a/WebServices/authenticator/.mvn/wrapper/maven-wrapper.properties b/WebServices/authenticator/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000000000000000000000000000000000..b7cb93e7050f42ff587aefbc40cc038ad4fa3271 --- /dev/null +++ b/WebServices/authenticator/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar diff --git a/WebServices/authenticator/Dockerfile b/WebServices/authenticator/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..c67f2ab856e8b1995fa16de97808c16e9703f072 --- /dev/null +++ b/WebServices/authenticator/Dockerfile @@ -0,0 +1,3 @@ +FROM openjdk:11 +COPY target/authenticator.jar authenticator.jar +ENTRYPOINT ["java","-jar","authenticator.jar"] \ No newline at end of file diff --git a/WebServices/authenticator/mvnw b/WebServices/authenticator/mvnw new file mode 100644 index 0000000000000000000000000000000000000000..8a8fb2282df5b8f7263470a5a2dc0e196f35f35f --- /dev/null +++ b/WebServices/authenticator/mvnw @@ -0,0 +1,316 @@ +#!/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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + 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" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/WebServices/authenticator/mvnw.cmd b/WebServices/authenticator/mvnw.cmd new file mode 100644 index 0000000000000000000000000000000000000000..1d8ab018eaf11d9b3a4a90e7818ace373dfbb380 --- /dev/null +++ b/WebServices/authenticator/mvnw.cmd @@ -0,0 +1,188 @@ +@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 Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/WebServices/authenticator/pom.xml b/WebServices/authenticator/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..255f5f4900e55f89aec2d8309e8d152bab55a82c --- /dev/null +++ b/WebServices/authenticator/pom.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>br.ufrn.imd</groupId> + <artifactId>dim0614</artifactId> + <version>1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> <!-- lookup parent from repository --> + </parent> + + <artifactId>authenticator</artifactId> + <version>0.0.1-SNAPSHOT</version> + <name>authenticator</name> + <description>authenticator service</description> + + <properties> + <java.version>11</java.version> + </properties> + + <build> + <finalName>authenticator</finalName> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <executable>true</executable> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.0</version> + <configuration> + <source>11</source> + <target>11</target> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/AuthenticatorApplication.java b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/AuthenticatorApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..6586d0527916a0836469e7cbcd47a184d5efe8c9 --- /dev/null +++ b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/AuthenticatorApplication.java @@ -0,0 +1,13 @@ +package br.ufrn.imd.authenticator; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class AuthenticatorApplication { + + public static void main(String[] args) { + SpringApplication.run(AuthenticatorApplication.class, args); + } + +} diff --git a/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/controller/AuthenticatorController.java b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/controller/AuthenticatorController.java new file mode 100644 index 0000000000000000000000000000000000000000..bd44adfbe01e008d4ab503d23edfbb28642e6d80 --- /dev/null +++ b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/controller/AuthenticatorController.java @@ -0,0 +1,19 @@ +package br.ufrn.imd.authenticator.controller; + +import br.ufrn.imd.authenticator.domain.Client; +import br.ufrn.imd.authenticator.service.AuthenticatorService; +import br.ufrn.imd.authenticator.utils.message.CredentialsMessage; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/banking/login") +public class AuthenticatorController { + private final AuthenticatorService service; + + @PostMapping + public Client authenticate(@RequestBody CredentialsMessage credentials) { + return service.authenticate(credentials.getNumber(), credentials.getPassword()); + } +} diff --git a/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/domain/Account.java b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/domain/Account.java new file mode 100644 index 0000000000000000000000000000000000000000..89dfce19f57d0541b2941cc8db5a4b81f2a0e00c --- /dev/null +++ b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/domain/Account.java @@ -0,0 +1,26 @@ +package br.ufrn.imd.authenticator.domain; + +import lombok.*; + +import javax.persistence.*; +import java.io.Serializable; + +@Data +@Entity +@AllArgsConstructor +@NoArgsConstructor +public class Account implements Serializable { + + private static final long serialVersionUID = 2L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column(unique = true) + private String number; + + private Double balance; + + private String password; +} diff --git a/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/domain/Client.java b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/domain/Client.java new file mode 100644 index 0000000000000000000000000000000000000000..cc4843fd3cb96fdbb3ca07ab044cb0e9fc6d21a2 --- /dev/null +++ b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/domain/Client.java @@ -0,0 +1,29 @@ +package br.ufrn.imd.authenticator.domain; + +import lombok.*; + +import javax.persistence.*; +import java.io.Serializable; + +@Data +@Entity +@AllArgsConstructor +@NoArgsConstructor +public class Client implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String name; + + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "account_id") + private Account account; + + public Client(Integer id) { + this.id = id; + } +} diff --git a/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/exception/BadRequestException.java b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/exception/BadRequestException.java new file mode 100644 index 0000000000000000000000000000000000000000..09b5277c696bcd03b93f638816b95389c752a446 --- /dev/null +++ b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/exception/BadRequestException.java @@ -0,0 +1,12 @@ +package br.ufrn.imd.authenticator.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(HttpStatus.BAD_REQUEST) +public class BadRequestException extends RuntimeException{ + + public BadRequestException(String message) { + super(message); + } +} diff --git a/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/exception/BadRequestExceptionDetails.java b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/exception/BadRequestExceptionDetails.java new file mode 100644 index 0000000000000000000000000000000000000000..99b5002b9980b4396aebb550a70780ce8a417932 --- /dev/null +++ b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/exception/BadRequestExceptionDetails.java @@ -0,0 +1,16 @@ +package br.ufrn.imd.authenticator.exception; + +import lombok.Builder; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +@Builder +public class BadRequestExceptionDetails { + private String title; + private int status; + private String details; + private String developerMessage; + private LocalDateTime timestamp; +} diff --git a/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/exception/RestExceptionHandler.java b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/exception/RestExceptionHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..e714d99f4b34bd34d79f9e23e95b6f7f7db40b05 --- /dev/null +++ b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/exception/RestExceptionHandler.java @@ -0,0 +1,24 @@ +package br.ufrn.imd.authenticator.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +import java.time.LocalDateTime; + +@ControllerAdvice +public class RestExceptionHandler { + @ExceptionHandler(BadRequestException.class) + public ResponseEntity<BadRequestExceptionDetails> handlerBadRequestException(BadRequestException bre) { + return new ResponseEntity<>( + BadRequestExceptionDetails.builder() + .timestamp(LocalDateTime.now()) + .status(HttpStatus.BAD_REQUEST.value()) + .title("Bad Request Exception") + .details(bre.getMessage()) + .developerMessage(bre.getClass().getName()) + .build(), HttpStatus.BAD_REQUEST + ); + } +} diff --git a/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/repository/ClientRepository.java b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/repository/ClientRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..5e9b5b9a8907e198495a409bd255ab7490fc7a5f --- /dev/null +++ b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/repository/ClientRepository.java @@ -0,0 +1,16 @@ +package br.ufrn.imd.authenticator.repository; + +import br.ufrn.imd.authenticator.domain.Client; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface ClientRepository extends JpaRepository<Client, Integer> { + + @Query(value = "SELECT c from Client c where c.account.number = ?1") + Optional<Client> findByAccountNumber(String number); + +} diff --git a/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/service/AuthenticatorService.java b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/service/AuthenticatorService.java new file mode 100644 index 0000000000000000000000000000000000000000..9dcfe74a8d19fbffaa53b1e86ce9f45b49ca298e --- /dev/null +++ b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/service/AuthenticatorService.java @@ -0,0 +1,29 @@ +package br.ufrn.imd.authenticator.service; + +import br.ufrn.imd.authenticator.domain.Client; +import br.ufrn.imd.authenticator.exception.BadRequestException; +import br.ufrn.imd.authenticator.repository.ClientRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.java.Log; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.stereotype.Service; + +@Log +@RequiredArgsConstructor +@Service +public class AuthenticatorService { + private final ClientRepository clientRepository; + + public Client authenticate(String accountNumber, String password) { + Client client = clientRepository.findByAccountNumber(accountNumber) + .orElseThrow(() -> new BadRequestException( + String.format("Customer not found with account number %s", accountNumber))); + + if(!new BCryptPasswordEncoder().matches(password, client.getAccount().getPassword())) { + throw new BadRequestException("Bad credentials"); + } + + log.info(client.getName() + " logged in (account number: " + client.getAccount().getNumber() + ")"); + return client; + } +} diff --git a/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/utils/DummyData.java b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/utils/DummyData.java new file mode 100644 index 0000000000000000000000000000000000000000..f4fdab4e8000f289f2f9235b19ad9f018c803ba5 --- /dev/null +++ b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/utils/DummyData.java @@ -0,0 +1,29 @@ +package br.ufrn.imd.authenticator.utils; + +import br.ufrn.imd.authenticator.domain.Account; +import br.ufrn.imd.authenticator.domain.Client; +import br.ufrn.imd.authenticator.repository.ClientRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; + +@RequiredArgsConstructor +@Component +public class DummyData { + private final ClientRepository clientRepository; + + @PostConstruct + public void insert() { + if(clientRepository.findAll().isEmpty()) { + Client client1 = new Client(null, "Fernando", new Account(null, "123", 3000d, + new BCryptPasswordEncoder().encode("s#nh4"))); + clientRepository.save(client1); + + Client client2 = new Client(null, "Maria", new Account(null, "321", 3000d, + new BCryptPasswordEncoder().encode("s#nh4"))); + clientRepository.save(client2); + } + } +} diff --git a/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/utils/message/CredentialsMessage.java b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/utils/message/CredentialsMessage.java new file mode 100644 index 0000000000000000000000000000000000000000..5853ed2abacfd77d77f9094736617f61c3b426ce --- /dev/null +++ b/WebServices/authenticator/src/main/java/br/ufrn/imd/authenticator/utils/message/CredentialsMessage.java @@ -0,0 +1,15 @@ +package br.ufrn.imd.authenticator.utils.message; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.io.Serializable; + +@Data +@AllArgsConstructor +public class CredentialsMessage implements Serializable { + private static final long serialVersionUID = 2L; + + private String number; + private String password; +} diff --git a/WebServices/authenticator/src/main/resources/application.yml b/WebServices/authenticator/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..b80dfd6f86c3a741a5cbd3653f3deef6e24538a9 --- /dev/null +++ b/WebServices/authenticator/src/main/resources/application.yml @@ -0,0 +1,25 @@ +server: + port: 8087 +eureka: + instance: + prefer-ip-address: true + client: + service-url: + defaultZone: http://registry:8081/eureka/ + fetch-registry: true + register-with-eureka: true + +spring: + application: + name: authenticator + datasource: + url: jdbc:postgresql://postgresServ:5432/postgres + username: postgres + password: postgres + jpa: + show-sql: false + database-platform: org.hibernate.dialect.PostgreSQL9Dialect + hibernate: + ddl-auto: update + jmx: + enabled: false \ No newline at end of file diff --git a/WebServices/authenticator/src/test/java/br/ufrn/imd/authenticator/AuthenticatorApplicationTests.java b/WebServices/authenticator/src/test/java/br/ufrn/imd/authenticator/AuthenticatorApplicationTests.java new file mode 100644 index 0000000000000000000000000000000000000000..fa71124c467ca33b6a744ff47614cd1eae01b9af --- /dev/null +++ b/WebServices/authenticator/src/test/java/br/ufrn/imd/authenticator/AuthenticatorApplicationTests.java @@ -0,0 +1,16 @@ +package br.ufrn.imd.authenticator; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +class AuthenticatorApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/WebServices/balance/.DS_Store b/WebServices/balance/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 Binary files /dev/null and b/WebServices/balance/.DS_Store differ diff --git a/WebServices/balance/.gitignore b/WebServices/balance/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ba5cb5cca8766c8b2403d25de25b1c880c5ef64a --- /dev/null +++ b/WebServices/balance/.gitignore @@ -0,0 +1,26 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ diff --git a/WebServices/balance/.mvn/wrapper/MavenWrapperDownloader.java b/WebServices/balance/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000000000000000000000000000000000000..47336fde724164b1329ed3595f5b6bff09f7c179 --- /dev/null +++ b/WebServices/balance/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,114 @@ +/* +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 + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.Properties; + +public class MavenWrapperDownloader { + + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/WebServices/balance/.mvn/wrapper/maven-wrapper.jar b/WebServices/balance/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..01e67997377a393fd672c7dcde9dccbedf0cb1e9 Binary files /dev/null and b/WebServices/balance/.mvn/wrapper/maven-wrapper.jar differ diff --git a/WebServices/balance/.mvn/wrapper/maven-wrapper.properties b/WebServices/balance/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000000000000000000000000000000000..cd0d451ccd6fc835996c9fe4eebf8a571154f515 --- /dev/null +++ b/WebServices/balance/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip diff --git a/WebServices/balance/Dockerfile b/WebServices/balance/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..f92094f4998baba1708d0c49f214ed30d149c7dd --- /dev/null +++ b/WebServices/balance/Dockerfile @@ -0,0 +1,3 @@ +FROM openjdk:11 +COPY target/balance.jar balance.jar +ENTRYPOINT ["java","-jar","balance.jar"] \ No newline at end of file diff --git a/WebServices/balance/mvnw b/WebServices/balance/mvnw new file mode 100755 index 0000000000000000000000000000000000000000..5551fde8e7dba1e37a1821e8b26374893e2a9e2e --- /dev/null +++ b/WebServices/balance/mvnw @@ -0,0 +1,286 @@ +#!/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 +# +# http://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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + 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" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + wget "$jarUrl" -O "$wrapperJarPath" + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + curl -o "$wrapperJarPath" "$jarUrl" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/WebServices/balance/mvnw.cmd b/WebServices/balance/mvnw.cmd new file mode 100644 index 0000000000000000000000000000000000000000..e5cfb0ae9eab80c314b7d79c164d4a00772824b8 --- /dev/null +++ b/WebServices/balance/mvnw.cmd @@ -0,0 +1,161 @@ +@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 http://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 Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" +FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + echo Found %WRAPPER_JAR% +) else ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" + echo Finished downloading %WRAPPER_JAR% +) +@REM End of extension + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/WebServices/balance/pom.xml b/WebServices/balance/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..0c76aad734c7c68a4339f8a8a4a2b138d58483ce --- /dev/null +++ b/WebServices/balance/pom.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>br.ufrn.imd</groupId> + <artifactId>dim0614</artifactId> + <version>1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> <!-- lookup parent from repository --> + </parent> + + <artifactId>balance</artifactId> + <version>0.0.1-SNAPSHOT</version> + <name>balance</name> + <description>balance service</description> + + <properties> + <java.version>11</java.version> + </properties> + + <build> + <finalName>balance</finalName> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <executable>true</executable> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.0</version> + <configuration> + <source>11</source> + <target>11</target> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/WebServices/balance/src/main/java/br/ufrn/imd/balance/BalanceApplication.java b/WebServices/balance/src/main/java/br/ufrn/imd/balance/BalanceApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..0d31538e08fea69fb74fa2cb12d7b26c68645be5 --- /dev/null +++ b/WebServices/balance/src/main/java/br/ufrn/imd/balance/BalanceApplication.java @@ -0,0 +1,13 @@ +package br.ufrn.imd.balance; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class BalanceApplication { + + public static void main(String[] args) { + SpringApplication.run(BalanceApplication.class, args); + } + +} diff --git a/WebServices/balance/src/main/java/br/ufrn/imd/balance/controller/BalanceController.java b/WebServices/balance/src/main/java/br/ufrn/imd/balance/controller/BalanceController.java new file mode 100644 index 0000000000000000000000000000000000000000..b07124dcf4301fb48e300c385ffac6ceb21179d8 --- /dev/null +++ b/WebServices/balance/src/main/java/br/ufrn/imd/balance/controller/BalanceController.java @@ -0,0 +1,18 @@ +package br.ufrn.imd.balance.controller; + +import br.ufrn.imd.balance.domain.Client; +import br.ufrn.imd.balance.service.BalanceService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/banking/client/{id}") +public class BalanceController { + private final BalanceService service; + + @GetMapping + public Client balance(@PathVariable Integer id) { + return service.balance(new Client(id)); + } +} diff --git a/WebServices/balance/src/main/java/br/ufrn/imd/balance/domain/Account.java b/WebServices/balance/src/main/java/br/ufrn/imd/balance/domain/Account.java new file mode 100644 index 0000000000000000000000000000000000000000..7c88d61e743d37152cfbaf2923e4e481891a5113 --- /dev/null +++ b/WebServices/balance/src/main/java/br/ufrn/imd/balance/domain/Account.java @@ -0,0 +1,26 @@ +package br.ufrn.imd.balance.domain; + +import lombok.*; + +import javax.persistence.*; +import java.io.Serializable; + +@Data +@Entity +@AllArgsConstructor +@NoArgsConstructor +public class Account implements Serializable { + + private static final long serialVersionUID = 2L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column(unique = true) + private String number; + + private Double balance; + + private String password; +} diff --git a/WebServices/balance/src/main/java/br/ufrn/imd/balance/domain/Client.java b/WebServices/balance/src/main/java/br/ufrn/imd/balance/domain/Client.java new file mode 100644 index 0000000000000000000000000000000000000000..c6ddcb0615c190ce29ab9419d2043ac70cdee50e --- /dev/null +++ b/WebServices/balance/src/main/java/br/ufrn/imd/balance/domain/Client.java @@ -0,0 +1,29 @@ +package br.ufrn.imd.balance.domain; + +import lombok.*; + +import javax.persistence.*; +import java.io.Serializable; + +@Data +@Entity +@AllArgsConstructor +@NoArgsConstructor +public class Client implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String name; + + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "account_id") + private Account account; + + public Client(Integer id) { + this.id = id; + } +} diff --git a/WebServices/balance/src/main/java/br/ufrn/imd/balance/exception/BadRequestException.java b/WebServices/balance/src/main/java/br/ufrn/imd/balance/exception/BadRequestException.java new file mode 100644 index 0000000000000000000000000000000000000000..e5045a33fc88da110d9b0a36bdbcfe8ded387974 --- /dev/null +++ b/WebServices/balance/src/main/java/br/ufrn/imd/balance/exception/BadRequestException.java @@ -0,0 +1,12 @@ +package br.ufrn.imd.balance.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(HttpStatus.BAD_REQUEST) +public class BadRequestException extends RuntimeException{ + + public BadRequestException(String message) { + super(message); + } +} diff --git a/WebServices/balance/src/main/java/br/ufrn/imd/balance/exception/BadRequestExceptionDetails.java b/WebServices/balance/src/main/java/br/ufrn/imd/balance/exception/BadRequestExceptionDetails.java new file mode 100644 index 0000000000000000000000000000000000000000..da6cf5c88148c93556fb440e7ad8cc099c3c7c54 --- /dev/null +++ b/WebServices/balance/src/main/java/br/ufrn/imd/balance/exception/BadRequestExceptionDetails.java @@ -0,0 +1,16 @@ +package br.ufrn.imd.balance.exception; + +import lombok.Builder; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +@Builder +public class BadRequestExceptionDetails { + private String title; + private int status; + private String details; + private String developerMessage; + private LocalDateTime timestamp; +} diff --git a/WebServices/balance/src/main/java/br/ufrn/imd/balance/exception/RestExceptionHandler.java b/WebServices/balance/src/main/java/br/ufrn/imd/balance/exception/RestExceptionHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..706ae7ddcf08250cfd6d4ae976dca903df403491 --- /dev/null +++ b/WebServices/balance/src/main/java/br/ufrn/imd/balance/exception/RestExceptionHandler.java @@ -0,0 +1,24 @@ +package br.ufrn.imd.balance.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +import java.time.LocalDateTime; + +@ControllerAdvice +public class RestExceptionHandler { + @ExceptionHandler(BadRequestException.class) + public ResponseEntity<BadRequestExceptionDetails> handlerBadRequestException(BadRequestException bre) { + return new ResponseEntity<>( + BadRequestExceptionDetails.builder() + .timestamp(LocalDateTime.now()) + .status(HttpStatus.BAD_REQUEST.value()) + .title("Bad Request Exception") + .details(bre.getMessage()) + .developerMessage(bre.getClass().getName()) + .build(), HttpStatus.BAD_REQUEST + ); + } +} diff --git a/WebServices/balance/src/main/java/br/ufrn/imd/balance/repository/ClientRepository.java b/WebServices/balance/src/main/java/br/ufrn/imd/balance/repository/ClientRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..78efb735c6634daf9cbaacc08f0855d2c7e30f74 --- /dev/null +++ b/WebServices/balance/src/main/java/br/ufrn/imd/balance/repository/ClientRepository.java @@ -0,0 +1,9 @@ +package br.ufrn.imd.balance.repository; + +import br.ufrn.imd.balance.domain.Client; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ClientRepository extends JpaRepository<Client, Integer> { +} diff --git a/WebServices/balance/src/main/java/br/ufrn/imd/balance/service/BalanceService.java b/WebServices/balance/src/main/java/br/ufrn/imd/balance/service/BalanceService.java new file mode 100644 index 0000000000000000000000000000000000000000..a53fadab653b264296e3ea71c9d4bf638de97b5a --- /dev/null +++ b/WebServices/balance/src/main/java/br/ufrn/imd/balance/service/BalanceService.java @@ -0,0 +1,25 @@ +package br.ufrn.imd.balance.service; + +import br.ufrn.imd.balance.domain.Account; +import br.ufrn.imd.balance.domain.Client; +import br.ufrn.imd.balance.exception.BadRequestException; +import br.ufrn.imd.balance.repository.ClientRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.java.Log; +import org.springframework.stereotype.Service; + +@Log +@Service +@RequiredArgsConstructor +public class BalanceService { + private final ClientRepository clientRepository; + + public Client balance(Client client) { + Client persistedClient = clientRepository.findById(client.getId()) + .orElseThrow(() -> new BadRequestException("Invalid user!")); + Account account = persistedClient.getAccount(); + log.info(String.format("Account Balance: R$ %.2f", account.getBalance())); + + return persistedClient; + } +} diff --git a/WebServices/balance/src/main/resources/application.yml b/WebServices/balance/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..920fb9b102878eecba51a5eaa535cec246c296fd --- /dev/null +++ b/WebServices/balance/src/main/resources/application.yml @@ -0,0 +1,25 @@ +server: + port: 8084 +eureka: + instance: + prefer-ip-address: true + client: + service-url: + defaultZone: http://registry:8081/eureka/ + fetch-registry: true + register-with-eureka: true + +spring: + application: + name: balance + datasource: + url: jdbc:postgresql://postgresServ:5432/postgres + username: postgres + password: postgres + jpa: + show-sql: false + database-platform: org.hibernate.dialect.PostgreSQL9Dialect + hibernate: + ddl-auto: update + jmx: + enabled: false \ No newline at end of file diff --git a/WebServices/balance/src/test/java/br/ufrn/imd/withdrawal/CourseApplicationTests.java b/WebServices/balance/src/test/java/br/ufrn/imd/withdrawal/CourseApplicationTests.java new file mode 100644 index 0000000000000000000000000000000000000000..b84743fe08d4bfdafd2ba2588a9a532fa80fa854 --- /dev/null +++ b/WebServices/balance/src/test/java/br/ufrn/imd/withdrawal/CourseApplicationTests.java @@ -0,0 +1,16 @@ +package br.ufrn.imd.withdrawal; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class CourseApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/WebServices/balance/target/classes/application.yml b/WebServices/balance/target/classes/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..920fb9b102878eecba51a5eaa535cec246c296fd --- /dev/null +++ b/WebServices/balance/target/classes/application.yml @@ -0,0 +1,25 @@ +server: + port: 8084 +eureka: + instance: + prefer-ip-address: true + client: + service-url: + defaultZone: http://registry:8081/eureka/ + fetch-registry: true + register-with-eureka: true + +spring: + application: + name: balance + datasource: + url: jdbc:postgresql://postgresServ:5432/postgres + username: postgres + password: postgres + jpa: + show-sql: false + database-platform: org.hibernate.dialect.PostgreSQL9Dialect + hibernate: + ddl-auto: update + jmx: + enabled: false \ No newline at end of file diff --git a/WebServices/balance/target/classes/br/ufrn/imd/balance/BalanceApplication.class b/WebServices/balance/target/classes/br/ufrn/imd/balance/BalanceApplication.class new file mode 100644 index 0000000000000000000000000000000000000000..954080045c0ccad237634742e89490f67f07358f Binary files /dev/null and b/WebServices/balance/target/classes/br/ufrn/imd/balance/BalanceApplication.class differ diff --git a/WebServices/balance/target/classes/br/ufrn/imd/balance/controller/BalanceController.class b/WebServices/balance/target/classes/br/ufrn/imd/balance/controller/BalanceController.class new file mode 100644 index 0000000000000000000000000000000000000000..ed4081f2b3cf0f4b4cdee5124506d97eac2803f3 Binary files /dev/null and b/WebServices/balance/target/classes/br/ufrn/imd/balance/controller/BalanceController.class differ diff --git a/WebServices/balance/target/classes/br/ufrn/imd/balance/domain/Account.class b/WebServices/balance/target/classes/br/ufrn/imd/balance/domain/Account.class new file mode 100644 index 0000000000000000000000000000000000000000..7a7de1665a1dfef9805b0d6a5027bbc5799f5025 Binary files /dev/null and b/WebServices/balance/target/classes/br/ufrn/imd/balance/domain/Account.class differ diff --git a/WebServices/balance/target/classes/br/ufrn/imd/balance/domain/Client.class b/WebServices/balance/target/classes/br/ufrn/imd/balance/domain/Client.class new file mode 100644 index 0000000000000000000000000000000000000000..63619d95b4b2833fc5ba0e309c04faf5a96fbcfb Binary files /dev/null and b/WebServices/balance/target/classes/br/ufrn/imd/balance/domain/Client.class differ diff --git a/WebServices/balance/target/classes/br/ufrn/imd/balance/repository/ClientRepository.class b/WebServices/balance/target/classes/br/ufrn/imd/balance/repository/ClientRepository.class new file mode 100644 index 0000000000000000000000000000000000000000..712598f71b37c3cbba4cc4f301c93fcfe4229165 Binary files /dev/null and b/WebServices/balance/target/classes/br/ufrn/imd/balance/repository/ClientRepository.class differ diff --git a/WebServices/balance/target/classes/br/ufrn/imd/balance/service/BalanceService.class b/WebServices/balance/target/classes/br/ufrn/imd/balance/service/BalanceService.class new file mode 100644 index 0000000000000000000000000000000000000000..6cb5c3ea9d7829d9e2493d1a707f1944ba4dd65c Binary files /dev/null and b/WebServices/balance/target/classes/br/ufrn/imd/balance/service/BalanceService.class differ diff --git a/WebServices/balance/target/maven-archiver/pom.properties b/WebServices/balance/target/maven-archiver/pom.properties new file mode 100644 index 0000000000000000000000000000000000000000..9c45c41d2c312d08c4537905879c7e190686aedc --- /dev/null +++ b/WebServices/balance/target/maven-archiver/pom.properties @@ -0,0 +1,4 @@ +#Created by Apache Maven 3.8.4 +groupId=br.ufrn.imd +artifactId=balance +version=0.0.1-SNAPSHOT diff --git a/WebServices/balance/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/WebServices/balance/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..ca2a7b017b942c116d5545fe5b4f2461de1d3337 --- /dev/null +++ b/WebServices/balance/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,10 @@ +br\ufrn\imd\balance\BalanceApplication.class +br\ufrn\imd\balance\controller\BalanceController.class +br\ufrn\imd\balance\domain\Account.class +br\ufrn\imd\balance\exception\RestExceptionHandler.class +br\ufrn\imd\balance\exception\BadRequestException.class +br\ufrn\imd\balance\domain\Client.class +br\ufrn\imd\balance\exception\BadRequestExceptionDetails$BadRequestExceptionDetailsBuilder.class +br\ufrn\imd\balance\exception\BadRequestExceptionDetails.class +br\ufrn\imd\balance\repository\ClientRepository.class +br\ufrn\imd\balance\service\BalanceService.class diff --git a/WebServices/balance/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/WebServices/balance/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..8485643f57e4481b76b30b013685a086d815c132 --- /dev/null +++ b/WebServices/balance/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,9 @@ +C:\Users\maria\Documents\Projetos\dim0614\WebServices\balance\src\main\java\br\ufrn\imd\balance\repository\ClientRepository.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\balance\src\main\java\br\ufrn\imd\balance\exception\BadRequestException.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\balance\src\main\java\br\ufrn\imd\balance\exception\RestExceptionHandler.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\balance\src\main\java\br\ufrn\imd\balance\controller\BalanceController.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\balance\src\main\java\br\ufrn\imd\balance\BalanceApplication.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\balance\src\main\java\br\ufrn\imd\balance\service\BalanceService.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\balance\src\main\java\br\ufrn\imd\balance\domain\Account.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\balance\src\main\java\br\ufrn\imd\balance\domain\Client.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\balance\src\main\java\br\ufrn\imd\balance\exception\BadRequestExceptionDetails.java diff --git a/WebServices/balance/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/WebServices/balance/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..3a5345ad0769a7ebacaabdd4abc78f4ee36396a5 --- /dev/null +++ b/WebServices/balance/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +br\ufrn\imd\withdrawal\CourseApplicationTests.class diff --git a/WebServices/balance/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/WebServices/balance/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..62020966d6bf88c17ef9d9e53124898e1e9dc931 --- /dev/null +++ b/WebServices/balance/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +C:\Users\maria\Documents\Projetos\dim0614\WebServices\balance\src\test\java\br\ufrn\imd\withdrawal\CourseApplicationTests.java diff --git a/WebServices/client/.DS_Store b/WebServices/client/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 Binary files /dev/null and b/WebServices/client/.DS_Store differ diff --git a/WebServices/client/.gitignore b/WebServices/client/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ba5cb5cca8766c8b2403d25de25b1c880c5ef64a --- /dev/null +++ b/WebServices/client/.gitignore @@ -0,0 +1,26 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ diff --git a/WebServices/client/.mvn/wrapper/MavenWrapperDownloader.java b/WebServices/client/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000000000000000000000000000000000000..47336fde724164b1329ed3595f5b6bff09f7c179 --- /dev/null +++ b/WebServices/client/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,114 @@ +/* +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 + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.Properties; + +public class MavenWrapperDownloader { + + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/WebServices/client/.mvn/wrapper/maven-wrapper.jar b/WebServices/client/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..01e67997377a393fd672c7dcde9dccbedf0cb1e9 Binary files /dev/null and b/WebServices/client/.mvn/wrapper/maven-wrapper.jar differ diff --git a/WebServices/client/.mvn/wrapper/maven-wrapper.properties b/WebServices/client/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000000000000000000000000000000000..cd0d451ccd6fc835996c9fe4eebf8a571154f515 --- /dev/null +++ b/WebServices/client/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip diff --git a/WebServices/client/Dockerfile b/WebServices/client/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..9885e7466359c0bd6426716ab718c12064632b70 --- /dev/null +++ b/WebServices/client/Dockerfile @@ -0,0 +1,3 @@ +FROM openjdk:11 +COPY target/withdrawal.jar withdrawal.jar +ENTRYPOINT ["java","-jar","withdrawal.jar"] \ No newline at end of file diff --git a/WebServices/client/mvnw b/WebServices/client/mvnw new file mode 100755 index 0000000000000000000000000000000000000000..5551fde8e7dba1e37a1821e8b26374893e2a9e2e --- /dev/null +++ b/WebServices/client/mvnw @@ -0,0 +1,286 @@ +#!/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 +# +# http://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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + 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" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + wget "$jarUrl" -O "$wrapperJarPath" + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + curl -o "$wrapperJarPath" "$jarUrl" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/WebServices/client/mvnw.cmd b/WebServices/client/mvnw.cmd new file mode 100644 index 0000000000000000000000000000000000000000..e5cfb0ae9eab80c314b7d79c164d4a00772824b8 --- /dev/null +++ b/WebServices/client/mvnw.cmd @@ -0,0 +1,161 @@ +@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 http://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 Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" +FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + echo Found %WRAPPER_JAR% +) else ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" + echo Finished downloading %WRAPPER_JAR% +) +@REM End of extension + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/WebServices/client/pom.xml b/WebServices/client/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..a2109e35c8f696f96d428af00d3803499099fe4b --- /dev/null +++ b/WebServices/client/pom.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>br.ufrn.imd</groupId> + <artifactId>dim0614</artifactId> + <version>1.0-SNAPSHOT</version> + <relativePath>../</relativePath> <!-- lookup parent from repository --> + </parent> + + <artifactId>client</artifactId> + <version>0.0.1-SNAPSHOT</version> + <name>client</name> + <description>Spring Boot Micro-services By DevDojo</description> + + <properties> + <java.version>11</java.version> + </properties> + + <build> + <finalName>client</finalName> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <executable>true</executable> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.0</version> + <configuration> + <source>11</source> + <target>11</target> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/WebServices/client/src/main/java/br/ufrn/imd/client/ClientApplication.java b/WebServices/client/src/main/java/br/ufrn/imd/client/ClientApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..9ae1baaae3cf0af97e64d0bebd6a6e6c2b640c6d --- /dev/null +++ b/WebServices/client/src/main/java/br/ufrn/imd/client/ClientApplication.java @@ -0,0 +1,25 @@ +package br.ufrn.imd.client; + +import br.ufrn.imd.client.utils.MachineState; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ClientApplication { + + public static void main(String[] args) { + + MachineState mS = new MachineState(); + + for(;;) { + while(!mS.hasUser()) mS.login(); + + while(mS.quit() || mS.hasUser()) { + mS.render(); + mS.processEvents(); + mS.update(); + } + } + + } + +} diff --git a/WebServices/client/src/main/java/br/ufrn/imd/client/domain/Account.java b/WebServices/client/src/main/java/br/ufrn/imd/client/domain/Account.java new file mode 100644 index 0000000000000000000000000000000000000000..6be2d49a8c008fe8e4d41cc2416e69b849de7058 --- /dev/null +++ b/WebServices/client/src/main/java/br/ufrn/imd/client/domain/Account.java @@ -0,0 +1,28 @@ +package br.ufrn.imd.client.domain; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import java.io.Serializable; + +@Data +@Entity +@AllArgsConstructor +@NoArgsConstructor +public class Account implements Serializable { + + private static final long serialVersionUID = 2L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column(unique = true) + private String number; + + private Double balance; + + private String password; +} diff --git a/WebServices/client/src/main/java/br/ufrn/imd/client/domain/Client.java b/WebServices/client/src/main/java/br/ufrn/imd/client/domain/Client.java new file mode 100644 index 0000000000000000000000000000000000000000..22a8981968c9ab542b8fddb5642c3bd8f0e51b38 --- /dev/null +++ b/WebServices/client/src/main/java/br/ufrn/imd/client/domain/Client.java @@ -0,0 +1,31 @@ +package br.ufrn.imd.client.domain; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import java.io.Serializable; + +@Data +@Entity +@AllArgsConstructor +@NoArgsConstructor +public class Client implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String name; + + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "account_id") + private Account account; + + public Client(Integer id) { + this.id = id; + } +} diff --git a/WebServices/client/src/main/java/br/ufrn/imd/client/exception/BadRequestException.java b/WebServices/client/src/main/java/br/ufrn/imd/client/exception/BadRequestException.java new file mode 100644 index 0000000000000000000000000000000000000000..4c07122fc9df9d54abda35cddc1be13eed3ccabd --- /dev/null +++ b/WebServices/client/src/main/java/br/ufrn/imd/client/exception/BadRequestException.java @@ -0,0 +1,12 @@ +package br.ufrn.imd.client.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(HttpStatus.BAD_REQUEST) +public class BadRequestException extends RuntimeException{ + + public BadRequestException(String message) { + super(message); + } +} diff --git a/WebServices/client/src/main/java/br/ufrn/imd/client/exception/BadRequestExceptionDetails.java b/WebServices/client/src/main/java/br/ufrn/imd/client/exception/BadRequestExceptionDetails.java new file mode 100644 index 0000000000000000000000000000000000000000..75feaad8eb398d4fe5da7270b857142dbbde5b29 --- /dev/null +++ b/WebServices/client/src/main/java/br/ufrn/imd/client/exception/BadRequestExceptionDetails.java @@ -0,0 +1,16 @@ +package br.ufrn.imd.client.exception; + +import lombok.Builder; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +@Builder +public class BadRequestExceptionDetails { + private String title; + private int status; + private String details; + private String developerMessage; + private LocalDateTime timestamp; +} diff --git a/WebServices/client/src/main/java/br/ufrn/imd/client/exception/RestExceptionHandler.java b/WebServices/client/src/main/java/br/ufrn/imd/client/exception/RestExceptionHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..254c74e4fb1baa84184a6fdc83e06bccb6c95725 --- /dev/null +++ b/WebServices/client/src/main/java/br/ufrn/imd/client/exception/RestExceptionHandler.java @@ -0,0 +1,24 @@ +package br.ufrn.imd.client.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +import java.time.LocalDateTime; + +@ControllerAdvice +public class RestExceptionHandler { + @ExceptionHandler(BadRequestException.class) + public ResponseEntity<BadRequestExceptionDetails> handlerBadRequestException(BadRequestException bre) { + return new ResponseEntity<>( + BadRequestExceptionDetails.builder() + .timestamp(LocalDateTime.now()) + .status(HttpStatus.BAD_REQUEST.value()) + .title("Bad Request Exception") + .details(bre.getMessage()) + .developerMessage(bre.getClass().getName()) + .build(), HttpStatus.BAD_REQUEST + ); + } +} diff --git a/WebServices/client/src/main/java/br/ufrn/imd/client/utils/MachineState.java b/WebServices/client/src/main/java/br/ufrn/imd/client/utils/MachineState.java new file mode 100644 index 0000000000000000000000000000000000000000..103dc5a14c10f33f37d09a8be063dcdd11a2f634 --- /dev/null +++ b/WebServices/client/src/main/java/br/ufrn/imd/client/utils/MachineState.java @@ -0,0 +1,252 @@ +package br.ufrn.imd.client.utils; + +import br.ufrn.imd.client.domain.Client; +import br.ufrn.imd.client.utils.message.CredentialsMessage; +import lombok.Data; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestTemplate; + +import java.util.Scanner; + +import static br.ufrn.imd.client.utils.NameSpace.*; + +@Data +@Component +public class MachineState { + + private RestTemplate restTemplate = new RestTemplate(); + public static final String INITIAL= "INITIAL"; + public static final String READ = "READ"; + public static final String DEPOSIT = "DEPOSIT"; + public static final String BALANCE = "BALANCE"; + public static final String WITHDRAWAL = "WITHDRAWAL"; + public static final String TRANSFER = "TRANSFER"; + + public static final String START = "START"; + public static final String INVALID_INPUT = "INVALID_INPUT"; + public static final String QUIT = "QUIT"; + + private String state; + private Scanner sc; + private String inputValue; + + private Client client; + + public MachineState() { + state = INITIAL; + inputValue = new String(); + sc = new Scanner(System.in); + } + + public void login() { + System.out.println(">>> Please enter your bank account number"); + String accountNumber = sc.nextLine(); + + System.out.println(">>> Please enter your password"); + String password = sc.nextLine(); + + try { + ResponseEntity<Client> response = restTemplate.postForEntity( + HOST_AUTHENTICATOR_SERVICE, + new CredentialsMessage(accountNumber, password), + Client.class); + if(response.getStatusCodeValue() == 200) { + state = INITIAL; + this.client = response.getBody(); + } + } catch (HttpClientErrorException ex){ + System.out.println(">>> Bad credentials"); + } + + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + + public Boolean hasUser() { + return client != null; + } + + public Boolean quit() { + return !state.equals(QUIT); + } + + public void update() { + if(state.equals(INITIAL)) { + state = START; + } else if(state.equals(START)) { + state = READ; + } else if(state.equals(READ)) { + state = inputValue; + } else if(state.equals(INVALID_INPUT)) { + state = START; + } else if(state.equals(DEPOSIT)) { + state = START; + } else if(state.equals(BALANCE)) { + state = START; + } else if(state.equals(WITHDRAWAL)) { + state = START; + } else if(state.equals(TRANSFER)) { + state = START; + } + } + + public void processEvents() { + if(state.equals(READ)) { + inputValue = sc.nextLine().trim().toUpperCase(); + if(!inputValue.isEmpty() && + !inputValue.equals(QUIT) && + !inputValue.equals(DEPOSIT) && + !inputValue.equals(BALANCE) && + !inputValue.equals(WITHDRAWAL) && + !inputValue.equals(TRANSFER)) { + inputValue = INVALID_INPUT; + } + } else if(state.equals(DEPOSIT)) { + String v = sc.nextLine(); + try { + ResponseEntity<Client> response = + restTemplate.getForEntity( + HOST_DEPOSIT_SERVICE + + String.format("/%d?value=%s", this.client.getId(), v), + Client.class); + if (response.getStatusCodeValue() == 200) { + System.out.println( + String.format(">>> Your balance is: %.2f", response.getBody().getAccount().getBalance()) + ); + } + } catch (Exception e) { + System.out.println("Invalid operation!"); + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + + } else if(state.equals(BALANCE)) { + try { + ResponseEntity<Client> response = + restTemplate.getForEntity(HOST_BALANCE_SERVICE + + String.format("/%d", this.client.getId()), Client.class); + if (response.getStatusCodeValue() == 200) { + System.out.println( + String.format(">>> Your balance is: %.2f", response.getBody().getAccount().getBalance()) + ); + } + } catch (Exception e) { + System.out.println("Invalid operation!"); + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + + } else if(state.equals(WITHDRAWAL)) { + String v = sc.nextLine(); + try { + ResponseEntity<Client> response = + restTemplate.getForEntity( + HOST_WITHDRAWAL_SERVICE + + String.format("/%d?value=%s", this.client.getId(), v), + Client.class); + if (response.getStatusCodeValue() == 200) { + System.out.println( + String.format(">>> Your balance is: %.2f", response.getBody().getAccount().getBalance()) + ); + } else if (response.getStatusCodeValue() == 500) { + System.out.println( + String.format(">>> %s", response.getBody()) + ); + } + } catch (Exception e) { + System.out.println("Invalid operation!"); + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } else if(state.equals(TRANSFER)) { + String accountNumber = sc.nextLine(); + System.out.println(">>> Please enter with the value that you want transfer"); + String v = sc.nextLine(); + try { + ResponseEntity<Client> response = + restTemplate.getForEntity( + HOST_TRANSFER_SERVICE + + String.format("/%d?value=%s&toAccount=%s", + this.client.getId(), + v, + accountNumber + ), + Client.class); + + if (response.getStatusCodeValue() == 200) { + System.out.println( + String.format(">>> Your balance is: %.2f", response.getBody().getAccount().getBalance()) + ); + } else if (response.getStatusCodeValue() == 500) { + System.out.println( + String.format(">>> %s", response.getBody()) + ); + } + } catch (Exception e) { + System.out.println("Invalid operation!"); + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } else if(state.equals(QUIT)) { + this.client = null; + System.out.println(">>> You have logged out"); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + + public void render() { + try { + if(state.equals(INITIAL)) { + System.out.println(">>> Initializing..."); + Thread.sleep(1000); + } else if(state.equals(START)) { + System.out.println("These are the avaliable operations"); + System.out.println("---------------------------------"); + System.out.println(" - deposit \t\t - balance"); + System.out.println(" - withdrawal \t - transfer"); + System.out.println(" - quit"); + System.out.println("---------------------------------"); + Thread.sleep(1000); + } else if(state.equals(READ)) { + System.out.println(">>> Please enter with wich operation do you want"); + } else if(state.equals(INVALID_INPUT)) { + System.out.println(">>> Please enter with a VALID operation"); + Thread.sleep(3000); + } else if(state.equals(DEPOSIT)) { + System.out.println(">>> Starting deposit operation"); + System.out.println(">>> Please enter with the value that you want deposit"); + } else if(state.equals(WITHDRAWAL)) { + System.out.println(">>> Starting withdrawal operation"); + System.out.println(">>> Please enter the value you want to withdraw"); + } else if(state.equals(TRANSFER)) { + System.out.println(">>> Starting transfer operation"); + System.out.println(">>> Please enter with the recipient's account number"); + } + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/WebServices/client/src/main/java/br/ufrn/imd/client/utils/NameSpace.java b/WebServices/client/src/main/java/br/ufrn/imd/client/utils/NameSpace.java new file mode 100644 index 0000000000000000000000000000000000000000..af41596d7387246c7f49a18c20fdcb82cd00bdfe --- /dev/null +++ b/WebServices/client/src/main/java/br/ufrn/imd/client/utils/NameSpace.java @@ -0,0 +1,14 @@ +package br.ufrn.imd.client.utils; + +public class NameSpace { + public final static Integer PORT_AUTHENTICATOR_SERVICE = 8080; + public final static Integer PORT_WITHDRAWAL_SERVICE = 8080; + public static final Integer PORT_DEPOSIT_SERVICE = 8080; + public static final Integer PORT_BALANCE_SERVICE = 8080; + public static final Integer PORT_TRANSFER_SERVICE = 8080; + public final static String HOST_AUTHENTICATOR_SERVICE = String.format("http://127.0.0.1:%d/%s", PORT_AUTHENTICATOR_SERVICE, "/gateway/authenticator/banking/login"); + public final static String HOST_WITHDRAWAL_SERVICE = String.format("http://127.0.0.1:%d/%s", PORT_WITHDRAWAL_SERVICE, "/gateway/withdrawal/banking/client"); + public static final String HOST_DEPOSIT_SERVICE = String.format("http://127.0.0.1:%d/%s", PORT_DEPOSIT_SERVICE, "/gateway/deposit/banking/client"); + public static final String HOST_BALANCE_SERVICE = String.format("http://127.0.0.1:%d/%s", PORT_BALANCE_SERVICE, "/gateway/balance/banking/client"); + public final static String HOST_TRANSFER_SERVICE = String.format("http://127.0.0.1:%d/%s", PORT_TRANSFER_SERVICE, "/gateway/transfer/banking/client"); +} diff --git a/WebServices/client/src/main/java/br/ufrn/imd/client/utils/message/CredentialsMessage.java b/WebServices/client/src/main/java/br/ufrn/imd/client/utils/message/CredentialsMessage.java new file mode 100644 index 0000000000000000000000000000000000000000..234192784d6603a7f9a248c9ac444356ac68bc0c --- /dev/null +++ b/WebServices/client/src/main/java/br/ufrn/imd/client/utils/message/CredentialsMessage.java @@ -0,0 +1,15 @@ +package br.ufrn.imd.client.utils.message; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.io.Serializable; + +@Data +@AllArgsConstructor +public class CredentialsMessage implements Serializable { + private static final long serialVersionUID = 2L; + + private String number; + private String password; +} diff --git a/WebServices/client/src/main/resources/application.yml b/WebServices/client/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..67cdb45d6c9da505cb5ac23ad2f6149abf3bed99 --- /dev/null +++ b/WebServices/client/src/main/resources/application.yml @@ -0,0 +1,5 @@ +server: + port: 8087 +spring: + application: + name: client \ No newline at end of file diff --git a/WebServices/client/src/test/java/br/ufrn/imd/withdrawal/CourseApplicationTests.java b/WebServices/client/src/test/java/br/ufrn/imd/withdrawal/CourseApplicationTests.java new file mode 100644 index 0000000000000000000000000000000000000000..b84743fe08d4bfdafd2ba2588a9a532fa80fa854 --- /dev/null +++ b/WebServices/client/src/test/java/br/ufrn/imd/withdrawal/CourseApplicationTests.java @@ -0,0 +1,16 @@ +package br.ufrn.imd.withdrawal; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class CourseApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/WebServices/deposit/.DS_Store b/WebServices/deposit/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 Binary files /dev/null and b/WebServices/deposit/.DS_Store differ diff --git a/WebServices/deposit/.gitignore b/WebServices/deposit/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ba5cb5cca8766c8b2403d25de25b1c880c5ef64a --- /dev/null +++ b/WebServices/deposit/.gitignore @@ -0,0 +1,26 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ diff --git a/WebServices/deposit/.mvn/wrapper/MavenWrapperDownloader.java b/WebServices/deposit/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000000000000000000000000000000000000..47336fde724164b1329ed3595f5b6bff09f7c179 --- /dev/null +++ b/WebServices/deposit/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,114 @@ +/* +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 + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.Properties; + +public class MavenWrapperDownloader { + + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/WebServices/deposit/.mvn/wrapper/maven-wrapper.jar b/WebServices/deposit/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..01e67997377a393fd672c7dcde9dccbedf0cb1e9 Binary files /dev/null and b/WebServices/deposit/.mvn/wrapper/maven-wrapper.jar differ diff --git a/WebServices/deposit/.mvn/wrapper/maven-wrapper.properties b/WebServices/deposit/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000000000000000000000000000000000..cd0d451ccd6fc835996c9fe4eebf8a571154f515 --- /dev/null +++ b/WebServices/deposit/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip diff --git a/WebServices/deposit/Dockerfile b/WebServices/deposit/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..875766f12fff59ac2bd2a5df733572d5465ad96b --- /dev/null +++ b/WebServices/deposit/Dockerfile @@ -0,0 +1,3 @@ +FROM openjdk:11 +COPY target/deposit.jar deposit.jar +ENTRYPOINT ["java","-jar","deposit.jar"] \ No newline at end of file diff --git a/WebServices/deposit/mvnw b/WebServices/deposit/mvnw new file mode 100755 index 0000000000000000000000000000000000000000..5551fde8e7dba1e37a1821e8b26374893e2a9e2e --- /dev/null +++ b/WebServices/deposit/mvnw @@ -0,0 +1,286 @@ +#!/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 +# +# http://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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + 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" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + wget "$jarUrl" -O "$wrapperJarPath" + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + curl -o "$wrapperJarPath" "$jarUrl" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/WebServices/deposit/mvnw.cmd b/WebServices/deposit/mvnw.cmd new file mode 100644 index 0000000000000000000000000000000000000000..e5cfb0ae9eab80c314b7d79c164d4a00772824b8 --- /dev/null +++ b/WebServices/deposit/mvnw.cmd @@ -0,0 +1,161 @@ +@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 http://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 Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" +FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + echo Found %WRAPPER_JAR% +) else ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" + echo Finished downloading %WRAPPER_JAR% +) +@REM End of extension + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/WebServices/deposit/pom.xml b/WebServices/deposit/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..5611f6e79c7079bad0854c12cb33d2e23145deb9 --- /dev/null +++ b/WebServices/deposit/pom.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>br.ufrn.imd</groupId> + <artifactId>dim0614</artifactId> + <version>1.0-SNAPSHOT</version> + <relativePath>../</relativePath> <!-- lookup parent from repository --> + </parent> + + <artifactId>deposit</artifactId> + <version>0.0.1-SNAPSHOT</version> + <name>deposit</name> + <description>Spring Boot Micro-services By DevDojo</description> + + <properties> + <java.version>11</java.version> + </properties> + + <build> + <finalName>deposit</finalName> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <executable>true</executable> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.0</version> + <configuration> + <source>11</source> + <target>11</target> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/DepositApplication.java b/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/DepositApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..23b7f5856812223d129e2f973f61a18cea69a364 --- /dev/null +++ b/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/DepositApplication.java @@ -0,0 +1,13 @@ +package br.ufrn.imd.deposit; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DepositApplication { + + public static void main(String[] args) { + SpringApplication.run(DepositApplication.class, args); + } + +} diff --git a/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/controller/DepositController.java b/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/controller/DepositController.java new file mode 100644 index 0000000000000000000000000000000000000000..02ac88128fc0160c013769bd3cd1d23e5e9a5253 --- /dev/null +++ b/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/controller/DepositController.java @@ -0,0 +1,18 @@ +package br.ufrn.imd.deposit.controller; + +import br.ufrn.imd.deposit.domain.Client; +import br.ufrn.imd.deposit.service.DepositService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/banking/client/{id}") +public class DepositController { + private final DepositService service; + + @GetMapping + public Client deposit(@PathVariable Integer id, @RequestParam(name = "value") Double value) { + return service.deposit(value, new Client(id)); + } +} diff --git a/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/domain/Account.java b/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/domain/Account.java new file mode 100644 index 0000000000000000000000000000000000000000..9bd8d2440ed686189b4a38081e3738d86961dd51 --- /dev/null +++ b/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/domain/Account.java @@ -0,0 +1,26 @@ +package br.ufrn.imd.deposit.domain; + +import lombok.*; + +import javax.persistence.*; +import java.io.Serializable; + +@AllArgsConstructor +@NoArgsConstructor +@Data +@Entity +public class Account implements Serializable { + + private static final long serialVersionUID = 2L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column(unique = true) + private String number; + + private Double balance; + + private String password; +} diff --git a/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/domain/Client.java b/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/domain/Client.java new file mode 100644 index 0000000000000000000000000000000000000000..fea289f41a982476a3d9c07a2701883d2f0e23a4 --- /dev/null +++ b/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/domain/Client.java @@ -0,0 +1,29 @@ +package br.ufrn.imd.deposit.domain; + +import lombok.*; + +import javax.persistence.*; +import java.io.Serializable; + +@AllArgsConstructor +@NoArgsConstructor +@Data +@Entity +public class Client implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String name; + + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "account_id") + private Account account; + + public Client(Integer id) { + this.id = id; + } +} diff --git a/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/repository/ClientRepository.java b/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/repository/ClientRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..bd5c797d6e36e8f1e63880e7c471d9d1ac9bb467 --- /dev/null +++ b/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/repository/ClientRepository.java @@ -0,0 +1,9 @@ +package br.ufrn.imd.deposit.repository; + +import br.ufrn.imd.deposit.domain.Client; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ClientRepository extends JpaRepository<Client, Integer> { +} diff --git a/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/service/DepositService.java b/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/service/DepositService.java new file mode 100644 index 0000000000000000000000000000000000000000..f266a4303a378a812648d5e0956b11653f103c39 --- /dev/null +++ b/WebServices/deposit/src/main/java/br/ufrn/imd/deposit/service/DepositService.java @@ -0,0 +1,29 @@ +package br.ufrn.imd.deposit.service; + +import br.ufrn.imd.deposit.domain.Account; +import br.ufrn.imd.deposit.domain.Client; +import br.ufrn.imd.deposit.repository.ClientRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.java.Log; +import org.springframework.stereotype.Service; + +@Log +@RequiredArgsConstructor +@Service +public class DepositService { + private final ClientRepository clientRepository; + + public Client deposit(Double value, Client client) { + client = clientRepository.findById(client.getId()) + .orElseThrow(() -> new RuntimeException("Invalid user!")); + + Account account = client.getAccount(); + account.setBalance(account.getBalance() + value); + client = clientRepository.save(client); + + log.info("Deposit concluded!"); + log.info(String.format("Total: %.2f", client.getAccount().getBalance())); + + return client; + } +} diff --git a/WebServices/deposit/src/main/resources/application.yml b/WebServices/deposit/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..76df8328cb3d8b4f2ba06b63501f8b40c034bd84 --- /dev/null +++ b/WebServices/deposit/src/main/resources/application.yml @@ -0,0 +1,25 @@ +server: + port: 8085 +eureka: + instance: + prefer-ip-address: true + client: + service-url: + defaultZone: http://registry:8081/eureka/ + fetch-registry: true + register-with-eureka: true + +spring: + application: + name: deposit + datasource: + url: jdbc:postgresql://postgresServ:5432/postgres + username: postgres + password: postgres + jpa: + show-sql: false + database-platform: org.hibernate.dialect.PostgreSQL9Dialect + hibernate: + ddl-auto: update + jmx: + enabled: false \ No newline at end of file diff --git a/WebServices/deposit/src/test/java/br/ufrn/imd/withdrawal/CourseApplicationTests.java b/WebServices/deposit/src/test/java/br/ufrn/imd/withdrawal/CourseApplicationTests.java new file mode 100644 index 0000000000000000000000000000000000000000..b84743fe08d4bfdafd2ba2588a9a532fa80fa854 --- /dev/null +++ b/WebServices/deposit/src/test/java/br/ufrn/imd/withdrawal/CourseApplicationTests.java @@ -0,0 +1,16 @@ +package br.ufrn.imd.withdrawal; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class CourseApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/WebServices/deposit/target/classes/application.yml b/WebServices/deposit/target/classes/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..76df8328cb3d8b4f2ba06b63501f8b40c034bd84 --- /dev/null +++ b/WebServices/deposit/target/classes/application.yml @@ -0,0 +1,25 @@ +server: + port: 8085 +eureka: + instance: + prefer-ip-address: true + client: + service-url: + defaultZone: http://registry:8081/eureka/ + fetch-registry: true + register-with-eureka: true + +spring: + application: + name: deposit + datasource: + url: jdbc:postgresql://postgresServ:5432/postgres + username: postgres + password: postgres + jpa: + show-sql: false + database-platform: org.hibernate.dialect.PostgreSQL9Dialect + hibernate: + ddl-auto: update + jmx: + enabled: false \ No newline at end of file diff --git a/WebServices/deposit/target/maven-archiver/pom.properties b/WebServices/deposit/target/maven-archiver/pom.properties new file mode 100644 index 0000000000000000000000000000000000000000..0bc277fa9d32e3056d794aaf0f4eab5b8d609390 --- /dev/null +++ b/WebServices/deposit/target/maven-archiver/pom.properties @@ -0,0 +1,4 @@ +#Created by Apache Maven 3.8.4 +groupId=br.ufrn.imd +artifactId=deposit +version=0.0.1-SNAPSHOT diff --git a/WebServices/deposit/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/WebServices/deposit/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..3874cffd6ccf32aa0b920ab83481dc9e2f34a9c8 --- /dev/null +++ b/WebServices/deposit/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,6 @@ +br\ufrn\imd\deposit\DepositApplication.class +br\ufrn\imd\deposit\domain\Client.class +br\ufrn\imd\deposit\repository\ClientRepository.class +br\ufrn\imd\deposit\service\DepositService.class +br\ufrn\imd\deposit\controller\DepositController.class +br\ufrn\imd\deposit\domain\Account.class diff --git a/WebServices/deposit/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/WebServices/deposit/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..ac0e43ae425d8307be71f3864cf0c615b72c20fb --- /dev/null +++ b/WebServices/deposit/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,6 @@ +C:\Users\maria\Documents\Projetos\dim0614\WebServices\deposit\src\main\java\br\ufrn\imd\deposit\domain\Client.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\deposit\src\main\java\br\ufrn\imd\deposit\controller\DepositController.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\deposit\src\main\java\br\ufrn\imd\deposit\domain\Account.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\deposit\src\main\java\br\ufrn\imd\deposit\repository\ClientRepository.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\deposit\src\main\java\br\ufrn\imd\deposit\DepositApplication.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\deposit\src\main\java\br\ufrn\imd\deposit\service\DepositService.java diff --git a/WebServices/deposit/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/WebServices/deposit/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..3a5345ad0769a7ebacaabdd4abc78f4ee36396a5 --- /dev/null +++ b/WebServices/deposit/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +br\ufrn\imd\withdrawal\CourseApplicationTests.class diff --git a/WebServices/deposit/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/WebServices/deposit/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..9ed5032d7443921f5703a4746380a7805d383002 --- /dev/null +++ b/WebServices/deposit/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +C:\Users\maria\Documents\Projetos\dim0614\WebServices\deposit\src\test\java\br\ufrn\imd\withdrawal\CourseApplicationTests.java diff --git a/WebServices/discovery/.gitignore b/WebServices/discovery/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ba5cb5cca8766c8b2403d25de25b1c880c5ef64a --- /dev/null +++ b/WebServices/discovery/.gitignore @@ -0,0 +1,26 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ diff --git a/WebServices/discovery/.mvn/wrapper/MavenWrapperDownloader.java b/WebServices/discovery/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000000000000000000000000000000000000..042d184cb5c15da221db5fb5330e2d6b2596eaa3 --- /dev/null +++ b/WebServices/discovery/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,114 @@ +/* +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 + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.Properties; + +public class MavenWrapperDownloader { + + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/WebServices/discovery/.mvn/wrapper/maven-wrapper.jar b/WebServices/discovery/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..01e67997377a393fd672c7dcde9dccbedf0cb1e9 Binary files /dev/null and b/WebServices/discovery/.mvn/wrapper/maven-wrapper.jar differ diff --git a/WebServices/discovery/.mvn/wrapper/maven-wrapper.properties b/WebServices/discovery/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000000000000000000000000000000000..cd0d451ccd6fc835996c9fe4eebf8a571154f515 --- /dev/null +++ b/WebServices/discovery/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip diff --git a/WebServices/discovery/Dockerfile b/WebServices/discovery/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..1615d429ca447933503a5565552b139d7e8e17d1 --- /dev/null +++ b/WebServices/discovery/Dockerfile @@ -0,0 +1,3 @@ +FROM openjdk:11 +COPY target/discovery.jar discovery.jar +ENTRYPOINT ["java","-jar","discovery.jar"] \ No newline at end of file diff --git a/WebServices/discovery/mvnw b/WebServices/discovery/mvnw new file mode 100755 index 0000000000000000000000000000000000000000..5551fde8e7dba1e37a1821e8b26374893e2a9e2e --- /dev/null +++ b/WebServices/discovery/mvnw @@ -0,0 +1,286 @@ +#!/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 +# +# http://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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + 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" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + wget "$jarUrl" -O "$wrapperJarPath" + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + curl -o "$wrapperJarPath" "$jarUrl" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/WebServices/discovery/mvnw.cmd b/WebServices/discovery/mvnw.cmd new file mode 100644 index 0000000000000000000000000000000000000000..e5cfb0ae9eab80c314b7d79c164d4a00772824b8 --- /dev/null +++ b/WebServices/discovery/mvnw.cmd @@ -0,0 +1,161 @@ +@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 http://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 Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" +FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + echo Found %WRAPPER_JAR% +) else ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" + echo Finished downloading %WRAPPER_JAR% +) +@REM End of extension + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/WebServices/discovery/pom.xml b/WebServices/discovery/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..ef11b960269ee69bf7ca31a01f56cd17f33f5d70 --- /dev/null +++ b/WebServices/discovery/pom.xml @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>br.ufrn.imd</groupId> + <artifactId>dim0614</artifactId> + <version>1.0-SNAPSHOT</version> + <relativePath>../</relativePath> <!-- lookup parent from repository --> + </parent> + + <artifactId>discovery</artifactId> + <version>0.0.1-SNAPSHOT</version> + <name>discovery</name> + <description>DevDojo's Service Discovery</description> + + <properties> + <java.version>11</java.version> + <jaxb-api.version>2.3.1</jaxb-api.version> + <jaxb-runtime.version>2.3.2</jaxb-runtime.version> + <javax-activation.version>1.2.0</javax-activation.version> + </properties> + + <dependencies> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> + </dependency> + <dependency> + <groupId>javax.xml.bind</groupId> + <artifactId>jaxb-api</artifactId> + <version>${jaxb-api.version}</version> + </dependency> + <dependency> + <groupId>javax.activation</groupId> + <artifactId>javax.activation-api</artifactId> + <version>${javax-activation.version}</version> + </dependency> + + <dependency> + <groupId>org.glassfish.jaxb</groupId> + <artifactId>jaxb-runtime</artifactId> + <version>${jaxb-runtime.version}</version> + </dependency> + + </dependencies> + + <build> + <finalName>discovery</finalName> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <executable>true</executable> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.0</version> + <configuration> + <source>11</source> + <target>11</target> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/WebServices/discovery/src/main/java/br/ufrn/imd/DiscoveryApplication.java b/WebServices/discovery/src/main/java/br/ufrn/imd/DiscoveryApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..fed87637edb1ec498a1e78cbdde45d68518adc6d --- /dev/null +++ b/WebServices/discovery/src/main/java/br/ufrn/imd/DiscoveryApplication.java @@ -0,0 +1,15 @@ +package br.ufrn.imd; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; + +@SpringBootApplication +@EnableEurekaServer +public class DiscoveryApplication { + + public static void main(String[] args) { + SpringApplication.run(DiscoveryApplication.class, args); + } + +} diff --git a/WebServices/discovery/src/main/resources/application.yml b/WebServices/discovery/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..51b3a1a44f1739dc143395a2a612073bebbc3ae0 --- /dev/null +++ b/WebServices/discovery/src/main/resources/application.yml @@ -0,0 +1,12 @@ +spring: + application: + name: registry +server: + port: 8081 + +eureka: + client: + register-with-eureka: false + fetch-registry: false + service-url: + defaultZone: http://registry:${server.port}/eureka/ diff --git a/WebServices/discovery/src/test/java/academy/devdojo/youtube/discovery/DiscoveryApplicationTests.java b/WebServices/discovery/src/test/java/academy/devdojo/youtube/discovery/DiscoveryApplicationTests.java new file mode 100644 index 0000000000000000000000000000000000000000..b6b9fe298bc276c6576ddfef537e4eac550caffd --- /dev/null +++ b/WebServices/discovery/src/test/java/academy/devdojo/youtube/discovery/DiscoveryApplicationTests.java @@ -0,0 +1,16 @@ +package academy.devdojo.youtube.discovery; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class DiscoveryApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/WebServices/docker-compose.yml b/WebServices/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..d10186cd3123f4ef8b90da263f88c44eac8867c4 --- /dev/null +++ b/WebServices/docker-compose.yml @@ -0,0 +1,114 @@ +version: "3.9" + +volumes: + postgres-server-volume: +services: + + postgresServ: + image: postgres:12.9 + container_name: postgresServ + ports: + - 5433:5432 + volumes: + - postgres-server-volume:/var/lib/postgresql/data + networks: + - sigsmartcampus2-network + environment: + POSTGRES_DB: postgres + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + + registry: + container_name: registry-server + build: + context: ./discovery + dockerfile: ./Dockerfile + ports: + - 8081:8081 + networks: + - sigsmartcampus2-network + + gateway: + container_name: gateway-server + build: + context: ./gateway + dockerfile: ./Dockerfile + ports: + - 8080:8080 + depends_on: + - registry + networks: + - sigsmartcampus2-network + + withdrawal: + container_name: withdrawal-server + build: + context: withdrawal + dockerfile: ./Dockerfile + ports: + - 8083:8083 + networks: + - sigsmartcampus2-network + depends_on: + - postgresServ + - gateway + + balance: + container_name: balance-server + build: + context: balance + dockerfile: ./Dockerfile + ports: + - 8084:8084 + networks: + - sigsmartcampus2-network + depends_on: + - postgresServ + - gateway + + deposit: + container_name: deposit-server + build: + context: deposit + dockerfile: ./Dockerfile + ports: + - 8085:8085 + networks: + - sigsmartcampus2-network + depends_on: + - postgresServ + - gateway + + + transfer: + container_name: tranfer-server + build: + context: transfer + dockerfile: ./Dockerfile + ports: + - 8086:8086 + networks: + - sigsmartcampus2-network + depends_on: + - postgresServ + - gateway + + + authenticator: + container_name: authenticator-server + build: + context: authenticator + dockerfile: ./Dockerfile + ports: + - 8087:8087 + networks: + - sigsmartcampus2-network + depends_on: + - postgresServ + - gateway + + + +networks: + sigsmartcampus2-network: + driver: bridge diff --git a/WebServices/gateway/.gitignore b/WebServices/gateway/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ba5cb5cca8766c8b2403d25de25b1c880c5ef64a --- /dev/null +++ b/WebServices/gateway/.gitignore @@ -0,0 +1,26 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ diff --git a/WebServices/gateway/.mvn/wrapper/MavenWrapperDownloader.java b/WebServices/gateway/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000000000000000000000000000000000000..042d184cb5c15da221db5fb5330e2d6b2596eaa3 --- /dev/null +++ b/WebServices/gateway/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,114 @@ +/* +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 + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.Properties; + +public class MavenWrapperDownloader { + + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/WebServices/gateway/.mvn/wrapper/maven-wrapper.jar b/WebServices/gateway/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..01e67997377a393fd672c7dcde9dccbedf0cb1e9 Binary files /dev/null and b/WebServices/gateway/.mvn/wrapper/maven-wrapper.jar differ diff --git a/WebServices/gateway/.mvn/wrapper/maven-wrapper.properties b/WebServices/gateway/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000000000000000000000000000000000..cd0d451ccd6fc835996c9fe4eebf8a571154f515 --- /dev/null +++ b/WebServices/gateway/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip diff --git a/WebServices/gateway/Dockerfile b/WebServices/gateway/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..3cf13a1c53d91e6312940d52fc4be4e83db39a97 --- /dev/null +++ b/WebServices/gateway/Dockerfile @@ -0,0 +1,3 @@ +FROM openjdk:11 +COPY target/gateway.jar gateway.jar +ENTRYPOINT ["java","-jar","gateway.jar"] \ No newline at end of file diff --git a/WebServices/gateway/mvnw b/WebServices/gateway/mvnw new file mode 100755 index 0000000000000000000000000000000000000000..5551fde8e7dba1e37a1821e8b26374893e2a9e2e --- /dev/null +++ b/WebServices/gateway/mvnw @@ -0,0 +1,286 @@ +#!/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 +# +# http://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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + 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" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + wget "$jarUrl" -O "$wrapperJarPath" + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + curl -o "$wrapperJarPath" "$jarUrl" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/WebServices/gateway/mvnw.cmd b/WebServices/gateway/mvnw.cmd new file mode 100644 index 0000000000000000000000000000000000000000..e5cfb0ae9eab80c314b7d79c164d4a00772824b8 --- /dev/null +++ b/WebServices/gateway/mvnw.cmd @@ -0,0 +1,161 @@ +@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 http://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 Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" +FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + echo Found %WRAPPER_JAR% +) else ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" + echo Finished downloading %WRAPPER_JAR% +) +@REM End of extension + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/WebServices/gateway/pom.xml b/WebServices/gateway/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..fcee5284ea03ad1dc8314a0a21125b28db7e3e6f --- /dev/null +++ b/WebServices/gateway/pom.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>br.ufrn.imd</groupId> + <artifactId>dim0614</artifactId> + <version>1.0-SNAPSHOT</version> + <relativePath>../</relativePath> <!-- lookup parent from repository --> + </parent> + + <artifactId>gateway</artifactId> + <version>0.0.1-SNAPSHOT</version> + <name>gateway</name> + <description>DevDojo's Gateway</description> + + <properties> + <java.version>11</java.version> + </properties> + <dependencies> + + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-netflix-zuul</artifactId> + </dependency> + + </dependencies> + <build> + <finalName>gateway</finalName> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <executable>true</executable> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.0</version> + <configuration> + <source>11</source> + <target>11</target> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/WebServices/gateway/src/main/java/br/ufrn/imd/gateway/GatewayApplication.java b/WebServices/gateway/src/main/java/br/ufrn/imd/gateway/GatewayApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..b97ea31a8d4cc0abce3e0b76a76b5fc4bd3059b6 --- /dev/null +++ b/WebServices/gateway/src/main/java/br/ufrn/imd/gateway/GatewayApplication.java @@ -0,0 +1,17 @@ +package br.ufrn.imd.gateway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.EnableEurekaClient; +import org.springframework.cloud.netflix.zuul.EnableZuulProxy; + +@SpringBootApplication +@EnableZuulProxy +@EnableEurekaClient +public class GatewayApplication { + + public static void main(String[] args) { + SpringApplication.run(GatewayApplication.class, args); + } + +} diff --git a/WebServices/gateway/src/main/resources/application.yml b/WebServices/gateway/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..c79f8ea6c29d79dce4e6a7323b996bf8e743292f --- /dev/null +++ b/WebServices/gateway/src/main/resources/application.yml @@ -0,0 +1,19 @@ +spring: + application: + name: gateway +server: + port: 8080 + servlet: + context-path: /gateway + +eureka: + instance: + prefer-ip-address: true + client: + service-url: + defaultZone: http://registry:8081/eureka/ + fetch-registry: true + register-with-eureka: true + +zuul: + sensitive-headers: Cookie diff --git a/WebServices/gateway/src/test/java/academy/devdojo/youtube/gateway/GatewayApplicationTests.java b/WebServices/gateway/src/test/java/academy/devdojo/youtube/gateway/GatewayApplicationTests.java new file mode 100644 index 0000000000000000000000000000000000000000..5b93859879a3387ff3f6b343f4ade6571d5c394f --- /dev/null +++ b/WebServices/gateway/src/test/java/academy/devdojo/youtube/gateway/GatewayApplicationTests.java @@ -0,0 +1,16 @@ +package academy.devdojo.youtube.gateway; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class GatewayApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/WebServices/pom.xml b/WebServices/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..c2fd4dd22da95538e1c68ac2cdf1398462d6f8fc --- /dev/null +++ b/WebServices/pom.xml @@ -0,0 +1,102 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-parent</artifactId> + <version>2.1.3.RELEASE</version> + <relativePath/> <!-- lookup parent from repository --> + </parent> + + <groupId>br.ufrn.imd</groupId> + <artifactId>dim0614</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>pom</packaging> + + <modules> + <module>withdrawal</module> + <module>gateway</module> + <module>discovery</module> + <module>balance</module> + <module>transfer</module> + <module>deposit</module> + <module>client</module> + <module>authenticator</module> + </modules> + <properties> + <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-validation</artifactId> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-devtools</artifactId> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.postgresql</groupId> + <artifactId>postgresql</artifactId> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-configuration-processor</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-dependencies</artifactId> + <version>${spring-cloud.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <repositories> + <repository> + <id>spring-milestones</id> + <name>Spring Milestones</name> + <url>https://repo.spring.io/milestone</url> + </repository> + </repositories> + +</project> diff --git a/WebServices/transfer/.DS_Store b/WebServices/transfer/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 Binary files /dev/null and b/WebServices/transfer/.DS_Store differ diff --git a/WebServices/transfer/.gitignore b/WebServices/transfer/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ba5cb5cca8766c8b2403d25de25b1c880c5ef64a --- /dev/null +++ b/WebServices/transfer/.gitignore @@ -0,0 +1,26 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ diff --git a/WebServices/transfer/.mvn/wrapper/MavenWrapperDownloader.java b/WebServices/transfer/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000000000000000000000000000000000000..47336fde724164b1329ed3595f5b6bff09f7c179 --- /dev/null +++ b/WebServices/transfer/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,114 @@ +/* +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 + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.Properties; + +public class MavenWrapperDownloader { + + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/WebServices/transfer/.mvn/wrapper/maven-wrapper.jar b/WebServices/transfer/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..01e67997377a393fd672c7dcde9dccbedf0cb1e9 Binary files /dev/null and b/WebServices/transfer/.mvn/wrapper/maven-wrapper.jar differ diff --git a/WebServices/transfer/.mvn/wrapper/maven-wrapper.properties b/WebServices/transfer/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000000000000000000000000000000000..cd0d451ccd6fc835996c9fe4eebf8a571154f515 --- /dev/null +++ b/WebServices/transfer/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip diff --git a/WebServices/transfer/Dockerfile b/WebServices/transfer/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..5b37841d0429140f21bdf43c8677ce2e8241c148 --- /dev/null +++ b/WebServices/transfer/Dockerfile @@ -0,0 +1,3 @@ +FROM openjdk:11 +COPY target/transfer.jar transfer.jar +ENTRYPOINT ["java","-jar","transfer.jar"] \ No newline at end of file diff --git a/WebServices/transfer/mvnw b/WebServices/transfer/mvnw new file mode 100755 index 0000000000000000000000000000000000000000..5551fde8e7dba1e37a1821e8b26374893e2a9e2e --- /dev/null +++ b/WebServices/transfer/mvnw @@ -0,0 +1,286 @@ +#!/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 +# +# http://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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + 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" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + wget "$jarUrl" -O "$wrapperJarPath" + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + curl -o "$wrapperJarPath" "$jarUrl" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/WebServices/transfer/mvnw.cmd b/WebServices/transfer/mvnw.cmd new file mode 100644 index 0000000000000000000000000000000000000000..e5cfb0ae9eab80c314b7d79c164d4a00772824b8 --- /dev/null +++ b/WebServices/transfer/mvnw.cmd @@ -0,0 +1,161 @@ +@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 http://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 Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" +FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + echo Found %WRAPPER_JAR% +) else ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" + echo Finished downloading %WRAPPER_JAR% +) +@REM End of extension + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/WebServices/transfer/pom.xml b/WebServices/transfer/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..29acda33783229d2fe24d2e0fb625b4cd60d6a94 --- /dev/null +++ b/WebServices/transfer/pom.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>br.ufrn.imd</groupId> + <artifactId>dim0614</artifactId> + <version>1.0-SNAPSHOT</version> + <relativePath>../</relativePath> <!-- lookup parent from repository --> + </parent> + + <artifactId>transfer</artifactId> + <version>0.0.1-SNAPSHOT</version> + <name>transfer</name> + <description>Spring Boot Micro-services By DevDojo</description> + + <properties> + <java.version>11</java.version> + </properties> + + <build> + <finalName>transfer</finalName> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <executable>true</executable> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.0</version> + <configuration> + <source>11</source> + <target>11</target> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/TransferApplication.java b/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/TransferApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..912127f66c81a0859e79d336706d4127e8c63615 --- /dev/null +++ b/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/TransferApplication.java @@ -0,0 +1,13 @@ +package br.ufrn.imd.transfer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class TransferApplication { + + public static void main(String[] args) { + SpringApplication.run(TransferApplication.class, args); + } + +} diff --git a/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/controller/TransferController.java b/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/controller/TransferController.java new file mode 100644 index 0000000000000000000000000000000000000000..2e4af71c668f0481510a5bd03af6a4c2a2b20b72 --- /dev/null +++ b/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/controller/TransferController.java @@ -0,0 +1,20 @@ +package br.ufrn.imd.transfer.controller; + +import br.ufrn.imd.transfer.domain.Account; +import br.ufrn.imd.transfer.domain.Client; +import br.ufrn.imd.transfer.service.TransferService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/banking/client/{id}") +public class TransferController { + private final TransferService service; + + @GetMapping + public Client transfer(@PathVariable Integer id, @RequestParam(name = "value") Double value, + @RequestParam(name = "toAccount") String toAccountNumber) { + return service.transfer(value, new Client(id), new Account(null, toAccountNumber, null, null)); + } +} diff --git a/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/domain/Account.java b/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/domain/Account.java new file mode 100644 index 0000000000000000000000000000000000000000..56196c5dfe07f6dd27fb08f2fa4b70e76c175073 --- /dev/null +++ b/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/domain/Account.java @@ -0,0 +1,26 @@ +package br.ufrn.imd.transfer.domain; + +import lombok.*; + +import javax.persistence.*; +import java.io.Serializable; + +@AllArgsConstructor +@NoArgsConstructor +@Data +@Entity +public class Account implements Serializable { + + private static final long serialVersionUID = 2L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column(unique = true) + private String number; + + private Double balance; + + private String password; +} diff --git a/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/domain/Client.java b/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/domain/Client.java new file mode 100644 index 0000000000000000000000000000000000000000..21af242865da3952f3ca8da5b283fc8fd9164315 --- /dev/null +++ b/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/domain/Client.java @@ -0,0 +1,29 @@ +package br.ufrn.imd.transfer.domain; + +import lombok.*; + +import javax.persistence.*; +import java.io.Serializable; + +@AllArgsConstructor +@NoArgsConstructor +@Data +@Entity +public class Client implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String name; + + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "account_id") + private Account account; + + public Client(Integer id) { + this.id = id; + } +} diff --git a/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/repository/ClientRepository.java b/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/repository/ClientRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..917cc223f1a496a0683df9c4e17f8387832a0936 --- /dev/null +++ b/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/repository/ClientRepository.java @@ -0,0 +1,16 @@ +package br.ufrn.imd.transfer.repository; + +import br.ufrn.imd.transfer.domain.Client; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface ClientRepository extends JpaRepository<Client, Integer> { + + @Query(value = "SELECT c from Client c where c.account.number = ?1") + Optional<Client> findByAccountNumber(String number); + +} diff --git a/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/service/TransferService.java b/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/service/TransferService.java new file mode 100644 index 0000000000000000000000000000000000000000..a0cc3713b60a4ff6a058f20796ab6db0190572df --- /dev/null +++ b/WebServices/transfer/src/main/java/br/ufrn/imd/transfer/service/TransferService.java @@ -0,0 +1,43 @@ +package br.ufrn.imd.transfer.service; + +import br.ufrn.imd.transfer.domain.Account; +import br.ufrn.imd.transfer.domain.Client; +import br.ufrn.imd.transfer.repository.ClientRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.java.Log; +import org.springframework.stereotype.Service; + +@Log +@RequiredArgsConstructor +@Service +public class TransferService { + private final ClientRepository clientRepository; + + public Client transfer(Double value, Client fromClient, Account toAccount) { + fromClient = clientRepository.findById(fromClient.getId()) + .orElseThrow(() -> new RuntimeException("Invalid user!")); + + Account finalToAccount = toAccount; + Client toClient = clientRepository.findByAccountNumber(toAccount.getNumber()) + .orElseThrow(() -> new RuntimeException( + String.format("Customer not found with account number %s", finalToAccount.getNumber()))); + + if(fromClient.getId().equals(toClient.getId())) + throw new RuntimeException("Invalid account"); + + Account fromAccount = fromClient.getAccount(); + if(value > fromAccount.getBalance()) throw new RuntimeException("Insufficient balance"); + + fromAccount.setBalance(fromAccount.getBalance() - value); + toAccount = toClient.getAccount(); + toAccount.setBalance(toAccount.getBalance() + value); + + clientRepository.save(toClient); + fromClient = clientRepository.save(fromClient); + log.info("Transfer concluded!"); + log.info(String.format("Account balance: R$ %.2f", fromClient.getAccount().getBalance())); + + return fromClient; + } + +} diff --git a/WebServices/transfer/src/main/resources/application.yml b/WebServices/transfer/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..30d93a08178d69ec7c4fd91ff512635465a266b1 --- /dev/null +++ b/WebServices/transfer/src/main/resources/application.yml @@ -0,0 +1,25 @@ +server: + port: 8086 +eureka: + instance: + prefer-ip-address: true + client: + service-url: + defaultZone: http://registry:8081/eureka/ + fetch-registry: true + register-with-eureka: true + +spring: + application: + name: transfer + datasource: + url: jdbc:postgresql://postgresServ:5432/postgres + username: postgres + password: postgres + jpa: + show-sql: false + database-platform: org.hibernate.dialect.PostgreSQL9Dialect + hibernate: + ddl-auto: update + jmx: + enabled: false \ No newline at end of file diff --git a/WebServices/transfer/src/test/java/br/ufrn/imd/withdrawal/CourseApplicationTests.java b/WebServices/transfer/src/test/java/br/ufrn/imd/withdrawal/CourseApplicationTests.java new file mode 100644 index 0000000000000000000000000000000000000000..b84743fe08d4bfdafd2ba2588a9a532fa80fa854 --- /dev/null +++ b/WebServices/transfer/src/test/java/br/ufrn/imd/withdrawal/CourseApplicationTests.java @@ -0,0 +1,16 @@ +package br.ufrn.imd.withdrawal; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class CourseApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/WebServices/transfer/target/classes/application.yml b/WebServices/transfer/target/classes/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..30d93a08178d69ec7c4fd91ff512635465a266b1 --- /dev/null +++ b/WebServices/transfer/target/classes/application.yml @@ -0,0 +1,25 @@ +server: + port: 8086 +eureka: + instance: + prefer-ip-address: true + client: + service-url: + defaultZone: http://registry:8081/eureka/ + fetch-registry: true + register-with-eureka: true + +spring: + application: + name: transfer + datasource: + url: jdbc:postgresql://postgresServ:5432/postgres + username: postgres + password: postgres + jpa: + show-sql: false + database-platform: org.hibernate.dialect.PostgreSQL9Dialect + hibernate: + ddl-auto: update + jmx: + enabled: false \ No newline at end of file diff --git a/WebServices/transfer/target/maven-archiver/pom.properties b/WebServices/transfer/target/maven-archiver/pom.properties new file mode 100644 index 0000000000000000000000000000000000000000..40e39ac6c141c3a9570e5c28983b998ab8e843ae --- /dev/null +++ b/WebServices/transfer/target/maven-archiver/pom.properties @@ -0,0 +1,4 @@ +#Created by Apache Maven 3.8.4 +groupId=br.ufrn.imd +artifactId=transfer +version=0.0.1-SNAPSHOT diff --git a/WebServices/transfer/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/WebServices/transfer/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..73a0ccf74d20d1c880891409cf59bd82a3c8f36c --- /dev/null +++ b/WebServices/transfer/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,6 @@ +br\ufrn\imd\transfer\domain\Account.class +br\ufrn\imd\transfer\TransferApplication.class +br\ufrn\imd\transfer\service\TransferService.class +br\ufrn\imd\transfer\controller\TransferController.class +br\ufrn\imd\transfer\domain\Client.class +br\ufrn\imd\transfer\repository\ClientRepository.class diff --git a/WebServices/transfer/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/WebServices/transfer/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..2a4e6d7faa424f6a7400b1afa21fb30adef02a4a --- /dev/null +++ b/WebServices/transfer/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,6 @@ +C:\Users\maria\Documents\Projetos\dim0614\WebServices\transfer\src\main\java\br\ufrn\imd\transfer\repository\ClientRepository.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\transfer\src\main\java\br\ufrn\imd\transfer\controller\TransferController.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\transfer\src\main\java\br\ufrn\imd\transfer\domain\Client.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\transfer\src\main\java\br\ufrn\imd\transfer\service\TransferService.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\transfer\src\main\java\br\ufrn\imd\transfer\domain\Account.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\transfer\src\main\java\br\ufrn\imd\transfer\TransferApplication.java diff --git a/WebServices/transfer/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/WebServices/transfer/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..3a5345ad0769a7ebacaabdd4abc78f4ee36396a5 --- /dev/null +++ b/WebServices/transfer/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +br\ufrn\imd\withdrawal\CourseApplicationTests.class diff --git a/WebServices/transfer/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/WebServices/transfer/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..53b7d27bca88aa20406b0ef108af0a6eabf9c8d0 --- /dev/null +++ b/WebServices/transfer/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +C:\Users\maria\Documents\Projetos\dim0614\WebServices\transfer\src\test\java\br\ufrn\imd\withdrawal\CourseApplicationTests.java diff --git a/WebServices/withdrawal/.DS_Store b/WebServices/withdrawal/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 Binary files /dev/null and b/WebServices/withdrawal/.DS_Store differ diff --git a/WebServices/withdrawal/.gitignore b/WebServices/withdrawal/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ba5cb5cca8766c8b2403d25de25b1c880c5ef64a --- /dev/null +++ b/WebServices/withdrawal/.gitignore @@ -0,0 +1,26 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ diff --git a/WebServices/withdrawal/.mvn/wrapper/MavenWrapperDownloader.java b/WebServices/withdrawal/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000000000000000000000000000000000000..47336fde724164b1329ed3595f5b6bff09f7c179 --- /dev/null +++ b/WebServices/withdrawal/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,114 @@ +/* +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 + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.Properties; + +public class MavenWrapperDownloader { + + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/WebServices/withdrawal/.mvn/wrapper/maven-wrapper.jar b/WebServices/withdrawal/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..01e67997377a393fd672c7dcde9dccbedf0cb1e9 Binary files /dev/null and b/WebServices/withdrawal/.mvn/wrapper/maven-wrapper.jar differ diff --git a/WebServices/withdrawal/.mvn/wrapper/maven-wrapper.properties b/WebServices/withdrawal/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000000000000000000000000000000000..cd0d451ccd6fc835996c9fe4eebf8a571154f515 --- /dev/null +++ b/WebServices/withdrawal/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip diff --git a/WebServices/withdrawal/Dockerfile b/WebServices/withdrawal/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..9885e7466359c0bd6426716ab718c12064632b70 --- /dev/null +++ b/WebServices/withdrawal/Dockerfile @@ -0,0 +1,3 @@ +FROM openjdk:11 +COPY target/withdrawal.jar withdrawal.jar +ENTRYPOINT ["java","-jar","withdrawal.jar"] \ No newline at end of file diff --git a/WebServices/withdrawal/mvnw b/WebServices/withdrawal/mvnw new file mode 100755 index 0000000000000000000000000000000000000000..5551fde8e7dba1e37a1821e8b26374893e2a9e2e --- /dev/null +++ b/WebServices/withdrawal/mvnw @@ -0,0 +1,286 @@ +#!/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 +# +# http://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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + 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" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + wget "$jarUrl" -O "$wrapperJarPath" + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + curl -o "$wrapperJarPath" "$jarUrl" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/WebServices/withdrawal/mvnw.cmd b/WebServices/withdrawal/mvnw.cmd new file mode 100644 index 0000000000000000000000000000000000000000..e5cfb0ae9eab80c314b7d79c164d4a00772824b8 --- /dev/null +++ b/WebServices/withdrawal/mvnw.cmd @@ -0,0 +1,161 @@ +@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 http://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 Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" +FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + echo Found %WRAPPER_JAR% +) else ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" + echo Finished downloading %WRAPPER_JAR% +) +@REM End of extension + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/WebServices/withdrawal/pom.xml b/WebServices/withdrawal/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..55a797289c948be048f8de552cd718a9673b4d66 --- /dev/null +++ b/WebServices/withdrawal/pom.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>br.ufrn.imd</groupId> + <artifactId>dim0614</artifactId> + <version>1.0-SNAPSHOT</version> + <relativePath>../</relativePath> <!-- lookup parent from repository --> + </parent> + + <artifactId>withdrawal</artifactId> + <version>0.0.1-SNAPSHOT</version> + <name>withdrawal</name> + <description>Spring Boot Micro-services By DevDojo</description> + + <properties> + <java.version>11</java.version> + </properties> + + <build> + <finalName>withdrawal</finalName> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <executable>true</executable> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.0</version> + <configuration> + <source>11</source> + <target>11</target> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/WithdrawalApplication.java b/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/WithdrawalApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..0c09c3de4bd4fa07cd42e583d3b259492bcc46cd --- /dev/null +++ b/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/WithdrawalApplication.java @@ -0,0 +1,14 @@ +package br.ufrn.imd.withdrawal; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication + +public class WithdrawalApplication { + + public static void main(String[] args) { + SpringApplication.run(WithdrawalApplication.class, args); + } + +} diff --git a/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/controller/WithdrawalController.java b/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/controller/WithdrawalController.java new file mode 100644 index 0000000000000000000000000000000000000000..4c62168d127f7f8cbc33de7b96e33c147662814b --- /dev/null +++ b/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/controller/WithdrawalController.java @@ -0,0 +1,18 @@ +package br.ufrn.imd.withdrawal.controller; + +import br.ufrn.imd.withdrawal.domain.Client; +import br.ufrn.imd.withdrawal.service.WithdrawalService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/banking/client/{id}") +public class WithdrawalController { + private final WithdrawalService service; + + @GetMapping + public Client withdrawal(@PathVariable Integer id, @RequestParam(name = "value") Double value) { + return service.withdraw(value, new Client(id)); + } +} diff --git a/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/domain/Account.java b/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/domain/Account.java new file mode 100644 index 0000000000000000000000000000000000000000..5dc148a4f8604bfcdf64ca00a3e77868dabf7970 --- /dev/null +++ b/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/domain/Account.java @@ -0,0 +1,26 @@ +package br.ufrn.imd.withdrawal.domain; + +import lombok.*; + +import javax.persistence.*; +import java.io.Serializable; + +@AllArgsConstructor +@NoArgsConstructor +@Data +@Entity +public class Account implements Serializable { + + private static final long serialVersionUID = 2L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column(unique = true) + private String number; + + private Double balance; + + private String password; +} diff --git a/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/domain/Client.java b/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/domain/Client.java new file mode 100644 index 0000000000000000000000000000000000000000..15df30b4413fab7e4dc7b3588d79bf4cbfb8563b --- /dev/null +++ b/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/domain/Client.java @@ -0,0 +1,29 @@ +package br.ufrn.imd.withdrawal.domain; + +import lombok.*; + +import javax.persistence.*; +import java.io.Serializable; + +@AllArgsConstructor +@NoArgsConstructor +@Data +@Entity +public class Client implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String name; + + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "account_id") + private Account account; + + public Client(Integer id) { + this.id = id; + } +} diff --git a/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/repository/ClientRepository.java b/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/repository/ClientRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..f2ab6a92c937cacd72c6db0169082da9970beb2e --- /dev/null +++ b/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/repository/ClientRepository.java @@ -0,0 +1,16 @@ +package br.ufrn.imd.withdrawal.repository; + +import br.ufrn.imd.withdrawal.domain.Client; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface ClientRepository extends JpaRepository<Client, Integer> { + + @Query(value = "SELECT c from Client c where c.account.number = ?1") + Optional<Client> findByAccountNumber(String number); + +} diff --git a/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/service/WithdrawalService.java b/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/service/WithdrawalService.java new file mode 100644 index 0000000000000000000000000000000000000000..b11e71f87953de0acfdf71f29ac3896d4e47f753 --- /dev/null +++ b/WebServices/withdrawal/src/main/java/br/ufrn/imd/withdrawal/service/WithdrawalService.java @@ -0,0 +1,29 @@ +package br.ufrn.imd.withdrawal.service; + +import br.ufrn.imd.withdrawal.domain.Account; +import br.ufrn.imd.withdrawal.domain.Client; +import br.ufrn.imd.withdrawal.repository.ClientRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.java.Log; +import org.springframework.stereotype.Service; + +@Log +@RequiredArgsConstructor +@Service +public class WithdrawalService { + private final ClientRepository clientRepository; + + public Client withdraw(Double value, Client client) { + client = clientRepository.findById(client.getId()) + .orElseThrow(() -> new RuntimeException("Invalid user!")); + + Account account = client.getAccount(); + if(value > account.getBalance()) throw new RuntimeException("Insufficient balance"); + + account.setBalance(account.getBalance() - value); + client = clientRepository.save(client); + log.info("Withdrawal concluded!"); + log.info(String.format("Account balance: R$ %.2f", client.getAccount().getBalance())); + return client; + } +} diff --git a/WebServices/withdrawal/src/main/resources/application.yml b/WebServices/withdrawal/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..f873ad3e8d5609ffeab3784d2988b55fb66fe7a0 --- /dev/null +++ b/WebServices/withdrawal/src/main/resources/application.yml @@ -0,0 +1,25 @@ +server: + port: 8083 +eureka: + instance: + prefer-ip-address: true + client: + service-url: + defaultZone: http://registry:8081/eureka/ + fetch-registry: true + register-with-eureka: true + +spring: + application: + name: withdrawal + datasource: + url: jdbc:postgresql://postgresServ:5432/postgres + username: postgres + password: postgres + jpa: + show-sql: false + database-platform: org.hibernate.dialect.PostgreSQL9Dialect + hibernate: + ddl-auto: create + jmx: + enabled: false \ No newline at end of file diff --git a/WebServices/withdrawal/src/test/java/br/ufrn/imd/withdrawal/CourseApplicationTests.java b/WebServices/withdrawal/src/test/java/br/ufrn/imd/withdrawal/CourseApplicationTests.java new file mode 100644 index 0000000000000000000000000000000000000000..b84743fe08d4bfdafd2ba2588a9a532fa80fa854 --- /dev/null +++ b/WebServices/withdrawal/src/test/java/br/ufrn/imd/withdrawal/CourseApplicationTests.java @@ -0,0 +1,16 @@ +package br.ufrn.imd.withdrawal; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class CourseApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/WebServices/withdrawal/target/classes/application.yml b/WebServices/withdrawal/target/classes/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..f873ad3e8d5609ffeab3784d2988b55fb66fe7a0 --- /dev/null +++ b/WebServices/withdrawal/target/classes/application.yml @@ -0,0 +1,25 @@ +server: + port: 8083 +eureka: + instance: + prefer-ip-address: true + client: + service-url: + defaultZone: http://registry:8081/eureka/ + fetch-registry: true + register-with-eureka: true + +spring: + application: + name: withdrawal + datasource: + url: jdbc:postgresql://postgresServ:5432/postgres + username: postgres + password: postgres + jpa: + show-sql: false + database-platform: org.hibernate.dialect.PostgreSQL9Dialect + hibernate: + ddl-auto: create + jmx: + enabled: false \ No newline at end of file diff --git a/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/WithdrawalApplication.class b/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/WithdrawalApplication.class new file mode 100644 index 0000000000000000000000000000000000000000..8a77e83faf07299900ed08c14b530413e659f15e Binary files /dev/null and b/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/WithdrawalApplication.class differ diff --git a/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/controller/WithdrawalController.class b/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/controller/WithdrawalController.class new file mode 100644 index 0000000000000000000000000000000000000000..e082a1c4d1a005d3a3039a0288eaee9494098276 Binary files /dev/null and b/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/controller/WithdrawalController.class differ diff --git a/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/domain/Account.class b/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/domain/Account.class new file mode 100644 index 0000000000000000000000000000000000000000..6c11f0e5d29c3870ff0027e55ee6890adcc560fb Binary files /dev/null and b/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/domain/Account.class differ diff --git a/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/domain/Client.class b/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/domain/Client.class new file mode 100644 index 0000000000000000000000000000000000000000..d0f30c239c03971ba491deee2bbfb58dcf0a8f4a Binary files /dev/null and b/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/domain/Client.class differ diff --git a/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/repository/ClientRepository.class b/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/repository/ClientRepository.class new file mode 100644 index 0000000000000000000000000000000000000000..cac00542eafbda4dc9b6de42f0e978b7fa504608 Binary files /dev/null and b/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/repository/ClientRepository.class differ diff --git a/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/service/WithdrawalService.class b/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/service/WithdrawalService.class new file mode 100644 index 0000000000000000000000000000000000000000..1039671381d13650ad65fc7e69a2e9715ae999ba Binary files /dev/null and b/WebServices/withdrawal/target/classes/br/ufrn/imd/withdrawal/service/WithdrawalService.class differ diff --git a/WebServices/withdrawal/target/maven-archiver/pom.properties b/WebServices/withdrawal/target/maven-archiver/pom.properties new file mode 100644 index 0000000000000000000000000000000000000000..91e3e62c8c101e08d504dc1aa799ce4adce805b1 --- /dev/null +++ b/WebServices/withdrawal/target/maven-archiver/pom.properties @@ -0,0 +1,4 @@ +#Created by Apache Maven 3.8.4 +groupId=br.ufrn.imd +artifactId=withdrawal +version=0.0.1-SNAPSHOT diff --git a/WebServices/withdrawal/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/WebServices/withdrawal/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..28229e8b7730aed9abc5090e0519d0499f82d0f8 --- /dev/null +++ b/WebServices/withdrawal/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,6 @@ +br\ufrn\imd\withdrawal\domain\Account.class +br\ufrn\imd\withdrawal\domain\Client.class +br\ufrn\imd\withdrawal\WithdrawalApplication.class +br\ufrn\imd\withdrawal\service\WithdrawalService.class +br\ufrn\imd\withdrawal\controller\WithdrawalController.class +br\ufrn\imd\withdrawal\repository\ClientRepository.class diff --git a/WebServices/withdrawal/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/WebServices/withdrawal/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..f0c96b287a0d63b4884344c085d5de5c789575e3 --- /dev/null +++ b/WebServices/withdrawal/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,6 @@ +C:\Users\maria\Documents\Projetos\dim0614\WebServices\withdrawal\src\main\java\br\ufrn\imd\withdrawal\domain\Account.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\withdrawal\src\main\java\br\ufrn\imd\withdrawal\domain\Client.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\withdrawal\src\main\java\br\ufrn\imd\withdrawal\WithdrawalApplication.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\withdrawal\src\main\java\br\ufrn\imd\withdrawal\repository\ClientRepository.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\withdrawal\src\main\java\br\ufrn\imd\withdrawal\controller\WithdrawalController.java +C:\Users\maria\Documents\Projetos\dim0614\WebServices\withdrawal\src\main\java\br\ufrn\imd\withdrawal\service\WithdrawalService.java diff --git a/WebServices/withdrawal/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/WebServices/withdrawal/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..3a5345ad0769a7ebacaabdd4abc78f4ee36396a5 --- /dev/null +++ b/WebServices/withdrawal/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +br\ufrn\imd\withdrawal\CourseApplicationTests.class diff --git a/WebServices/withdrawal/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/WebServices/withdrawal/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..bb62f833d933e8ccda5183988e551c989fbbad0a --- /dev/null +++ b/WebServices/withdrawal/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +C:\Users\maria\Documents\Projetos\dim0614\WebServices\withdrawal\src\test\java\br\ufrn\imd\withdrawal\CourseApplicationTests.java diff --git a/banking-server/target/classes/ufrn/imd/BankingServerApp.class b/banking-server/target/classes/ufrn/imd/BankingServerApp.class deleted file mode 100644 index d2be3c2c2aa3de8f81a018455bbf467e4d6bfe88..0000000000000000000000000000000000000000 Binary files a/banking-server/target/classes/ufrn/imd/BankingServerApp.class and /dev/null differ diff --git a/banking-server/target/classes/ufrn/imd/controller/Controller.class b/banking-server/target/classes/ufrn/imd/controller/Controller.class deleted file mode 100644 index d963fb57c51b2717ad5df0b7a9c8b917478a9e46..0000000000000000000000000000000000000000 Binary files a/banking-server/target/classes/ufrn/imd/controller/Controller.class and /dev/null differ diff --git a/banking-server/target/classes/ufrn/imd/controller/impl/BalanceControllerImpl.class b/banking-server/target/classes/ufrn/imd/controller/impl/BalanceControllerImpl.class deleted file mode 100644 index d21c3306c0a4f767e4fda868fd072ae710e59058..0000000000000000000000000000000000000000 Binary files a/banking-server/target/classes/ufrn/imd/controller/impl/BalanceControllerImpl.class and /dev/null differ diff --git a/banking-server/target/classes/ufrn/imd/controller/impl/DepositControllerImpl.class b/banking-server/target/classes/ufrn/imd/controller/impl/DepositControllerImpl.class deleted file mode 100644 index 78b16605a3148faa5588123ef88a11f98ff3a3ce..0000000000000000000000000000000000000000 Binary files a/banking-server/target/classes/ufrn/imd/controller/impl/DepositControllerImpl.class and /dev/null differ diff --git a/banking-server/target/classes/ufrn/imd/domain/Account.class b/banking-server/target/classes/ufrn/imd/domain/Account.class deleted file mode 100644 index 06c1afe87e3de366a0157786e0a200a2309ba51b..0000000000000000000000000000000000000000 Binary files a/banking-server/target/classes/ufrn/imd/domain/Account.class and /dev/null differ diff --git a/banking-server/target/classes/ufrn/imd/domain/Client.class b/banking-server/target/classes/ufrn/imd/domain/Client.class deleted file mode 100644 index e09b310a54921733a8906a5ffc2612b07666c2b6..0000000000000000000000000000000000000000 Binary files a/banking-server/target/classes/ufrn/imd/domain/Client.class and /dev/null differ diff --git a/banking-server/target/classes/ufrn/imd/repository/Repository.class b/banking-server/target/classes/ufrn/imd/repository/Repository.class deleted file mode 100644 index 1a11f1ee8fe4d9f5937cf449985bd127fe02bb02..0000000000000000000000000000000000000000 Binary files a/banking-server/target/classes/ufrn/imd/repository/Repository.class and /dev/null differ diff --git a/banking-server/target/classes/ufrn/imd/repository/impl/ClientRepository.class b/banking-server/target/classes/ufrn/imd/repository/impl/ClientRepository.class deleted file mode 100644 index 658438575ee7bb42b918da5360c0bbef6d7432f5..0000000000000000000000000000000000000000 Binary files a/banking-server/target/classes/ufrn/imd/repository/impl/ClientRepository.class and /dev/null differ diff --git a/banking-server/target/classes/ufrn/imd/service/impl/BalanceServiceImpl.class b/banking-server/target/classes/ufrn/imd/service/impl/BalanceServiceImpl.class deleted file mode 100644 index 57779ee31278c81ffb0caab53459b83b0f814be4..0000000000000000000000000000000000000000 Binary files a/banking-server/target/classes/ufrn/imd/service/impl/BalanceServiceImpl.class and /dev/null differ diff --git a/banking-server/target/classes/ufrn/imd/service/impl/DepositServiceImpl.class b/banking-server/target/classes/ufrn/imd/service/impl/DepositServiceImpl.class deleted file mode 100644 index 7663a247d03d86603195f6987564d6775fa06d0b..0000000000000000000000000000000000000000 Binary files a/banking-server/target/classes/ufrn/imd/service/impl/DepositServiceImpl.class and /dev/null differ diff --git a/banking-server/target/classes/ufrn/imd/utils/NameSpace.class b/banking-server/target/classes/ufrn/imd/utils/NameSpace.class deleted file mode 100644 index bca364926d480d38728b84a028f4af2299447065..0000000000000000000000000000000000000000 Binary files a/banking-server/target/classes/ufrn/imd/utils/NameSpace.class and /dev/null differ