diff options
author | 2019-03-25 17:43:24 -0400 | |
---|---|---|
committer | 2019-03-25 17:47:57 -0400 | |
commit | a956a490499cf5c3f4ed2bff1921aec9a2b5a200 (patch) | |
tree | 2b0a4cd34b6b2a7f4d74b23761f908e7b524cf49 /ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller | |
parent | 97ce3b94390c10a1af43ed5614ca976095c0097d (diff) |
Only formatting changes for checkstyle fixes
Change-Id: I276b0946c5b03e5369a3c70468672378825c0766
Issue-ID: POLICY-1434
Signed-off-by: pa834y <pa834y@att.com>
Diffstat (limited to 'ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller')
9 files changed, 1723 insertions, 1245 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryController.java index a0044d26b..d6ebed2b8 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryController.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,15 +20,16 @@ package org.onap.policy.pap.xacml.rest.controller; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.io.StringWriter; import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.List; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import org.apache.commons.io.IOUtils; import org.onap.policy.api.PEDependency; import org.onap.policy.common.logging.flexlogger.FlexLogger; @@ -50,15 +51,11 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - @Controller -public class BRMSDictionaryController{ +public class BRMSDictionaryController { - private static final Logger LOGGER = FlexLogger.getLogger(BRMSDictionaryController.class); + private static final Logger LOGGER = FlexLogger.getLogger(BRMSDictionaryController.class); private static final String VALIDATIONRESPONSE = "Validation"; @@ -67,9 +64,9 @@ public class BRMSDictionaryController{ private static String successMsg = "Success"; private static String duplicateResponseString = "Duplicate"; private static String ruleName = "ruleName"; - private static String errorMessage = "Error"; + private static String errorMessage = "Error"; private static String operation = "operation"; - private static String dictionaryFields ="dictionaryFields"; + private static String dictionaryFields = "dictionaryFields"; private static String userid = "userid"; private static String dependencyName = "dependencyName"; private static String controllerName = "controllerName"; @@ -78,7 +75,7 @@ public class BRMSDictionaryController{ private static String brmsControllerDatas = "brmsControllerDictionaryDatas"; @Autowired - public BRMSDictionaryController(CommonClassDao commonClassDao){ + public BRMSDictionaryController(CommonClassDao commonClassDao) { BRMSDictionaryController.commonClassDao = commonClassDao; } @@ -90,32 +87,36 @@ public class BRMSDictionaryController{ super(); } - private DictionaryUtils getDictionaryUtilsInstance(){ + private DictionaryUtils getDictionaryUtilsInstance() { return DictionaryUtils.getDictionaryUtils(); } - @RequestMapping(value={"/get_BRMSParamDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getBRMSParamDictionaryByNameEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_BRMSParamDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getBRMSParamDictionaryByNameEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, brmsParamDatas, ruleName, BRMSParamTemplate.class); } - @RequestMapping(value={"/get_BRMSParamData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getBRMSParamDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_BRMSParamData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getBRMSParamDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, brmsParamDatas, BRMSParamTemplate.class); } - @RequestMapping(value={"/brms_dictionary/set_BRMSParamData"}, method={RequestMethod.POST}) - public static void setRuleData(HttpServletRequest request) throws IOException{ + @RequestMapping(value = {"/brms_dictionary/set_BRMSParamData"}, method = {RequestMethod.POST}) + public static void setRuleData(HttpServletRequest request) throws IOException { StringWriter writer = new StringWriter(); - IOUtils.copy(request.getInputStream() , writer, StandardCharsets.UTF_8); - String cleanStreamBoundary = writer.toString().replaceFirst("------(.*)(?s).*octet-stream", ""); - rule = cleanStreamBoundary.substring(0, cleanStreamBoundary.lastIndexOf("end")+4); + IOUtils.copy(request.getInputStream(), writer, StandardCharsets.UTF_8); + String cleanStreamBoundary = + writer.toString().replaceFirst("------(.*)(?s).*octet-stream", ""); + rule = cleanStreamBoundary.substring(0, cleanStreamBoundary.lastIndexOf("end") + 4); } - @RequestMapping(value={"/brms_dictionary/save_BRMSParam"}, method={RequestMethod.POST}) - public ModelAndView saveBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/brms_dictionary/save_BRMSParam"}, method = {RequestMethod.POST}) + public ModelAndView saveBRMSParamDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -125,83 +126,96 @@ public class BRMSDictionaryController{ BRMSParamTemplate bRMSParamTemplateData; String userId = null; - if(fromAPI){ - bRMSParamTemplateData = mapper.readValue(root.get(dictionaryFields).toString(), BRMSParamTemplate.class); + if (fromAPI) { + bRMSParamTemplateData = mapper.readValue(root.get(dictionaryFields).toString(), + BRMSParamTemplate.class); userId = "API"; - }else{ - bRMSParamTemplateData = mapper.readValue(root.get("brmsParamDictionaryData").toString(), BRMSParamTemplate.class); + } else { + bRMSParamTemplateData = mapper.readValue( + root.get("brmsParamDictionaryData").toString(), BRMSParamTemplate.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(bRMSParamTemplateData.getRuleName(), ruleName, BRMSParamTemplate.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry( + bRMSParamTemplateData.getRuleName(), ruleName, BRMSParamTemplate.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { BRMSParamTemplate data = (BRMSParamTemplate) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { bRMSParamTemplateData.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != bRMSParamTemplateData.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != bRMSParamTemplateData.getId()))) { duplicateflag = true; } } String responseString = null; boolean validation = false; - if(rule != null && CreateBRMSRuleTemplate.validateRuleParams(rule)){ + if (rule != null && CreateBRMSRuleTemplate.validateRuleParams(rule)) { bRMSParamTemplateData.setRule(rule); validation = true; - if(!duplicateflag){ - if(bRMSParamTemplateData.getId() == 0){ + if (!duplicateflag) { + if (bRMSParamTemplateData.getId() == 0) { bRMSParamTemplateData.setUserCreatedBy(userInfo); commonClassDao.save(bRMSParamTemplateData); - }else{ + } else { commonClassDao.update(bRMSParamTemplateData); } - responseString = mapper.writeValueAsString(commonClassDao.getData(BRMSParamTemplate.class)); - }else{ + responseString = mapper + .writeValueAsString(commonClassDao.getData(BRMSParamTemplate.class)); + } else { responseString = duplicateResponseString; } } - if(!validation){ + if (!validation) { responseString = VALIDATIONRESPONSE; } - if(fromAPI){ - if (responseString!=null && !(duplicateResponseString).equals(responseString) && !VALIDATIONRESPONSE.equals(responseString)) { + if (fromAPI) { + if (responseString != null && !(duplicateResponseString).equals(responseString) + && !VALIDATIONRESPONSE.equals(responseString)) { responseString = successMsg; } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; - }else{ + } else { utils.setResponseData(response, brmsParamDatas, responseString); } - }catch(Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/brms_dictionary/remove_brmsParam"}, method={RequestMethod.POST}) - public void removeBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response)throws IOException { + @RequestMapping(value = {"/brms_dictionary/remove_brmsParam"}, method = {RequestMethod.POST}) + public void removeBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, brmsParamDatas, BRMSParamTemplate.class); } - @RequestMapping(value={"/get_BRMSDependencyDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getBRMSDependencyDictionaryByNameEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_BRMSDependencyDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getBRMSDependencyDictionaryByNameEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, brmsDependencyDatas, dependencyName, BRMSDependency.class); } - - @RequestMapping(value={"/get_BRMSDependencyData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getBRMSDependencyDictionaryEntityData(HttpServletResponse response){ + + @RequestMapping(value = {"/get_BRMSDependencyData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getBRMSDependencyDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, brmsDependencyDatas, BRMSDependency.class); } - - @RequestMapping(value={"/brms_dictionary/save_BRMSDependencyData"}, method={RequestMethod.POST}) - public ModelAndView saveBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + + @RequestMapping(value = {"/brms_dictionary/save_BRMSDependencyData"}, + method = {RequestMethod.POST}) + public ModelAndView saveBRMSDependencyDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { LOGGER.debug("DictionaryController: saveBRMSDependencyDictionary() is called"); @@ -212,91 +226,109 @@ public class BRMSDictionaryController{ BRMSDependency brmsDependency; String userId = null; - if(fromAPI){ - brmsDependency = mapper.readValue(root.get(dictionaryFields).toString(), BRMSDependency.class); + if (fromAPI) { + brmsDependency = mapper.readValue(root.get(dictionaryFields).toString(), + BRMSDependency.class); userId = "API"; - }else{ - brmsDependency = mapper.readValue(root.get("brmsDependencyDictionaryData").toString(), BRMSDependency.class); + } else { + brmsDependency = mapper.readValue( + root.get("brmsDependencyDictionaryData").toString(), BRMSDependency.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(brmsDependency.getDependencyName(), dependencyName, BRMSDependency.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry( + brmsDependency.getDependencyName(), dependencyName, BRMSDependency.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { BRMSDependency data = (BRMSDependency) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { brmsDependency.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != brmsDependency.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != brmsDependency.getId()))) { duplicateflag = true; } } LOGGER.audit("the userId from the onap portal is: " + userId); String responseString = null; - if(brmsDependency.getDependency()!=null && !("").equals(brmsDependency.getDependency().trim())){ + if (brmsDependency.getDependency() != null + && !("").equals(brmsDependency.getDependency().trim())) { PEDependency dependency = null; - try{ - dependency = PolicyUtils.jsonStringToObject(brmsDependency.getDependency(), PEDependency.class); - }catch(Exception e){ - LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "wrong data given for BRMS PEDependency Dictionary : " + brmsDependency.getDependency(),e); + try { + dependency = PolicyUtils.jsonStringToObject(brmsDependency.getDependency(), + PEDependency.class); + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + + "wrong data given for BRMS PEDependency Dictionary : " + + brmsDependency.getDependency(), e); } - if(dependency==null){ + if (dependency == null) { responseString = errorMessage; - }else{ - if(!duplicateflag){ + } else { + if (!duplicateflag) { brmsDependency.setUserModifiedBy(userInfo); - if(brmsDependency.getId() == 0){ + if (brmsDependency.getId() == 0) { brmsDependency.setUserCreatedBy(userInfo); commonClassDao.save(brmsDependency); - }else{ + } else { brmsDependency.setModifiedDate(new Date()); commonClassDao.update(brmsDependency); } - responseString = mapper.writeValueAsString(commonClassDao.getData(BRMSDependency.class)); - }else{ + responseString = mapper + .writeValueAsString(commonClassDao.getData(BRMSDependency.class)); + } else { responseString = duplicateResponseString; } } } - if(fromAPI){ - if(responseString!=null && !duplicateResponseString.equals(responseString) && !errorMessage.equals(responseString)){ + if (fromAPI) { + if (responseString != null && !duplicateResponseString.equals(responseString) + && !errorMessage.equals(responseString)) { responseString = successMsg; } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; - }else{ + } else { utils.setResponseData(response, brmsDependencyDatas, responseString); } - } catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - - @RequestMapping(value={"/brms_dictionary/remove_brmsDependency"}, method={RequestMethod.POST}) - public void removeBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + + @RequestMapping(value = {"/brms_dictionary/remove_brmsDependency"}, + method = {RequestMethod.POST}) + public void removeBRMSDependencyDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, brmsDependencyDatas, BRMSDependency.class); } - - - @RequestMapping(value={"/get_BRMSControllerDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getBRMSControllerDictionaryByNameEntityData(HttpServletResponse response){ + + + @RequestMapping(value = {"/get_BRMSControllerDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getBRMSControllerDictionaryByNameEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, brmsControllerDatas, controllerName, BRMSController.class); } - - @RequestMapping(value={"/get_BRMSControllerData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getBRMSControllerDictionaryEntityData(HttpServletResponse response){ + + @RequestMapping(value = {"/get_BRMSControllerData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getBRMSControllerDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, brmsControllerDatas, BRMSController.class); } - - @RequestMapping(value={"/brms_dictionary/save_BRMSControllerData"}, method={RequestMethod.POST}) - public ModelAndView saveBRMSControllerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + + @RequestMapping(value = {"/brms_dictionary/save_BRMSControllerData"}, + method = {RequestMethod.POST}) + public ModelAndView saveBRMSControllerDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { LOGGER.debug("DictionaryController: saveBRMSControllerDictionary() is called"); @@ -306,79 +338,95 @@ public class BRMSDictionaryController{ JsonNode root = mapper.readTree(request.getReader()); BRMSController brmsController; String userId = null; - if(fromAPI){ - brmsController = mapper.readValue(root.get(dictionaryFields).toString(), BRMSController.class); + if (fromAPI) { + brmsController = mapper.readValue(root.get(dictionaryFields).toString(), + BRMSController.class); userId = "API"; - }else{ - brmsController = mapper.readValue(root.get("brmsControllerDictionaryData").toString(), BRMSController.class); + } else { + brmsController = mapper.readValue( + root.get("brmsControllerDictionaryData").toString(), BRMSController.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(brmsController.getControllerName(), controllerName, BRMSController.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry( + brmsController.getControllerName(), controllerName, BRMSController.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { BRMSController data = (BRMSController) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { brmsController.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != brmsController.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != brmsController.getId()))) { duplicateflag = true; } } String responseString = null; - if(brmsController.getController()!=null && !("").equals(brmsController.getController().trim())){ + if (brmsController.getController() != null + && !("").equals(brmsController.getController().trim())) { PEDependency dependency = null; - try{ - dependency = PolicyUtils.jsonStringToObject(brmsController.getController(), PEDependency.class); - }catch(Exception e){ - LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "wrong data given for BRMS Controller Dictionary : " + brmsController.getController(),e); + try { + dependency = PolicyUtils.jsonStringToObject(brmsController.getController(), + PEDependency.class); + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + + "wrong data given for BRMS Controller Dictionary : " + + brmsController.getController(), e); } - if(dependency==null){ + if (dependency == null) { responseString = errorMessage; - }else{ - if(!duplicateflag){ + } else { + if (!duplicateflag) { brmsController.setUserModifiedBy(userInfo); - if(brmsController.getId() == 0){ + if (brmsController.getId() == 0) { brmsController.setUserCreatedBy(userInfo); commonClassDao.save(brmsController); - }else{ + } else { brmsController.setModifiedDate(new Date()); commonClassDao.update(brmsController); } - responseString = mapper.writeValueAsString(commonClassDao.getData(OnapName.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(OnapName.class)); + } else { responseString = duplicateResponseString; } } } - if(fromAPI){ - if (responseString!=null && !(duplicateResponseString).equals(responseString) && !(errorMessage).equals(responseString)) { + if (fromAPI) { + if (responseString != null && !(duplicateResponseString).equals(responseString) + && !(errorMessage).equals(responseString)) { responseString = successMsg; } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; - }else{ + } else { utils.setResponseData(response, brmsControllerDatas, responseString); } - } catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - - @RequestMapping(value={"/brms_dictionary/remove_brmsController"}, method={RequestMethod.POST}) - public void removeBRMSControllerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + + @RequestMapping(value = {"/brms_dictionary/remove_brmsController"}, + method = {RequestMethod.POST}) + public void removeBRMSControllerDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, brmsControllerDatas, BRMSController.class); } - - public BRMSDependency getDependencyDataByID(String dependencyName){ - return (BRMSDependency) commonClassDao.getEntityItem(BRMSDependency.class, BRMSDictionaryController.dependencyName, dependencyName); + + public BRMSDependency getDependencyDataByID(String dependencyName) { + return (BRMSDependency) commonClassDao.getEntityItem(BRMSDependency.class, + BRMSDictionaryController.dependencyName, dependencyName); + } + + public BRMSController getControllerDataByID(String controllerName) { + return (BRMSController) commonClassDao.getEntityItem(BRMSController.class, + BRMSDictionaryController.controllerName, controllerName); } - - public BRMSController getControllerDataByID(String controllerName){ - return (BRMSController) commonClassDao.getEntityItem(BRMSController.class, BRMSDictionaryController.controllerName, controllerName); - } } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java index 5e7113ad8..2aec0cc0d 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.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,13 +20,14 @@ package org.onap.policy.pap.xacml.rest.controller; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.Date; import java.util.List; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import org.onap.policy.pap.xacml.rest.adapters.GridData; import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl; import org.onap.policy.pap.xacml.rest.util.DictionaryUtils; @@ -46,12 +47,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - @Controller -public class ClosedLoopDictionaryController{ +public class ClosedLoopDictionaryController { private static CommonClassDao commonClassDao; private static String vsclaction = "vsclaction"; @@ -72,11 +69,11 @@ public class ClosedLoopDictionaryController{ private static String closedLoopSiteDatas = "closedLoopSiteDictionaryDatas"; @Autowired - public ClosedLoopDictionaryController(CommonClassDao commonClassDao){ + public ClosedLoopDictionaryController(CommonClassDao commonClassDao) { ClosedLoopDictionaryController.commonClassDao = commonClassDao; } - public void setCommonClassDao(CommonClassDao commonClassDao){ + public void setCommonClassDao(CommonClassDao commonClassDao) { ClosedLoopDictionaryController.commonClassDao = commonClassDao; } @@ -84,89 +81,102 @@ public class ClosedLoopDictionaryController{ commonClassDao = commonClassDaoImpl; } - public ClosedLoopDictionaryController(){ + public ClosedLoopDictionaryController() { super(); } - private DictionaryUtils getDictionaryUtilsInstance(){ + private DictionaryUtils getDictionaryUtilsInstance() { return DictionaryUtils.getDictionaryUtils(); } - @RequestMapping(value={"/get_VSCLActionDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getVSCLActionDictionaryByNameEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_VSCLActionDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getVSCLActionDictionaryByNameEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, vsclActionDatas, vsclaction, VSCLAction.class); } - @RequestMapping(value={"/get_VSCLActionData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getVSCLActionDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_VSCLActionData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getVSCLActionDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, vsclActionDatas, VSCLAction.class); } - @RequestMapping(value={"/get_VNFTypeDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getVNFTypeDictionaryByNameEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_VNFTypeDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getVNFTypeDictionaryByNameEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, vnfTypeDatas, vnftype, VNFType.class); } - @RequestMapping(value={"/get_VNFTypeData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getVNFTypeDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_VNFTypeData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getVNFTypeDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, vnfTypeDatas, VNFType.class); } - @RequestMapping(value={"/get_PEPOptionsDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPEPOptionsDictionaryByNameEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_PEPOptionsDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getPEPOptionsDictionaryByNameEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, pepOptionDatas, pepName, PEPOptions.class); } - @RequestMapping(value={"/get_PEPOptionsData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPEPOptionsDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_PEPOptionsData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getPEPOptionsDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, pepOptionDatas, PEPOptions.class); } - @RequestMapping(value={"/get_VarbindDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getVarbindDictionaryByNameEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_VarbindDictionaryDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getVarbindDictionaryByNameEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, varbindDatas, varbindName, VarbindDictionary.class); } - @RequestMapping(value={"/get_VarbindDictionaryData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getVarbindDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_VarbindDictionaryData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getVarbindDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, varbindDatas, VarbindDictionary.class); } - @RequestMapping(value={"/get_ClosedLoopServicesDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_ClosedLoopServicesDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, closedLoopDatas, serviceName, ClosedLoopD2Services.class); } - @RequestMapping(value={"/get_ClosedLoopServicesData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getClosedLoopServiceDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_ClosedLoopServicesData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getClosedLoopServiceDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, closedLoopDatas, ClosedLoopD2Services.class); } - @RequestMapping(value={"/get_ClosedLoopSiteDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_ClosedLoopSiteDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, closedLoopSiteDatas, siteName, ClosedLoopSite.class); } - @RequestMapping(value={"/get_ClosedLoopSiteData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getClosedLoopSiteDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_ClosedLoopSiteData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getClosedLoopSiteDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, closedLoopSiteDatas, ClosedLoopSite.class); } - @RequestMapping(value={"/cl_dictionary/save_vsclAction"}, method={RequestMethod.POST}) - public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response)throws IOException{ + @RequestMapping(value = {"/cl_dictionary/save_vsclAction"}, method = {RequestMethod.POST}) + public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -176,59 +186,68 @@ public class ClosedLoopDictionaryController{ VSCLAction vSCLAction; String userId = null; if (fromAPI) { - vSCLAction = mapper.readValue(root.get(dictionaryFields).toString(), VSCLAction.class); + vSCLAction = + mapper.readValue(root.get(dictionaryFields).toString(), VSCLAction.class); userId = "API"; } else { - vSCLAction = mapper.readValue(root.get("vsclActionDictionaryData").toString(), VSCLAction.class); + vSCLAction = mapper.readValue(root.get("vsclActionDictionaryData").toString(), + VSCLAction.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class); + List<Object> duplicateData = commonClassDao + .checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { VSCLAction data = (VSCLAction) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { vSCLAction.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != vSCLAction.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != vSCLAction.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ + if (!duplicateflag) { vSCLAction.setUserModifiedBy(userInfo); - if(vSCLAction.getId() == 0){ + if (vSCLAction.getId() == 0) { vSCLAction.setUserCreatedBy(userInfo); commonClassDao.save(vSCLAction); - }else{ + } else { vSCLAction.setModifiedDate(new Date()); commonClassDao.update(vSCLAction); } - responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, vsclActionDatas, responseString); } - }catch(Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/cl_dictionary/remove_VsclAction"}, method={RequestMethod.POST}) - public void removeVSCLAction(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/cl_dictionary/remove_VsclAction"}, method = {RequestMethod.POST}) + public void removeVSCLAction(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, vsclActionDatas, OnapName.class); } - @RequestMapping(value={"/cl_dictionary/save_vnfType"}, method={RequestMethod.POST}) - public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/cl_dictionary/save_vnfType"}, method = {RequestMethod.POST}) + public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -241,56 +260,63 @@ public class ClosedLoopDictionaryController{ vNFType = mapper.readValue(root.get(dictionaryFields).toString(), VNFType.class); userId = "API"; } else { - vNFType = mapper.readValue(root.get("vnfTypeDictionaryData").toString(), VNFType.class); + vNFType = mapper.readValue(root.get("vnfTypeDictionaryData").toString(), + VNFType.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), vnftype, VNFType.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), + vnftype, VNFType.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { VNFType data = (VNFType) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { vNFType.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != vNFType.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != vNFType.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ + if (!duplicateflag) { vNFType.setUserModifiedBy(userInfo); - if(vNFType.getId() == 0){ + if (vNFType.getId() == 0) { vNFType.setUserCreatedBy(userInfo); commonClassDao.save(vNFType); - }else{ + } else { vNFType.setModifiedDate(new Date()); commonClassDao.update(vNFType); } responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class)); - }else{ + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, vnfTypeDatas, responseString); } - }catch(Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/cl_dictionary/remove_vnfType"}, method={RequestMethod.POST}) - public void removeVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/cl_dictionary/remove_vnfType"}, method = {RequestMethod.POST}) + public void removeVnfType(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, vnfTypeDatas, VNFType.class); } - @RequestMapping(value={"/cl_dictionary/save_pepOptions"}, method={RequestMethod.POST}) - public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/cl_dictionary/save_pepOptions"}, method = {RequestMethod.POST}) + public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -300,66 +326,76 @@ public class ClosedLoopDictionaryController{ PEPOptions pEPOptions; GridData gridData; String userId = null; - if(fromAPI){ - pEPOptions = mapper.readValue(root.get(dictionaryFields).toString(), PEPOptions.class); + if (fromAPI) { + pEPOptions = + mapper.readValue(root.get(dictionaryFields).toString(), PEPOptions.class); gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class); userId = "API"; - }else{ - pEPOptions = mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class); - gridData = mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class); + } else { + pEPOptions = mapper.readValue(root.get("pepOptionsDictionaryData").toString(), + PEPOptions.class); + gridData = mapper.readValue(root.get("pepOptionsDictionaryData").toString(), + GridData.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); - - if(!gridData.getAttributes().isEmpty()){ + + if (!gridData.getAttributes().isEmpty()) { pEPOptions.setActions(utils.appendKeyValue(gridData.getAttributes(), ":#@", "=#@")); } - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), + pepName, PEPOptions.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { PEPOptions data = (PEPOptions) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { pEPOptions.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != pEPOptions.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != pEPOptions.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ + if (!duplicateflag) { pEPOptions.setUserModifiedBy(userInfo); - if(pEPOptions.getId() == 0){ + if (pEPOptions.getId() == 0) { pEPOptions.setUserCreatedBy(userInfo); commonClassDao.save(pEPOptions); - }else{ + } else { pEPOptions.setModifiedDate(new Date()); commonClassDao.update(pEPOptions); } - responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, pepOptionDatas, responseString); } - }catch(Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/cl_dictionary/remove_pepOptions"}, method={RequestMethod.POST}) - public void removePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/cl_dictionary/remove_pepOptions"}, method = {RequestMethod.POST}) + public void removePEPOptions(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, pepOptionDatas, VNFType.class); } - @RequestMapping(value={"/cl_dictionary/save_service"}, method={RequestMethod.POST}) - public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/cl_dictionary/save_service"}, method = {RequestMethod.POST}) + public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -368,59 +404,69 @@ public class ClosedLoopDictionaryController{ JsonNode root = mapper.readTree(request.getReader()); ClosedLoopD2Services serviceData; String userId = null; - if(fromAPI){ - serviceData = mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopD2Services.class); + if (fromAPI) { + serviceData = mapper.readValue(root.get(dictionaryFields).toString(), + ClosedLoopD2Services.class); userId = "API"; } else { - serviceData = mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class); + serviceData = + mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), + ClosedLoopD2Services.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry( + serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { serviceData.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != serviceData.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != serviceData.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ + if (!duplicateflag) { serviceData.setUserModifiedBy(userInfo); - if(serviceData.getId() == 0){ + if (serviceData.getId() == 0) { serviceData.setUserCreatedBy(userInfo); commonClassDao.save(serviceData); - }else{ + } else { serviceData.setModifiedDate(new Date()); commonClassDao.update(serviceData); } - responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)); - }else{ + responseString = mapper + .writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, closedLoopDatas, responseString); } - }catch(Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/cl_dictionary/remove_Service"}, method={RequestMethod.POST}) - public void removeServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/cl_dictionary/remove_Service"}, method = {RequestMethod.POST}) + public void removeServiceType(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, closedLoopDatas, VNFType.class); } - @RequestMapping(value={"/cl_dictionary/save_siteName"}, method={RequestMethod.POST}) - public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/cl_dictionary/save_siteName"}, method = {RequestMethod.POST}) + public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -429,59 +475,68 @@ public class ClosedLoopDictionaryController{ JsonNode root = mapper.readTree(request.getReader()); ClosedLoopSite siteData; String userId = null; - if(fromAPI){ - siteData = mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopSite.class); + if (fromAPI) { + siteData = mapper.readValue(root.get(dictionaryFields).toString(), + ClosedLoopSite.class); userId = "API"; - }else{ - siteData = mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), ClosedLoopSite.class); + } else { + siteData = mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), + ClosedLoopSite.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); - - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), siteName, ClosedLoopSite.class); + + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), + siteName, ClosedLoopSite.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { ClosedLoopSite data = (ClosedLoopSite) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { siteData.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != siteData.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != siteData.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ + if (!duplicateflag) { siteData.setUserModifiedBy(userInfo); - if(siteData.getId() == 0){ + if (siteData.getId() == 0) { siteData.setUserCreatedBy(userInfo); commonClassDao.save(siteData); - }else{ + } else { siteData.setModifiedDate(new Date()); commonClassDao.update(siteData); } - responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, closedLoopSiteDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/cl_dictionary/remove_site"}, method={RequestMethod.POST}) - public void removeSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/cl_dictionary/remove_site"}, method = {RequestMethod.POST}) + public void removeSiteType(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, closedLoopSiteDatas, VNFType.class); } - @RequestMapping(value={"/cl_dictionary/save_varbind"}, method={RequestMethod.POST}) - public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/cl_dictionary/save_varbind"}, method = {RequestMethod.POST}) + public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -490,55 +545,63 @@ public class ClosedLoopDictionaryController{ JsonNode root = mapper.readTree(request.getReader()); VarbindDictionary varbindDictionary; String userId = null; - if(fromAPI){ - varbindDictionary = mapper.readValue(root.get(dictionaryFields).toString(), VarbindDictionary.class); + if (fromAPI) { + varbindDictionary = mapper.readValue(root.get(dictionaryFields).toString(), + VarbindDictionary.class); userId = "API"; - }else{ - varbindDictionary = mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class); + } else { + varbindDictionary = mapper.readValue(root.get("varbindDictionaryData").toString(), + VarbindDictionary.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry( + varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { VarbindDictionary data = (VarbindDictionary) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { varbindDictionary.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != varbindDictionary.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != varbindDictionary.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ + if (!duplicateflag) { varbindDictionary.setUserModifiedBy(userInfo); - if(varbindDictionary.getId() == 0){ + if (varbindDictionary.getId() == 0) { varbindDictionary.setUserCreatedBy(userInfo); commonClassDao.save(varbindDictionary); - }else{ + } else { varbindDictionary.setModifiedDate(new Date()); commonClassDao.update(varbindDictionary); } - responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, varbindDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/cl_dictionary/remove_varbindDict"}, method={RequestMethod.POST}) - public void removeVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/cl_dictionary/remove_varbindDict"}, method = {RequestMethod.POST}) + public void removeVarbind(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, varbindDatas, VNFType.class); } -}
\ No newline at end of file +} diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java index 738a808f6..c89d21e91 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.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,14 +20,15 @@ package org.onap.policy.pap.xacml.rest.controller; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.List; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import org.onap.policy.pap.xacml.rest.util.DictionaryUtils; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.DecisionSettings; @@ -40,10 +41,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - @Controller public class DecisionPolicyDictionaryController { @@ -54,36 +51,40 @@ public class DecisionPolicyDictionaryController { private static String duplicateResponseString = "Duplicate"; private static String settingDatas = "settingsDictionaryDatas"; private static String rainDayDatas = "rainyDayDictionaryDatas"; - private static String dictionaryFields ="dictionaryFields"; + private static String dictionaryFields = "dictionaryFields"; @Autowired - public DecisionPolicyDictionaryController(CommonClassDao commonClassDao){ + public DecisionPolicyDictionaryController(CommonClassDao commonClassDao) { DecisionPolicyDictionaryController.commonClassDao = commonClassDao; } - public DecisionPolicyDictionaryController(){ + public DecisionPolicyDictionaryController() { super(); } - private DictionaryUtils getDictionaryUtilsInstance(){ + private DictionaryUtils getDictionaryUtilsInstance() { return DictionaryUtils.getDictionaryUtils(); } - @RequestMapping(value={"/get_SettingsDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getSettingsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + @RequestMapping(value = {"/get_SettingsDictionaryDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getSettingsDictionaryByNameEntityData(HttpServletRequest request, + HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, settingDatas, xacmlId, DecisionSettings.class); } - @RequestMapping(value={"/get_SettingsDictionaryData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getSettingsDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_SettingsDictionaryData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getSettingsDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, settingDatas, DecisionSettings.class); } - @RequestMapping(value={"/decision_dictionary/save_Settings"}, method={RequestMethod.POST}) - public ModelAndView saveSettingsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/decision_dictionary/save_Settings"}, method = {RequestMethod.POST}) + public ModelAndView saveSettingsDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -93,74 +94,86 @@ public class DecisionPolicyDictionaryController { DecisionSettings decisionSettings; String userId = null; - if(fromAPI){ - decisionSettings = mapper.readValue(root.get(dictionaryFields).toString(), DecisionSettings.class); + if (fromAPI) { + decisionSettings = mapper.readValue(root.get(dictionaryFields).toString(), + DecisionSettings.class); userId = "API"; - }else{ - decisionSettings = mapper.readValue(root.get("settingsDictionaryData").toString(), DecisionSettings.class); + } else { + decisionSettings = mapper.readValue(root.get("settingsDictionaryData").toString(), + DecisionSettings.class); userId = root.get("userid").textValue(); } UserInfo userInfo = utils.getUserInfo(userId); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(decisionSettings.getXacmlId(), xacmlId, DecisionSettings.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry( + decisionSettings.getXacmlId(), xacmlId, DecisionSettings.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { DecisionSettings data = (DecisionSettings) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { decisionSettings.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != decisionSettings.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != decisionSettings.getId()))) { duplicateflag = true; } } - if(decisionSettings.getDatatypeBean().getShortName() != null){ + if (decisionSettings.getDatatypeBean().getShortName() != null) { String datatype = decisionSettings.getDatatypeBean().getShortName(); decisionSettings.setDatatypeBean(utils.getDataType(datatype)); } String responseString = null; - if(!duplicateflag){ + if (!duplicateflag) { decisionSettings.setUserModifiedBy(userInfo); - if(decisionSettings.getId() == 0){ + if (decisionSettings.getId() == 0) { decisionSettings.setUserCreatedBy(userInfo); commonClassDao.save(decisionSettings); - }else{ + } else { decisionSettings.setModifiedDate(new Date()); commonClassDao.update(decisionSettings); } - responseString = mapper.writeValueAsString(commonClassDao.getData(DecisionSettings.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(DecisionSettings.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, settingDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/settings_dictionary/remove_settings"}, method={RequestMethod.POST}) - public void removeSettingsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/settings_dictionary/remove_settings"}, method = {RequestMethod.POST}) + public void removeSettingsDictionary(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, settingDatas, DecisionSettings.class); } - @RequestMapping(value={"/get_RainyDayDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getRainyDayDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + @RequestMapping(value = {"/get_RainyDayDictionaryDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getRainyDayDictionaryByNameEntityData(HttpServletRequest request, + HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, rainDayDatas, bbID, RainyDayTreatments.class); } - @RequestMapping(value={"/get_RainyDayDictionaryData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getRainyDayDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_RainyDayDictionaryData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getRainyDayDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, rainDayDatas, RainyDayTreatments.class); } - @RequestMapping(value={"/decision_dictionary/save_RainyDay"}, method={RequestMethod.POST}) - public ModelAndView saveRainyDayDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/decision_dictionary/save_RainyDay"}, method = {RequestMethod.POST}) + public ModelAndView saveRainyDayDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -169,57 +182,70 @@ public class DecisionPolicyDictionaryController { JsonNode root = mapper.readTree(request.getReader()); RainyDayTreatments decisionRainyDay; TreatmentValues treatmentsData = null; - if(fromAPI){ - decisionRainyDay = mapper.readValue(root.get(dictionaryFields).toString(), RainyDayTreatments.class); - treatmentsData = mapper.readValue(root.get(dictionaryFields).toString(), TreatmentValues.class); - }else{ - decisionRainyDay = mapper.readValue(root.get("rainyDayDictionaryData").toString(), RainyDayTreatments.class); - treatmentsData = mapper.readValue(root.get("rainyDayDictionaryData").toString(), TreatmentValues.class); + if (fromAPI) { + decisionRainyDay = mapper.readValue(root.get(dictionaryFields).toString(), + RainyDayTreatments.class); + treatmentsData = mapper.readValue(root.get(dictionaryFields).toString(), + TreatmentValues.class); + } else { + decisionRainyDay = mapper.readValue(root.get("rainyDayDictionaryData").toString(), + RainyDayTreatments.class); + treatmentsData = mapper.readValue(root.get("rainyDayDictionaryData").toString(), + TreatmentValues.class); } - decisionRainyDay.setTreatments(utils.appendKey(treatmentsData.getUserDataTypeValues(), "treatment", ",")); + decisionRainyDay.setTreatments( + utils.appendKey(treatmentsData.getUserDataTypeValues(), "treatment", ",")); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(decisionRainyDay.getBbid()+":"+decisionRainyDay.getWorkstep(), "bbid:workstep", RainyDayTreatments.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry( + decisionRainyDay.getBbid() + ":" + decisionRainyDay.getWorkstep(), + "bbid:workstep", RainyDayTreatments.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { RainyDayTreatments data = (RainyDayTreatments) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { decisionRainyDay.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != decisionRainyDay.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != decisionRainyDay.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ - if(decisionRainyDay.getId() == 0){ + if (!duplicateflag) { + if (decisionRainyDay.getId() == 0) { commonClassDao.save(decisionRainyDay); - }else{ + } else { commonClassDao.update(decisionRainyDay); } - responseString = mapper.writeValueAsString(commonClassDao.getData(RainyDayTreatments.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(RainyDayTreatments.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, rainDayDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/decision_dictionary/remove_rainyDay"}, method={RequestMethod.POST}) - public void removeRainyDayDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/decision_dictionary/remove_rainyDay"}, method = {RequestMethod.POST}) + public void removeRainyDayDictionary(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, rainDayDatas, RainyDayTreatments.class); } } -class TreatmentValues { + +class TreatmentValues { private List<Object> userDataTypeValues = new ArrayList<>(); public List<Object> getUserDataTypeValues() { diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java index a1d1bc8ff..51c8a1d91 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.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,13 +20,14 @@ package org.onap.policy.pap.xacml.rest.controller; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.Date; import java.util.List; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import org.onap.policy.pap.xacml.rest.adapters.GridData; import org.onap.policy.pap.xacml.rest.util.DictionaryUtils; import org.onap.policy.rest.dao.CommonClassDao; @@ -39,10 +40,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - @Controller public class DescriptiveDictionaryController { @@ -52,36 +49,40 @@ public class DescriptiveDictionaryController { private static String descriptiveDatas = "descriptiveScopeDictionaryDatas"; @Autowired - public DescriptiveDictionaryController(CommonClassDao commonClassDao){ + public DescriptiveDictionaryController(CommonClassDao commonClassDao) { DescriptiveDictionaryController.commonClassDao = commonClassDao; } - public void setCommonClassDao(CommonClassDao commonClassDao){ + public void setCommonClassDao(CommonClassDao commonClassDao) { DescriptiveDictionaryController.commonClassDao = commonClassDao; } - public DescriptiveDictionaryController(){ + public DescriptiveDictionaryController() { super(); } - private DictionaryUtils getDictionaryUtilsInstance(){ + private DictionaryUtils getDictionaryUtilsInstance() { return DictionaryUtils.getDictionaryUtils(); } - @RequestMapping(value={"/get_DescriptiveScopeByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getDescriptiveDictionaryByNameEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_DescriptiveScopeByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getDescriptiveDictionaryByNameEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, descriptiveDatas, dScopeName, DescriptiveScope.class); } - @RequestMapping(value={"/get_DescriptiveScope"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getDescriptiveDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_DescriptiveScope"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getDescriptiveDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, descriptiveDatas, DescriptiveScope.class); } - @RequestMapping(value={"/descriptive_dictionary/save_descriptive"}, method={RequestMethod.POST}) - public ModelAndView saveDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response)throws IOException{ + @RequestMapping(value = {"/descriptive_dictionary/save_descriptive"}, + method = {RequestMethod.POST}) + public ModelAndView saveDescriptiveDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -91,56 +92,67 @@ public class DescriptiveDictionaryController { DescriptiveScope descriptiveScope; GridData data; String userId = null; - if(fromAPI){ - descriptiveScope = mapper.readValue(root.get("dictionaryFields").toString(), DescriptiveScope.class); + if (fromAPI) { + descriptiveScope = mapper.readValue(root.get("dictionaryFields").toString(), + DescriptiveScope.class); data = mapper.readValue(root.get("dictionaryFields").toString(), GridData.class); userId = "API"; - }else{ - descriptiveScope = mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), DescriptiveScope.class); - data = mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), GridData.class); + } else { + descriptiveScope = + mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), + DescriptiveScope.class); + data = mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), + GridData.class); userId = root.get("userid").textValue(); } descriptiveScope.setSearch(utils.appendKeyValue(data.getAttributes(), "AND", ":")); UserInfo userInfo = utils.getUserInfo(userId); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(descriptiveScope.getScopeName(), dScopeName, DescriptiveScope.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry( + descriptiveScope.getScopeName(), dScopeName, DescriptiveScope.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { DescriptiveScope data1 = (DescriptiveScope) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { descriptiveScope.setId(data1.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data1.getId() != descriptiveScope.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data1.getId() != descriptiveScope.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ + if (!duplicateflag) { descriptiveScope.setUserModifiedBy(userInfo); - if(descriptiveScope.getId() == 0){ + if (descriptiveScope.getId() == 0) { descriptiveScope.setUserCreatedBy(userInfo); commonClassDao.save(descriptiveScope); - }else{ + } else { descriptiveScope.setModifiedDate(new Date()); commonClassDao.update(descriptiveScope); } - responseString = mapper.writeValueAsString(commonClassDao.getData(DescriptiveScope.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(DescriptiveScope.class)); + } else { responseString = "Duplicate"; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, descriptiveDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/descriptive_dictionary/remove_descriptiveScope"}, method={RequestMethod.POST}) - public void removeDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/descriptive_dictionary/remove_descriptiveScope"}, + method = {RequestMethod.POST}) + public void removeDescriptiveDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, descriptiveDatas, DescriptiveScope.class); } -}
\ No newline at end of file +} diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryController.java index 72539880c..94275e7c1 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryController.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,13 +20,14 @@ package org.onap.policy.pap.xacml.rest.controller; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.Date; import java.util.List; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.onap.policy.pap.xacml.rest.util.DictionaryUtils; @@ -41,52 +42,51 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - @Controller public class DictionaryController { - private static final Log LOGGER = LogFactory.getLog(DictionaryController.class); + private static final Log LOGGER = LogFactory.getLog(DictionaryController.class); private static CommonClassDao commonClassDao; private static String xacmlId = "xacmlId"; private static String operation = "operation"; - private static String dictionaryFields ="dictionaryFields"; + private static String dictionaryFields = "dictionaryFields"; private static String duplicateResponseString = "Duplicate"; private static String onapName = "onapName"; private static String attributeDatas = "attributeDictionaryDatas"; private static String onapNameDatas = "onapNameDictionaryDatas"; @Autowired - public DictionaryController(CommonClassDao commonClassDao){ + public DictionaryController(CommonClassDao commonClassDao) { DictionaryController.commonClassDao = commonClassDao; } - public DictionaryController(){ + public DictionaryController() { super(); } - private DictionaryUtils getDictionaryUtilsInstance(){ + private DictionaryUtils getDictionaryUtilsInstance() { return DictionaryUtils.getDictionaryUtils(); } - @RequestMapping(value={"/get_AttributeDatabyAttributeName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getAttributeDictionaryEntityDatabyAttributeName(HttpServletResponse response){ + @RequestMapping(value = {"/get_AttributeDatabyAttributeName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getAttributeDictionaryEntityDatabyAttributeName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, attributeDatas, xacmlId, Attribute.class); } - //Attribute Dictionary - @RequestMapping(value="/get_AttributeData", method= RequestMethod.GET , produces=MediaType.APPLICATION_JSON_VALUE) - public void getAttributeDictionaryEntityData(HttpServletResponse response){ + // Attribute Dictionary + @RequestMapping(value = "/get_AttributeData", method = RequestMethod.GET, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getAttributeDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, attributeDatas, Attribute.class); } - @RequestMapping(value={"/attribute_dictionary/save_attribute"}, method={RequestMethod.POST}) - public ModelAndView saveAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/attribute_dictionary/save_attribute"}, method = {RequestMethod.POST}) + public ModelAndView saveAttributeDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -96,84 +96,99 @@ public class DictionaryController { Attribute attributeData = null; AttributeValues attributeValueData = null; String userId = null; - if(fromAPI){ - attributeData = mapper.readValue(root.get(dictionaryFields).toString(), Attribute.class); - attributeValueData = mapper.readValue(root.get(dictionaryFields).toString(), AttributeValues.class); + if (fromAPI) { + attributeData = + mapper.readValue(root.get(dictionaryFields).toString(), Attribute.class); + attributeValueData = mapper.readValue(root.get(dictionaryFields).toString(), + AttributeValues.class); userId = "API"; - }else{ - attributeData = mapper.readValue(root.get("attributeDictionaryData").toString(), Attribute.class); - attributeValueData = mapper.readValue(root.get("attributeDictionaryData").toString(), AttributeValues.class); + } else { + attributeData = mapper.readValue(root.get("attributeDictionaryData").toString(), + Attribute.class); + attributeValueData = mapper.readValue( + root.get("attributeDictionaryData").toString(), AttributeValues.class); userId = root.get("userid").textValue(); } UserInfo userInfo = utils.getUserInfo(userId); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(attributeData.getXacmlId(), xacmlId, Attribute.class); + List<Object> duplicateData = commonClassDao + .checkDuplicateEntry(attributeData.getXacmlId(), xacmlId, Attribute.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { Attribute data = (Attribute) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { attributeData.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != attributeData.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != attributeData.getId()))) { duplicateflag = true; } } - if(attributeValueData.getUserDataTypeValues() != null && !attributeValueData.getUserDataTypeValues().isEmpty()){ - attributeData.setAttributeValue(utils.appendKey(attributeValueData.getUserDataTypeValues(), "attributeValues", ",")); + if (attributeValueData.getUserDataTypeValues() != null + && !attributeValueData.getUserDataTypeValues().isEmpty()) { + attributeData.setAttributeValue(utils.appendKey( + attributeValueData.getUserDataTypeValues(), "attributeValues", ",")); } - if(attributeData.getDatatypeBean().getShortName() != null){ + if (attributeData.getDatatypeBean().getShortName() != null) { String datatype = attributeData.getDatatypeBean().getShortName(); attributeData.setDatatypeBean(utils.getDataType(datatype)); } String responseString = null; - if(!duplicateflag){ + if (!duplicateflag) { attributeData.setUserModifiedBy(userInfo); - if(attributeData.getId() == 0){ + if (attributeData.getId() == 0) { attributeData.setCategoryBean(utils.getCategory()); attributeData.setUserCreatedBy(userInfo); commonClassDao.save(attributeData); - }else{ + } else { attributeData.setModifiedDate(new Date()); commonClassDao.update(attributeData); } responseString = mapper.writeValueAsString(commonClassDao.getData(Attribute.class)); - }else{ + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, attributeDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/attribute_dictionary/remove_attribute"}, method={RequestMethod.POST}) - public void removeAttributeDictionary(HttpServletRequest request, HttpServletResponse response)throws IOException { + @RequestMapping(value = {"/attribute_dictionary/remove_attribute"}, + method = {RequestMethod.POST}) + public void removeAttributeDictionary(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, attributeDatas, Attribute.class); } - //OnapName Dictionary - @RequestMapping(value={"/get_OnapNameDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getOnapNameDictionaryByNameEntityData(HttpServletResponse response){ + // OnapName Dictionary + @RequestMapping(value = {"/get_OnapNameDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getOnapNameDictionaryByNameEntityData(HttpServletResponse response) { LOGGER.info("get_OnapNameDataByName is called"); DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, onapNameDatas, onapName, OnapName.class); } - @RequestMapping(value={"/get_OnapNameData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getOnapNameDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_OnapNameData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getOnapNameDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, onapNameDatas, OnapName.class); } - @RequestMapping(value={"/onap_dictionary/save_onapName"}, method={RequestMethod.POST}) - public ModelAndView saveOnapDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/onap_dictionary/save_onapName"}, method = {RequestMethod.POST}) + public ModelAndView saveOnapDictionary(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -182,59 +197,66 @@ public class DictionaryController { JsonNode root = mapper.readTree(request.getReader()); OnapName onapData; String userId = null; - if(fromAPI){ + if (fromAPI) { onapData = mapper.readValue(root.get(dictionaryFields).toString(), OnapName.class); userId = "API"; - }else{ - onapData = mapper.readValue(root.get("onapNameDictionaryData").toString(), OnapName.class); + } else { + onapData = mapper.readValue(root.get("onapNameDictionaryData").toString(), + OnapName.class); userId = root.get("userid").textValue(); } UserInfo userInfo = utils.getUserInfo(userId); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getOnapName(), onapName, OnapName.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getOnapName(), + onapName, OnapName.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { OnapName data = (OnapName) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { onapData.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != onapData.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != onapData.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ + if (!duplicateflag) { onapData.setUserModifiedBy(userInfo); - if(onapData.getId() == 0){ + if (onapData.getId() == 0) { onapData.setUserCreatedBy(userInfo); commonClassDao.save(onapData); - }else{ + } else { onapData.setModifiedDate(new Date()); commonClassDao.update(onapData); } responseString = mapper.writeValueAsString(commonClassDao.getData(OnapName.class)); - }else{ + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, onapNameDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/onap_dictionary/remove_onap"}, method={RequestMethod.POST}) - public void removeOnapDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/onap_dictionary/remove_onap"}, method = {RequestMethod.POST}) + public void removeOnapDictionary(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, onapNameDatas, OnapName.class); } } -class AttributeValues{ + +class AttributeValues { private List<Object> userDataTypeValues; public List<Object> getUserDataTypeValues() { @@ -244,4 +266,4 @@ class AttributeValues{ public void setUserDataTypeValues(List<Object> userDataTypeValues) { this.userDataTypeValues = userDataTypeValues; } -}
\ No newline at end of file +} 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..b42731d61 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,16 +20,17 @@ 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; import java.io.IOException; 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.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; @@ -67,23 +68,18 @@ 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 +87,19 @@ 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 +107,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<String[]> 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<rows.length; j++ ){ - if("xacml_id".equalsIgnoreCase(dictSheet.get(0)[j]) || "Attribute ID".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("xacml_id".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Attribute ID".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setXacmlId(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } - if("priority".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("priority".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setPriority(rows[j]); } - if("datatype".equalsIgnoreCase(dictSheet.get(0)[j]) || "Data Type".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("datatype".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Data Type".equalsIgnoreCase(dictSheet.get(0)[j])) { Datatype dataType = new Datatype(); - if("string".equalsIgnoreCase(rows[j])){ + if ("string".equalsIgnoreCase(rows[j])) { dataType.setId(26); - }else if("integer".equalsIgnoreCase(rows[j])){ + } else if ("integer".equalsIgnoreCase(rows[j])) { dataType.setId(12); - }else if("double".equalsIgnoreCase(rows[j])){ + } else if ("double".equalsIgnoreCase(rows[j])) { dataType.setId(25); - }else if("boolean".equalsIgnoreCase(rows[j])){ + } else if ("boolean".equalsIgnoreCase(rows[j])) { dataType.setId(18); - }else if("user".equalsIgnoreCase(rows[j])){ + } else if ("user".equalsIgnoreCase(rows[j])) { dataType.setId(29); } attribute.setDatatypeBean(dataType); @@ -157,60 +157,63 @@ public class DictionaryImportController { category.setId(5); attribute.setCategoryBean(category); } - if("attribute_value".equalsIgnoreCase(dictSheet.get(0)[j]) || "Attribute Value".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("attribute_value".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Attribute Value".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setAttributeValue(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("ActionPolicyDictionary")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("ActionPolicyDictionary")) { + for (int i = 1; i < dictSheet.size(); i++) { ActionPolicyDict attribute = new ActionPolicyDict(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); attribute.setUserModifiedBy(userinfo); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("attribute_name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Attribute Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("attribute_name".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Attribute Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setAttributeName(rows[j]); } - if("body".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("body".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setBody(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } - if("headers".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("headers".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setHeader(rows[j]); } - if("method".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("method".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setMethod(rows[j]); } - if("type".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("type".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setType(rows[j]); } - if("url".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("url".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setUrl(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("OnapName")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("OnapName")) { + for (int i = 1; i < dictSheet.size(); i++) { OnapName attribute = new OnapName(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); attribute.setUserModifiedBy(userinfo); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("onap_name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Onap Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("onap_name".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Onap Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setOnapName(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } } @@ -218,39 +221,41 @@ public class DictionaryImportController { } } - if(dictionaryName.startsWith("MSPolicyDictionary")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("MSPolicyDictionary")) { + for (int i = 1; i < dictSheet.size(); i++) { MicroServiceModels attribute = new MicroServiceModels(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("modelName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Micro Service Model".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("modelName".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Micro Service Model".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setModelName(rows[j]); } - if("version".equalsIgnoreCase(dictSheet.get(0)[j]) || "Model Version".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("version".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Model Version".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setVersion(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } - if(DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDependency(rows[j]); } - if("attributes".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("attributes".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setAttributes(rows[j]); } - if("enumValues".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("enumValues".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setEnumValues(rows[j]); } - if("Ref Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("Ref Attributes".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setRef_attributes(rows[j]); } - if("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setSub_attributes(rows[j]); } - if("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) { + if ("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setAnnotation(rows[j]); } } @@ -259,39 +264,42 @@ public class DictionaryImportController { } } - if(dictionaryName.startsWith("OptimizationPolicyDictionary")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("OptimizationPolicyDictionary")) { + for (int i = 1; i < dictSheet.size(); i++) { MicroServiceModels attribute = new MicroServiceModels(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("modelName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Optimization Service Model".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("modelName".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Optimization Service Model" + .equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setModelName(rows[j]); } - if("version".equalsIgnoreCase(dictSheet.get(0)[j]) || "Model Version".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("version".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Model Version".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setVersion(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } - if(DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDependency(rows[j]); } - if("attributes".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("attributes".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setAttributes(rows[j]); } - if("enumValues".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("enumValues".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setEnumValues(rows[j]); } - if("Ref Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("Ref Attributes".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setRef_attributes(rows[j]); } - if("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setSub_attributes(rows[j]); } - if("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) { + if ("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setAnnotation(rows[j]); } } @@ -300,218 +308,231 @@ public class DictionaryImportController { } } - if(dictionaryName.startsWith("VNFType")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("VNFType")) { + for (int i = 1; i < dictSheet.size(); i++) { VNFType attribute = new VNFType(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); attribute.setUserModifiedBy(userinfo); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("vnf_type".equalsIgnoreCase(dictSheet.get(0)[j]) || "VNF Type".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("vnf_type".equalsIgnoreCase(dictSheet.get(0)[j]) + || "VNF Type".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setVnftype(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("VSCLAction")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("VSCLAction")) { + for (int i = 1; i < dictSheet.size(); i++) { VSCLAction attribute = new VSCLAction(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); attribute.setUserModifiedBy(userinfo); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("vscl_action".equalsIgnoreCase(dictSheet.get(0)[j]) || "VSCL Action".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("vscl_action".equalsIgnoreCase(dictSheet.get(0)[j]) + || "VSCL Action".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setVsclaction(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("ClosedLoopService")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("ClosedLoopService")) { + for (int i = 1; i < dictSheet.size(); i++) { ClosedLoopD2Services attribute = new ClosedLoopD2Services(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); attribute.setUserModifiedBy(userinfo); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("serviceName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Service Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("serviceName".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Service Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setServiceName(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("ClosedLoopSite")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("ClosedLoopSite")) { + for (int i = 1; i < dictSheet.size(); i++) { ClosedLoopSite attribute = new ClosedLoopSite(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); attribute.setUserModifiedBy(userinfo); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("siteName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Site Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("siteName".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Site Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setSiteName(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("PEPOptions")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("PEPOptions")) { + for (int i = 1; i < dictSheet.size(); i++) { PEPOptions attribute = new PEPOptions(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); attribute.setUserModifiedBy(userinfo); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("PEP_NAME".equalsIgnoreCase(dictSheet.get(0)[j]) || "PEP Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("PEP_NAME".equalsIgnoreCase(dictSheet.get(0)[j]) + || "PEP Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setPepName(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } - if("Actions".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("Actions".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setActions(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("VarbindDictionary")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("VarbindDictionary")) { + for (int i = 1; i < dictSheet.size(); i++) { VarbindDictionary attribute = new VarbindDictionary(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); attribute.setUserModifiedBy(userinfo); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("varbind_Name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Varbind Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("varbind_Name".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Varbind Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setVarbindName(rows[j]); } - if("varbind_Description".equalsIgnoreCase(dictSheet.get(0)[j]) || "Varbind Description".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("varbind_Description".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Varbind Description".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setVarbindDescription(rows[j]); } - if("varbind_oid".equalsIgnoreCase(dictSheet.get(0)[j]) || "Varbind OID".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("varbind_oid".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Varbind OID".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setVarbindOID(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("BRMSParamDictionary")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("BRMSParamDictionary")) { + for (int i = 1; i < dictSheet.size(); i++) { BRMSParamTemplate attribute = new BRMSParamTemplate(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("param_template_name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Rule Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("param_template_name".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Rule Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setRuleName(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } - if("rule".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("rule".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setRule(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("BRMSControllerDictionary")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("BRMSControllerDictionary")) { + for (int i = 1; i < dictSheet.size(); i++) { BRMSController attribute = new BRMSController(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("controllerName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Controller Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("controllerName".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Controller Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setControllerName(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } - if("controller".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("controller".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setController(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("BRMSDependencyDictionary")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("BRMSDependencyDictionary")) { + for (int i = 1; i < dictSheet.size(); i++) { BRMSDependency attribute = new BRMSDependency(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("dependencyName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Dependency Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("dependencyName".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Dependency Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDependencyName(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } - if(DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDependency(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("Settings")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("Settings")) { + for (int i = 1; i < dictSheet.size(); i++) { DecisionSettings attribute = new DecisionSettings(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); attribute.setUserModifiedBy(userinfo); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("xacml_id".equalsIgnoreCase(dictSheet.get(0)[j]) || "Settings ID".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("xacml_id".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Settings ID".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setXacmlId(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } - if("priority".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("priority".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setPriority(rows[j]); } - if("datatype".equalsIgnoreCase(dictSheet.get(0)[j]) || "Data Type".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("datatype".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Data Type".equalsIgnoreCase(dictSheet.get(0)[j])) { Datatype dataType = new Datatype(); - if("string".equalsIgnoreCase(rows[j])){ + if ("string".equalsIgnoreCase(rows[j])) { dataType.setId(26); - }else if("integer".equalsIgnoreCase(rows[j])){ + } else if ("integer".equalsIgnoreCase(rows[j])) { dataType.setId(12); - }else if("double".equalsIgnoreCase(rows[j])){ + } else if ("double".equalsIgnoreCase(rows[j])) { dataType.setId(25); - }else if("boolean".equalsIgnoreCase(rows[j])){ + } else if ("boolean".equalsIgnoreCase(rows[j])) { dataType.setId(18); - }else if("user".equalsIgnoreCase(rows[j])){ + } else if ("user".equalsIgnoreCase(rows[j])) { dataType.setId(29); } attribute.setDatatypeBean(dataType); @@ -520,200 +541,229 @@ public class DictionaryImportController { commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("PrefixList")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("PrefixList")) { + for (int i = 1; i < dictSheet.size(); i++) { PrefixList attribute = new PrefixList(); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("prefixListName".equalsIgnoreCase(dictSheet.get(0)[j]) || "PrefixList Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("prefixListName".equalsIgnoreCase(dictSheet.get(0)[j]) + || "PrefixList Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setPrefixListName(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setPrefixListValue(rows[j]); } - if("prefixListValue".equalsIgnoreCase(dictSheet.get(0)[j]) || "PrefixList Value".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("prefixListValue".equalsIgnoreCase(dictSheet.get(0)[j]) + || "PrefixList Value".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("SecurityZone")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("SecurityZone")) { + for (int i = 1; i < dictSheet.size(); i++) { SecurityZone attribute = new SecurityZone(); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("zoneName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Zone Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("zoneName".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Zone Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setZoneName(rows[j]); } - if("zoneValue".equalsIgnoreCase(dictSheet.get(0)[j]) || "Zone Value".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("zoneValue".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Zone Value".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setZoneValue(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("Zone")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("Zone")) { + for (int i = 1; i < dictSheet.size(); i++) { Zone attribute = new Zone(); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("zoneName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Zone Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("zoneName".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Zone Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setZoneName(rows[j]); } - if("zoneValue".equalsIgnoreCase(dictSheet.get(0)[j]) || "Zone Value".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("zoneValue".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Zone Value".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setZoneValue(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("ServiceList")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("ServiceList")) { + for (int i = 1; i < dictSheet.size(); i++) { ServiceList attribute = new ServiceList(); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("serviceName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Service Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("serviceName".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Service Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setServiceName(rows[j]); } - if("serviceDesc".equalsIgnoreCase(dictSheet.get(0)[j]) || DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("serviceDesc".equalsIgnoreCase(dictSheet.get(0)[j]) + || DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setServiceDescription(rows[j]); } - if("serviceType".equalsIgnoreCase(dictSheet.get(0)[j]) || "Service Type".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("serviceType".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Service Type".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setServiceType(rows[j]); } - if("serviceTrasProtocol".equalsIgnoreCase(dictSheet.get(0)[j]) || "Transport Protocol".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("serviceTrasProtocol".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Transport Protocol".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setServiceTransProtocol(rows[j]); } - if("serviceAppProtocol".equalsIgnoreCase(dictSheet.get(0)[j]) || "APP Protocol".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("serviceAppProtocol".equalsIgnoreCase(dictSheet.get(0)[j]) + || "APP Protocol".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setServiceAppProtocol(rows[j]); } - if("servicePorts".equalsIgnoreCase(dictSheet.get(0)[j]) || "Ports".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("servicePorts".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Ports".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setServicePorts(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("ServiceGroup")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("ServiceGroup")) { + for (int i = 1; i < dictSheet.size(); i++) { GroupServiceList attribute = new GroupServiceList(); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Group Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("name".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Group Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setGroupName(rows[j]); } - if("serviceList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Service List".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("serviceList".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Service List".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setServiceList(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("AddressGroup")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("AddressGroup")) { + for (int i = 1; i < dictSheet.size(); i++) { AddressGroup attribute = new AddressGroup(); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Group Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("name".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Group Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setGroupName(rows[j]); } - if("serviceList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Prefix List".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("serviceList".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Prefix List".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setServiceList(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("ProtocolList")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("ProtocolList")) { + for (int i = 1; i < dictSheet.size(); i++) { ProtocolList attribute = new ProtocolList(); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("protocolName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Protocol Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("protocolName".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Protocol Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setProtocolName(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("ActionList")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("ActionList")) { + for (int i = 1; i < dictSheet.size(); i++) { ActionList attribute = new ActionList(); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("actionName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Action Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("actionName".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Action Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setActionName(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("TermList")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("TermList")) { + for (int i = 1; i < dictSheet.size(); i++) { TermList attribute = new TermList(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); attribute.setUserModifiedBy(userinfo); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("termName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Term-Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("termName".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Term-Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setTermName(rows[j]); } - if("Term-Description".equalsIgnoreCase(dictSheet.get(0)[j]) || "termDescription".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("Term-Description".equalsIgnoreCase(dictSheet.get(0)[j]) + || "termDescription".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } - if("fromZone".equalsIgnoreCase(dictSheet.get(0)[j]) || "From Zone".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("fromZone".equalsIgnoreCase(dictSheet.get(0)[j]) + || "From Zone".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setFromZones(rows[j]); } - if("toZone".equalsIgnoreCase(dictSheet.get(0)[j]) || "To Zone".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("toZone".equalsIgnoreCase(dictSheet.get(0)[j]) + || "To Zone".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setToZones(rows[j]); } - if("srcIPList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Source-IP-List".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("srcIPList".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Source-IP-List".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setSrcIPList(rows[j]); } - if("destIPList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Destination-IP-List".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("destIPList".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Destination-IP-List".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDestIPList(rows[j]); } - if("srcPortList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Source-Port-List".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("srcPortList".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Source-Port-List".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setSrcPortList(rows[j]); } - if("destPortList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Destination-Port-List".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("destPortList".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Destination-Port-List".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDestPortList(rows[j]); } - if("action".equalsIgnoreCase(dictSheet.get(0)[j]) || "Action List".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("action".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Action List".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setAction(rows[j]); } } commonClassDao.save(attribute); } } - if(dictionaryName.startsWith("SearchCriteria")){ - for(int i = 1; i< dictSheet.size(); i++){ + if (dictionaryName.startsWith("SearchCriteria")) { + for (int i = 1; i < dictSheet.size(); i++) { DescriptiveScope attribute = new DescriptiveScope(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); attribute.setUserModifiedBy(userinfo); String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if("descriptiveScopeName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Descriptive Scope Name".equalsIgnoreCase(dictSheet.get(0)[j])){ + for (int j = 0; j < rows.length; j++) { + if ("descriptiveScopeName".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Descriptive Scope Name".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setScopeName(rows[j]); } - if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){ + if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); } - if("search".equalsIgnoreCase(dictSheet.get(0)[j]) || "Search Criteria".equalsIgnoreCase(dictSheet.get(0)[j])){ + if ("search".equalsIgnoreCase(dictSheet.get(0)[j]) + || "Search Criteria".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setSearch(rows[j]); } } @@ -723,24 +773,24 @@ public class DictionaryImportController { csvReader.close(); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().write("Success"); - }catch(Exception e){ - LOGGER.error("Exception Occured while importing dictionary"+e); + } catch (Exception e) { + LOGGER.error("Exception Occured while importing dictionary" + e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.getWriter().write(ERROR); - }finally{ - if(file != null && file.exists()){ + } finally { + if (file != null && file.exists()) { boolean deleted = file.delete(); - LOGGER.error("Imported File has been deleted: "+deleted); + LOGGER.error("Imported File has been deleted: " + deleted); } } } - public boolean isValidDictionaryName(String dictionaryName){ + public boolean isValidDictionaryName(String dictionaryName) { String nameCheck = dictionaryName.replace(".csv", ""); - try{ + try { DictionaryNames mode = DictionaryNames.valueOf(nameCheck); - switch (mode){ + switch (mode) { case Attribute: case ActionPolicyDictionary: case OnapName: @@ -770,9 +820,9 @@ public class DictionaryImportController { default: return false; } - }catch(Exception e){ - LOGGER.error("Dictionary not exits: " +dictionaryName +e); + } catch (Exception e) { + LOGGER.error("Dictionary not exits: " + dictionaryName + e); return false; } } -}
\ No newline at end of file +} diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java index 891787fa0..7cf12043c 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.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,15 +20,16 @@ package org.onap.policy.pap.xacml.rest.controller; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.io.PrintWriter; import java.net.UnknownHostException; import java.util.Date; import java.util.List; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import org.jboss.netty.handler.ipfilter.CIDR; import org.json.JSONObject; import org.onap.policy.common.logging.flexlogger.FlexLogger; @@ -57,29 +58,25 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - @Controller public class FirewallDictionaryController { - private static final Logger LOGGER = FlexLogger.getLogger(FirewallDictionaryController.class); + private static final Logger LOGGER = FlexLogger.getLogger(FirewallDictionaryController.class); private static CommonClassDao commonClassDao; private static String prefixListName = "prefixListName"; private static String successMessage = "success"; private static String operation = "operation"; - private static String errorMsg = "error"; - private static String dictionaryFields ="dictionaryFields"; + private static String errorMsg = "error"; + private static String dictionaryFields = "dictionaryFields"; private static String duplicateResponseString = "Duplicate"; private static String utf8 = "UTF-8"; private static String applicationJsonContentType = "application / json"; private static String protocolName = "protocolName"; private static String groupNameStart = "Group_"; private static String option = "option"; - private static String zoneName = "zoneName"; + private static String zoneName = "zoneName"; private static String serviceName = "serviceName"; private static String termName = "termName"; private static String userid = "userid"; @@ -100,36 +97,39 @@ public class FirewallDictionaryController { @Autowired - public FirewallDictionaryController(CommonClassDao commonClassDao){ + public FirewallDictionaryController(CommonClassDao commonClassDao) { FirewallDictionaryController.commonClassDao = commonClassDao; } - public static void setCommonClassDao(CommonClassDao clDao){ + public static void setCommonClassDao(CommonClassDao clDao) { commonClassDao = clDao; } - public FirewallDictionaryController(){ + public FirewallDictionaryController() { super(); } - private DictionaryUtils getDictionaryUtilsInstance(){ + private DictionaryUtils getDictionaryUtilsInstance() { return DictionaryUtils.getDictionaryUtils(); } - @RequestMapping(value={"/get_PrefixListDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPrefixListDictionaryEntityDataByName(HttpServletResponse response){ + @RequestMapping(value = {"/get_PrefixListDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getPrefixListDictionaryEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, pfListDatas, prefixListName, PrefixList.class); } - @RequestMapping(value={"/get_PrefixListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPrefixListDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_PrefixListData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getPrefixListDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, pfListDatas, PrefixList.class); } - @RequestMapping(value={"/fw_dictionary/save_prefixList"}, method={RequestMethod.POST}) - public ModelAndView savePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/save_prefixList"}, method = {RequestMethod.POST}) + public ModelAndView savePrefixListDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -138,62 +138,72 @@ public class FirewallDictionaryController { JsonNode root = mapper.readTree(request.getReader()); PrefixList prefixList; if (fromAPI) { - prefixList = mapper.readValue(root.get(dictionaryFields).toString(), PrefixList.class); + prefixList = + mapper.readValue(root.get(dictionaryFields).toString(), PrefixList.class); } else { - prefixList = mapper.readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class); + prefixList = mapper.readValue(root.get("prefixListDictionaryData").toString(), + PrefixList.class); } - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), prefixListName, PrefixList.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry( + prefixList.getPrefixListName(), prefixListName, PrefixList.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { PrefixList data = (PrefixList) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { prefixList.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != prefixList.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != prefixList.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ - if(prefixList.getId() == 0){ + if (!duplicateflag) { + if (prefixList.getId() == 0) { commonClassDao.save(prefixList); - }else{ + } else { commonClassDao.update(prefixList); } - responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(PrefixList.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, pfListDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/fw_dictionary/remove_PrefixList"}, method={RequestMethod.POST}) - public void removePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/remove_PrefixList"}, method = {RequestMethod.POST}) + public void removePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, pfListDatas, PrefixList.class); } - @RequestMapping(value={"/fw_dictionary/validate_prefixList"}, method={RequestMethod.POST}) - public void validatePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/validate_prefixList"}, method = {RequestMethod.POST}) + public void validatePrefixListDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); - PrefixList prefixList = mapper.readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class); + PrefixList prefixList = mapper + .readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class); String responseValidation = successMessage; - try{ + try { CIDR.newCIDR(prefixList.getPrefixListValue()); - }catch(UnknownHostException e){ + } catch (UnknownHostException e) { LOGGER.error(e); responseValidation = errorMsg; } @@ -204,20 +214,21 @@ public class FirewallDictionaryController { PrintWriter out = response.getWriter(); JSONObject j = new JSONObject("{result: " + responseValidation + "}"); out.write(j.toString()); - } - catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } } - @RequestMapping(value={"/get_PortListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPortListDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_PortListData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getPortListDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, portListDatas, PortList.class); } - @RequestMapping(value={"/fw_dictionary/save_portName"}, method={RequestMethod.POST}) - public ModelAndView savePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/save_portName"}, method = {RequestMethod.POST}) + public ModelAndView savePortListDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -225,64 +236,73 @@ public class FirewallDictionaryController { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); PortList portList; - if(fromAPI){ + if (fromAPI) { portList = mapper.readValue(root.get(dictionaryFields).toString(), PortList.class); - }else{ - portList = mapper.readValue(root.get("portListDictionaryData").toString(), PortList.class); + } else { + portList = mapper.readValue(root.get("portListDictionaryData").toString(), + PortList.class); } - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(portList.getPortName(), "portName", PortList.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(portList.getPortName(), + "portName", PortList.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { PortList data = (PortList) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { portList.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != portList.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != portList.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ - if(portList.getId() == 0){ + if (!duplicateflag) { + if (portList.getId() == 0) { commonClassDao.save(portList); - }else{ + } else { commonClassDao.update(portList); } responseString = mapper.writeValueAsString(commonClassDao.getData(PortList.class)); - }else{ + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, portListDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/fw_dictionary/remove_PortList"}, method={RequestMethod.POST}) - public void removePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/remove_PortList"}, method = {RequestMethod.POST}) + public void removePortListDictionary(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, portListDatas, PortList.class); } - @RequestMapping(value={"/get_ProtocolListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getProtocolListDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_ProtocolListData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getProtocolListDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, protocolListDatas, ProtocolList.class); } - @RequestMapping(value={"/get_ProtocolListDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getProtocolListDictionaryEntityDataByName(HttpServletResponse response){ + @RequestMapping(value = {"/get_ProtocolListDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getProtocolListDictionaryEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, protocolListDatas, protocolName, ProtocolList.class); } - @RequestMapping(value={"/fw_dictionary/save_protocolList"}, method={RequestMethod.POST}) - public ModelAndView saveProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/save_protocolList"}, method = {RequestMethod.POST}) + public ModelAndView saveProtocolListDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -290,64 +310,75 @@ public class FirewallDictionaryController { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); ProtocolList protocolList; - if(fromAPI){ - protocolList = mapper.readValue(root.get(dictionaryFields).toString(), ProtocolList.class); - }else{ - protocolList = mapper.readValue(root.get("protocolListDictionaryData").toString(), ProtocolList.class); + if (fromAPI) { + protocolList = + mapper.readValue(root.get(dictionaryFields).toString(), ProtocolList.class); + } else { + protocolList = mapper.readValue(root.get("protocolListDictionaryData").toString(), + ProtocolList.class); } - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), protocolName, ProtocolList.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry( + protocolList.getProtocolName(), protocolName, ProtocolList.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { ProtocolList data = (ProtocolList) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { protocolList.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != protocolList.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != protocolList.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ - if(protocolList.getId() == 0){ + if (!duplicateflag) { + if (protocolList.getId() == 0) { commonClassDao.save(protocolList); - }else{ + } else { commonClassDao.update(protocolList); } - responseString = mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, protocolListDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/fw_dictionary/remove_protocol"}, method={RequestMethod.POST}) - public void removeProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/remove_protocol"}, method = {RequestMethod.POST}) + public void removeProtocolListDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, protocolListDatas, ProtocolList.class); } - @RequestMapping(value={"/get_AddressGroupDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getAddressGroupDictionaryEntityDataByName(HttpServletResponse response){ + @RequestMapping(value = {"/get_AddressGroupDictionaryDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getAddressGroupDictionaryEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, addressGroupDatas, "name", AddressGroup.class); } - @RequestMapping(value={"/get_AddressGroupData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getAddressGroupDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_AddressGroupData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getAddressGroupDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, addressGroupDatas, AddressGroup.class); } - @RequestMapping(value={"/fw_dictionary/save_addressGroup"}, method={RequestMethod.POST}) - public ModelAndView saveAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/save_addressGroup"}, method = {RequestMethod.POST}) + public ModelAndView saveAddressGroupDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -356,71 +387,83 @@ public class FirewallDictionaryController { JsonNode root = mapper.readTree(request.getReader()); AddressGroup addressGroup; GridData gridData; - if(fromAPI){ - addressGroup = mapper.readValue(root.get(dictionaryFields).toString(), AddressGroup.class); + if (fromAPI) { + addressGroup = + mapper.readValue(root.get(dictionaryFields).toString(), AddressGroup.class); gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class); - }else{ - addressGroup = mapper.readValue(root.get("addressGroupDictionaryData").toString(), AddressGroup.class); - gridData = mapper.readValue(root.get("addressGroupDictionaryData").toString(), GridData.class); + } else { + addressGroup = mapper.readValue(root.get("addressGroupDictionaryData").toString(), + AddressGroup.class); + gridData = mapper.readValue(root.get("addressGroupDictionaryData").toString(), + GridData.class); } - if(!addressGroup.getGroupName().startsWith(groupNameStart)){ - String groupName = groupNameStart+addressGroup.getGroupName(); + if (!addressGroup.getGroupName().startsWith(groupNameStart)) { + String groupName = groupNameStart + addressGroup.getGroupName(); addressGroup.setGroupName(groupName); } addressGroup.setServiceList(utils.appendKey(gridData.getAttributes(), option, ",")); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class); + List<Object> duplicateData = commonClassDao + .checkDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { AddressGroup data = (AddressGroup) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { addressGroup.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != addressGroup.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != addressGroup.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ - if(addressGroup.getId() == 0){ + if (!duplicateflag) { + if (addressGroup.getId() == 0) { commonClassDao.save(addressGroup); - }else{ + } else { commonClassDao.update(addressGroup); } - responseString = mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, addressGroupDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/fw_dictionary/remove_AddressGroup"}, method={RequestMethod.POST}) - public void removeAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/remove_AddressGroup"}, method = {RequestMethod.POST}) + public void removeAddressGroupDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, addressGroupDatas, AddressGroup.class); } - @RequestMapping(value={"/get_ActionListDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getActionListDictionaryEntityDataByName(HttpServletResponse response){ + @RequestMapping(value = {"/get_ActionListDictionaryDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getActionListDictionaryEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, actionListDatas, "actionName", ActionList.class); } - @RequestMapping(value={"/get_ActionListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getActionListDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_ActionListData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getActionListDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, actionListDatas, ActionList.class); } - @RequestMapping(value={"/fw_dictionary/save_ActionList"}, method={RequestMethod.POST}) - public ModelAndView saveActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/save_ActionList"}, method = {RequestMethod.POST}) + public ModelAndView saveActionListDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -429,63 +472,74 @@ public class FirewallDictionaryController { JsonNode root = mapper.readTree(request.getReader()); ActionList actionList; if (fromAPI) { - actionList = mapper.readValue(root.get(dictionaryFields).toString(), ActionList.class); + actionList = + mapper.readValue(root.get(dictionaryFields).toString(), ActionList.class); } else { - actionList = mapper.readValue(root.get("actionListDictionaryData").toString(), ActionList.class); + actionList = mapper.readValue(root.get("actionListDictionaryData").toString(), + ActionList.class); } - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(actionList.getActionName(), "actionName", ActionList.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry( + actionList.getActionName(), "actionName", ActionList.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { ActionList data = (ActionList) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { actionList.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != actionList.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != actionList.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ - if(actionList.getId() == 0){ + if (!duplicateflag) { + if (actionList.getId() == 0) { commonClassDao.save(actionList); - }else{ + } else { commonClassDao.update(actionList); } - responseString = mapper.writeValueAsString(commonClassDao.getData(ActionList.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(ActionList.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, actionListDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/fw_dictionary/remove_ActionList"}, method={RequestMethod.POST}) - public void removeActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/remove_ActionList"}, method = {RequestMethod.POST}) + public void removeActionListDictionary(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, actionListDatas, ActionList.class); } - @RequestMapping(value={"/get_ServiceGroupData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getServiceGroupDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_ServiceGroupData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getServiceGroupDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, serviceGroupDatas, GroupServiceList.class); } - @RequestMapping(value={"/get_ServiceGroupDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getServiceGroupDictionaryEntityDataByName(HttpServletResponse response){ + @RequestMapping(value = {"/get_ServiceGroupDictionaryDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getServiceGroupDictionaryEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, serviceGroupDatas, "name", GroupServiceList.class); } - @RequestMapping(value={"/fw_dictionary/save_serviceGroup"}, method={RequestMethod.POST}) - public ModelAndView saveServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/save_serviceGroup"}, method = {RequestMethod.POST}) + public ModelAndView saveServiceGroupDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -494,71 +548,83 @@ public class FirewallDictionaryController { JsonNode root = mapper.readTree(request.getReader()); GroupServiceList groupServiceList; GridData gridData; - if(fromAPI){ - groupServiceList = mapper.readValue(root.get(dictionaryFields).toString(), GroupServiceList.class); + if (fromAPI) { + groupServiceList = mapper.readValue(root.get(dictionaryFields).toString(), + GroupServiceList.class); gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class); - }else{ - groupServiceList = mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GroupServiceList.class); - gridData = mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GridData.class); + } else { + groupServiceList = mapper.readValue( + root.get("serviceGroupDictionaryData").toString(), GroupServiceList.class); + gridData = mapper.readValue(root.get("serviceGroupDictionaryData").toString(), + GridData.class); } - if(!groupServiceList.getGroupName().startsWith(groupNameStart)){ - String groupName = groupNameStart+groupServiceList.getGroupName(); + if (!groupServiceList.getGroupName().startsWith(groupNameStart)) { + String groupName = groupNameStart + groupServiceList.getGroupName(); groupServiceList.setGroupName(groupName); } groupServiceList.setServiceList(utils.appendKey(gridData.getAttributes(), option, ",")); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(groupServiceList.getGroupName(), "name", GroupServiceList.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry( + groupServiceList.getGroupName(), "name", GroupServiceList.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { GroupServiceList data = (GroupServiceList) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { groupServiceList.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != groupServiceList.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != groupServiceList.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ - if(groupServiceList.getId() == 0){ + if (!duplicateflag) { + if (groupServiceList.getId() == 0) { commonClassDao.save(groupServiceList); - }else{ + } else { commonClassDao.update(groupServiceList); } - responseString = mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, serviceGroupDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/fw_dictionary/remove_serviceGroup"}, method={RequestMethod.POST}) - public void removeServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/remove_serviceGroup"}, method = {RequestMethod.POST}) + public void removeServiceGroupDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, serviceGroupDatas, GroupServiceList.class); } - @RequestMapping(value={"/get_SecurityZoneDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getSecurityZoneDictionaryEntityDataByName(HttpServletResponse response){ + @RequestMapping(value = {"/get_SecurityZoneDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getSecurityZoneDictionaryEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, securityZoneDatas, zoneName, SecurityZone.class); } - @RequestMapping(value={"/get_SecurityZoneData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getSecurityZoneDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_SecurityZoneData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getSecurityZoneDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, securityZoneDatas, SecurityZone.class); } - @RequestMapping(value={"/fw_dictionary/save_securityZone"}, method={RequestMethod.POST}) - public ModelAndView saveSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/save_securityZone"}, method = {RequestMethod.POST}) + public ModelAndView saveSecurityZoneDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -566,65 +632,76 @@ public class FirewallDictionaryController { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); SecurityZone securityZone; - if(fromAPI){ - securityZone = mapper.readValue(root.get(dictionaryFields).toString(), SecurityZone.class); - }else{ - securityZone = mapper.readValue(root.get("securityZoneDictionaryData").toString(), SecurityZone.class); + if (fromAPI) { + securityZone = + mapper.readValue(root.get(dictionaryFields).toString(), SecurityZone.class); + } else { + securityZone = mapper.readValue(root.get("securityZoneDictionaryData").toString(), + SecurityZone.class); } - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), zoneName, SecurityZone.class); + List<Object> duplicateData = commonClassDao + .checkDuplicateEntry(securityZone.getZoneName(), zoneName, SecurityZone.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { SecurityZone data = (SecurityZone) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { securityZone.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != securityZone.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != securityZone.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ - if(securityZone.getId() == 0){ + if (!duplicateflag) { + if (securityZone.getId() == 0) { commonClassDao.save(securityZone); - }else{ + } else { commonClassDao.update(securityZone); } - responseString = mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, securityZoneDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/fw_dictionary/remove_securityZone"}, method={RequestMethod.POST}) - public void removeSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/fw_dictionary/remove_securityZone"}, method = {RequestMethod.POST}) + public void removeSecurityZoneDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, securityZoneDatas, SecurityZone.class); } - @RequestMapping(value={"/get_ServiceListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getServiceListDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_ServiceListData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getServiceListDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, serviceListDatas, ServiceList.class); } - @RequestMapping(value={"/get_ServiceListDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getServiceListDictionaryEntityDataByName(HttpServletResponse response){ + @RequestMapping(value = {"/get_ServiceListDictionaryDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getServiceListDictionaryEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, serviceListDatas, serviceName, ServiceList.class); } - @RequestMapping(value={"/fw_dictionary/save_serviceList"}, method={RequestMethod.POST}) - public ModelAndView saveServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/save_serviceList"}, method = {RequestMethod.POST}) + public ModelAndView saveServiceListDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -633,69 +710,84 @@ public class FirewallDictionaryController { JsonNode root = mapper.readTree(request.getReader()); ServiceList serviceList; GridData serviceListGridData; - if(fromAPI){ - serviceList = mapper.readValue(root.get(dictionaryFields).toString(), ServiceList.class); - serviceListGridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class); - }else{ - serviceList = mapper.readValue(root.get("serviceListDictionaryData").toString(), ServiceList.class); - serviceListGridData = mapper.readValue(root.get("serviceListDictionaryData").toString(), GridData.class); + if (fromAPI) { + serviceList = + mapper.readValue(root.get(dictionaryFields).toString(), ServiceList.class); + serviceListGridData = + mapper.readValue(root.get(dictionaryFields).toString(), GridData.class); + } else { + serviceList = mapper.readValue(root.get("serviceListDictionaryData").toString(), + ServiceList.class); + serviceListGridData = mapper.readValue( + root.get("serviceListDictionaryData").toString(), GridData.class); } - serviceList.setServiceTransProtocol(utils.appendKey(serviceListGridData.getTransportProtocols(), option, ",")); - serviceList.setServiceAppProtocol(utils.appendKey(serviceListGridData.getAppProtocols(), option, ",")); + serviceList.setServiceTransProtocol( + utils.appendKey(serviceListGridData.getTransportProtocols(), option, ",")); + serviceList.setServiceAppProtocol( + utils.appendKey(serviceListGridData.getAppProtocols(), option, ",")); serviceList.setServiceType("SERVICE"); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), serviceName, ServiceList.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry( + serviceList.getServiceName(), serviceName, ServiceList.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { ServiceList data = (ServiceList) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { serviceList.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != serviceList.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != serviceList.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ - if(serviceList.getId() == 0){ + if (!duplicateflag) { + if (serviceList.getId() == 0) { commonClassDao.save(serviceList); - }else{ + } else { commonClassDao.update(serviceList); } - responseString = mapper.writeValueAsString(commonClassDao.getData(ServiceList.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(ServiceList.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, serviceListDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/fw_dictionary/remove_serviceList"}, method={RequestMethod.POST}) - public void removeServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/fw_dictionary/remove_serviceList"}, method = {RequestMethod.POST}) + public void removeServiceListDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, serviceListDatas, ServiceList.class); } - @RequestMapping(value={"/get_ZoneData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getZoneDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_ZoneData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getZoneDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, zoneDatas, Zone.class); } - @RequestMapping(value={"/get_ZoneDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getZoneDictionaryEntityDataByName(HttpServletResponse response){ + @RequestMapping(value = {"/get_ZoneDictionaryDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getZoneDictionaryEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, zoneDatas, zoneName, Zone.class); } - @RequestMapping(value={"/fw_dictionary/save_zoneName"}, method={RequestMethod.POST}) - public ModelAndView saveZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/save_zoneName"}, method = {RequestMethod.POST}) + public ModelAndView saveZoneDictionary(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -708,59 +800,67 @@ public class FirewallDictionaryController { } else { zone = mapper.readValue(root.get("zoneDictionaryData").toString(), Zone.class); } - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(zone.getZoneName(), zoneName, Zone.class); + List<Object> duplicateData = + commonClassDao.checkDuplicateEntry(zone.getZoneName(), zoneName, Zone.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { Zone data = (Zone) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { zone.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != zone.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != zone.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ - if(zone.getId() == 0){ + if (!duplicateflag) { + if (zone.getId() == 0) { commonClassDao.save(zone); - }else{ + } else { commonClassDao.update(zone); } responseString = mapper.writeValueAsString(commonClassDao.getData(Zone.class)); - }else{ + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, zoneDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/fw_dictionary/remove_zone"}, method={RequestMethod.POST}) - public void removeZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/remove_zone"}, method = {RequestMethod.POST}) + public void removeZoneDictionary(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, zoneDatas, Zone.class); } - @RequestMapping(value={"/get_TermListDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getTermListDictionaryEntityDataByName(HttpServletResponse response){ + @RequestMapping(value = {"/get_TermListDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getTermListDictionaryEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, termListDictDatas, termName, TermList.class); } - @RequestMapping(value={"/get_TermListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getTermListDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_TermListData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getTermListDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, termListDictDatas, TermList.class); } - @RequestMapping(value={"/fw_dictionary/save_termList"}, method={RequestMethod.POST}) - public ModelAndView saveTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/save_termList"}, method = {RequestMethod.POST}) + public ModelAndView saveTermListDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -770,82 +870,97 @@ public class FirewallDictionaryController { TermList termList; TermListData termListDatas; String userId = null; - if(fromAPI){ + if (fromAPI) { termList = mapper.readValue(root.get(dictionaryFields).toString(), TermList.class); - termListDatas = mapper.readValue(root.get(dictionaryFields).toString(), TermListData.class); + termListDatas = + mapper.readValue(root.get(dictionaryFields).toString(), TermListData.class); userId = "API"; - }else{ - termList = mapper.readValue(root.get("termListDictionaryData").toString(), TermList.class); - termListDatas = mapper.readValue(root.get("termListDictionaryData").toString(), TermListData.class); + } else { + termList = mapper.readValue(root.get("termListDictionaryData").toString(), + TermList.class); + termListDatas = mapper.readValue(root.get("termListDictionaryData").toString(), + TermListData.class); userId = root.get(userid).textValue(); } termList.setFromZones(utils.appendKey(termListDatas.getFromZoneDatas(), option, ",")); termList.setToZones(utils.appendKey(termListDatas.getToZoneDatas(), option, ",")); termList.setSrcIPList(utils.appendKey(termListDatas.getSourceListDatas(), option, ",")); - termList.setDestIPList(utils.appendKey(termListDatas.getDestinationListDatas(), option, ",")); - termList.setSrcPortList(utils.appendKey(termListDatas.getSourceServiceDatas(), option, ",")); - termList.setDestPortList(utils.appendKey(termListDatas.getDestinationServiceDatas(), option, ",")); + termList.setDestIPList( + utils.appendKey(termListDatas.getDestinationListDatas(), option, ",")); + termList.setSrcPortList( + utils.appendKey(termListDatas.getSourceServiceDatas(), option, ",")); + termList.setDestPortList( + utils.appendKey(termListDatas.getDestinationServiceDatas(), option, ",")); termList.setAction(utils.appendKey(termListDatas.getActionListDatas(), option, ",")); UserInfo userInfo = utils.getUserInfo(userId); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(termList.getTermName(), termName, TermList.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(termList.getTermName(), + termName, TermList.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { TermList data = (TermList) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { termList.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != termList.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != termList.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ + if (!duplicateflag) { termList.setUserModifiedBy(userInfo); - if(termList.getId() == 0){ + if (termList.getId() == 0) { termList.setUserCreatedBy(userInfo); commonClassDao.save(termList); - }else{ + } else { termList.setModifiedDate(new Date()); commonClassDao.update(termList); } responseString = mapper.writeValueAsString(commonClassDao.getData(TermList.class)); - }else{ + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, termListDictDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/fw_dictionary/remove_termList"}, method={RequestMethod.POST}) - public void removeTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/remove_termList"}, method = {RequestMethod.POST}) + public void removeTermListDictionary(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, termListDictDatas, TermList.class); } - //ParentList Dictionary Data - @RequestMapping(value={"/get_FWDictionaryListDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getFWDictListDictionaryEntityDataByName(HttpServletResponse response){ + // ParentList Dictionary Data + @RequestMapping(value = {"/get_FWDictionaryListDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getFWDictListDictionaryEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); - utils.getDataByEntity(response, fwDictListDatas, "parentItemName", FirewallDictionaryList.class); + utils.getDataByEntity(response, fwDictListDatas, "parentItemName", + FirewallDictionaryList.class); } - @RequestMapping(value={"/get_FWDictionaryListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getFWDictionaryListEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_FWDictionaryListData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getFWDictionaryListEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, fwDictListDatas, FirewallDictionaryList.class); } - @RequestMapping(value={"/fw_dictionary/save_FWDictionaryList"}, method={RequestMethod.POST}) - public ModelAndView saveFWDictionaryList(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/save_FWDictionaryList"}, method = {RequestMethod.POST}) + public ModelAndView saveFWDictionaryList(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -855,71 +970,83 @@ public class FirewallDictionaryController { FirewallDictionaryList fwDictList; GridData gridData; if (fromAPI) { - fwDictList = mapper.readValue(root.get(dictionaryFields).toString(), FirewallDictionaryList.class); + fwDictList = mapper.readValue(root.get(dictionaryFields).toString(), + FirewallDictionaryList.class); gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class); } else { - fwDictList = mapper.readValue(root.get("fwDictListDictionaryData").toString(), FirewallDictionaryList.class); - gridData = mapper.readValue(root.get("fwDictListDictionaryData").toString(), GridData.class); + fwDictList = mapper.readValue(root.get("fwDictListDictionaryData").toString(), + FirewallDictionaryList.class); + gridData = mapper.readValue(root.get("fwDictListDictionaryData").toString(), + GridData.class); } fwDictList.setServiceList(utils.appendKey(gridData.getAttributes(), option, ",")); fwDictList.setAddressList(utils.appendKey(gridData.getAlAttributes(), option, ",")); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwDictList.getParentItemName(), "parentItemName", FirewallDictionaryList.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry( + fwDictList.getParentItemName(), "parentItemName", FirewallDictionaryList.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { FirewallDictionaryList data = (FirewallDictionaryList) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { fwDictList.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != fwDictList.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != fwDictList.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ - if(fwDictList.getId() == 0){ + if (!duplicateflag) { + if (fwDictList.getId() == 0) { commonClassDao.save(fwDictList); - }else{ + } else { commonClassDao.update(fwDictList); } - responseString = mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class)); - }else{ + responseString = mapper + .writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, fwDictListDatas, responseString); } - } - catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/fw_dictionary/remove_FWDictionaryList"}, method={RequestMethod.POST}) - public void removeFWDictionaryList(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/fw_dictionary/remove_FWDictionaryList"}, + method = {RequestMethod.POST}) + public void removeFWDictionaryList(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, fwDictListDatas, FirewallDictionaryList.class); } - @RequestMapping(value={"/get_TagPickerNameByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getTagPickerNameEntityDataByName(HttpServletResponse response){ + @RequestMapping(value = {"/get_TagPickerNameByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getTagPickerNameEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, fwTagPickerDatas, tagPickerName, FWTagPicker.class); } - @RequestMapping(value={"/get_TagPickerListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getTagPickerDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_TagPickerListData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getTagPickerDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, fwTagPickerDatas, FWTagPicker.class); } - @RequestMapping(value={"/fw_dictionary/save_fwTagPicker"}, method={RequestMethod.POST}) - public ModelAndView saveFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/save_fwTagPicker"}, method = {RequestMethod.POST}) + public ModelAndView saveFirewallTagPickerDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -930,76 +1057,87 @@ public class FirewallDictionaryController { TagGridValues data; String userId = ""; if (fromAPI) { - fwTagPicker = mapper.readValue(root.get(dictionaryFields).toString(), FWTagPicker.class); + fwTagPicker = + mapper.readValue(root.get(dictionaryFields).toString(), FWTagPicker.class); data = mapper.readValue(root.get(dictionaryFields).toString(), TagGridValues.class); userId = "API"; } else { - fwTagPicker = mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), FWTagPicker.class); - data = mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), TagGridValues.class); + fwTagPicker = mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), + FWTagPicker.class); + data = mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), + TagGridValues.class); userId = root.get(userid).textValue(); } fwTagPicker.setTagValues(utils.appendKeyValue(data.getTags(), "#", ":")); UserInfo userInfo = utils.getUserInfo(userId); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), tagPickerName, FWTagPicker.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry( + fwTagPicker.getTagPickerName(), tagPickerName, FWTagPicker.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { FWTagPicker data1 = (FWTagPicker) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { fwTagPicker.setId(data1.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data1.getId() != fwTagPicker.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data1.getId() != fwTagPicker.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ + if (!duplicateflag) { fwTagPicker.setUserModifiedBy(userInfo); - if(fwTagPicker.getId() == 0){ + if (fwTagPicker.getId() == 0) { fwTagPicker.setUserCreatedBy(userInfo); commonClassDao.save(fwTagPicker); - }else{ + } else { fwTagPicker.setModifiedDate(new Date()); commonClassDao.update(fwTagPicker); } - responseString = mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, fwTagPickerDatas, responseString); } - } - catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/fw_dictionary/remove_tagPicker"}, method={RequestMethod.POST}) - public void removeFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/fw_dictionary/remove_tagPicker"}, method = {RequestMethod.POST}) + public void removeFirewallTagPickerDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, fwTagPickerDatas, FWTagPicker.class); } - @RequestMapping(value={"/get_TagListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getTagDictionaryEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_TagListData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getTagDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, fwTagDatas, FWTag.class); } - @RequestMapping(value={"/get_TagNameByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getTagNameEntityDataByName(HttpServletResponse response){ + @RequestMapping(value = {"/get_TagNameByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getTagNameEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, fwTagDatas, "fwTagName", FWTag.class); } - @RequestMapping(value={"/fw_dictionary/save_fwTag"}, method={RequestMethod.POST}) - public ModelAndView saveFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/save_fwTag"}, method = {RequestMethod.POST}) + public ModelAndView saveFirewallTagDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -1008,64 +1146,71 @@ public class FirewallDictionaryController { JsonNode root = mapper.readTree(request.getReader()); FWTag fwTag; TagGridValues tagGridValues; - String userId=""; - if(fromAPI){ + String userId = ""; + if (fromAPI) { fwTag = mapper.readValue(root.get(dictionaryFields).toString(), FWTag.class); - tagGridValues = mapper.readValue(root.get(dictionaryFields).toString(), TagGridValues.class); + tagGridValues = mapper.readValue(root.get(dictionaryFields).toString(), + TagGridValues.class); userId = "API"; - }else{ + } else { fwTag = mapper.readValue(root.get("fwTagDictionaryData").toString(), FWTag.class); - tagGridValues = mapper.readValue(root.get("fwTagDictionaryData").toString(), TagGridValues.class); + tagGridValues = mapper.readValue(root.get("fwTagDictionaryData").toString(), + TagGridValues.class); userId = root.get(userid).textValue(); } fwTag.setTagValues(utils.appendKey(tagGridValues.getTags(), "tags", ",")); UserInfo userInfo = utils.getUserInfo(userId); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "fwTagName", FWTag.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), + "fwTagName", FWTag.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { FWTag data = (FWTag) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { fwTag.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != fwTag.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != fwTag.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ + if (!duplicateflag) { fwTag.setUserModifiedBy(userInfo); - if(fwTag.getId() == 0){ + if (fwTag.getId() == 0) { fwTag.setUserCreatedBy(userInfo); commonClassDao.save(fwTag); - }else{ + } else { fwTag.setModifiedDate(new Date()); commonClassDao.update(fwTag); } responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.class)); - }else{ + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, fwTagDatas, responseString); } - } - catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/fw_dictionary/remove_tagList"}, method={RequestMethod.POST}) - public void removeFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/fw_dictionary/remove_tagList"}, method = {RequestMethod.POST}) + public void removeFirewallTagDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, fwTagDatas, FWTag.class); } } -class TagGridValues{ + +class TagGridValues { private List<Object> tags; public List<Object> getTags() { @@ -1077,7 +1222,8 @@ class TagGridValues{ } } -class AGGridData{ + +class AGGridData { private List<Object> attributes; public List<Object> getAttributes() { @@ -1089,7 +1235,8 @@ class AGGridData{ } } -class TermListData{ + +class TermListData { private List<Object> fromZoneDatas; private List<Object> toZoneDatas; private List<Object> sourceListDatas; @@ -1097,46 +1244,60 @@ class TermListData{ private List<Object> sourceServiceDatas; private List<Object> destinationServiceDatas; private List<Object> actionListDatas; + public List<Object> getFromZoneDatas() { return fromZoneDatas; } + public void setFromZoneDatas(List<Object> fromZoneDatas) { this.fromZoneDatas = fromZoneDatas; } + public List<Object> getToZoneDatas() { return toZoneDatas; } + public void setToZoneDatas(List<Object> toZoneDatas) { this.toZoneDatas = toZoneDatas; } + public List<Object> getSourceListDatas() { return sourceListDatas; } + public void setSourceListDatas(List<Object> sourceListDatas) { this.sourceListDatas = sourceListDatas; } + public List<Object> getDestinationListDatas() { return destinationListDatas; } + public void setDestinationListDatas(List<Object> destinationListDatas) { this.destinationListDatas = destinationListDatas; } + public List<Object> getSourceServiceDatas() { return sourceServiceDatas; } + public void setSourceServiceDatas(List<Object> sourceServiceDatas) { this.sourceServiceDatas = sourceServiceDatas; } + public List<Object> getDestinationServiceDatas() { return destinationServiceDatas; } + public void setDestinationServiceDatas(List<Object> destinationServiceDatas) { this.destinationServiceDatas = destinationServiceDatas; } + public List<Object> getActionListDatas() { return actionListDatas; } + public void setActionListDatas(List<Object> actionListDatas) { this.actionListDatas = actionListDatas; } -}
\ No newline at end of file +} diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java index 965235cce..c0e7729db 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.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,13 +20,14 @@ package org.onap.policy.pap.xacml.rest.controller; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.ArrayList; import java.util.List; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import org.apache.commons.lang.StringUtils; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; @@ -45,19 +46,16 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - @Controller public class PolicyScopeDictionaryController { - private static final Logger LOGGER = FlexLogger.getLogger(PolicyScopeDictionaryController.class); + private static final Logger LOGGER = + FlexLogger.getLogger(PolicyScopeDictionaryController.class); private static CommonClassDao commonClassDao; private static String operation = "operation"; private static String groupPolicyScopeListData1 = "groupPolicyScopeListData1"; - private static String policyScope= "PolicyScope"; + private static String policyScope = "PolicyScope"; private static String duplicateResponseString = "Duplicate"; private static String groupPolicyScopeDatas = "groupPolicyScopeListDatas"; private static String dictionaryFields = "dictionaryFields"; @@ -66,37 +64,41 @@ public class PolicyScopeDictionaryController { private static String psTypeDatas = "psTypeDictionaryDatas"; private static String psResourceDatas = "psResourceDictionaryDatas"; - public PolicyScopeDictionaryController(){ + public PolicyScopeDictionaryController() { super(); } - private DictionaryUtils getDictionaryUtilsInstance(){ + private DictionaryUtils getDictionaryUtilsInstance() { return DictionaryUtils.getDictionaryUtils(); } @Autowired - public PolicyScopeDictionaryController(CommonClassDao commonClassDao){ + public PolicyScopeDictionaryController(CommonClassDao commonClassDao) { PolicyScopeDictionaryController.commonClassDao = commonClassDao; } - public void setCommonClassDao(CommonClassDao commonClassDao){ + public void setCommonClassDao(CommonClassDao commonClassDao) { PolicyScopeDictionaryController.commonClassDao = commonClassDao; } - @RequestMapping(value={"/get_GroupPolicyScopeDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getGroupPolicyScopeEntityDataByName(HttpServletResponse response){ + @RequestMapping(value = {"/get_GroupPolicyScopeDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getGroupPolicyScopeEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, groupPolicyScopeDatas, "name", GroupPolicyScopeList.class); } - @RequestMapping(value={"/get_GroupPolicyScopeData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getGroupPolicyScopeEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_GroupPolicyScopeData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getGroupPolicyScopeEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, groupPolicyScopeDatas, GroupPolicyScopeList.class); } - @RequestMapping(value={"/ps_dictionary/save_psGroupPolicyScope"}, method={RequestMethod.POST}) - public ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/ps_dictionary/save_psGroupPolicyScope"}, + method = {RequestMethod.POST}) + public ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -107,31 +109,43 @@ public class PolicyScopeDictionaryController { GroupPolicyScope groupData = null; boolean duplicateGroupFlag = false; if (fromAPI) { - gpdata = mapper.readValue(root.get(dictionaryFields).toString(), GroupPolicyScopeList.class); - try{ - groupData = mapper.readValue(root.get(groupPolicyScopeListData1).toString(), GroupPolicyScope.class); - }catch(Exception e){ + gpdata = mapper.readValue(root.get(dictionaryFields).toString(), + GroupPolicyScopeList.class); + try { + groupData = mapper.readValue(root.get(groupPolicyScopeListData1).toString(), + GroupPolicyScope.class); + } catch (Exception e) { groupData = new GroupPolicyScope(); - groupData.setResource(root.get(dictionaryFields).get("resource").toString().replace("\"", "")); - groupData.setClosedloop(root.get(dictionaryFields).get("closedloop").toString().replace("\"", "")); - groupData.setService(root.get(dictionaryFields).get("service").toString().replace("\"", "")); - groupData.setType(root.get(dictionaryFields).get("type").toString().replace("\"", "")); + groupData.setResource(root.get(dictionaryFields).get("resource").toString() + .replace("\"", "")); + groupData.setClosedloop(root.get(dictionaryFields).get("closedloop").toString() + .replace("\"", "")); + groupData.setService( + root.get(dictionaryFields).get("service").toString().replace("\"", "")); + groupData.setType( + root.get(dictionaryFields).get("type").toString().replace("\"", "")); LOGGER.error(e); } } else { - gpdata = mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class); - try{ - groupData = mapper.readValue(root.get(groupPolicyScopeListData1).toString(), GroupPolicyScope.class); - }catch(Exception e){ + gpdata = mapper.readValue(root.get("groupPolicyScopeListData").toString(), + GroupPolicyScopeList.class); + try { + groupData = mapper.readValue(root.get(groupPolicyScopeListData1).toString(), + GroupPolicyScope.class); + } catch (Exception e) { LOGGER.error(e); groupData = new GroupPolicyScope(); - groupData.setResource(root.get(groupPolicyScopeListData1).get("resource").toString().replace("\"", "")); - groupData.setClosedloop(root.get(groupPolicyScopeListData1).get("closedloop").toString().replace("\"", "")); - groupData.setService(root.get(groupPolicyScopeListData1).get("service").toString().replace("\"", "")); - groupData.setType(root.get(groupPolicyScopeListData1).get("type").toString().replace("\"", "")); + groupData.setResource(root.get(groupPolicyScopeListData1).get("resource") + .toString().replace("\"", "")); + groupData.setClosedloop(root.get(groupPolicyScopeListData1).get("closedloop") + .toString().replace("\"", "")); + groupData.setService(root.get(groupPolicyScopeListData1).get("service") + .toString().replace("\"", "")); + groupData.setType(root.get(groupPolicyScopeListData1).get("type").toString() + .replace("\"", "")); } } - if(!gpdata.getGroupName().startsWith(policyScope)){ + if (!gpdata.getGroupName().startsWith(policyScope)) { String name = "PolicyScope_" + gpdata.getGroupName(); gpdata.setGroupName(name); } @@ -143,71 +157,83 @@ public class PolicyScopeDictionaryController { valueList.add("resource=" + resourceValue); valueList.add("service=" + serviceValue); valueList.add("type=" + typeValue); - valueList.add("closedLoopControlName=" + closedLoopValue); - String list = StringUtils.replaceEach(valueList.toString(), new String[]{"[", "]", " "}, new String[]{"", "", ""}); + valueList.add("closedLoopControlName=" + closedLoopValue); + String list = StringUtils.replaceEach(valueList.toString(), + new String[] {"[", "]", " "}, new String[] {"", "", ""}); gpdata.setGroupList(list); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), "name", GroupPolicyScopeList.class); - if(duplicateData.isEmpty()){ - duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupList(), "groupList", GroupPolicyScopeList.class); - if(duplicateData.isEmpty()){ + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), + "name", GroupPolicyScopeList.class); + if (duplicateData.isEmpty()) { + duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupList(), + "groupList", GroupPolicyScopeList.class); + if (duplicateData.isEmpty()) { duplicateGroupFlag = true; } } boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { GroupPolicyScopeList data = (GroupPolicyScopeList) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { gpdata.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != gpdata.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != gpdata.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag && !duplicateGroupFlag){ - if(gpdata.getId() == 0){ + if (!duplicateflag && !duplicateGroupFlag) { + if (gpdata.getId() == 0) { commonClassDao.save(gpdata); - }else{ + } else { commonClassDao.update(gpdata); } - responseString = mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class)); - }else if(duplicateGroupFlag){ + responseString = mapper + .writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class)); + } else if (duplicateGroupFlag) { responseString = "DuplicateGroup"; - }else{ + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, groupPolicyScopeDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/ps_dictionary/remove_GroupPolicyScope"}, method={RequestMethod.POST}) - public void removePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/ps_dictionary/remove_GroupPolicyScope"}, + method = {RequestMethod.POST}) + public void removePSGroupScopeDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, groupPolicyScopeDatas, GroupPolicyScopeList.class); } - @RequestMapping(value={"/get_PSClosedLoopDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPSClosedLoopEntityDataByName(HttpServletResponse response){ + @RequestMapping(value = {"/get_PSClosedLoopDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getPSClosedLoopEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, psCLDatas, "name", OnapName.class); } - @RequestMapping(value={"/get_PSClosedLoopData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPSClosedLoopEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_PSClosedLoopData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getPSClosedLoopEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, psCLDatas, PolicyScopeClosedLoop.class); } - @RequestMapping(value={"/ps_dictionary/save_psClosedLoop"}, method={RequestMethod.POST}) - public ModelAndView savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/ps_dictionary/save_psClosedLoop"}, method = {RequestMethod.POST}) + public ModelAndView savePSClosedLoopDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -215,65 +241,76 @@ public class PolicyScopeDictionaryController { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); PolicyScopeClosedLoop onapData; - if(fromAPI){ - onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeClosedLoop.class); - }else{ - onapData = mapper.readValue(root.get("psClosedLoopDictionaryData").toString(), PolicyScopeClosedLoop.class); + if (fromAPI) { + onapData = mapper.readValue(root.get(dictionaryFields).toString(), + PolicyScopeClosedLoop.class); + } else { + onapData = mapper.readValue(root.get("psClosedLoopDictionaryData").toString(), + PolicyScopeClosedLoop.class); } - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeClosedLoop.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), + "name", PolicyScopeClosedLoop.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { PolicyScopeClosedLoop data = (PolicyScopeClosedLoop) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { onapData.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != onapData.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != onapData.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ - if(onapData.getId() == 0){ + if (!duplicateflag) { + if (onapData.getId() == 0) { commonClassDao.save(onapData); - }else{ + } else { commonClassDao.update(onapData); } - responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class)); - }else{ + responseString = mapper + .writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, psCLDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/ps_dictionary/remove_PSClosedLoop"}, method={RequestMethod.POST}) - public void removePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/ps_dictionary/remove_PSClosedLoop"}, method = {RequestMethod.POST}) + public void removePSClosedLoopDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, psCLDatas, PolicyScopeClosedLoop.class); } - @RequestMapping(value={"/get_PSServiceDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPSServiceEntityDataByName(HttpServletResponse response){ + @RequestMapping(value = {"/get_PSServiceDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getPSServiceEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, psServiceDatas, "name", PolicyScopeService.class); } - @RequestMapping(value={"/get_PSServiceData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPSServiceEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_PSServiceData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getPSServiceEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, psServiceDatas, PolicyScopeService.class); } - @RequestMapping(value={"/ps_dictionary/save_psService"}, method={RequestMethod.POST}) - public ModelAndView savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/ps_dictionary/save_psService"}, method = {RequestMethod.POST}) + public ModelAndView savePSServiceDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -282,64 +319,75 @@ public class PolicyScopeDictionaryController { JsonNode root = mapper.readTree(request.getReader()); PolicyScopeService onapData; if (fromAPI) { - onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeService.class); + onapData = mapper.readValue(root.get(dictionaryFields).toString(), + PolicyScopeService.class); } else { - onapData = mapper.readValue(root.get("psServiceDictionaryData").toString(), PolicyScopeService.class); + onapData = mapper.readValue(root.get("psServiceDictionaryData").toString(), + PolicyScopeService.class); } - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), + "name", PolicyScopeService.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { PolicyScopeService data = (PolicyScopeService) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { onapData.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != onapData.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != onapData.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ - if(onapData.getId() == 0){ + if (!duplicateflag) { + if (onapData.getId() == 0) { commonClassDao.save(onapData); - }else{ + } else { commonClassDao.update(onapData); } - responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, psServiceDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/ps_dictionary/remove_PSService"}, method={RequestMethod.POST}) - public void removePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/ps_dictionary/remove_PSService"}, method = {RequestMethod.POST}) + public void removePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, psServiceDatas, PolicyScopeService.class); } - @RequestMapping(value={"/get_PSTypeDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPSTypeEntityDataByName(HttpServletResponse response){ + @RequestMapping(value = {"/get_PSTypeDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getPSTypeEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, psTypeDatas, "name", PolicyScopeType.class); } - @RequestMapping(value={"/get_PSTypeData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPSTypeEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_PSTypeData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getPSTypeEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, psTypeDatas, PolicyScopeType.class); } - @RequestMapping(value={"/ps_dictionary/save_psType"}, method={RequestMethod.POST}) - public ModelAndView savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/ps_dictionary/save_psType"}, method = {RequestMethod.POST}) + public ModelAndView savePSTypeDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -347,65 +395,76 @@ public class PolicyScopeDictionaryController { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); PolicyScopeType onapData; - if(fromAPI){ - onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeType.class); - }else{ - onapData = mapper.readValue(root.get("psTypeDictionaryData").toString(), PolicyScopeType.class); + if (fromAPI) { + onapData = mapper.readValue(root.get(dictionaryFields).toString(), + PolicyScopeType.class); + } else { + onapData = mapper.readValue(root.get("psTypeDictionaryData").toString(), + PolicyScopeType.class); } - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeType.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), + "name", PolicyScopeType.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { PolicyScopeType data = (PolicyScopeType) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { onapData.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != onapData.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != onapData.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ - if(onapData.getId() == 0){ + if (!duplicateflag) { + if (onapData.getId() == 0) { commonClassDao.save(onapData); - }else{ + } else { commonClassDao.update(onapData); } - responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, psTypeDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/ps_dictionary/remove_PSType"}, method={RequestMethod.POST}) - public void removePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/ps_dictionary/remove_PSType"}, method = {RequestMethod.POST}) + public void removePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, psTypeDatas, PolicyScopeType.class); } - @RequestMapping(value={"/get_PSResourceDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPSResourceEntityDataByName(HttpServletResponse response){ + @RequestMapping(value = {"/get_PSResourceDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getPSResourceEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, psResourceDatas, "name", PolicyScopeResource.class); } - @RequestMapping(value={"/get_PSResourceData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPSResourceEntityData(HttpServletResponse response){ + @RequestMapping(value = {"/get_PSResourceData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) + public void getPSResourceEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, psResourceDatas, PolicyScopeResource.class); } - @RequestMapping(value={"/ps_dictionary/save_psResource"}, method={RequestMethod.POST}) - public ModelAndView savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/ps_dictionary/save_psResource"}, method = {RequestMethod.POST}) + public ModelAndView savePSResourceDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -414,77 +473,94 @@ public class PolicyScopeDictionaryController { JsonNode root = mapper.readTree(request.getReader()); PolicyScopeResource onapData; if (fromAPI) { - onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeResource.class); + onapData = mapper.readValue(root.get(dictionaryFields).toString(), + PolicyScopeResource.class); } else { - onapData = mapper.readValue(root.get("psResourceDictionaryData").toString(), PolicyScopeResource.class); + onapData = mapper.readValue(root.get("psResourceDictionaryData").toString(), + PolicyScopeResource.class); } - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeResource.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), + "name", PolicyScopeResource.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { PolicyScopeResource data = (PolicyScopeResource) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { onapData.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != onapData.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != onapData.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ - if(onapData.getId() == 0){ + if (!duplicateflag) { + if (onapData.getId() == 0) { commonClassDao.save(onapData); - }else{ + } else { commonClassDao.update(onapData); } - responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class)); - }else{ + responseString = mapper + .writeValueAsString(commonClassDao.getData(PolicyScopeResource.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, psResourceDatas, responseString); } - }catch (Exception e){ + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value={"/ps_dictionary/remove_PSResource"}, method={RequestMethod.POST}) - public void removePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/ps_dictionary/remove_PSResource"}, method = {RequestMethod.POST}) + public void removePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, psResourceDatas, PolicyScopeResource.class); } } -class GroupPolicyScope{ + +class GroupPolicyScope { String resource; String type; String service; String closedloop; + public String getResource() { return resource; } + public void setResource(String resource) { this.resource = resource; } + public String getType() { return type; } + public void setType(String type) { this.type = type; } + public String getService() { return service; } + public void setService(String service) { this.service = service; } + public String getClosedloop() { return closedloop; } + public void setClosedloop(String closedloop) { this.closedloop = closedloop; } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyController.java index fe49e3478..6e794d966 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyController.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,13 +20,14 @@ package org.onap.policy.pap.xacml.rest.controller; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.Date; import java.util.List; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import org.onap.policy.pap.xacml.rest.util.DictionaryUtils; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.RiskType; @@ -39,10 +40,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - @Controller public class SafePolicyController { @@ -53,36 +50,39 @@ public class SafePolicyController { private static String safePolicyWarningDatas = "safePolicyWarningDatas"; @Autowired - public SafePolicyController(CommonClassDao commonClassDao){ + public SafePolicyController(CommonClassDao commonClassDao) { SafePolicyController.commonClassDao = commonClassDao; } - public void setCommonClassDao(CommonClassDao commonClassDao){ + public void setCommonClassDao(CommonClassDao commonClassDao) { SafePolicyController.commonClassDao = commonClassDao; } - public SafePolicyController(){ + public SafePolicyController() { super(); } - private DictionaryUtils getDictionaryUtilsInstance(){ + private DictionaryUtils getDictionaryUtilsInstance() { return DictionaryUtils.getDictionaryUtils(); } - @RequestMapping(value = { "/get_RiskTypeDataByName" }, method = {RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = {"/get_RiskTypeDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) public void getRiskTypeDictionaryByNameEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, riskTypeDatas, "name", RiskType.class); } - @RequestMapping(value = { "/get_RiskTypeData" }, method = {RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = {"/get_RiskTypeData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) public void getRiskTypeDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, riskTypeDatas, RiskType.class); } - @RequestMapping(value = { "/sp_dictionary/save_riskType" }, method = {RequestMethod.POST }) - public ModelAndView saveRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/sp_dictionary/save_riskType"}, method = {RequestMethod.POST}) + public ModelAndView saveRiskTypeDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -92,69 +92,80 @@ public class SafePolicyController { RiskType riskTypeData; String userId = null; if (fromAPI) { - riskTypeData = mapper.readValue(root.get("dictionaryFields").toString(), RiskType.class); + riskTypeData = + mapper.readValue(root.get("dictionaryFields").toString(), RiskType.class); userId = "API"; } else { - riskTypeData = mapper.readValue(root.get("riskTypeDictionaryData").toString(), RiskType.class); + riskTypeData = mapper.readValue(root.get("riskTypeDictionaryData").toString(), + RiskType.class); userId = root.get("userid").textValue(); } UserInfo userInfo = utils.getUserInfo(userId); - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(riskTypeData.getRiskName(), "name", RiskType.class); + List<Object> duplicateData = commonClassDao + .checkDuplicateEntry(riskTypeData.getRiskName(), "name", RiskType.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { RiskType data = (RiskType) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { riskTypeData.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != riskTypeData.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != riskTypeData.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ + if (!duplicateflag) { riskTypeData.setUserModifiedBy(userInfo); - if(riskTypeData.getId() == 0){ + if (riskTypeData.getId() == 0) { riskTypeData.setUserCreatedBy(userInfo); commonClassDao.save(riskTypeData); - }else{ + } else { riskTypeData.setModifiedDate(new Date()); commonClassDao.update(riskTypeData); } responseString = mapper.writeValueAsString(commonClassDao.getData(RiskType.class)); - }else{ + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, riskTypeDatas, responseString); } - }catch (Exception e) { + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value = { "/sp_dictionary/remove_riskType" }, method = {RequestMethod.POST }) - public void removeRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + @RequestMapping(value = {"/sp_dictionary/remove_riskType"}, method = {RequestMethod.POST}) + public void removeRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response) + throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, riskTypeDatas, RiskType.class); } - @RequestMapping(value = { "/get_SafePolicyWarningDataByName" }, method = {RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = {"/get_SafePolicyWarningDataByName"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) public void getSafePolicyWarningEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getDataByEntity(response, safePolicyWarningDatas, "name", SafePolicyWarning.class); } - @RequestMapping(value = { "/get_SafePolicyWarningData" }, method = {RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = {"/get_SafePolicyWarningData"}, method = {RequestMethod.GET}, + produces = MediaType.APPLICATION_JSON_VALUE) public void getSafePolicyWarningeEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.getData(response, safePolicyWarningDatas, SafePolicyWarning.class); } - @RequestMapping(value = { "/sp_dictionary/save_safePolicyWarning" }, method = {RequestMethod.POST }) - public ModelAndView saveSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/sp_dictionary/save_safePolicyWarning"}, + method = {RequestMethod.POST}) + public ModelAndView saveSafePolicyWarningDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); @@ -163,46 +174,55 @@ public class SafePolicyController { JsonNode root = mapper.readTree(request.getReader()); SafePolicyWarning safePolicyWarning; if (fromAPI) { - safePolicyWarning = mapper.readValue(root.get("dictionaryFields").toString(), SafePolicyWarning.class); + safePolicyWarning = mapper.readValue(root.get("dictionaryFields").toString(), + SafePolicyWarning.class); } else { - safePolicyWarning = mapper.readValue(root.get("safePolicyWarningData").toString(), SafePolicyWarning.class); + safePolicyWarning = mapper.readValue(root.get("safePolicyWarningData").toString(), + SafePolicyWarning.class); } - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(safePolicyWarning.getName(), "name", SafePolicyWarning.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry( + safePolicyWarning.getName(), "name", SafePolicyWarning.class); boolean duplicateflag = false; - if(!duplicateData.isEmpty()){ + if (!duplicateData.isEmpty()) { SafePolicyWarning data = (SafePolicyWarning) duplicateData.get(0); - if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){ + if (request.getParameter(operation) != null + && "update".equals(request.getParameter(operation))) { safePolicyWarning.setId(data.getId()); - }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || - (request.getParameter(operation) == null && (data.getId() != safePolicyWarning.getId()))){ + } else if ((request.getParameter(operation) != null + && !"update".equals(request.getParameter(operation))) + || (request.getParameter(operation) == null + && (data.getId() != safePolicyWarning.getId()))) { duplicateflag = true; } } String responseString = null; - if(!duplicateflag){ - if(safePolicyWarning.getId() == 0){ + if (!duplicateflag) { + if (safePolicyWarning.getId() == 0) { commonClassDao.save(safePolicyWarning); - }else{ + } else { commonClassDao.update(safePolicyWarning); } - responseString = mapper.writeValueAsString(commonClassDao.getData(SafePolicyWarning.class)); - }else{ + responseString = + mapper.writeValueAsString(commonClassDao.getData(SafePolicyWarning.class)); + } else { responseString = duplicateResponseString; } - if(fromAPI){ + if (fromAPI) { return utils.getResultForApi(responseString); - }else{ + } else { utils.setResponseData(response, safePolicyWarningDatas, responseString); } - }catch (Exception e) { + } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } - @RequestMapping(value = { "/sp_dictionary/remove_SafePolicyWarning" }, method = {RequestMethod.POST }) - public void removeSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { + @RequestMapping(value = {"/sp_dictionary/remove_SafePolicyWarning"}, + method = {RequestMethod.POST}) + public void removeSafePolicyWarningDictionary(HttpServletRequest request, + HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); utils.removeData(request, response, safePolicyWarningDatas, SafePolicyWarning.class); } |