- UserInfo userInfo = new UserInfo();
- userInfo.setUserLoginId(userId);
- if(policyActiveInPDP.isEmpty()){
- renameScope(scopesList, scopeName, newScopeName, controller);
- }else if(rename){
- renameScope(scopesList, scopeName, newScopeName, controller);
- for(String scope : scopeOfPolicyActiveInPDP){
- PolicyEditorScopes editorScopeEntity = new PolicyEditorScopes();
- editorScopeEntity.setScopeName(scope.replace("\\", "\\\\\\\\"));
- editorScopeEntity.setUserCreatedBy(userInfo);
- editorScopeEntity.setUserModifiedBy(userInfo);
- controller.saveData(editorScopeEntity);
- }
+ 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";
+ String scopeNamequery = FROM_POLICY_EDITOR_SCOPES_WHERE_SCOPENAME_LIKE_SCOPE_NAME;
+ SimpleBindings pvParams = new SimpleBindings();
+ pvParams.put(SCOPE_NAME, scopeName + "%");
+ List<Object> activePolicies = controller.getDataByQuery(query, pvParams);
+ List<Object> scopesList = controller.getDataByQuery(scopeNamequery, 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));