X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fadmin%2FPolicyRestController.java;h=507f19820d36807a0e3d37c03ec37e90c9d09511;hb=7bb6ef9ad8a483bdac3ff1544cd0910ecebe5a98;hp=f38f3e26683d03b70b54718386b74050739869ec;hpb=428150834ee60899b9a8da019bae3c8bf009adf1;p=policy%2Fengine.git diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java index f38f3e266..507f19820 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Engine * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -84,23 +84,25 @@ public class PolicyRestController extends RestrictedBaseController{ private static CommonClassDao commonClassDao; - public static CommonClassDao getCommonClassDao() { - return commonClassDao; + public PolicyRestController(){ + //default constructor } - public static void setCommonClassDao(CommonClassDao commonClassDao) { - PolicyRestController.commonClassDao = commonClassDao; - } - @Autowired private PolicyRestController(CommonClassDao commonClassDao){ PolicyRestController.commonClassDao = commonClassDao; } - public PolicyRestController(){ - //default constructor + public static CommonClassDao getCommonClassDao() { + return commonClassDao; } + public static void setCommonClassDao(CommonClassDao commonClassDao) { + PolicyRestController.commonClassDao = commonClassDao; + } + + + @RequestMapping(value={"/policycreation/save_policy"}, method={RequestMethod.POST}) public void policyCreationController(HttpServletRequest request, HttpServletResponse response) { String userId = UserUtils.getUserSession(request).getOrgUserId(); @@ -129,7 +131,7 @@ public class PolicyRestController extends RestrictedBaseController{ policyData.setDomainDir(dirName + root.get(PolicyController.getPolicydata()).get(modal).get("name").toString().replace("\"", "")); } }else{ - String domain = root.get(PolicyController.getPolicydata()).get("model").get("name").toString(); + String domain = root.get(PolicyController.getPolicydata()).get(modal).get("name").toString(); if(domain.contains("/")){ domain = domain.substring(0, domain.lastIndexOf('/')).replace("/", File.separator); } @@ -139,14 +141,11 @@ public class PolicyRestController extends RestrictedBaseController{ if(policyData.getConfigPolicyType() != null){ if("ClosedLoop_Fault".equalsIgnoreCase(policyData.getConfigPolicyType())){ - CreateClosedLoopFaultController faultController = new CreateClosedLoopFaultController(); - policyData = faultController.setDataToPolicyRestAdapter(policyData, root); + policyData = new CreateClosedLoopFaultController().setDataToPolicyRestAdapter(policyData, root); }else if("Firewall Config".equalsIgnoreCase(policyData.getConfigPolicyType())){ - CreateFirewallController fwController = new CreateFirewallController(); - policyData = fwController.setDataToPolicyRestAdapter(policyData); + policyData = new CreateFirewallController().setDataToPolicyRestAdapter(policyData); }else if("Micro Service".equalsIgnoreCase(policyData.getConfigPolicyType())){ - CreateDcaeMicroServiceController msController = new CreateDcaeMicroServiceController(); - policyData = msController.setDataToPolicyRestAdapter(policyData, root); + policyData = new CreateDcaeMicroServiceController().setDataToPolicyRestAdapter(policyData, root); } } @@ -370,7 +369,7 @@ public class PolicyRestController extends RestrictedBaseController{ @RequestMapping(value={"/getDictionary/*"}, method={RequestMethod.GET}) public void getDictionaryController(HttpServletRequest request, HttpServletResponse response){ String uri = request.getRequestURI().replace("/getDictionary", ""); - String body = null; + String body; ResponseEntity responseEntity = sendToPAP(null, uri, HttpMethod.GET); if(responseEntity != null){ body = responseEntity.getBody().toString(); @@ -385,7 +384,7 @@ public class PolicyRestController extends RestrictedBaseController{ } @RequestMapping(value={"/saveDictionary/*/*"}, method={RequestMethod.POST}) - public ModelAndView saveDictionaryController(HttpServletRequest request, HttpServletResponse response) throws IOException{ + public void saveDictionaryController(HttpServletRequest request, HttpServletResponse response) throws IOException{ String userId = ""; String uri = request.getRequestURI().replace("/saveDictionary", ""); if(uri.startsWith("/")){ @@ -402,12 +401,15 @@ public class PolicyRestController extends RestrictedBaseController{ policyLogger.info("***********************************************************************************************************************************"); String body = callPAP(request, "POST", uri.replaceFirst("/", "").trim()); - response.getWriter().write(body); - return null; + if(body != null && !body.isEmpty()){ + response.getWriter().write(body); + }else{ + response.getWriter().write("Failed"); + } } @RequestMapping(value={"/deleteDictionary/*/*"}, method={RequestMethod.POST}) - public ModelAndView deletetDictionaryController(HttpServletRequest request, HttpServletResponse response) throws IOException { + public void deletetDictionaryController(HttpServletRequest request, HttpServletResponse response) throws IOException { String uri = request.getRequestURI().replace("/deleteDictionary", ""); if(uri.startsWith("/")){ uri = uri.substring(uri.indexOf('/')+1); @@ -420,13 +422,16 @@ public class PolicyRestController extends RestrictedBaseController{ policyLogger.info("*************************************************************************************************************************************"); String body = callPAP(request, "POST", uri.replaceFirst("/", "").trim()); - response.getWriter().write(body); - return null; + if(body != null && !body.isEmpty()){ + response.getWriter().write(body); + }else{ + response.getWriter().write("Failed"); + } } @RequestMapping(value={"/searchDictionary"}, method={RequestMethod.POST}) public ModelAndView searchDictionaryController(HttpServletRequest request, HttpServletResponse response) throws IOException { - Object resultList = null; + Object resultList; String uri = request.getRequestURI(); if(uri.startsWith("/")){ uri = uri.substring(uri.indexOf('/')+1); @@ -459,7 +464,7 @@ public class PolicyRestController extends RestrictedBaseController{ @RequestMapping(value={"/searchPolicy"}, method={RequestMethod.POST}) public ModelAndView searchPolicy(HttpServletRequest request, HttpServletResponse response) throws IOException{ - Object resultList = null; + Object resultList; String uri = request.getRequestURI()+"?action=search"; if(uri.startsWith("/")){ uri = uri.substring(uri.indexOf('/')+1); @@ -472,7 +477,9 @@ public class PolicyRestController extends RestrictedBaseController{ resultList = json.get("policyresult"); }catch(Exception e){ List data = new ArrayList<>(); - data.add("Elastic Search Server is down"); + resultList = json.get("data"); + data.add("Exception"); + data.add(resultList.toString()); resultList = data; policyLogger.error("Exception Occured while searching for Policy in Elastic Database" +e); } @@ -491,5 +498,10 @@ public class PolicyRestController extends RestrictedBaseController{ String uri = "searchPolicy?action=delete&policyName='"+fileName+"'"; callPAP(null, "POST", uri.trim()); } + + public String notifyOtherPAPSToUpdateConfigurations(String mode, String newName, String oldName){ + String uri = "onap/notifyOtherPAPs?action="+mode+"&newPolicyName="+newName+"&oldPolicyName="+oldName+""; + return callPAP(null, "POST", uri.trim()); + } -} \ No newline at end of file +}