X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcontroller%2FDictionaryImportController.java;h=7400eb0c8fe833926e61da8a55a519ec62a233ee;hb=ad162645e845baae599383a227122bcfffb8d326;hp=7093cd5149c7ec9f4b002ce25ea54edbb119ca10;hpb=dea7a9791960ac2f913e2ab4c70491706ab9e2a0;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java index 7093cd514..7400eb0c8 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 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. @@ -20,6 +20,11 @@ package org.onap.policy.pap.xacml.rest.controller; +import au.com.bytecode.opencsv.CSVReader; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; @@ -39,9 +44,9 @@ 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.BRMSController; -import org.onap.policy.rest.jpa.BRMSDependency; -import org.onap.policy.rest.jpa.BRMSParamTemplate; +import org.onap.policy.rest.jpa.BrmsController; +import org.onap.policy.rest.jpa.BrmsDependency; +import org.onap.policy.rest.jpa.BrmsParamTemplate; import org.onap.policy.rest.jpa.Category; import org.onap.policy.rest.jpa.ClosedLoopD2Services; import org.onap.policy.rest.jpa.ClosedLoopSite; @@ -67,23 +72,17 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; - -import au.com.bytecode.opencsv.CSVReader; - - @Controller public class DictionaryImportController { - private static final Logger LOGGER = FlexLogger.getLogger(DictionaryImportController.class); + private static final Logger LOGGER = FlexLogger.getLogger(DictionaryImportController.class); private static CommonClassDao commonClassDao; - private static final String DESCRIPTION= "description"; - private static final String ERROR= "Error"; - private static final String DEPENDENCY= "dependency"; + private static final String DESCRIPTION = "description"; + private static final String ERROR = "Error"; + private static final String DEPENDENCY = "dependency"; @Autowired - public DictionaryImportController(CommonClassDao commonClassDao){ + public DictionaryImportController(CommonClassDao commonClassDao) { setCommonClassDao(commonClassDao); } @@ -91,18 +90,18 @@ public class DictionaryImportController { DictionaryImportController.commonClassDao = commonClassDao; } - public DictionaryImportController(){ + public DictionaryImportController() { super(); } - @RequestMapping(value={"/dictionary/import_dictionary"}, method={RequestMethod.POST}) - public void importDictionaryData(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/dictionary/import_dictionary"}, method = {RequestMethod.POST}) + public void importDictionaryData(HttpServletRequest request, HttpServletResponse response) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); String userId = request.getParameter("userId"); String dictionaryName = request.getParameter("dictionaryName"); - if(dictionaryName == null || dictionaryName.isEmpty()){ + if (dictionaryName == null || dictionaryName.isEmpty()) { LOGGER.error("dictionaryName is null/empty"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().write(ERROR); @@ -110,46 +109,49 @@ public class DictionaryImportController { } // fix Fortify Path Manipulation issue - if(!isValidDictionaryName(dictionaryName)){ + if (!isValidDictionaryName(dictionaryName)) { LOGGER.error("dictionaryName is invalid"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().write(ERROR); return; } File file = new File(dictionaryName); - try(OutputStream outputStream = new FileOutputStream(file); FileReader fileReader = new FileReader(file.toString())){ + try (OutputStream outputStream = new FileOutputStream(file); + FileReader fileReader = new FileReader(file.toString())) { IOUtils.copy(request.getInputStream(), outputStream); CSVReader csvReader = new CSVReader(fileReader); List dictSheet = csvReader.readAll(); - if(dictionaryName.startsWith("Attribute")){ - for(int i = 1; i< dictSheet.size(); i++){ + 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