+
+ @RequestMapping(value="/searchPolicy", method= RequestMethod.POST)
+ public void searchPolicy(HttpServletRequest request, HttpServletResponse response) {
+ try{
+ boolean result = false;
+ boolean policyResult = false;
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ PolicyRestAdapter policyData = new PolicyRestAdapter();
+ PolicyElasticSearchController controller = new PolicyElasticSearchController();
+ Map<String, String> searchKeyValue = new HashMap<String, String>();
+ List<String> policyList = new ArrayList<String>();
+ if(request.getParameter("policyName") != null){
+ String policyName = request.getParameter("policyName");
+ policyData.setNewFileName(policyName);
+ if("delete".equalsIgnoreCase(request.getParameter("action"))){
+ result = controller.deleteElk(policyData);
+ }else{
+ result = controller.updateElk(policyData);
+ }
+ }
+ if("search".equalsIgnoreCase(request.getParameter("action"))){
+ try {
+ JsonNode root = mapper.readTree(request.getReader());
+ SearchData searchData = (SearchData)mapper.readValue(root.get("searchdata").toString(), SearchData.class);
+
+ String policyType = searchData.getPolicyType();
+
+ String searchText = searchData.getQuery();
+ String descriptivevalue = searchData.getDescriptiveScope();
+ if(descriptivevalue != null){
+ DescriptiveScope dsSearch = (DescriptiveScope) commonClassDao.getEntityItem(DescriptiveScope.class, "descriptiveScopeName", searchData.getDescriptiveScope());
+ if(dsSearch != null){
+ String[] descriptiveList = dsSearch.getSearch().split("AND");
+ for(String keyValue : descriptiveList){
+ String[] entry = keyValue.split(":");
+ searchKeyValue.put(entry[0], entry[1]);
+ }
+ }
+ }
+
+ if(searchData.getClosedLooppolicyType() != null){
+ String closedLoopType;
+ if("Config_Fault".equalsIgnoreCase(searchData.getClosedLooppolicyType())){
+ closedLoopType = "ClosedLoop_Fault";
+ }else{
+ closedLoopType = "ClosedLoop_PM";
+ }
+ searchKeyValue.put("configPolicyType", closedLoopType);
+ }
+ if(searchData.getEcompName() != null){
+ searchKeyValue.put("ecompName", searchData.getEcompName());
+ }
+ if(searchData.getD2Service() != null){
+ String d2Service = searchData.getD2Service().trim();
+ if(d2Service.equalsIgnoreCase("Hosted Voice (Trinity)")){
+ d2Service = "trinity";
+ }else if(d2Service.equalsIgnoreCase("vUSP")){
+ d2Service = "vUSP";
+ }else if(d2Service.equalsIgnoreCase("MCR")){
+ d2Service = "mcr";
+ }else if(d2Service.equalsIgnoreCase("Gamma")){
+ d2Service = "gamma";
+ }else if(d2Service.equalsIgnoreCase("vDNS")){
+ d2Service = "vDNS";
+ }
+ searchKeyValue.put("jsonBodyData."+d2Service+"", "true");
+ }
+ if(searchData.getVnfType() != null){
+ searchKeyValue.put("jsonBodyData.vnfType", searchData.getVnfType());
+ }
+ if(searchData.getPolicyStatus() != null){
+ searchKeyValue.put("jsonBodyData.closedLoopPolicyStatus", searchData.getPolicyStatus());
+ }
+ if(searchData.getVproAction() != null){
+ searchKeyValue.put("jsonBodyData.actions", searchData.getVproAction());
+ }
+ if(searchData.getServiceType() != null){
+ searchKeyValue.put("jsonBodyData.serviceTypePolicyName", searchData.getServiceType());
+ }
+ if(searchData.getBindTextSearch() != null){
+ searchKeyValue.put(searchData.getBindTextSearch(), searchText);
+ searchText = null;
+ }
+ PolicyIndexType type = null;
+ if(policyType != null){
+ if(policyType.equalsIgnoreCase("action")){
+ type = ElkConnector.PolicyIndexType.action;
+ }else if(policyType.equalsIgnoreCase("decision")){
+ type = ElkConnector.PolicyIndexType.decision;
+ }else if(policyType.equalsIgnoreCase("config")){
+ type = ElkConnector.PolicyIndexType.config;
+ }else {
+ type = ElkConnector.PolicyIndexType.closedloop;
+ }
+ }else{
+ type = ElkConnector.PolicyIndexType.all;
+ }
+ JestResult policyResultList = controller.search(type, searchText, searchKeyValue);
+ if(policyResultList.isSucceeded()){
+ result = true;
+ policyResult = true;
+ JsonArray resultObject = policyResultList.getJsonObject().get("hits").getAsJsonObject().get("hits").getAsJsonArray();
+ for(int i =0; i < resultObject.size(); i++){
+ String policyName = resultObject.get(i).getAsJsonObject().get("_id").toString();
+ policyList.add(policyName);
+ }
+ }else{
+ LOGGER.error("Exception Occured While Searching for Data in Elastic Search Server, Check the Logs");
+ }
+ }catch(Exception e){
+ LOGGER.error("Exception Occured While Searching for Data in Elastic Search Server" + e);
+ }
+ }
+ String message="";
+ if(result){
+ message = "Elastic Server Transaction is success";
+ }else{
+ message = "Elastic Server Transaction is failed, please check the logs";
+ }
+ JsonMessage msg = new JsonMessage(mapper.writeValueAsString(message));
+ JSONObject j = new JSONObject(msg);
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.addHeader("success", "success");
+ if(policyResult){
+ JSONObject k = new JSONObject("{policyresult: " + policyList + "}");
+ response.getWriter().write(k.toString());
+ }else{
+ response.getWriter().write(j.toString());
+ }
+ }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());
+ }
+ }
+