23398bedc6930525fa1919baf8c31cc826f540b4
[dcaegen2/services/mapper.git] /
1 /*
2 * ============LICENSE_START=======================================================
3 * ONAP : DCAE
4 * ================================================================================
5 * Copyright 2018 TechMahindra
6 *=================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20 package org.onap.dcaegen2.services.mapper.snmpmapper.controller;
21
22 import java.io.BufferedInputStream;
23 import java.io.FileInputStream;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.InputStreamReader;
27 import java.nio.charset.StandardCharsets;
28 import java.sql.Connection;
29 import java.sql.DriverManager;
30 import java.sql.PreparedStatement;
31 import java.sql.SQLException;
32
33 import javax.servlet.http.HttpServletRequest;
34
35 import org.apache.catalina.startup.ClassLoaderFactory.Repository;
36 import org.onap.dcaegen2.services.mapper.snmpmapper.entity.MappingFile;
37 import org.onap.dcaegen2.services.mapper.snmpmapper.service.MappingFileService;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.beans.factory.annotation.Value;
40 import org.springframework.stereotype.Controller;
41 import org.springframework.web.bind.annotation.GetMapping;
42 import org.springframework.web.bind.annotation.RequestMapping;
43 import org.springframework.web.bind.annotation.RequestMethod;
44 import org.springframework.web.bind.annotation.RequestParam;
45 import org.springframework.web.multipart.MultipartFile;
46 import org.springframework.web.multipart.commons.CommonsMultipartFile;
47 import org.springframework.web.servlet.ModelAndView;
48
49
50 @Controller
51 public class SnmpmapperController {
52     
53         @Autowired
54         MappingFileService mappingFileService;
55         
56     @GetMapping("/")
57     public String index() {
58         return "uploadform.html";
59     }
60
61     
62  
63     /**
64      * 
65      * Method to upload Mapping file in the postgresql db
66      * @param request
67      * @param mapper
68      * @return
69      * 
70      */
71     @RequestMapping(value = "uploadFile", method = RequestMethod.POST)
72     public String saveUploadedFileInDatabase(HttpServletRequest request, final @RequestParam MultipartFile[] mapper){
73     String      result=mappingFileService.saveUploadedFileInDatabase(request, mapper);
74     if(result.equals("success")) {
75          return  "success.html";
76     }else
77     {
78         return "fail.html";
79     }
80    
81     }
82     
83 }