From e0addf5b588a1244f9679becd90999dfcb4c3a94 Mon Sep 17 00:00:00 2001 From: "ITSERVICES\\rb7147" Date: Tue, 25 Apr 2017 11:46:00 -0400 Subject: Policy 1707 commit to LF Change-Id: Ibe6f01d92f9a434c040abb05d5386e89d675ae65 Signed-off-by: ITSERVICES\rb7147 --- .../ActionPolicyDictionaryController.java | 132 +- .../rest/controller/BRMSDictionaryController.java | 428 +++++- .../CheckDictionaryDuplicateEntries.java | 65 - .../controller/ClosedLoopDictionaryController.java | 1364 ++++++++++-------- .../DecisionPolicyDictionaryController.java | 133 +- .../DescriptiveDictionaryController.java | 136 +- .../rest/controller/DictionaryController.java | 268 ++-- .../controller/DictionaryImportController.java | 882 ++++++------ .../controller/EnforcerDictionaryController.java | 28 +- .../controller/FirewallDictionaryController.java | 1450 +++++++++++++++----- .../MicroServiceDictionaryController.java | 852 ++++++++---- .../PolicyScopeDictionaryController.java | 606 +++++--- .../rest/controller/PushPolicyController.java | 253 ++++ .../rest/controller/SafePolicyController.java | 274 ++-- .../pap/xacml/rest/controller/package-info.java | 7 +- 15 files changed, 4584 insertions(+), 2294 deletions(-) delete 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/PushPolicyController.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 index fa00fc1cc..1f9250383 100644 --- 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 @@ -31,9 +31,10 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.json.JSONObject; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; 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.dao.CommonClassDao; import org.openecomp.policy.rest.jpa.ActionPolicyDict; import org.openecomp.policy.rest.jpa.UserInfo; import org.springframework.beans.factory.annotation.Autowired; @@ -49,29 +50,34 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Controller public class ActionPolicyDictionaryController { - @Autowired - ActionPolicyDictDao actionPolicyDictDao; + private static final Logger LOGGER = FlexLogger.getLogger(ActionPolicyDictionaryController.class); + + private static CommonClassDao commonClassDao; @Autowired - UserInfoDao userInfoDao; + public ActionPolicyDictionaryController(CommonClassDao commonClassDao){ + ActionPolicyDictionaryController.commonClassDao = commonClassDao; + } + public ActionPolicyDictionaryController(){} + public UserInfo getUserInfo(String loginId){ - UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", 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())); + model.put("actionPolicyDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ActionPolicyDict.class, "attributeName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(e.getMessage()); } } @@ -80,26 +86,61 @@ public class ActionPolicyDictionaryController { try{ Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); - model.put("actionPolicyDictionaryDatas", mapper.writeValueAsString(actionPolicyDictDao.getActionDictData())); + model.put("actionPolicyDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ActionPolicyDict.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(e.getMessage()); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - - @RequestMapping(value={"/action_dictionary/save_ActionDict.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/action_dictionary/save_ActionDict"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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(); + ActionPolicyDict actionPolicyDict = null; + ActionAdapter adapter = null; + String userId = null; + + if(fromAPI) { + actionPolicyDict = (ActionPolicyDict)mapper.readValue(root.get("dictionaryFields").toString(), ActionPolicyDict.class); + adapter = (ActionAdapter)mapper.readValue(root.get("dictionaryFields").toString(), ActionAdapter.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(actionPolicyDict.getAttributeName(), "attributeName", ActionPolicyDict.class); + int id = 0; + ActionPolicyDict data = (ActionPolicyDict) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + actionPolicyDict.setId(1); + } else { + actionPolicyDict.setId(id); + } + actionPolicyDict.setUserCreatedBy(this.getUserInfo(userId)); + } + } else { + actionPolicyDict = (ActionPolicyDict)mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionPolicyDict.class); + adapter = mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionAdapter.class); + userId = root.get("userid").textValue(); + } String header = ""; int counter = 0; if(adapter.getHeaders().size() > 0){ @@ -118,37 +159,54 @@ public class ActionPolicyDictionaryController { } actionPolicyDict.setHeader(header); if(actionPolicyDict.getId() == 0){ - CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); - List duplicateData = entry.CheckDuplicateEntry(actionPolicyDict.getAttributeName(), "attributeName", ActionPolicyDict.class); + List duplicateData = commonClassDao.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); + commonClassDao.save(actionPolicyDict); } }else{ - actionPolicyDict.setUserModifiedBy(this.getUserInfo(userId)); - actionPolicyDictDao.update(actionPolicyDict); + if(!isFakeUpdate) { + actionPolicyDict.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.update(actionPolicyDict); + } } - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); - PrintWriter out = response.getWriter(); - String responseString = ""; - if(duplicateflag){ + String responseString = null; + if(duplicateflag) { responseString = "Duplicate"; - }else{ - responseString = mapper.writeValueAsString(this.actionPolicyDictDao.getActionDictData()); - } - JSONObject j = new JSONObject("{actionPolicyDictionaryDatas: " + responseString + "}"); + } else { + responseString = mapper.writeValueAsString(commonClassDao.getData(ActionPolicyDict.class)); + } - out.write(j.toString()); + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate) { + responseString = "Exists"; + } else { + responseString = "Success"; + } + } - return null; + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{actionPolicyDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } } catch (Exception e){ + LOGGER.error(e.getMessage()); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -157,28 +215,28 @@ public class ActionPolicyDictionaryController { return null; } - @RequestMapping(value={"/action_dictionary/remove_actionPolicyDict.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/action_dictionary/remove_actionPolicyDict"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(ActionPolicyDictionaryController.commonClassDao.getData(ActionPolicyDict.class)); JSONObject j = new JSONObject("{actionPolicyDictionaryDatas: " + responseString + "}"); out.write(j.toString()); return null; } catch (Exception e){ - System.out.println(e); + LOGGER.error(e.getMessage()); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); 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 index bdf4d2c01..09c995dbe 100644 --- 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 @@ -32,11 +32,17 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; import org.json.JSONObject; +import org.openecomp.policy.api.PEDependency; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; 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.dao.CommonClassDao; +import org.openecomp.policy.rest.jpa.BRMSController; +import org.openecomp.policy.rest.jpa.BRMSDependency; import org.openecomp.policy.rest.jpa.BRMSParamTemplate; import org.openecomp.policy.rest.jpa.UserInfo; +import org.openecomp.policy.utils.PolicyUtils; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -50,17 +56,23 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Controller public class BRMSDictionaryController{ + + private static final Logger LOGGER = FlexLogger.getLogger(BRMSDictionaryController.class); - @Autowired - BRMSParamTemplateDao brmsParamTemplateDao; + + private static CommonClassDao commonClassDao; @Autowired - UserInfoDao userInfoDao; + public BRMSDictionaryController(CommonClassDao commonClassDao){ + BRMSDictionaryController.commonClassDao = commonClassDao; + } + public BRMSDictionaryController() {} + private String rule; public UserInfo getUserInfo(String loginId){ - UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); return name; } @@ -69,13 +81,13 @@ public class BRMSDictionaryController{ try{ Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); - model.put("brmsParamDictionaryDatas", mapper.writeValueAsString(brmsParamTemplateDao.getBRMSParamDataByName())); + model.put("brmsParamDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(BRMSParamTemplate.class, "ruleName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } @@ -84,17 +96,21 @@ public class BRMSDictionaryController{ try{ Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); - model.put("brmsParamDictionaryDatas", mapper.writeValueAsString(brmsParamTemplateDao.getBRMSParamTemplateData())); + model.put("brmsParamDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(BRMSParamTemplate.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - @RequestMapping(value={"/brms_dictionary/set_BRMSParamData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/brms_dictionary/set_BRMSParamData"}, 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); @@ -102,46 +118,80 @@ public class BRMSDictionaryController{ rule = cleanStreamBoundary.substring(0, cleanStreamBoundary.lastIndexOf("end")+4); } - @RequestMapping(value={"/brms_dictionary/save_BRMSParam.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/brms_dictionary/save_BRMSParam"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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(); + + BRMSParamTemplate bRMSParamTemplateData; + String userId = null; + if(fromAPI) { + bRMSParamTemplateData = (BRMSParamTemplate)mapper.readValue(root.get("dictionaryFields").toString(), BRMSParamTemplate.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(bRMSParamTemplateData.getRuleName(), "ruleName", BRMSParamTemplate.class); + int id = 0; + BRMSParamTemplate data = (BRMSParamTemplate) duplicateData.get(0); + id = data.getId(); + bRMSParamTemplateData.setId(id); + bRMSParamTemplateData.setUserCreatedBy(this.getUserInfo(userId)); + } + } else { + bRMSParamTemplateData = (BRMSParamTemplate)mapper.readValue(root.get("brmsParamDictionaryData").toString(), BRMSParamTemplate.class); + userId = root.get("userid").textValue(); + } + bRMSParamTemplateData.setRule(rule); if(bRMSParamTemplateData.getId() == 0){ - CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); - List duplicateData = entry.CheckDuplicateEntry(bRMSParamTemplateData.getRuleName(), "ruleName", BRMSParamTemplate.class); + List duplicateData = commonClassDao.checkDuplicateEntry(bRMSParamTemplateData.getRuleName(), "ruleName", BRMSParamTemplate.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ bRMSParamTemplateData.setUserCreatedBy(this.getUserInfo(userId)); - brmsParamTemplateDao.Save(bRMSParamTemplateData); + commonClassDao.save(bRMSParamTemplateData); } }else{ - brmsParamTemplateDao.update(bRMSParamTemplateData); + commonClassDao.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()); + responseString = mapper.writeValueAsString(BRMSDictionaryController.commonClassDao.getData(BRMSParamTemplate.class)); + } + if(fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + responseString = "Success"; + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); - return null; + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{brmsParamDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } } catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -150,28 +200,28 @@ public class BRMSDictionaryController{ return null; } - @RequestMapping(value={"/brms_dictionary/remove_brmsParam.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/brms_dictionary/remove_brmsParam"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(BRMSDictionaryController.commonClassDao.getData(BRMSParamTemplate.class)); JSONObject j = new JSONObject("{brmsParamDictionaryDatas: " + responseString + "}"); out.write(j.toString()); return null; } catch (Exception e){ - System.out.println(e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -180,4 +230,324 @@ public class BRMSDictionaryController{ return null; } + @RequestMapping(value={"/get_BRMSDependencyDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getBRMSDependencyDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("brmsDependencyDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(BRMSDependency.class, "dependencyName"))); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_BRMSDependencyData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getBRMSDependencyDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("brmsDependencyDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(BRMSDependency.class))); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); + e.printStackTrace(); + } + } + + @RequestMapping(value={"/brms_dictionary/save_BRMSDependencyData"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + LOGGER.debug("DictionaryController: saveBRMSDependencyDictionary() is called"); + + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } + + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + + BRMSDependency brmsDependency; + String userId = null; + if (fromAPI) { + brmsDependency = (BRMSDependency)mapper.readValue(root.get("dictionaryFields").toString(), BRMSDependency.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(brmsDependency.getDependencyName(), "dependencyName", BRMSDependency.class); + int id = 0; + BRMSDependency data = (BRMSDependency) duplicateData.get(0); + id = data.getId(); + brmsDependency.setId(id); + brmsDependency.setUserCreatedBy(this.getUserInfo(userId)); + } + } else { + brmsDependency = (BRMSDependency)mapper.readValue(root.get("brmsDependencyDictionaryData").toString(), BRMSDependency.class); + userId = root.get("userid").textValue(); + } + + LOGGER.audit("the userId from the ecomp portal is: " + userId); + String responseString = null; + + if(brmsDependency.getDependency()!=null && !brmsDependency.getDependency().trim().equals("")){ + PEDependency dependency = null; + try{ + dependency = PolicyUtils.jsonStringToObject(brmsDependency.getDependency(), PEDependency.class); + }catch(Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "wrong data given for BRMS PEDependency Dictionary : " + brmsDependency.getDependency()); + } + if(dependency==null){ + responseString = "Error"; + }else{ + if(brmsDependency.getId() == 0){ + List duplicateData = commonClassDao.checkDuplicateEntry(brmsDependency.getDependencyName(), "dependencyName", BRMSDependency.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + brmsDependency.setUserCreatedBy(getUserInfo(userId)); + brmsDependency.setUserModifiedBy(getUserInfo(userId)); + LOGGER.audit("DictionaryController: got the user info now about to call Save() method on brmsDependencydao"); + commonClassDao.save(brmsDependency); + } + }else{ + brmsDependency.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.update(brmsDependency); + } + if(duplicateflag) { + responseString = "Duplicate"; + } else { + responseString = mapper.writeValueAsString(commonClassDao.getData(BRMSDependency.class)); + } + } + } + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate") && !responseString.equals("Error")) { + responseString = "Success"; + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{brmsDependencyDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + } catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/brms_dictionary/remove_brmsDependency"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeBRMSDependencyDictionary(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()); + BRMSDependency brmsDependency = (BRMSDependency)mapper.readValue(root.get("data").toString(), BRMSDependency.class); + commonClassDao.delete(brmsDependency); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(commonClassDao.getData(BRMSDependency.class)); + JSONObject j = new JSONObject("{brmsDependencyDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + + @RequestMapping(value={"/get_BRMSControllerDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getBRMSControllerDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("brmsControllerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(BRMSController.class, "controllerName"))); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_BRMSControllerData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getBRMSControllerDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("brmsControllerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(BRMSController.class))); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); + e.printStackTrace(); + } + } + + @RequestMapping(value={"/brms_dictionary/save_BRMSControllerData"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveBRMSControllerDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + LOGGER.debug("DictionaryController: saveBRMSControllerDictionary() is called"); + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + BRMSController brmsController; + String userId = null; + if (fromAPI) { + brmsController = (BRMSController)mapper.readValue(root.get("dictionaryFields").toString(), BRMSController.class); + userId = "API"; + //check if update operation or create, get id for data to be updated + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(brmsController.getControllerName(), "controllerName", BRMSController.class); + int id = 0; + BRMSController data = (BRMSController) duplicateData.get(0); + id = data.getId(); + brmsController.setId(id); + brmsController.setUserCreatedBy(this.getUserInfo(userId)); + } + } else { + brmsController = (BRMSController)mapper.readValue(root.get("brmsControllerDictionaryData").toString(), BRMSController.class); + userId = root.get("userid").textValue(); + } + LOGGER.audit("the userId from the ecomp portal is: " + userId); + String responseString = null; + if(brmsController.getController()!=null && !brmsController.getController().trim().equals("")){ + PEDependency dependency = null; + try{ + dependency = PolicyUtils.jsonStringToObject(brmsController.getController(), PEDependency.class); + }catch(Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "wrong data given for BRMS Controller Dictionary : " + brmsController.getController()); + } + if(dependency==null){ + responseString = "Error"; + }else{ + if(brmsController.getId() == 0){ + List duplicateData = commonClassDao.checkDuplicateEntry(brmsController.getControllerName(), "controllerName", BRMSController.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + brmsController.setUserCreatedBy(getUserInfo(userId)); + brmsController.setUserModifiedBy(getUserInfo(userId)); + LOGGER.audit("DictionaryController: got the user info now about to call Save() method on brmsControllerdao"); + commonClassDao.save(brmsController); + } + }else{ + brmsController.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.update(brmsController); + } + if(duplicateflag) { + responseString = "Duplicate"; + } else { + responseString = mapper.writeValueAsString(commonClassDao.getData(BRMSController.class)); + } + } + } + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate") && !responseString.equals("Error")) { + responseString = "Success"; + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{brmsControllerDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + } catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/brms_dictionary/remove_brmsController"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeBRMSControllerDictionary(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()); + BRMSController brmsController = (BRMSController)mapper.readValue(root.get("data").toString(), BRMSController.class); + commonClassDao.delete(brmsController); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(commonClassDao.getData(BRMSController.class)); + JSONObject j = new JSONObject("{brmsControllerDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + public BRMSDependency getDependencyDataByID(String dependencyName){ + return (BRMSDependency) commonClassDao.getEntityItem(BRMSDependency.class, "dependencyName", dependencyName); + } + + public BRMSController getControllerDataByID(String controllerName){ + return (BRMSController) commonClassDao.getEntityItem(BRMSController.class, "controllerName", controllerName); + } + } 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 deleted file mode 100644 index e044340a9..000000000 --- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/CheckDictionaryDuplicateEntries.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============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 index d70661f88..26d9a6535 100644 --- 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 @@ -21,7 +21,6 @@ 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; @@ -31,15 +30,11 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.json.JSONObject; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; 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.dao.CommonClassDao; import org.openecomp.policy.rest.jpa.ClosedLoopD2Services; import org.openecomp.policy.rest.jpa.ClosedLoopSite; import org.openecomp.policy.rest.jpa.PEPOptions; @@ -47,6 +42,7 @@ 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.xacml.api.XACMLErrorConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -60,705 +56,969 @@ 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; + private static final Logger LOGGER = FlexLogger.getLogger(ClosedLoopDictionaryController.class); + + private static CommonClassDao commonClassDao; @Autowired - UserInfoDao userInfoDao; + public ClosedLoopDictionaryController(CommonClassDao commonClassDao){ + ClosedLoopDictionaryController.commonClassDao = commonClassDao; + } + public ClosedLoopDictionaryController(){} + public UserInfo getUserInfo(String loginId){ - UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); - return name; + UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", 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)); + model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VSCLAction.class, "vsclaction"))); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - - + + @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())); + model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - + @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())); + model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VNFType.class, "vnftype"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - + @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())); + model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VNFType.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - + @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())); + model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PEPOptions.class, "pepName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - + @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())); + model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - + @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())); + model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VarbindDictionary.class, "varbindName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - + @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())); + model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - + @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())); + model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopD2Services.class, "serviceName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - + @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())); + model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - + @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())); + model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopSite.class, "siteName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - + @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())); + model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - - @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){ + + @RequestMapping(value={"/cl_dictionary/save_vsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + VSCLAction vSCLAction; + String userId = null; + if (fromAPI) { + vSCLAction = (VSCLAction)mapper.readValue(root.get("dictionaryFields").toString(), VSCLAction.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), "vsclaction", VSCLAction.class); + int id = 0; + VSCLAction data = (VSCLAction) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + vSCLAction.setId(1); + } else { + vSCLAction.setId(id); + } + + vSCLAction.setUserCreatedBy(this.getUserInfo(userId)); + } + + } else { + vSCLAction = (VSCLAction)mapper.readValue(root.get("vsclActionDictionaryData").toString(), VSCLAction.class); + userId = root.get("userid").textValue(); + } + if(vSCLAction.getId() == 0){ + List duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), "vsclaction", VSCLAction.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + vSCLAction.setUserCreatedBy(this.getUserInfo(userId)); + vSCLAction.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.save(vSCLAction); + } + }else{ + if(!isFakeUpdate) { + vSCLAction.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.update(vSCLAction); + } + } + + 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 = ""; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class)); + } + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate) { + responseString = "Exists"; + } else { + responseString = "Success"; + } + + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + 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"}, 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); + commonClassDao.delete(vSCLAction); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class)); + JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + 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"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + VNFType vNFType; + String userId = null; + + if (fromAPI) { + vNFType = (VNFType)mapper.readValue(root.get("dictionaryFields").toString(), VNFType.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), "vnftype", VNFType.class); + int id = 0; + VNFType data = (VNFType) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + vNFType.setId(1); + } else { + vNFType.setId(id); + } + vNFType.setUserCreatedBy(this.getUserInfo(userId)); + } + } else { + vNFType = (VNFType)mapper.readValue(root.get("vnfTypeDictionaryData").toString(), VNFType.class); + userId = root.get("userid").textValue(); + } + if(vNFType.getId() == 0){ + List duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), "vnftype", VNFType.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + vNFType.setUserCreatedBy(this.getUserInfo(userId)); + vNFType.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.save(vNFType); + } + }else{ + if(!isFakeUpdate) { + vNFType.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.update(vNFType); + } + } + String responseString = ""; if(duplicateflag){ responseString = "Duplicate"; }else{ - responseString = mapper.writeValueAsString(this.vnfTypeDao.getVNFTypeData()); + responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class)); } - 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 ++; + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate) { + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + 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"}, 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); + commonClassDao.delete(vNFType); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class)); + JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + 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"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PEPOptions pEPOptions; + GridData gridData; + String userId = null; + if (fromAPI) { + pEPOptions = (PEPOptions)mapper.readValue(root.get("dictionaryFields").toString(), PEPOptions.class); + gridData = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), "pepName", PEPOptions.class); + int id = 0; + PEPOptions data = (PEPOptions) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + pEPOptions.setId(1); + } else { + pEPOptions.setId(id); + } + pEPOptions.setUserCreatedBy(this.getUserInfo(userId)); + } + } else { + pEPOptions = (PEPOptions)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class); + gridData = (GridData)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class); + userId = root.get("userid").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; - } - + } + pEPOptions.setActions(actions); + if(pEPOptions.getId() == 0){ + List duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), "pepName", PEPOptions.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + pEPOptions.setUserCreatedBy(this.getUserInfo(userId)); + pEPOptions.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.save(pEPOptions); + } + }else{ + if(!isFakeUpdate){ + pEPOptions.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.update(pEPOptions); + } + } + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class)); + } + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + 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"}, 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); + commonClassDao.delete(pEPOptions); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class)); + JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + 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"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ClosedLoopD2Services serviceData; + String userId = null; + if (fromAPI) { + serviceData = (ClosedLoopD2Services)mapper.readValue(root.get("dictionaryFields").toString(), ClosedLoopD2Services.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), "serviceName", ClosedLoopD2Services.class); + int id = 0; + ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + serviceData.setId(1); + } else { + serviceData.setId(id); + } + serviceData.setUserCreatedBy(this.getUserInfo(userId)); + } + } else { + serviceData = (ClosedLoopD2Services)mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class); + userId = root.get("userid").textValue(); + } + if(serviceData.getId() == 0){ + List duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), "serviceName", ClosedLoopD2Services.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + serviceData.setUserCreatedBy(this.getUserInfo(userId)); + serviceData.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.save(serviceData); + } + }else{ + if(!isFakeUpdate){ + serviceData.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.update(serviceData); + } + } + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)); + } + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + 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"}, 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); + commonClassDao.delete(closedLoopD2Services); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)); + JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + 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"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ClosedLoopSite siteData; + String userId = null; + if (fromAPI) { + siteData = (ClosedLoopSite)mapper.readValue(root.get("dictionaryFields").toString(), ClosedLoopSite.class); + userId = "API"; + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), "siteName", ClosedLoopSite.class); + int id = 0; + ClosedLoopSite data = (ClosedLoopSite) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + siteData.setId(1); + } else { + siteData.setId(id); + } + siteData.setUserCreatedBy(this.getUserInfo(userId)); + } + } else { + siteData = (ClosedLoopSite)mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), ClosedLoopSite.class); + userId = root.get("userid").textValue(); + } + if(siteData.getId() == 0){ + List duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), "siteName", ClosedLoopSite.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + siteData.setUserCreatedBy(this.getUserInfo(userId)); + siteData.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.save(siteData); + } + }else{ + if(!isFakeUpdate) { + siteData.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.update(siteData); + } + } + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class)); + } + + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + 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"}, 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); + commonClassDao.delete(closedLoopSite); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class)); + JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + 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"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + VarbindDictionary varbindDictionary; + String userId = null; + if (fromAPI) { + varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("dictionaryFields").toString(), VarbindDictionary.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), "varbindName", VarbindDictionary.class); + int id = 0; + VarbindDictionary data = (VarbindDictionary) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + varbindDictionary.setId(1); + } else { + varbindDictionary.setId(id); + } + varbindDictionary.setUserCreatedBy(this.getUserInfo(userId)); + } + } else { + varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class); + userId = root.get("userid").textValue(); + } + if(varbindDictionary.getId() == 0){ + List duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), "varbindName", VarbindDictionary.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + varbindDictionary.setUserCreatedBy(this.getUserInfo(userId)); + varbindDictionary.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.save(varbindDictionary); + } + }else{ + if(!isFakeUpdate){ + varbindDictionary.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.update(varbindDictionary); + } + } + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class)); + } + + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + 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"}, 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); + commonClassDao.delete(varbindDictionary); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class)); + JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + 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 index 3308a990f..60ed95a07 100644 --- 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 @@ -29,12 +29,14 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.json.JSONObject; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; 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.dao.CommonClassDao; import org.openecomp.policy.rest.jpa.Datatype; import org.openecomp.policy.rest.jpa.DecisionSettings; import org.openecomp.policy.rest.jpa.UserInfo; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -48,14 +50,19 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Controller public class DecisionPolicyDictionaryController { - @Autowired - DecisionPolicyDao decisionPolicyDao; + private static final Logger LOGGER = FlexLogger.getLogger(DecisionPolicyDictionaryController.class); + + private static CommonClassDao commonClassDao; @Autowired - UserInfoDao userInfoDao; + public DecisionPolicyDictionaryController(CommonClassDao commonClassDao){ + DecisionPolicyDictionaryController.commonClassDao = commonClassDao; + } + + public DecisionPolicyDictionaryController(){} public UserInfo getUserInfo(String loginId){ - UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); return name; } @@ -64,13 +71,13 @@ public class DecisionPolicyDictionaryController { try{ Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); - model.put("settingsDictionaryDatas", mapper.writeValueAsString(decisionPolicyDao.getDecisionDataByName())); + model.put("settingsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(DecisionSettings.class, "xacmlId"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } @@ -80,25 +87,57 @@ public class DecisionPolicyDictionaryController { try{ Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); - model.put("settingsDictionaryDatas", mapper.writeValueAsString(decisionPolicyDao.getDecisionSettingsData())); + model.put("settingsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(DecisionSettings.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - @RequestMapping(value={"/decision_dictionary/save_Settings.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/decision_dictionary/save_Settings"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveSettingsDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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(); + DecisionSettings decisionSettings; + String userId = null; + + if (fromAPI) { + decisionSettings = (DecisionSettings)mapper.readValue(root.get("dictionaryFields").toString(), DecisionSettings.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(decisionSettings.getXacmlId(), "xacmlId", DecisionSettings.class); + int id = 0; + DecisionSettings data = (DecisionSettings) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + decisionSettings.setId(1); + } else { + decisionSettings.setId(id); + } + decisionSettings.setUserCreatedBy(this.getUserInfo(userId)); + } + } else { + decisionSettings = (DecisionSettings)mapper.readValue(root.get("settingsDictionaryData").toString(), DecisionSettings.class); + userId = root.get("userid").textValue(); + } if(decisionSettings.getDatatypeBean().getShortName() != null){ String datatype = decisionSettings.getDatatypeBean().getShortName(); Datatype a = new Datatype(); @@ -116,37 +155,51 @@ public class DecisionPolicyDictionaryController { decisionSettings.setDatatypeBean(a); } if(decisionSettings.getId() == 0){ - CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); - List duplicateData = entry.CheckDuplicateEntry(decisionSettings.getXacmlId(), "xacmlId", DecisionSettings.class); + List duplicateData = commonClassDao.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); + commonClassDao.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()); + if(!isFakeUpdate) { + decisionSettings.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.update(decisionSettings); + } } - JSONObject j = new JSONObject("{settingsDictionaryDatas: " + responseString + "}"); - - out.write(j.toString()); - - return null; - } - catch (Exception e){ + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(DecisionSettings.class)); + } + + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{settingsDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -155,28 +208,28 @@ public class DecisionPolicyDictionaryController { return null; } - @RequestMapping(value={"/settings_dictionary/remove_settings.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/settings_dictionary/remove_settings"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(DecisionSettings.class)); JSONObject j = new JSONObject("{settingsDictionaryDatas: " + responseString + "}"); out.write(j.toString()); return null; } catch (Exception e){ - System.out.println(e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); 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 index c184464fb..aa05f5209 100644 --- 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 @@ -30,12 +30,14 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.json.JSONObject; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; 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.dao.CommonClassDao; import org.openecomp.policy.rest.jpa.DescriptiveScope; import org.openecomp.policy.rest.jpa.UserInfo; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -49,14 +51,19 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Controller public class DescriptiveDictionaryController { - @Autowired - DescriptiveScopeDao descriptiveScopeDao; + private static final Logger LOGGER = FlexLogger.getLogger(DescriptiveDictionaryController.class); + + private static CommonClassDao commonClassDao; @Autowired - UserInfoDao userInfoDao; + public DescriptiveDictionaryController(CommonClassDao commonClassDao){ + DescriptiveDictionaryController.commonClassDao = commonClassDao; + } + + public DescriptiveDictionaryController(){} public UserInfo getUserInfo(String loginId){ - UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); return name; } @@ -65,13 +72,13 @@ public class DescriptiveDictionaryController { try{ Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); - model.put("descriptiveScopeDictionaryDatas", mapper.writeValueAsString(descriptiveScopeDao.getDescriptiveScopeDataByName())); + model.put("descriptiveScopeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(DescriptiveScope.class, "descriptiveScopeName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } @@ -80,26 +87,59 @@ public class DescriptiveDictionaryController { try{ Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); - model.put("descriptiveScopeDictionaryDatas", mapper.writeValueAsString(descriptiveScopeDao.getDescriptiveScope())); + model.put("descriptiveScopeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(DescriptiveScope.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - @RequestMapping(value={"/descriptive_dictionary/save_descriptive.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/descriptive_dictionary/save_descriptive"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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(); + DescriptiveScope descriptiveScope; + GridData data; + String userId = null; + if (fromAPI) { + descriptiveScope = (DescriptiveScope)mapper.readValue(root.get("dictionaryFields").toString(), DescriptiveScope.class); + data = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(descriptiveScope.getScopeName(), "descriptiveScopeName", DescriptiveScope.class); + int id = 0; + DescriptiveScope dbdata = (DescriptiveScope) duplicateData.get(0); + id = dbdata.getId(); + if(id==0){ + isFakeUpdate=true; + descriptiveScope.setId(1); + } else { + descriptiveScope.setId(id); + } + descriptiveScope.setUserCreatedBy(this.getUserInfo(userId)); + } + } else { + descriptiveScope = (DescriptiveScope)mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), DescriptiveScope.class); + data = (GridData)mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), GridData.class); + userId = root.get("userid").textValue(); + } String header = ""; int counter = 0; if(data.getAttributes().size() > 0){ @@ -118,37 +158,51 @@ public class DescriptiveDictionaryController { } descriptiveScope.setSearch(header); if(descriptiveScope.getId() == 0){ - CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); - List duplicateData = entry.CheckDuplicateEntry(descriptiveScope.getScopeName(), "descriptiveScopeName", DescriptiveScope.class); + List duplicateData = commonClassDao.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); + commonClassDao.save(descriptiveScope); } }else{ - descriptiveScope.setUserModifiedBy(this.getUserInfo(userId)); - descriptiveScopeDao.update(descriptiveScope); + if(!isFakeUpdate){ + descriptiveScope.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.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){ + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(DescriptiveScope.class)); + } + + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{descriptiveScopeDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -157,28 +211,28 @@ public class DescriptiveDictionaryController { return null; } - @RequestMapping(value={"/descriptive_dictionary/remove_descriptiveScope.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/descriptive_dictionary/remove_descriptiveScope"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(DescriptiveScope.class)); JSONObject j = new JSONObject("{descriptiveScopeDictionaryDatas: " + responseString + "}"); out.write(j.toString()); return null; } catch (Exception e){ - System.out.println(e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); 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 index aa2fb4acd..c08bba6ca 100644 --- 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 @@ -34,15 +34,13 @@ 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.dao.CommonClassDao; 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.openecomp.policy.xacml.api.XACMLErrorConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -57,36 +55,33 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Controller public class DictionaryController { - private static final Log logger = LogFactory.getLog(DictionaryController.class); + private static final Log LOGGER = LogFactory.getLog(DictionaryController.class); - @Autowired - AttributeDao attributeDao; - - @Autowired - EcompNameDao ecompNameDao; + private static CommonClassDao commonClassDao; @Autowired - UserInfoDao userInfoDao; + public DictionaryController(CommonClassDao commonClassDao){ + DictionaryController.commonClassDao = commonClassDao; + } - @Autowired - CategoryDao categoryDao; + public DictionaryController(){} + + public UserInfo getUserInfo(String loginId){ + UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); + return name; + } public Category getCategory(){ - for (int i = 0; i < categoryDao.getCategoryListData().size() ; i++) { - Category value = categoryDao.getCategoryListData().get(i); + List list = commonClassDao.getData(Category.class); + for (int i = 0; i < list.size() ; i++) { + Category value = (Category) list.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){ @@ -94,13 +89,13 @@ public class DictionaryController { System.out.println(); Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); - model.put("attributeDictionaryDatas", mapper.writeValueAsString(attributeDao.getAttributeData())); + model.put("attributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(Attribute.class, "xacmlId"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } @@ -111,26 +106,60 @@ public class DictionaryController { System.out.println(); Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); - model.put("attributeDictionaryDatas", mapper.writeValueAsString(attributeDao.getData())); + model.put("attributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(Attribute.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - @RequestMapping(value={"/attribute_dictionary/save_attribute.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/attribute_dictionary/save_attribute"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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(); + Attribute attributeData = null; + AttributeValues attributeValueData = null; + String userId = null; + if (fromAPI) { + //JsonNode json = root.get("dictionaryFields"); + attributeData = (Attribute)mapper.readValue(root.get("dictionaryFields").toString(), Attribute.class); + attributeValueData = (AttributeValues)mapper.readValue(root.get("dictionaryFields").toString(), AttributeValues.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(attributeData.getXacmlId(), "xacmlId", Attribute.class); + int id = 0; + Attribute data = (Attribute) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + attributeData.setId(1); + } else { + attributeData.setId(id); + } + attributeData.setUserCreatedBy(this.getUserInfo(userId)); + } + } else { + attributeData = (Attribute)mapper.readValue(root.get("attributeDictionaryData").toString(), Attribute.class); + attributeValueData = (AttributeValues)mapper.readValue(root.get("attributeDictionaryData").toString(), AttributeValues.class); + userId = root.get("userid").textValue(); + } String userValue = ""; int counter = 0; if(attributeValueData.getUserDataTypeValues().size() > 0){ @@ -163,38 +192,51 @@ public class DictionaryController { attributeData.setDatatypeBean(a); } if(attributeData.getId() == 0){ - CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); - List duplicateData = entry.CheckDuplicateEntry(attributeData.getXacmlId(), "xacmlId", Attribute.class); + List duplicateData = commonClassDao.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); + commonClassDao.save(attributeData); } }else{ - attributeData.setUserModifiedBy(this.getUserInfo(userId)); - attributeDao.update(attributeData); + if(!isFakeUpdate) { + attributeData.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.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){ + String responseString = null; + if(duplicateflag) { + responseString = "Duplicate"; + } else { + responseString = mapper.writeValueAsString(commonClassDao.getData(Attribute.class)); + } + + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate) { + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{attributeDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -203,28 +245,26 @@ public class DictionaryController { return null; } - @RequestMapping(value={"/attribute_dictionary/remove_attribute.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/attribute_dictionary/remove_attribute"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(Attribute.class)); JSONObject j = new JSONObject("{attributeDictionaryDatas: " + responseString + "}"); out.write(j.toString()); - return null; } catch (Exception e){ - System.out.println(e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -236,82 +276,120 @@ public class DictionaryController { //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"); + LOGGER.info("get_EcompNameDataByName is called"); try{ Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); - model.put("ecompNameDictionaryDatas", mapper.writeValueAsString(ecompNameDao.getEcompNameDataByName())); + model.put("ecompNameDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(EcompName.class, "ecompName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } @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())); + model.put("ecompNameDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(EcompName.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); - logger.error("ERROR While callinge DAO: " + e.getMessage()); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - @RequestMapping(value={"/ecomp_dictionary/save_ecompName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/ecomp_dictionary/save_ecompName"}, 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"); + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + EcompName ecompData; + String userId = null; + if (fromAPI) { + ecompData = (EcompName)mapper.readValue(root.get("dictionaryFields").toString(), EcompName.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getEcompName(), "ecompName", EcompName.class); + int id = 0; + EcompName data = (EcompName) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + ecompData.setId(1); + } else { + ecompData.setId(id); + } + ecompData.setUserCreatedBy(this.getUserInfo(userId)); + } + } else { + ecompData = (EcompName)mapper.readValue(root.get("ecompNameDictionaryData").toString(), EcompName.class); + userId = root.get("userid").textValue(); + } if(ecompData.getId() == 0){ - CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); - List duplicateData = entry.CheckDuplicateEntry(ecompData.getEcompName(), "ecompName", EcompName.class); + List duplicateData = commonClassDao.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); + commonClassDao.save(ecompData); } }else{ - ecompData.setUserModifiedBy(this.getUserInfo(userId)); - ecompNameDao.update(ecompData); + if(!isFakeUpdate){ + ecompData.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.update(ecompData); + } } - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); - - PrintWriter out = response.getWriter(); - String responseString = ""; - if(duplicateflag){ + String responseString = null; + if(duplicateflag) { responseString = "Duplicate"; - }else{ - responseString = mapper.writeValueAsString(this.ecompNameDao.getEcompName()); + } else { + responseString = mapper.writeValueAsString(commonClassDao.getData(EcompName.class)); } - JSONObject j = new JSONObject("{ecompNameDictionaryDatas: " + responseString + "}"); + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } - out.write(j.toString()); + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); - return null; - } - catch (Exception e){ + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{ecompNameDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -320,28 +398,28 @@ public class DictionaryController { return null; } - @RequestMapping(value={"/ecomp_dictionary/remove_ecomp.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/ecomp_dictionary/remove_ecomp"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(EcompName.class)); JSONObject j = new JSONObject("{ecompNameDictionaryDatas: " + responseString + "}"); out.write(j.toString()); return null; } catch (Exception e){ - System.out.println(e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); 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 index 3ed8f5d1c..95172ac74 100644 --- 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 @@ -33,31 +33,7 @@ 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.dao.CommonClassDao; import org.openecomp.policy.rest.jpa.ActionList; import org.openecomp.policy.rest.jpa.ActionPolicyDict; import org.openecomp.policy.rest.jpa.AddressGroup; @@ -70,7 +46,7 @@ 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.PrefixList; import org.openecomp.policy.rest.jpa.ProtocolList; import org.openecomp.policy.rest.jpa.SecurityZone; import org.openecomp.policy.rest.jpa.ServiceList; @@ -94,524 +70,470 @@ import au.com.bytecode.opencsv.CSVReader; public class DictionaryImportController { private String newFile; + private static CommonClassDao commonClassDao; + @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; + public DictionaryImportController(CommonClassDao commonClassDao){ + DictionaryImportController.commonClassDao = commonClassDao; + } + + public DictionaryImportController(){} - @Autowired - BRMSParamTemplateDao brmsParamTemplateDao; - @RequestMapping(value={"/dictionary/import_dictionary.htm/*"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/dictionary/import_dictionary"}, 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 dictSheet = csvReader.readAll(); + if(dictionaryName.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())); + List list = commonClassDao.getData(EnforcingType.class); + List dictList = new ArrayList(); + for(int i = 0; i < list.size(); i++){ + EnforcingType dict = (EnforcingType) list.get(i); + dictList.add(dict.getEnforcingType()); + } + model.put("enforcerDictionaryDatas", mapper.writeValueAsString(dictList)); org.openecomp.policy.pap.xacml.rest.util.JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -62,7 +70,7 @@ public class EnforcerDictionaryController { } } - @RequestMapping(value={"/enforcer_dictionary/save_enforcerType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/enforcer_dictionary/save_enforcerType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveEnforcerDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { ObjectMapper mapper = new ObjectMapper(); @@ -70,16 +78,16 @@ public class EnforcerDictionaryController { JsonNode root = mapper.readTree(request.getReader()); EnforcingType enforcingType = (EnforcingType)mapper.readValue(root.get("enforcerDictionaryData").toString(), EnforcingType.class); if(enforcingType.getId() == 0){ - enforcerPolicyDao.Save(enforcingType); + commonClassDao.save(enforcingType); }else{ - enforcerPolicyDao.update(enforcingType); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(EnforcingType.class)); JSONObject j = new JSONObject("{enforcerDictionaryDatas: " + responseString + "}"); out.write(j.toString()); @@ -95,21 +103,21 @@ public class EnforcerDictionaryController { return null; } - @RequestMapping(value={"/enforcer_dictionary/remove_enforcer.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/enforcer_dictionary/remove_enforcer"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(EnforcingType.class)); JSONObject j = new JSONObject("{enforcerDictionaryDatas: " + responseString + "}"); out.write(j.toString()); 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 index d2c371509..2c0d3de7f 100644 --- 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 @@ -33,25 +33,18 @@ import javax.servlet.http.HttpServletResponse; import org.jboss.netty.handler.ipfilter.CIDR; import org.json.JSONObject; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; 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.dao.CommonClassDao; import org.openecomp.policy.rest.jpa.ActionList; import org.openecomp.policy.rest.jpa.AddressGroup; +import org.openecomp.policy.rest.jpa.FWTag; +import org.openecomp.policy.rest.jpa.FWTagPicker; 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.PrefixList; import org.openecomp.policy.rest.jpa.PortList; import org.openecomp.policy.rest.jpa.ProtocolList; import org.openecomp.policy.rest.jpa.SecurityZone; @@ -59,6 +52,7 @@ 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.openecomp.policy.xacml.api.XACMLErrorConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -73,116 +67,131 @@ 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; + private static final Logger LOGGER = FlexLogger.getLogger(FirewallDictionaryController.class); + + private static CommonClassDao commonClassDao; @Autowired - FirewallDictionaryListDao fwDictionaryListDao; + public FirewallDictionaryController(CommonClassDao commonClassDao){ + FirewallDictionaryController.commonClassDao = commonClassDao; + } + public FirewallDictionaryController(){} - public UserInfo getUserInfo(String loginId){ - UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); - return name; + UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", 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())); + model.put("prefixListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PrefixList.class, "prefixListName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - + @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())); + model.put("prefixListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PrefixList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - - @RequestMapping(value={"/fw_dictionary/save_prefixList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/fw_dictionary/save_prefixList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView savePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + PrefixList prefixList; + if (fromAPI) { + prefixList = (PrefixList)mapper.readValue(root.get("dictionaryFields").toString(), PrefixList.class); + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), "prefixListName", PrefixList.class); + int id = 0; + PrefixList data = (PrefixList) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + prefixList.setId(1); + } else { + prefixList.setId(id); + } + } + } else { + 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); + List duplicateData = commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), "prefixListName", PrefixList.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - prefixListDao.Save(prefixList); + commonClassDao.save(prefixList); } }else{ - prefixListDao.update(prefixList); + if(!isFakeUpdate) { + commonClassDao.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()); + responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class)); } - JSONObject j = new JSONObject("{prefixListDictionaryDatas: " + responseString + "}"); - - out.write(j.toString()); - return null; - } - catch (Exception e){ + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{prefixListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -191,28 +200,26 @@ public class FirewallDictionaryController { return null; } - @RequestMapping(value={"/fw_dictionary/remove_PrefixList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/fw_dictionary/remove_PrefixList"}, 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); + PrefixList prefixList = (PrefixList)mapper.readValue(root.get("data").toString(), PrefixList.class); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class)); JSONObject j = new JSONObject("{prefixListDictionaryDatas: " + responseString + "}"); out.write(j.toString()); - return null; } catch (Exception e){ - System.out.println(e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -220,21 +227,20 @@ public class FirewallDictionaryController { } return null; } - - @RequestMapping(value={"/fw_dictionary/validate_prefixList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/fw_dictionary/validate_prefixList"}, 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); + 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"); - } + try{ + CIDR.newCIDR(prefixList.getPrefixListValue()); + }catch(UnknownHostException e){ + responseValidation = "error"; + } response.setCharacterEncoding("UTF-8"); response.setContentType("application / json"); request.setCharacterEncoding("UTF-8"); @@ -242,10 +248,10 @@ public class FirewallDictionaryController { PrintWriter out = response.getWriter(); JSONObject j = new JSONObject("{result: " + responseValidation + "}"); out.write(j.toString()); - return null; } catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -253,23 +259,27 @@ public class FirewallDictionaryController { } 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())); + model.put("portListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PortList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - - @RequestMapping(value={"/fw_dictionary/save_portName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/fw_dictionary/save_portName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView savePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; @@ -278,15 +288,14 @@ public class FirewallDictionaryController { 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); + List duplicateData = commonClassDao.checkDuplicateEntry(portList.getPortName(), "portName", PortList.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - portListDao.Save(portList); + commonClassDao.save(portList); } }else{ - portListDao.update(portList); + commonClassDao.update(portList); } response.setCharacterEncoding("UTF-8"); response.setContentType("application / json"); @@ -297,7 +306,7 @@ public class FirewallDictionaryController { if(duplicateflag){ responseString = "Duplicate"; }else{ - responseString = mapper.writeValueAsString(this.portListDao.getPortListData()); + responseString = mapper.writeValueAsString(commonClassDao.getData(PortList.class)); } JSONObject j = new JSONObject("{portListDictionaryDatas: " + responseString + "}"); @@ -306,6 +315,7 @@ public class FirewallDictionaryController { return null; } catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -314,28 +324,26 @@ public class FirewallDictionaryController { return null; } - @RequestMapping(value={"/fw_dictionary/remove_PortList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/fw_dictionary/remove_PortList"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(PortList.class)); JSONObject j = new JSONObject("{portListDictionaryDatas: " + responseString + "}"); out.write(j.toString()); - return null; } catch (Exception e){ - System.out.println(e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -343,74 +351,115 @@ public class FirewallDictionaryController { } 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())); + model.put("protocolListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - + @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())); + model.put("protocolListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ProtocolList.class, "protocolName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - - @RequestMapping(value={"/fw_dictionary/save_protocolList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/fw_dictionary/save_protocolList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + ProtocolList protocolList; + if (fromAPI) { + protocolList = (ProtocolList)mapper.readValue(root.get("dictionaryFields").toString(), ProtocolList.class); + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), "protocolName", ProtocolList.class); + int id = 0; + ProtocolList data = (ProtocolList) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + protocolList.setId(1); + } else { + protocolList.setId(id); + } + } + } else { + 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); + List duplicateData = commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), "protocolName", ProtocolList.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - protocolListDao.Save(protocolList); + commonClassDao.save(protocolList); } }else{ - protocolListDao.update(protocolList); + if(!isFakeUpdate){ + commonClassDao.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()); + responseString = mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class)); } - JSONObject j = new JSONObject("{protocolListDictionaryDatas: " + responseString + "}"); - out.write(j.toString()); - - return null; - } - catch (Exception e){ + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{protocolListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -419,28 +468,27 @@ public class FirewallDictionaryController { return null; } - @RequestMapping(value={"/fw_dictionary/remove_protocol.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/fw_dictionary/remove_protocol"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class)); JSONObject j = new JSONObject("{protocolListDictionaryDatas: " + responseString + "}"); out.write(j.toString()); - return null; } catch (Exception e){ - System.out.println(e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -448,49 +496,84 @@ public class FirewallDictionaryController { } 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())); + model.put("addressGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(AddressGroup.class, "name"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - + @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())); + model.put("addressGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - - @RequestMapping(value={"/fw_dictionary/save_addressGroup.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/fw_dictionary/save_addressGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + AddressGroup addressGroup; + GridData gridData; + if (fromAPI) { + addressGroup = (AddressGroup)mapper.readValue(root.get("dictionaryFields").toString(), AddressGroup.class); + gridData = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class); + + if(!addressGroup.getGroupName().startsWith("Group_")){ + String groupName = "Group_"+addressGroup.getGroupName(); + addressGroup.setGroupName(groupName); + } + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class); + int id = 0; + AddressGroup data = (AddressGroup) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + addressGroup.setId(1); + } else { + addressGroup.setId(id); + } + } + } else { + addressGroup = (AddressGroup)mapper.readValue(root.get("addressGroupDictionaryData").toString(), AddressGroup.class); + 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; @@ -508,34 +591,46 @@ public class FirewallDictionaryController { } addressGroup.setServiceList(userValue); if(addressGroup.getId() == 0){ - CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); - List duplicateData = entry.CheckDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class); + List duplicateData = commonClassDao.checkDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - addressGroupDao.Save(addressGroup); + commonClassDao.save(addressGroup); } }else{ - addressGroupDao.update(addressGroup); + if (!isFakeUpdate) { + commonClassDao.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()); + responseString = mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class)); } - JSONObject j = new JSONObject("{addressGroupDictionaryDatas: " + responseString + "}"); - - out.write(j.toString()); - - return null; - } - catch (Exception e){ + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{addressGroupDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -544,28 +639,27 @@ public class FirewallDictionaryController { return null; } - @RequestMapping(value={"/fw_dictionary/remove_AddressGroup.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/fw_dictionary/remove_AddressGroup"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class)); JSONObject j = new JSONObject("{addressGroupDictionaryDatas: " + responseString + "}"); out.write(j.toString()); - return null; } catch (Exception e){ - System.out.println(e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -573,74 +667,121 @@ public class FirewallDictionaryController { } 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())); + List list = commonClassDao.getData(ActionList.class); + List dictList = new ArrayList(); + for(int i = 0; i < list.size(); i++){ + ActionList dict = (ActionList) list.get(i); + dictList.add(dict.getActionName()); + } + model.put("actionListDictionaryDatas", mapper.writeValueAsString(dictList)); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - + @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())); + model.put("actionListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ActionList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - - @RequestMapping(value={"/fw_dictionary/save_ActionList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/fw_dictionary/save_ActionList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + ActionList actionList; + if (fromAPI) { + actionList = (ActionList)mapper.readValue(root.get("dictionaryFields").toString(), ActionList.class); + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(actionList.getActionName(), "actionName", ActionList.class); + int id = 0; + ActionList data = (ActionList) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + actionList.setId(1); + } else { + actionList.setId(id); + } + } + } else { + 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); + List duplicateData = commonClassDao.checkDuplicateEntry(actionList.getActionName(), "actionName", ActionList.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - actionListDao.Save(actionList); + commonClassDao.save(actionList); } }else{ - actionListDao.update(actionList); + if(!isFakeUpdate) { + commonClassDao.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()); + responseString = mapper.writeValueAsString(commonClassDao.getData(ActionList.class)); } - JSONObject j = new JSONObject("{actionListDictionaryDatas: " + responseString + "}"); - - out.write(j.toString()); - return null; - } - catch (Exception e){ + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{actionListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -649,28 +790,26 @@ public class FirewallDictionaryController { return null; } - @RequestMapping(value={"/fw_dictionary/remove_ActionList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/fw_dictionary/remove_ActionList"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(ActionList.class)); JSONObject j = new JSONObject("{actionListDictionaryDatas: " + responseString + "}"); out.write(j.toString()); - return null; } catch (Exception e){ - System.out.println(e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -678,46 +817,81 @@ public class FirewallDictionaryController { } 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())); + model.put("serviceGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - + @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())); + model.put("serviceGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(GroupServiceList.class, "name"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - - @RequestMapping(value={"/fw_dictionary/save_serviceGroup.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/fw_dictionary/save_serviceGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + GroupServiceList groupServiceList; + GridData gridData; + if (fromAPI) { + groupServiceList = (GroupServiceList)mapper.readValue(root.get("dictionaryFields").toString(), GroupServiceList.class); + gridData = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class); + + if(!groupServiceList.getGroupName().startsWith("Group_")){ + String groupName = "Group_"+groupServiceList.getGroupName(); + groupServiceList.setGroupName(groupName); + } + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(groupServiceList.getGroupName(), "name", GroupServiceList.class); + int id = 0; + GroupServiceList data = (GroupServiceList) duplicateData.get(0); + id = data.getId(); + + if(id==0){ + isFakeUpdate=true; + groupServiceList.setId(1); + } else { + groupServiceList.setId(id); + } + } + } else { + groupServiceList = (GroupServiceList)mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GroupServiceList.class); + gridData = (GridData)mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GridData.class); + } if(!groupServiceList.getGroupName().startsWith("Group_")){ String groupName = "Group_"+groupServiceList.getGroupName(); groupServiceList.setGroupName(groupName); @@ -738,34 +912,47 @@ public class FirewallDictionaryController { } groupServiceList.setServiceList(userValue); if(groupServiceList.getId() == 0){ - CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); - List duplicateData = entry.CheckDuplicateEntry(groupServiceList.getGroupName(), "name", GroupServiceList.class); + List duplicateData = commonClassDao.checkDuplicateEntry(groupServiceList.getGroupName(), "name", GroupServiceList.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - serviceGroupDao.Save(groupServiceList); + commonClassDao.save(groupServiceList); } }else{ - serviceGroupDao.update(groupServiceList); + if(!isFakeUpdate) { + commonClassDao.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()); + responseString = mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class)); } - JSONObject j = new JSONObject("{serviceGroupDictionaryDatas: " + responseString + "}"); - out.write(j.toString()); - - return null; - } - catch (Exception e){ + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{serviceGroupDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -774,21 +961,21 @@ public class FirewallDictionaryController { return null; } - @RequestMapping(value={"/fw_dictionary/remove_serviceGroup.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/fw_dictionary/remove_serviceGroup"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class)); JSONObject j = new JSONObject("{serviceGroupDictionaryDatas: " + responseString + "}"); out.write(j.toString()); @@ -803,74 +990,116 @@ public class FirewallDictionaryController { } 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())); + model.put("securityZoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(SecurityZone.class, "zoneName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - + @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())); + model.put("securityZoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - - @RequestMapping(value={"/fw_dictionary/save_securityZone.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/fw_dictionary/save_securityZone"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + SecurityZone securityZone; + if (fromAPI) { + securityZone = (SecurityZone)mapper.readValue(root.get("dictionaryFields").toString(), SecurityZone.class); + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), "zoneName", SecurityZone.class); + int id = 0; + SecurityZone data = (SecurityZone) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + securityZone.setId(1); + } else { + securityZone.setId(id); + } + } + } else { + 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); + List duplicateData = commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), "zoneName", SecurityZone.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - securityZoneDao.Save(securityZone); + commonClassDao.save(securityZone); } }else{ - securityZoneDao.update(securityZone); + if(!isFakeUpdate) { + commonClassDao.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()); + responseString = mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class)); } - JSONObject j = new JSONObject("{securityZoneDictionaryDatas: " + responseString + "}"); - out.write(j.toString()); + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{securityZoneDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } - return null; - } - catch (Exception e){ + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -879,28 +1108,28 @@ public class FirewallDictionaryController { return null; } - @RequestMapping(value={"/fw_dictionary/remove_securityZone.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/fw_dictionary/remove_securityZone"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class)); JSONObject j = new JSONObject("{securityZoneDictionaryDatas: " + responseString + "}"); out.write(j.toString()); return null; } catch (Exception e){ - System.out.println(e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -908,47 +1137,77 @@ public class FirewallDictionaryController { } 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())); + model.put("serviceListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ServiceList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - + @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())); + model.put("serviceListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ServiceList.class, "serviceName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - - @RequestMapping(value={"/fw_dictionary/save_serviceList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/fw_dictionary/save_serviceList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + ServiceList serviceList; + GridData serviceListGridData; + if (fromAPI) { + serviceList = (ServiceList)mapper.readValue(root.get("dictionaryFields").toString(), ServiceList.class); + serviceListGridData = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class); + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), "serviceName", ServiceList.class); + int id = 0; + ServiceList data = (ServiceList) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + serviceList.setId(1); + } else { + serviceList.setId(id); + } + } + }else{ + serviceList = (ServiceList)mapper.readValue(root.get("serviceListDictionaryData").toString(), ServiceList.class); + serviceListGridData = (GridData)mapper.readValue(root.get("serviceListDictionaryData").toString(), GridData.class); + } String tcpValue = ""; int counter = 0; if(serviceListGridData.getTransportProtocols().size() > 0){ @@ -981,58 +1240,71 @@ public class FirewallDictionaryController { serviceList.setServiceAppProtocol(appValue); serviceList.setServiceType("SERVICE"); if(serviceList.getId() == 0){ - CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); - List duplicateData = entry.CheckDuplicateEntry(serviceList.getServiceName(), "serviceName", ServiceList.class); + List duplicateData = commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), "serviceName", ServiceList.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - serviceListDao.Save(serviceList); + commonClassDao.save(serviceList); } - }else{ - serviceListDao.update(serviceList); + if(!isFakeUpdate) { + commonClassDao.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()); + responseString = mapper.writeValueAsString(commonClassDao.getData(ServiceList.class)); } - JSONObject j = new JSONObject("{serviceListDictionaryDatas: " + responseString + "}"); - - out.write(j.toString()); - - return null; - } - catch (Exception e){ + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{serviceListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + 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}) + @RequestMapping(value={"/fw_dictionary/remove_serviceList"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(ServiceList.class)); JSONObject j = new JSONObject("{serviceListDictionaryDatas: " + responseString + "}"); out.write(j.toString()); @@ -1047,74 +1319,113 @@ public class FirewallDictionaryController { } 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())); + model.put("zoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(Zone.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); 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())); + model.put("zoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(Zone.class, "zoneName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - - @RequestMapping(value={"/fw_dictionary/save_zoneName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/fw_dictionary/save_zoneName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + Zone zone; + if (fromAPI) { + zone = (Zone)mapper.readValue(root.get("dictionaryFields").toString(), Zone.class); + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(zone.getZoneName(), "zoneName", Zone.class); + int id = 0; + Zone data = (Zone) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + zone.setId(1); + } else { + zone.setId(id); + } + } + } else { + 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); + List duplicateData = commonClassDao.checkDuplicateEntry(zone.getZoneName(), "zoneName", Zone.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - zoneDao.Save(zone); + commonClassDao.save(zone); } }else{ - zoneDao.update(zone); + if(!isFakeUpdate) { + commonClassDao.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()); + responseString = mapper.writeValueAsString(commonClassDao.getData(Zone.class)); } - JSONObject j = new JSONObject("{zoneDictionaryDatas: " + responseString + "}"); - out.write(j.toString()); - - return null; - } - catch (Exception e){ + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{zoneDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -1123,28 +1434,28 @@ public class FirewallDictionaryController { return null; } - @RequestMapping(value={"/fw_dictionary/remove_zone.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/fw_dictionary/remove_zone"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(Zone.class)); JSONObject j = new JSONObject("{zoneDictionaryDatas: " + responseString + "}"); out.write(j.toString()); return null; } catch (Exception e){ - System.out.println(e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -1152,47 +1463,80 @@ public class FirewallDictionaryController { } 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())); + model.put("termListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(TermList.class, "termName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - + @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())); + model.put("termListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(TermList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - - @RequestMapping(value={"/fw_dictionary/save_termList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/fw_dictionary/save_termList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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(); + TermList termList; + TermListData termListDatas; + String userId = null; + if (fromAPI) { + termList = (TermList)mapper.readValue(root.get("dictionaryFields").toString(), TermList.class); + termListDatas = (TermListData)mapper.readValue(root.get("dictionaryFields").toString(), TermListData.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(termList.getTermName(), "termName", TermList.class); + int id = 0; + TermList data = (TermList) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + termList.setId(1); + } else { + termList.setId(id); + } + termList.setUserCreatedBy(this.getUserInfo(userId)); + } + } else { + termList = (TermList)mapper.readValue(root.get("termListDictionaryData").toString(), TermList.class); + termListDatas = (TermListData)mapper.readValue(root.get("termListDictionaryData").toString(), TermListData.class); + userId = root.get("userid").textValue(); + } String fromZoneValue = ""; int counter = 0; if(termListDatas.getFromZoneDatas().size() > 0){ @@ -1208,7 +1552,7 @@ public class FirewallDictionaryController { } } termList.setFromZones(fromZoneValue); - + String toZoneValue = ""; int toZonecounter = 0; if(termListDatas.getToZoneDatas().size() > 0){ @@ -1224,7 +1568,7 @@ public class FirewallDictionaryController { } } termList.setToZones(toZoneValue); - + String srcListValues = ""; int srcListcounter = 0; if(termListDatas.getSourceListDatas().size() > 0){ @@ -1240,7 +1584,7 @@ public class FirewallDictionaryController { } } termList.setSrcIPList(srcListValues); - + String desListValues = ""; int destListcounter = 0; if(termListDatas.getDestinationListDatas().size() > 0){ @@ -1256,7 +1600,7 @@ public class FirewallDictionaryController { } } termList.setDestIPList(desListValues); - + String srcSerValue = ""; int srcSercounter = 0; if(termListDatas.getSourceServiceDatas().size() > 0){ @@ -1272,7 +1616,7 @@ public class FirewallDictionaryController { } } termList.setSrcPortList(srcSerValue); - + String desSrcValue = ""; int desSrccounter = 0; if(termListDatas.getDestinationServiceDatas().size() > 0){ @@ -1288,7 +1632,7 @@ public class FirewallDictionaryController { } } termList.setDestPortList(desSrcValue); - + String actionValue = ""; int actioncounter = 0; if(termListDatas.getActionListDatas().size() > 0){ @@ -1304,40 +1648,52 @@ public class FirewallDictionaryController { } } termList.setAction(actionValue); - + if(termList.getId() == 0){ - CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); - List duplicateData = entry.CheckDuplicateEntry(termList.getTermName(), "termName", TermList.class); + List duplicateData = commonClassDao.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); + commonClassDao.save(termList); } }else{ - termList.setUserModifiedBy(this.getUserInfo(userId)); - termListDao.update(termList); + if(!isFakeUpdate) { + termList.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.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()); + responseString = mapper.writeValueAsString(commonClassDao.getData(TermList.class)); } - JSONObject j = new JSONObject("{termListDictionaryDatas: " + responseString + "}"); - out.write(j.toString()); - - return null; - } - catch (Exception e){ + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{termListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + }catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -1346,28 +1702,28 @@ public class FirewallDictionaryController { return null; } - @RequestMapping(value={"/fw_dictionary/remove_termList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/fw_dictionary/remove_termList"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(TermList.class)); JSONObject j = new JSONObject("{termListDictionaryDatas: " + responseString + "}"); out.write(j.toString()); return null; } catch (Exception e){ - System.out.println(e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -1381,32 +1737,36 @@ public class FirewallDictionaryController { try{ Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); - model.put("fwDictListDictionaryDatas", mapper.writeValueAsString(fwDictionaryListDao.getFWDictionaryListDataByName())); + model.put("fwDictListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FirewallDictionaryList.class, "parentItemName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - + @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())); + model.put("fwDictListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - - @RequestMapping(value={"/fw_dictionary/save_FWDictionaryList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/fw_dictionary/save_FWDictionaryList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveFWDictionaryList(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; @@ -1446,15 +1806,14 @@ public class FirewallDictionaryController { } fwDictList.setAddressList(userALValue); if(fwDictList.getId() == 0){ - CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); - List duplicateData = entry.CheckDuplicateEntry(fwDictList.getParentItemName(), "parentItemName", FirewallDictionaryList.class); + List duplicateData = commonClassDao.checkDuplicateEntry(fwDictList.getParentItemName(), "parentItemName", FirewallDictionaryList.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - fwDictionaryListDao.Save(fwDictList); + commonClassDao.save(fwDictList); } }else{ - fwDictionaryListDao.update(fwDictList); + commonClassDao.update(fwDictList); } response.setCharacterEncoding("UTF-8"); response.setContentType("application / json"); @@ -1465,7 +1824,7 @@ public class FirewallDictionaryController { if(duplicateflag){ responseString = "Duplicate"; }else{ - responseString = mapper.writeValueAsString(this.fwDictionaryListDao.getFWDictionaryListData()); + responseString = mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class)); } JSONObject j = new JSONObject("{fwDictListDictionaryDatas: " + responseString + "}"); @@ -1474,6 +1833,7 @@ public class FirewallDictionaryController { return null; } catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -1482,28 +1842,28 @@ public class FirewallDictionaryController { return null; } - @RequestMapping(value={"/fw_dictionary/remove_FWDictionaryList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/fw_dictionary/remove_FWDictionaryList"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class)); JSONObject j = new JSONObject("{fwDictListDictionaryDatas: " + responseString + "}"); out.write(j.toString()); return null; } catch (Exception e){ - System.out.println(e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); @@ -1511,6 +1871,348 @@ public class FirewallDictionaryController { } return null; } + + + @RequestMapping(value={"/get_TagPickerNameByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getTagPickerNameEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("fwTagPickerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FWTagPicker.class, "tagPickerName"))); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_TagPickerListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getTagPickerDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("fwTagPickerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class))); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_fwTagPicker"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } + + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + + + FWTagPicker fwTagPicker; + TagGridValues data; + String userId = null; + if (fromAPI) { + fwTagPicker = (FWTagPicker)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), FWTagPicker.class); + data = (TagGridValues)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), TagGridValues.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), "tagPickerName", FWTagPicker.class); + int id = 0; + FWTagPicker dbdata = (FWTagPicker) duplicateData.get(0); + id = dbdata.getId(); + fwTagPicker.setId(id); + fwTagPicker.setUserCreatedBy(this.getUserInfo(userId)); + } + } else { + + fwTagPicker = (FWTagPicker)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), FWTagPicker.class); + data = (TagGridValues)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), TagGridValues.class); + userId = root.get("userid").textValue(); + } + + String header = ""; + int counter = 0; + if(data.getTags().size() > 0){ + for(Object attribute : data.getTags()){ + 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 ++; + } + } + } + fwTagPicker.setTagValues(header); + if(fwTagPicker.getId() == 0){ + List duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), "tagPickerName", FWTagPicker.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + fwTagPicker.setUserCreatedBy(this.getUserInfo(userId)); + fwTagPicker.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.save(fwTagPicker); + } + }else{ + fwTagPicker.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.update(fwTagPicker); + } + + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class)); + } + + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + responseString = "Success"; + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{fwTagPickerDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_tagPicker"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeFirewallTagPickerDictionary(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()); + FWTagPicker fwTagPicker = (FWTagPicker)mapper.readValue(root.get("data").toString(), FWTagPicker.class); + commonClassDao.delete(fwTagPicker); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class)); + JSONObject j = new JSONObject("{fwTagPickerDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + + @RequestMapping(value={"/get_TagNameByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getTagNameEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("fwTagDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FWTag.class, "fwTagName"))); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_TagListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getTagDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("fwTagDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(FWTag.class))); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_fwTag"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } + + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + + + FWTag fwTag; + TagGridValues tagGridValues; + String userId = null; + if (fromAPI) { + fwTag = (FWTag)mapper.readValue(root.get("fwTagDictionaryDatas").toString(), FWTag.class); + tagGridValues = (TagGridValues)mapper.readValue(root.get("fwTagDictionaryDatas").toString(), TagGridValues.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "tagName", FWTag.class); + int id = 0; + FWTag data = (FWTag) duplicateData.get(0); + id = data.getId(); + fwTag.setId(id); + fwTag.setUserCreatedBy(this.getUserInfo(userId)); + + } + } else { + fwTag = (FWTag)mapper.readValue(root.get("fwTagDictionaryData").toString(), FWTag.class); + tagGridValues = (TagGridValues)mapper.readValue(root.get("fwTagDictionaryData").toString(), TagGridValues.class); + userId = root.get("userid").textValue(); + } + + String userValue = ""; + int counter = 0; + if(tagGridValues.getTags().size() > 0){ + for(Object attribute : tagGridValues.getTags()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("tags").toString(); + if(counter>0){ + userValue = userValue + ","; + } + userValue = userValue + key ; + counter ++; + } + } + } + fwTag.setTagValues(userValue); + if(fwTag.getId() == 0){ + List duplicateData = commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "fwTagName", FWTag.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + fwTag.setUserCreatedBy(this.getUserInfo(userId)); + fwTag.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.save(fwTag); + } + }else{ + fwTag.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.update(fwTag); + } + + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.class)); + } + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + responseString = "Success"; + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{fwTagDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + return null; + } + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_tagList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeFirewallTagDictionary(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()); + FWTag fwTag = (FWTag)mapper.readValue(root.get("data").toString(), FWTag.class); + commonClassDao.delete(fwTag); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.class)); + JSONObject j = new JSONObject("{fwTagDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } +} + +class TagGridValues{ + private ArrayList tags; + + public ArrayList getTags() { + return tags; + } + + public void setTags(ArrayList tags) { + this.tags = tags; + } } class AGGridData{ 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 index c3329db14..75a3c7fa0 100644 --- 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 @@ -20,46 +20,32 @@ 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 java.util.Set; 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.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.pap.xacml.rest.XACMLPapServlet; 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.dao.CommonClassDao; import org.openecomp.policy.rest.jpa.DCAEuuid; +import org.openecomp.policy.rest.jpa.MicroServiceAttribute; 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.openecomp.policy.rest.util.MSModelUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -72,42 +58,43 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Controller public class MicroServiceDictionaryController { - private static final Log logger = LogFactory.getLog(MicroServiceDictionaryController.class); + private static final Logger LOGGER = FlexLogger.getLogger(MicroServiceDictionaryController.class); - @Autowired - MicroServiceConfigNameDao microServiceConfigNameDao; + private static CommonClassDao commonClassDao; @Autowired - MicroServiceLocationDao microServiceLocationDao; + public MicroServiceDictionaryController(CommonClassDao commonClassDao){ + MicroServiceDictionaryController.commonClassDao = commonClassDao; + } - @Autowired - MicroServiceModelsDao microServiceModelsDao; + public MicroServiceDictionaryController(){} - @Autowired - DCAEUUIDDao dcaeUUIDDao; + public UserInfo getUserInfo(String loginId){ + UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); + return name; + } - @Autowired - UserInfoDao userInfoDao; + private static String SUCCESSKEY= "successMapKey"; + private static String SUCCESS = "success"; + private static String OPERATION = "operation"; + private static String GETDICTIONARY = "getDictionary"; + private static String ERROR = "error"; + private static String DICTIONARYDBQUERY = "dictionaryDBQuery"; + private HashMap classMap; + private List modelList = new ArrayList(); + - private String newFile; - private String directory; - private List dirDependencyList = new ArrayList(); - private HashMap classMap = new HashMap(); - MSModelUtitils utils = new MSModelUtitils(); + MSModelUtils utils = new MSModelUtils(XACMLPapServlet.msEcompName, XACMLPapServlet.msPolicyName); 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())); + model.put("dcaeUUIDDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(DCAEuuid.class, "name"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -122,53 +109,93 @@ public class MicroServiceDictionaryController { try{ Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); - model.put("dcaeUUIDDictionaryDatas", mapper.writeValueAsString(dcaeUUIDDao.getDCAEuuidData())); + model.put("dcaeUUIDDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(DCAEuuid.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader(SUCCESSKEY, SUCCESS); + response.addHeader(OPERATION, GETDICTIONARY); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader(ERROR, DICTIONARYDBQUERY); + LOGGER.error(e.getMessage()); } } - @RequestMapping(value={"/ms_dictionary/save_dcaeUUID.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/ms_dictionary/save_dcaeUUID"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + DCAEuuid dCAEuuid; + if (fromAPI) { + dCAEuuid = (DCAEuuid)mapper.readValue(root.get("dictionaryFields").toString(), DCAEuuid.class); + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter(OPERATION).equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(dCAEuuid.getName(), "name", DCAEuuid.class); + int id = 0; + DCAEuuid data = (DCAEuuid) duplicateData.get(0); + id = data.getId(); + if(id==0){ + isFakeUpdate=true; + dCAEuuid.setId(1); + } else { + dCAEuuid.setId(id); + } + } + } else { + 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); + List duplicateData = commonClassDao.checkDuplicateEntry(dCAEuuid.getName(), "name", DCAEuuid.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - dcaeUUIDDao.Save(dCAEuuid); + commonClassDao.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()); + if(!isFakeUpdate) { + commonClassDao.update(dCAEuuid); + } } - JSONObject j = new JSONObject("{dcaeUUIDDictionaryDatas: " + responseString + "}"); - - out.write(j.toString()); - - return null; - } - catch (Exception e){ + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(DCAEuuid.class)); + } + + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + 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(); @@ -177,21 +204,21 @@ public class MicroServiceDictionaryController { return null; } - @RequestMapping(value={"/ms_dictionary/remove_dcaeuuid.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/ms_dictionary/remove_dcaeuuid"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(DCAEuuid.class)); JSONObject j = new JSONObject("{dcaeUUIDDictionaryDatas: " + responseString + "}"); out.write(j.toString()); @@ -213,7 +240,7 @@ public class MicroServiceDictionaryController { try{ Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); - model.put("microServiceCongigNameDictionaryDatas", mapper.writeValueAsString(microServiceConfigNameDao.getMSConfigDataByName())); + model.put("microServiceCongigNameDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceConfigName.class, "name"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -230,53 +257,94 @@ public class MicroServiceDictionaryController { try{ Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); - model.put("microServiceCongigNameDictionaryDatas", mapper.writeValueAsString(microServiceConfigNameDao.getMicroServiceConfigNameData())); + model.put("microServiceCongigNameDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceConfigName.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader(SUCCESSKEY, SUCCESS); + response.addHeader(OPERATION, GETDICTIONARY); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader(ERROR, DICTIONARYDBQUERY); + LOGGER.error(e.getMessage()); } } - @RequestMapping(value={"/ms_dictionary/save_configName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/ms_dictionary/save_configName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + MicroServiceConfigName microServiceConfigName; + if (fromAPI) { + microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceConfigName.class); + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter(OPERATION).equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(microServiceConfigName.getName(), "name", MicroServiceConfigName.class); + int id = 0; + MicroServiceConfigName data = (MicroServiceConfigName) duplicateData.get(0); + id = data.getId(); + + if(id==0){ + isFakeUpdate=true; + microServiceConfigName.setId(1); + } else { + microServiceConfigName.setId(id); + } + } + } else { + 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); + List duplicateData = commonClassDao.checkDuplicateEntry(microServiceConfigName.getName(), "name", MicroServiceConfigName.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - microServiceConfigNameDao.Save(microServiceConfigName); + commonClassDao.save(microServiceConfigName); } }else{ - microServiceConfigNameDao.update(microServiceConfigName); + if(!isFakeUpdate) { + commonClassDao.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){ + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceConfigName.class)); + } + + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + 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(); @@ -285,21 +353,21 @@ public class MicroServiceDictionaryController { return null; } - @RequestMapping(value={"/ms_dictionary/remove_msConfigName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/ms_dictionary/remove_msConfigName"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceConfigName.class)); JSONObject j = new JSONObject("{microServiceCongigNameDictionaryDatas: " + responseString + "}"); out.write(j.toString()); @@ -320,7 +388,7 @@ public class MicroServiceDictionaryController { try{ Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); - model.put("microServiceLocationDictionaryDatas", mapper.writeValueAsString(microServiceLocationDao.getMSLocationDataByName())); + model.put("microServiceLocationDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceLocation.class, "name"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -335,53 +403,94 @@ public class MicroServiceDictionaryController { try{ Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); - model.put("microServiceLocationDictionaryDatas", mapper.writeValueAsString(microServiceLocationDao.getMicroServiceLocationData())); + model.put("microServiceLocationDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceLocation.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader(SUCCESSKEY, SUCCESS); + response.addHeader(OPERATION, GETDICTIONARY); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader(ERROR, DICTIONARYDBQUERY); + LOGGER.error(e.getMessage()); } } - @RequestMapping(value={"/ms_dictionary/save_location.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/ms_dictionary/save_location"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + MicroServiceLocation microServiceLocation; + if (fromAPI) { + microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceLocation.class); + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter(OPERATION).equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(microServiceLocation.getName(), "name", MicroServiceLocation.class); + int id = 0; + MicroServiceLocation data = (MicroServiceLocation) duplicateData.get(0); + id = data.getId(); + + if(id==0){ + isFakeUpdate=true; + microServiceLocation.setId(1); + } else { + microServiceLocation.setId(id); + } + } + } else { + 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); + List duplicateData = commonClassDao.checkDuplicateEntry(microServiceLocation.getName(), "name", MicroServiceLocation.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - microServiceLocationDao.Save(microServiceLocation); + commonClassDao.save(microServiceLocation); } }else{ - microServiceLocationDao.update(microServiceLocation); + if(!isFakeUpdate) { + commonClassDao.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){ + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceLocation.class)); + } + + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + 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(); @@ -390,21 +499,21 @@ public class MicroServiceDictionaryController { return null; } - @RequestMapping(value={"/ms_dictionary/remove_msLocation.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/ms_dictionary/remove_msLocation"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceLocation.class)); JSONObject j = new JSONObject("{microServiceLocationDictionaryDatas: " + responseString + "}"); out.write(j.toString()); @@ -420,81 +529,367 @@ public class MicroServiceDictionaryController { return null; } + @RequestMapping(value={"/get_MicroServiceAttributeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceAttributeByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("microServiceAttributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceAttribute.class, "name"))); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + LOGGER.error(e.getMessage()); + } + } + + @RequestMapping(value={"/get_MicroServiceAttributeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceAttributeDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("microServiceAttributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceAttribute.class))); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.addHeader(SUCCESSKEY, SUCCESS); + response.addHeader(OPERATION, GETDICTIONARY); + response.getWriter().write(j.toString()); + + } + catch (Exception e){ + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader(ERROR, DICTIONARYDBQUERY); + LOGGER.error(e.getMessage()); + } + } + + @RequestMapping(value={"/ms_dictionary/save_modelAttribute"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } + + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + + MicroServiceAttribute microServiceAttribute; + if (fromAPI) { + microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceAttribute.class); + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter(OPERATION).equals("update")) { + MicroServiceAttribute initialAttribute = (MicroServiceAttribute)mapper.readValue(root.get("initialFields").toString(), MicroServiceAttribute.class); + + String checkValue = initialAttribute.getName() + ":" + initialAttribute.getValue() + ":" + initialAttribute.getModelName(); + List duplicateData = commonClassDao.checkDuplicateEntry(checkValue, "name:value:modelName", MicroServiceAttribute.class); + int id=0; + for (int i= 0; i duplicateData = commonClassDao.checkDuplicateEntry(checkValue, "name:value:modelName", MicroServiceAttribute.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + commonClassDao.save(microServiceAttribute); + } + }else{ + commonClassDao.update(microServiceAttribute); + } + + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceAttribute.class)); + } + + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + responseString = "Success"; + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{microServiceAttributeDictionaryDatas: " + 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_modelAttribute"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeMicroServiceAttributeDictionary(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()); + MicroServiceAttribute microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get("data").toString(), MicroServiceAttribute.class); + commonClassDao.delete(microServiceAttribute); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(MicroServiceDictionaryController.commonClassDao.getData(MicroServiceAttribute.class)); + JSONObject j = new JSONObject("{microServiceAttributeDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + LOGGER.error(e.getMessage()); + 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())); + model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceModels.class, "modelName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(e.getMessage()); } } + @RequestMapping(value={"/get_MicroServiceModelsDataByVersion"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceModelsDictionaryByVersionEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + JsonNode root = mapper.readTree(request.getReader()); + String modelName = null; + if (root.get("microServiceModelsDictionaryData").has("modelName")){ + modelName = root.get("microServiceModelsDictionaryData").get("modelName").asText().replace("\"", ""); + } + if (modelName!=null){ + model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataById(MicroServiceModels.class, "modelName", modelName))); + } else{ + model.put(ERROR, "No model name given"); + } + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + LOGGER.error(e.getMessage()); + } + } + @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())); + model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceModels.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader(SUCCESSKEY, SUCCESS); + response.addHeader(OPERATION, GETDICTIONARY); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader(ERROR, DICTIONARYDBQUERY); + LOGGER.error(e.getMessage()); } } - @RequestMapping(value={"/ms_dictionary/save_model.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/get_MicroServiceModelsDataServiceVersion"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceModelsDictionaryEntityDataServiceVersion(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + List data = new ArrayList(); + List datas = commonClassDao.getData(MicroServiceModels.class); + for(int i = 0; i < datas.size(); i++){ + MicroServiceModels msmodel = (MicroServiceModels) datas.get(i); + if (!data.contains(msmodel.getModelName())){ + data.add(msmodel.getModelName() + "-v" + msmodel.getVersion()); + } + } + model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(data)); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); + response.getWriter().write(j.toString()); + + } + catch (Exception e){ + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_MicroServiceModelsDataByClass"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceModelsDictionaryClassEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("microServiceModelsDictionaryClassDatas", mapper.writeValueAsString(modelList)); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.addHeader(SUCCESSKEY, SUCCESS); + response.addHeader(OPERATION, GETDICTIONARY); + response.getWriter().write(j.toString()); + + } + catch (Exception e){ + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader(ERROR, DICTIONARYDBQUERY); + LOGGER.error(e.getMessage()); + } + } + + @RequestMapping(value={"/ms_dictionary/save_model"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean fromAPI = false; + this.newModel = new MicroServiceModels(); + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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 microServiceModels = new MicroServiceModels(); + String userId = null; + if (fromAPI) { + microServiceModels = (MicroServiceModels)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceModels.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter(OPERATION).equals("update")) { + String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion(); + List duplicateData = commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class); + int id = 0; + for (int i=0; i< duplicateData.size(); i++){ + MicroServiceModels data = (MicroServiceModels) duplicateData.get(0); + id = data.getId(); + } + microServiceModels.setId(id); + microServiceModels.setUserCreatedBy(this.getUserInfo(userId)); + + } + } else { + //microServiceModels = (MicroServiceModels)mapper.readValue(root.get("microServiceModelsDictionaryData").toString(), MicroServiceModels.class); + if (root.has("microServiceModelsDictionaryData")){ + if (root.get("microServiceModelsDictionaryData").has("description")){ + microServiceModels.setDescription(root.get("microServiceModelsDictionaryData").get("description").asText().replace("\"", "")); + } + if (root.get("microServiceModelsDictionaryData").has("modelName")){ + microServiceModels.setModelName(root.get("microServiceModelsDictionaryData").get("modelName").asText().replace("\"", "")); + this.newModel.setModelName(microServiceModels.getModelName()); + } + if (root.get("microServiceModelsDictionaryData").has("version")){ + microServiceModels.setVersion(root.get("microServiceModelsDictionaryData").get("version").asText().replace("\"", "")); + this.newModel.setVersion(microServiceModels.getVersion()); + } + } + if(root.has("classMap")){ + classMap = new HashMap(); + JsonNode data = root.get("classMap"); + ObjectMapper mapper1 = new ObjectMapper(); + String data1 = data.toString().substring(1, data.toString().length()-1); + data1 = data1.replace("\\", ""); + JSONObject jsonObject = new JSONObject(data1); + Set keys = jsonObject.keySet(); + for(String key : keys){ + String value = jsonObject.get(key).toString(); + MSAttributeObject msAttributeObject = mapper1.readValue(value, MSAttributeObject.class); + classMap.put(key, msAttributeObject); + } + } + userId = root.get("userid").textValue(); + addValuesToNewModel(classMap); + } 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()); + microServiceModels.setEnumValues(this.newModel.getEnumValues()); + microServiceModels.setAnnotation(this.newModel.getAnnotation()); + if(microServiceModels.getId() == 0){ - CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); - List duplicateData = entry.CheckDuplicateEntry(microServiceModels.getModelName(), "modelName", MicroServiceModels.class); + String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion(); + List duplicateData = commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ microServiceModels.setUserCreatedBy(this.getUserInfo(userId)); - microServiceModelsDao.Save(microServiceModels); + commonClassDao.save(microServiceModels); } }else{ - microServiceModelsDao.update(microServiceModels); + commonClassDao.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){ + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceModels.class)); + } + + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + responseString = "Success"; + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + 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(); @@ -503,21 +898,21 @@ public class MicroServiceDictionaryController { return null; } - @RequestMapping(value={"/ms_dictionary/remove_msModel.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/ms_dictionary/remove_msModel"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceModels.class)); JSONObject j = new JSONObject("{microServiceModelsDictionaryDatas: " + responseString + "}"); out.write(j.toString()); @@ -533,55 +928,12 @@ public class MicroServiceDictionaryController { 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() { + + + + private void addValuesToNewModel(HashMap classMap) { + new MicroServiceModels(); //Loop through the classmap and pull out the required info for the new file. MSAttributeObject mainClass = null; ArrayList dependency = null; @@ -615,7 +967,9 @@ public class MicroServiceDictionaryController { this.newModel.setSub_attributes(subAttribute.toString()); this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", "")); this.newModel.setRef_attributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", "")); - + this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", "")); + this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", "")); + } private ArrayList getFullDependencyList(ArrayList dependency) { @@ -639,80 +993,4 @@ public class MicroServiceDictionaryController { 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 index b8803d738..ab86ce2a8 100644 --- 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 @@ -31,13 +31,10 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; import org.json.JSONObject; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; 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.dao.CommonClassDao; import org.openecomp.policy.rest.jpa.GroupPolicyScopeList; import org.openecomp.policy.rest.jpa.PolicyScopeClosedLoop; import org.openecomp.policy.rest.jpa.PolicyScopeResource; @@ -57,36 +54,30 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Controller public class PolicyScopeDictionaryController { - @Autowired - GroupPolicyScopeListDao groupPolicyScopeListDao; - - @Autowired - PolicyScopeClosedLoopDao policyScopeClosedLoopDao; - - @Autowired - PolicyScopeResourceDao PolicyScopeResourceDao; - - @Autowired - PolicyScopeTypeDao policyScopeTypeDao; + private static final Logger LOGGER = FlexLogger.getLogger(PolicyScopeDictionaryController.class); + + private static CommonClassDao commonClassDao; @Autowired - PolicyScopeServiceDao policyScopeServiceDao; + public PolicyScopeDictionaryController(CommonClassDao commonClassDao){ + PolicyScopeDictionaryController.commonClassDao = commonClassDao; + } + public PolicyScopeDictionaryController(){} + + private static String SUCCESSMAPKEY = "successMapKey"; - @Autowired - UserInfoDao userInfoDao; - public UserInfo getUserInfo(String loginId){ - UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", 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())); + model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(GroupPolicyScopeList.class, "name"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -95,41 +86,96 @@ public class PolicyScopeDictionaryController { 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())); + model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader(SUCCESSMAPKEY, "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); + LOGGER.error(e); } } - - @RequestMapping(value={"/ps_dictionary/save_psGroupPolicyScope.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/ps_dictionary/save_psGroupPolicyScope"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean duplicateGroupFlag = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } + 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); + //GroupPolicyScopeList gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class); + GroupPolicyScopeList gpdata = null; 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("\"", "")); + if (fromAPI) { + gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("dictionaryFields").toString(), GroupPolicyScopeList.class); + try{ + groupData = (GroupPolicyScope)mapper.readValue(root.get("groupPolicyScopeListData1").toString(), GroupPolicyScope.class); + }catch(Exception e){ + groupData = new GroupPolicyScope(); + groupData.setResource(root.get("dictionaryFields").get("resource").toString().replace("\"", "")); + groupData.setClosedloop(root.get("dictionaryFields").get("closedloop").toString().replace("\"", "")); + groupData.setService(root.get("dictionaryFields").get("service").toString().replace("\"", "")); + groupData.setType(root.get("dictionaryFields").get("type").toString().replace("\"", "")); + } + + if(!gpdata.getGroupName().startsWith("PolicyScope")){ + String name = "PolicyScope_" + gpdata.getGroupName(); + gpdata.setGroupName(name); + } + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + + List duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), "name", GroupPolicyScopeList.class); + int id = 0; + for (int i =0; i< duplicateData.size(); i++){ + GroupPolicyScopeList data = (GroupPolicyScopeList) duplicateData.get(0); + id = data.getId(); + } + + if(id==0){ + isFakeUpdate=true; + gpdata.setId(1); + } else { + gpdata.setId(id); + } + + } + } else { + gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class); + + 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("\"", "")); + } + if(!gpdata.getGroupName().startsWith("PolicyScope")){ + String name = "PolicyScope_" + gpdata.getGroupName(); + gpdata.setGroupName(name); + } + } - ArrayList valueList = new ArrayList(); String list = null; String resourceValue = groupData.getResource(); @@ -141,40 +187,66 @@ public class PolicyScopeDictionaryController { 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); + gpdata.setGroupList(list); + if(!gpdata.getGroupName().startsWith("PolicyScope")){ + String name = "PolicyScope_" + gpdata.getGroupName(); + gpdata.setGroupName(name); } - if(ecompData.getId() == 0){ - CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); - List duplicateData = entry.CheckDuplicateEntry(ecompData.getGroupName(), "name", GroupPolicyScopeList.class); + if(gpdata.getId() == 0){ + List duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), "name", GroupPolicyScopeList.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - groupPolicyScopeListDao.Save(ecompData); + duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupList(), "groupList", GroupPolicyScopeList.class); + if(!duplicateData.isEmpty()){ + duplicateGroupFlag = true; + }else{ + commonClassDao.save(gpdata); + } } }else{ - groupPolicyScopeListDao.update(ecompData); - } - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); - - PrintWriter out = response.getWriter(); + if(!isFakeUpdate) { + List duplicateGroupList = commonClassDao.checkExistingGroupListforUpdate(gpdata.getGroupList(), gpdata.getGroupName()); + if(!duplicateGroupList.isEmpty()) { + duplicateGroupFlag = true; + } else { + commonClassDao.update(gpdata); + } + } + } String responseString = ""; if(duplicateflag){ responseString = "Duplicate"; + }else if(duplicateGroupFlag){ + responseString = "DuplicateGroup"; }else{ - responseString = mapper.writeValueAsString(this.groupPolicyScopeListDao.getGroupPolicyScopeListData()); + responseString = mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class)); } - JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}"); - out.write(j.toString()); + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate") && !responseString.equals("DuplicateGroup")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } - return null; - } - catch (Exception e){ + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + 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(); @@ -183,21 +255,21 @@ public class PolicyScopeDictionaryController { return null; } - @RequestMapping(value={"/ps_dictionary/remove_GroupPolicyScope.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/ps_dictionary/remove_GroupPolicyScope"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class)); JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}"); out.write(j.toString()); @@ -212,13 +284,13 @@ public class PolicyScopeDictionaryController { } 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())); + model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeClosedLoop.class, "name"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -227,59 +299,106 @@ public class PolicyScopeDictionaryController { 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())); + model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader(SUCCESSMAPKEY, "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); + LOGGER.error(e); } } - - @RequestMapping(value={"/ps_dictionary/save_psClosedLoop.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/ps_dictionary/save_psClosedLoop"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + PolicyScopeClosedLoop ecompData; + if (fromAPI) { + ecompData = (PolicyScopeClosedLoop)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeClosedLoop.class); + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getName(), "name", PolicyScopeClosedLoop.class); + int id = 0; + for (int i =0; i< duplicateData.size(); i++){ + PolicyScopeClosedLoop data = (PolicyScopeClosedLoop) duplicateData.get(0); + id = data.getId(); + } + + if(id==0){ + isFakeUpdate=true; + ecompData.setId(1); + } else { + ecompData.setId(id); + } + + } + } else { + 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); + List duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getName(), "name", PolicyScopeClosedLoop.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - policyScopeClosedLoopDao.Save(ecompData); + commonClassDao.save(ecompData); } }else{ - policyScopeClosedLoopDao.update(ecompData); + if(!isFakeUpdate) { + commonClassDao.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 + "}"); + responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class)); + } - out.write(j.toString()); + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); - return null; - } - catch (Exception e){ + PrintWriter out = response.getWriter(); + 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(); @@ -288,21 +407,21 @@ public class PolicyScopeDictionaryController { return null; } - @RequestMapping(value={"/ps_dictionary/remove_PSClosedLoop.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/ps_dictionary/remove_PSClosedLoop"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class)); JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}"); out.write(j.toString()); @@ -317,13 +436,13 @@ public class PolicyScopeDictionaryController { } 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())); + model.put("psServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeService.class, "name"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -332,59 +451,103 @@ public class PolicyScopeDictionaryController { 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())); + model.put("psServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader(SUCCESSMAPKEY, "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); + LOGGER.error(e); } } - - @RequestMapping(value={"/ps_dictionary/save_psService.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/ps_dictionary/save_psService"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + PolicyScopeService ecompData; + if (fromAPI) { + ecompData = (PolicyScopeService)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeService.class); + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getName(), "name", PolicyScopeService.class); + int id = 0; + for (int i =0; i< duplicateData.size(); i++){ + PolicyScopeService data = (PolicyScopeService) duplicateData.get(0); + id = data.getId(); + } + if(id==0){ + isFakeUpdate=true; + ecompData.setId(1); + } else { + ecompData.setId(id); + } + } + } else { + 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); + List duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getName(), "name", PolicyScopeService.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - policyScopeServiceDao.Save(ecompData); + commonClassDao.save(ecompData); } }else{ - policyScopeServiceDao.update(ecompData); + if(!isFakeUpdate) { + commonClassDao.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){ + responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class)); + } + + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + 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(); @@ -393,21 +556,21 @@ public class PolicyScopeDictionaryController { return null; } - @RequestMapping(value={"/ps_dictionary/remove_PSService.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/ps_dictionary/remove_PSService"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class)); JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}"); out.write(j.toString()); @@ -422,13 +585,13 @@ public class PolicyScopeDictionaryController { } 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())); + model.put("psTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeType.class, "name"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -437,59 +600,109 @@ public class PolicyScopeDictionaryController { 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())); + model.put("psTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader(SUCCESSMAPKEY, "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); + LOGGER.error(e); } } - - @RequestMapping(value={"/ps_dictionary/save_psType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/ps_dictionary/save_psType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + PolicyScopeType ecompData; + if (fromAPI) { + ecompData = (PolicyScopeType)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeType.class); + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getName(), "name", PolicyScopeType.class); + int id = 0; + for (int i =0; i< duplicateData.size(); i++){ + PolicyScopeType data = (PolicyScopeType) duplicateData.get(0); + id = data.getId(); + } + + if(id==0){ + isFakeUpdate=true; + ecompData.setId(1); + } else { + ecompData.setId(id); + } + + } + } else { + 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); + List duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getName(), "name", PolicyScopeType.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - policyScopeTypeDao.Save(ecompData); + commonClassDao.save(ecompData); } }else{ - policyScopeTypeDao.update(ecompData); + if(!isFakeUpdate) { + commonClassDao.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()); + responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class)); } - JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}"); - out.write(j.toString()); + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } - return null; - } - catch (Exception e){ + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + + } else { + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + 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(); @@ -498,21 +711,21 @@ public class PolicyScopeDictionaryController { return null; } - @RequestMapping(value={"/ps_dictionary/remove_PSType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/ps_dictionary/remove_PSType"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class)); JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}"); out.write(j.toString()); @@ -527,13 +740,13 @@ public class PolicyScopeDictionaryController { } 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())); + model.put("psResourceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeResource.class, "name"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -542,59 +755,106 @@ public class PolicyScopeDictionaryController { 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())); + model.put("psResourceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ - e.printStackTrace(); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); + LOGGER.error(e); } } - - @RequestMapping(value={"/ps_dictionary/save_psResource.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + + @RequestMapping(value={"/ps_dictionary/save_psResource"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + PolicyScopeResource ecompData; + if (fromAPI) { + ecompData = (PolicyScopeResource)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeResource.class); + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getName(), "name", PolicyScopeResource.class); + int id = 0; + PolicyScopeResource data = (PolicyScopeResource) duplicateData.get(0); + id = data.getId(); + + if(id==0){ + isFakeUpdate=true; + ecompData.setId(1); + } else { + ecompData.setId(id); + } + } + } else { + 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); + List duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getName(), "name", PolicyScopeResource.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - PolicyScopeResourceDao.Save(ecompData); + commonClassDao.save(ecompData); } }else{ - PolicyScopeResourceDao.update(ecompData); + if(!isFakeUpdate) { + commonClassDao.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 + "}"); + responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class)); + } - out.write(j.toString()); + if (fromAPI) { + if (responseString!=null && !responseString.equals("Duplicate")) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } - return null; - } - catch (Exception e){ + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + + } else { + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + 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(); @@ -603,21 +863,21 @@ public class PolicyScopeDictionaryController { return null; } - @RequestMapping(value={"/ps_dictionary/remove_PSResource.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + @RequestMapping(value={"/ps_dictionary/remove_PSResource"}, 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class)); JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}"); out.write(j.toString()); @@ -634,7 +894,7 @@ public class PolicyScopeDictionaryController { } } - class GroupPolicyScope{ +class GroupPolicyScope{ String resource; String type; String service; @@ -663,5 +923,5 @@ public class PolicyScopeDictionaryController { public void setClosedloop(String closedloop) { this.closedloop = closedloop; } - + } diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/PushPolicyController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/PushPolicyController.java new file mode 100644 index 000000000..046bb3cfb --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/PushPolicyController.java @@ -0,0 +1,253 @@ +/*- + * ============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.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.net.URI; +import java.util.List; +import java.util.UUID; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.pap.xacml.rest.XACMLPapServlet; +import org.openecomp.policy.rest.dao.CommonClassDao; +import org.openecomp.policy.rest.jpa.PolicyEntity; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.xacml.std.pap.StdPDPGroup; +import org.openecomp.policy.xacml.std.pap.StdPDPPolicy; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import com.att.research.xacml.api.pap.PAPException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +public class PushPolicyController { + private static final Logger LOGGER = FlexLogger.getLogger(PushPolicyController.class); + + private static CommonClassDao commonClassDao; + + @Autowired + public PushPolicyController(CommonClassDao commonClassDao){ + PushPolicyController.commonClassDao = commonClassDao; + } + + public PushPolicyController(){} + + @RequestMapping(value="/pushPolicy", method=RequestMethod.POST) + public void pushPolicy(HttpServletRequest request, HttpServletResponse response){ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + try { + JsonNode root = mapper.readTree(request.getInputStream()); + String policyScope = root.get("policyScope").asText(); + String filePrefix = root.get("filePrefix").asText(); + String policyName = root.get("policyName").asText(); + String pdpGroup = root.get("pdpGroup").asText(); + String requestID = request.getHeader("X-ECOMP-RequestID"); + if(requestID==null){ + requestID = UUID.randomUUID().toString(); + LOGGER.info("No request ID provided, sending generated ID: " + requestID.toString()); + } + LOGGER.info("Push policy Request : " + root.asText()); + String policyVersionName = policyScope.replace(".", File.separator) + File.separator + + filePrefix + policyName; + List policyVersionObject = commonClassDao.getDataById(PolicyVersion.class, "policyName", policyVersionName); + if(policyVersionObject!=null){ + PolicyVersion policyVersion = (PolicyVersion) policyVersionObject.get(0); + String policyID = policyVersionName.replace(File.separator, "."); // This is before adding version. + policyVersionName += "." + policyVersion.getActiveVersion() + ".xml"; + addPolicyToGroup(policyScope, policyID, policyVersionName.replace(File.separator, "."), pdpGroup, response); + }else{ + String message = "Unknown Policy '" + policyName + "'"; + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); + response.addHeader("error", "unknownPolicy"); + response.addHeader("operation", "push"); + response.addHeader("message", message); + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + return; + } + //safetyChecker(policyName); + } catch (NullPointerException | IOException e) { + LOGGER.error(e); + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + response.addHeader("error", "unknown"); + response.addHeader("operation", "push"); + return; + } + } + + /*private void safetyChecker(String policyName) { + if (XACMLProperties.getProperty("xacml.rest.pap.safetychecker").equals("on")) { + if (policyName.contains("Config_MS_") || policyName.contains("BRMS_Param")) { + SafetyCheckerService service = new SafetyCheckerService(); + PolicySafetyChecker safetyChecker = new PolicySafetyChecker(); + boolean isEntered = false; + try { + JSONObject policyDataObj = service.getConfigByPolicyName(policyName, XACMLPapServlet.getConfigHome()); + isEntered = safetyChecker.addItem(policyDataObj); + } catch (Exception e) { + PolicyLogger.warn(MessageCodes.ERROR_PROCESS_FLOW, "XACMLPapServlet", e, "Error while adding ClosedLoop in the database: " + + "This is a PolicySafetyChecker warning, the push execution may proceed normally."); + } + if (isEntered) { + LOGGER.info("SafetyChecker successfully added the closedLoop to the DB table."); + } else { + LOGGER.info("SafetyChecker failed to add the closedLoop to the DB table."); + } + } + } else { + LOGGER.info("PolicySafetyChecker is turned off."); + } + }*/ + + private void addPolicyToGroup(String policyScope, String policyID, String policyName, String pdpGroup, HttpServletResponse response) { + StdPDPGroup selectedPDPGroup = null; + StdPDPPolicy selectedPolicy = null; + //Get the current policies from the Group and Add the new one + //Set currentPoliciesInGroup = null; + try { + selectedPDPGroup = (StdPDPGroup) XACMLPapServlet.getPAPEngine().getGroup(pdpGroup); + } catch (PAPException e1) { + PolicyLogger.error(e1); + } + if(selectedPDPGroup==null){ + String message = "Unknown groupId '" + selectedPDPGroup + "'"; + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); + response.addHeader("error", "unknownGroupId"); + response.addHeader("operation", "push"); + response.addHeader("message", message); + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + return; + } + //Get PolicyEntity from DB; + EntityManager em = XACMLPapServlet.getEmf().createEntityManager(); + Query createPolicyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:policyName"); + createPolicyQuery.setParameter("scope", policyScope); + createPolicyQuery.setParameter("policyName", policyName.substring(policyScope.length()+1)); + List createPolicyQueryList = createPolicyQuery.getResultList(); + PolicyEntity policyEntity = null; + if(createPolicyQueryList.size()>0){ + policyEntity = (PolicyEntity)createPolicyQueryList.get(0); + }else{ + PolicyLogger.error("Somehow, more than one policy with the same scope, name, and deleted status were found in the database"); + String message = "Unknown Policy '" + policyName + "'"; + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); + response.addHeader("error", "unknownPolicy"); + response.addHeader("operation", "push"); + response.addHeader("message", message); + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + return; + } + File temp = new File(policyName); + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(temp)); + bw.write(policyEntity.getPolicyData()); + bw.close(); + URI selectedURI = temp.toURI(); + // Create the policy Object + selectedPolicy = new StdPDPPolicy(policyName, true, policyID, selectedURI); + } catch (IOException e) { + LOGGER.error("Unable to create policy '" + policyName + "': "+ e.getMessage()); + } + try { + new ObjectOutputStream(response.getOutputStream()).writeObject(selectedPolicy); + } catch (IOException e) { + LOGGER.error(e); + response.addHeader("error", "policyCopyError"); + response.addHeader("message", e.getMessage()); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + return; + } + response.addHeader("Content-Type","application/json"); + response.setStatus(HttpServletResponse.SC_ACCEPTED); + response.addHeader("operation", "push"); + response.addHeader("policyId", policyName); + return; + // TODO : Check point to push policies within PAP. + /*PolicyDBDaoTransaction addPolicyToGroupTransaction = XACMLPapServlet.getDbDaoTransaction(); + try{ + if (selectedPolicy != null) { + // Add Current policies from container + currentPoliciesInGroup = selectedPDPGroup.getPolicies(); + // copy policy to PAP + addPolicyToGroupTransaction.addPolicyToGroup(selectedPDPGroup.getId(), policyName,"XACMLPapServlet.pushPolicyController"); + ((StdPDPGroup) selectedPDPGroup).copyPolicyToFile(policyName, policyID, new FileInputStream(temp)); + addPolicyToGroupTransaction.commitTransaction(); + } + }catch (Exception e) { + addPolicyToGroupTransaction.rollbackTransaction(); + String message = "Policy '" + policyName + "' not copied to group '" + pdpGroup +"': " + e; + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " " + message); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.addHeader("error", "policyCopyError"); + response.addHeader("message", message); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + return; + } + //If the selected policy is in the group we must remove it because the name is default + for (PDPPolicy existingPolicy : currentPoliciesInGroup) { + if (existingPolicy.getId().equals(selectedPolicy.getId())) { + selectedPDPGroup.removePolicyFromGroup(existingPolicy); + LOGGER.debug("Removing existing policy: " + existingPolicy); + break; + } + } + //Update the PDP Group after removing old version of policy + //Set updatedPoliciesInGroup = selectedPDPGroup.getPolicies(); + //need to remove the policy with default name from group + for (PDPPolicy updatedPolicy : currentPoliciesInGroup) { + if (updatedPolicy.getName().equalsIgnoreCase("default")) { + selectedPDPGroup.removePolicyFromGroup(updatedPolicy); + } + } + Set policies = selectedPDPGroup.getPolicies(); + policies.add(selectedPolicy); + selectedPDPGroup.setPolicies(policies); + // Update now. + try { + XACMLPapServlet.getPAPEngine().updateGroup(selectedPDPGroup); + } catch (PAPException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // policy file copied ok and the Group was updated on the PDP + response.setStatus(HttpServletResponse.SC_NO_CONTENT); + response.addHeader("operation", "push"); + response.addHeader("policyId", policyName); + response.addHeader("groupId", pdpGroup); + return;*/ + } +} 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 index 5ee72f4f0..1f84ae09a 100644 --- 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 @@ -28,15 +28,11 @@ 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.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; 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.dao.CommonClassDao; import org.openecomp.policy.rest.jpa.RiskType; import org.openecomp.policy.rest.jpa.SafePolicyWarning; import org.openecomp.policy.rest.jpa.UserInfo; @@ -53,45 +49,31 @@ 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; + private static final Logger LOGGER = FlexLogger.getLogger(SafePolicyController.class); - - 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; + private static CommonClassDao commonClassDao; + + @Autowired + public SafePolicyController(CommonClassDao commonClassDao){ + SafePolicyController.commonClassDao = commonClassDao; } - - public UserInfo getUserInfo(String loginId) { - UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); - return name; + + public SafePolicyController(){} + + public UserInfo getUserInfo(String loginId){ + UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); + return name; } + + private static String DUPLICATE = "Duplicate"; - // 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())); + model.put("riskTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(RiskType.class, "name"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -103,68 +85,108 @@ public class SafePolicyController { @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())); + model.put("riskTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(RiskType.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e) { - e.printStackTrace(); - logger.error("ERROR While callinge DAO: " + e.getMessage()); + LOGGER.error(e.getMessage()); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); } } - @RequestMapping(value = { "/sp_dictionary/save_riskType.htm" }, method = { + @RequestMapping(value = { "/sp_dictionary/save_riskType" }, 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"); + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + RiskType riskTypeData; + String userId = null; + if (fromAPI) { + riskTypeData = (RiskType) mapper.readValue(root.get("dictionaryFields").toString(), + RiskType.class); + userId = "API"; + + //check if update operation or create, get id for data to be updated and update attributeData + if ("update".equalsIgnoreCase(request.getParameter("operation"))){ + List duplicateData = commonClassDao.checkDuplicateEntry(riskTypeData.getRiskName(), "name", RiskType.class); + int id = 0; + RiskType data = (RiskType) duplicateData.get(0); + id = data.getId(); + + if(id==0){ + isFakeUpdate=true; + riskTypeData.setId(1); + } else { + riskTypeData.setId(id); + } + + riskTypeData.setUserCreatedBy(this.getUserInfo(userId)); + } + } else { + riskTypeData = (RiskType) mapper.readValue(root.get("riskTypeDictionaryData").toString(), RiskType.class); + userId = root.get("userid").textValue(); + } + if (riskTypeData.getId() == 0) { - CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); - List duplicateData = entry.CheckDuplicateEntry(riskTypeData.getRiskName(), "name", RiskType.class); + List duplicateData = commonClassDao.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); + commonClassDao.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()); + if (!isFakeUpdate) { + riskTypeData.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.update(riskTypeData); + } } - JSONObject j = new JSONObject("{riskTypeDictionaryDatas: " + responseString + "}"); - - out.write(j.toString()); - - return null; - } catch (Exception e) { + String responseString = ""; + if(duplicateflag){ + responseString = DUPLICATE; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(RiskType.class)); + } + + if (fromAPI) { + if (responseString!=null && !responseString.equals(DUPLICATE)) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + 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(); @@ -173,7 +195,7 @@ public class SafePolicyController { return null; } - @RequestMapping(value = { "/sp_dictionary/remove_riskType.htm" }, method = { + @RequestMapping(value = { "/sp_dictionary/remove_riskType" }, method = { org.springframework.web.bind.annotation.RequestMethod.POST }) public ModelAndView removeEcompDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { @@ -182,20 +204,19 @@ public class SafePolicyController { 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); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(RiskType.class)); 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(); @@ -211,7 +232,7 @@ public class SafePolicyController { Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); model.put("safePolicyWarningDatas", - mapper.writeValueAsString(safePolicyWarningDao.getSafePolicyWarningDataByName())); + mapper.writeValueAsString(commonClassDao.getDataByColumn(SafePolicyWarning.class, "name"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -227,55 +248,98 @@ public class SafePolicyController { Map model = new HashMap(); ObjectMapper mapper = new ObjectMapper(); model.put("safePolicyWarningDatas", - mapper.writeValueAsString(safePolicyWarningDao.getSafePolicyWarningData())); + mapper.writeValueAsString(commonClassDao.getData(SafePolicyWarning.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e) { - e.printStackTrace(); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "dictionaryDBQuery"); + LOGGER.error(e.getMessage()); } } - @RequestMapping(value = { "/sp_dictionary/save_safePolicyWarning.htm" }, method = { + @RequestMapping(value = { "/sp_dictionary/save_safePolicyWarning" }, method = { org.springframework.web.bind.annotation.RequestMethod.POST }) public ModelAndView saveSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { try { boolean duplicateflag = false; + boolean isFakeUpdate = false; + boolean fromAPI = false; + if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + fromAPI = true; + } 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); + SafePolicyWarning safePolicyWarning; + if (fromAPI) { + safePolicyWarning = (SafePolicyWarning) mapper + .readValue(root.get("dictionaryFields").toString(), SafePolicyWarning.class); + + //check if update operation or create, get id for data to be updated and update attributeData + if (request.getParameter("operation").equals("update")) { + List duplicateData = commonClassDao.checkDuplicateEntry(safePolicyWarning.getName(), "name", SafePolicyWarning.class); + int id = 0; + SafePolicyWarning data = (SafePolicyWarning) duplicateData.get(0); + id = data.getId(); + + if(id==0){ + isFakeUpdate=true; + safePolicyWarning.setId(1); + } else { + safePolicyWarning.setId(id); + } + } + } else { + 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); + List duplicateData = commonClassDao.checkDuplicateEntry(safePolicyWarning.getName(), "name", SafePolicyWarning.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ - safePolicyWarningDao.Save(safePolicyWarning); + commonClassDao.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()); + if(!isFakeUpdate) { + commonClassDao.update(safePolicyWarning); + } } - JSONObject j = new JSONObject("{safePolicyWarningDatas: " + responseString + "}"); - - out.write(j.toString()); - - return null; - } catch (Exception e) { + String responseString = ""; + if(duplicateflag){ + responseString = DUPLICATE; + }else{ + responseString = mapper.writeValueAsString(commonClassDao.getData(SafePolicyWarning.class)); + } + + if (fromAPI) { + if (responseString!=null && !responseString.equals(DUPLICATE)) { + if(isFakeUpdate){ + responseString = "Exists"; + } else { + responseString = "Success"; + } + } + ModelAndView result = new ModelAndView(); + result.setViewName(responseString); + return result; + } else { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + 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(); @@ -284,7 +348,7 @@ public class SafePolicyController { return null; } - @RequestMapping(value = { "/sp_dictionary/remove_SafePolicyWarning.htm" }, method = { + @RequestMapping(value = { "/sp_dictionary/remove_SafePolicyWarning" }, method = { org.springframework.web.bind.annotation.RequestMethod.POST }) public ModelAndView removeSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { @@ -294,14 +358,14 @@ public class SafePolicyController { JsonNode root = mapper.readTree(request.getReader()); SafePolicyWarning safePolicyWarningData = (SafePolicyWarning) mapper.readValue(root.get("data").toString(), SafePolicyWarning.class); - safePolicyWarningDao.delete(safePolicyWarningData); + commonClassDao.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()); + String responseString = mapper.writeValueAsString(commonClassDao.getData(SafePolicyWarning.class)); JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}"); out.write(j.toString()); 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 index df0e40a56..049f3c72c 100644 --- 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 @@ -18,10 +18,5 @@ * ============LICENSE_END========================================================= */ -/** - * - */ -/** - * - */ + package org.openecomp.policy.pap.xacml.rest.controller; -- cgit 1.2.3-korg