2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.dcaegen2.services.mapper.snmpmapper.service;
22 import java.io.IOException;
23 import java.sql.SQLException;
25 import javax.servlet.http.HttpServletRequest;
27 import org.onap.dcaegen2.services.mapper.snmpmapper.DAO.MappingFileDAO;
28 import org.onap.dcaegen2.services.mapper.snmpmapper.entity.MappingFile;
29 import org.onap.dcaegen2.services.mapper.snmpmapper.exception.SnmpMapperException;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.stereotype.Service;
34 import org.springframework.web.multipart.MultipartFile;
37 public class MappingFileServiceImpl implements MappingFileService {
38 private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
40 static String enterpriseid;
41 static MappingFile mapping;
44 MappingFileDAO mappingFileDAO;
47 public String saveUploadedFileInDatabase(HttpServletRequest request, MultipartFile[] mappingfile) {
49 // Reading File Upload Form Input Parameters
50 enterpriseid = request.getParameter("eid");
52 LOGGER.debug("EnterPrise ID recieved:{}",enterpriseid);
55 if ((mappingfile != null) && (mappingfile.length > 0) && (!mappingfile.equals(""))) {
56 for (MultipartFile aFile : mappingfile) {
60 LOGGER.debug("MappingFile Name = {} with enterprise id:{}", aFile.getOriginalFilename(),enterpriseid);
61 if (!aFile.getOriginalFilename().equals("")) {
63 mapping = new MappingFile();
64 mapping.setEnterprise_ID(enterpriseid);
66 mapping.setMapping_File(aFile.getBytes());
68 mapping.setMimetype(aFile.getContentType());
69 mapping.setName(aFile.getOriginalFilename());
73 mappingFileDAO.uploadMappingFile(aFile,enterpriseid);
74 } catch (SnmpMapperException snmpMapperException) {
75 LOGGER.error(snmpMapperException.getMessage());
76 } catch (IOException e) {
77 LOGGER.error("IOException occured:{}",e.getCause());
79 } catch (SQLException e) {
80 // TODO Auto-generated catch block
81 LOGGER.error("SQLException occured:{}",e.getCause());
87 LOGGER.debug("File Is Successfully Uploaded & Saved In The Database\n");