/*- * ============LICENSE_START======================================================= * ONAP-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.onap.policy.pap.xacml.rest.controller; /* * * * */ import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.OutputStream; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.commons.compress.utils.IOUtils; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.ActionList; import org.onap.policy.rest.jpa.ActionPolicyDict; import org.onap.policy.rest.jpa.AddressGroup; import org.onap.policy.rest.jpa.Attribute; import org.onap.policy.rest.jpa.BRMSParamTemplate; import org.onap.policy.rest.jpa.Category; import org.onap.policy.rest.jpa.Datatype; import org.onap.policy.rest.jpa.DecisionSettings; import org.onap.policy.rest.jpa.DescriptiveScope; import org.onap.policy.rest.jpa.GroupServiceList; import org.onap.policy.rest.jpa.OnapName; import org.onap.policy.rest.jpa.PEPOptions; import org.onap.policy.rest.jpa.PrefixList; import org.onap.policy.rest.jpa.ProtocolList; import org.onap.policy.rest.jpa.SecurityZone; import org.onap.policy.rest.jpa.ServiceList; import org.onap.policy.rest.jpa.TermList; import org.onap.policy.rest.jpa.UserInfo; import org.onap.policy.rest.jpa.VNFType; import org.onap.policy.rest.jpa.VSCLAction; import org.onap.policy.rest.jpa.VarbindDictionary; import org.onap.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; private static CommonClassDao commonClassDao; @Autowired public DictionaryImportController(CommonClassDao commonClassDao){ DictionaryImportController.commonClassDao = commonClassDao; } public DictionaryImportController(){} @RequestMapping(value={"/dictionary/import_dictionary"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public void ImportDictionaryData(HttpServletRequest request) throws IOException{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); String userId = request.getParameter("userId"); String dictionaryName = request.getParameter("dictionaryName"); File file = new File(dictionaryName); OutputStream outputStream = new FileOutputStream(file); IOUtils.copy(request.getInputStream(), outputStream); outputStream.close(); this.newFile = file.toString(); CSVReader csvReader = new CSVReader(new FileReader(this.newFile)); List dictSheet = csvReader.readAll(); if(dictionaryName.startsWith("Attribute")){ for(int i = 1; i< dictSheet.size(); i++){ Attribute attribute = new Attribute(""); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); attribute.setUserModifiedBy(userinfo); String[] rows = dictSheet.get(i); for (int j=0 ; j