diff options
Diffstat (limited to 'snmpmapper')
18 files changed, 995 insertions, 0 deletions
diff --git a/snmpmapper/.gitignore b/snmpmapper/.gitignore new file mode 100644 index 0000000..63bdaca --- /dev/null +++ b/snmpmapper/.gitignore @@ -0,0 +1,28 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ +# Package Files # +*.jar +.mvn/* +.settings/*
\ No newline at end of file diff --git a/snmpmapper/build.gradle b/snmpmapper/build.gradle new file mode 100644 index 0000000..00c0e39 --- /dev/null +++ b/snmpmapper/build.gradle @@ -0,0 +1,32 @@ +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 new file mode 100644 index 0000000..7b87588 --- /dev/null +++ b/snmpmapper/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#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 new file mode 100644 index 0000000..27309d9 --- /dev/null +++ b/snmpmapper/gradlew @@ -0,0 +1,164 @@ +#!/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 new file mode 100644 index 0000000..832fdb6 --- /dev/null +++ b/snmpmapper/gradlew.bat @@ -0,0 +1,90 @@ +@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/pom.xml b/snmpmapper/pom.xml new file mode 100644 index 0000000..67875b6 --- /dev/null +++ b/snmpmapper/pom.xml @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <!-- <groupId>org.springframework</groupId> + <artifactId>snmpmapper</artifactId> + <version>0.0.1-SNAPSHOT</version> + <packaging>jar</packaging> + --> + <name>snmpmapper</name> + <description>snmpmapper demo</description> + + <!-- <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> + + + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <java.version>1.8</java.version> + </properties> + + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <version>2.0.0.RELEASE</version> + + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-thymeleaf</artifactId> + <version>2.0.0.RELEASE</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <version>2.0.0.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> + </dependency> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + <version>24.0-jre</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + <!-- <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.19.1</version> + </plugin> --> + + </plugins> + </build> + + +</project> diff --git a/snmpmapper/src/main/java/org/onap/dcae/mapper/FileUploadController.java b/snmpmapper/src/main/java/org/onap/dcae/mapper/FileUploadController.java new file mode 100644 index 0000000..fce8dfa --- /dev/null +++ b/snmpmapper/src/main/java/org/onap/dcae/mapper/FileUploadController.java @@ -0,0 +1,128 @@ +/* +* ============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 new file mode 100644 index 0000000..4893a2a --- /dev/null +++ b/snmpmapper/src/main/java/org/onap/dcae/mapper/SnmpmapperApplication.java @@ -0,0 +1,46 @@ +/* +* ============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 new file mode 100644 index 0000000..5cee706 --- /dev/null +++ b/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/FileSystemStorageService.java @@ -0,0 +1,130 @@ +/* +* ============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 new file mode 100644 index 0000000..dd2675d --- /dev/null +++ b/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageException.java @@ -0,0 +1,32 @@ +/* +* ============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 new file mode 100644 index 0000000..ef88087 --- /dev/null +++ b/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageFileNotFoundException.java @@ -0,0 +1,32 @@ +/* +* ============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 new file mode 100644 index 0000000..a2f5396 --- /dev/null +++ b/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageProperties.java @@ -0,0 +1,44 @@ +/* +* ============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 new file mode 100644 index 0000000..cb278f2 --- /dev/null +++ b/snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageService.java @@ -0,0 +1,43 @@ +/* +* ============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/resources/application.properties b/snmpmapper/src/main/resources/application.properties new file mode 100644 index 0000000..bee02d9 --- /dev/null +++ b/snmpmapper/src/main/resources/application.properties @@ -0,0 +1,2 @@ +fileService.rootPath=D:/configFiles +server.port=8888
\ 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..22ffc68 --- /dev/null +++ b/snmpmapper/src/main/resources/templates/uploadForm.html @@ -0,0 +1,19 @@ +<html xmlns:th="http://www.thymeleaf.org"> +<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> diff --git a/snmpmapper/src/test/java/org/onap/dcae/mapper/StorageExceptionTest.java b/snmpmapper/src/test/java/org/onap/dcae/mapper/StorageExceptionTest.java new file mode 100644 index 0000000..1f4783d --- /dev/null +++ b/snmpmapper/src/test/java/org/onap/dcae/mapper/StorageExceptionTest.java @@ -0,0 +1,37 @@ +/* +* ============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 new file mode 100644 index 0000000..39fbeac --- /dev/null +++ b/snmpmapper/src/test/java/org/onap/dcae/mapper/StorageFileNotFoundExceptionTest.java @@ -0,0 +1,37 @@ +/* +* ============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 new file mode 100644 index 0000000..64915f5 --- /dev/null +++ b/snmpmapper/src/test/java/org/onap/dcae/mapper/StoragePropertiesTest.java @@ -0,0 +1,39 @@ +/* +* ============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 |