diff options
32 files changed, 783 insertions, 1281 deletions
diff --git a/snmpmapper/.gitignore b/snmpmapper/.gitignore index 63bdaca..82eca33 100644 --- a/snmpmapper/.gitignore +++ b/snmpmapper/.gitignore @@ -1,4 +1,4 @@ -target/ +/target/ !.mvn/wrapper/maven-wrapper.jar ### STS ### @@ -8,6 +8,7 @@ target/ .project .settings .springBeans +.sts4-cache ### IntelliJ IDEA ### .idea @@ -16,13 +17,9 @@ target/ *.ipr ### NetBeans ### -nbproject/private/ -build/ -nbbuild/ -dist/ -nbdist/ -.nb-gradle/ -# Package Files # -*.jar -.mvn/* -.settings/*
\ No newline at end of file +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/
\ No newline at end of file diff --git a/snmpmapper/.mvn/wrapper/maven-wrapper.jar b/snmpmapper/.mvn/wrapper/maven-wrapper.jar Binary files differnew file mode 100644 index 0000000..9cc84ea --- /dev/null +++ b/snmpmapper/.mvn/wrapper/maven-wrapper.jar diff --git a/snmpmapper/.mvn/wrapper/maven-wrapper.properties b/snmpmapper/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..b573bb5 --- /dev/null +++ b/snmpmapper/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip diff --git a/snmpmapper/Dockerfile b/snmpmapper/Dockerfile new file mode 100644 index 0000000..9483baf --- /dev/null +++ b/snmpmapper/Dockerfile @@ -0,0 +1,20 @@ +FROM ubuntu:16.04 + +WORKDIR /opt/app/SnmpMapper + +ENV HOME /opt/app/SnmpMapper + +ENV JAVA_HOME /usr + +RUN apt-get update && apt-get install -y \ + curl \ + vim \ + openjdk-8-jdk + + +COPY snmpmapper.jar /opt/snmpmapper.jar + +RUN bash -c 'touch /opt/snmpmapper.jar' + +ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/opt/snmpmapper.jar"] + diff --git a/snmpmapper/README.md b/snmpmapper/README.md deleted file mode 100644 index 7ca23d9..0000000 --- a/snmpmapper/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# DCAE SNMP Mapper - -DCAE SNMP mapper is a micro-service to upload the vendor specific mapper file into the database - - -### Build Docker image - -The following Maven command will build the mapper JAR, build the Docker image to the local machine registry and then push the same image to the specified remote registry. - -``` -mvn clean package docker:build -DpushImageTag -``` - -The image will be tagged with the project version found in the `pom.xml`. - -### Run via Docker - -Execute this to run. - - -``` -docker run -p 8081:8888 <image_name> - -``` - - ### Access - <host>:<expose port> -
\ No newline at end of file diff --git a/snmpmapper/build.gradle b/snmpmapper/build.gradle deleted file mode 100644 index 00c0e39..0000000 --- a/snmpmapper/build.gradle +++ /dev/null @@ -1,32 +0,0 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.RELEASE") - } -} - -apply plugin: 'java' -apply plugin: 'eclipse' -apply plugin: 'org.springframework.boot' -apply plugin: 'io.spring.dependency-management' - -jar { - baseName = 'gs-uploading-files' - version = '0.1.0' -} - -repositories { - mavenCentral() -} - -sourceCompatibility = 1.8 -targetCompatibility = 1.8 - -dependencies { - compile("org.springframework.boot:spring-boot-starter-web") - compile("org.springframework.boot:spring-boot-starter-thymeleaf") - testCompile("org.springframework.boot:spring-boot-starter-test") -} - diff --git a/snmpmapper/gradle/wrapper/gradle-wrapper.properties b/snmpmapper/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 7b87588..0000000 --- a/snmpmapper/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Thu Mar 01 09:05:27 CST 2018 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip diff --git a/snmpmapper/gradlew b/snmpmapper/gradlew deleted file mode 100644 index 27309d9..0000000 --- a/snmpmapper/gradlew +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/env bash - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -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 -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -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 - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/snmpmapper/gradlew.bat b/snmpmapper/gradlew.bat deleted file mode 100644 index 832fdb6..0000000 --- a/snmpmapper/gradlew.bat +++ /dev/null @@ -1,90 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/snmpmapper/mvnw b/snmpmapper/mvnw new file mode 100644 index 0000000..5bf251c --- /dev/null +++ b/snmpmapper/mvnw @@ -0,0 +1,225 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/snmpmapper/mvnw.cmd b/snmpmapper/mvnw.cmd new file mode 100644 index 0000000..019bd74 --- /dev/null +++ b/snmpmapper/mvnw.cmd @@ -0,0 +1,143 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/snmpmapper/pom.xml b/snmpmapper/pom.xml index b06853a..4304a90 100644 --- a/snmpmapper/pom.xml +++ b/snmpmapper/pom.xml @@ -1,52 +1,22 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- -* ============LICENSE_START======================================================= -* ONAP : DCAEGEN2/services/mapper -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= - --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <!-- <groupId>org.springframework</groupId> + <groupId>com.onap.dcae.upload</groupId> <artifactId>snmpmapper</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> - --> + <name>snmpmapper</name> - <description>snmpmapper demo</description> + <description>saves mapping file to potsgresql database</description> - <!-- <parent> + <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> - <version>2.0.0.RELEASE</version> - <relativePath /> lookup parent from repository - </parent> --> - <groupId>org.onap.dcaegen2.services.mapper.vesadapter</groupId> - <artifactId>snmpmapper</artifactId> - <version>0.0.1</version> - - <parent> - <groupId>org.onap.dcaegen2.services.mapper</groupId> - <artifactId>mapper</artifactId> - <version>0.0.1-SNAPSHOT</version> - </parent> - - + <version>2.0.3.RELEASE</version> + <relativePath/> <!-- lookup parent from repository --> + </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> @@ -57,33 +27,53 @@ <dependencies> <dependency> <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - <version>2.0.0.RELEASE</version> - + <artifactId>spring-boot-starter-thymeleaf</artifactId> + <version>2.0.3.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-thymeleaf</artifactId> - <version>2.0.0.RELEASE</version> + <artifactId>spring-boot-starter-web</artifactId> + <version>2.0.3.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> - <version>2.0.0.RELEASE</version> + <version>2.0.3.RELEASE</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-configuration-processor</artifactId> - <version>2.0.0.RELEASE</version> - <optional>true</optional> + <artifactId>spring-boot-starter-data-jpa</artifactId> + <version>2.0.3.RELEASE</version> </dependency> <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - <version>24.0-jre</version> + <groupId>org.postgresql</groupId> + <artifactId>postgresql</artifactId> + <scope>runtime</scope> </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>4.3.11.RELEASE</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>3.0-alpha-1</version> + </dependency> + <dependency> + <groupId>javax.servlet.jsp</groupId> + <artifactId>jsp-api</artifactId> + <version>2.1</version> + </dependency> + <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload --> +<dependency> + <groupId>commons-fileupload</groupId> + <artifactId>commons-fileupload</artifactId> + <version>1.3.3</version> +</dependency> + </dependencies> <build> @@ -91,78 +81,10 @@ <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> - <version>2.0.0.RELEASE</version> - <executions> - <execution> - <goals> - <goal>repackage</goal> - </goals> - <configuration> - <mainClass>org.onap.dcae.mapper.SnmpmapperApplication</mainClass> - </configuration> - </execution> - </executions> </plugin> - <plugin> - <groupId>com.spotify</groupId> - <artifactId>docker-maven-plugin</artifactId> - <version>${docker.maven.version}</version> - <configuration> - <skipDockerBuild>false</skipDockerBuild> - <imageName>${onap.nexus.dockerregistry.daily}/onap/${project.groupId}.${project.artifactId}</imageName> - <baseImage>openjdk:8-jre</baseImage> - <entryPoint>["java", "-jar", "/opt/${project.build.finalName}.jar", "server"]</entryPoint> - <resources> - <resource> - <targetPath>/opt</targetPath> - <directory>${project.build.directory}</directory> - <include>${project.build.finalName}.jar</include> - </resource> - </resources> - <exposes> - <expose>8888</expose> - </exposes> - <imageTags> - <!-- imageTag>${project.version}-SNAPSHOT-${maven.build.timestamp}Z</imageTag --> - <imageTag>${project.version}</imageTag> - <imageTag>latest</imageTag> - </imageTags> - <serverId>${onap.nexus.dockerregistry.daily}</serverId> - </configuration> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <version>1.9.1</version> - <executions> - <execution> - <id>add-source</id> - <phase>generate-sources</phase> - <goals> - <goal>add-source</goal> - </goals> - <configuration> - <sources> - <source>src/gen/java</source> - </sources> - </configuration> - </execution> - <execution> - <id>regex-property</id> - <goals> - <goal>regex-property</goal> - </goals> - <configuration> - <name>docker.version</name> - <value>${project.version}</value> - <regex>(^[0-9]+.[0-9]+.[0-9]+$)</regex> - <replacement>$1-STAGING</replacement> - <failIfNoMatch>false</failIfNoMatch> - </configuration> - </execution> - </executions> - </plugin> + </plugins> + <finalName>snmpmapper</finalName> </build> diff --git a/snmpmapper/src/main/java/org/onap/dcae/mapper/FileUploadController.java b/snmpmapper/src/main/java/org/onap/dcae/mapper/FileUploadController.java deleted file mode 100644 index fce8dfa..0000000 --- a/snmpmapper/src/main/java/org/onap/dcae/mapper/FileUploadController.java +++ /dev/null @@ -1,128 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= -*/ - -package org.onap.dcae.mapper; - -import java.io.IOException; -import java.net.URL; -import java.util.stream.Collectors; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.Resource; -import org.springframework.http.HttpHeaders; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; -import org.springframework.web.servlet.mvc.support.RedirectAttributes; - -import com.google.common.base.Charsets; -import com.google.common.io.Resources; - -import org.onap.dcae.mapper.storage.StorageFileNotFoundException; -import org.onap.dcae.mapper.storage.StorageService; - -/** - * @author BS00493532 This Controller shifts control according to the uri - * accessed by the user. Accordingly control shifts to get and post - * methods. - * - */ -@Controller -public class FileUploadController { - - private final StorageService storageService; - - @Autowired - public FileUploadController(StorageService storageService) { - this.storageService = storageService; - } - - @GetMapping("/") - public String listUploadedFiles(Model model) throws IOException { - - model.addAttribute("files", - storageService.loadAll() - .map(path -> MvcUriComponentsBuilder - .fromMethodName(FileUploadController.class, "serveFile", path.getFileName().toString()) - .build().toString()) - .collect(Collectors.toList())); - - return "uploadForm"; - - /** - * @author BS00493532 - * - * Returns the upload form like a html page - */ - - } - - @GetMapping("/files/{filename:.+}") - @ResponseBody - public ResponseEntity<Resource> serveFile(@PathVariable String filename) { - - Resource file = storageService.loadAsResource(filename); - return ResponseEntity.ok() - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getFilename() + "\"") - .body(file); - } - - @GetMapping("/fileAsString/{filename:.+}") - @ResponseBody - public String serveFileAsString(@PathVariable String filename) { - - Resource file = storageService.loadAsResource(filename); - // URL url = Resources.getResource(file. getFilename());// - // getResource(file.getURL()); - String fileContent = null; - try { - fileContent = Resources.toString(file.getURL(), Charsets.UTF_8); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return fileContent; - } - - @PostMapping("/") - public String handleFileUpload(@RequestParam("file") MultipartFile file, RedirectAttributes redirectAttributes) { - System.out.println("1"); - - storageService.store(file); - redirectAttributes.addFlashAttribute("message", - "You successfully uploaded " + file.getOriginalFilename() + "!"); - - return "redirect:/"; - } - - @ExceptionHandler(StorageFileNotFoundException.class) - public ResponseEntity<?> handleStorageFileNotFound(StorageFileNotFoundException exc) { - return ResponseEntity.notFound().build(); - } - -} diff --git a/snmpmapper/src/main/java/org/onap/dcae/mapper/SnmpmapperApplication.java b/snmpmapper/src/main/java/org/onap/dcae/mapper/SnmpmapperApplication.java deleted file mode 100644 index 4893a2a..0000000 --- a/snmpmapper/src/main/java/org/onap/dcae/mapper/SnmpmapperApplication.java +++ /dev/null @@ -1,46 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= -*/ - -package org.onap.dcae.mapper; - -import org.onap.dcae.mapper.storage.StorageProperties; -import org.onap.dcae.mapper.storage.StorageService; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; - -@SpringBootApplication -@EnableConfigurationProperties(StorageProperties.class) -public class SnmpmapperApplication { - - public static void main(String[] args) { - SpringApplication.run(SnmpmapperApplication.class, args); - } - - @Bean - CommandLineRunner init(StorageService storageService) { - return (args) -> { - // storageService.deleteAll(); - storageService.init(); - }; - } -} diff --git a/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/FileSystemStorageService.java b/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/FileSystemStorageService.java deleted file mode 100644 index 5cee706..0000000 --- a/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/FileSystemStorageService.java +++ /dev/null @@ -1,130 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= -*/ - -package org.onap.dcae.mapper.storage; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.util.stream.Stream; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.Resource; -import org.springframework.core.io.UrlResource; -import org.springframework.stereotype.Service; -import org.springframework.util.FileSystemUtils; -import org.springframework.util.StringUtils; -import org.springframework.web.multipart.MultipartFile; - -@Service -public class FileSystemStorageService implements StorageService { - - private final Path rootLocation; - - @Autowired - public FileSystemStorageService(StorageProperties properties) { - this.rootLocation = Paths.get(properties.getLocation()); - } - - @Override - public void store(MultipartFile file) { - String filename = StringUtils.cleanPath(file.getOriginalFilename()); - try { - if (file.isEmpty()) { - throw new StorageException("Failed to store empty file " + filename); - } - - /** - * @author BS00493532 Checks the contents of the file. If empty, throws - * exception - */ - if (filename.contains("..")) { - // This is a security check - throw new StorageException( - "Cannot store file with relative path outside current directory " + filename); - } - Files.copy(file.getInputStream(), this.rootLocation.resolve(filename), StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - throw new StorageException("Failed to store file " + filename, e); - } - } - - @Override - public Stream<Path> loadAll() { - try { - return Files.walk(this.rootLocation, 1).filter(path -> !path.equals(this.rootLocation)) - .map(path -> this.rootLocation.relativize(path)); - } - - /** - * @author BS00493532 Loads all the files in the given path - * - */ - - catch (IOException e) { - throw new StorageException("Failed to read stored files", e); - } - - } - - @Override - public Path load(String filename) { - return rootLocation.resolve(filename); - } - - @Override - public Resource loadAsResource(String filename) { - try { - Path file = load(filename); - Resource resource = new UrlResource(file.toUri()); - if (resource.exists() || resource.isReadable()) { - return resource; - } else { - throw new StorageFileNotFoundException("Could not read file: " + filename); - - } - } catch (MalformedURLException e) { - throw new StorageFileNotFoundException("Could not read file: " + filename, e); - } - } - - /* - * @Override public void deleteAll() { - * FileSystemUtils.deleteRecursively(rootLocation.toFile()); } - */ - - @Override - public void init() { - try { - Files.createDirectories(rootLocation); - } - - /** - * @author BS00493532 Initializes Storage - */ - - catch (IOException e) { - throw new StorageException("Could not initialize storage", e); - } - } -} diff --git a/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageException.java b/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageException.java deleted file mode 100644 index dd2675d..0000000 --- a/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= -*/ - -package org.onap.dcae.mapper.storage; - -public class StorageException extends RuntimeException { - - public StorageException(String message) { - super(message); - } - - public StorageException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageFileNotFoundException.java b/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageFileNotFoundException.java deleted file mode 100644 index ef88087..0000000 --- a/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageFileNotFoundException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= -*/ - -package org.onap.dcae.mapper.storage; - -public class StorageFileNotFoundException extends StorageException { - - public StorageFileNotFoundException(String message) { - super(message); - } - - public StorageFileNotFoundException(String message, Throwable cause) { - super(message, cause); - } -}
\ No newline at end of file diff --git a/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageProperties.java b/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageProperties.java deleted file mode 100644 index a2f5396..0000000 --- a/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageProperties.java +++ /dev/null @@ -1,44 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= -*/ - -package org.onap.dcae.mapper.storage; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.properties.ConfigurationProperties; - -@ConfigurationProperties("storage") -public class StorageProperties { - - /** - * Folder location for storing files - */ - // private String location = "upload-dir"; - @Value("${fileService.rootPath}") - private String location; - - public String getLocation() { - return location; - } - - public void setLocation(String location) { - this.location = location; - } - -} diff --git a/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageService.java b/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageService.java deleted file mode 100644 index cb278f2..0000000 --- a/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageService.java +++ /dev/null @@ -1,43 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= -*/ - -package org.onap.dcae.mapper.storage; - -import java.nio.file.Path; -import java.util.stream.Stream; - -import org.springframework.core.io.Resource; -import org.springframework.web.multipart.MultipartFile; - -public interface StorageService { - - void init(); - - void store(MultipartFile file); - - Stream<Path> loadAll(); - - Path load(String filename); - - Resource loadAsResource(String filename); - - // void deleteAll(); - -} diff --git a/snmpmapper/src/main/java/org/onap/dcae/servicedb/Mapping_file.java b/snmpmapper/src/main/java/org/onap/dcae/servicedb/Mapping_file.java new file mode 100644 index 0000000..a4669da --- /dev/null +++ b/snmpmapper/src/main/java/org/onap/dcae/servicedb/Mapping_file.java @@ -0,0 +1,77 @@ +package org.onap.dcae.servicedb; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.Table; + +@Entity +@Table(name = "mapping_file") +public class Mapping_file { + + @Id + @Column(name = "EnterpriseID") + public String Enterprise_ID; + + @Column(name = "File_Name") + public String name; + + + @Column(name = "mimetype") + private String mimetype; + + + @Column(name = "mappingfilecontents") + private byte[] Mapping_File; + + + + public Mapping_file() { + super(); + } + + public Mapping_file(String enterprise_ID, String name, String mimetype, byte[] mapping_File) { + super(); + Enterprise_ID = enterprise_ID; + this.name = name; + this.mimetype = mimetype; + Mapping_File = mapping_File; + } + + public String getEnterprise_ID() { + return Enterprise_ID; + } + + public void setEnterprise_ID(String enterprise_ID) { + Enterprise_ID = enterprise_ID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMimetype() { + return mimetype; + } + + public void setMimetype(String mimetype) { + this.mimetype = mimetype; + } + + public byte[] getMapping_File() { + return Mapping_File; + } + + public void setMapping_File(byte[] mapping_File) { + Mapping_File = mapping_File; + } + + + + +} diff --git a/snmpmapper/src/main/java/org/onap/dcae/snmpmapperApplication.java b/snmpmapper/src/main/java/org/onap/dcae/snmpmapperApplication.java new file mode 100644 index 0000000..5354f86 --- /dev/null +++ b/snmpmapper/src/main/java/org/onap/dcae/snmpmapperApplication.java @@ -0,0 +1,12 @@ +package org.onap.dcae; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class snmpmapperApplication { + + public static void main(String[] args) { + SpringApplication.run(snmpmapperApplication.class, args); + } +} diff --git a/snmpmapper/src/main/java/org/onap/dcae/snmpmapperController.java b/snmpmapper/src/main/java/org/onap/dcae/snmpmapperController.java new file mode 100644 index 0000000..94eca54 --- /dev/null +++ b/snmpmapper/src/main/java/org/onap/dcae/snmpmapperController.java @@ -0,0 +1,124 @@ +package org.onap.dcae; + +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.catalina.startup.ClassLoaderFactory.Repository; +import org.onap.dcae.servicedb.Mapping_file; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.commons.CommonsMultipartFile; +import org.springframework.web.servlet.ModelAndView; + +@Controller +public class snmpmapperController { + + /*@Autowired + private UploadPageSample1Service upss;*/ + + @Value("${spring.datasource.url}") + String url; + @Value("${spring.datasource.username}") + String user; + @Value("${spring.datasource.password}") + String pwd; + + static String enterpriseid; + static Mapping_file mapping; + + @GetMapping("/") + public String index() { + return "uploadform.html"; + } + + + // This Method Is Used To Get Or Retrieve The Uploaded File And Save It In The Db + @RequestMapping(value = "uploadFile", method = RequestMethod.POST) + public String saveUploadedFileInDatabase(HttpServletRequest request, final @RequestParam MultipartFile[] mapper) throws IllegalStateException, IOException, SQLException { + + // Reading File Upload Form Input Parameters + enterpriseid = request.getParameter("eid"); + + // Logging The Input Parameter (i.e. File Description) For The Debugging Purpose + System.out.println("\nEnterPrise ID Is = " + enterpriseid + "\n"); + + // Determine If There Is An File Upload. If Yes, Attach It To The Client Email + if ((mapper != null) && (mapper.length > 0) && (!mapper.equals(""))) { + for (MultipartFile aFile : mapper) { + if(aFile.isEmpty()) { + continue; + } else { + System.out.println("MappingFile Name = " + aFile.getOriginalFilename() + "\n"); + if (!aFile.getOriginalFilename().equals("")) { + mapping = new Mapping_file(); + mapping.setEnterprise_ID(enterpriseid); + mapping.setMapping_File(aFile.getBytes()); + mapping.setMimetype(aFile.getContentType()); + mapping.setName(aFile.getOriginalFilename()); + + + + /*InputStream inputStream = new BufferedInputStream(aFile.getInputStream());*/ + + System.out.println("1"); + try (Connection con = DriverManager.getConnection(url, user, pwd)) { + + System.out.println("2"); + /*CopyManager cm = new CopyManager((BaseConnection) con);*/ + PreparedStatement pstmt=con.prepareStatement("INSERT INTO mapping_file(enterpriseid, mappingfilecontents, mimetype, File_Name) VALUES (?, ?, ?, ?)"); + pstmt.setString(1, enterpriseid); + System.out.println("3"); + pstmt.setBytes(2, aFile.getBytes()); + pstmt.setString(3, aFile.getContentType()); + pstmt.setString(4, aFile.getOriginalFilename()); + + + System.out.println("4"); + pstmt.executeUpdate(); + + + + + + + /*String fileName = "D:\\configFiles\\TestFile.txt";*/ + + /*try (FileInputStream fis = new FileInputStream(fileName); + InputStreamReader isr = new InputStreamReader(fis, + StandardCharsets.UTF_8)) {*/ + + + + + } + + + + } + } + System.out.println("File Is Successfully Uploaded & Saved In The Database\n"); + } + } else { + // Do Nothing + } + + return "success.html"; + } + +} diff --git a/snmpmapper/src/main/resources/application.properties b/snmpmapper/src/main/resources/application.properties index bee02d9..cf4f33c 100644 --- a/snmpmapper/src/main/resources/application.properties +++ b/snmpmapper/src/main/resources/application.properties @@ -1,2 +1,11 @@ -fileService.rootPath=D:/configFiles -server.port=8888
\ No newline at end of file +server.port=9090 +spring.datasource.url=jdbc:postgresql://10.49.16.19:5432/dummy +spring.datasource.username=postgres +spring.datasource.password=root +spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true +spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false +spring.servlet.multipart.enabled=true +spring.servlet.multipart.max-file-size=1MB +spring.servlet.multipart.max-request-size=10MB +spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect + diff --git a/snmpmapper/src/main/resources/templates/success.html b/snmpmapper/src/main/resources/templates/success.html new file mode 100644 index 0000000..c5a0d34 --- /dev/null +++ b/snmpmapper/src/main/resources/templates/success.html @@ -0,0 +1,34 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <title>Mapping File</title> + <style type="text/css"> + #fileUploadDiv { + text-align: center; + padding-top: 16px; + } + #fileUploadFormPage { + text-decoration: none; + text-align: center; + cursor: pointer; + } + #successMessage { + text-align: center; + color: green; + font-size: 25px; + padding-top: 17px; + } + </style> + </head> + <body> + <center> + <h2>Uploaded Mapping File </h2> + </center> + <div id="successMessage"> + <strong>Successfully Uploaded Mapping File</strong> + <a href="/">Submit another mapping file</a> + </div> + + </body> +</html>
\ No newline at end of file diff --git a/snmpmapper/src/main/resources/templates/uploadForm.html b/snmpmapper/src/main/resources/templates/uploadForm.html index 22ffc68..89ef4c2 100644 --- a/snmpmapper/src/main/resources/templates/uploadForm.html +++ b/snmpmapper/src/main/resources/templates/uploadForm.html @@ -1,19 +1,36 @@ -<html xmlns:th="http://www.thymeleaf.org"> +<!DOCTYPE html> +<html lang="en"> +<head> + <title>Mapping File</title> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"> + <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> + <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script> + <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script> +</head> + <body> - - <div th:if="${message}"> - <h2 th:text="${message}"/> - </div> - - <div> - <form method="POST" enctype="multipart/form-data" action="/"> - <table> - <tr><td>File to upload:</td><td><input type="file" name="file" /></td></tr> - <tr><td></td><td><input type="submit" value="Upload" /></td></tr> - </table> - </form> - </div> - - -</body> -</html> + <center> + <h2>Upload Mapping File</h2> + <form id="fileUploadForm" method="post" action="uploadFile" enctype="multipart/form-data"> + <table id="fileUploadFormBeanTable" border="0" width="80%"> + <tr> + <td>Enterprise ID:</td> + <td><input id="enterpriseid" type="text" name="eid" size="65" /></td> + </tr> + <tr> + <td>Mapping file:</td> + <td> + <input id="mappingfile" type="file" name="mapper" size="60" /> + <span id="fileUploadErr">Please Upload A File!</span> + </td> + </tr> + <tr> + <td colspan="2" align="center"><input id="fileUploadBtn" type="submit" value="Upload" /></td> + </tr> + </table> + </form> + </center> + </body> +</html>
\ No newline at end of file diff --git a/snmpmapper/src/main/resources/templates/uploadform.html b/snmpmapper/src/main/resources/templates/uploadform.html new file mode 100644 index 0000000..89ef4c2 --- /dev/null +++ b/snmpmapper/src/main/resources/templates/uploadform.html @@ -0,0 +1,36 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <title>Mapping File</title> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"> + <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> + <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script> + <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script> +</head> + +<body> + <center> + <h2>Upload Mapping File</h2> + <form id="fileUploadForm" method="post" action="uploadFile" enctype="multipart/form-data"> + <table id="fileUploadFormBeanTable" border="0" width="80%"> + <tr> + <td>Enterprise ID:</td> + <td><input id="enterpriseid" type="text" name="eid" size="65" /></td> + </tr> + <tr> + <td>Mapping file:</td> + <td> + <input id="mappingfile" type="file" name="mapper" size="60" /> + <span id="fileUploadErr">Please Upload A File!</span> + </td> + </tr> + <tr> + <td colspan="2" align="center"><input id="fileUploadBtn" type="submit" value="Upload" /></td> + </tr> + </table> + </form> + </center> + </body> +</html>
\ No newline at end of file diff --git a/snmpmapper/src/test/java/org/onap/dcae/mapper/FileUploadControllerTest.java b/snmpmapper/src/test/java/org/onap/dcae/mapper/FileUploadControllerTest.java deleted file mode 100644 index d970724..0000000 --- a/snmpmapper/src/test/java/org/onap/dcae/mapper/FileUploadControllerTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= -*/ -package org.onap.dcae.mapper; - -import static org.junit.Assert.*; - -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.onap.dcae.mapper.storage.StorageService; -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.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.ui.ExtendedModelMap; -import org.springframework.ui.Model; -import org.springframework.web.servlet.ModelAndView; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes=SnmpmapperApplication.class) -@AutoConfigureMockMvc - -public class FileUploadControllerTest { - - @Autowired - private MockMvc mockMvc; - - @Mock - private StorageService storageService; - - @Autowired - @InjectMocks - private FileUploadController fuc; - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - } - - - @Test - public void listUploadedFilesTest() throws Exception { - - Model map = new ExtendedModelMap(); - - Path p1 = Paths.get("."); - List<Path> list = new ArrayList<>(); - list.add(p1); - - - try { - Mockito.when(storageService.loadAll()).thenReturn(list.stream()); - } catch (Exception e) { - - } - - try { - String listUploadedFiles = fuc.listUploadedFiles(map); - - assertEquals("uploadForm", listUploadedFiles); - } catch (IOException e) { - - e.printStackTrace(); - } - - - - - } - -} diff --git a/snmpmapper/src/test/java/org/onap/dcae/mapper/StorageExceptionTest.java b/snmpmapper/src/test/java/org/onap/dcae/mapper/StorageExceptionTest.java deleted file mode 100644 index 1f4783d..0000000 --- a/snmpmapper/src/test/java/org/onap/dcae/mapper/StorageExceptionTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= -*/ -package org.onap.dcae.mapper; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.onap.dcae.mapper.storage.StorageException; - -public class StorageExceptionTest { - - StorageException se = new StorageException("message"); - StorageException se1 = new StorageException("message", se); - - @Test - public void test() { - - -} -} diff --git a/snmpmapper/src/test/java/org/onap/dcae/mapper/StorageFileNotFoundExceptionTest.java b/snmpmapper/src/test/java/org/onap/dcae/mapper/StorageFileNotFoundExceptionTest.java deleted file mode 100644 index 39fbeac..0000000 --- a/snmpmapper/src/test/java/org/onap/dcae/mapper/StorageFileNotFoundExceptionTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= -*/ -package org.onap.dcae.mapper; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.onap.dcae.mapper.storage.StorageFileNotFoundException; - -public class StorageFileNotFoundExceptionTest { - - StorageFileNotFoundException sfnfe = new StorageFileNotFoundException("message"); - StorageFileNotFoundException sfnfe1 = new StorageFileNotFoundException("message", sfnfe); - - @Test - public void test() { - - } - -} diff --git a/snmpmapper/src/test/java/org/onap/dcae/mapper/StoragePropertiesTest.java b/snmpmapper/src/test/java/org/onap/dcae/mapper/StoragePropertiesTest.java deleted file mode 100644 index 64915f5..0000000 --- a/snmpmapper/src/test/java/org/onap/dcae/mapper/StoragePropertiesTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= -*/ -package org.onap.dcae.mapper; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.onap.dcae.mapper.storage.StorageProperties; - -public class StoragePropertiesTest { - - StorageProperties sp= new StorageProperties(); - - -@Test -public void testStorageProperties() { - - sp.setLocation("location"); - assertEquals(sp.getLocation(), "location"); - -} -}
\ No newline at end of file diff --git a/snmpmapper/src/test/java/org/onap/dcae/mapper/storage/FileSystemStorageServiceTest.java b/snmpmapper/src/test/java/org/onap/dcae/mapper/storage/FileSystemStorageServiceTest.java deleted file mode 100644 index 56fc518..0000000 --- a/snmpmapper/src/test/java/org/onap/dcae/mapper/storage/FileSystemStorageServiceTest.java +++ /dev/null @@ -1,144 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= -*/ -package org.onap.dcae.mapper.storage; - -import static org.junit.Assert.*; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.onap.dcae.mapper.FileUploadController; -import org.onap.dcae.mapper.SnmpmapperApplication; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.core.io.Resource; -import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.web.multipart.MultipartFile; - - - -@RunWith(SpringRunner.class) -@SpringBootTest(classes=SnmpmapperApplication.class) -public class FileSystemStorageServiceTest { - - - - StorageProperties sp = new StorageProperties(); - @Autowired - FileSystemStorageService fileSystemStorageService ; - - - - @Value("${fileService.rootPath}") - private String location; - - - - byte[] content = null; - - - - - - String filename; - - - @Test - public void testFileSystemStorageServiceLoadMethod() throws IOException { - fileSystemStorageService.init(); - saveFile(); - - Path filePath = fileSystemStorageService.load("TestFile.txt"); - - assertEquals(Paths.get(location), filePath.getParent()); - - - } - - - - @Test - public void storeTest() throws IOException - { - fileSystemStorageService.init(); - saveFile(); - - assertEquals(true, Files.exists(Paths.get(location, "TestFile.txt"))); - - - - - - } - - private void saveFile() throws IOException { - Files.deleteIfExists(Paths.get(location, "TestFile.txt")); - content = "randomString".getBytes(); - MultipartFile file=new MockMultipartFile("TestFile.txt","TestFile.txt", "text/plain", content); - - - fileSystemStorageService.store(file); - } - @Test - public void testFileSystemStorageServiceLoadAllMethod() throws IOException { - fileSystemStorageService.init(); - saveFile(); - - Stream<Path> filePath = fileSystemStorageService.loadAll(); - List<Path> listOfPaths =filePath.collect(Collectors.toList()); - - assertEquals(true, listOfPaths.contains(Paths.get("TestFile.txt"))); - - - } - - @Test - public void testFileSystemStorageServiceLoadResourceMethod() throws IOException { - fileSystemStorageService.init(); - saveFile(); - - - - Resource fileResource = fileSystemStorageService.loadAsResource("TestFile.txt"); - - - assertEquals(Paths.get(location,"TestFile.txt").getFileName().toString(), fileResource.getFilename()); - - - } - -}
\ No newline at end of file diff --git a/snmpmapper/src/test/java/org/onap/dcae/snmpmapperApplicationTests.java b/snmpmapper/src/test/java/org/onap/dcae/snmpmapperApplicationTests.java new file mode 100644 index 0000000..59d1d92 --- /dev/null +++ b/snmpmapper/src/test/java/org/onap/dcae/snmpmapperApplicationTests.java @@ -0,0 +1,16 @@ +package org.onap.dcae; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class snmpmapperApplicationTests { + + @Test + public void contextLoads() { + } + +} |