public class PolicyManagerServlet extends HttpServlet {
private static final Logger LOGGER = FlexLogger.getLogger(PolicyManagerServlet.class);
private static final long serialVersionUID = -8453502699403909016L;
+ private static final String VERSION = "version";;
+ private static final String NAME = "name";
+ private static final String DATE = "date";
+ private static final String SIZE = "size";
+ private static final String TYPE = "type";
+ private static final String CREATED_BY = "createdBy";
+ private static final String MODIFIED_BY = "modifiedBy";
private enum Mode {
LIST, RENAME, COPY, DELETE, EDITFILE, ADDFOLDER, DESCRIBEPOLICYFILE, VIEWPOLICY, ADDSUBSCOPE, SWITCHVERSION, EXPORT, SEARCHLIST
//Policy Import Functionality
private void uploadFile(HttpServletRequest request, HttpServletResponse response) throws ServletException {
try {
- String newFile;
Map<String, InputStream> files = new HashMap<>();
List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
}
private JSONObject searchPolicyList(JSONObject params, HttpServletRequest request) {
- Set<String> scopes;
- List<String> roles;
List<Object> policyData = new ArrayList<>();
JSONArray policyList = null;
if(params.has("policyList")){
PolicyController controller = getPolicyControllerInstance();
List<JSONObject> resultList = new ArrayList<>();
try {
- //Get the Login Id of the User from Request
- String userId = UserUtils.getUserSession(request).getOrgUserId();
- List<Object> userRoles = controller.getRoles(userId);
- Pair<Set<String>, List<String>> pair = org.onap.policy.utils.UserUtils.checkRoleAndScope(userRoles);
- roles = pair.u;
- scopes = pair.t;
- if (roles.contains(ADMIN) || roles.contains(EDITOR) || roles.contains(GUEST) ) {
- if(scopes.isEmpty()){
- return error("No Scopes has been Assigned to the User. Please, Contact Super-Admin");
- }
- Set<String> tempScopes = scopes;
- for(String scope : tempScopes){
- addScope(scopes, scope);
- }
+ if (!lookupPolicyData(request, policyData, policyList, controller, resultList))
+ return error("No Scopes has been Assigned to the User. Please, Contact Super-Admin");
+
+ }catch(Exception e){
+ LOGGER.error("Exception occured while reading policy Data from Policy Version table for Policy Search Data"+e);
+ }
+
+ return new JSONObject().put(RESULT, resultList);
+ }
+
+ private boolean lookupPolicyData(HttpServletRequest request, List<Object> policyData, JSONArray policyList, PolicyController controller, List<JSONObject> resultList) throws ServletException {
+ List<String> roles;
+ Set<String> scopes;//Get the Login Id of the User from Request
+ String userId = UserUtils.getUserSession(request).getOrgUserId();
+ List<Object> userRoles = controller.getRoles(userId);
+ Pair<Set<String>, List<String>> pair = org.onap.policy.utils.UserUtils.checkRoleAndScope(userRoles);
+ roles = pair.u;
+ scopes = pair.t;
+ if (roles.contains(ADMIN) || roles.contains(EDITOR) || roles.contains(GUEST) ) {
+ if(scopes.isEmpty()){
+ return false;
}
- if(policyList!= null){
- for(int i = 0; i < policyList.length(); i++){
- String policyName = policyList.get(i).toString().replace(".xml", "");
- String version = policyName.substring(policyName.lastIndexOf('.')+1);
- policyName = policyName.substring(0, policyName.lastIndexOf('.')).replace(".", File.separator);
- parsePolicyList(resultList, controller, policyName, version);
- }
+ Set<String> tempScopes = scopes;
+ for(String scope : tempScopes){
+ addScope(scopes, scope);
+ }
+ }
+ if(policyList!= null){
+ for(int i = 0; i < policyList.length(); i++){
+ String policyName = policyList.get(i).toString().replace(".xml", "");
+ String version = policyName.substring(policyName.lastIndexOf('.')+1);
+ policyName = policyName.substring(0, policyName.lastIndexOf('.')).replace(".", File.separator);
+ parsePolicyList(resultList, controller, policyName, version);
+ }
+ }else{
+ if (roles.contains(SUPERADMIN) || roles.contains(SUPEREDITOR) || roles.contains(SUPERGUEST) ){
+ policyData = controller.getData(PolicyVersion.class);
}else{
- if (roles.contains(SUPERADMIN) || roles.contains(SUPEREDITOR) || roles.contains(SUPERGUEST) ){
- policyData = controller.getData(PolicyVersion.class);
- }else{
- List<Object> filterdatas = controller.getData(PolicyVersion.class);
- for(Object filter : filterdatas){
- PolicyVersion filterdata = (PolicyVersion) filter;
- try{
- String scopeName = filterdata.getPolicyName().substring(0, filterdata.getPolicyName().lastIndexOf(File.separator));
- if(scopes.contains(scopeName)){
- policyData.add(filterdata);
- }
- }catch(Exception e){
- LOGGER.error("Exception occured while filtering policyversion data"+e);
- }
- }
+ List<Object> filterdatas = controller.getData(PolicyVersion.class);
+ for(Object filter : filterdatas) {
+ addFilterData(policyData, scopes, (PolicyVersion) filter);
}
+ }
- if(!policyData.isEmpty()){
- updateResultList(policyData, resultList);
- }
+ if(!policyData.isEmpty()){
+ updateResultList(policyData, resultList);
}
- }catch(Exception e){
- LOGGER.error("Exception occured while reading policy Data from Policy Version table for Policy Search Data"+e);
}
+ return true;
+ }
- return new JSONObject().put(RESULT, resultList);
+ private void addFilterData(List<Object> policyData, Set<String> scopes, PolicyVersion filter) {
+ try{
+ String scopeName = filter.getPolicyName().substring(0, filter.getPolicyName().lastIndexOf(File.separator));
+ if(scopes.contains(scopeName)){
+ policyData.add(filter);
+ }
+ }catch(Exception e){
+ LOGGER.error("Exception occured while filtering policyversion data"+e);
+ }
}
private void updateResultList(List<Object> policyData, List<JSONObject> resultList) {
for(int i =0; i < policyData.size(); i++){
PolicyVersion policy = (PolicyVersion) policyData.get(i);
JSONObject el = new JSONObject();
- el.put("name", policy.getPolicyName().replace(File.separator, "/"));
- el.put("date", policy.getModifiedDate());
- el.put("version", policy.getActiveVersion());
- el.put("size", "");
- el.put("type", "file");
- el.put("createdBy", getUserName(policy.getCreatedBy()));
- el.put("modifiedBy", getUserName(policy.getModifiedBy()));
+ el.put(NAME, policy.getPolicyName().replace(File.separator, "/"));
+ el.put(DATE, policy.getModifiedDate());
+ el.put(VERSION, policy.getActiveVersion());
+ el.put(SIZE, "");
+ el.put(TYPE, "file");
+ el.put(CREATED_BY, getUserName(policy.getCreatedBy()));
+ el.put(MODIFIED_BY, getUserName(policy.getModifiedBy()));
resultList.add(el);
}
}
String policyVersionQuery = "From PolicyVersion where policy_name = :policyName and active_version = :version and id >0";
SimpleBindings pvParams = new SimpleBindings();
pvParams.put("policyName", policyName);
- pvParams.put("version", version);
+ pvParams.put(VERSION, version);
List<Object> activeData = controller.getDataByQuery(policyVersionQuery, pvParams);
if(!activeData.isEmpty()){
PolicyVersion policy = (PolicyVersion) activeData.get(0);
JSONObject el = new JSONObject();
- el.put("name", policy.getPolicyName().replace(File.separator, "/"));
- el.put("date", policy.getModifiedDate());
- el.put("version", policy.getActiveVersion());
- el.put("size", "");
- el.put("type", "file");
- el.put("createdBy", getUserName(policy.getCreatedBy()));
- el.put("modifiedBy", getUserName(policy.getModifiedBy()));
+ el.put(NAME, policy.getPolicyName().replace(File.separator, "/"));
+ el.put(DATE, policy.getModifiedDate());
+ el.put(VERSION, policy.getActiveVersion());
+ el.put(SIZE, "");
+ el.put(TYPE, "file");
+ el.put(CREATED_BY, getUserName(policy.getCreatedBy()));
+ el.put(MODIFIED_BY, getUserName(policy.getModifiedBy()));
resultList.add(el);
}
}
//Get the List of Policies and Scopes for Showing in Editor tab
private JSONObject list(JSONObject params, HttpServletRequest request) throws ServletException {
- Set<String> scopes = null;
- List<String> roles = null;
try {
- PolicyController controller = getPolicyControllerInstance();
- //Get the Login Id of the User from Request
- String testUserID = getTestUserId();
- String userId = testUserID != null ? testUserID : UserUtils.getUserSession(request).getOrgUserId();
- List<Object> userRoles = controller.getRoles(userId);
- Pair<Set<String>, List<String>> pair = org.onap.policy.utils.UserUtils.checkRoleAndScope(userRoles);
- roles = pair.u;
- scopes = pair.t;
-
- List<JSONObject> resultList = new ArrayList<>();
- boolean onlyFolders = params.getBoolean("onlyFolders");
- String path = params.getString("path");
- if(path.contains("..xml")){
- path = path.replaceAll("..xml", "").trim();
- }
+ return processPolicyList(params, request);
+ } catch (Exception e) {
+ LOGGER.error("list", e);
+ return error(e.getMessage());
+ }
+ }
- if (roles.contains(ADMIN) || roles.contains(EDITOR) || roles.contains(GUEST) ) {
- if(scopes.isEmpty()){
- return error("No Scopes has been Assigned to the User. Please, Contact Super-Admin");
- }else{
- if(!"/".equals(path)){
- String tempScope = path.substring(1, path.length());
- tempScope = tempScope.replace("/", File.separator);
- scopes.add(tempScope);
- }
- }
- }
+ private JSONObject processPolicyList(JSONObject params, HttpServletRequest request) throws ServletException {
+ List<String> roles;
+ Set<String> scopes;PolicyController controller = getPolicyControllerInstance();
+ //Get the Login Id of the User from Request
+ String testUserID = getTestUserId();
+ String userId = testUserID != null ? testUserID : UserUtils.getUserSession(request).getOrgUserId();
+ List<Object> userRoles = controller.getRoles(userId);
+ Pair<Set<String>, List<String>> pair = org.onap.policy.utils.UserUtils.checkRoleAndScope(userRoles);
+ roles = pair.u;
+ scopes = pair.t;
- if("/".equals(path)){
- if(roles.contains(SUPERADMIN) || roles.contains(SUPEREDITOR) || roles.contains(SUPERGUEST)){
- List<Object> scopesList = queryPolicyEditorScopes(null);
- for(Object list : scopesList){
- PolicyEditorScopes scope = (PolicyEditorScopes) list;
- if(!(scope.getScopeName().contains(File.separator))){
- JSONObject el = new JSONObject();
- el.put("name", scope.getScopeName());
- el.put("date", scope.getModifiedDate());
- el.put("size", "");
- el.put("type", "dir");
- el.put("createdBy", scope.getUserCreatedBy().getUserName());
- el.put("modifiedBy", scope.getUserModifiedBy().getUserName());
- resultList.add(el);
- }
- }
- }else if(roles.contains(ADMIN) || roles.contains(EDITOR) || roles.contains(GUEST)){
- for(Object scope : scopes){
- JSONObject el = new JSONObject();
- List<Object> scopesList = queryPolicyEditorScopes(scope.toString());
- if(!scopesList.isEmpty()){
- PolicyEditorScopes scopeById = (PolicyEditorScopes) scopesList.get(0);
- el.put("name", scopeById.getScopeName());
- el.put("date", scopeById.getModifiedDate());
- el.put("size", "");
- el.put("type", "dir");
- el.put("createdBy", scopeById.getUserCreatedBy().getUserName());
- el.put("modifiedBy", scopeById.getUserModifiedBy().getUserName());
- resultList.add(el);
- }
- }
- }
+ List<JSONObject> resultList = new ArrayList<>();
+ boolean onlyFolders = params.getBoolean("onlyFolders");
+ String path = params.getString("path");
+ if(path.contains("..xml")){
+ path = path.replaceAll("..xml", "").trim();
+ }
+
+ if (roles.contains(ADMIN) || roles.contains(EDITOR) || roles.contains(GUEST) ) {
+ if(scopes.isEmpty()){
+ return error("No Scopes has been Assigned to the User. Please, Contact Super-Admin");
}else{
- try{
- String scopeName = path.substring(path.indexOf('/') +1);
- activePolicyList(scopeName, resultList, roles, scopes, onlyFolders);
- } catch (Exception ex) {
- LOGGER.error("Error Occured While reading Policy Files List"+ex );
+ if(!"/".equals(path)){
+ String tempScope = path.substring(1, path.length());
+ tempScope = tempScope.replace("/", File.separator);
+ scopes.add(tempScope);
}
}
+ }
+ if (!"/".equals(path)) {
+ try{
+ String scopeName = path.substring(path.indexOf('/') +1);
+ activePolicyList(scopeName, resultList, roles, scopes, onlyFolders);
+ } catch (Exception ex) {
+ LOGGER.error("Error Occured While reading Policy Files List"+ex );
+ }
return new JSONObject().put(RESULT, resultList);
- } catch (Exception e) {
- LOGGER.error("list", e);
- return error(e.getMessage());
+ }
+
+ processRoles(scopes, roles, resultList);
+
+ return new JSONObject().put(RESULT, resultList);
+ }
+
+ private void processRoles(Set<String> scopes, List<String> roles, List<JSONObject> resultList) {
+ if(roles.contains(SUPERADMIN) || roles.contains(SUPEREDITOR) || roles.contains(SUPERGUEST)){
+ List<Object> scopesList = queryPolicyEditorScopes(null);
+ for(Object list : scopesList){
+ PolicyEditorScopes scope = (PolicyEditorScopes) list;
+ if(!(scope.getScopeName().contains(File.separator))){
+ JSONObject el = new JSONObject();
+ el.put(NAME, scope.getScopeName());
+ el.put(DATE, scope.getModifiedDate());
+ el.put(SIZE, "");
+ el.put(TYPE, "dir");
+ el.put(CREATED_BY, scope.getUserCreatedBy().getUserName());
+ el.put(MODIFIED_BY, scope.getUserModifiedBy().getUserName());
+ resultList.add(el);
+ }
+ }
+ }else if(roles.contains(ADMIN) || roles.contains(EDITOR) || roles.contains(GUEST)){
+ for(Object scope : scopes){
+ JSONObject el = new JSONObject();
+ List<Object> scopesList = queryPolicyEditorScopes(scope.toString());
+ if(!scopesList.isEmpty()){
+ PolicyEditorScopes scopeById = (PolicyEditorScopes) scopesList.get(0);
+ el.put(NAME, scopeById.getScopeName());
+ el.put(DATE, scopeById.getModifiedDate());
+ el.put(SIZE, "");
+ el.put(TYPE, "dir");
+ el.put(CREATED_BY, scopeById.getUserCreatedBy().getUserName());
+ el.put(MODIFIED_BY, scopeById.getUserModifiedBy().getUserName());
+ resultList.add(el);
+ }
+ }
}
}
activePolicies = controller.getDataByQuery(query, params);
scopesList = controller.getDataByQuery(scopeNamequery, params);
}
- for(Object list : scopesList){
- PolicyEditorScopes scopeById = (PolicyEditorScopes) list;
- String scope = scopeById.getScopeName();
- if(scope.contains(File.separator)){
- String checkScope = scope.substring(0, scope.lastIndexOf(File.separator));
- if(scopeName.contains("\\\\")){
- scopeName = scopeName.replace("\\\\", File.separator);
- }
- if(scope.contains(File.separator)){
- scope = scope.substring(checkScope.length()+1);
- if(scope.contains(File.separator)){
- scope = scope.substring(0, scope.indexOf(File.separator));
- }
- }
- if(scopeName.equalsIgnoreCase(checkScope)){
- JSONObject el = new JSONObject();
- el.put("name", scope);
- el.put("date", scopeById.getModifiedDate());
- el.put("size", "");
- el.put("type", "dir");
- el.put("createdBy", scopeById.getUserCreatedBy().getUserName());
- el.put("modifiedBy", scopeById.getUserModifiedBy().getUserName());
- resultList.add(el);
- }
- }
+ for(Object list : scopesList) {
+ scopeName = checkScope(resultList, scopeName, (PolicyEditorScopes) list);
}
String scopeNameCheck;
for (Object list : activePolicies) {
}
if(scopeNameValue.equals(scopeNameCheck)){
JSONObject el = new JSONObject();
- el.put("name", policy.getPolicyName().substring(policy.getPolicyName().lastIndexOf(File.separator)+1));
- el.put("date", policy.getModifiedDate());
- el.put("version", policy.getActiveVersion());
- el.put("size", "");
- el.put("type", "file");
- el.put("createdBy", getUserName(policy.getCreatedBy()));
- el.put("modifiedBy", getUserName(policy.getModifiedBy()));
+ el.put(NAME, policy.getPolicyName().substring(policy.getPolicyName().lastIndexOf(File.separator)+1));
+ el.put(DATE, policy.getModifiedDate());
+ el.put(VERSION, policy.getActiveVersion());
+ el.put(SIZE, "");
+ el.put(TYPE, "file");
+ el.put(CREATED_BY, getUserName(policy.getCreatedBy()));
+ el.put(MODIFIED_BY, getUserName(policy.getModifiedBy()));
resultList.add(el);
}
}else if(!scopes.isEmpty() && scopes.contains(scopeNameValue)){
JSONObject el = new JSONObject();
- el.put("name", policy.getPolicyName().substring(policy.getPolicyName().lastIndexOf(File.separator)+1));
- el.put("date", policy.getModifiedDate());
- el.put("version", policy.getActiveVersion());
- el.put("size", "");
- el.put("type", "file");
- el.put("createdBy", getUserName(policy.getCreatedBy()));
- el.put("modifiedBy", getUserName(policy.getModifiedBy()));
+ el.put(NAME, policy.getPolicyName().substring(policy.getPolicyName().lastIndexOf(File.separator)+1));
+ el.put(DATE, policy.getModifiedDate());
+ el.put(VERSION, policy.getActiveVersion());
+ el.put(SIZE, "");
+ el.put(TYPE, "file");
+ el.put(CREATED_BY, getUserName(policy.getCreatedBy()));
+ el.put(MODIFIED_BY, getUserName(policy.getModifiedBy()));
resultList.add(el);
}
}
}
+ private String checkScope(List<JSONObject> resultList, String scopeName, PolicyEditorScopes scopeById) {
+ String scope = scopeById.getScopeName();
+ if(scope.contains(File.separator)){
+ String targetScope = scope.substring(0, scope.lastIndexOf(File.separator));
+ if(scopeName.contains("\\\\")){
+ scopeName = scopeName.replace("\\\\", File.separator);
+ }
+ if(scope.contains(File.separator)){
+ scope = scope.substring(targetScope.length()+1);
+ if(scope.contains(File.separator)){
+ scope = scope.substring(0, scope.indexOf(File.separator));
+ }
+ }
+ if(scopeName.equalsIgnoreCase(targetScope)){
+ JSONObject el = new JSONObject();
+ el.put(NAME, scope);
+ el.put(DATE, scopeById.getModifiedDate());
+ el.put(SIZE, "");
+ el.put(TYPE, "dir");
+ el.put(CREATED_BY, scopeById.getUserCreatedBy().getUserName());
+ el.put(MODIFIED_BY, scopeById.getUserModifiedBy().getUserName());
+ resultList.add(el);
+ }
+ }
+ return scopeName;
+ }
+
private String getUserName(String loginId){
PolicyController controller = getPolicyControllerInstance();
UserInfo userInfo = (UserInfo) controller.getEntityItem(UserInfo.class, "userLoginId", loginId);
//Rename Policy
private JSONObject rename(JSONObject params, HttpServletRequest request) throws ServletException {
try {
- 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 = 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);
+ return handlePolicyRename(params, request);
+ } catch (Exception e) {
+ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Exception Occured While Renaming Policy"+e);
+ return error(e.getMessage());
+ }
+ }
+
+ 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 = 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;
+ }
+ }else{
+ String scopeName = oldPath;
+ String newScopeName = newPath;
+ if(scopeName.contains("/")){
+ scopeName = scopeName.replace("/", File.separator);
+ newScopeName = newScopeName.replace("/", File.separator);
+ }
+ 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";
+ SimpleBindings pvParams = new SimpleBindings();
+ pvParams.put("scopeName", 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, "/") + "." + activeVersion.getActiveVersion() + ".xml";
+ String policyNewPath = policyOldPath.replace(oldPath, newPath);
+ JSONObject result = policyRename(policyOldPath, policyNewPath, userId);
if(!(Boolean)(result.getJSONObject("result").get("success"))){
- return result;
- }
- }else{
- String scopeName = oldPath;
- String newScopeName = newPath;
- if(scopeName.contains("/")){
- scopeName = scopeName.replace("/", File.separator);
- newScopeName = newScopeName.replace("/", File.separator);
- }
- 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";
- SimpleBindings pvParams = new SimpleBindings();
- pvParams.put("scopeName", 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, "/") + "." + 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("/", File.separator));
- }
- }
- boolean rename = false;
- if(activePolicies.size() != policyActiveInPDP.size()){
- rename = true;
+ isActive = true;
+ policyActiveInPDP.add(policyOldPath);
+ String scope = policyOldPath.substring(0, policyOldPath.lastIndexOf('/'));
+ scopeOfPolicyActiveInPDP.add(scope.replace("/", File.separator));
}
+ }
+ boolean rename = false;
+ if(activePolicies.size() != policyActiveInPDP.size()){
+ rename = true;
+ }
- 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);
- }
- }
- if(isActive){
- return error("The Following policies rename failed. Since they are active in PDP Groups" +policyActiveInPDP);
+ 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);
}
}
- return success();
- } catch (Exception e) {
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Exception Occured While Renaming Policy"+e);
- return error(e.getMessage());
+ if(isActive){
+ return error("The Following policies rename failed. Since they are active in PDP Groups" +policyActiveInPDP);
+ }
}
+ return success();
}
private void renameScope(List<Object> scopesList, String inScopeName, String newScopeName, PolicyController controller){
name = params.getString("path").replace("/", File.separator) + File.separator +params.getString("subScopename");
}
}else{
- name = params.getString("name");
+ name = params.getString(NAME);
}
}catch(Exception e){
- name = params.getString("name");
+ name = params.getString(NAME);
LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Exception Occured While Adding Scope"+e);
}
String validateName;