+ private JSONObject searchPolicyList(JSONObject params, HttpServletRequest request) {
+ Set<String> scopes = null;
+ List<String> roles = null;
+ policyData = null;
+ JSONArray policyList = null;
+ if(params.has("policyList")){
+ policyList = (JSONArray) params.get("policyList");
+ }
+ PolicyController controller = new PolicyController();
+ List<JSONObject> resultList = new ArrayList<JSONObject>();
+ try {
+ //Get the Login Id of the User from Request
+ String userId = UserUtils.getUserSession(request).getOrgUserId();
+ //Check if the Role and Scope Size are Null get the values from db.
+ List<Object> userRoles = PolicyController.getRoles(userId);
+ roles = new ArrayList<String>();
+ scopes = new HashSet<String>();
+ for(Object role: userRoles){
+ Roles userRole = (Roles) role;
+ roles.add(userRole.getRole());
+ if(userRole.getScope() != null){
+ if(userRole.getScope().contains(",")){
+ String[] multipleScopes = userRole.getScope().split(",");
+ for(int i =0; i < multipleScopes.length; i++){
+ scopes.add(multipleScopes[i]);
+ }
+ }else{
+ scopes.add(userRole.getScope());
+ }
+ }
+ }
+ 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");
+ }
+ }
+ 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);
+ if(policyName.contains("\\")){
+ policyName = policyName.replace("\\", "\\\\");
+ }
+ String policyVersionQuery = "From PolicyVersion where policy_name ='"+policyName+"' and active_version = '"+version+"'and id >0";
+ List<Object> activeData = controller.getDataByQuery(policyVersionQuery);
+ 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()));
+ resultList.add(el);
+ }
+ }
+ }else{
+ if (roles.contains("super-admin") || roles.contains("super-editor") || roles.contains("super-guest") ){
+ policyData = controller.getData(PolicyVersion.class);
+ }else{
+ List<Object> filterdatas = controller.getData(PolicyVersion.class);
+ for(Object filter : filterdatas){
+ PolicyVersion filterdata = (PolicyVersion) filter;
+ String scopeName = filterdata.getPolicyName().substring(0, filterdata.getPolicyName().lastIndexOf(File.separator));
+ if(scopes.contains(scopeName)){
+ policyData.add(filterdata);
+ }
+ }
+ }
+
+ if(!policyData.isEmpty()){
+ 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()));
+ resultList.add(el);
+ }
+ }
+ }
+ }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);
+ }
+