/*- * ============LICENSE_START======================================================= * ECOMP-PAP-REST * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * 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.openecomp.policy.pap.xacml.rest.controller; /* * * * */ import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.OutputStream; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.compress.utils.IOUtils; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.openecomp.policy.rest.dao.ActionListDao; import org.openecomp.policy.rest.dao.ActionPolicyDictDao; import org.openecomp.policy.rest.dao.AddressGroupDao; import org.openecomp.policy.rest.dao.AttributeDao; import org.openecomp.policy.rest.dao.BRMSParamTemplateDao; import org.openecomp.policy.rest.dao.DecisionPolicyDao; import org.openecomp.policy.rest.dao.DescriptiveScopeDao; import org.openecomp.policy.rest.dao.EcompNameDao; import org.openecomp.policy.rest.dao.PEPOptionsDao; import org.openecomp.policy.rest.dao.PortListDao; import org.openecomp.policy.rest.dao.PrefixListDao; import org.openecomp.policy.rest.dao.ProtocolListDao; import org.openecomp.policy.rest.dao.SecurityZoneDao; import org.openecomp.policy.rest.dao.ServiceDictionaryDao; import org.openecomp.policy.rest.dao.ServiceGroupDao; import org.openecomp.policy.rest.dao.ServiceListDao; import org.openecomp.policy.rest.dao.SiteDictionaryDao; import org.openecomp.policy.rest.dao.TermListDao; import org.openecomp.policy.rest.dao.VNFTypeDao; import org.openecomp.policy.rest.dao.VSCLActionDao; import org.openecomp.policy.rest.dao.VarbindDictionaryDao; import org.openecomp.policy.rest.dao.ZoneDao; import org.openecomp.policy.rest.jpa.ActionList; import org.openecomp.policy.rest.jpa.ActionPolicyDict; import org.openecomp.policy.rest.jpa.AddressGroup; import org.openecomp.policy.rest.jpa.Attribute; import org.openecomp.policy.rest.jpa.BRMSParamTemplate; import org.openecomp.policy.rest.jpa.Category; import org.openecomp.policy.rest.jpa.Datatype; import org.openecomp.policy.rest.jpa.DecisionSettings; import org.openecomp.policy.rest.jpa.DescriptiveScope; import org.openecomp.policy.rest.jpa.EcompName; import org.openecomp.policy.rest.jpa.GroupServiceList; import org.openecomp.policy.rest.jpa.PEPOptions; import org.openecomp.policy.rest.jpa.PREFIXLIST; import org.openecomp.policy.rest.jpa.ProtocolList; import org.openecomp.policy.rest.jpa.SecurityZone; import org.openecomp.policy.rest.jpa.ServiceList; import org.openecomp.policy.rest.jpa.TermList; import org.openecomp.policy.rest.jpa.UserInfo; import org.openecomp.policy.rest.jpa.VNFType; import org.openecomp.policy.rest.jpa.VSCLAction; import org.openecomp.policy.rest.jpa.VarbindDictionary; import org.openecomp.policy.rest.jpa.Zone; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import au.com.bytecode.opencsv.CSVReader; @Controller public class DictionaryImportController { private String newFile; @Autowired AttributeDao attributeDao; @Autowired ActionPolicyDictDao actionPolicyDictDao; @Autowired EcompNameDao ecompNameDao; @Autowired VNFTypeDao vnfTypeDao; @Autowired VSCLActionDao vsclActionDao; @Autowired PEPOptionsDao pepOptionsDao; @Autowired VarbindDictionaryDao varbindDao; @Autowired ServiceDictionaryDao closedLoopServiceDao; @Autowired SiteDictionaryDao closedLoopSiteDao; @Autowired DescriptiveScopeDao descriptiveScopeDao; @Autowired PrefixListDao prefixListDao; @Autowired PortListDao portListDao; @Autowired ProtocolListDao protocolListDao; @Autowired AddressGroupDao addressGroupDao; @Autowired ActionListDao actionListDao; @Autowired SecurityZoneDao securityZoneDao; @Autowired ServiceGroupDao serviceGroupDao; @Autowired ServiceListDao serviceListDao; @Autowired TermListDao termListDao; @Autowired ZoneDao zoneDao; @Autowired DecisionPolicyDao decisionSettingsDao; @Autowired BRMSParamTemplateDao brmsParamTemplateDao; @RequestMapping(value={"/dictionary/import_dictionary.htm/*"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public void ImportDictionaryData(HttpServletRequest request, HttpServletResponse response) throws Exception{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); //JsonNode root = mapper.readTree(request.getReader()); String userId = request.getPathInfo().substring(request.getPathInfo().lastIndexOf("/")+1); List items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : items) { File file = new File(item.getName()); OutputStream outputStream = new FileOutputStream(file); IOUtils.copy(item.getInputStream(), outputStream); outputStream.close(); this.newFile = file.toString(); CSVReader csvReader = new CSVReader(new FileReader(this.newFile)); List dictSheet = csvReader.readAll(); if(item.getName().startsWith("Attribute")){ for(int i = 1; i< dictSheet.size(); i++){ Attribute attribute = new Attribute("", userId); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); attribute.setUserModifiedBy(userinfo); String[] rows = dictSheet.get(i); for (int j=0 ; j