X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fadmin%2FPolicyManagerServlet.java;fp=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fadmin%2FPolicyManagerServlet.java;h=9498529aff226e908c9432f0712d0e6e74a21434;hb=695d88bd7a987a06173fc4fa13f4135916a79a86;hp=16a8ff7a97021b057c5b5b8f2bf1fbeb2cb98897;hpb=6425d452d8507e9eeeb4da2f9f7051e602af541e;p=policy%2Fengine.git diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java index 16a8ff7a9..9498529af 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.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. @@ -653,7 +653,7 @@ public class PolicyManagerServlet extends HttpServlet { scopeName = scopeName.replace("/", File.separator); } if(scopeName.contains("\\")){ - scopeName = scopeName.replace("\\", "\\\\\\\\"); + scopeName = scopeName.replace("\\", "\\\\"); } String query = "from PolicyVersion where POLICY_NAME like :scopeName"; String scopeNamequery = "from PolicyEditorScopes where SCOPENAME like :scopeName"; @@ -751,7 +751,14 @@ public class PolicyManagerServlet extends HttpServlet { String newPath = params.getString("newPath"); oldPath = oldPath.substring(oldPath.indexOf('/')+1); newPath = newPath.substring(newPath.indexOf('/')+1); + String checkValidation = null; if(oldPath.endsWith(".xml")){ + checkValidation = newPath.replace(".xml", ""); + checkValidation = checkValidation.substring(checkValidation.indexOf('_') + 1, checkValidation.lastIndexOf(".")); + checkValidation = checkValidation.substring(checkValidation.lastIndexOf("/")+1); + if(!PolicyUtils.policySpecialCharValidator(checkValidation).contains("success")){ + return error("Policy Rename Failed. The Name contains special characters."); + } JSONObject result = policyRename(oldPath, newPath, userId); if(!(Boolean)(result.getJSONObject("result").get("success"))){ return result; @@ -763,10 +770,14 @@ public class PolicyManagerServlet extends HttpServlet { scopeName = scopeName.replace("/", File.separator); newScopeName = newScopeName.replace("/", File.separator); } - if(scopeName.contains("\\")){ - scopeName = scopeName.replace("\\", "\\\\\\\\"); - newScopeName = newScopeName.replace("\\", "\\\\\\\\"); - } + checkValidation = newScopeName.substring(newScopeName.lastIndexOf(File.separator)+1); + if(scopeName.contains("\\")){ + scopeName = scopeName.replace("\\", "\\\\\\\\"); + newScopeName = newScopeName.replace("\\", "\\\\\\\\"); + } + if(!PolicyUtils.policySpecialCharValidator(checkValidation).contains("success")){ + return error("Scope Rename Failed. The Name contains special characters."); + } PolicyController controller = getPolicyControllerInstance(); String query = "from PolicyVersion where POLICY_NAME like :scopeName"; String scopeNamequery = "from PolicyEditorScopes where SCOPENAME like :scopeName"; @@ -901,7 +912,12 @@ public class PolicyManagerServlet extends HttpServlet { } for(int i=0; i 1){ @@ -1262,7 +1302,12 @@ public class PolicyManagerServlet extends HttpServlet { entity.setModifiedBy(userId); controller.watchPolicyFunction(entity, policyNamewithExtension, "DeleteOne"); - String updatequery = "update PolicyVersion set active_version='"+highestVersion+"' , highest_version='"+highestVersion+"' where policy_name ='" +policyNamewithoutExtension.replace("\\", "\\\\")+"'"; + String updatequery = ""; + if(highestVersion != 0){ + updatequery = "update PolicyVersion set active_version='"+highestVersion+"' , highest_version='"+highestVersion+"' where policy_name ='" +policyNamewithoutExtension.replace("\\", "\\\\")+"'"; + }else{ + updatequery = "delete from PolicyVersion where policy_name ='" +policyNamewithoutExtension.replace("\\", "\\\\")+"' and id >0"; + } controller.executeQuery(updatequery); }else{ String policyVersionQuery = "delete from PolicyVersion where policy_name ='" +policyNamewithoutExtension.replace("\\", "\\\\")+"' and id >0"; @@ -1297,9 +1342,11 @@ public class PolicyManagerServlet extends HttpServlet { if(policyNamewithoutExtension.contains("Config_")){ Files.deleteIfExists(Paths.get(PolicyController.getConfigHome() + File.separator + policyEntity.getConfigurationData().getConfigurationName())); controller.deleteData(policyEntity.getConfigurationData()); + restController.notifyOtherPAPSToUpdateConfigurations("delete", null, policyEntity.getConfigurationData().getConfigurationName()); }else if(policyNamewithoutExtension.contains("Action_")){ Files.deleteIfExists(Paths.get(PolicyController.getActionHome() + File.separator + policyEntity.getActionBodyEntity().getActionBodyName())); controller.deleteData(policyEntity.getActionBodyEntity()); + restController.notifyOtherPAPSToUpdateConfigurations("delete", null, policyEntity.getActionBodyEntity().getActionBodyName()); } } }