Merge changes from topic '13891'
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / onap / policy / admin / PolicyManagerServlet.java
index b481714..4f42023 100644 (file)
@@ -91,6 +91,16 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 public class PolicyManagerServlet extends HttpServlet {
        private static final Logger LOGGER      = FlexLogger.getLogger(PolicyManagerServlet.class);
        private static final long serialVersionUID = -8453502699403909016L;
+       
+       private static boolean jUnit = false;
+
+       public static boolean isjUnit() {
+               return jUnit;
+       }
+
+       public static void setjUnit(boolean jUnit) {
+               PolicyManagerServlet.jUnit = jUnit;
+       }
 
        private enum Mode {
                LIST, RENAME, COPY, DELETE, EDITFILE, ADDFOLDER, DESCRIBEPOLICYFILE, VIEWPOLICY, ADDSUBSCOPE, SWITCHVERSION, EXPORT, SEARCHLIST
@@ -531,7 +541,12 @@ public class PolicyManagerServlet extends HttpServlet {
                SimpleBindings peParams = new SimpleBindings();
                peParams.put("split_1", split[1]);
                peParams.put("split_0", split[0]);
-               List<Object> queryData = controller.getDataByQuery(query, peParams);
+               List<Object> queryData = null;
+               if(jUnit){
+                       queryData = controller.getDataByQuery(query, null);
+               }else{
+                       queryData = controller.getDataByQuery(query, peParams);
+               }
                if(!queryData.isEmpty()){
                        PolicyEntity entity = (PolicyEntity) queryData.get(0);
                        File temp = null;
@@ -668,7 +683,12 @@ public class PolicyManagerServlet extends HttpServlet {
                        params.put("scopeName", scopeName + "%");
                }
                PolicyController controller = getPolicyControllerInstance();
-               List<Object> scopesList = controller.getDataByQuery(scopeNamequery, params);
+               List<Object> scopesList = null;
+               if(jUnit){
+                       scopesList = controller.getDataByQuery(scopeNamequery, null);
+               }else{
+                       scopesList = controller.getDataByQuery(scopeNamequery, params);
+               }
                return  scopesList;
        }
 
@@ -687,8 +707,15 @@ public class PolicyManagerServlet extends HttpServlet {
                SimpleBindings params = new SimpleBindings();
                params.put("scopeName", scopeName + "%");
                
-               List<Object> activePolicies = controller.getDataByQuery(query, params);
-               List<Object> scopesList = controller.getDataByQuery(scopeNamequery, params);
+               List<Object> activePolicies = null;
+               List<Object> scopesList = null;
+               if(jUnit){
+                       activePolicies = controller.getDataByQuery(query, null);
+                       scopesList = controller.getDataByQuery(scopeNamequery, null);
+               }else{
+                       activePolicies = controller.getDataByQuery(query, params);
+                       scopesList = controller.getDataByQuery(scopeNamequery, params);
+               }
                for(Object list : scopesList){
                        PolicyEditorScopes scopeById = (PolicyEditorScopes) list;
                        String scope = scopeById.getScopeName();
@@ -736,8 +763,7 @@ public class PolicyManagerServlet extends HttpServlet {
                                        el.put("modifiedBy", getUserName(policy.getModifiedBy()));
                                        resultList.add(el);
                                }
-                       }else if(!scopes.isEmpty()){
-                               if(scopes.contains(scopeNameValue)){
+                       }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());
@@ -747,7 +773,6 @@ public class PolicyManagerServlet extends HttpServlet {
                                        el.put("createdBy", getUserName(policy.getCreatedBy()));
                                        el.put("modifiedBy", getUserName(policy.getModifiedBy()));
                                        resultList.add(el);
-                               }
                        }
                }       
        }
@@ -1396,7 +1421,12 @@ public class PolicyManagerServlet extends HttpServlet {
                        SimpleBindings peParams = new SimpleBindings();
                        peParams.put("split_1", split[1]);
                        peParams.put("split_0", split[0]);
-                       List<Object> queryData = controller.getDataByQuery(query, peParams);
+                       List<Object> queryData = null;
+                       if(jUnit){
+                               queryData = controller.getDataByQuery(query, null);
+                       }else{
+                               queryData = controller.getDataByQuery(query, peParams);
+                       }
                        PolicyEntity entity = (PolicyEntity) queryData.get(0);
                        InputStream stream = new ByteArrayInputStream(entity.getPolicyData().getBytes(StandardCharsets.UTF_8));
 
@@ -1460,7 +1490,7 @@ public class PolicyManagerServlet extends HttpServlet {
                                validateName = name;
                        }
                        if(!name.isEmpty()){
-                               String validate = PolicyUtils.emptyPolicyValidator(validateName);
+                               String validate = PolicyUtils.policySpecialCharValidator(validateName);
                                if(!validate.contains("success")){
                                        return error(validate);
                                }