Merge "Adding PolicyType to getConfig Response"
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / elk / client / PolicyElasticSearchController.java
index 2f4dc59..77e45e3 100644 (file)
@@ -20,7 +20,9 @@
 package org.onap.policy.pap.xacml.rest.elk.client;
 
 
+import java.io.IOException;
 import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
 import java.security.KeyManagementException;
 import java.security.NoSuchAlgorithmException;
 import java.security.cert.X509Certificate;
@@ -91,11 +93,11 @@ public class PolicyElasticSearchController{
                psGroupPolicy, safeRisk, safePolicyWarning
        }
 
-       public static final HashMap<String, String> name2jsonPath = new HashMap<String, String>() {
+       protected static final HashMap<String, String> name2jsonPath = new HashMap<String, String>() {
                private static final long serialVersionUID = 1L;
        };
        
-       public static CommonClassDao commonClassDao;
+       private static CommonClassDao commonClassDao;
 
        @Autowired
        public PolicyElasticSearchController(CommonClassDao commonClassDao) {
@@ -229,7 +231,7 @@ public class PolicyElasticSearchController{
                                                                if(searchData.getPolicyType() != null && "closedLoop".equals(searchData.getPolicyType())){
                                                                        searchKeyValue.put("jsonBodyData", "*" +entry[1] +"*");
                                                                }else{
-                                                                       searchKeyValue.put(entry[0], entry[1]);
+                                                                       searchText = entry[1];
                                                                }
                                                        }
                                                }
@@ -263,13 +265,13 @@ public class PolicyElasticSearchController{
                                                searchKeyValue.put("jsonBodyData."+d2Service+"", "true");
                                        }       
                                        if(searchData.getVnfType() != null){
-                                               searchKeyValue.put("jsonBodyData", "*" +searchData.getVnfType() +"*");                                  
+                                               searchKeyValue.put("jsonBodyData", "*"+searchData.getVnfType()+"*");                                    
                                        }
                                        if(searchData.getPolicyStatus() != null){
-                                               searchKeyValue.put("jsonBodyData", "*" +searchData.getPolicyStatus()+"*");
+                                               searchKeyValue.put("jsonBodyData", "*"+searchData.getPolicyStatus()+"*");
                                        }
                                        if(searchData.getVproAction() != null){
-                                               searchKeyValue.put("jsonBodyData", "*" +searchData.getVproAction()+"*");
+                                               searchKeyValue.put("jsonBodyData", "*"+searchData.getVproAction()+"*");
                                        }
                                        if(searchData.getServiceType() != null){
                                                searchKeyValue.put("serviceType", searchData.getServiceType());
@@ -286,8 +288,10 @@ public class PolicyElasticSearchController{
                                                        type = ElkConnector.PolicyIndexType.decision;
                                                }else if(policyType.equalsIgnoreCase("config")){
                                                        type = ElkConnector.PolicyIndexType.config;
-                                               }else {
+                                               }else if(policyType.equalsIgnoreCase("closedloop")){
                                                        type = ElkConnector.PolicyIndexType.closedloop;
+                                               }else{
+                                                       type = ElkConnector.PolicyIndexType.all;
                                                }
                                        }else{
                                                type = ElkConnector.PolicyIndexType.all;
@@ -327,12 +331,12 @@ public class PolicyElasticSearchController{
                }catch(Exception e){
                        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                        response.addHeader("error", "Exception Occured While Performing Elastic Transaction");
-                       LOGGER.error("Exception Occured While Performing Elastic Transaction"+e.getMessage());
+                       LOGGER.error("Exception Occured While Performing Elastic Transaction"+e.getMessage(),e);
                }
        }
        
        @RequestMapping(value={"/searchDictionary"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
-       public ModelAndView searchDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
+       public ModelAndView searchDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
                try{
                        PolicyIndexType config = PolicyIndexType.config;
                        PolicyIndexType closedloop = PolicyIndexType.closedloop;
@@ -386,17 +390,17 @@ public class PolicyElasticSearchController{
                        case clVarbind :
                                VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("data").toString(), VarbindDictionary.class);
                                value = varbindDictionary.getVarbindName();
-                               policyList = searchElkDatabase(closedloop, "jsonBodyData.triggerSignaturesUsedForUI.signatures",value);
+                               policyList = searchElkDatabase(closedloop, "jsonBodyData","*"+value+"*");
                                break;
                        case clVnf :
                                VNFType vNFType = (VNFType)mapper.readValue(root.get("data").toString(), VNFType.class);
                                value = vNFType.getVnftype();
-                               policyList = searchElkDatabase(closedloop, "jsonBodyData.vnfType",value);
+                               policyList = searchElkDatabase(closedloop, "jsonBodyData","*"+value+"*");
                                break;
                        case clVSCL :
                                VSCLAction vsclAction = (VSCLAction)mapper.readValue(root.get("data").toString(), VSCLAction.class);
                                value = vsclAction.getVsclaction();
-                               policyList = searchElkDatabase(closedloop, "jsonBodyData.actions",value);
+                               policyList = searchElkDatabase(closedloop, "jsonBodyData","*"+value+"*");
                                break;
                        case decision :
                                DecisionSettings decisionSettings = (DecisionSettings)mapper.readValue(root.get("data").toString(), DecisionSettings.class);
@@ -450,6 +454,7 @@ public class PolicyElasticSearchController{
                        request.setCharacterEncoding("UTF-8");
                        PrintWriter out = response.getWriter();
                        out.write(e.getMessage());
+                       LOGGER.error(e);
                }
                return null;
        }