aboutsummaryrefslogtreecommitdiffstats
path: root/snmpmapper/src/main
diff options
context:
space:
mode:
authorBharathS24 <BS00493532@techmahindra.com>2018-08-20 17:47:05 +0530
committerBharathS24 <BS00493532@techmahindra.com>2018-08-20 17:47:05 +0530
commit7cb9a25a7e32bcf141a5ad8f8ab1af0ed6064a99 (patch)
tree2560145d3fc9758c746fa3375ebed122278956ad /snmpmapper/src/main
parent1463aaab6db65130de04d84a68fd9331a1c0caa9 (diff)
Modified snmpmapper
Now snmpmapper is using DB(postgres) to save mapping file Issue-ID: DCAEGEN2-338 Change-Id: Ifdf173f7b405463005a96f76dee2558a291548e6 Signed-off-by: BharathS24 <BS00493532@techmahindra.com>
Diffstat (limited to 'snmpmapper/src/main')
-rw-r--r--snmpmapper/src/main/java/org/onap/dcae/mapper/FileUploadController.java128
-rw-r--r--snmpmapper/src/main/java/org/onap/dcae/mapper/SnmpmapperApplication.java46
-rw-r--r--snmpmapper/src/main/java/org/onap/dcae/mapper/storage/FileSystemStorageService.java130
-rw-r--r--snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageException.java32
-rw-r--r--snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageFileNotFoundException.java32
-rw-r--r--snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageProperties.java44
-rw-r--r--snmpmapper/src/main/java/org/onap/dcae/mapper/storage/StorageService.java43
-rw-r--r--snmpmapper/src/main/java/org/onap/dcae/servicedb/Mapping_file.java77
-rw-r--r--snmpmapper/src/main/java/org/onap/dcae/snmpmapperApplication.java12
-rw-r--r--snmpmapper/src/main/java/org/onap/dcae/snmpmapperController.java124
-rw-r--r--snmpmapper/src/main/resources/application.properties13
-rw-r--r--snmpmapper/src/main/resources/templates/success.html34
-rw-r--r--snmpmapper/src/main/resources/templates/uploadForm.html53
-rw-r--r--snmpmapper/src/main/resources/templates/uploadform.html36
14 files changed, 329 insertions, 475 deletions
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