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=8df9d1b89f24d9394f00f95f1d683af5de0ad3b5;hb=2db31606da32d9f5d3a16854385de8e496cd28f6;hp=63d0cb29899f1cde3ddbfc0fe0b33b8cc4a54753;hpb=c579209f8a4045d7f96f2b566a82ce1b8cf8660d;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 63d0cb298..8df9d1b89 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. @@ -45,6 +45,7 @@ import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.controller.CreateClosedLoopFaultController; import org.onap.policy.controller.CreateDcaeMicroServiceController; import org.onap.policy.controller.CreateFirewallController; +import org.onap.policy.controller.CreateOptimizationController; import org.onap.policy.controller.PolicyController; import org.onap.policy.rest.XACMLRestProperties; import org.onap.policy.rest.adapter.PolicyRestAdapter; @@ -66,7 +67,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; import org.springframework.web.servlet.ModelAndView; - +import org.onap.policy.utils.CryptoUtils; import com.att.research.xacml.util.XACMLProperties; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; @@ -79,7 +80,7 @@ public class PolicyRestController extends RestrictedBaseController{ private static final Logger policyLogger = FlexLogger.getLogger(PolicyRestController.class); - private static final String modal = "model"; + private static final String model = "model"; private static final String importDictionary = "import_dictionary"; private static CommonClassDao commonClassDao; @@ -117,21 +118,21 @@ public class PolicyRestController extends RestrictedBaseController{ PolicyRestAdapter policyData = mapper.readValue(root.get(PolicyController.getPolicydata()).get("policy").toString(), PolicyRestAdapter.class); - if("file".equals(root.get(PolicyController.getPolicydata()).get(modal).get("type").toString().replace("\"", ""))){ + if("file".equals(root.get(PolicyController.getPolicydata()).get(model).get("type").toString().replace("\"", ""))){ policyData.setEditPolicy(true); } - if(root.get(PolicyController.getPolicydata()).get(modal).get("path").size() != 0){ + if(root.get(PolicyController.getPolicydata()).get(model).get("path").size() != 0){ String dirName = ""; - for(int i = 0; i < root.get(PolicyController.getPolicydata()).get(modal).get("path").size(); i++){ - dirName = dirName.replace("\"", "") + root.get(PolicyController.getPolicydata()).get(modal).get("path").get(i).toString().replace("\"", "") + File.separator; + for(int i = 0; i < root.get(PolicyController.getPolicydata()).get(model).get("path").size(); i++){ + dirName = dirName.replace("\"", "") + root.get(PolicyController.getPolicydata()).get(model).get("path").get(i).toString().replace("\"", "") + File.separator; } if(policyData.isEditPolicy()){ policyData.setDomainDir(dirName.substring(0, dirName.lastIndexOf(File.separator))); }else{ - policyData.setDomainDir(dirName + root.get(PolicyController.getPolicydata()).get(modal).get("name").toString().replace("\"", "")); + policyData.setDomainDir(dirName + root.get(PolicyController.getPolicydata()).get(model).get("name").toString().replace("\"", "")); } }else{ - String domain = root.get(PolicyController.getPolicydata()).get(modal).get("name").toString(); + String domain = root.get(PolicyController.getPolicydata()).get(model).get("name").toString(); if(domain.contains("/")){ domain = domain.substring(0, domain.lastIndexOf('/')).replace("/", File.separator); } @@ -146,6 +147,8 @@ public class PolicyRestController extends RestrictedBaseController{ policyData = new CreateFirewallController().setDataToPolicyRestAdapter(policyData); }else if("Micro Service".equalsIgnoreCase(policyData.getConfigPolicyType())){ policyData = new CreateDcaeMicroServiceController().setDataToPolicyRestAdapter(policyData, root); + }else if("Optimization".equalsIgnoreCase(policyData.getConfigPolicyType())){ + policyData = new CreateOptimizationController().setDataToPolicyRestAdapter(policyData, root); } } @@ -195,7 +198,7 @@ public class PolicyRestController extends RestrictedBaseController{ private ResponseEntity sendToPAP(String body, String requestURI, HttpMethod method){ String papUrl = PolicyController.getPapUrl(); String papID = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_USERID); - String papPass = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS); + String papPass = CryptoUtils.decryptTxtNoExStr(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS)); Base64.Encoder encoder = Base64.getEncoder(); String encoding = encoder.encodeToString((papID+":"+papPass).getBytes(StandardCharsets.UTF_8)); @@ -245,7 +248,7 @@ public class PolicyRestController extends RestrictedBaseController{ String boundary = null; String papUrl = PolicyController.getPapUrl(); String papID = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_USERID); - String papPass = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS); + String papPass = CryptoUtils.decryptTxtNoExStr(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS)); Base64.Encoder encoder = Base64.getEncoder(); String encoding = encoder.encodeToString((papID+":"+papPass).getBytes(StandardCharsets.UTF_8)); @@ -384,7 +387,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("/")){ @@ -401,12 +404,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); @@ -419,8 +425,11 @@ 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}) @@ -471,7 +480,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); } @@ -490,5 +501,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()); + } }