From 91d04c64771832a0b8815ffbe1f0f9920320d94d Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Tue, 14 Feb 2017 19:41:00 -0500 Subject: Initial OpenECOMP policy/engine commit Change-Id: I7dbff37733b661643dd4d1caefa3d7dccc361b6e Signed-off-by: Pamela Dragosh --- .../ActionPolicyDictionaryController.java | 201 +++ .../rest/controller/BRMSDictionaryController.java | 183 +++ .../CheckDictionaryDuplicateEntries.java | 65 + .../controller/ClosedLoopDictionaryController.java | 764 ++++++++++ .../DecisionPolicyDictionaryController.java | 188 +++ .../DescriptiveDictionaryController.java | 190 +++ .../rest/controller/DictionaryController.java | 366 +++++ .../controller/DictionaryImportController.java | 617 ++++++++ .../controller/EnforcerDictionaryController.java | 127 ++ .../controller/FirewallDictionaryController.java | 1578 ++++++++++++++++++++ .../MicroServiceDictionaryController.java | 718 +++++++++ .../PolicyScopeDictionaryController.java | 667 +++++++++ .../rest/controller/SafePolicyController.java | 319 ++++ .../pap/xacml/rest/controller/package-info.java | 27 + 14 files changed, 6010 insertions(+) create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/BRMSDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/CheckDictionaryDuplicateEntries.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DictionaryImportController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/EnforcerDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/FirewallDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/SafePolicyController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/package-info.java (limited to 'ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller') diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java new file mode 100644 index 000000000..fa00fc1cc --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java @@ -0,0 +1,201 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.ActionPolicyDictDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.ActionPolicyDict; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +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 ActionPolicyDictionaryController { + + @Autowired + ActionPolicyDictDao actionPolicyDictDao; + + @Autowired + UserInfoDao userInfoDao; + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + @RequestMapping(value={"/get_ActionPolicyDictDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getActionEntitybyName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("actionPolicyDictionaryDatas", mapper.writeValueAsString(actionPolicyDictDao.getActionDictDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ActionPolicyDictData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getActionPolicyDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("actionPolicyDictionaryDatas", mapper.writeValueAsString(actionPolicyDictDao.getActionDictData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/action_dictionary/save_ActionDict.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ActionPolicyDict actionPolicyDict = (ActionPolicyDict)mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionPolicyDict.class); + ActionAdapter adapter = mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionAdapter.class); + String userId = root.get("loginId").textValue(); + String header = ""; + int counter = 0; + if(adapter.getHeaders().size() > 0){ + for(Object attribute : adapter.getHeaders()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + String value = ((LinkedHashMap) attribute).get("number").toString(); + if(counter>0){ + header = header + ":"; + } + header = header + key + "="; + header = header + value; + counter ++; + } + } + } + actionPolicyDict.setHeader(header); + if(actionPolicyDict.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(actionPolicyDict.getAttributeName(), "attributeName", ActionPolicyDict.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + actionPolicyDict.setUserCreatedBy(this.getUserInfo(userId)); + actionPolicyDict.setUserModifiedBy(this.getUserInfo(userId)); + actionPolicyDictDao.Save(actionPolicyDict); + } + }else{ + actionPolicyDict.setUserModifiedBy(this.getUserInfo(userId)); + actionPolicyDictDao.update(actionPolicyDict); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.actionPolicyDictDao.getActionDictData()); + } + JSONObject j = new JSONObject("{actionPolicyDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/action_dictionary/remove_actionPolicyDict.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ActionPolicyDict actionPolicyDict = (ActionPolicyDict)mapper.readValue(root.get("data").toString(), ActionPolicyDict.class); + actionPolicyDictDao.delete(actionPolicyDict); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.actionPolicyDictDao.getActionDictData()); + JSONObject j = new JSONObject("{actionPolicyDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } +} + +class ActionAdapter{ + private ArrayList headers; + + public ArrayList getHeaders() { + return headers; + } + + public void setHeaders(ArrayList headers) { + this.headers = headers; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/BRMSDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/BRMSDictionaryController.java new file mode 100644 index 000000000..bdf4d2c01 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/BRMSDictionaryController.java @@ -0,0 +1,183 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.IOUtils; +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.BRMSParamTemplateDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.BRMSParamTemplate; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +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{ + + @Autowired + BRMSParamTemplateDao brmsParamTemplateDao; + + @Autowired + UserInfoDao userInfoDao; + + private String rule; + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + @RequestMapping(value={"/get_BRMSParamDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getBRMSParamDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("brmsParamDictionaryDatas", mapper.writeValueAsString(brmsParamTemplateDao.getBRMSParamDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_BRMSParamData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getBRMSParamDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("brmsParamDictionaryDatas", mapper.writeValueAsString(brmsParamTemplateDao.getBRMSParamTemplateData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/brms_dictionary/set_BRMSParamData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public void SetRuleData(HttpServletRequest request, HttpServletResponse response) throws Exception{ + 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); + } + + @RequestMapping(value={"/brms_dictionary/save_BRMSParam.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + BRMSParamTemplate bRMSParamTemplateData = (BRMSParamTemplate)mapper.readValue(root.get("brmsParamDictionaryData").toString(), BRMSParamTemplate.class); + String userId = root.get("loginId").textValue(); + bRMSParamTemplateData.setRule(rule); + if(bRMSParamTemplateData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(bRMSParamTemplateData.getRuleName(), "ruleName", BRMSParamTemplate.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + bRMSParamTemplateData.setUserCreatedBy(this.getUserInfo(userId)); + brmsParamTemplateDao.Save(bRMSParamTemplateData); + } + }else{ + brmsParamTemplateDao.update(bRMSParamTemplateData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.brmsParamTemplateDao.getBRMSParamTemplateData()); + } + JSONObject j = new JSONObject("{brmsParamDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/brms_dictionary/remove_brmsParam.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + BRMSParamTemplate bRMSParamTemplateData = (BRMSParamTemplate)mapper.readValue(root.get("data").toString(), BRMSParamTemplate.class); + brmsParamTemplateDao.delete(bRMSParamTemplateData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.brmsParamTemplateDao.getBRMSParamTemplateData()); + JSONObject j = new JSONObject("{brmsParamDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/CheckDictionaryDuplicateEntries.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/CheckDictionaryDuplicateEntries.java new file mode 100644 index 000000000..e044340a9 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/CheckDictionaryDuplicateEntries.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +/* + * + * + * + * */ +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +public class CheckDictionaryDuplicateEntries { + + private static final Log logger = LogFactory.getLog(CheckDictionaryDuplicateEntries.class); + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public List CheckDuplicateEntry(String value, String columnName, Class class1) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(class1); + cr.add(Restrictions.eq(columnName,value)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying for Duplicate Entries for Table"+e + class1); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java new file mode 100644 index 000000000..d70661f88 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java @@ -0,0 +1,764 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.adapters.GridData; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.PEPOptionsDao; +import org.openecomp.policy.rest.dao.ServiceDictionaryDao; +import org.openecomp.policy.rest.dao.SiteDictionaryDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.dao.VNFTypeDao; +import org.openecomp.policy.rest.dao.VSCLActionDao; +import org.openecomp.policy.rest.dao.VarbindDictionaryDao; +import org.openecomp.policy.rest.jpa.ClosedLoopD2Services; +import org.openecomp.policy.rest.jpa.ClosedLoopSite; +import org.openecomp.policy.rest.jpa.PEPOptions; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.openecomp.policy.rest.jpa.VNFType; +import org.openecomp.policy.rest.jpa.VSCLAction; +import org.openecomp.policy.rest.jpa.VarbindDictionary; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +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{ + + @Autowired + VSCLActionDao vsclActionDao; + + @Autowired + VNFTypeDao vnfTypeDao; + + @Autowired + PEPOptionsDao pepOptionsDao; + + @Autowired + VarbindDictionaryDao varbindDao; + + @Autowired + ServiceDictionaryDao closedLoopServiceDao; + + @Autowired + SiteDictionaryDao closedLoopSiteDao; + + @Autowired + UserInfoDao userInfoDao; + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + + @RequestMapping(value={"/get_VSCLActionDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getVSCLActionDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(vsclActionDao.getVsclActionDataByName())); + org.openecomp.policy.pap.xacml.rest.util.JsonMessage msg = new org.openecomp.policy.pap.xacml.rest.util.JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + + @RequestMapping(value={"/get_VSCLActionData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getVSCLActionDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(vsclActionDao.getVSCLActionData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_VNFTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getVNFTypeDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(vnfTypeDao.getVNFTypeDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_VNFTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getVNFTypeDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(vnfTypeDao.getVNFTypeData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_PEPOptionsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPEPOptionsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(pepOptionsDao.getPEPOptionsDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_PEPOptionsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPEPOptionsDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(pepOptionsDao.getPEPOptionsData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_VarbindDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getVarbindDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("varbindDictionaryDatas", mapper.writeValueAsString(varbindDao.getVarbindDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_VarbindDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getVarbindDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("varbindDictionaryDatas", mapper.writeValueAsString(varbindDao.getVarbindDictionaryData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ClosedLoopServicesDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(closedLoopServiceDao.getCLServiceDictDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ClosedLoopServicesData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getClosedLoopServiceDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(closedLoopServiceDao.getClosedLoopD2ServicesData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ClosedLoopSiteDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(closedLoopSiteDao.getCLSiteDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ClosedLoopSiteData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getClosedLoopSiteDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(closedLoopSiteDao.getClosedLoopSiteData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/cl_dictionary/save_vsclAction.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + VSCLAction vSCLAction = (VSCLAction)mapper.readValue(root.get("vsclActionDictionaryData").toString(), VSCLAction.class); + String userId = root.get("loginId").textValue(); + if(vSCLAction.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(vSCLAction.getVsclaction(), "vsclaction", VSCLAction.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + vSCLAction.setUserCreatedBy(this.getUserInfo(userId)); + vSCLAction.setUserModifiedBy(this.getUserInfo(userId)); + vsclActionDao.Save(vSCLAction); + } + }else{ + vSCLAction.setUserModifiedBy(this.getUserInfo(userId)); + vsclActionDao.update(vSCLAction); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.vsclActionDao.getVSCLActionData()); + } + JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/remove_VsclAction.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeVSCLAction(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + VSCLAction vSCLAction = (VSCLAction)mapper.readValue(root.get("data").toString(), VSCLAction.class); + vsclActionDao.delete(vSCLAction); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.vsclActionDao.getVSCLActionData()); + JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/save_vnfType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + VNFType vNFType = (VNFType)mapper.readValue(root.get("vnfTypeDictionaryData").toString(), VNFType.class); + String userId = root.get("loginId").textValue(); + if(vNFType.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(vNFType.getVnftype(), "vnftype", VNFType.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + vNFType.setUserCreatedBy(this.getUserInfo(userId)); + vNFType.setUserModifiedBy(this.getUserInfo(userId)); + vnfTypeDao.Save(vNFType); + } + }else{ + vNFType.setUserModifiedBy(this.getUserInfo(userId)); + vnfTypeDao.update(vNFType); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.vnfTypeDao.getVNFTypeData()); + } + JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/remove_vnfType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeVnfType(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + VNFType vNFType = (VNFType)mapper.readValue(root.get("data").toString(), VNFType.class); + vnfTypeDao.delete(vNFType); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.vnfTypeDao.getVNFTypeData()); + JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/save_pepOptions.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PEPOptions pEPOptions = (PEPOptions)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class); + GridData gridData = (GridData)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class); + String userId = root.get("loginId").textValue(); + String actions = ""; + int counter = 0; + if(gridData.getAttributes().size() > 0){ + for(Object attribute : gridData.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + String value = ((LinkedHashMap) attribute).get("number").toString(); + if(counter>0){ + actions = actions + ":#@"; + } + actions = actions + key + "=#@"; + actions = actions + value; + counter ++; + } + } + } + pEPOptions.setActions(actions); + if(pEPOptions.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(pEPOptions.getPepName(), "pepName", PEPOptions.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + pEPOptions.setUserCreatedBy(this.getUserInfo(userId)); + pEPOptions.setUserModifiedBy(this.getUserInfo(userId)); + pepOptionsDao.Save(pEPOptions); + } + }else{ + pEPOptions.setUserModifiedBy(this.getUserInfo(userId)); + pepOptionsDao.update(pEPOptions); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.pepOptionsDao.getPEPOptionsData()); + } + JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/remove_pepOptions.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePEPOptions(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PEPOptions pEPOptions = (PEPOptions)mapper.readValue(root.get("data").toString(), PEPOptions.class); + pepOptionsDao.delete(pEPOptions); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.pepOptionsDao.getPEPOptionsData()); + JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/save_service.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ClosedLoopD2Services serviceData = (ClosedLoopD2Services)mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class); + String userId = root.get("loginId").textValue(); + if(serviceData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(serviceData.getServiceName(), "serviceName", ClosedLoopD2Services.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + serviceData.setUserCreatedBy(this.getUserInfo(userId)); + serviceData.setUserModifiedBy(this.getUserInfo(userId)); + closedLoopServiceDao.Save(serviceData); + } + }else{ + serviceData.setUserModifiedBy(this.getUserInfo(userId)); + closedLoopServiceDao.update(serviceData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.closedLoopServiceDao.getClosedLoopD2ServicesData()); + } + JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/remove_Service.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeServiceType(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ClosedLoopD2Services closedLoopD2Services = (ClosedLoopD2Services)mapper.readValue(root.get("data").toString(), ClosedLoopD2Services.class); + closedLoopServiceDao.delete(closedLoopD2Services); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.closedLoopServiceDao.getClosedLoopD2ServicesData()); + JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/save_siteName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ClosedLoopSite siteData = (ClosedLoopSite)mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), ClosedLoopSite.class); + String userId = root.get("loginId").textValue(); + if(siteData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(siteData.getSiteName(), "siteName", ClosedLoopSite.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + siteData.setUserCreatedBy(this.getUserInfo(userId)); + siteData.setUserModifiedBy(this.getUserInfo(userId)); + closedLoopSiteDao.Save(siteData); + } + }else{ + siteData.setUserModifiedBy(this.getUserInfo(userId)); + closedLoopSiteDao.update(siteData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.closedLoopSiteDao.getClosedLoopSiteData()); + } + JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/remove_site.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeSiteType(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ClosedLoopSite closedLoopSite = (ClosedLoopSite)mapper.readValue(root.get("data").toString(), ClosedLoopSite.class); + closedLoopSiteDao.delete(closedLoopSite); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.closedLoopSiteDao.getClosedLoopSiteData()); + JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/save_varbind.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class); + String userId = root.get("loginId").textValue(); + if(varbindDictionary.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(varbindDictionary.getVarbindName(), "varbindName", VarbindDictionary.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + varbindDictionary.setUserCreatedBy(this.getUserInfo(userId)); + varbindDictionary.setUserModifiedBy(this.getUserInfo(userId)); + varbindDao.Save(varbindDictionary); + } + }else{ + varbindDictionary.setUserModifiedBy(this.getUserInfo(userId)); + varbindDao.update(varbindDictionary); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.varbindDao.getVarbindDictionaryData()); + } + JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/remove_varbindDict.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeVarbind(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("data").toString(), VarbindDictionary.class); + varbindDao.delete(varbindDictionary); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.varbindDao.getVarbindDictionaryData()); + JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + +} + diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java new file mode 100644 index 000000000..3308a990f --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java @@ -0,0 +1,188 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.DecisionPolicyDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.Datatype; +import org.openecomp.policy.rest.jpa.DecisionSettings; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +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 { + + @Autowired + DecisionPolicyDao decisionPolicyDao; + + @Autowired + UserInfoDao userInfoDao; + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + @RequestMapping(value={"/get_SettingsDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getSettingsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("settingsDictionaryDatas", mapper.writeValueAsString(decisionPolicyDao.getDecisionDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + + @RequestMapping(value={"/get_SettingsDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getSettingsDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("settingsDictionaryDatas", mapper.writeValueAsString(decisionPolicyDao.getDecisionSettingsData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/decision_dictionary/save_Settings.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveSettingsDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + DecisionSettings decisionSettings = (DecisionSettings)mapper.readValue(root.get("settingsDictionaryData").toString(), DecisionSettings.class); + String userId = root.get("loginId").textValue(); + if(decisionSettings.getDatatypeBean().getShortName() != null){ + String datatype = decisionSettings.getDatatypeBean().getShortName(); + Datatype a = new Datatype(); + if(datatype.equalsIgnoreCase("string")){ + a.setId(26); + }else if(datatype.equalsIgnoreCase("integer")){ + a.setId(12); + }else if(datatype.equalsIgnoreCase("boolean")){ + a.setId(18); + }else if(datatype.equalsIgnoreCase("double")){ + a.setId(25); + }else if(datatype.equalsIgnoreCase("user")){ + a.setId(29); + } + decisionSettings.setDatatypeBean(a); + } + if(decisionSettings.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(decisionSettings.getXacmlId(), "xacmlId", DecisionSettings.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + decisionSettings.setUserCreatedBy(this.getUserInfo(userId)); + decisionSettings.setUserModifiedBy(this.getUserInfo(userId)); + decisionPolicyDao.Save(decisionSettings); + } + }else{ + decisionSettings.setUserModifiedBy(this.getUserInfo(userId)); + decisionPolicyDao.update(decisionSettings); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.decisionPolicyDao.getDecisionSettingsData()); + } + JSONObject j = new JSONObject("{settingsDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/settings_dictionary/remove_settings.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeSettingsDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + DecisionSettings decisionSettings = (DecisionSettings)mapper.readValue(root.get("data").toString(), DecisionSettings.class); + decisionPolicyDao.delete(decisionSettings); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.decisionPolicyDao.getDecisionSettingsData()); + JSONObject j = new JSONObject("{settingsDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java new file mode 100644 index 000000000..c184464fb --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java @@ -0,0 +1,190 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.adapters.GridData; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.DescriptiveScopeDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.DescriptiveScope; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +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 { + + @Autowired + DescriptiveScopeDao descriptiveScopeDao; + + @Autowired + UserInfoDao userInfoDao; + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + @RequestMapping(value={"/get_DescriptiveScopeByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getDescriptiveDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("descriptiveScopeDictionaryDatas", mapper.writeValueAsString(descriptiveScopeDao.getDescriptiveScopeDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_DescriptiveScope"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getDescriptiveDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("descriptiveScopeDictionaryDatas", mapper.writeValueAsString(descriptiveScopeDao.getDescriptiveScope())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/descriptive_dictionary/save_descriptive.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + DescriptiveScope descriptiveScope = (DescriptiveScope)mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), DescriptiveScope.class); + GridData data = (GridData)mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), GridData.class); + String userId = root.get("loginId").textValue(); + String header = ""; + int counter = 0; + if(data.getAttributes().size() > 0){ + for(Object attribute : data.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + String value = ((LinkedHashMap) attribute).get("number").toString(); + if(counter>0){ + header = header + "AND"; + } + header = header + key + ":"; + header = header + value; + counter ++; + } + } + } + descriptiveScope.setSearch(header); + if(descriptiveScope.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(descriptiveScope.getScopeName(), "descriptiveScopeName", DescriptiveScope.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + descriptiveScope.setUserCreatedBy(this.getUserInfo(userId)); + descriptiveScope.setUserModifiedBy(this.getUserInfo(userId)); + descriptiveScopeDao.Save(descriptiveScope); + } + }else{ + descriptiveScope.setUserModifiedBy(this.getUserInfo(userId)); + descriptiveScopeDao.update(descriptiveScope); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.descriptiveScopeDao.getDescriptiveScope()); + } + JSONObject j = new JSONObject("{descriptiveScopeDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/descriptive_dictionary/remove_descriptiveScope.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + DescriptiveScope descriptiveScope = (DescriptiveScope)mapper.readValue(root.get("data").toString(), DescriptiveScope.class); + descriptiveScopeDao.delete(descriptiveScope); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.descriptiveScopeDao.getDescriptiveScope()); + JSONObject j = new JSONObject("{descriptiveScopeDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } +} + diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DictionaryController.java new file mode 100644 index 000000000..aa2fb4acd --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DictionaryController.java @@ -0,0 +1,366 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.AttributeDao; +import org.openecomp.policy.rest.dao.CategoryDao; +import org.openecomp.policy.rest.dao.EcompNameDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.Attribute; +import org.openecomp.policy.rest.jpa.Category; +import org.openecomp.policy.rest.jpa.Datatype; +import org.openecomp.policy.rest.jpa.EcompName; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +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); + + @Autowired + AttributeDao attributeDao; + + @Autowired + EcompNameDao ecompNameDao; + + @Autowired + UserInfoDao userInfoDao; + + @Autowired + CategoryDao categoryDao; + + + public Category getCategory(){ + for (int i = 0; i < categoryDao.getCategoryListData().size() ; i++) { + Category value = categoryDao.getCategoryListData().get(i); + if (value.getShortName().equals("resource")) { + return value; + } + } + return null; + } + + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + @RequestMapping(value={"/get_AttributeDatabyAttributeName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getAttributeDictionaryEntityDatabyAttributeName(HttpServletRequest request, HttpServletResponse response){ + try{ + System.out.println(); + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("attributeDictionaryDatas", mapper.writeValueAsString(attributeDao.getAttributeData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + //Attribute Dictionary + @RequestMapping(value="/get_AttributeData", method= RequestMethod.GET , produces=MediaType.APPLICATION_JSON_VALUE) + public void getAttributeDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + System.out.println(); + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("attributeDictionaryDatas", mapper.writeValueAsString(attributeDao.getData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/attribute_dictionary/save_attribute.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + Attribute attributeData = (Attribute)mapper.readValue(root.get("attributeDictionaryData").toString(), Attribute.class); + AttributeValues attributeValueData = (AttributeValues)mapper.readValue(root.get("attributeDictionaryData").toString(), AttributeValues.class); + String userId = root.get("loginId").textValue(); + String userValue = ""; + int counter = 0; + if(attributeValueData.getUserDataTypeValues().size() > 0){ + for(Object attribute : attributeValueData.getUserDataTypeValues()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("attributeValues").toString(); + if(counter>0){ + userValue = userValue + ","; + } + userValue = userValue + key ; + counter ++; + } + } + } + attributeData.setAttributeValue(userValue); + if(attributeData.getDatatypeBean().getShortName() != null){ + String datatype = attributeData.getDatatypeBean().getShortName(); + Datatype a = new Datatype(); + if(datatype.equalsIgnoreCase("string")){ + a.setId(26); + }else if(datatype.equalsIgnoreCase("integer")){ + a.setId(12); + }else if(datatype.equalsIgnoreCase("boolean")){ + a.setId(18); + }else if(datatype.equalsIgnoreCase("double")){ + a.setId(25); + }else if(datatype.equalsIgnoreCase("user")){ + a.setId(29); + } + attributeData.setDatatypeBean(a); + } + if(attributeData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(attributeData.getXacmlId(), "xacmlId", Attribute.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + attributeData.setCategoryBean(this.getCategory()); + attributeData.setUserCreatedBy(this.getUserInfo(userId)); + attributeData.setUserModifiedBy(this.getUserInfo(userId)); + attributeDao.Save(attributeData); + } + }else{ + attributeData.setUserModifiedBy(this.getUserInfo(userId)); + attributeDao.update(attributeData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.attributeDao.getData()); + } + JSONObject j = new JSONObject("{attributeDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/attribute_dictionary/remove_attribute.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + Attribute attributeData = (Attribute)mapper.readValue(root.get("data").toString(), Attribute.class); + attributeDao.delete(attributeData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.attributeDao.getData()); + JSONObject j = new JSONObject("{attributeDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + //EcompName Dictionary + @RequestMapping(value={"/get_EcompNameDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getEcompNameDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + logger.info("get_EcompNameDataByName is called"); + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("ecompNameDictionaryDatas", mapper.writeValueAsString(ecompNameDao.getEcompNameDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_EcompNameData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getEcompNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + logger.info("get_EcompNameData is called"); + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("ecompNameDictionaryDatas", mapper.writeValueAsString(ecompNameDao.getEcompName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + logger.error("ERROR While callinge DAO: " + e.getMessage()); + } + } + + @RequestMapping(value={"/ecomp_dictionary/save_ecompName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveEcompDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + System.out.println("DictionaryController: saveEcompDictionary() is called"); + logger.debug("DictionaryController: saveEcompDictionary() is called"); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + EcompName ecompData = (EcompName)mapper.readValue(root.get("ecompNameDictionaryData").toString(), EcompName.class); + String userId = root.get("loginId").textValue(); + System.out.println("the userId from the ecomp portal is: " + userId); + if(ecompData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(ecompData.getEcompName(), "ecompName", EcompName.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + ecompData.setUserCreatedBy(getUserInfo(userId)); + ecompData.setUserModifiedBy(getUserInfo(userId)); + System.out.println("DictionaryController: got the user info now about to call Save() method on ecompNamedao"); + ecompNameDao.Save(ecompData); + } + }else{ + ecompData.setUserModifiedBy(this.getUserInfo(userId)); + ecompNameDao.update(ecompData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.ecompNameDao.getEcompName()); + } + JSONObject j = new JSONObject("{ecompNameDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ecomp_dictionary/remove_ecomp.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeEcompDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + EcompName ecompData = (EcompName)mapper.readValue(root.get("data").toString(), EcompName.class); + ecompNameDao.delete(ecompData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.ecompNameDao.getEcompName()); + JSONObject j = new JSONObject("{ecompNameDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + +} + +class AttributeValues{ + private ArrayList userDataTypeValues; + + public ArrayList getUserDataTypeValues() { + return userDataTypeValues; + } + + public void setUserDataTypeValues(ArrayList userDataTypeValues) { + this.userDataTypeValues = userDataTypeValues; + } +} + diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DictionaryImportController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DictionaryImportController.java new file mode 100644 index 000000000..3ed8f5d1c --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DictionaryImportController.java @@ -0,0 +1,617 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + /* + * + * + * */ +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.OutputStream; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.compress.utils.IOUtils; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.openecomp.policy.rest.dao.ActionListDao; +import org.openecomp.policy.rest.dao.ActionPolicyDictDao; +import org.openecomp.policy.rest.dao.AddressGroupDao; +import org.openecomp.policy.rest.dao.AttributeDao; +import org.openecomp.policy.rest.dao.BRMSParamTemplateDao; +import org.openecomp.policy.rest.dao.DecisionPolicyDao; +import org.openecomp.policy.rest.dao.DescriptiveScopeDao; +import org.openecomp.policy.rest.dao.EcompNameDao; +import org.openecomp.policy.rest.dao.PEPOptionsDao; +import org.openecomp.policy.rest.dao.PortListDao; +import org.openecomp.policy.rest.dao.PrefixListDao; +import org.openecomp.policy.rest.dao.ProtocolListDao; +import org.openecomp.policy.rest.dao.SecurityZoneDao; +import org.openecomp.policy.rest.dao.ServiceDictionaryDao; +import org.openecomp.policy.rest.dao.ServiceGroupDao; +import org.openecomp.policy.rest.dao.ServiceListDao; +import org.openecomp.policy.rest.dao.SiteDictionaryDao; +import org.openecomp.policy.rest.dao.TermListDao; +import org.openecomp.policy.rest.dao.VNFTypeDao; +import org.openecomp.policy.rest.dao.VSCLActionDao; +import org.openecomp.policy.rest.dao.VarbindDictionaryDao; +import org.openecomp.policy.rest.dao.ZoneDao; +import org.openecomp.policy.rest.jpa.ActionList; +import org.openecomp.policy.rest.jpa.ActionPolicyDict; +import org.openecomp.policy.rest.jpa.AddressGroup; +import org.openecomp.policy.rest.jpa.Attribute; +import org.openecomp.policy.rest.jpa.BRMSParamTemplate; +import org.openecomp.policy.rest.jpa.Category; +import org.openecomp.policy.rest.jpa.Datatype; +import org.openecomp.policy.rest.jpa.DecisionSettings; +import org.openecomp.policy.rest.jpa.DescriptiveScope; +import org.openecomp.policy.rest.jpa.EcompName; +import org.openecomp.policy.rest.jpa.GroupServiceList; +import org.openecomp.policy.rest.jpa.PEPOptions; +import org.openecomp.policy.rest.jpa.PREFIXLIST; +import org.openecomp.policy.rest.jpa.ProtocolList; +import org.openecomp.policy.rest.jpa.SecurityZone; +import org.openecomp.policy.rest.jpa.ServiceList; +import org.openecomp.policy.rest.jpa.TermList; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.openecomp.policy.rest.jpa.VNFType; +import org.openecomp.policy.rest.jpa.VSCLAction; +import org.openecomp.policy.rest.jpa.VarbindDictionary; +import org.openecomp.policy.rest.jpa.Zone; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +import au.com.bytecode.opencsv.CSVReader; + + +@Controller +public class DictionaryImportController { + private String newFile; + + @Autowired + AttributeDao attributeDao; + + @Autowired + ActionPolicyDictDao actionPolicyDictDao; + + @Autowired + EcompNameDao ecompNameDao; + + @Autowired + VNFTypeDao vnfTypeDao; + + @Autowired + VSCLActionDao vsclActionDao; + + @Autowired + PEPOptionsDao pepOptionsDao; + + @Autowired + VarbindDictionaryDao varbindDao; + + @Autowired + ServiceDictionaryDao closedLoopServiceDao; + + @Autowired + SiteDictionaryDao closedLoopSiteDao; + + @Autowired + DescriptiveScopeDao descriptiveScopeDao; + + @Autowired + PrefixListDao prefixListDao; + + @Autowired + PortListDao portListDao; + + @Autowired + ProtocolListDao protocolListDao; + + @Autowired + AddressGroupDao addressGroupDao; + + @Autowired + ActionListDao actionListDao; + + @Autowired + SecurityZoneDao securityZoneDao; + + @Autowired + ServiceGroupDao serviceGroupDao; + + @Autowired + ServiceListDao serviceListDao; + + @Autowired + TermListDao termListDao; + + @Autowired + ZoneDao zoneDao; + + @Autowired + DecisionPolicyDao decisionSettingsDao; + + @Autowired + BRMSParamTemplateDao brmsParamTemplateDao; + + @RequestMapping(value={"/dictionary/import_dictionary.htm/*"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public void ImportDictionaryData(HttpServletRequest request, HttpServletResponse response) throws Exception{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + //JsonNode root = mapper.readTree(request.getReader()); + String userId = request.getPathInfo().substring(request.getPathInfo().lastIndexOf("/")+1); + List items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); + for (FileItem item : items) { + File file = new File(item.getName()); + OutputStream outputStream = new FileOutputStream(file); + IOUtils.copy(item.getInputStream(), outputStream); + outputStream.close(); + this.newFile = file.toString(); + CSVReader csvReader = new CSVReader(new FileReader(this.newFile)); + List dictSheet = csvReader.readAll(); + if(item.getName().startsWith("Attribute")){ + for(int i = 1; i< dictSheet.size(); i++){ + Attribute attribute = new Attribute("", userId); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + attribute.setUserModifiedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("enforcerDictionaryDatas", mapper.writeValueAsString(enforcerPolicyDao.getEnforcingTypeData())); + org.openecomp.policy.pap.xacml.rest.util.JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/enforcer_dictionary/save_enforcerType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveEnforcerDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + EnforcingType enforcingType = (EnforcingType)mapper.readValue(root.get("enforcerDictionaryData").toString(), EnforcingType.class); + if(enforcingType.getId() == 0){ + enforcerPolicyDao.Save(enforcingType); + }else{ + enforcerPolicyDao.update(enforcingType); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(this.enforcerPolicyDao.getEnforcingTypeData()); + JSONObject j = new JSONObject("{enforcerDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/enforcer_dictionary/remove_enforcer.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeEnforcerDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + EnforcingType enforcingType = (EnforcingType)mapper.readValue(root.get("data").toString(), EnforcingType.class); + enforcerPolicyDao.delete(enforcingType); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.enforcerPolicyDao.getEnforcingTypeData()); + JSONObject j = new JSONObject("{enforcerDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/FirewallDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/FirewallDictionaryController.java new file mode 100644 index 000000000..d2c371509 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/FirewallDictionaryController.java @@ -0,0 +1,1578 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.jboss.netty.handler.ipfilter.CIDR; +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.adapters.GridData; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.ActionListDao; +import org.openecomp.policy.rest.dao.AddressGroupDao; +import org.openecomp.policy.rest.dao.FirewallDictionaryListDao; +import org.openecomp.policy.rest.dao.PortListDao; +import org.openecomp.policy.rest.dao.PrefixListDao; +import org.openecomp.policy.rest.dao.ProtocolListDao; +import org.openecomp.policy.rest.dao.SecurityZoneDao; +import org.openecomp.policy.rest.dao.ServiceGroupDao; +import org.openecomp.policy.rest.dao.ServiceListDao; +import org.openecomp.policy.rest.dao.TermListDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.dao.ZoneDao; +import org.openecomp.policy.rest.jpa.ActionList; +import org.openecomp.policy.rest.jpa.AddressGroup; +import org.openecomp.policy.rest.jpa.FirewallDictionaryList; +import org.openecomp.policy.rest.jpa.GroupServiceList; +import org.openecomp.policy.rest.jpa.PREFIXLIST; +import org.openecomp.policy.rest.jpa.PortList; +import org.openecomp.policy.rest.jpa.ProtocolList; +import org.openecomp.policy.rest.jpa.SecurityZone; +import org.openecomp.policy.rest.jpa.ServiceList; +import org.openecomp.policy.rest.jpa.TermList; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.openecomp.policy.rest.jpa.Zone; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +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 { + + @Autowired + PrefixListDao prefixListDao; + + @Autowired + PortListDao portListDao; + + @Autowired + ProtocolListDao protocolListDao; + + @Autowired + AddressGroupDao addressGroupDao; + + @Autowired + ActionListDao actionListDao; + + @Autowired + SecurityZoneDao securityZoneDao; + + @Autowired + ServiceGroupDao serviceGroupDao; + + @Autowired + ServiceListDao serviceListDao; + + @Autowired + TermListDao termListDao; + + @Autowired + ZoneDao zoneDao; + + @Autowired + UserInfoDao userInfoDao; + + @Autowired + FirewallDictionaryListDao fwDictionaryListDao; + + + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + @RequestMapping(value={"/get_PrefixListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPrefixListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("prefixListDictionaryDatas", mapper.writeValueAsString(prefixListDao.getPrefixListDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_PrefixListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPrefixListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("prefixListDictionaryDatas", mapper.writeValueAsString(prefixListDao.getPREFIXLISTData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_prefixList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PREFIXLIST prefixList = (PREFIXLIST)mapper.readValue(root.get("prefixListDictionaryData").toString(), PREFIXLIST.class); + if(prefixList.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(prefixList.getPrefixListName(), "prefixListName", PREFIXLIST.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + prefixListDao.Save(prefixList); + } + }else{ + prefixListDao.update(prefixList); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.prefixListDao.getPREFIXLISTData()); + } + JSONObject j = new JSONObject("{prefixListDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_PrefixList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PREFIXLIST prefixList = (PREFIXLIST)mapper.readValue(root.get("data").toString(), PREFIXLIST.class); + prefixListDao.delete(prefixList); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.prefixListDao.getPREFIXLISTData()); + JSONObject j = new JSONObject("{prefixListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/validate_prefixList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView validatePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PREFIXLIST prefixList = (PREFIXLIST)mapper.readValue(root.get("prefixListDictionaryData").toString(), PREFIXLIST.class); + String responseValidation = "success"; + try{ + CIDR.newCIDR(prefixList.getPrefixListValue()); + }catch(UnknownHostException e){ + responseValidation = "error"; + //AdminNotification.warn("IP not according to CIDR notation"); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{result: " + responseValidation + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_PortListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPortListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("portListDictionaryDatas", mapper.writeValueAsString(portListDao.getPortListData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_portName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PortList portList = (PortList)mapper.readValue(root.get("portListDictionaryData").toString(), PortList.class); + if(portList.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(portList.getPortName(), "portName", PortList.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + portListDao.Save(portList); + } + }else{ + portListDao.update(portList); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.portListDao.getPortListData()); + } + JSONObject j = new JSONObject("{portListDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_PortList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PortList portList = (PortList)mapper.readValue(root.get("data").toString(), PortList.class); + portListDao.delete(portList); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.portListDao.getPortListData()); + JSONObject j = new JSONObject("{portListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_ProtocolListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getProtocolListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("protocolListDictionaryDatas", mapper.writeValueAsString(protocolListDao.getProtocolListData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ProtocolListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getProtocolListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("protocolListDictionaryDatas", mapper.writeValueAsString(protocolListDao.getProtocolListDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_protocolList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ProtocolList protocolList = (ProtocolList)mapper.readValue(root.get("protocolListDictionaryData").toString(), ProtocolList.class); + if(protocolList.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(protocolList.getProtocolName(), "protocolName", ProtocolList.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + protocolListDao.Save(protocolList); + } + }else{ + protocolListDao.update(protocolList); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.protocolListDao.getProtocolListData()); + } + JSONObject j = new JSONObject("{protocolListDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_protocol.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ProtocolList protocolList = (ProtocolList)mapper.readValue(root.get("data").toString(), ProtocolList.class); + protocolListDao.delete(protocolList); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.protocolListDao.getProtocolListData()); + JSONObject j = new JSONObject("{protocolListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_AddressGroupDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getAddressGroupDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("addressGroupDictionaryDatas", mapper.writeValueAsString(addressGroupDao.getAddressGroupDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_AddressGroupData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getAddressGroupDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("addressGroupDictionaryDatas", mapper.writeValueAsString(addressGroupDao.getAddressGroupData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_addressGroup.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + AddressGroup addressGroup = (AddressGroup)mapper.readValue(root.get("addressGroupDictionaryData").toString(), AddressGroup.class); + GridData gridData = (GridData)mapper.readValue(root.get("addressGroupDictionaryData").toString(), GridData.class); + if(!addressGroup.getGroupName().startsWith("Group_")){ + String groupName = "Group_"+addressGroup.getGroupName(); + addressGroup.setGroupName(groupName); + } + String userValue = ""; + int counter = 0; + if(gridData.getAttributes().size() > 0){ + for(Object attribute : gridData.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + if(counter>0){ + userValue = userValue + ","; + } + userValue = userValue + key ; + counter ++; + } + } + } + addressGroup.setServiceList(userValue); + if(addressGroup.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + addressGroupDao.Save(addressGroup); + } + }else{ + addressGroupDao.update(addressGroup); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.addressGroupDao.getAddressGroupData()); + } + JSONObject j = new JSONObject("{addressGroupDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_AddressGroup.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + AddressGroup addressGroup = (AddressGroup)mapper.readValue(root.get("data").toString(), AddressGroup.class); + addressGroupDao.delete(addressGroup); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.addressGroupDao.getAddressGroupData()); + JSONObject j = new JSONObject("{addressGroupDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_ActionListDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getActionListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("actionListDictionaryDatas", mapper.writeValueAsString(actionListDao.getActionListDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ActionListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getActionListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("actionListDictionaryDatas", mapper.writeValueAsString(actionListDao.getActionListData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_ActionList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ActionList actionList = (ActionList)mapper.readValue(root.get("actionListDictionaryData").toString(), ActionList.class); + if(actionList.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(actionList.getActionName(), "actionName", ActionList.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + actionListDao.Save(actionList); + } + }else{ + actionListDao.update(actionList); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.actionListDao.getActionListData()); + } + JSONObject j = new JSONObject("{actionListDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_ActionList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ActionList actionList = (ActionList)mapper.readValue(root.get("data").toString(), ActionList.class); + actionListDao.delete(actionList); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.actionListDao.getActionListData()); + JSONObject j = new JSONObject("{actionListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_ServiceGroupData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getServiceGroupDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("serviceGroupDictionaryDatas", mapper.writeValueAsString(serviceGroupDao.getGroupServiceListData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ServiceGroupDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getServiceGroupDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("serviceGroupDictionaryDatas", mapper.writeValueAsString(serviceGroupDao.getGroupServiceDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_serviceGroup.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + GroupServiceList groupServiceList = (GroupServiceList)mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GroupServiceList.class); + GridData gridData = (GridData)mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GridData.class); + if(!groupServiceList.getGroupName().startsWith("Group_")){ + String groupName = "Group_"+groupServiceList.getGroupName(); + groupServiceList.setGroupName(groupName); + } + String userValue = ""; + int counter = 0; + if(gridData.getAttributes().size() > 0){ + for(Object attribute : gridData.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + if(counter>0){ + userValue = userValue + ","; + } + userValue = userValue + key ; + counter ++; + } + } + } + groupServiceList.setServiceList(userValue); + if(groupServiceList.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(groupServiceList.getGroupName(), "name", GroupServiceList.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + serviceGroupDao.Save(groupServiceList); + } + }else{ + serviceGroupDao.update(groupServiceList); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.serviceGroupDao.getGroupServiceListData()); + } + JSONObject j = new JSONObject("{serviceGroupDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_serviceGroup.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + GroupServiceList groupServiceList = (GroupServiceList)mapper.readValue(root.get("data").toString(), GroupServiceList.class); + serviceGroupDao.delete(groupServiceList); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.serviceGroupDao.getGroupServiceListData()); + JSONObject j = new JSONObject("{serviceGroupDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_SecurityZoneDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getSecurityZoneDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("securityZoneDictionaryDatas", mapper.writeValueAsString(securityZoneDao.getSecurityZoneDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_SecurityZoneData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getSecurityZoneDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("securityZoneDictionaryDatas", mapper.writeValueAsString(securityZoneDao.getSecurityZoneData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_securityZone.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + SecurityZone securityZone = (SecurityZone)mapper.readValue(root.get("securityZoneDictionaryData").toString(), SecurityZone.class); + if(securityZone.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(securityZone.getZoneName(), "zoneName", SecurityZone.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + securityZoneDao.Save(securityZone); + } + }else{ + securityZoneDao.update(securityZone); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.securityZoneDao.getSecurityZoneData()); + } + JSONObject j = new JSONObject("{securityZoneDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_securityZone.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + SecurityZone securityZone = (SecurityZone)mapper.readValue(root.get("data").toString(), SecurityZone.class); + securityZoneDao.delete(securityZone); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.securityZoneDao.getSecurityZoneData()); + JSONObject j = new JSONObject("{securityZoneDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + + @RequestMapping(value={"/get_ServiceListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getServiceListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("serviceListDictionaryDatas", mapper.writeValueAsString(serviceListDao.getServiceListData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ServiceListDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getServiceListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("serviceListDictionaryDatas", mapper.writeValueAsString(serviceListDao.getServiceListDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_serviceList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ServiceList serviceList = (ServiceList)mapper.readValue(root.get("serviceListDictionaryData").toString(), ServiceList.class); + GridData serviceListGridData = (GridData)mapper.readValue(root.get("serviceListDictionaryData").toString(), GridData.class); + String tcpValue = ""; + int counter = 0; + if(serviceListGridData.getTransportProtocols().size() > 0){ + for(Object attribute : serviceListGridData.getTransportProtocols()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + if(counter>0){ + tcpValue = tcpValue + ","; + } + tcpValue = tcpValue + key ; + counter ++; + } + } + } + serviceList.setServiceTransProtocol(tcpValue); + String appValue = ""; + int counter1 = 0; + if(serviceListGridData.getAppProtocols().size() > 0){ + for(Object attribute : serviceListGridData.getAppProtocols()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + if(counter1>0){ + appValue = appValue + ","; + } + appValue = appValue + key ; + counter1 ++; + } + } + } + serviceList.setServiceAppProtocol(appValue); + serviceList.setServiceType("SERVICE"); + if(serviceList.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(serviceList.getServiceName(), "serviceName", ServiceList.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + serviceListDao.Save(serviceList); + } + + }else{ + serviceListDao.update(serviceList); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.serviceListDao.getServiceListData()); + } + JSONObject j = new JSONObject("{serviceListDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_serviceList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ServiceList serviceList = (ServiceList)mapper.readValue(root.get("data").toString(), ServiceList.class); + serviceListDao.delete(serviceList); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.serviceListDao.getServiceListData()); + JSONObject j = new JSONObject("{serviceListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_ZoneData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getZoneDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("zoneDictionaryDatas", mapper.writeValueAsString(zoneDao.getZoneData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ZoneDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getZoneDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("zoneDictionaryDatas", mapper.writeValueAsString(zoneDao.getZoneDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_zoneName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + Zone zone = (Zone)mapper.readValue(root.get("zoneDictionaryData").toString(), Zone.class); + if(zone.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(zone.getZoneName(), "zoneName", Zone.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + zoneDao.Save(zone); + } + }else{ + zoneDao.update(zone); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.zoneDao.getZoneData()); + } + JSONObject j = new JSONObject("{zoneDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_zone.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + Zone zone = (Zone)mapper.readValue(root.get("data").toString(), Zone.class); + zoneDao.delete(zone); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.zoneDao.getZoneData()); + JSONObject j = new JSONObject("{zoneDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_TermListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getTermListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("termListDictionaryDatas", mapper.writeValueAsString(termListDao.getTermListDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_TermListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getTermListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("termListDictionaryDatas", mapper.writeValueAsString(termListDao.getTermListData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_termList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + TermList termList = (TermList)mapper.readValue(root.get("termListDictionaryData").toString(), TermList.class); + TermListData termListDatas = (TermListData)mapper.readValue(root.get("termListDictionaryData").toString(), TermListData.class); + String userId = root.get("loginId").textValue(); + String fromZoneValue = ""; + int counter = 0; + if(termListDatas.getFromZoneDatas().size() > 0){ + for(Object fromZone : termListDatas.getFromZoneDatas()){ + if(fromZone instanceof LinkedHashMap){ + String key = ((LinkedHashMap) fromZone).get("option").toString(); + if(counter>0){ + fromZoneValue = fromZoneValue + ","; + } + fromZoneValue = fromZoneValue + key ; + counter ++; + } + } + } + termList.setFromZones(fromZoneValue); + + String toZoneValue = ""; + int toZonecounter = 0; + if(termListDatas.getToZoneDatas().size() > 0){ + for(Object toZone : termListDatas.getToZoneDatas()){ + if(toZone instanceof LinkedHashMap){ + String key = ((LinkedHashMap) toZone).get("option").toString(); + if(toZonecounter>0){ + toZoneValue = toZoneValue + ","; + } + toZoneValue = toZoneValue + key ; + toZonecounter ++; + } + } + } + termList.setToZones(toZoneValue); + + String srcListValues = ""; + int srcListcounter = 0; + if(termListDatas.getSourceListDatas().size() > 0){ + for(Object srcList : termListDatas.getSourceListDatas()){ + if(srcList instanceof LinkedHashMap){ + String key = ((LinkedHashMap) srcList).get("option").toString(); + if(srcListcounter>0){ + srcListValues = srcListValues + ","; + } + srcListValues = srcListValues + key ; + srcListcounter ++; + } + } + } + termList.setSrcIPList(srcListValues); + + String desListValues = ""; + int destListcounter = 0; + if(termListDatas.getDestinationListDatas().size() > 0){ + for(Object desList : termListDatas.getDestinationListDatas()){ + if(desList instanceof LinkedHashMap){ + String key = ((LinkedHashMap) desList).get("option").toString(); + if(destListcounter>0){ + desListValues = desListValues + ","; + } + desListValues = desListValues + key ; + destListcounter ++; + } + } + } + termList.setDestIPList(desListValues); + + String srcSerValue = ""; + int srcSercounter = 0; + if(termListDatas.getSourceServiceDatas().size() > 0){ + for(Object srcSrc : termListDatas.getSourceServiceDatas()){ + if(srcSrc instanceof LinkedHashMap){ + String key = ((LinkedHashMap) srcSrc).get("option").toString(); + if(srcSercounter>0){ + srcSerValue = srcSerValue + ","; + } + srcSerValue = srcSerValue + key ; + srcSercounter ++; + } + } + } + termList.setSrcPortList(srcSerValue); + + String desSrcValue = ""; + int desSrccounter = 0; + if(termListDatas.getDestinationServiceDatas().size() > 0){ + for(Object desSrc : termListDatas.getDestinationServiceDatas()){ + if(desSrc instanceof LinkedHashMap){ + String key = ((LinkedHashMap) desSrc).get("option").toString(); + if(desSrccounter>0){ + desSrcValue = desSrcValue + ","; + } + desSrcValue = desSrcValue + key ; + desSrccounter ++; + } + } + } + termList.setDestPortList(desSrcValue); + + String actionValue = ""; + int actioncounter = 0; + if(termListDatas.getActionListDatas().size() > 0){ + for(Object actionList : termListDatas.getActionListDatas()){ + if(actionList instanceof LinkedHashMap){ + String key = ((LinkedHashMap) actionList).get("option").toString(); + if(actioncounter>0){ + actionValue = actionValue + ","; + } + actionValue = actionValue + key ; + actioncounter ++; + } + } + } + termList.setAction(actionValue); + + if(termList.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(termList.getTermName(), "termName", TermList.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + termList.setUserCreatedBy(this.getUserInfo(userId)); + termList.setUserModifiedBy(this.getUserInfo(userId)); + termListDao.Save(termList); + } + }else{ + termList.setUserModifiedBy(this.getUserInfo(userId)); + termListDao.update(termList); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.termListDao.getTermListData()); + } + JSONObject j = new JSONObject("{termListDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_termList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + TermList termList = (TermList)mapper.readValue(root.get("data").toString(), TermList.class); + termListDao.delete(termList); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.termListDao.getTermListData()); + JSONObject j = new JSONObject("{termListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + //ParentList Dictionary Data + @RequestMapping(value={"/get_FWDictionaryListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getFWDictListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("fwDictListDictionaryDatas", mapper.writeValueAsString(fwDictionaryListDao.getFWDictionaryListDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_FWDictionaryListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getFWDictionaryListEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("fwDictListDictionaryDatas", mapper.writeValueAsString(fwDictionaryListDao.getFWDictionaryListData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_FWDictionaryList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveFWDictionaryList(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + FirewallDictionaryList fwDictList = (FirewallDictionaryList)mapper.readValue(root.get("fwDictListDictionaryData").toString(), FirewallDictionaryList.class); + GridData gridData = (GridData)mapper.readValue(root.get("fwDictListDictionaryData").toString(), GridData.class); + String userSLValue = ""; + int slcounter = 0; + if(gridData.getAttributes().size() > 0){ + for(Object attribute : gridData.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + if(slcounter>0){ + userSLValue = userSLValue + ","; + } + userSLValue = userSLValue + key ; + slcounter ++; + } + } + } + fwDictList.setServiceList(userSLValue); + String userALValue = ""; + int alcounter = 0; + if(gridData.getAlAttributes().size() > 0){ + for(Object attribute : gridData.getAlAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + if(alcounter>0){ + userALValue = userALValue + ","; + } + userALValue = userALValue + key ; + alcounter ++; + } + } + } + fwDictList.setAddressList(userALValue); + if(fwDictList.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(fwDictList.getParentItemName(), "parentItemName", FirewallDictionaryList.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + fwDictionaryListDao.Save(fwDictList); + } + }else{ + fwDictionaryListDao.update(fwDictList); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.fwDictionaryListDao.getFWDictionaryListData()); + } + JSONObject j = new JSONObject("{fwDictListDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_FWDictionaryList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeFWDictionaryListy(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + FirewallDictionaryList fwDictList = (FirewallDictionaryList)mapper.readValue(root.get("data").toString(), FirewallDictionaryList.class); + fwDictionaryListDao.delete(fwDictList); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.fwDictionaryListDao.getFWDictionaryListData()); + JSONObject j = new JSONObject("{fwDictListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } +} + +class AGGridData{ + private ArrayList attributes; + + public ArrayList getAttributes() { + return attributes; + } + + public void setAttributes(ArrayList attributes) { + this.attributes = attributes; + } +} + +class TermListData{ + private ArrayList fromZoneDatas; + private ArrayList toZoneDatas; + private ArrayList sourceListDatas; + private ArrayList destinationListDatas; + private ArrayList sourceServiceDatas; + private ArrayList destinationServiceDatas; + private ArrayList actionListDatas; + public ArrayList getFromZoneDatas() { + return fromZoneDatas; + } + public void setFromZoneDatas(ArrayList fromZoneDatas) { + this.fromZoneDatas = fromZoneDatas; + } + public ArrayList getToZoneDatas() { + return toZoneDatas; + } + public void setToZoneDatas(ArrayList toZoneDatas) { + this.toZoneDatas = toZoneDatas; + } + public ArrayList getSourceListDatas() { + return sourceListDatas; + } + public void setSourceListDatas(ArrayList sourceListDatas) { + this.sourceListDatas = sourceListDatas; + } + public ArrayList getDestinationListDatas() { + return destinationListDatas; + } + public void setDestinationListDatas(ArrayList destinationListDatas) { + this.destinationListDatas = destinationListDatas; + } + public ArrayList getSourceServiceDatas() { + return sourceServiceDatas; + } + public void setSourceServiceDatas(ArrayList sourceServiceDatas) { + this.sourceServiceDatas = sourceServiceDatas; + } + public ArrayList getDestinationServiceDatas() { + return destinationServiceDatas; + } + public void setDestinationServiceDatas(ArrayList destinationServiceDatas) { + this.destinationServiceDatas = destinationServiceDatas; + } + public ArrayList getActionListDatas() { + return actionListDatas; + } + public void setActionListDatas(ArrayList actionListDatas) { + this.actionListDatas = actionListDatas; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java new file mode 100644 index 000000000..c3329db14 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java @@ -0,0 +1,718 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.compress.utils.IOUtils; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.DCAEUUIDDao; +import org.openecomp.policy.rest.dao.MicroServiceConfigNameDao; +import org.openecomp.policy.rest.dao.MicroServiceLocationDao; +import org.openecomp.policy.rest.dao.MicroServiceModelsDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.DCAEuuid; +import org.openecomp.policy.rest.jpa.MicroServiceConfigName; +import org.openecomp.policy.rest.jpa.MicroServiceLocation; +import org.openecomp.policy.rest.jpa.MicroServiceModels; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.openecomp.policy.rest.util.MSAttributeObject; +import org.openecomp.policy.rest.util.MSModelUtitils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +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 MicroServiceDictionaryController { + private static final Log logger = LogFactory.getLog(MicroServiceDictionaryController.class); + + @Autowired + MicroServiceConfigNameDao microServiceConfigNameDao; + + @Autowired + MicroServiceLocationDao microServiceLocationDao; + + @Autowired + MicroServiceModelsDao microServiceModelsDao; + + @Autowired + DCAEUUIDDao dcaeUUIDDao; + + @Autowired + UserInfoDao userInfoDao; + + + private String newFile; + private String directory; + private List dirDependencyList = new ArrayList(); + private HashMap classMap = new HashMap(); + MSModelUtitils utils = new MSModelUtitils(); + private MicroServiceModels newModel; + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + @RequestMapping(value={"/get_DCAEUUIDDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getDCAEUUIDDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("dcaeUUIDDictionaryDatas", mapper.writeValueAsString(dcaeUUIDDao.getDCAEuuidDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_DCAEUUIDData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getDCAEUUIDDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("dcaeUUIDDictionaryDatas", mapper.writeValueAsString(dcaeUUIDDao.getDCAEuuidData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ms_dictionary/save_dcaeUUID.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + DCAEuuid dCAEuuid = (DCAEuuid)mapper.readValue(root.get("dcaeUUIDDictionaryData").toString(), DCAEuuid.class); + if(dCAEuuid.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(dCAEuuid.getName(), "name", DCAEuuid.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + dcaeUUIDDao.Save(dCAEuuid); + } + }else{ + dcaeUUIDDao.update(dCAEuuid); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.dcaeUUIDDao.getDCAEuuidData()); + } + JSONObject j = new JSONObject("{dcaeUUIDDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ms_dictionary/remove_dcaeuuid.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + DCAEuuid dCAEuuid = (DCAEuuid)mapper.readValue(root.get("data").toString(), DCAEuuid.class); + dcaeUUIDDao.delete(dCAEuuid); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.dcaeUUIDDao.getDCAEuuidData()); + JSONObject j = new JSONObject("{dcaeUUIDDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + + @RequestMapping(value={"/get_MicroServiceConfigNameDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceConfigNameByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("microServiceCongigNameDictionaryDatas", mapper.writeValueAsString(microServiceConfigNameDao.getMSConfigDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + + + @RequestMapping(value={"/get_MicroServiceConfigNameData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceConfigNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("microServiceCongigNameDictionaryDatas", mapper.writeValueAsString(microServiceConfigNameDao.getMicroServiceConfigNameData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ms_dictionary/save_configName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + MicroServiceConfigName microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get("microServiceCongigNameDictionaryData").toString(), MicroServiceConfigName.class); + if(microServiceConfigName.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(microServiceConfigName.getName(), "name", MicroServiceConfigName.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + microServiceConfigNameDao.Save(microServiceConfigName); + } + }else{ + microServiceConfigNameDao.update(microServiceConfigName); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.microServiceConfigNameDao.getMicroServiceConfigNameData()); + } + JSONObject j = new JSONObject("{microServiceCongigNameDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ms_dictionary/remove_msConfigName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + MicroServiceConfigName microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get("data").toString(), MicroServiceConfigName.class); + microServiceConfigNameDao.delete(microServiceConfigName); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.microServiceConfigNameDao.getMicroServiceConfigNameData()); + JSONObject j = new JSONObject("{microServiceCongigNameDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_MicroServiceLocationDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceLocationByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("microServiceLocationDictionaryDatas", mapper.writeValueAsString(microServiceLocationDao.getMSLocationDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_MicroServiceLocationData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceLocationDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("microServiceLocationDictionaryDatas", mapper.writeValueAsString(microServiceLocationDao.getMicroServiceLocationData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ms_dictionary/save_location.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + MicroServiceLocation microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get("microServiceLocationDictionaryData").toString(), MicroServiceLocation.class); + if(microServiceLocation.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(microServiceLocation.getName(), "name", MicroServiceLocation.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + microServiceLocationDao.Save(microServiceLocation); + } + }else{ + microServiceLocationDao.update(microServiceLocation); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.microServiceLocationDao.getMicroServiceLocationData()); + } + JSONObject j = new JSONObject("{microServiceLocationDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ms_dictionary/remove_msLocation.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + MicroServiceLocation microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get("data").toString(), MicroServiceLocation.class); + microServiceLocationDao.delete(microServiceLocation); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.microServiceLocationDao.getMicroServiceLocationData()); + JSONObject j = new JSONObject("{microServiceLocationDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_MicroServiceModelsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceModelsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(microServiceModelsDao.getMSModelsDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_MicroServiceModelsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceModelsDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(microServiceModelsDao.getMicroServiceModelsData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ms_dictionary/save_model.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + MicroServiceModels microServiceModels = (MicroServiceModels)mapper.readValue(root.get("microServiceModelsDictionaryData").toString(), MicroServiceModels.class); + String userId = root.get("loginId").textValue(); + microServiceModels.setAttributes(this.newModel.getAttributes()); + microServiceModels.setRef_attributes(this.newModel.getRef_attributes()); + microServiceModels.setDependency(this.newModel.getDependency()); + microServiceModels.setModelName(this.newModel.getModelName()); + microServiceModels.setSub_attributes(this.newModel.getSub_attributes()); + microServiceModels.setVersion(this.newModel.getVersion()); + if(microServiceModels.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(microServiceModels.getModelName(), "modelName", MicroServiceModels.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + microServiceModels.setUserCreatedBy(this.getUserInfo(userId)); + microServiceModelsDao.Save(microServiceModels); + } + }else{ + microServiceModelsDao.update(microServiceModels); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.microServiceModelsDao.getMicroServiceModelsData()); + } + JSONObject j = new JSONObject("{microServiceModelsDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ms_dictionary/remove_msModel.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + MicroServiceModels microServiceModels = (MicroServiceModels)mapper.readValue(root.get("data").toString(), MicroServiceModels.class); + microServiceModelsDao.delete(microServiceModels); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.microServiceModelsDao.getMicroServiceModelsData()); + JSONObject j = new JSONObject("{microServiceModelsDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ms_dictionary/set_MSModelData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public void SetRuleData(HttpServletRequest request, HttpServletResponse response) throws Exception{ + List items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); + for (FileItem item : items) { + if(item.getName().endsWith(".zip")){ + this.newModel = new MicroServiceModels(); + try{ + File file = new File(item.getName()); + OutputStream outputStream = new FileOutputStream(file); + IOUtils.copy(item.getInputStream(), outputStream); + outputStream.close(); + this.newFile = file.toString(); + this.newModel.setModelName(this.newFile.toString().split("-v")[0]); + if (this.newFile.toString().contains("-v")){ + this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".zip", "")); + } + }catch(Exception e){ + logger.error("Upload error : " + e); + } + } + } + extractFolder(this.newFile); + List fileList = listModelFiles(this.directory); + + File folder = new File(this.directory); + File[] test = folder.listFiles(); + + //Process Main Model file first + String ignoreFile = null; + for (File file : test) { + if(!file.isDirectory() && file.getName().endsWith(".xmi")){ + retreiveDependency(file.toString(), true); + ignoreFile = file.toString(); + } + } + + for(File tempFile: fileList){ + if (!tempFile.toString().contains(ignoreFile)){ + retreiveDependency(tempFile.toString(), false); + } + } + + addValuesToNewModel(); + + File deleteFile = new File(this.newFile); + deleteFile.delete(); + } + + private void addValuesToNewModel() { + //Loop through the classmap and pull out the required info for the new file. + MSAttributeObject mainClass = null; + ArrayList dependency = null; + String subAttribute = null; + + mainClass = classMap.get(this.newModel.getModelName()); + + if (mainClass !=null){ + String dependTemp = StringUtils.replaceEach(mainClass.getDependency(), new String[]{"[", "]", " "}, new String[]{"", "", ""}); + dependency = new ArrayList(Arrays.asList(dependTemp.split(","))); + dependency = getFullDependencyList(dependency); + for (String element : dependency){ + MSAttributeObject temp = new MSAttributeObject(); + temp = classMap.get(element); + if (temp!=null){ + mainClass.addAllRefAttribute(temp.getRefAttribute()); + mainClass.addAllAttribute(temp.getAttribute()); + } + } + subAttribute = utils.createSubAttributes(dependency, classMap, this.newModel.getModelName()); + }else{ + subAttribute = "{}"; + this.newModel.setDependency(""); + } + + if (mainClass.getDependency()==null){ + mainClass.setDependency(""); + } + + this.newModel.setDependency(mainClass.getDependency()); + this.newModel.setSub_attributes(subAttribute.toString()); + this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", "")); + this.newModel.setRef_attributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", "")); + + } + + private ArrayList getFullDependencyList(ArrayList dependency) { + ArrayList returnList = new ArrayList(); + ArrayList workingList = new ArrayList(); + returnList.addAll(dependency); + for (String element : dependency ){ + if (classMap.containsKey(element)){ + MSAttributeObject value = classMap.get(element); + String rawValue = StringUtils.replaceEach(value.getDependency(), new String[]{"[", "]"}, new String[]{"", ""}); + workingList = new ArrayList(Arrays.asList(rawValue.split(","))); + for(String depend : workingList){ + if (!returnList.contains(depend) && !depend.isEmpty()){ + returnList.add(depend.trim()); + //getFullDepedency(workingList) + } + } + } + } + + return returnList; + } + + + /* + * Unzip file and store in the model directory for processing + */ + @SuppressWarnings("rawtypes") + private void extractFolder(String zipFile ) { + int BUFFER = 2048; + File file = new File(zipFile); + + ZipFile zip; + try { + zip = new ZipFile(file); + String newPath = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4); + this.directory = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4); + new File(newPath).mkdir(); + Enumeration zipFileEntries = zip.entries(); + + // Process each entry + while (zipFileEntries.hasMoreElements()){ + // grab a zip file entry + ZipEntry entry = (ZipEntry) zipFileEntries.nextElement(); + String currentEntry = entry.getName(); + File destFile = new File("model" + File.separator + currentEntry); + File destinationParent = destFile.getParentFile(); + + destinationParent.mkdirs(); + + if (!entry.isDirectory()){ + BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry)); + int currentByte; + byte data[] = new byte[BUFFER]; + FileOutputStream fos = new FileOutputStream(destFile); + BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER); + while ((currentByte = is.read(data, 0, BUFFER)) != -1) { + dest.write(data, 0, currentByte); + } + dest.flush(); + dest.close(); + is.close(); + } + + if (currentEntry.endsWith(".zip")){ + extractFolder(destFile.getAbsolutePath()); + } + } + } catch (IOException e) { + logger.error("Failed to unzip model file " + zipFile); + } + } + + private void retreiveDependency(String workingFile, Boolean modelClass) { + + MSModelUtitils utils = new MSModelUtitils(); + HashMap tempMap = new HashMap(); + + tempMap = utils.processEpackage(workingFile); + + classMap.putAll(tempMap); + System.out.println(tempMap); + + return; } + + private List listModelFiles(String directoryName) { + File directory = new File(directoryName); + List resultList = new ArrayList(); + File[] fList = directory.listFiles(); + for (File file : fList) { + if (file.isFile()) { + resultList.add(file); + } else if (file.isDirectory()) { + dirDependencyList.add(file.getName()); + resultList.addAll(listModelFiles(file.getAbsolutePath())); + } + } + return resultList; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java new file mode 100644 index 000000000..b8803d738 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java @@ -0,0 +1,667 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.GroupPolicyScopeListDao; +import org.openecomp.policy.rest.dao.PolicyScopeClosedLoopDao; +import org.openecomp.policy.rest.dao.PolicyScopeResourceDao; +import org.openecomp.policy.rest.dao.PolicyScopeServiceDao; +import org.openecomp.policy.rest.dao.PolicyScopeTypeDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.GroupPolicyScopeList; +import org.openecomp.policy.rest.jpa.PolicyScopeClosedLoop; +import org.openecomp.policy.rest.jpa.PolicyScopeResource; +import org.openecomp.policy.rest.jpa.PolicyScopeService; +import org.openecomp.policy.rest.jpa.PolicyScopeType; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +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 { + + @Autowired + GroupPolicyScopeListDao groupPolicyScopeListDao; + + @Autowired + PolicyScopeClosedLoopDao policyScopeClosedLoopDao; + + @Autowired + PolicyScopeResourceDao PolicyScopeResourceDao; + + @Autowired + PolicyScopeTypeDao policyScopeTypeDao; + + @Autowired + PolicyScopeServiceDao policyScopeServiceDao; + + + @Autowired + UserInfoDao userInfoDao; + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + @RequestMapping(value={"/get_GroupPolicyScopeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getGroupPolicyScopeEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(groupPolicyScopeListDao.getGroupPolicyScopeListDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_GroupPolicyScopeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getGroupPolicyScopeEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(groupPolicyScopeListDao.getGroupPolicyScopeListData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ps_dictionary/save_psGroupPolicyScope.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + GroupPolicyScopeList ecompData = (GroupPolicyScopeList)mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class); + GroupPolicyScope groupData = null; + try{ + groupData = (GroupPolicyScope)mapper.readValue(root.get("groupPolicyScopeListData1").toString(), GroupPolicyScope.class); + }catch(Exception 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("\"", "")); + } + + ArrayList valueList = new ArrayList(); + String list = null; + String resourceValue = groupData.getResource(); + String typeValue = groupData.getType(); + String serviceValue = groupData.getService(); + String closedLoopValue = groupData.getClosedloop(); + valueList.add("resource=" + resourceValue); + valueList.add("service=" + serviceValue); + valueList.add("type=" + typeValue); + valueList.add("closedLoopControlName=" + closedLoopValue); + list = StringUtils.replaceEach(valueList.toString(), new String[]{"[", "]", " "}, new String[]{"", "", ""}); + ecompData.setGroupList(list); + if(!ecompData.getGroupName().startsWith("PolicyScope")){ + String name = "PolicyScope_" + ecompData.getGroupName(); + ecompData.setGroupName(name); + } + if(ecompData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(ecompData.getGroupName(), "name", GroupPolicyScopeList.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + groupPolicyScopeListDao.Save(ecompData); + } + }else{ + groupPolicyScopeListDao.update(ecompData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.groupPolicyScopeListDao.getGroupPolicyScopeListData()); + } + JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ps_dictionary/remove_GroupPolicyScope.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + GroupPolicyScopeList ecompData = (GroupPolicyScopeList)mapper.readValue(root.get("data").toString(), GroupPolicyScopeList.class); + groupPolicyScopeListDao.delete(ecompData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.groupPolicyScopeListDao.getGroupPolicyScopeListData()); + JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_PSClosedLoopDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPSClosedLoopEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(policyScopeClosedLoopDao.getPolicyScopeClosedLoopDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_PSClosedLoopData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPSClosedLoopEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(policyScopeClosedLoopDao.getPolicyScopeClosedLoopData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ps_dictionary/save_psClosedLoop.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyScopeClosedLoop ecompData = (PolicyScopeClosedLoop)mapper.readValue(root.get("psClosedLoopDictionaryData").toString(), PolicyScopeClosedLoop.class); + if(ecompData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(ecompData.getName(), "name", PolicyScopeClosedLoop.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + policyScopeClosedLoopDao.Save(ecompData); + } + }else{ + policyScopeClosedLoopDao.update(ecompData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.policyScopeClosedLoopDao.getPolicyScopeClosedLoopData()); + } + JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ps_dictionary/remove_PSClosedLoop.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyScopeClosedLoop ecompData = (PolicyScopeClosedLoop)mapper.readValue(root.get("data").toString(), PolicyScopeClosedLoop.class); + policyScopeClosedLoopDao.delete(ecompData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.policyScopeClosedLoopDao.getPolicyScopeClosedLoopData()); + JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_PSServiceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPSServiceEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("psServiceDictionaryDatas", mapper.writeValueAsString(policyScopeServiceDao.getPolicyScopeServiceDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_PSServiceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPSServiceEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("psServiceDictionaryDatas", mapper.writeValueAsString(policyScopeServiceDao.getPolicyScopeServiceData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ps_dictionary/save_psService.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyScopeService ecompData = (PolicyScopeService)mapper.readValue(root.get("psServiceDictionaryData").toString(), PolicyScopeService.class); + if(ecompData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(ecompData.getName(), "name", PolicyScopeService.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + policyScopeServiceDao.Save(ecompData); + } + }else{ + policyScopeServiceDao.update(ecompData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.policyScopeServiceDao.getPolicyScopeServiceData()); + } + JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ps_dictionary/remove_PSService.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyScopeService ecompData = (PolicyScopeService)mapper.readValue(root.get("data").toString(), PolicyScopeService.class); + policyScopeServiceDao.delete(ecompData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.policyScopeServiceDao.getPolicyScopeServiceData()); + JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_PSTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPSTypeEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("psTypeDictionaryDatas", mapper.writeValueAsString(policyScopeTypeDao.getPolicyScopeTypeDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_PSTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPSTypeEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("psTypeDictionaryDatas", mapper.writeValueAsString(policyScopeTypeDao.getPolicyScopeTypeData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ps_dictionary/save_psType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyScopeType ecompData = (PolicyScopeType)mapper.readValue(root.get("psTypeDictionaryData").toString(), PolicyScopeType.class); + if(ecompData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(ecompData.getName(), "name", PolicyScopeType.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + policyScopeTypeDao.Save(ecompData); + } + }else{ + policyScopeTypeDao.update(ecompData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.policyScopeTypeDao.getPolicyScopeTypeData()); + } + JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ps_dictionary/remove_PSType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyScopeType ecompData = (PolicyScopeType)mapper.readValue(root.get("data").toString(), PolicyScopeType.class); + policyScopeTypeDao.delete(ecompData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.policyScopeTypeDao.getPolicyScopeTypeData()); + JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_PSResourceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPSResourceEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("psResourceDictionaryDatas", mapper.writeValueAsString(PolicyScopeResourceDao.getPolicyScopeResourceDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_PSResourceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPSResourceEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("psResourceDictionaryDatas", mapper.writeValueAsString(PolicyScopeResourceDao.getPolicyScopeResourceData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ps_dictionary/save_psResource.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyScopeResource ecompData = (PolicyScopeResource)mapper.readValue(root.get("psResourceDictionaryData").toString(), PolicyScopeResource.class); + if(ecompData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(ecompData.getName(), "name", PolicyScopeResource.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + PolicyScopeResourceDao.Save(ecompData); + } + }else{ + PolicyScopeResourceDao.update(ecompData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.PolicyScopeResourceDao.getPolicyScopeResourceData()); + } + JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ps_dictionary/remove_PSResource.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyScopeResource ecompData = (PolicyScopeResource)mapper.readValue(root.get("data").toString(), PolicyScopeResource.class); + PolicyScopeResourceDao.delete(ecompData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.PolicyScopeResourceDao.getPolicyScopeResourceData()); + JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } +} + + 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/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/SafePolicyController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/SafePolicyController.java new file mode 100644 index 000000000..5ee72f4f0 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/SafePolicyController.java @@ -0,0 +1,319 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.CategoryDao; +import org.openecomp.policy.rest.dao.RiskTypeDao; +import org.openecomp.policy.rest.dao.SafePolicyWarningDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.Category; +import org.openecomp.policy.rest.jpa.RiskType; +import org.openecomp.policy.rest.jpa.SafePolicyWarning; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +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 { + + private static final Log logger = LogFactory.getLog(SafePolicyController.class); + + @Autowired + SafePolicyWarningDao safePolicyWarningDao; + + @Autowired + RiskTypeDao riskTypeDao; + + @Autowired + UserInfoDao userInfoDao; + + @Autowired + CategoryDao categoryDao; + + + public Category getCategory() { + for (int i = 0; i < categoryDao.getCategoryListData().size(); i++) { + Category value = categoryDao.getCategoryListData().get(i); + if (value.getShortName().equals("resource")) { + return value; + } + } + return null; + } + + public UserInfo getUserInfo(String loginId) { + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + // EcompName Dictionary + @RequestMapping(value = { "/get_RiskTypeDataByName" }, method = { + org.springframework.web.bind.annotation.RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE) + public void getRiskTypeDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response) { + logger.info("get_RiskTypeDataByName is called"); + try { + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("riskTypeDictionaryDatas", mapper.writeValueAsString(riskTypeDao.getRiskTypeDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @RequestMapping(value = { "/get_RiskTypeData" }, method = { + org.springframework.web.bind.annotation.RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE) + public void getEcompNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response) { + logger.info("get_RiskTypeData is called"); + try { + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("riskTypeDictionaryDatas", mapper.writeValueAsString(riskTypeDao.getRiskName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } catch (Exception e) { + e.printStackTrace(); + logger.error("ERROR While callinge DAO: " + e.getMessage()); + } + } + + @RequestMapping(value = { "/sp_dictionary/save_riskType.htm" }, method = { + org.springframework.web.bind.annotation.RequestMethod.POST }) + public ModelAndView saveRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response) + throws Exception { + try { + boolean duplicateflag = false; + System.out.println("SafePolicyController: saveRiskTypeDictionary() is called"); + logger.debug("SafePolicyController: saveRiskTypeDictionary() is called"); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + RiskType riskTypeData = (RiskType) mapper.readValue(root.get("riskTypeDictionaryData").toString(), + RiskType.class); + String userId = root.get("loginId").textValue(); + System.out.println("the userId from the ecomp portal is: " + userId); + if (riskTypeData.getId() == 0) { + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(riskTypeData.getRiskName(), "name", RiskType.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + riskTypeData.setUserCreatedBy(getUserInfo(userId)); + riskTypeData.setUserModifiedBy(getUserInfo(userId)); + System.out.println( + "SafePolicyController: got the user info now about to call Save() method on riskTypedao"); + riskTypeDao.Save(riskTypeData); + } + } else { + riskTypeData.setUserModifiedBy(this.getUserInfo(userId)); + riskTypeDao.update(riskTypeData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.riskTypeDao.getRiskName()); + } + JSONObject j = new JSONObject("{riskTypeDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } catch (Exception e) { + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value = { "/sp_dictionary/remove_riskType.htm" }, method = { + org.springframework.web.bind.annotation.RequestMethod.POST }) + public ModelAndView removeEcompDictionary(HttpServletRequest request, HttpServletResponse response) + throws Exception { + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + RiskType ecompData = (RiskType) mapper.readValue(root.get("data").toString(), RiskType.class); + riskTypeDao.delete(ecompData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.riskTypeDao.getRiskName()); + JSONObject j = new JSONObject("{riskTypeDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } catch (Exception e) { + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value = { "/get_SafePolicyWarningDataByName" }, method = { + org.springframework.web.bind.annotation.RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE) + public void getSafePolicyWarningEntityDataByName(HttpServletRequest request, HttpServletResponse response) { + try { + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("safePolicyWarningDatas", + mapper.writeValueAsString(safePolicyWarningDao.getSafePolicyWarningDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @RequestMapping(value = { "/get_SafePolicyWarningData" }, method = { + org.springframework.web.bind.annotation.RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE) + public void getSafePolicyWarningeEntityData(HttpServletRequest request, HttpServletResponse response) { + try { + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("safePolicyWarningDatas", + mapper.writeValueAsString(safePolicyWarningDao.getSafePolicyWarningData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @RequestMapping(value = { "/sp_dictionary/save_safePolicyWarning.htm" }, method = { + org.springframework.web.bind.annotation.RequestMethod.POST }) + public ModelAndView saveSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) + throws Exception { + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + SafePolicyWarning safePolicyWarning = (SafePolicyWarning) mapper + .readValue(root.get("safePolicyWarningData").toString(), SafePolicyWarning.class); + + if (safePolicyWarning.getId() == 0) { + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(safePolicyWarning.getName(), "name", SafePolicyWarning.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + safePolicyWarningDao.Save(safePolicyWarning); + } + } else { + safePolicyWarningDao.update(safePolicyWarning); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.safePolicyWarningDao.getSafePolicyWarningData()); + } + JSONObject j = new JSONObject("{safePolicyWarningDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } catch (Exception e) { + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value = { "/sp_dictionary/remove_SafePolicyWarning.htm" }, method = { + org.springframework.web.bind.annotation.RequestMethod.POST }) + public ModelAndView removeSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) + throws Exception { + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + SafePolicyWarning safePolicyWarningData = (SafePolicyWarning) mapper.readValue(root.get("data").toString(), + SafePolicyWarning.class); + safePolicyWarningDao.delete(safePolicyWarningData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.safePolicyWarningDao.getSafePolicyWarningData()); + JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } catch (Exception e) { + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/package-info.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/package-info.java new file mode 100644 index 000000000..df0e40a56 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + * + */ +/** + * + */ +package org.openecomp.policy.pap.xacml.rest.controller; -- cgit 1.2.3-korg