+ private JSONObject handlePolicyRename(JSONObject params, HttpServletRequest request) throws ServletException {
+ boolean isActive = false;
+ List<String> policyActiveInPdp = new ArrayList<>();
+ Set<String> scopeOfPolicyActiveInPdp = new HashSet<>();
+ String userId = UserUtils.getUserSession(request).getOrgUserId();
+ String oldPath = params.getString("path");
+ String newPath = params.getString("newPath");
+ oldPath = oldPath.substring(oldPath.indexOf('/') + 1);
+ newPath = newPath.substring(newPath.indexOf('/') + 1);
+ String checkValidation;
+ if (oldPath.endsWith(".xml")) {
+ checkValidation = newPath.replace(".xml", "");
+ checkValidation =
+ checkValidation.substring(checkValidation.indexOf('_') + 1, checkValidation.lastIndexOf('.'));
+ checkValidation = checkValidation.substring(checkValidation.lastIndexOf(FORWARD_SLASH) + 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;
+ }
+ } else {
+ String scopeName = oldPath;
+ String newScopeName = newPath;
+ if (scopeName.contains(FORWARD_SLASH)) {
+ scopeName = scopeName.replace(FORWARD_SLASH, File.separator);
+ newScopeName = newScopeName.replace(FORWARD_SLASH, File.separator);
+ }
+ checkValidation = newScopeName.substring(newScopeName.lastIndexOf(File.separator) + 1);
+ if (scopeName.contains(BACKSLASH)) {
+ scopeName = scopeName.replace(BACKSLASH, BACKSLASH_8TIMES);
+ newScopeName = newScopeName.replace(BACKSLASH, BACKSLASH_8TIMES);
+ }
+ 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";
+ SimpleBindings pvParams = new SimpleBindings();
+ pvParams.put(SCOPE_NAME, scopeName + "%");
+ List<Object> activePolicies = controller.getDataByQuery(query, pvParams);
+ List<Object> scopesList =
+ controller.getDataByQuery(FROM_POLICY_EDITOR_SCOPES_WHERE_SCOPENAME_LIKE_SCOPE_NAME, pvParams);
+ for (Object object : activePolicies) {
+ PolicyVersion activeVersion = (PolicyVersion) object;
+ String policyOldPath = activeVersion.getPolicyName().replace(File.separator, FORWARD_SLASH) + "."
+ + activeVersion.getActiveVersion() + ".xml";
+ String policyNewPath = policyOldPath.replace(oldPath, newPath);
+ JSONObject result = policyRename(policyOldPath, policyNewPath, userId);
+ if (!(Boolean) (result.getJSONObject("result").get(SUCCESS))) {
+ isActive = true;
+ policyActiveInPdp.add(policyOldPath);
+ String scope = policyOldPath.substring(0, policyOldPath.lastIndexOf('/'));
+ scopeOfPolicyActiveInPdp.add(scope.replace(FORWARD_SLASH, File.separator));
+ }
+ }
+ boolean rename = activePolicies.size() != policyActiveInPdp.size();
+ if (policyActiveInPdp.isEmpty()) {
+ renameScope(scopesList, scopeName, newScopeName, controller);
+ } else if (rename) {
+ renameScope(scopesList, scopeName, newScopeName, controller);