Compare commits
26 Commits
Author | SHA1 | Date |
---|---|---|
VANNEAU | be5475868b | 1 year ago |
floxx2112 | 6ea78fb75d | 1 year ago |
floxx2112 | d12344a67b | 1 year ago |
floxx2112 | 3f4f3bd733 | 1 year ago |
floxx2112 | dab3f85d6f | 1 year ago |
floxx2112 | 2ca96c3778 | 1 year ago |
fhibert | ef26c7b3c8 | 1 year ago |
floxx2112 | 7d36756f15 | 1 year ago |
floxx2112 | e9347aaa9a | 2 years ago |
floxx2112 | c37c5f15c8 | 2 years ago |
floxx2112 | 951904394b | 2 years ago |
floxx2112 | c0100c5d68 | 2 years ago |
floxx2112 | 8512a97924 | 2 years ago |
floxx2112 | c4f5863ce0 | 2 years ago |
floxx2112 | 09a954a2e2 | 2 years ago |
floxx2112 | 8e1bd3a7a8 | 2 years ago |
fhibert | c93ed93277 | 2 years ago |
floxx2112 | bd23448f42 | 2 years ago |
floxx2112 | 8ecc9bd066 | 2 years ago |
floxx2112 | 889ee57e04 | 2 years ago |
floxx2112 | ce432af07f | 2 years ago |
floxx2112 | dd8ec9d844 | 2 years ago |
floxx2112 | 42085b6439 | 2 years ago |
floxx2112 | 6ea92f86fd | 2 years ago |
floxx2112 | dbd113590f | 2 years ago |
floxx2112 | 2dbfd6d667 | 2 years ago |
@ -0,0 +1,35 @@ |
||||
HELP.md |
||||
target/ |
||||
!.mvn/wrapper/maven-wrapper.jar |
||||
!**/src/main/**/target/ |
||||
!**/src/test/**/target/ |
||||
|
||||
### 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/ |
||||
!**/src/main/**/build/ |
||||
!**/src/test/**/build/ |
||||
|
||||
### VS Code ### |
||||
.vscode/ |
||||
src/main/resources/application.properties |
||||
src/main/resources/application.properties |
Binary file not shown.
@ -0,0 +1,2 @@ |
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip |
||||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar |
@ -0,0 +1,28 @@ |
||||
# FROM eclipse-temurin:19-jdk-jammy |
||||
# |
||||
# WORKDIR /app |
||||
# |
||||
# COPY .mvn/ .mvn |
||||
# COPY mvnw pom.xml ./ |
||||
# RUN ./mvnw dependency:resolve |
||||
# |
||||
# COPY src ./src |
||||
# |
||||
# CMD ["./mvnw", "spring-boot:run"] |
||||
# |
||||
# Build |
||||
# |
||||
FROM maven:3.9.0-eclipse-temurin-19-focal AS build |
||||
COPY src /home/app/src |
||||
COPY pom.xml /home/app |
||||
RUN mvn -f /home/app/pom.xml clean package -DskipTests |
||||
# |
||||
# Package stage |
||||
# |
||||
FROM openjdk:19-jdk-alpine |
||||
WORKDIR /usr/local/lib |
||||
RUN mkdir git |
||||
RUN mkdir json |
||||
COPY src/main/resources/json /usr/local/lib/json |
||||
COPY --from=build /home/app/target/assistDbBackend-0.0.1-SNAPSHOT.jar /usr/local/lib/assistDbBackend.jar |
||||
CMD ["java","-jar", "-Dapplication.config.path=classpath:", "/usr/local/lib/assistDbBackend.jar"] |
@ -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 "$@" |
@ -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% |
@ -0,0 +1,120 @@ |
||||
<?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 https://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>3.0.2</version> |
||||
<relativePath/> <!-- lookup parent from repository --> |
||||
</parent> |
||||
<groupId>com.apside</groupId> |
||||
<artifactId>assistDbBackend</artifactId> |
||||
<version>0.0.1-SNAPSHOT</version> |
||||
<name>assistDbBackend</name> |
||||
<description>Demo project for Spring Boot</description> |
||||
<properties> |
||||
<java.version>19</java.version> |
||||
</properties> |
||||
<packaging>jar</packaging> |
||||
<dependencies> |
||||
<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-starter-tomcat</artifactId> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.mysql</groupId> |
||||
<artifactId>mysql-connector-j</artifactId> |
||||
<scope>runtime</scope> |
||||
</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> |
||||
<dependency> |
||||
<groupId>com.fasterxml.jackson.core</groupId> |
||||
<artifactId>jackson-databind</artifactId> |
||||
<version>2.13.3</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.json</groupId> |
||||
<artifactId>json</artifactId> |
||||
<version>20180130</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.vaadin.external.google</groupId> |
||||
<artifactId>android-json</artifactId> |
||||
<version>0.0.20131108.vaadin1</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.eclipse.jgit</groupId> |
||||
<artifactId>org.eclipse.jgit</artifactId> |
||||
<version>6.4.0.202211300538-r</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.h2database</groupId> |
||||
<artifactId>h2</artifactId> |
||||
<scope>runtime</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>junit</groupId> |
||||
<artifactId>junit</artifactId> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.mockito</groupId> |
||||
<artifactId>mockito-core</artifactId> |
||||
<version>3.6.28</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.junit.jupiter</groupId> |
||||
<artifactId>junit-jupiter-engine</artifactId> |
||||
<version>5.9.1</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.assertj</groupId> |
||||
<artifactId>assertj-core</artifactId> |
||||
<version>3.4.1</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>log4j</groupId> |
||||
<artifactId>log4j</artifactId> |
||||
<version>1.2.17</version> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
<configuration> |
||||
<excludes> |
||||
<exclude> |
||||
<groupId>org.projectlombok</groupId> |
||||
<artifactId>lombok</artifactId> |
||||
</exclude> |
||||
</excludes> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
|
||||
</project> |
@ -0,0 +1,15 @@ |
||||
package com.apside.assist.db.backend; |
||||
|
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; |
||||
|
||||
@SpringBootApplication(exclude = SecurityAutoConfiguration.class) |
||||
public class AssistDBBackendApplication { |
||||
|
||||
public static void main(String[] args){ |
||||
SpringApplication.run(AssistDBBackendApplication.class, args); |
||||
|
||||
|
||||
} |
||||
} |
@ -0,0 +1,110 @@ |
||||
package com.apside.assist.db.backend.controller; |
||||
|
||||
import com.apside.assist.db.backend.model.InfoColumn; |
||||
import com.apside.assist.db.backend.service.InfoColumnService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.http.ResponseEntity; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
|
||||
@RestController |
||||
@RequestMapping("/api") |
||||
@Slf4j |
||||
public class InfoColumnController { |
||||
public static final String ERROR_COLUMNS = "Error occurred while fetching columns"; |
||||
private final InfoColumnService infoColumnService; |
||||
|
||||
public InfoColumnController(InfoColumnService infoColumnService) { |
||||
this.infoColumnService = infoColumnService; |
||||
} |
||||
|
||||
/** |
||||
* Read - Get one column |
||||
* @param id The id of the InfoColumn |
||||
* @return An InfoColumn object full filled |
||||
*/ |
||||
@GetMapping("/column/{id}") |
||||
public ResponseEntity<InfoColumn> getColumn(@PathVariable("id") final Long id) { |
||||
log.debug("Start GetColumn - Get Request - with id: " + id); |
||||
Optional<InfoColumn> infoColumn = infoColumnService.getColumn(id); |
||||
return infoColumn.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).build()); |
||||
} |
||||
|
||||
/** |
||||
* Read - Get all Columns |
||||
* @return - An Iterable object of InfoColumn full filled |
||||
*/ |
||||
@GetMapping("/columns/all") |
||||
public ResponseEntity<Iterable<InfoColumn>> getColumns() { |
||||
log.debug("Start getColumns - Get Request"); |
||||
try { |
||||
Iterable<InfoColumn> columns = infoColumnService.getAllColumns(); |
||||
return ResponseEntity.ok(columns); |
||||
} catch (Exception e){ |
||||
log.error(ERROR_COLUMNS, e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Read - Get Columns by Schema's and Table's name |
||||
* @return - An Iterable object of InfoColumn full filled |
||||
*/ |
||||
@GetMapping("/columns/{schema}/{table}") |
||||
public ResponseEntity<Iterable<InfoColumn>> getSelectedColumns(@PathVariable("schema") final String schema, @PathVariable("table") final String table) { |
||||
log.debug("Start GetSelectedColumns - Get Request - with schema: {}, table: {}", schema, table); |
||||
try { |
||||
Iterable<InfoColumn> columnsSelected = infoColumnService.getSelectedColumns(table, schema); |
||||
return ResponseEntity.ok(columnsSelected); |
||||
} catch (Exception e){ |
||||
log.error(ERROR_COLUMNS, e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@GetMapping("/columns/{firstSchema}/{secondSchema}/{firstTable}/{secondTable}") |
||||
public ResponseEntity<Iterable<InfoColumn>> getColumnsForJoin(@PathVariable("firstTable") final String firstTable, @PathVariable("secondTable") final String secondTable, @PathVariable("firstSchema") final String firstSchema, @PathVariable("secondSchema") final String secondSchema) { |
||||
log.debug("Start GetColumnsForJoin - Get Request - with firstTable: {}, secondTable: {}, firstSchema: {}, secondSchema: {}", firstTable, secondTable, firstSchema, secondSchema); |
||||
try { |
||||
Iterable<InfoColumn> columnsForJoin = infoColumnService.getColumnsForJoin(firstTable, secondTable, firstSchema, secondSchema); |
||||
return ResponseEntity.ok(columnsForJoin); |
||||
} catch (Exception e){ |
||||
log.error(ERROR_COLUMNS, e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@GetMapping("/columns/joins") |
||||
public ResponseEntity<Iterable<InfoColumn>> getColumnsForJoinTwo(@RequestParam("tables") String tables, @RequestParam("schemas") String schemas) { |
||||
log.debug("Start GetColumnsForJoinTwo - Get Request - with tables: {}, schemas: {}", tables, schemas); |
||||
List<String> tablesList = new ArrayList<>(Arrays.asList(tables.split(","))); |
||||
List<String> schemasList = new ArrayList<>(Arrays.asList(schemas.split(","))); |
||||
try { |
||||
Iterable<InfoColumn> columnsForJoin = infoColumnService.getColumnsForJoinTwo(tablesList, schemasList); |
||||
return ResponseEntity.ok(columnsForJoin); |
||||
} catch (Exception e){ |
||||
log.error(ERROR_COLUMNS, e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@DeleteMapping("/columns/deleteAll") |
||||
public ResponseEntity<Void> deleteAllColumns() { |
||||
log.debug("DeleteAllColumns called"); |
||||
try { |
||||
infoColumnService.deleteAllColumn(); |
||||
return ResponseEntity.ok().build(); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while deleting columns", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,131 @@ |
||||
package com.apside.assist.db.backend.controller; |
||||
|
||||
import com.apside.assist.db.backend.model.InfoTable; |
||||
import com.apside.assist.db.backend.service.InfoTableService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.http.ResponseEntity; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
@RestController |
||||
@RequestMapping("/api") |
||||
@Slf4j |
||||
public class InfoTableController { |
||||
|
||||
public static final String ERROR_DELETING_TABLES = "Error occurred while deleting tables"; |
||||
private final InfoTableService infoTableService; |
||||
|
||||
public InfoTableController(InfoTableService infoTableService) { |
||||
this.infoTableService = infoTableService; |
||||
} |
||||
|
||||
/** |
||||
* Read - Get one table |
||||
* @param id The id of the InfoTable |
||||
* @return An InfoTable object full filled |
||||
*/ |
||||
@GetMapping("/table/{id}") |
||||
public ResponseEntity<InfoTable> getTable(@PathVariable("id") final Long id) { |
||||
log.debug("Start getTable - Get Request - with id: " + id); |
||||
|
||||
Optional<InfoTable> infoTable = infoTableService.getTable(id); |
||||
return infoTable.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); |
||||
} |
||||
|
||||
/** |
||||
* Read - Get all Tables |
||||
* @return - An Iterable object of InfoTable full filled |
||||
*/ |
||||
@GetMapping("/tables/all") |
||||
public ResponseEntity<Iterable<InfoTable>> getTables() { |
||||
try { |
||||
Iterable<InfoTable> tables = infoTableService.getAllTables(); |
||||
return ResponseEntity.ok(tables); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while fetching tables", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
/** |
||||
* Read - Get all Schemas |
||||
* @return - An Iterable object of String full filled |
||||
*/ |
||||
@GetMapping("/schemas/all") |
||||
public ResponseEntity<Iterable<String>> getSchemas() { |
||||
log.debug("Start getSchemas - Get Request"); |
||||
try { |
||||
Iterable<String> schemas = infoTableService.getAllSchemas(); |
||||
return ResponseEntity.ok(schemas); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while fetching schemas", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Read - Get Tables by Schema's name |
||||
* @return - An Iterable object of InfoTable full filled |
||||
*/ |
||||
@GetMapping("/tables/{schema}") |
||||
public ResponseEntity<Iterable<InfoTable>> getTablesBySchemaName(@PathVariable("schema") final String schema) { |
||||
log.debug("Start getTablesBySchemaName - Get Request - with schema: {}", schema); |
||||
try { |
||||
Iterable<InfoTable> tables = infoTableService.getTablesBySchemaName(schema); |
||||
return ResponseEntity.ok(tables); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while fetching tables by schema", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@GetMapping("/schemas/{table}") |
||||
public ResponseEntity<Iterable<InfoTable>> getSchemaByTableName(@PathVariable("table") final String table) { |
||||
log.debug("Start getSchemaByTableName - Get Request - with table: {}", table); |
||||
try { |
||||
Iterable<InfoTable> schemas = infoTableService.getSchemaByTableName(table); |
||||
return ResponseEntity.ok(schemas); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while fetching schema by table name", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@DeleteMapping("/tables/deleteAll") |
||||
public ResponseEntity<Void> deleteAllTables() { |
||||
log.debug("DeleteAllTables called"); |
||||
try { |
||||
infoTableService.deleteAllTable(); |
||||
return ResponseEntity.ok().build(); |
||||
} catch (Exception e) { |
||||
log.error(ERROR_DELETING_TABLES, e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@GetMapping("/tables/filter/{filter}") |
||||
public ResponseEntity<Iterable<InfoTable>> getTablesWithFilter(@PathVariable("filter") String filter){ |
||||
log.debug("getTablesWithFilter called"); |
||||
try { |
||||
Iterable<InfoTable> tables = infoTableService.getTablesWithFilter(filter); |
||||
return ResponseEntity.ok(tables); |
||||
} catch (Exception e) { |
||||
log.error(ERROR_DELETING_TABLES, e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@GetMapping("/tables/filter/{schema}/{filter}") |
||||
public ResponseEntity<Iterable<InfoTable>> getTablesWithFilterAndSchema(@PathVariable("filter") String filter, @PathVariable("schema") String schema){ |
||||
log.debug("getTablesWithFilterAndSchema called"); |
||||
try { |
||||
Iterable<InfoTable> tables = infoTableService.getTablesWithFilterAndSchema(filter, schema); |
||||
return ResponseEntity.ok(tables); |
||||
} catch (Exception e) { |
||||
log.error(ERROR_DELETING_TABLES, e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,62 @@ |
||||
package com.apside.assist.db.backend.controller; |
||||
|
||||
import com.apside.assist.db.backend.model.LinkInfo; |
||||
import com.apside.assist.db.backend.service.LinkInfoService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.http.ResponseEntity; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
@RestController |
||||
@RequestMapping("/api") |
||||
@Slf4j |
||||
public class LinkInfoController { |
||||
|
||||
private final LinkInfoService linkInfoService; |
||||
|
||||
public LinkInfoController(LinkInfoService linkInfoService) { |
||||
this.linkInfoService = linkInfoService; |
||||
} |
||||
|
||||
/** |
||||
* Read - Get one Link |
||||
* @param id The id of the LinkInfo |
||||
* @return An LinkInfo object full filled |
||||
*/ |
||||
@GetMapping("/link/{id}") |
||||
public ResponseEntity<LinkInfo> getLinkInfo(@PathVariable("id") final Long id) { |
||||
log.debug("Start getLinkInfo - Get Request - with id: " + id); |
||||
Optional<LinkInfo> linkInfo = linkInfoService.getLinkInfo(id); |
||||
return linkInfo.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); |
||||
} |
||||
|
||||
/** |
||||
* Read - Get all LinkInfos |
||||
* @return - An Iterable object of LinkInfo full filled |
||||
*/ |
||||
@GetMapping("/links/all") |
||||
public ResponseEntity<Iterable<LinkInfo>> getLinksInfos() { |
||||
log.debug("Start getLinksInfos - Get Request"); |
||||
try { |
||||
Iterable<LinkInfo> linksInfos = linkInfoService.getAllLinksInfos(); |
||||
return ResponseEntity.ok(linksInfos); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while fetching link infos", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@DeleteMapping("/links/deleteAll") |
||||
public ResponseEntity<Void> deleteAllLinks() { |
||||
log.debug("DeleteAllLinks called"); |
||||
try { |
||||
linkInfoService.deleteAllLinks(); |
||||
return ResponseEntity.ok().build(); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while deleting links", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,33 @@ |
||||
package com.apside.assist.db.backend.controller; |
||||
|
||||
import com.apside.assist.db.backend.service.ResetDataService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.http.ResponseEntity; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
@RestController |
||||
@RequestMapping("/api") |
||||
@Slf4j |
||||
public class ResetDataController { |
||||
|
||||
private final ResetDataService resetDataService; |
||||
|
||||
public ResetDataController(ResetDataService resetDataService) { |
||||
this.resetDataService = resetDataService; |
||||
} |
||||
|
||||
@PostMapping("/reset") |
||||
public ResponseEntity<Void> resetData() { |
||||
log.debug("ResetData called"); |
||||
try { |
||||
resetDataService.deleteEverything(); |
||||
resetDataService.insertEverything(); |
||||
resetDataService.checkAndInsertLinks(); |
||||
return ResponseEntity.ok().build(); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while resetting data", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,88 @@ |
||||
package com.apside.assist.db.backend.controller; |
||||
|
||||
import com.apside.assist.db.backend.model.LinkScriptTag; |
||||
import com.apside.assist.db.backend.model.Script; |
||||
import com.apside.assist.db.backend.service.ScriptsService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.http.ResponseEntity; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.List; |
||||
|
||||
@RestController |
||||
@RequestMapping("/api") |
||||
@Slf4j |
||||
public class ScriptController { |
||||
|
||||
private final ScriptsService scriptsService; |
||||
|
||||
public ScriptController(ScriptsService scriptsService) { |
||||
this.scriptsService = scriptsService; |
||||
} |
||||
|
||||
@GetMapping("/scripts") |
||||
public ResponseEntity<List<Script>> getAllScripts() { |
||||
log.debug("GetAllScripts called"); |
||||
try { |
||||
List<Script> scripts = scriptsService.retrieveScripts(); |
||||
return ResponseEntity.ok(scripts); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while retrieving scripts", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@GetMapping("/scripts/link") |
||||
public ResponseEntity<List<LinkScriptTag>> getAllLinkScriptsTags() { |
||||
log.debug("GetAllLinkScriptsTags called"); |
||||
try { |
||||
List<LinkScriptTag> linkScriptsTags = scriptsService.getAllScriptTag(); |
||||
return ResponseEntity.ok(linkScriptsTags); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while retrieving link scripts tags", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@DeleteMapping("/script/delete/{name}") |
||||
public ResponseEntity<Void> deleteScript(@PathVariable("name") final String name) { |
||||
log.debug("Start DeleteScript - Delete Request - with name: {}", name); |
||||
try { |
||||
scriptsService.deleteOneScript(name); |
||||
return ResponseEntity.ok().build(); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while deleting script", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
|
||||
@PostMapping("/script/add") |
||||
public ResponseEntity<Void> addScript(@RequestBody String content, @RequestParam("name") String name, @RequestParam("desc") String description, @RequestParam("tagList") List<String> tagsList, @RequestParam("linkid") int linkId) { |
||||
log.debug("Start AddScript - Get Request - with name: {}, description: {}, tagsList: {} and linkId: {}", name, description, tagsList, linkId); |
||||
try { |
||||
scriptsService.addOneScript(content, name); |
||||
scriptsService.addOneLink(name, description, tagsList, linkId); |
||||
return ResponseEntity.ok().build(); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while adding script", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@PostMapping("/script/edit") |
||||
public ResponseEntity<Void> editScript(@RequestBody String content, @RequestParam("defaultname") String defaultName, @RequestParam("newname") String newName, @RequestParam("desc") String description, @RequestParam("tagList") List<String> tagsList, @RequestParam("linkid") int linkId) { |
||||
log.debug("Start EditScript - Get Request - with defaultName: {}, newName: {}, description: {}, tagsList: {}, linkId: {}", defaultName, newName, description, tagsList, linkId); |
||||
try { |
||||
scriptsService.simpleDeleteScript(defaultName); |
||||
scriptsService.addOneScript(content, newName); |
||||
scriptsService.updateOneLink(newName, description, tagsList, linkId); |
||||
return ResponseEntity.ok().build(); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while editing script", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,70 @@ |
||||
package com.apside.assist.db.backend.controller; |
||||
|
||||
import com.apside.assist.db.backend.model.Tag; |
||||
import com.apside.assist.db.backend.service.TagsService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.http.ResponseEntity; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.List; |
||||
|
||||
@RestController |
||||
@RequestMapping("/api") |
||||
@Slf4j |
||||
public class TagsController { |
||||
|
||||
private final TagsService tagsService; |
||||
|
||||
public TagsController(TagsService tagsService) { |
||||
this.tagsService = tagsService; |
||||
} |
||||
|
||||
@GetMapping("/tags/all") |
||||
public ResponseEntity<List<Tag>> getTags() { |
||||
log.debug("GetTags called"); |
||||
try { |
||||
List<Tag> tags = tagsService.getAllTags(); |
||||
return ResponseEntity.ok(tags); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while retrieving tags", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@DeleteMapping("/tag/delete/{nameTag}") |
||||
public ResponseEntity<Void> deleteTag(@PathVariable("nameTag") final String nameTag) { |
||||
log.debug("Start DeleteTag - Delete Request - with name: {}", nameTag); |
||||
try { |
||||
tagsService.deleteTag(nameTag); |
||||
return ResponseEntity.ok().build(); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while deleting tag", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@PostMapping("/tag/add") |
||||
public ResponseEntity<Void> addTag(@RequestBody Tag tag) { |
||||
log.debug("Start AddTag - Post Request - with tag: {}", tag); |
||||
try { |
||||
tagsService.addTag(tag); |
||||
return ResponseEntity.ok().build(); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while adding tag", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@PutMapping("/tag/update/{prevTag}") |
||||
public ResponseEntity<Void> updateTag(@PathVariable("prevTag") final String prevTag, @RequestBody Tag tag) { |
||||
log.debug("Start UpdateTag - Put Request - with previous tag: {}, new tag info: {}", prevTag, tag); |
||||
try { |
||||
tagsService.updateTag(prevTag, tag); |
||||
return ResponseEntity.ok().build(); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while updating tag", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,44 @@ |
||||
package com.apside.assist.db.backend.model; |
||||
|
||||
import jakarta.persistence.*; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
@Builder |
||||
@Entity |
||||
@Table(name = "informations_column") |
||||
public class InfoColumn { |
||||
@Id |
||||
@GeneratedValue(strategy = GenerationType.IDENTITY) |
||||
private Long id; |
||||
|
||||
@Column(name="name_column") |
||||
private String nameColumn; |
||||
|
||||
@Column(name="data_type") |
||||
private String dataType; |
||||
|
||||
@Column(name = "length_column") |
||||
private int lengthColumn; |
||||
|
||||
@Column(name = "column_text") |
||||
private String columnText; |
||||
|
||||
public InfoColumn(){} |
||||
|
||||
public InfoColumn(Long id, String nameColumn, String dataType, int lengthColumn, String columnText){ |
||||
this.id = id; |
||||
this.nameColumn = nameColumn; |
||||
this.dataType = dataType; |
||||
this.lengthColumn = lengthColumn; |
||||
this.columnText = columnText; |
||||
} |
||||
|
||||
public InfoColumn(String nameColumn, String dataType, int lengthColumn, String columnText){ |
||||
this.nameColumn = nameColumn; |
||||
this.dataType = dataType; |
||||
this.lengthColumn = lengthColumn; |
||||
this.columnText = columnText; |
||||
} |
||||
} |
@ -0,0 +1,39 @@ |
||||
package com.apside.assist.db.backend.model; |
||||
|
||||
import jakarta.persistence.*; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
@Builder |
||||
@Entity |
||||
@Table(name = "informations_table") |
||||
public class InfoTable { |
||||
@Id |
||||
@GeneratedValue(strategy = GenerationType.IDENTITY) |
||||
private Long id; |
||||
|
||||
@Column(name="name_table") |
||||
private String nameTable; |
||||
|
||||
@Column(name="name_schema") |
||||
private String nameSchema; |
||||
|
||||
@Column(name = "table_text") |
||||
private String tableText; |
||||
|
||||
public InfoTable(){} |
||||
|
||||
public InfoTable(Long id, String nameTable, String nameSchema, String tableText){ |
||||
this.id = id; |
||||
this.nameTable = nameTable; |
||||
this.nameSchema = nameSchema; |
||||
this.tableText = tableText; |
||||
} |
||||
|
||||
public InfoTable(String table, String schema, String tableText) { |
||||
this.nameTable = table; |
||||
this.nameSchema = schema; |
||||
this.tableText = tableText; |
||||
} |
||||
} |
@ -0,0 +1,37 @@ |
||||
package com.apside.assist.db.backend.model; |
||||
|
||||
import jakarta.persistence.*; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
@Entity |
||||
@Table(name = "link_informations") |
||||
public class LinkInfo { |
||||
@Id |
||||
@GeneratedValue(strategy = GenerationType.IDENTITY) |
||||
private Long id; |
||||
|
||||
@Column(name="name_table") |
||||
private String nameTable; |
||||
|
||||
@Column(name="name_schema") |
||||
private String nameSchema; |
||||
|
||||
@Column(name = "column_id") |
||||
private int columnId; |
||||
|
||||
public LinkInfo(){} |
||||
|
||||
public LinkInfo(Long id, String nameTable, String nameSchema, int columnId){ |
||||
this.id = id; |
||||
this.nameTable = nameTable; |
||||
this.nameSchema = nameSchema; |
||||
this.columnId = columnId; |
||||
} |
||||
|
||||
public LinkInfo(String nameTable, String nameSchema, int columnId){ |
||||
this.nameTable = nameTable; |
||||
this.nameSchema = nameSchema; |
||||
this.columnId = columnId; |
||||
} |
||||
} |
@ -0,0 +1,25 @@ |
||||
package com.apside.assist.db.backend.model; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Data |
||||
public class LinkScriptTag { |
||||
private int id; |
||||
|
||||
private String scriptName; |
||||
|
||||
private String description; |
||||
|
||||
private List<String> tags; |
||||
|
||||
public LinkScriptTag(){} |
||||
|
||||
public LinkScriptTag(int id, String scriptName, String description, List<String> tags){ |
||||
this.id = id; |
||||
this.scriptName = scriptName; |
||||
this.description = description; |
||||
this.tags = tags; |
||||
} |
||||
} |
@ -0,0 +1,20 @@ |
||||
package com.apside.assist.db.backend.model; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class Script { |
||||
private String extension; |
||||
private String name; |
||||
|
||||
private String data; |
||||
|
||||
|
||||
public Script(){} |
||||
|
||||
public Script(String extension, String name, String data){ |
||||
this.extension = extension; |
||||
this.name = name; |
||||
this.data = data; |
||||
} |
||||
} |
@ -0,0 +1,21 @@ |
||||
package com.apside.assist.db.backend.model; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class Tag { |
||||
|
||||
private int tagId; |
||||
|
||||
private String nameTag; |
||||
|
||||
private String descriptionTag; |
||||
|
||||
public Tag(){} |
||||
|
||||
public Tag(int tagId, String nameTag, String descriptionTag){ |
||||
this.tagId = tagId; |
||||
this.nameTag = nameTag; |
||||
this.descriptionTag = descriptionTag; |
||||
} |
||||
} |
@ -0,0 +1,11 @@ |
||||
package com.apside.assist.db.backend.model.json; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class Column { |
||||
private String name; |
||||
private String data_type; |
||||
private int length; |
||||
private String column_text; |
||||
} |
@ -0,0 +1,13 @@ |
||||
package com.apside.assist.db.backend.model.json; |
||||
|
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Data |
||||
public class DataEnum { |
||||
private List<Column> columns; |
||||
private String table_text; |
||||
private String table; |
||||
} |
@ -0,0 +1,11 @@ |
||||
package com.apside.assist.db.backend.model.json; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Data |
||||
public class Schema { |
||||
private String schema; |
||||
private List<DataEnum> data; |
||||
} |
@ -0,0 +1,35 @@ |
||||
package com.apside.assist.db.backend.repository; |
||||
|
||||
import com.apside.assist.db.backend.model.InfoColumn; |
||||
import org.springframework.data.jpa.repository.Modifying; |
||||
import org.springframework.data.jpa.repository.Query; |
||||
import org.springframework.data.repository.CrudRepository; |
||||
import org.springframework.data.repository.query.Param; |
||||
import org.springframework.stereotype.Repository; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Repository |
||||
public interface InfoColumnRepository extends CrudRepository<InfoColumn, Long> { |
||||
@Query(value = "SELECT * FROM informations_column WHERE id IN\n" + |
||||
"(SELECT column_id FROM link_informations WHERE name_table= :table AND name_schema= :schema)", nativeQuery = true) |
||||
Iterable<InfoColumn> getSelectedColumns(@Param("table") String table, @Param("schema") String schema); |
||||
|
||||
@Query(value = "SELECT * FROM informations_column WHERE id IN\n" + |
||||
"(SELECT column_id FROM link_informations WHERE name_table IN (:firstTable, :secondTable) AND name_schema IN (:firstSchema, :secondSchema) GROUP BY column_id HAVING COUNT(column_id) > 1)", nativeQuery = true) |
||||
Iterable<InfoColumn> getColumnsForJoin(@Param("firstTable") String firstTable, @Param("secondTable") String secondTable, @Param("firstSchema") String firstSchema, @Param("secondSchema") String secondSchema); |
||||
|
||||
@Query(value = "SELECT * FROM informations_column WHERE id IN\n" + |
||||
"(SELECT column_id FROM link_informations WHERE name_table IN :tables AND name_schema IN :schemas GROUP BY column_id HAVING COUNT(column_id) > 1)", nativeQuery = true) |
||||
Iterable<InfoColumn> getColumnsForJoinTwo(@RequestParam("tables") List<String> tables, @RequestParam("schemas") List<String> schemas); |
||||
|
||||
@Query(value = "SELECT * FROM informations_column WHERE name_column = :namecol AND data_type = :datatype AND length_column = :lengthcol AND column_text = :columntext collate utf8mb4_bin", nativeQuery = true) |
||||
InfoColumn getSpecColumn(@Param("namecol") String nameCol, @Param("datatype") String dataType, @Param("lengthcol") int lengthCol, @Param("columntext") String columnText); |
||||
|
||||
@Modifying |
||||
@Transactional |
||||
@Query(value = "TRUNCATE TABLE informations_column", nativeQuery = true) |
||||
void truncateMyColumn(); |
||||
} |
@ -0,0 +1,42 @@ |
||||
package com.apside.assist.db.backend.repository; |
||||
|
||||
import com.apside.assist.db.backend.model.InfoTable; |
||||
import org.springframework.data.jpa.repository.Modifying; |
||||
import org.springframework.data.jpa.repository.Query; |
||||
import org.springframework.data.repository.CrudRepository; |
||||
import org.springframework.data.repository.query.Param; |
||||
import org.springframework.stereotype.Repository; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
@Repository |
||||
public interface InfoTableRepository extends CrudRepository<InfoTable, Long> { |
||||
@Query( |
||||
value = "SELECT DISTINCT name_schema FROM informations_table", |
||||
nativeQuery = true) |
||||
Iterable<String> getAllSchemas(); |
||||
|
||||
@Query( |
||||
value = "SELECT * FROM informations_table WHERE name_schema=:schema", |
||||
nativeQuery = true) |
||||
Iterable<InfoTable> getTablesBySchemaName(@Param("schema") String schema); |
||||
|
||||
@Query( |
||||
value = "SELECT * FROM informations_table WHERE name_table=:table", |
||||
nativeQuery = true) |
||||
Iterable<InfoTable> getSchemaByTableName(@Param("table") String table); |
||||
|
||||
@Query( |
||||
value = "SELECT * FROM informations_table WHERE name_table LIKE %:filter% ORDER BY CHAR_LENGTH(name_table)", |
||||
nativeQuery = true) |
||||
Iterable<InfoTable> getTablesWithFilter (@Param("filter") String filter); |
||||
|
||||
@Query( |
||||
value = "SELECT * FROM informations_table WHERE name_table LIKE %:filter% AND name_schema=:schema ORDER BY CHAR_LENGTH(name_table)", |
||||
nativeQuery = true) |
||||
Iterable<InfoTable> getTablesWithFilterAndSchema (@Param("filter") String filter, @Param("schema") String schema); |
||||
|
||||
@Modifying |
||||
@Transactional |
||||
@Query(value = "TRUNCATE TABLE informations_table", nativeQuery = true) |
||||
void truncateMyTable(); |
||||
} |
@ -0,0 +1,17 @@ |
||||
package com.apside.assist.db.backend.repository; |
||||
|
||||
import com.apside.assist.db.backend.model.LinkInfo; |
||||
import org.springframework.data.jpa.repository.Modifying; |
||||
import org.springframework.data.jpa.repository.Query; |
||||
import org.springframework.data.repository.CrudRepository; |
||||
import org.springframework.stereotype.Repository; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
@Repository |
||||
public interface LinkInfoRepository extends CrudRepository<LinkInfo, Long>{ |
||||
|
||||
@Modifying |
||||
@Transactional |
||||
@Query(value = "TRUNCATE TABLE link_informations", nativeQuery = true) |
||||
void truncateMyLink(); |
||||
} |
@ -0,0 +1,25 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import org.eclipse.jgit.api.errors.GitAPIException; |
||||
|
||||
import java.io.IOException; |
||||
import java.net.URISyntaxException; |
||||
|
||||
public interface GitService { |
||||
|
||||
/** |
||||
* Réalise un push sur le Gitea - AdditionalFiles |
||||
* @param |
||||
* @return void |
||||
* @throws | IOException | GitAPIException | URISyntaxException |
||||
*/ |
||||
void pushToGit() throws IOException, GitAPIException, URISyntaxException; |
||||
|
||||
/** |
||||
* Réalise un pull via le Gitea - AdditionalFiles |
||||
* @param |
||||
* @return void |
||||
* @throws | IOException | GitAPIException | URISyntaxException |
||||
*/ |
||||
void pullFromGit() throws IOException, GitAPIException; |
||||
} |
@ -0,0 +1,96 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.model.InfoColumn; |
||||
|
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
|
||||
public interface InfoColumnService { |
||||
|
||||
/** |
||||
* Récupère une colonne spécifique |
||||
* @param id |
||||
* @return InfoColum, |
||||
*/ |
||||
Optional<InfoColumn> getColumn(final Long id); |
||||
|
||||
/** |
||||
* Récupère toutes les colonnes |
||||
* @param |
||||
* @return InfoColum, |
||||
*/ |
||||
Iterable<InfoColumn> getAllColumns(); |
||||
|
||||
/** |
||||
* Récupère les colonnes présentes dans un duo Schéma/Table spécifique |
||||
* @param table |
||||
* @param schema |
||||
* @return InfoColum, |
||||
*/ |
||||
Iterable<InfoColumn> getSelectedColumns(String table, String schema); |
||||
|
||||
/** |
||||
* Récupère les colonnes présentes dans deux tables différentes |
||||
* @param firstTable |
||||
* @param secondTable |
||||
* @param firstSchema |
||||
* @param secondSchema |
||||
* @return InfoColum, |
||||
*/ |
||||
Iterable<InfoColumn> getColumnsForJoin(String firstTable, String secondTable, String firstSchema, String secondSchema); |
||||
|
||||
/** |
||||
* Récupère les colonnes présentes dans deux tables différentes |
||||
* @param tables |
||||
* @param schemas |
||||
* @return InfoColum, |
||||
*/ |
||||
Iterable<InfoColumn> getColumnsForJoinTwo(List<String> tables, List<String> schemas); |
||||
|
||||
/** |
||||
* Supprime une colonne spécifique |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
void deleteColumn(final Long id); |
||||
|
||||
/** |
||||
* Supprime toutes les colonnes |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void deleteAllColumn(); |
||||
|
||||
/** |
||||
* Ajoute ou modifie une colonne |
||||
* @param infoColumn |
||||
* @return InfoColum, |
||||
*/ |
||||
InfoColumn addOrUpdateColumn(InfoColumn infoColumn); |
||||
|
||||
/** |
||||
* Ajoute une liste de colonnes |
||||
* @param listOfColumns |
||||
* @return Iterable<InfoColum>, |
||||
*/ |
||||
Iterable<InfoColumn> addMultipleColumns(Iterable<InfoColumn> listOfColumns); |
||||
|
||||
|
||||
/** |
||||
* Récupère les informations d'une colonne spécifique |
||||
* @param nameCol |
||||
* @param dataType |
||||
* @param lengthCol |
||||
* @param columnText |
||||
* @return InfoColum, |
||||
*/ |
||||
InfoColumn getSpecCol(String nameCol, String dataType, int lengthCol, String columnText); |
||||
|
||||
/** |
||||
* Vide la table contenant toutes les colonnes |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void truncateMyColumn(); |
||||
|
||||
} |
@ -0,0 +1,97 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.model.InfoColumn; |
||||
import com.apside.assist.db.backend.model.InfoTable; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
public interface InfoTableService { |
||||
|
||||
/** |
||||
* Récupère une table spécifique |
||||
* @param id |
||||
* @return InfoTable, |
||||
*/ |
||||
Optional<InfoTable> getTable(final Long id); |
||||
|
||||
/** |
||||
* Récupère toutes les tables |
||||
* @param |
||||
* @return InfoTable, |
||||
*/ |
||||
Iterable<InfoTable> getAllTables(); |
||||
|
||||
/** |
||||
* Récupère les tables ayant un schéma spécifique |
||||
* @param schema |
||||
* @return InfoTable, |
||||
*/ |
||||
Iterable<InfoTable> getTablesBySchemaName(String schema); |
||||
|
||||
/** |
||||
* Récupère les schémas ayant une table spécifique |
||||
* @param table |
||||
* @return InfoTable, |
||||
*/ |
||||
Iterable<InfoTable> getSchemaByTableName(String table); |
||||
|
||||
/** |
||||
* Récupère tous les schémas |
||||
* @param |
||||
* @return String, |
||||
*/ |
||||
Iterable<String> getAllSchemas(); |
||||
|
||||
/** |
||||
* Supprime une table spécifique |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
void deleteTable(final Long id); |
||||
|
||||
/** |
||||
* Supprime toutes les tables |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void deleteAllTable(); |
||||
|
||||
/** |
||||
* Ajoute ou modifie une table |
||||
* @param infoTable |
||||
* @return InfoTable, |
||||
*/ |
||||
InfoTable addOrUpdateTable(InfoTable infoTable); |
||||
|
||||
/** |
||||
* Ajoute une liste de tables |
||||
* @param listOfTables |
||||
* @return Iterable<InfoTable>, |
||||
*/ |
||||
Iterable<InfoTable> addMultipleTables(Iterable<InfoTable> listOfTables); |
||||
|
||||
|
||||
/** |
||||
* Vide la table contenant toutes les tables |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void truncateMyTable(); |
||||
|
||||
/** |
||||
* Récupère les tables contenant les caractères du filtre |
||||
* @param filter |
||||
* @return InfoTable, |
||||
*/ |
||||
Iterable<InfoTable> getTablesWithFilter(String filter); |
||||
|
||||
/** |
||||
* Récupère les tables contenant les caractères du filtre et un schéma spécifique |
||||
* @param filter |
||||
* @param schema |
||||
* @return InfoTable, |
||||
*/ |
||||
Iterable<InfoTable> getTablesWithFilterAndSchema(String filter, String schema); |
||||
|
||||
|
||||
} |
@ -0,0 +1,58 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.model.LinkInfo; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
public interface LinkInfoService { |
||||
|
||||
/** |
||||
* Récupère un lien spécifique |
||||
* @param id |
||||
* @return LinkInfo, |
||||
*/ |
||||
Optional<LinkInfo> getLinkInfo(final Long id); |
||||
|
||||
/** |
||||
* Récupère tous les liens |
||||
* @param |
||||
* @return LinkInfo, |
||||
*/ |
||||
Iterable<LinkInfo> getAllLinksInfos(); |
||||
|
||||
/** |
||||
* Supprime un lien spécifique |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
void deleteLinkInfo(final Long id); |
||||
|
||||
/** |
||||
* Supprime tous les liens |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void deleteAllLinks(); |
||||
|
||||
/** |
||||
* Ajoute ou modifie un lien spécifique |
||||
* @param linkInfo |
||||
* @return LinkInfo, |
||||
*/ |
||||
LinkInfo addOrUpdateLink(LinkInfo linkInfo); |
||||
|
||||
/** |
||||
* Ajoute une liste de liens |
||||
* @param listOfLinkInfo |
||||
* @return Iterable<LinkInfo>, |
||||
*/ |
||||
Iterable<LinkInfo> addMultipleLinkInfo(Iterable<LinkInfo> listOfLinkInfo); |
||||
|
||||
|
||||
/** |
||||
* Vide la table contenant tous les liens entre tables et colonnes |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void truncateMyLink(); |
||||
} |
@ -0,0 +1,28 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException; |
||||
|
||||
public interface ResetDataService { |
||||
|
||||
/** |
||||
* Supprime toutes les données stockées en Base de données |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void deleteEverything(); |
||||
|
||||
/** |
||||
* Insert les données des tables, colonnes et schémas dans la base de données |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void insertEverything() throws JsonProcessingException; |
||||
|
||||
/** |
||||
* Insert les informations des liens entre les colonnes et les tables en base de données |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void checkAndInsertLinks() throws JsonProcessingException; |
||||
|
||||
} |
@ -0,0 +1,86 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.model.LinkScriptTag; |
||||
import com.apside.assist.db.backend.model.Script; |
||||
import org.eclipse.jgit.api.errors.GitAPIException; |
||||
|
||||
import java.io.IOException; |
||||
import java.net.URISyntaxException; |
||||
import java.util.List; |
||||
|
||||
public interface ScriptsService { |
||||
|
||||
/** |
||||
* Initialise le chemin du répertoire où les fichiers seront récupérés |
||||
* @param |
||||
* @return |
||||
* @throws IOException |
||||
*/ |
||||
void initialize() throws IOException; |
||||
|
||||
/** |
||||
* Permet de récupérer l'ensemble des scripts et requêtes dans le répertoire |
||||
* @param |
||||
* @return Script |
||||
* @throws IOException |
||||
* @throws GitAPIException |
||||
*/ |
||||
List<Script> retrieveScripts() throws IOException, GitAPIException; |
||||
|
||||
/** |
||||
* Permet de récupérer l'ensemble des informations liant les scripts et leurs tags associés via le fichier json "scripts" |
||||
* @param |
||||
* @return LinkScriptTag |
||||
* @throws IOException |
||||
*/ |
||||
List<LinkScriptTag> getAllScriptTag() throws IOException; |
||||
|
||||
/** |
||||
* Supprime un script spécifique |
||||
* @param name |
||||
* @return |
||||
*/ |
||||
void deleteOneScript(final String name); |
||||
|
||||
/** |
||||
* Supprime un script spécifique |
||||
* @param name |
||||
* @return |
||||
*/ |
||||
void simpleDeleteScript(final String name); |
||||
|
||||
/** |
||||
* Ajoute un script dans le répertoire |
||||
* @param content |
||||
* @param name |
||||
* @return |
||||
* @throws IOException |
||||
*/ |
||||
void addOneScript(final String content, final String name) throws IOException; |
||||
|
||||
/** |
||||
* Ajoute un lien entre un script et ses tags dans le fichier json |
||||
* @param name |
||||
* @param description |
||||
* @param tagList |
||||
* @param linkId |
||||
* @return |
||||
* @throws IOException |
||||
* @throws GitAPIException |
||||
* @throws URISyntaxException |
||||
*/ |
||||
void addOneLink(final String name, final String description, final List<String> tagList, final int linkId) throws IOException, GitAPIException, URISyntaxException; |
||||
|
||||
/** |
||||
* Modifie et actualise un lien spécifique entre un script et ses tags |
||||
* @param name |
||||
* @param description |
||||
* @param tagList |
||||
* @param linkId |
||||
* @return |
||||
* @throws IOException |
||||
* @throws GitAPIException |
||||
* @throws URISyntaxException |
||||
*/ |
||||
void updateOneLink(final String name, final String description, final List<String> tagList, final int linkId) throws IOException, GitAPIException, URISyntaxException; |
||||
} |
@ -0,0 +1,59 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.model.Tag; |
||||
import org.eclipse.jgit.api.errors.GitAPIException; |
||||
|
||||
import java.io.IOException; |
||||
import java.net.URISyntaxException; |
||||
import java.util.List; |
||||
|
||||
public interface TagsService { |
||||
|
||||
/** |
||||
* Initialise le chemin du répertoire où le fichier json contenant les tags se situe |
||||
* @param |
||||
* @return |
||||
* @throws IOException |
||||
*/ |
||||
void initialize() throws IOException; |
||||
|
||||
/** |
||||
* Permet de récupérer tous les tags via le fichier json "tags" |
||||
* @param |
||||
* @return Tag |
||||
* @throws IOException |
||||
* @throws GitAPIException |
||||
*/ |
||||
List<Tag> getAllTags() throws IOException, GitAPIException; |
||||
|
||||
/** |
||||
* Supprime un tag dans le fichier json |
||||
* @param deleteNameTag |
||||
* @return |
||||
* @throws IOException |
||||
* @throws GitAPIException |
||||
* @throws URISyntaxException |
||||
*/ |
||||
void deleteTag(final String deleteNameTag) throws IOException, GitAPIException, URISyntaxException; |
||||
|
||||
/** |
||||
* Ajoute un tag dans le fichier json |
||||
* @param tag |
||||
* @return |
||||
* @throws IOException |
||||
* @throws GitAPIException |
||||
* @throws URISyntaxException |
||||
*/ |
||||
void addTag(Tag tag) throws IOException, GitAPIException, URISyntaxException; |
||||
|
||||
/** |
||||
* Modifie et actualise un tag |
||||
* @param prevTag |
||||
* @param modTag |
||||
* @return |
||||
* @throws IOException |
||||
* @throws GitAPIException |
||||
* @throws URISyntaxException |
||||
*/ |
||||
void updateTag(final String prevTag, Tag modTag) throws IOException, GitAPIException, URISyntaxException; |
||||
} |
@ -0,0 +1,93 @@ |
||||
package com.apside.assist.db.backend.service.implementation; |
||||
|
||||
import com.apside.assist.db.backend.service.GitService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.eclipse.jgit.api.Git; |
||||
import org.eclipse.jgit.api.RemoteAddCommand; |
||||
import org.eclipse.jgit.api.errors.GitAPIException; |
||||
import org.eclipse.jgit.transport.URIish; |
||||
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; |
||||
import org.springframework.beans.factory.InitializingBean; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.core.io.PathResource; |
||||
import org.springframework.core.io.Resource; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.net.URISyntaxException; |
||||
import java.util.Objects; |
||||
|
||||
@Service |
||||
@Slf4j |
||||
public class GitServiceImpl implements GitService, InitializingBean { |
||||
|
||||
private String tempDirectoryPath; |
||||
@Value("${assistDb.get.username}") |
||||
private String userGit; |
||||
|
||||
@Value("${assistDb.get.password}") |
||||
private String accesToken; |
||||
|
||||
@Value("${assistDb.get.uri}") |
||||
private String uriGit; |
||||
private static final String NAME_URI = "origin"; |
||||
private static final String COMMIT_MESSAGE = "commited"; |
||||
private static final String BRANCH_NAME = "main"; |
||||
|
||||
@Override |
||||
public void afterPropertiesSet() throws Exception { |
||||
log.info("Initialisation GIT"); |
||||
Resource resource = new PathResource("git"); |
||||
tempDirectoryPath = resource.getURI().getPath(); |
||||
if (Objects.requireNonNull(resource.getFile().list()).length == 0) { |
||||
log.info("Récupération GIT"); |
||||
Git.cloneRepository() |
||||
.setURI(uriGit) |
||||
.setDirectory(resource.getFile()) |
||||
.call(); |
||||
} else { |
||||
log.info("Fichiers GIT déjà existants"); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void pushToGit() throws IOException, GitAPIException, URISyntaxException { |
||||
log.debug("Starting pushToGit method."); |
||||
pullFromGit(); |
||||
try (Git git = Git.open(new File(tempDirectoryPath))){ |
||||
RemoteAddCommand remoteAddCommand = git.remoteAdd(); |
||||
remoteAddCommand.setName(NAME_URI); |
||||
remoteAddCommand.setUri(new URIish(uriGit)); |
||||
// you can add more settings here if needed
|
||||
remoteAddCommand.call(); |
||||
|
||||
git.add().setUpdate(true).addFilepattern(".").call(); |
||||
git.add().addFilepattern(".").call(); |
||||
git.commit().setMessage(COMMIT_MESSAGE).call(); |
||||
|
||||
git.push().setCredentialsProvider(createCredential()).call(); |
||||
log.info("Push to Git successful."); |
||||
} catch (IOException|GitAPIException exception){ |
||||
log.error("Error push from git", exception); |
||||
throw exception; |
||||
} |
||||
|
||||
} |
||||
|
||||
public void pullFromGit() throws IOException, GitAPIException { |
||||
log.debug("Starting pullFromGit method."); |
||||
try (Git git = Git.open(new File(tempDirectoryPath))){ |
||||
git.pull().setCredentialsProvider(createCredential()).setRemote(NAME_URI).setRemoteBranchName(BRANCH_NAME).call(); |
||||
log.info("Pull from Git successful."); |
||||
} catch (IOException|GitAPIException exception){ |
||||
log.error("Error pull from git", exception); |
||||
throw exception; |
||||
} |
||||
|
||||
} |
||||
|
||||
private UsernamePasswordCredentialsProvider createCredential() { |
||||
return new UsernamePasswordCredentialsProvider(userGit, accesToken); |
||||
} |
||||
} |
@ -0,0 +1,87 @@ |
||||
package com.apside.assist.db.backend.service.implementation; |
||||
|
||||
import com.apside.assist.db.backend.model.InfoColumn; |
||||
import com.apside.assist.db.backend.repository.InfoColumnRepository; |
||||
import com.apside.assist.db.backend.service.InfoColumnService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
|
||||
@Service |
||||
@Slf4j |
||||
public class InfoColumnServiceImpl implements InfoColumnService { |
||||
|
||||
private final InfoColumnRepository infoColumnRepository; |
||||
|
||||
public InfoColumnServiceImpl(InfoColumnRepository infoColumnRepository) { |
||||
this.infoColumnRepository = infoColumnRepository; |
||||
} |
||||
|
||||
@Override |
||||
public Optional<InfoColumn> getColumn(final Long id) { |
||||
log.debug("Start GetColumn method - CRUD"); |
||||
return infoColumnRepository.findById(id); |
||||
} |
||||
|
||||
@Override |
||||
public Iterable<InfoColumn> getAllColumns() { |
||||
log.debug("Start GetAllColumns method - CRUD"); |
||||
return infoColumnRepository.findAll(); |
||||
} |
||||
|
||||
@Override |
||||
public Iterable<InfoColumn> getSelectedColumns(String table, String schema) { |
||||
log.debug("Start GetSelectedColumn method - Custom"); |
||||
return infoColumnRepository.getSelectedColumns(table, schema); |
||||
} |
||||
|
||||
@Override |
||||
public Iterable<InfoColumn> getColumnsForJoin(String firstTable, String secondTable, String firstSchema, String secondSchema) { |
||||
log.debug("Start GetColumnForJoin method - Custom"); |
||||
return infoColumnRepository.getColumnsForJoin(firstTable, secondTable, firstSchema, secondSchema); |
||||
} |
||||
|
||||
@Override |
||||
public Iterable<InfoColumn> getColumnsForJoinTwo(List<String> tables, List<String> schemas) { |
||||
log.debug("Start GetColumnForJoinTwo method - Custom"); |
||||
return infoColumnRepository.getColumnsForJoinTwo(tables, schemas); |
||||
} |
||||
|
||||
@Override |
||||
public void deleteColumn(final Long id) { |
||||
log.debug("Start deleteColumn method - CRUD"); |
||||
infoColumnRepository.deleteById(id); |
||||
} |
||||
|
||||
@Override |
||||
public void deleteAllColumn() { |
||||
log.debug("Start deleteAllColumns method - CRUD"); |
||||
infoColumnRepository.deleteAll(); |
||||
} |
||||
|
||||
@Override |
||||
public InfoColumn addOrUpdateColumn(InfoColumn infoColumn) { |
||||
log.debug("Start addOrUpdateColumn method - CRUD"); |
||||
return infoColumnRepository.save(infoColumn); |
||||
} |
||||
|
||||
@Override |
||||
public Iterable<InfoColumn> addMultipleColumns(Iterable<InfoColumn> listOfColumns) { |
||||
log.debug("Start addMultipleColumns method - CRUD"); |
||||
return infoColumnRepository.saveAll(listOfColumns); |
||||
} |
||||
|
||||
@Override |
||||
public InfoColumn getSpecCol(String nameCol, String dataType, int lengthCol, String columnText){ |
||||
log.debug("Start getSpecCol method - Custom"); |
||||
return infoColumnRepository.getSpecColumn(nameCol, dataType, lengthCol, columnText); |
||||
} |
||||
|
||||
@Override |
||||
public void truncateMyColumn(){ |
||||
log.debug("Start truncateMyColumn method - Custom"); |
||||
infoColumnRepository.truncateMyColumn(); |
||||
} |
||||
} |
@ -0,0 +1,93 @@ |
||||
package com.apside.assist.db.backend.service.implementation; |
||||
|
||||
import com.apside.assist.db.backend.repository.InfoTableRepository; |
||||
import com.apside.assist.db.backend.model.InfoTable; |
||||
import com.apside.assist.db.backend.service.InfoTableService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
@Service |
||||
@Slf4j |
||||
public class InfoTableServiceImpl implements InfoTableService { |
||||
|
||||
private final InfoTableRepository infoTableRepository; |
||||
|
||||
public InfoTableServiceImpl(InfoTableRepository infoTableRepository) { |
||||
this.infoTableRepository = infoTableRepository; |
||||
} |
||||
|
||||
@Override |
||||
public Optional<InfoTable> getTable(final Long id) { |
||||
log.debug("Start getTable method - CRUD"); |
||||
return infoTableRepository.findById(id); |
||||
} |
||||
|
||||
@Override |
||||
public Iterable<InfoTable> getAllTables() { |
||||
log.debug("Start getAllTables method - CRUD"); |
||||
return infoTableRepository.findAll(); |
||||
} |
||||
|
||||
@Override |
||||
public Iterable<InfoTable> getTablesBySchemaName(String schema) { |
||||
log.debug("Start getTableBySchemaName method - Custom"); |
||||
return infoTableRepository.getTablesBySchemaName(schema); |
||||
} |
||||
|
||||
@Override |
||||
public Iterable<InfoTable> getSchemaByTableName(String table) { |
||||
log.debug("Start getSchemaByTableName method - Custom"); |
||||
return infoTableRepository.getSchemaByTableName(table); |
||||
} |
||||
|
||||
@Override |
||||
public Iterable<String> getAllSchemas(){ |
||||
log.debug("Start getAllSchemas method - CRUD"); |
||||
return infoTableRepository.getAllSchemas(); |
||||
} |
||||
|
||||
@Override |
||||
public void deleteTable(final Long id) { |
||||
log.debug("Start deleteTable method - CRUD"); |
||||
infoTableRepository.deleteById(id); |
||||
} |
||||
|
||||
@Override |
||||
public void deleteAllTable() { |
||||
log.debug("Start deleteAllTable method - CRUD"); |
||||
infoTableRepository.deleteAll(); |
||||
} |
||||
|
||||
@Override |
||||
public InfoTable addOrUpdateTable(InfoTable infoTable) { |
||||
log.debug("Start deleteAllTable method - CRUD"); |
||||
return infoTableRepository.save(infoTable); |
||||
} |
||||
|
||||
@Override |
||||
public Iterable<InfoTable> addMultipleTables(Iterable<InfoTable> listOfTables) { |
||||
log.debug("Start addMultipleTables method - CRUD"); |
||||
return infoTableRepository.saveAll(listOfTables); |
||||
} |
||||
|
||||
@Override |
||||
public void truncateMyTable(){ |
||||
log.debug("Start truncateMyTable method - Custom"); |
||||
infoTableRepository.truncateMyTable(); |
||||
} |
||||
|
||||
@Override |
||||
public Iterable<InfoTable> getTablesWithFilter(String filter){ |
||||
log.debug("Start getTablesWithFilter method - Custom"); |
||||
return infoTableRepository.getTablesWithFilter(filter); |
||||
} |
||||
@Override |
||||
public Iterable<InfoTable> getTablesWithFilterAndSchema(String filter, String schema){ |
||||
log.debug("Start getTablesWithFilterAndSchema method - Custom"); |
||||
return infoTableRepository.getTablesWithFilterAndSchema(filter, schema); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,62 @@ |
||||
package com.apside.assist.db.backend.service.implementation; |
||||
|
||||
import com.apside.assist.db.backend.model.LinkInfo; |
||||
import com.apside.assist.db.backend.repository.LinkInfoRepository; |
||||
import com.apside.assist.db.backend.service.LinkInfoService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
@Service |
||||
@Slf4j |
||||
public class LinkInfoServiceImpl implements LinkInfoService { |
||||
|
||||
private final LinkInfoRepository linkInfoRepository; |
||||
|
||||
public LinkInfoServiceImpl(LinkInfoRepository linkInfoRepository) { |
||||
this.linkInfoRepository = linkInfoRepository; |
||||
} |
||||
|
||||
@Override |
||||
public Optional<LinkInfo> getLinkInfo(final Long id) { |
||||
log.debug("Start getLinkInfo method - CRUD"); |
||||
return linkInfoRepository.findById(id); |
||||
} |
||||
|
||||
@Override |
||||
public Iterable<LinkInfo> getAllLinksInfos() { |
||||
log.debug("Start getAllLinksInfos method - CRUD"); |
||||
return linkInfoRepository.findAll(); |
||||
} |
||||
|
||||
@Override |
||||
public void deleteLinkInfo(final Long id) { |
||||
log.debug("Start deleteLinkInfo method - CRUD"); |
||||
linkInfoRepository.deleteById(id); |
||||
} |
||||
|
||||
@Override |
||||
public void deleteAllLinks() { |
||||
log.debug("Start deleteAllLinks method - CRUD"); |
||||
linkInfoRepository.deleteAll(); |
||||
} |
||||
|
||||
@Override |
||||
public LinkInfo addOrUpdateLink(LinkInfo linkInfo) { |
||||
log.debug("Start addOrUpdateLink method - CRUD"); |
||||
return linkInfoRepository.save(linkInfo); |
||||
} |
||||
|
||||
@Override |
||||
public Iterable<LinkInfo> addMultipleLinkInfo(Iterable<LinkInfo> listOfLinkInfo) { |
||||
log.debug("Start addMultipleLinkInfo method - CRUD"); |
||||
return linkInfoRepository.saveAll(listOfLinkInfo); |
||||
} |
||||
|
||||
@Override |
||||
public void truncateMyLink(){ |
||||
log.debug("Start truncateMyLink method - Custom"); |
||||
linkInfoRepository.truncateMyLink(); |
||||
} |
||||
} |
@ -0,0 +1,109 @@ |
||||
package com.apside.assist.db.backend.service.implementation; |
||||
|
||||
import com.apside.assist.db.backend.model.InfoColumn; |
||||
import com.apside.assist.db.backend.model.InfoTable; |
||||
import com.apside.assist.db.backend.model.LinkInfo; |
||||
import com.apside.assist.db.backend.model.json.Column; |
||||
import com.apside.assist.db.backend.model.json.DataEnum; |
||||
import com.apside.assist.db.backend.model.json.Schema; |
||||
import com.apside.assist.db.backend.service.InfoColumnService; |
||||
import com.apside.assist.db.backend.service.InfoTableService; |
||||
import com.apside.assist.db.backend.service.LinkInfoService; |
||||
import com.apside.assist.db.backend.service.ResetDataService; |
||||
import com.fasterxml.jackson.core.JsonProcessingException; |
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.InitializingBean; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.core.io.PathResource; |
||||
import org.springframework.core.io.Resource; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.nio.file.Files; |
||||
import java.nio.file.Paths; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Objects; |
||||
|
||||
@Service |
||||
@Slf4j |
||||
public class ResetDataServiceImpl implements ResetDataService, InitializingBean { |
||||
|
||||
private final InfoTableService infoTableService; |
||||
private final InfoColumnService infoColumnService; |
||||
private final LinkInfoService linkInfoService; |
||||
|
||||
@Value("${assistDb.db.json.file}") |
||||
private String fileName; |
||||
private String result; |
||||
|
||||
public ResetDataServiceImpl(InfoTableService infoTableService, InfoColumnService infoColumnService, LinkInfoService linkInfoService) { |
||||
this.infoTableService = infoTableService; |
||||
this.infoColumnService = infoColumnService; |
||||
this.linkInfoService = linkInfoService; |
||||
} |
||||
|
||||
@Override |
||||
public void afterPropertiesSet() throws Exception { |
||||
Resource resource = new PathResource("json/" + fileName); |
||||
result = new String(Files.readAllBytes(Paths.get(resource.getURI()))); |
||||
} |
||||
|
||||
@Override |
||||
public void deleteEverything(){ |
||||
infoColumnService.truncateMyColumn(); |
||||
infoTableService.truncateMyTable(); |
||||
linkInfoService.truncateMyLink(); |
||||
} |
||||
|
||||
@Override |
||||
public void insertEverything() throws JsonProcessingException { |
||||
log.debug("Start insert every data into DB"); |
||||
List<InfoColumn> listOfColumns = new ArrayList<>(); |
||||
List<InfoTable> listOfTables = new ArrayList<>(); |
||||
ObjectMapper objectMapper = new ObjectMapper(); |
||||
Schema[] jsonData = objectMapper.readValue(result, Schema[].class); |
||||
for (Schema schema: jsonData) { |
||||
for (DataEnum dat: schema.getData()) { |
||||
listOfTables.add(new InfoTable(dat.getTable(), schema.getSchema(), dat.getTable_text())); |
||||
for (Column col: dat.getColumns()) { |
||||
String descCol = col.getColumn_text(); |
||||
if(descCol == null){ |
||||
descCol = ""; |
||||
} |
||||
listOfColumns.add(new InfoColumn(col.getName(), col.getData_type(), col.getLength(), descCol)); |
||||
} |
||||
} |
||||
} |
||||
List<InfoColumn> filteredListOfColumns = listOfColumns.stream().distinct().toList(); |
||||
infoTableService.addMultipleTables(listOfTables); |
||||
infoColumnService.addMultipleColumns(filteredListOfColumns); |
||||
log.info("Insert all data into DB - success"); |
||||
} |
||||
|
||||
@Override |
||||
public void checkAndInsertLinks() throws JsonProcessingException { |
||||
log.debug("Start check data into DB and insert links between table and columns"); |
||||
List<LinkInfo> listOfLink = new ArrayList<>(); |
||||
ObjectMapper objectMapper = new ObjectMapper(); |
||||
Schema[] jsonData = objectMapper.readValue(result, Schema[].class); |
||||
for (Schema schema: jsonData) { |
||||
for (DataEnum dat: schema.getData()) { |
||||
for (Column col: dat.getColumns()) { |
||||
String descCol = col.getColumn_text(); |
||||
if(descCol == null){ |
||||
descCol = ""; |
||||
} |
||||
InfoColumn findCol = infoColumnService.getSpecCol(col.getName(), col.getData_type(), col.getLength(), descCol); |
||||
if (Objects.nonNull(findCol)) { |
||||
int idCol = Math.toIntExact(findCol.getId()); |
||||
listOfLink.add(new LinkInfo(dat.getTable(), schema.getSchema(), idCol)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
linkInfoService.addMultipleLinkInfo(listOfLink); |
||||
log.info("Check and insert links data into DB - success"); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,217 @@ |
||||
package com.apside.assist.db.backend.service.implementation; |
||||
|
||||
import com.apside.assist.db.backend.model.LinkScriptTag; |
||||
import com.apside.assist.db.backend.model.Script; |
||||
import com.apside.assist.db.backend.service.GitService; |
||||
import com.apside.assist.db.backend.service.ScriptsService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.eclipse.jgit.api.errors.GitAPIException; |
||||
import org.json.JSONArray; |
||||
import org.json.JSONObject; |
||||
import org.springframework.beans.factory.InitializingBean; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.core.io.PathResource; |
||||
import org.springframework.core.io.Resource; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileWriter; |
||||
import java.io.IOException; |
||||
import java.net.URISyntaxException; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
import java.nio.file.Paths; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Objects; |
||||
|
||||
@Service |
||||
@Slf4j |
||||
public class ScriptsServiceImpl implements ScriptsService, InitializingBean { |
||||
|
||||
private final GitService gitService; |
||||
private Path pathOfLink; |
||||
|
||||
private JSONObject dataGlobalScripts; |
||||
private JSONArray dataLinkScriptsTags; |
||||
private String tempDirectoryPath; |
||||
private File scriptDirectory; |
||||
|
||||
@Value("${assistDb.db.json.script}") |
||||
private String fileName; |
||||
|
||||
@Value("${assistDb.db.json.directory}") |
||||
private String directory; |
||||
|
||||
private static final String FILE_NAME_STRING = "filename"; |
||||
private static final String DESCRIPTION_STRING = "description"; |
||||
private static final String TAG_NAME_STRING = "tagname"; |
||||
private static final String ID_STRING = "id"; |
||||
private static final String TAGS_STRING = "tags"; |
||||
private static final String DATA_STRING = "data"; |
||||
|
||||
public ScriptsServiceImpl(GitService gitService) { |
||||
this.gitService = gitService; |
||||
} |
||||
|
||||
@Override |
||||
public void afterPropertiesSet() throws Exception { |
||||
Resource resource = new PathResource("git/" + fileName); |
||||
pathOfLink = Paths.get(resource.getURI()); |
||||
resource = new PathResource("git/" + directory); |
||||
tempDirectoryPath = resource.getURI().getPath(); |
||||
scriptDirectory = resource.getFile(); |
||||
} |
||||
|
||||
@Override |
||||
public void initialize() throws IOException { |
||||
String allScriptsContent = new String((Files.readAllBytes(pathOfLink))); |
||||
dataGlobalScripts = new JSONObject(allScriptsContent); |
||||
dataLinkScriptsTags = dataGlobalScripts.getJSONArray(DATA_STRING); |
||||
} |
||||
|
||||
@Override |
||||
public List<Script> retrieveScripts() throws IOException, GitAPIException { |
||||
log.debug("Start retrieve all scripts"); |
||||
gitService.pullFromGit(); |
||||
List<Script> listOfScripts = new ArrayList<>(); |
||||
//Creating a File object for directory
|
||||
String[] contents = scriptDirectory.list(); |
||||
if (Objects.nonNull(contents)) { |
||||
for (String content : contents) { |
||||
Path filePath = Path.of(tempDirectoryPath, content); |
||||
String allData = Files.readString(filePath); |
||||
String extension = content.substring(content.lastIndexOf(".") + 1); |
||||
Script tempScript = new Script(extension, content, allData); |
||||
listOfScripts.add(tempScript); |
||||
} |
||||
} |
||||
log.info("Get all Scripts successful : {}", listOfScripts.size()); |
||||
return listOfScripts; |
||||
} |
||||
|
||||
@Override |
||||
public List<LinkScriptTag> getAllScriptTag() throws IOException { |
||||
log.debug("Start retrieve all links scripts/tags"); |
||||
initialize(); |
||||
List<LinkScriptTag> listLinkScriptTag = new ArrayList<>(); |
||||
if (dataLinkScriptsTags.length()>0){ |
||||
for (int i = 0; i<dataLinkScriptsTags.length(); i++){ |
||||
JSONObject link = dataLinkScriptsTags.getJSONObject(i); |
||||
int linkId = link.getInt(ID_STRING); |
||||
String scriptName = link.getString(FILE_NAME_STRING); |
||||
String desc = link.getString(DESCRIPTION_STRING); |
||||
List<String> tagList = new ArrayList<>(); |
||||
JSONArray tags = link.getJSONArray(TAGS_STRING); |
||||
for (int j=0; j<tags.length(); j++){ |
||||
JSONObject unitTag = tags.getJSONObject(j); |
||||
String tagName = unitTag.getString(TAG_NAME_STRING); |
||||
tagList.add(tagName); |
||||
} |
||||
LinkScriptTag newLinkScriptTag = new LinkScriptTag(linkId, scriptName, desc, tagList); |
||||
listLinkScriptTag.add(newLinkScriptTag); |
||||
} |
||||
} |
||||
log.info("Get all links between Scripts and Tags successful"); |
||||
return listLinkScriptTag; |
||||
} |
||||
|
||||
@Override |
||||
public void deleteOneScript(final String name){ |
||||
log.debug("Start delete one script with Git"); |
||||
try { |
||||
File scriptDirectoryToDelete = new File(tempDirectoryPath, name); |
||||
Files.delete(scriptDirectoryToDelete.toPath()); |
||||
gitService.pushToGit(); |
||||
log.info("Delete one Script successful"); |
||||
} catch (Exception e){ |
||||
log.error("Error : ", e); |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void simpleDeleteScript(final String name){ |
||||
log.debug("Start delete one script without Git"); |
||||
try { |
||||
File scriptDirectoryToSimpleDelete = new File(tempDirectoryPath, name); |
||||
Files.delete(scriptDirectoryToSimpleDelete.toPath()); |
||||
log.info("Delete one Script successful"); |
||||
} catch (Exception e){ |
||||
e.printStackTrace(); |
||||
log.error("Error : ", e); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void addOneScript(final String content, final String name) throws IOException { |
||||
log.debug("Start add one scripts"); |
||||
try (FileWriter writerDataFile = new FileWriter(tempDirectoryPath + "/" + name);) { |
||||
writerDataFile.write(content); |
||||
log.info("Add one Script successful"); |
||||
} catch (IOException ioException){ |
||||
log.error("Error add one Script : ", ioException); |
||||
throw ioException; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void addOneLink(final String name, final String description, final List<String> tagList, final int linkId) throws IOException, GitAPIException, URISyntaxException { |
||||
log.debug("Start add one link between script and tags"); |
||||
initialize(); |
||||
gitService.pullFromGit(); |
||||
JSONObject newLink = new JSONObject(); |
||||
newLink.put(ID_STRING, linkId); |
||||
newLink.put(FILE_NAME_STRING, name); |
||||
newLink.put(DESCRIPTION_STRING, description); |
||||
JSONArray tagArray = new JSONArray(); |
||||
for (String s : tagList) { |
||||
JSONObject tempTag = new JSONObject(); |
||||
tempTag.put(TAG_NAME_STRING, s); |
||||
tagArray.put(tempTag); |
||||
} |
||||
newLink.put(TAGS_STRING, tagArray); |
||||
JSONArray newArr = dataLinkScriptsTags.put(newLink); |
||||
JSONObject newObj = dataGlobalScripts.put(DATA_STRING, newArr); |
||||
Files.write(pathOfLink, newObj.toString().getBytes()); |
||||
gitService.pushToGit(); |
||||
log.info("Add one link successful"); |
||||
} |
||||
|
||||
@Override |
||||
public void updateOneLink(final String name, final String description, final List<String> tagList, final int linkId) throws IOException, GitAPIException, URISyntaxException { |
||||
log.debug("Start update one link between script and tags"); |
||||
initialize(); |
||||
gitService.pullFromGit(); |
||||
JSONArray newArr = new JSONArray(); |
||||
for (int d = 0; d<dataLinkScriptsTags.length(); d++){ |
||||
JSONObject actualLink = dataLinkScriptsTags.getJSONObject(d); |
||||
int actualId = actualLink.getInt(ID_STRING); |
||||
if (!Objects.equals(linkId, actualId)){ |
||||
newArr.put(actualLink); |
||||
} else { |
||||
JSONObject newLink = new JSONObject(); |
||||
newLink.put(ID_STRING, linkId); |
||||
newLink.put(FILE_NAME_STRING, name); |
||||
newLink.put(DESCRIPTION_STRING, description); |
||||
JSONArray tagArray = new JSONArray(); |
||||
|
||||
for (String s : tagList) { |
||||
JSONObject tempTag = new JSONObject(); |
||||
tempTag.put(TAG_NAME_STRING, s); |
||||
tagArray.put(tempTag); |
||||
} |
||||
newLink.put(TAGS_STRING, tagArray); |
||||
newArr.put(newLink); |
||||
} |
||||
} |
||||
JSONObject newObj = dataGlobalScripts.put(DATA_STRING, newArr); |
||||
Files.write(pathOfLink, newObj.toString().getBytes()); |
||||
|
||||
gitService.pushToGit(); |
||||
log.info("Update one link successful"); |
||||
|
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,136 @@ |
||||
package com.apside.assist.db.backend.service.implementation; |
||||
|
||||
import com.apside.assist.db.backend.model.Tag; |
||||
import com.apside.assist.db.backend.service.GitService; |
||||
import com.apside.assist.db.backend.service.TagsService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.eclipse.jgit.api.errors.GitAPIException; |
||||
import org.json.JSONArray; |
||||
import org.json.JSONObject; |
||||
import org.springframework.beans.factory.InitializingBean; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.core.io.PathResource; |
||||
import org.springframework.core.io.Resource; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.io.IOException; |
||||
import java.net.URISyntaxException; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
import java.nio.file.Paths; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Objects; |
||||
|
||||
@Service |
||||
@Slf4j |
||||
public class TagsServiceImpl implements TagsService, InitializingBean { |
||||
|
||||
private final GitService gitService; |
||||
private Path path; |
||||
private JSONObject dataGlobal; |
||||
private JSONArray data; |
||||
|
||||
@Value("${assistDb.db.json.tags}") |
||||
private String fileName; |
||||
private static final String TAG_ID_STRING = "tagId"; |
||||
private static final String DATA_STRING = "data"; |
||||
private static final String TAG_STRING = "tag"; |
||||
private static final String DESCRIPTION_STRING = "description"; |
||||
|
||||
public TagsServiceImpl(GitService gitService) { |
||||
this.gitService = gitService; |
||||
} |
||||
|
||||
@Override |
||||
public void afterPropertiesSet() throws Exception { |
||||
Resource resource = new PathResource("git/" + fileName); |
||||
path = Paths.get(resource.getURI()); |
||||
} |
||||
|
||||
@Override |
||||
public void initialize() throws IOException { |
||||
String jsonContent = new String(Files.readAllBytes(path)); |
||||
dataGlobal = new JSONObject(jsonContent); |
||||
data = dataGlobal.getJSONArray(DATA_STRING); |
||||
} |
||||
|
||||
@Override |
||||
public List<Tag> getAllTags() throws IOException, GitAPIException { |
||||
log.debug("Start get all tags from json"); |
||||
gitService.pullFromGit(); |
||||
initialize(); |
||||
List<Tag> listOfTag = new ArrayList<>(); |
||||
for (int i=0; i<data.length(); i++){ |
||||
JSONObject tag = data.getJSONObject(i); |
||||
int tagId = tag.getInt(TAG_ID_STRING); |
||||
String tagName = tag.getString(TAG_STRING); |
||||
String tagDescription = tag.getString(DESCRIPTION_STRING); |
||||
Tag tempTag = new Tag(tagId, tagName, tagDescription); |
||||
listOfTag.add(tempTag); |
||||
} |
||||
log.info("Get all tags from json successful"); |
||||
return listOfTag; |
||||
} |
||||
|
||||
@Override |
||||
public void deleteTag(final String deleteNameTag) throws IOException, GitAPIException, URISyntaxException { |
||||
log.debug("Start delete one tag in json"); |
||||
initialize(); |
||||
JSONArray newArr = new JSONArray(); |
||||
for (int i=0; i<data.length(); i++) { |
||||
JSONObject tag = data.getJSONObject(i); |
||||
String tagName = tag.getString(TAG_STRING); |
||||
if(!Objects.equals(tagName, deleteNameTag)){ |
||||
newArr.put(tag); |
||||
} |
||||
} |
||||
JSONObject newObj = dataGlobal.put(DATA_STRING, newArr); |
||||
Files.write(path, newObj.toString().getBytes()); |
||||
gitService.pushToGit(); |
||||
log.info("Delete one tag in json file successful"); |
||||
} |
||||
|
||||
@Override |
||||
public void addTag(Tag tag) throws IOException, GitAPIException, URISyntaxException { |
||||
log.debug("Start add one tag in json"); |
||||
initialize(); |
||||
gitService.pullFromGit(); |
||||
JSONObject newTag = new JSONObject(); |
||||
newTag.put(TAG_ID_STRING, tag.getTagId()); |
||||
newTag.put(TAG_STRING, tag.getNameTag()); |
||||
newTag.put(DESCRIPTION_STRING, tag.getDescriptionTag()); |
||||
JSONArray newArr = data.put(newTag); |
||||
JSONObject newObj = dataGlobal.put(DATA_STRING, newArr); |
||||
Files.write(path, newObj.toString().getBytes()); |
||||
gitService.pushToGit(); |
||||
log.info("Delete one tag in json successful"); |
||||
} |
||||
|
||||
@Override |
||||
public void updateTag(final String prevTag, Tag modTag) throws IOException, GitAPIException, URISyntaxException { |
||||
log.debug("Start update one tag in json"); |
||||
initialize(); |
||||
gitService.pullFromGit(); |
||||
JSONArray newArr = new JSONArray(); |
||||
for (int i=0; i<data.length(); i++) { |
||||
JSONObject tag = data.getJSONObject(i); |
||||
String tagName = tag.getString(TAG_STRING); |
||||
if(!Objects.equals(tagName, prevTag)){ |
||||
newArr.put(tag); |
||||
} else { |
||||
JSONObject newTag = new JSONObject(); |
||||
newTag.put(TAG_ID_STRING, modTag.getTagId()); |
||||
newTag.put(TAG_STRING, modTag.getNameTag()); |
||||
newTag.put(DESCRIPTION_STRING, modTag.getDescriptionTag()); |
||||
newArr.put(newTag); |
||||
} |
||||
} |
||||
JSONObject newObj = dataGlobal.put(DATA_STRING, newArr); |
||||
Files.write(path, newObj.toString().getBytes()); |
||||
gitService.pushToGit(); |
||||
log.info("Update one tag in json successful"); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,19 @@ |
||||
|
||||
spring.application.name=AssistDBBackend |
||||
#spring.datasource.url=jdbc:mysql://178.18.0.2:3306/prudencetest?rewriteBatchedStatements=true&cachePrepStmts=true&useServerPrepStmts=true |
||||
spring.datasource.url=jdbc:mysql://178.18.0.2:3306/prudencetest |
||||
spring.datasource.username=root |
||||
spring.datasource.password=Pompom.21 |
||||
server.port=9001 |
||||
|
||||
assistDb.get.username = ***** |
||||
assistDb.get.password = ***** |
||||
assistDb.get.uri = https://gitea.ci.apside-top.fr/Prudence_Creole/AssistDB_AdditionalFiles.git |
||||
|
||||
assistDb.db.json.file=assistDbData.json |
||||
assistDb.db.json.script=scripts.json |
||||
assistDb.db.json.directory=Scripts |
||||
assistDb.db.json.tags=tags.json |
||||
|
||||
logging.level.org.springframework.boot.web.embedded.tomcat=INFO |
||||
logging.level.org.springframework=error |
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -0,0 +1,15 @@ |
||||
# Log4J configuration |
||||
log4j.rootLogger=DEBUG,CONSOLE,FILE |
||||
|
||||
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender |
||||
log4j.appender.CONSOLE.Target=System.out |
||||
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout |
||||
log4j.appender.CONSOLE.layout.ConversionPattern=[%d] %t %c %L %-5p - %m%n |
||||
|
||||
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender |
||||
log4j.appender.FILE.File=/apps/logs/appname.log |
||||
log4j.appender.FILE.DatePattern='.'yyyy-MM-dd |
||||
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout |
||||
log4j.appender.FILE.layout.ConversionPattern=[%d] %t %c %L %-5p - %m%n |
||||
|
||||
log4j.logger.org.springframework=WARN |
@ -0,0 +1,33 @@ |
||||
package com.apside.assist.db.backend; |
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; |
||||
|
||||
import static org.hamcrest.CoreMatchers.is; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
||||
import org.springframework.context.annotation.ComponentScan; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.context.annotation.PropertySource; |
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; |
||||
import org.springframework.test.web.servlet.MockMvc; |
||||
|
||||
@Configuration |
||||
@PropertySource({"classpath:application-test.properties"}) |
||||
@ComponentScan(basePackages = { |
||||
"com.apside.assistDbBackend.service", |
||||
"com.apside.assistDbBackend.model", |
||||
}) |
||||
@SpringBootTest |
||||
public class AssistDBBackendTest { |
||||
|
||||
@Test |
||||
void contextLoads(){ |
||||
|
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,135 @@ |
||||
package com.apside.assist.db.backend.repository; |
||||
|
||||
import com.apside.assist.db.backend.model.InfoColumn; |
||||
import com.apside.assist.db.backend.model.LinkInfo; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||
|
||||
@DataJpaTest |
||||
class InfoColumnRepositoryTest { |
||||
|
||||
@Autowired |
||||
private InfoColumnRepository infoColumnRepository; |
||||
|
||||
@Autowired |
||||
private LinkInfoRepository linkInfoRepository; |
||||
|
||||
@Test |
||||
void testGetSelectedColumns() { |
||||
// Arrange
|
||||
InfoColumn infoColumn1 = new InfoColumn(1L, "Column1", "DataType1", 10, "Column Text 1"); |
||||
InfoColumn infoColumn2 = new InfoColumn(2L, "Column2", "DataType2", 20, "Column Text 2"); |
||||
// Save the InfoColumns to the database
|
||||
infoColumnRepository.save(infoColumn1); |
||||
infoColumnRepository.save(infoColumn2); |
||||
List<LinkInfo> linkInfos = new ArrayList<>(); |
||||
linkInfos.add(new LinkInfo(1L, "table1", "schema1", 1)); |
||||
linkInfos.add(new LinkInfo(2L, "table2", "schema1", 2)); |
||||
linkInfoRepository.saveAll(linkInfos); |
||||
|
||||
// Act
|
||||
Iterable<InfoColumn> selectedColumns = infoColumnRepository.getSelectedColumns("table1", "schema1"); |
||||
|
||||
// Assert
|
||||
List<InfoColumn> columns = new ArrayList<>(); |
||||
selectedColumns.forEach(columns::add); |
||||
assertEquals(1, columns.size()); |
||||
assertEquals("Column1", columns.get(0).getNameColumn()); |
||||
// Perform assertions on the selected columns
|
||||
// ...
|
||||
} |
||||
|
||||
@Test |
||||
void testGetColumnsForJoin() { |
||||
// Arrange
|
||||
InfoColumn infoColumn1 = new InfoColumn(1L, "Column1", "DataType1", 10, "Column Text 1"); |
||||
InfoColumn infoColumn2 = new InfoColumn(2L, "Column2", "DataType2", 20, "Column Text 2"); |
||||
// Save the InfoColumns to the database
|
||||
infoColumnRepository.save(infoColumn1); |
||||
infoColumnRepository.save(infoColumn2); |
||||
List<LinkInfo> linkInfos = new ArrayList<>(); |
||||
linkInfos.add(new LinkInfo(1L, "table1", "schema1", 1)); |
||||
linkInfos.add(new LinkInfo(2L, "table2", "schema2", 1)); |
||||
linkInfoRepository.saveAll(linkInfos); |
||||
|
||||
// Act
|
||||
Iterable<InfoColumn> columnsForJoin = infoColumnRepository.getColumnsForJoin("table1", "table2", "schema1", "schema2"); |
||||
|
||||
// Assert
|
||||
List<InfoColumn> columns = new ArrayList<>(); |
||||
columnsForJoin.forEach(columns::add); |
||||
assertEquals(1, columns.size()); |
||||
// Perform assertions on the columns for join
|
||||
// ...
|
||||
} |
||||
|
||||
@Test |
||||
void testGetColumnsForJoinTwo() { |
||||
// Arrange
|
||||
InfoColumn infoColumn1 = new InfoColumn(1L, "Column1", "DataType1", 10, "Column Text 1"); |
||||
InfoColumn infoColumn2 = new InfoColumn(2L, "Column2", "DataType2", 20, "Column Text 2"); |
||||
// Save the InfoColumns to the database
|
||||
infoColumnRepository.save(infoColumn1); |
||||
infoColumnRepository.save(infoColumn2); |
||||
List<LinkInfo> linkInfos = new ArrayList<>(); |
||||
linkInfos.add(new LinkInfo(1L, "table1", "schema1", 1)); |
||||
linkInfos.add(new LinkInfo(2L, "table2", "schema2", 1)); |
||||
linkInfoRepository.saveAll(linkInfos); |
||||
|
||||
// Act
|
||||
List<String> tables = new ArrayList<>(); |
||||
tables.add("table1"); |
||||
tables.add("table2"); |
||||
List<String> schemas = new ArrayList<>(); |
||||
schemas.add("schema1"); |
||||
schemas.add("schema2"); |
||||
Iterable<InfoColumn> columnsForJoinTwo = infoColumnRepository.getColumnsForJoinTwo(tables, schemas); |
||||
|
||||
// Assert
|
||||
List<InfoColumn> columns = new ArrayList<>(); |
||||
columnsForJoinTwo.forEach(columns::add); |
||||
assertEquals(1, columns.size()); |
||||
|
||||
} |
||||
|
||||
@Test |
||||
void testGetSpecColumn() { |
||||
// Arrange
|
||||
InfoColumn infoColumn = new InfoColumn(1L, "Column1", "DataType1", 10, "Column Text 1"); |
||||
// Save the InfoColumn to the database
|
||||
infoColumnRepository.save(infoColumn); |
||||
|
||||
// Act
|
||||
InfoColumn specColumn = infoColumnRepository.getSpecColumn("Column1", "DataType1", 10, "Column Text 1"); |
||||
|
||||
// Assert
|
||||
assertEquals(infoColumn.getId(), specColumn.getId()); |
||||
|
||||
} |
||||
|
||||
@Test |
||||
void testTruncateMyColumn() { |
||||
// Arrange
|
||||
InfoColumn infoColumn1 = new InfoColumn(1L, "Column1", "DataType1", 10, "Column Text 1"); |
||||
InfoColumn infoColumn2 = new InfoColumn(2L, "Column2", "DataType2", 20, "Column Text 2"); |
||||
// Save the InfoColumns to the database
|
||||
infoColumnRepository.save(infoColumn1); |
||||
infoColumnRepository.save(infoColumn2); |
||||
|
||||
// Act
|
||||
infoColumnRepository.truncateMyColumn(); |
||||
|
||||
// Assert
|
||||
Iterable<InfoColumn> columns = infoColumnRepository.findAll(); |
||||
List<InfoColumn> columnList = new ArrayList<>(); |
||||
columns.forEach(columnList::add); |
||||
assertEquals(0, columnList.size()); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,97 @@ |
||||
package com.apside.assist.db.backend.repository; |
||||
|
||||
import com.apside.assist.db.backend.model.InfoTable; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||
|
||||
@DataJpaTest |
||||
class InfoTableRepositoryTest { |
||||
|
||||
@Autowired |
||||
private InfoTableRepository infoTableRepository; |
||||
|
||||
@Test |
||||
void testGetAllSchemas() { |
||||
// Arrange
|
||||
List<InfoTable> infoTables = new ArrayList<>(); |
||||
infoTables.add(new InfoTable(1L, "table1", "schema1", "table1text")); |
||||
infoTables.add(new InfoTable(2L, "table2", "schema2", "table2text")); |
||||
infoTables.add(new InfoTable(3L, "table3", "schema1", "table3text")); |
||||
|
||||
infoTableRepository.saveAll(infoTables); |
||||
|
||||
// Act
|
||||
Iterable<String> schemas = infoTableRepository.getAllSchemas(); |
||||
|
||||
// Assert
|
||||
List<String> schemaList = new ArrayList<>(); |
||||
schemas.forEach(schemaList::add); |
||||
assertEquals(2, schemaList.size()); |
||||
assertEquals("schema1", schemaList.get(0)); |
||||
assertEquals("schema2", schemaList.get(1)); |
||||
} |
||||
|
||||
@Test |
||||
void testGetTablesBySchemaName() { |
||||
// Arrange
|
||||
List<InfoTable> infoTables = new ArrayList<>(); |
||||
infoTables.add(new InfoTable(1L, "table1", "schema1", "table1text")); |
||||
infoTables.add(new InfoTable(2L, "table2", "schema1", "table2text")); |
||||
infoTables.add(new InfoTable(3L, "table3", "schema2", "table3text")); |
||||
infoTableRepository.saveAll(infoTables); |
||||
|
||||
// Act
|
||||
Iterable<InfoTable> tables = infoTableRepository.getTablesBySchemaName("schema1"); |
||||
|
||||
// Assert
|
||||
List<InfoTable> tableList = new ArrayList<>(); |
||||
tables.forEach(tableList::add); |
||||
assertEquals(2, tableList.size()); |
||||
assertEquals("table1", tableList.get(0).getNameTable()); |
||||
assertEquals("table2", tableList.get(1).getNameTable()); |
||||
} |
||||
|
||||
@Test |
||||
void testGetSchemaByTableName() { |
||||
// Arrange
|
||||
List<InfoTable> infoTables = new ArrayList<>(); |
||||
infoTables.add(new InfoTable(1L, "table1", "schema1", "table1text")); |
||||
infoTables.add(new InfoTable(2L, "table2", "schema1", "table2text")); |
||||
infoTables.add(new InfoTable(3L, "table3", "schema2", "table3text")); |
||||
infoTableRepository.saveAll(infoTables); |
||||
|
||||
// Act
|
||||
Iterable<InfoTable> schemas = infoTableRepository.getSchemaByTableName("table2"); |
||||
|
||||
// Assert
|
||||
List<InfoTable> schemaList = new ArrayList<>(); |
||||
schemas.forEach(schemaList::add); |
||||
assertEquals(1, schemaList.size()); |
||||
assertEquals("schema1", schemaList.get(0).getNameSchema()); |
||||
} |
||||
|
||||
@Test |
||||
void testTruncateMyTable() { |
||||
// Arrange
|
||||
List<InfoTable> infoTables = new ArrayList<>(); |
||||
infoTables.add(new InfoTable(1L, "table1", "schema1", "table1text")); |
||||
infoTables.add(new InfoTable(2L, "table2", "schema1", "table2text")); |
||||
infoTables.add(new InfoTable(3L, "table3", "schema2", "table3text")); |
||||
infoTableRepository.saveAll(infoTables); |
||||
|
||||
// Act
|
||||
infoTableRepository.truncateMyTable(); |
||||
|
||||
// Assert
|
||||
Iterable<InfoTable> tables = infoTableRepository.findAll(); |
||||
List<InfoTable> tableList = new ArrayList<>(); |
||||
tables.forEach(tableList::add); |
||||
assertEquals(0, tableList.size()); |
||||
} |
||||
} |
@ -0,0 +1,37 @@ |
||||
package com.apside.assist.db.backend.repository; |
||||
|
||||
import com.apside.assist.db.backend.model.InfoTable; |
||||
import com.apside.assist.db.backend.model.LinkInfo; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import static org.junit.jupiter.api.Assertions.*; |
||||
|
||||
@DataJpaTest |
||||
class LinkInfoRepositoryTest { |
||||
@Autowired |
||||
private LinkInfoRepository linkInfoRepository; |
||||
|
||||
|
||||
@Test |
||||
void truncateMyLink() { |
||||
List<LinkInfo> linkInfos = new ArrayList<>(); |
||||
linkInfos.add(new LinkInfo(1L, "table1", "schema1", 1)); |
||||
linkInfos.add(new LinkInfo(2L, "table2", "schema1", 1)); |
||||
linkInfos.add(new LinkInfo(3L, "table3", "schema2", 2)); |
||||
linkInfoRepository.saveAll(linkInfos); |
||||
|
||||
// Act
|
||||
linkInfoRepository.truncateMyLink(); |
||||
|
||||
// Assert
|
||||
Iterable<LinkInfo> links = linkInfoRepository.findAll(); |
||||
List<InfoTable> tableList = new ArrayList<>(); |
||||
links.forEach(linkInfos::add); |
||||
assertEquals(0, tableList.size()); |
||||
} |
||||
} |
@ -0,0 +1,127 @@ |
||||
//package com.apside.assistDbBackend.service;
|
||||
//
|
||||
//import org.eclipse.jgit.api.*;
|
||||
//import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
//import org.eclipse.jgit.api.errors.InvalidRemoteException;
|
||||
//import org.eclipse.jgit.api.errors.JGitInternalException;
|
||||
//import org.eclipse.jgit.api.errors.RefNotFoundException;
|
||||
//import org.eclipse.jgit.lib.Repository;
|
||||
//import org.eclipse.jgit.transport.PushResult;
|
||||
//import org.eclipse.jgit.transport.URIish;
|
||||
//import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
|
||||
//import org.junit.jupiter.api.AfterEach;
|
||||
//import org.junit.jupiter.api.BeforeEach;
|
||||
//import org.junit.jupiter.api.DisplayName;
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//import org.junit.runner.RunWith;
|
||||
//import org.mockito.InjectMocks;
|
||||
//import org.mockito.Mock;
|
||||
//import org.mockito.Mockito;
|
||||
//import org.mockito.MockitoAnnotations;
|
||||
//import org.mockito.junit.MockitoJUnitRunner;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//
|
||||
//import java.io.File;
|
||||
//import java.io.IOException;
|
||||
//import java.net.URISyntaxException;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import static org.junit.Assert.assertTrue;
|
||||
//import static org.mockito.Mockito.*;
|
||||
//
|
||||
//@RunWith(MockitoJUnitRunner.class)
|
||||
//class GitServiceTest {
|
||||
//
|
||||
// @InjectMocks
|
||||
// private GitService gitService;
|
||||
//
|
||||
// @Mock
|
||||
// private Git git;
|
||||
//
|
||||
// @Mock
|
||||
// private RemoteAddCommand remoteAddCommand;
|
||||
//
|
||||
// private PushResult pushResult;
|
||||
// private PushCommand pushCommand;
|
||||
//
|
||||
// @BeforeEach
|
||||
// void setUp() throws IOException {
|
||||
// MockitoAnnotations.openMocks(this);
|
||||
// gitService = new GitService();
|
||||
// //Runtime.getRuntime().exec("cmd.exe /c ");
|
||||
// String pathForExec = new File(System.getProperty("user.dir")).getParent();
|
||||
//
|
||||
//
|
||||
// ProcessBuilder processBuilder = new ProcessBuilder();
|
||||
// processBuilder.directory(new File(pathForExec));
|
||||
// processBuilder.command("cmd.exe", "/c", "mkdir test_repo & mkdir repo & cd " + pathForExec + "/test_repo" + " & git --bare init & cd " + pathForExec + "/repo" + " & git clone " + pathForExec + "/test_repo" + " test & cd " + pathForExec + "/repo/test & mkdir change");
|
||||
//
|
||||
// processBuilder.start();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @AfterEach
|
||||
// void closeUp() throws IOException {
|
||||
//
|
||||
// String pathForExec = new File(System.getProperty("user.dir")).getParent();
|
||||
//
|
||||
// ProcessBuilder processBuilder = new ProcessBuilder();
|
||||
// processBuilder.directory(new File(pathForExec));
|
||||
// processBuilder.command("cmd.exe", "/c", "rmdir test_repo & rmdir repo");
|
||||
//
|
||||
// processBuilder.start();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @DisplayName("Test push to git success")
|
||||
// @Test
|
||||
// void pushToGitSuccess() {
|
||||
// // TODO
|
||||
// }
|
||||
//
|
||||
//// @DisplayName("Test push to git fail cause error with remote add command")
|
||||
//// @Test
|
||||
//// void pushToGitFailCauseGitAPIExceptionWithRemoteAddCommand() throws Exception {
|
||||
//// when(git.remoteAdd()).thenReturn(remoteAddCommand);
|
||||
//// when(remoteAddCommand.setName("origin")).thenReturn(remoteAddCommand);
|
||||
//// when(remoteAddCommand.setUri(new URIish("https://gitea.ci.apside-top.fr/Prudence_Creole/AssistDB_AdditionalFiles.git"))).thenReturn(remoteAddCommand);
|
||||
////
|
||||
//// when(git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider("fhibert@apside.fr", "e54612b6d1d73eef4f0a49c88b0e35ccf02d45eb")).call()).thenThrow(JGitInternalException.class);
|
||||
////
|
||||
//// gitService.pushToGit();
|
||||
//// }
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// void pushToGit_shouldPushChangesToRemoteRepository() throws GitAPIException, IOException, URISyntaxException {
|
||||
// // Arrange
|
||||
//
|
||||
// String pathPush = new File(System.getProperty("user.dir")).getParent() + "\\test_repo";
|
||||
// // Arrange
|
||||
// when(git.remoteAdd()).thenReturn(remoteAddCommand);
|
||||
// when(remoteAddCommand.setName("origin")).thenReturn(remoteAddCommand);
|
||||
// remoteAddCommand.setUri(new URIish(pathPush));
|
||||
// when(remoteAddCommand.setUri(Mockito.any(URIish.class))).thenReturn(remoteAddCommand);
|
||||
// gitService.setAccesToken("");
|
||||
//
|
||||
// gitService.pushToGit();
|
||||
//
|
||||
// // Assert
|
||||
// verify(git, times(1)).add();
|
||||
// verify(git, times(1)).commit();
|
||||
// verify(git, times(1)).push();
|
||||
// }
|
||||
////
|
||||
//// @Test
|
||||
//// void pullFromGit_shouldPullChangesFromRemoteRepository() throws GitAPIException, IOException {
|
||||
//// // Arrange
|
||||
//// doNothing().when(git).pull();
|
||||
////
|
||||
//// // Act
|
||||
//// gitService.pullFromGit();
|
||||
////
|
||||
//// // Assert
|
||||
//// verify(git, times(1)).pull();
|
||||
//// }
|
||||
//}
|
@ -0,0 +1,228 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.service.implementation.InfoColumnServiceImpl; |
||||
import com.apside.assist.db.backend.repository.InfoColumnRepository; |
||||
import com.apside.assist.db.backend.model.InfoColumn; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
import org.mockito.InjectMocks; |
||||
import org.mockito.Mock; |
||||
import org.mockito.junit.jupiter.MockitoExtension; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
|
||||
import static org.junit.jupiter.api.Assertions.*; |
||||
import static org.assertj.core.api.Assertions.*; |
||||
import static org.mockito.Mockito.*; |
||||
|
||||
@ExtendWith(MockitoExtension.class) |
||||
class InfoColumnServiceImplTest { |
||||
@Mock |
||||
private InfoColumnRepository infoColumnRepository; |
||||
@InjectMocks |
||||
private InfoColumnServiceImpl underTest; |
||||
|
||||
|
||||
@Test |
||||
void testGetColumn() { |
||||
InfoColumn infoColumn = new InfoColumn( |
||||
1L, |
||||
"test", |
||||
"test", |
||||
10, |
||||
"test" |
||||
); |
||||
Long id = 1L; |
||||
when(infoColumnRepository.findById(id)).thenReturn(Optional.of(infoColumn)); |
||||
Optional<InfoColumn> result = underTest.getColumn(id); |
||||
assertTrue(result.isPresent()); |
||||
assertEquals(infoColumn, result.get()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetColumnNotFound() { |
||||
// Given
|
||||
Long id = 1L; |
||||
when(infoColumnRepository.findById(id)).thenReturn(Optional.empty()); |
||||
|
||||
// When
|
||||
Optional<InfoColumn> result = underTest.getColumn(id); |
||||
|
||||
// Then
|
||||
assertFalse(result.isPresent()); |
||||
} |
||||
|
||||
@Test |
||||
void testGetAllColumns() { |
||||
List<InfoColumn> res = new ArrayList<>(); |
||||
res.add(new InfoColumn()); |
||||
when(infoColumnRepository.findAll()).thenReturn(res); |
||||
Iterable<InfoColumn> expected = underTest.getAllColumns(); |
||||
|
||||
assertEquals(expected, res); |
||||
} |
||||
|
||||
@Test |
||||
void testGetSelectedColumns() { |
||||
// Given
|
||||
List<InfoColumn> infoColumns = Arrays.asList( |
||||
new InfoColumn(1L, |
||||
"test", |
||||
"test", |
||||
10, |
||||
"test"), |
||||
new InfoColumn(2L, |
||||
"test2", |
||||
"test2", |
||||
11, |
||||
"test2") |
||||
); |
||||
String table = "myTable"; |
||||
String schema = "mySchema"; |
||||
when(infoColumnRepository.getSelectedColumns(table, schema)).thenReturn(infoColumns); |
||||
|
||||
// When
|
||||
Iterable<InfoColumn> result = underTest.getSelectedColumns(table, schema); |
||||
|
||||
// Then
|
||||
assertNotNull(result); |
||||
assertThat(result).hasSize(2); |
||||
assertThat(result).contains(infoColumns.get(0), infoColumns.get(1)); |
||||
} |
||||
|
||||
@Test |
||||
void testGetColumnsForJoin() { |
||||
// Given
|
||||
List<InfoColumn> infoColumns = Arrays.asList( |
||||
new InfoColumn(1L, |
||||
"test", |
||||
"test", |
||||
10, |
||||
"test"), |
||||
new InfoColumn(2L, |
||||
"test2", |
||||
"test2", |
||||
11, |
||||
"test2") |
||||
); |
||||
String firstTable = "firstTable"; |
||||
String secondTable = "secondTable"; |
||||
String firstSchema = "firstSchema"; |
||||
String secondSchema = "secondSchema"; |
||||
when(infoColumnRepository.getColumnsForJoin(firstTable, secondTable, firstSchema, secondSchema)).thenReturn(infoColumns); |
||||
|
||||
// When
|
||||
Iterable<InfoColumn> result = underTest.getColumnsForJoin(firstTable, secondTable, firstSchema, secondSchema); |
||||
|
||||
// Then
|
||||
assertNotNull(result); |
||||
assertThat(result).hasSize(2); |
||||
assertThat(result).contains(infoColumns.get(0), infoColumns.get(1)); |
||||
} |
||||
|
||||
@Test |
||||
void testGetColumnsForJoinTwo() { |
||||
// Given
|
||||
List<String> tables = Arrays.asList("table1", "table2"); |
||||
List<String> schemas = Arrays.asList("schema1", "schema2"); |
||||
List<InfoColumn> infoColumns = Arrays.asList( |
||||
new InfoColumn(1L, |
||||
"test", |
||||
"test", |
||||
10, |
||||
"test"), |
||||
new InfoColumn(2L, |
||||
"test2", |
||||
"test2", |
||||
11, |
||||
"test2"), |
||||
new InfoColumn(3L, |
||||
"test3", |
||||
"test3", |
||||
12, |
||||
"test3") |
||||
); |
||||
when(infoColumnRepository.getColumnsForJoinTwo(tables, schemas)).thenReturn(infoColumns); |
||||
|
||||
// When
|
||||
Iterable<InfoColumn> result = underTest.getColumnsForJoinTwo(tables, schemas); |
||||
|
||||
// Then
|
||||
assertNotNull(result); |
||||
assertThat(result).hasSize(3); |
||||
assertThat(result).contains(infoColumns.get(0), infoColumns.get(1), infoColumns.get(2)); |
||||
} |
||||
|
||||
@Test |
||||
void testDeleteColumn() { |
||||
// Given
|
||||
Long id = 1L; |
||||
|
||||
// When
|
||||
underTest.deleteColumn(id); |
||||
|
||||
// Then
|
||||
verify(infoColumnRepository, times(1)).deleteById(id); |
||||
} |
||||
|
||||
@Test |
||||
void testDeleteAllColumn() { |
||||
// When
|
||||
underTest.deleteAllColumn(); |
||||
|
||||
// Then
|
||||
verify(infoColumnRepository, times(1)).deleteAll(); |
||||
} |
||||
|
||||
@Test |
||||
void testAddOrUpdateColumn() { |
||||
// Given
|
||||
InfoColumn infoColumn = new InfoColumn( |
||||
1L, |
||||
"test", |
||||
"test", |
||||
10, |
||||
"test"); |
||||
|
||||
// When
|
||||
when(infoColumnRepository.save(infoColumn)).thenReturn(infoColumn); |
||||
InfoColumn savedInfoColumn = underTest.addOrUpdateColumn(infoColumn); |
||||
|
||||
// Then
|
||||
verify(infoColumnRepository, times(1)).save(infoColumn); |
||||
assertThat(savedInfoColumn.getNameColumn()).isEqualTo("test"); |
||||
} |
||||
|
||||
@Test |
||||
void testGetSpecCol() { |
||||
String nameCol = "columnName"; |
||||
String dataType = "dataType"; |
||||
int lengthCol = 100; |
||||
String columnText = "sometext"; |
||||
InfoColumn expectedInfoColumn = new InfoColumn(); |
||||
expectedInfoColumn.setNameColumn(nameCol); |
||||
expectedInfoColumn.setDataType(dataType); |
||||
expectedInfoColumn.setLengthColumn(lengthCol); |
||||
expectedInfoColumn.setColumnText(columnText); |
||||
|
||||
// When
|
||||
when(infoColumnRepository.getSpecColumn(nameCol, dataType, lengthCol, columnText)).thenReturn(expectedInfoColumn); |
||||
InfoColumn actualInfoColumn = underTest.getSpecCol(nameCol, dataType, lengthCol, columnText); |
||||
|
||||
// Then
|
||||
verify(infoColumnRepository, times(1)).getSpecColumn(nameCol, dataType, lengthCol, columnText); |
||||
assertThat(actualInfoColumn).isEqualTo(expectedInfoColumn); |
||||
} |
||||
|
||||
@Test |
||||
void testTruncateMyColumn() { |
||||
// When
|
||||
underTest.truncateMyColumn(); |
||||
|
||||
// Then
|
||||
verify(infoColumnRepository, times(1)).truncateMyColumn(); |
||||
} |
||||
} |
@ -0,0 +1,157 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.service.implementation.InfoTableServiceImpl; |
||||
import com.apside.assist.db.backend.model.InfoTable; |
||||
import com.apside.assist.db.backend.repository.InfoTableRepository; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
import org.mockito.InjectMocks; |
||||
import org.mockito.Mock; |
||||
import org.mockito.junit.jupiter.MockitoExtension; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.junit.jupiter.api.Assertions.*; |
||||
import static org.mockito.Mockito.*; |
||||
|
||||
@ExtendWith(MockitoExtension.class) |
||||
class InfoTableServiceImplTest { |
||||
|
||||
@Mock |
||||
private InfoTableRepository infoTableRepository; |
||||
|
||||
@InjectMocks |
||||
private InfoTableServiceImpl infoTableServiceImpl; |
||||
|
||||
@Test |
||||
void testGetTable() { |
||||
InfoTable infoTable = new InfoTable( |
||||
1L, |
||||
"nameTable", |
||||
"nameSchema", |
||||
"tableText" |
||||
); |
||||
Long id = 1L; |
||||
when(infoTableRepository.findById(id)).thenReturn(Optional.of(infoTable)); |
||||
Optional<InfoTable> result = infoTableServiceImpl.getTable(id); |
||||
assertTrue(result.isPresent()); |
||||
assertEquals(infoTable, result.get()); |
||||
} |
||||
|
||||
@Test |
||||
void testGetAllTables() { |
||||
List<InfoTable> res = new ArrayList<>(); |
||||
res.add(new InfoTable()); |
||||
when(infoTableRepository.findAll()).thenReturn(res); |
||||
Iterable<InfoTable> expected = infoTableServiceImpl.getAllTables(); |
||||
|
||||
assertEquals(expected, res); |
||||
} |
||||
|
||||
@Test |
||||
void testGetTablesBySchemaName() { |
||||
String schemaName = "nameSchema"; |
||||
List<InfoTable> infoTables = Arrays.asList( |
||||
new InfoTable( |
||||
1L, |
||||
"nameTableOne", |
||||
"nameSchema", |
||||
"tableTextOne"), |
||||
new InfoTable( |
||||
2L, |
||||
"nameTableTwo", |
||||
"nameSchema", |
||||
"tableTextTwo") |
||||
); |
||||
when(infoTableRepository.getTablesBySchemaName(schemaName)).thenReturn(infoTables); |
||||
|
||||
// When
|
||||
Iterable<InfoTable> result = infoTableServiceImpl.getTablesBySchemaName(schemaName); |
||||
|
||||
// Then
|
||||
assertNotNull(result); |
||||
assertThat(result).hasSize(2); |
||||
assertThat(result).contains(infoTables.get(0), infoTables.get(1)); |
||||
|
||||
} |
||||
|
||||
@Test |
||||
void testGetSchemaByTableName() { |
||||
String tableName = "nameTable"; |
||||
List<InfoTable> infoTables = Arrays.asList( |
||||
new InfoTable( |
||||
1L, |
||||
"nameTable", |
||||
"nameSchemaOne", |
||||
"tableTextOne"), |
||||
new InfoTable( |
||||
2L, |
||||
"nameTable", |
||||
"nameSchemaTwo", |
||||
"tableTextTwo") |
||||
); |
||||
when(infoTableRepository.getSchemaByTableName(tableName)).thenReturn(infoTables); |
||||
|
||||
// When
|
||||
Iterable<InfoTable> result = infoTableServiceImpl.getSchemaByTableName(tableName); |
||||
|
||||
// Then
|
||||
assertNotNull(result); |
||||
assertThat(result).hasSize(2); |
||||
assertThat(result).contains(infoTables.get(0), infoTables.get(1)); |
||||
|
||||
} |
||||
|
||||
@Test |
||||
void testGetAllSchemas() { |
||||
List<String> schemasList = Arrays.asList(new String("shcemaOne"), new String("schemaTwo")); |
||||
when(infoTableRepository.getAllSchemas()).thenReturn(schemasList); |
||||
Iterable<String> expectedAllSchemas = infoTableServiceImpl.getAllSchemas(); |
||||
assertEquals(expectedAllSchemas, schemasList); |
||||
} |
||||
|
||||
@Test |
||||
void testDeleteTable() { |
||||
Long id = 1L; |
||||
|
||||
infoTableServiceImpl.deleteTable(id); |
||||
|
||||
verify(infoTableRepository, times(1)).deleteById(id); |
||||
} |
||||
|
||||
@Test |
||||
void testDeleteAllTable() { |
||||
infoTableServiceImpl.deleteAllTable(); |
||||
|
||||
verify(infoTableRepository, times(1)).deleteAll(); |
||||
} |
||||
|
||||
@Test |
||||
void testAddOrUpdateTable() { |
||||
InfoTable infoTable = new InfoTable( |
||||
1L, |
||||
"nameTable", |
||||
"nameSchema", |
||||
"tableText"); |
||||
|
||||
// When
|
||||
when(infoTableRepository.save(infoTable)).thenReturn(infoTable); |
||||
InfoTable savedInfoTable = infoTableServiceImpl.addOrUpdateTable(infoTable); |
||||
|
||||
// Then
|
||||
verify(infoTableRepository, times(1)).save(infoTable); |
||||
assertThat(savedInfoTable.getNameTable()).isEqualTo("nameTable"); |
||||
|
||||
} |
||||
|
||||
@Test |
||||
void testTruncateMyTable() { |
||||
infoTableServiceImpl.truncateMyTable(); |
||||
|
||||
verify(infoTableRepository, times(1)).truncateMyTable(); |
||||
} |
||||
} |
@ -0,0 +1,94 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.service.implementation.LinkInfoServiceImpl; |
||||
import com.apside.assist.db.backend.repository.LinkInfoRepository; |
||||
import com.apside.assist.db.backend.model.LinkInfo; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
import org.mockito.InjectMocks; |
||||
import org.mockito.Mock; |
||||
import org.mockito.junit.jupiter.MockitoExtension; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.junit.jupiter.api.Assertions.*; |
||||
import static org.mockito.Mockito.*; |
||||
|
||||
@ExtendWith(MockitoExtension.class) |
||||
class LinkInfoServiceImplTest { |
||||
|
||||
@Mock |
||||
private LinkInfoRepository linkInfoRepository; |
||||
@InjectMocks |
||||
private LinkInfoServiceImpl linkInfoServiceImpl; |
||||
|
||||
@Test |
||||
void testGetLinkInfo() { |
||||
LinkInfo linkInfo = new LinkInfo( |
||||
1L, |
||||
"nameTable", |
||||
"nameSchema", |
||||
1 |
||||
); |
||||
Long id = 1L; |
||||
when(linkInfoRepository.findById(id)).thenReturn(Optional.of(linkInfo)); |
||||
Optional<LinkInfo> result = linkInfoServiceImpl.getLinkInfo(id); |
||||
assertTrue(result.isPresent()); |
||||
assertEquals(linkInfo, result.get()); |
||||
} |
||||
|
||||
@Test |
||||
void testGetAllLinksInfos() { |
||||
List<LinkInfo> res = new ArrayList<>(); |
||||
res.add(new LinkInfo()); |
||||
when(linkInfoRepository.findAll()).thenReturn(res); |
||||
Iterable<LinkInfo> expected = linkInfoServiceImpl.getAllLinksInfos(); |
||||
|
||||
assertEquals(expected, res); |
||||
} |
||||
|
||||
@Test |
||||
void testDeleteLinkInfo() { |
||||
Long id = 1L; |
||||
|
||||
linkInfoServiceImpl.deleteLinkInfo(id); |
||||
|
||||
verify(linkInfoRepository, times(1)).deleteById(id); |
||||
} |
||||
|
||||
@Test |
||||
void testDeleteAllLinks() { |
||||
linkInfoServiceImpl.deleteAllLinks(); |
||||
|
||||
verify(linkInfoRepository, times(1)).deleteAll(); |
||||
} |
||||
|
||||
@Test |
||||
void testAddOrUpdateLink() { |
||||
LinkInfo linkInfo = new LinkInfo( |
||||
1L, |
||||
"nameTable", |
||||
"nameSchema", |
||||
1 |
||||
); |
||||
|
||||
// When
|
||||
when(linkInfoRepository.save(linkInfo)).thenReturn(linkInfo); |
||||
LinkInfo savedLinkInfo = linkInfoServiceImpl.addOrUpdateLink(linkInfo); |
||||
|
||||
// Then
|
||||
verify(linkInfoRepository, times(1)).save(linkInfo); |
||||
assertThat(savedLinkInfo.getNameTable()).isEqualTo("nameTable"); |
||||
|
||||
} |
||||
|
||||
@Test |
||||
void testTruncateMyLink() { |
||||
linkInfoServiceImpl.truncateMyLink(); |
||||
|
||||
verify(linkInfoRepository, times(1)).truncateMyLink(); |
||||
} |
||||
} |
@ -0,0 +1,88 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.model.InfoTable; |
||||
import com.apside.assist.db.backend.model.InfoColumn; |
||||
import com.apside.assist.db.backend.model.LinkInfo; |
||||
import com.apside.assist.db.backend.service.implementation.InfoColumnServiceImpl; |
||||
import com.apside.assist.db.backend.service.implementation.InfoTableServiceImpl; |
||||
import com.apside.assist.db.backend.service.implementation.LinkInfoServiceImpl; |
||||
import com.apside.assist.db.backend.service.implementation.ResetDataServiceImpl; |
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
import org.mockito.InjectMocks; |
||||
import org.mockito.Mock; |
||||
import org.mockito.junit.jupiter.MockitoExtension; |
||||
import org.springframework.test.context.TestPropertySource; |
||||
import org.springframework.test.util.ReflectionTestUtils; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
import static org.mockito.Mockito.*; |
||||
|
||||
@TestPropertySource(locations = {"classpath:application-test.properties"}) |
||||
@ExtendWith(MockitoExtension.class) |
||||
class ResetDataServiceImplTest { |
||||
|
||||
@Mock |
||||
private InfoTableServiceImpl infoTableServiceImpl; |
||||
|
||||
@Mock |
||||
private InfoColumnServiceImpl infoColumnServiceImpl; |
||||
|
||||
@Mock |
||||
private LinkInfoServiceImpl linkInfoServiceImpl; |
||||
|
||||
@InjectMocks |
||||
private ResetDataServiceImpl resetDataServiceImpl; |
||||
|
||||
@BeforeEach |
||||
public void setUp() throws Exception { |
||||
ReflectionTestUtils.setField(resetDataServiceImpl, "pathForData", "src/test/resources/testDb.json"); |
||||
resetDataServiceImpl.afterPropertiesSet(); |
||||
} |
||||
|
||||
@Test |
||||
void deleteEverything_shouldTruncateTables() { |
||||
// Arrange
|
||||
doNothing().when(infoColumnServiceImpl).truncateMyColumn(); |
||||
doNothing().when(infoTableServiceImpl).truncateMyTable(); |
||||
doNothing().when(linkInfoServiceImpl).truncateMyLink(); |
||||
// Act
|
||||
resetDataServiceImpl.deleteEverything(); |
||||
|
||||
// Assert
|
||||
verify(infoColumnServiceImpl, times(1)).truncateMyColumn(); |
||||
verify(infoTableServiceImpl, times(1)).truncateMyTable(); |
||||
verify(linkInfoServiceImpl, times(1)).truncateMyLink(); |
||||
} |
||||
|
||||
@Test |
||||
void insertEverything_shouldInsertData() throws IOException { |
||||
// Arrange
|
||||
InfoTable infoTable = new InfoTable(1L, "test", "test", "test"); |
||||
InfoColumn infoColumn = new InfoColumn(1L, "test", "test", 1, "test"); |
||||
when(infoTableServiceImpl.addOrUpdateTable(any(InfoTable.class))).thenReturn(infoTable); |
||||
when(infoColumnServiceImpl.addOrUpdateColumn(any(InfoColumn.class))).thenReturn(infoColumn); |
||||
|
||||
// Act
|
||||
resetDataServiceImpl.insertEverything(); |
||||
|
||||
// Assert
|
||||
verify(infoTableServiceImpl, times(1)).addOrUpdateTable(any(InfoTable.class)); |
||||
verify(infoColumnServiceImpl, times(1)).addOrUpdateColumn(any(InfoColumn.class)); |
||||
} |
||||
|
||||
@Test |
||||
void checkAndInsertLinks_shouldInsertLinks() throws IOException { |
||||
// Arrange
|
||||
when(infoColumnServiceImpl.getSpecCol(anyString(), anyString(), anyInt(), anyString())) |
||||
.thenReturn(new InfoColumn(1L, "col1", "type1", 10, "coltext1")); // Mocking infoColumnService.getSpecCol()
|
||||
|
||||
// Act
|
||||
resetDataServiceImpl.checkAndInsertLinks(); |
||||
|
||||
// Assert
|
||||
verify(linkInfoServiceImpl, times(1)).addOrUpdateLink(any(LinkInfo.class)); |
||||
} |
||||
} |
@ -0,0 +1,254 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.service.implementation.GitServiceImpl; |
||||
import com.apside.assist.db.backend.service.implementation.ScriptsServiceImpl; |
||||
import com.apside.assist.db.backend.model.LinkScriptTag; |
||||
import com.apside.assist.db.backend.model.Script; |
||||
import org.eclipse.jgit.api.errors.GitAPIException; |
||||
import org.json.JSONArray; |
||||
import org.json.JSONObject; |
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
import org.mockito.InjectMocks; |
||||
import org.mockito.Mock; |
||||
import org.mockito.junit.jupiter.MockitoExtension; |
||||
import org.springframework.test.context.TestPropertySource; |
||||
import org.springframework.test.util.ReflectionTestUtils; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.net.URISyntaxException; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
import java.nio.file.Paths; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
|
||||
import static org.junit.jupiter.api.Assertions.*; |
||||
import static org.mockito.Mockito.*; |
||||
|
||||
@TestPropertySource(locations = {"classpath:application-test.properties"}) |
||||
@ExtendWith(MockitoExtension.class) |
||||
class ScriptsServiceImplTest { |
||||
@Mock |
||||
private GitServiceImpl gitServiceImpl; |
||||
|
||||
@InjectMocks |
||||
private ScriptsServiceImpl scriptsServiceImpl; |
||||
|
||||
private Path tempDirectoryPathJsonTest; |
||||
private String jsonContent; |
||||
private JSONObject dataGlobal; |
||||
private JSONArray data; |
||||
private String tempDirectoryPathTest; |
||||
private File scriptDirectoryTest; |
||||
|
||||
@Mock |
||||
private JSONObject jsonObject; |
||||
|
||||
@BeforeEach |
||||
void setUp() throws Exception { |
||||
ReflectionTestUtils.setField(scriptsServiceImpl, "PATH_FOR_SCRIPT_JSON", "/AssistDB_V2_Back/src/test/resources/scripts.json"); |
||||
ReflectionTestUtils.setField(scriptsServiceImpl, "PATH_TO_SCRIPT_DIR", "/AssistDB_V2_Back/src/test/resources/scriptsTest"); |
||||
|
||||
scriptsServiceImpl.afterPropertiesSet(); |
||||
tempDirectoryPathJsonTest = Paths.get("src/test/resources/scripts.json"); |
||||
|
||||
jsonContent = "{\"data\":[{\"filename\":\"test.txt\", \"description\":\"Description test\", \"id\":1, \"tags\":[{\"tagname\":\"TXT\"}]}, {\"filename\":\"test2.txt\", \"description\":\"Description test2\", \"id\":2, \"tags\":[{\"tagname\":\"JOIN\"}]}]}"; |
||||
Files.write(tempDirectoryPathJsonTest, jsonContent.getBytes()); |
||||
dataGlobal = new JSONObject(jsonContent); |
||||
data = dataGlobal.getJSONArray("data"); |
||||
|
||||
|
||||
tempDirectoryPathTest = new File("src/test/resources/scriptsTest").toString(); |
||||
scriptDirectoryTest = new File(tempDirectoryPathTest); |
||||
|
||||
|
||||
} |
||||
|
||||
@Test |
||||
void retrieveScripts() throws GitAPIException, IOException { |
||||
// mock git service
|
||||
doNothing().when(gitServiceImpl).pullFromGit(); |
||||
|
||||
// create temp directory for test
|
||||
String scriptContent1 = "Script 1 content"; |
||||
String scriptContent2 = "Script 2 content"; |
||||
Path filePath1 = Path.of(tempDirectoryPathTest + "/script1.sql"); |
||||
Path filePath2 = Path.of(tempDirectoryPathTest + "/script2.sql"); |
||||
Files.createFile(filePath1); |
||||
Files.createFile(filePath2); |
||||
Files.writeString(filePath1, scriptContent1); |
||||
Files.writeString(filePath2, scriptContent2); |
||||
|
||||
// Act
|
||||
List<Script> result = scriptsServiceImpl.retrieveScripts(); |
||||
|
||||
verify(gitServiceImpl, times(1)).pullFromGit(); |
||||
assertEquals(2, result.size()); |
||||
assertEquals("sql", result.get(0).getExtension()); |
||||
assertEquals("script1.sql", result.get(0).getName()); |
||||
assertEquals(scriptContent1, result.get(0).getData()); |
||||
assertEquals("sql", result.get(1).getExtension()); |
||||
assertEquals("script2.sql", result.get(1).getName()); |
||||
assertEquals(scriptContent2, result.get(1).getData()); |
||||
|
||||
// Clean up
|
||||
Files.deleteIfExists(filePath1); |
||||
Files.deleteIfExists(filePath2); |
||||
} |
||||
|
||||
@Test |
||||
void getAllScriptTag() throws IOException { |
||||
// Arrange
|
||||
List<LinkScriptTag> expectedTags = new ArrayList<>(); |
||||
List<String> tagList1 = Arrays.asList("TXT"); |
||||
List<String> tagList2 = Arrays.asList("JOIN"); |
||||
LinkScriptTag tag1 = new LinkScriptTag(1, "test.txt", "Description test", tagList1); |
||||
LinkScriptTag tag2 = new LinkScriptTag(2, "test2.txt", "Description test2", tagList2); |
||||
expectedTags.add(tag1); |
||||
expectedTags.add(tag2); |
||||
|
||||
// Act
|
||||
List<LinkScriptTag> result = scriptsServiceImpl.getAllScriptTag(); |
||||
|
||||
// Assert
|
||||
assertEquals(expectedTags, result); |
||||
} |
||||
|
||||
@Test |
||||
void deleteOneScript() throws IOException, GitAPIException, URISyntaxException { |
||||
// Arrange
|
||||
String scriptName = "testDel.txt"; |
||||
|
||||
File scriptFile = new File(scriptDirectoryTest, scriptName); |
||||
if (!scriptDirectoryTest.exists()) { |
||||
scriptDirectoryTest.mkdirs(); |
||||
} |
||||
if (!scriptFile.exists()) { |
||||
scriptFile.createNewFile(); |
||||
} |
||||
doNothing().when(gitServiceImpl).pushToGit(); |
||||
doNothing().when(gitServiceImpl).pullFromGit(); |
||||
|
||||
// Act
|
||||
scriptsServiceImpl.deleteOneScript(scriptName); |
||||
|
||||
// Assert
|
||||
assertFalse(scriptFile.exists()); |
||||
verify(gitServiceImpl, times(1)).pushToGit(); |
||||
verify(gitServiceImpl, times(1)).pullFromGit(); |
||||
} |
||||
|
||||
@Test |
||||
void simpleDeleteScript() throws IOException { |
||||
// Arrange
|
||||
String scriptName = "testDel.txt"; |
||||
File scriptFile = new File(scriptDirectoryTest, scriptName); |
||||
if (!scriptDirectoryTest.exists()) { |
||||
scriptDirectoryTest.mkdirs(); |
||||
} |
||||
if (!scriptFile.exists()) { |
||||
scriptFile.createNewFile(); |
||||
} |
||||
|
||||
// Act
|
||||
scriptsServiceImpl.simpleDeleteScript(scriptName); |
||||
|
||||
// Assert
|
||||
assertFalse(scriptFile.exists()); |
||||
} |
||||
|
||||
@Test |
||||
void addOneScript() throws IOException { |
||||
// Arrange
|
||||
String content = "Script content"; |
||||
String name = "new_script.sql"; |
||||
File scriptFile = new File(scriptDirectoryTest, name); |
||||
if (!scriptDirectoryTest.exists()) { |
||||
scriptDirectoryTest.mkdirs(); |
||||
} |
||||
if (scriptFile.exists()) { |
||||
scriptFile.delete(); |
||||
} |
||||
|
||||
// Act
|
||||
scriptsServiceImpl.addOneScript(content, name); |
||||
|
||||
// Assert
|
||||
assertTrue(scriptFile.exists()); |
||||
String fileContent = Files.readString(scriptFile.toPath()); |
||||
assertEquals(content, fileContent); |
||||
|
||||
// Clean up
|
||||
scriptFile.delete(); |
||||
} |
||||
|
||||
@Test |
||||
void addOneLink() throws GitAPIException, IOException, URISyntaxException { |
||||
String name = "new_script.sql"; |
||||
String description = "New script"; |
||||
List<String> tagList = Arrays.asList("TAG1", "TAG2"); |
||||
int linkId = 3; |
||||
doNothing().when(gitServiceImpl).pullFromGit(); |
||||
doNothing().when(gitServiceImpl).pushToGit(); |
||||
|
||||
scriptsServiceImpl.addOneLink(name, description, tagList, linkId); |
||||
|
||||
// Assert
|
||||
String allScriptsContentTest = new String((Files.readAllBytes(tempDirectoryPathJsonTest))); |
||||
JSONObject dataGlobalScriptsTest = new JSONObject(allScriptsContentTest); |
||||
JSONArray updatedDataLinkScriptsTags = dataGlobalScriptsTest.getJSONArray("data"); |
||||
assertEquals(3, updatedDataLinkScriptsTags.length()); |
||||
JSONObject newLink = updatedDataLinkScriptsTags.getJSONObject(2); |
||||
|
||||
assertEquals(linkId, newLink.getInt("id")); |
||||
assertEquals(name, newLink.getString("filename")); |
||||
assertEquals(description, newLink.getString("description")); |
||||
JSONArray newTags = newLink.getJSONArray("tags"); |
||||
assertEquals(2, newTags.length()); |
||||
JSONObject tagObj1 = newTags.getJSONObject(0); |
||||
assertEquals("TAG1", tagObj1.getString("tagname")); |
||||
JSONObject tagObj2 = newTags.getJSONObject(1); |
||||
assertEquals("TAG2", tagObj2.getString("tagname")); |
||||
verify(gitServiceImpl, times(1)).pullFromGit(); |
||||
verify(gitServiceImpl, times(1)).pushToGit(); |
||||
} |
||||
|
||||
@Test |
||||
void updateOneLink() throws GitAPIException, IOException, URISyntaxException { |
||||
// Arrange
|
||||
String name = "updated_script.sql"; |
||||
String description = "Updated script"; |
||||
List<String> tagList = Arrays.asList("TAG1", "TAG3"); |
||||
int linkId = 2; |
||||
|
||||
//scriptsService.setDataLinkScriptsTags(dataLinkScriptsTags);
|
||||
doNothing().when(gitServiceImpl).pullFromGit(); |
||||
doNothing().when(gitServiceImpl).pushToGit(); |
||||
// Act
|
||||
scriptsServiceImpl.updateOneLink(name, description, tagList, linkId); |
||||
|
||||
// Assert
|
||||
String allScriptsContentTest = new String((Files.readAllBytes(tempDirectoryPathJsonTest))); |
||||
JSONObject dataGlobalScriptsTest = new JSONObject(allScriptsContentTest); |
||||
JSONArray updatedDataLinkScriptsTags = dataGlobalScriptsTest.getJSONArray("data"); |
||||
assertEquals(2, updatedDataLinkScriptsTags.length()); |
||||
JSONObject updatedLink = updatedDataLinkScriptsTags.getJSONObject(1); |
||||
System.out.println(updatedDataLinkScriptsTags); |
||||
|
||||
assertEquals(linkId, updatedLink.getInt("id")); |
||||
assertEquals(name, updatedLink.getString("filename")); |
||||
assertEquals(description, updatedLink.getString("description")); |
||||
JSONArray updatedTags = updatedLink.getJSONArray("tags"); |
||||
assertEquals(2, updatedTags.length()); |
||||
JSONObject tagObj1 = updatedTags.getJSONObject(0); |
||||
assertEquals("TAG1", tagObj1.getString("tagname")); |
||||
JSONObject tagObj2 = updatedTags.getJSONObject(1); |
||||
assertEquals("TAG3", tagObj2.getString("tagname")); |
||||
verify(gitServiceImpl, times(1)).pullFromGit(); |
||||
verify(gitServiceImpl, times(1)).pushToGit(); |
||||
} |
||||
} |
@ -0,0 +1,151 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.service.implementation.GitServiceImpl; |
||||
import com.apside.assist.db.backend.service.implementation.TagsServiceImpl; |
||||
import com.apside.assist.db.backend.model.Tag; |
||||
import org.eclipse.jgit.api.errors.GitAPIException; |
||||
import org.json.JSONArray; |
||||
import org.json.JSONObject; |
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Order; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
import org.mockito.InjectMocks; |
||||
import org.mockito.Mock; |
||||
import org.mockito.junit.jupiter.MockitoExtension; |
||||
import org.springframework.test.context.TestPropertySource; |
||||
import org.springframework.test.util.ReflectionTestUtils; |
||||
|
||||
import java.io.IOException; |
||||
import java.net.URISyntaxException; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
import java.nio.file.Paths; |
||||
import java.util.List; |
||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||
import static org.mockito.Mockito.*; |
||||
|
||||
@TestPropertySource(locations = {"classpath:application-test.properties"}) |
||||
@ExtendWith(MockitoExtension.class) |
||||
class TagsServiceImplTest { |
||||
|
||||
@Mock |
||||
private GitServiceImpl gitServiceImpl; |
||||
@InjectMocks |
||||
private TagsServiceImpl tagsServiceImpl; |
||||
private String jsonContent; |
||||
private JSONObject dataGlobal; |
||||
private JSONArray data; |
||||
private Path tempDirectory; |
||||
@Mock |
||||
private JSONObject jsonObject; |
||||
|
||||
@BeforeEach |
||||
void setUp() throws Exception { |
||||
ReflectionTestUtils.setField(tagsServiceImpl, "PATH_FOR_TAG_JSON", "/AssistDB_V2_Back/src/test/resources/tagtest.json"); |
||||
tagsServiceImpl.afterPropertiesSet(); |
||||
jsonContent = "{\"data\":[{\"tagId\":1, \"description\":\"Description 1\", \"tag\":\"Tag1\"},{\"tagId\":2, \"description\":\"Description 2\", \"tag\":\"Tag2\"}]}"; |
||||
tempDirectory = Paths.get("src/test/resources/tagtest.json"); |
||||
|
||||
Files.write(tempDirectory, jsonContent.getBytes()); |
||||
dataGlobal = new JSONObject(jsonContent); |
||||
data = dataGlobal.getJSONArray("data"); |
||||
} |
||||
|
||||
@Test |
||||
@Order(1) |
||||
void getAllTags_shouldReturnListOfTags() throws IOException, GitAPIException { |
||||
// Arrange
|
||||
doNothing().when(gitServiceImpl).pullFromGit(); |
||||
|
||||
// Act
|
||||
List<Tag> result = tagsServiceImpl.getAllTags(); |
||||
|
||||
// Assert
|
||||
verify(gitServiceImpl, times(1)).pullFromGit(); |
||||
assertEquals(2, result.size()); |
||||
assertEquals(1, result.get(0).getTagId()); |
||||
assertEquals("Tag1", result.get(0).getNameTag()); |
||||
assertEquals("Description 1", result.get(0).getDescriptionTag()); |
||||
assertEquals(2, result.get(1).getTagId()); |
||||
assertEquals("Tag2", result.get(1).getNameTag()); |
||||
assertEquals("Description 2", result.get(1).getDescriptionTag()); |
||||
} |
||||
|
||||
@Test |
||||
@Order(2) |
||||
void deleteTag_shouldDeleteTag() throws IOException, GitAPIException, URISyntaxException { |
||||
// Arrange
|
||||
doNothing().when(gitServiceImpl).pullFromGit(); |
||||
doNothing().when(gitServiceImpl).pushToGit(); |
||||
|
||||
// Act
|
||||
tagsServiceImpl.deleteTag("Tag1"); |
||||
|
||||
// Assert
|
||||
verify(gitServiceImpl, times(1)).pullFromGit(); |
||||
verify(gitServiceImpl, times(1)).pushToGit(); |
||||
|
||||
String updatedJsonContent = new String(Files.readAllBytes(tempDirectory)); |
||||
JSONObject updatedDataGlobal = new JSONObject(updatedJsonContent); |
||||
JSONArray updatedData = updatedDataGlobal.getJSONArray("data"); |
||||
|
||||
assertEquals(1, updatedData.length()); |
||||
JSONObject tag = updatedData.getJSONObject(0); |
||||
assertEquals(2, tag.getInt("tagId")); |
||||
assertEquals("Tag2", tag.getString("tag")); |
||||
assertEquals("Description 2", tag.getString("description")); |
||||
} |
||||
|
||||
@Test |
||||
void addTag_shouldAddTag() throws IOException, GitAPIException, URISyntaxException { |
||||
// Arrange
|
||||
doNothing().when(gitServiceImpl).pullFromGit(); |
||||
doNothing().when(gitServiceImpl).pushToGit(); |
||||
|
||||
Tag newTag = new Tag(3, "Tag3", "Description 3"); |
||||
|
||||
// Act
|
||||
tagsServiceImpl.addTag(newTag); |
||||
|
||||
// Assert
|
||||
verify(gitServiceImpl, times(2)).pullFromGit(); |
||||
verify(gitServiceImpl, times(1)).pushToGit(); |
||||
|
||||
String updatedJsonContent = new String(Files.readAllBytes(tempDirectory)); |
||||
JSONObject updatedDataGlobal = new JSONObject(updatedJsonContent); |
||||
JSONArray updatedData = updatedDataGlobal.getJSONArray("data"); |
||||
|
||||
assertEquals(3, updatedData.length()); |
||||
JSONObject tag = updatedData.getJSONObject(2); |
||||
assertEquals(3, tag.getInt("tagId")); |
||||
assertEquals("Tag3", tag.getString("tag")); |
||||
assertEquals("Description 3", tag.getString("description")); |
||||
} |
||||
|
||||
@Test |
||||
void updateTag_shouldUpdateTag() throws IOException, GitAPIException, URISyntaxException { |
||||
// Arrange
|
||||
doNothing().when(gitServiceImpl).pullFromGit(); |
||||
doNothing().when(gitServiceImpl).pushToGit(); |
||||
|
||||
Tag modifiedTag = new Tag(2, "ModifiedTag", "ModifiedDescription"); |
||||
|
||||
// Act
|
||||
tagsServiceImpl.updateTag("Tag2", modifiedTag); |
||||
|
||||
// Assert
|
||||
verify(gitServiceImpl, times(2)).pullFromGit(); |
||||
verify(gitServiceImpl, times(1)).pushToGit(); |
||||
|
||||
String updatedJsonContent = new String(Files.readAllBytes(tempDirectory)); |
||||
JSONObject updatedDataGlobal = new JSONObject(updatedJsonContent); |
||||
JSONArray updatedData = updatedDataGlobal.getJSONArray("data"); |
||||
|
||||
assertEquals(2, updatedData.length()); |
||||
JSONObject tag = updatedData.getJSONObject(1); |
||||
assertEquals(2, tag.getInt("tagId")); |
||||
assertEquals("ModifiedTag", tag.getString("tag")); |
||||
assertEquals("ModifiedDescription", tag.getString("description")); |
||||
} |
||||
} |
@ -0,0 +1,14 @@ |
||||
spring.datasource.url=jdbc:h2://mem:DB;DB_CLOSE_DELAY=-1 |
||||
spring.datasource.username=sa |
||||
spring.datasource.password=sa |
||||
spring.datasource.driver-class-name=org.h2.Driver |
||||
spring.jpa.hibernate.ddl-auto=create-drop |
||||
spring.jpa.show-sql=true |
||||
|
||||
USERNAME_GIT = fhibert@apside.fr |
||||
ACCESS_TOKEN_GIT = e54612b6d1d73eef4f0a49c88b0e35ccf02d45eb |
||||
|
||||
PATH_FOR_DATA = src/test/resources/testDb.json |
||||
PATH_FOR_SCRIPT_JSON = /AssistDB_V2_Back/src/test/resources/scripts.json |
||||
PATH_TO_SCRIPT_DIR = /AssistDB_V2_Back/src/test/resources/scriptsTest |
||||
PATH_FOR_TAG_JSON = /AssistDB_V2_Back/src/test/resources/tagtest.json |
@ -0,0 +1,27 @@ |
||||
DROP TABLE IF EXISTS `informations_column`; |
||||
CREATE TABLE `informations_column` ( |
||||
`id` int NOT NULL AUTO_INCREMENT, |
||||
`name_column` varchar(100) DEFAULT NULL, |
||||
`data_type` varchar(100) DEFAULT NULL, |
||||
`length_column` int DEFAULT NULL, |
||||
`column_text` varchar(255) DEFAULT NULL, |
||||
PRIMARY KEY (`id`) |
||||
) |
||||
|
||||
DROP TABLE IF EXISTS `informations_table`; |
||||
CREATE TABLE `informations_table` ( |
||||
`id` int NOT NULL AUTO_INCREMENT, |
||||
`name_table` varchar(100) DEFAULT NULL, |
||||
`name_schema` varchar(100) DEFAULT NULL, |
||||
`table_text` varchar(255) DEFAULT NULL, |
||||
PRIMARY KEY (`id`) |
||||
) |
||||
|
||||
DROP TABLE IF EXISTS `link_informations`; |
||||
CREATE TABLE `link_informations` ( |
||||
`id` int NOT NULL AUTO_INCREMENT, |
||||
`name_table` varchar(100) DEFAULT NULL, |
||||
`name_schema` varchar(100) DEFAULT NULL, |
||||
`column_id` int DEFAULT NULL, |
||||
PRIMARY KEY (`id`) |
||||
) |
@ -0,0 +1 @@ |
||||
{"data":[{"filename":"test.txt","description":"Description test","id":1,"tags":[{"tagname":"TXT"}]},{"filename":"updated_script.sql","description":"Updated script","id":2,"tags":[{"tagname":"TAG1"},{"tagname":"TAG3"}]}]} |
@ -0,0 +1 @@ |
||||
{"data":[{"tagId":2,"description":"Description 2","tag":"Tag2"}]} |
@ -0,0 +1,18 @@ |
||||
[ |
||||
{ |
||||
"schema": "schema1", |
||||
"data": [ |
||||
{ |
||||
"columns": [ |
||||
{ |
||||
"name": "col1", |
||||
"data_type": "type1", |
||||
"length": 10, |
||||
"column_text": "coltext1" |
||||
}], |
||||
"table_text": "testtable1", |
||||
"table": "table1" |
||||
} |
||||
] |
||||
} |
||||
] |
Loading…
Reference in new issue