- String policyType = searchData.getPolicyType();
-
- String searchText = searchData.getQuery();
- String descriptivevalue = searchData.getDescriptiveScope();
- if(descriptivevalue != null){
- DescriptiveScope dsSearch = (DescriptiveScope) commonClassDao.getEntityItem(DescriptiveScope.class, "descriptiveScopeName", descriptivevalue);
- if(dsSearch != null){
- String[] descriptiveList = dsSearch.getSearch().split("AND");
- for(String keyValue : descriptiveList){
- String[] entry = keyValue.split(":");
- if(searchData.getPolicyType() != null && "closedLoop".equals(searchData.getPolicyType())){
- searchKeyValue.put("jsonBodyData", "*" +entry[1] +"*");
- }else{
- 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.getOnapName() != null){
- searchKeyValue.put("onapName", searchData.getOnapName());
- }
- 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", "*" +searchData.getVnfType() +"*");
- }
- if(searchData.getPolicyStatus() != null){
- searchKeyValue.put("jsonBodyData", "*" +searchData.getPolicyStatus()+"*");
- }
- if(searchData.getVproAction() != null){
- searchKeyValue.put("jsonBodyData", "*" +searchData.getVproAction()+"*");
- }
- if(searchData.getServiceType() != null){
- searchKeyValue.put("serviceType", 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(),e);
- }
- }
-
- @RequestMapping(value={"/searchDictionary"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView searchDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
- try{
- PolicyIndexType config = PolicyIndexType.config;
- PolicyIndexType closedloop = PolicyIndexType.closedloop;
- PolicyIndexType action = PolicyIndexType.action;
- PolicyIndexType decision = PolicyIndexType.decision;
- PolicyIndexType all = PolicyIndexType.all;
-
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- JsonNode root = mapper.readTree(request.getReader());
- String dictionaryType = root.get("type").textValue();
- Mode mode = Mode.valueOf(dictionaryType);
- String value;
- List<String> policyList = new ArrayList<>();
- switch (mode){
- case attribute :
- Attribute attributedata = (Attribute)mapper.readValue(root.get("data").toString(), Attribute.class);
- value = attributedata.getXacmlId();
- policyList = searchElkDatabase(all, "pholder",value);
- break;
- case onapName :
- OnapName onapName = (OnapName)mapper.readValue(root.get("data").toString(), OnapName.class);
- value = onapName.getOnapName();
- policyList = searchElkDatabase(all, "onapName",value);
- break;
- case actionPolicy :
- ActionPolicyDict actionPolicyDict = (ActionPolicyDict)mapper.readValue(root.get("data").toString(), ActionPolicyDict.class);
- value = actionPolicyDict.getAttributeName();
- policyList = searchElkDatabase(action, "actionAttributeValue",value);
- break;
- case brmsParam :
- BRMSParamTemplate bRMSParamTemplate = (BRMSParamTemplate)mapper.readValue(root.get("data").toString(), BRMSParamTemplate.class);
- value = bRMSParamTemplate.getRuleName();
- policyList = searchElkDatabase(config, "ruleName",value);
- break;
- case pepOptions :
- PEPOptions pEPOptions = (PEPOptions)mapper.readValue(root.get("data").toString(), PEPOptions.class);
- value = pEPOptions.getPepName();
- policyList = searchElkDatabase(closedloop,"jsonBodyData.pepName",value);
- break;
- case clSite :
- ClosedLoopSite closedLoopSite = (ClosedLoopSite)mapper.readValue(root.get("data").toString(), ClosedLoopSite.class);
- value = closedLoopSite.getSiteName();
- policyList = searchElkDatabase(closedloop,"siteNames",value);
- break;
- case clService :
- ClosedLoopD2Services closedLoopD2Services = (ClosedLoopD2Services)mapper.readValue(root.get("data").toString(), ClosedLoopD2Services.class);
- value = closedLoopD2Services.getServiceName();
- policyList = searchElkDatabase(closedloop, "pholder",value);
- break;
- case clVarbind :
- VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("data").toString(), VarbindDictionary.class);
- value = varbindDictionary.getVarbindName();
- policyList = searchElkDatabase(closedloop, "jsonBodyData.triggerSignaturesUsedForUI.signatures",value);
- break;
- case clVnf :
- VNFType vNFType = (VNFType)mapper.readValue(root.get("data").toString(), VNFType.class);
- value = vNFType.getVnftype();
- policyList = searchElkDatabase(closedloop, "jsonBodyData.vnfType",value);
- break;
- case clVSCL :
- VSCLAction vsclAction = (VSCLAction)mapper.readValue(root.get("data").toString(), VSCLAction.class);
- value = vsclAction.getVsclaction();
- policyList = searchElkDatabase(closedloop, "jsonBodyData.actions",value);
- break;
- case decision :
- DecisionSettings decisionSettings = (DecisionSettings)mapper.readValue(root.get("data").toString(), DecisionSettings.class);
- value = decisionSettings.getXacmlId();
- policyList = searchElkDatabase(decision,"pholder",value);
- break;
- case fwTerm :
- TermList term = (TermList)mapper.readValue(root.get("data").toString(), TermList.class);
- value = term.getTermName();
- policyList = searchElkDatabase(config, "pholder",value);
- break;
- case msDCAEUUID :
- DCAEuuid dcaeUUID = (DCAEuuid)mapper.readValue(root.get("data").toString(), DCAEuuid.class);
- value = dcaeUUID.getName();
- policyList = searchElkDatabase(config, "uuid",value);
- break;
- case msLocation :
- MicroServiceLocation mslocation = (MicroServiceLocation)mapper.readValue(root.get("data").toString(), MicroServiceLocation.class);
- value = mslocation.getName();
- policyList = searchElkDatabase(config, "location",value);
- break;
- case msModels :
- MicroServiceModels msModels = (MicroServiceModels)mapper.readValue(root.get("data").toString(), MicroServiceModels.class);
- value = msModels.getModelName();
- policyList = searchElkDatabase(config, "serviceType",value);
- break;
- case psGroupPolicy :
- GroupPolicyScopeList groupPoilicy = (GroupPolicyScopeList)mapper.readValue(root.get("data").toString(), GroupPolicyScopeList.class);
- value = groupPoilicy.getGroupName();
- policyList = searchElkDatabase(config, "pholder",value);
- break;
- case safeRisk :
- RiskType riskType= (RiskType)mapper.readValue(root.get("data").toString(), RiskType.class);
- value = riskType.getRiskName();
- policyList = searchElkDatabase(config, "riskType",value);
- break;
- case safePolicyWarning :
- SafePolicyWarning safePolicy = (SafePolicyWarning)mapper.readValue(root.get("data").toString(), SafePolicyWarning.class);
- value = safePolicy.getName();
- policyList = searchElkDatabase(config, "pholder",value);
- break;
- default:
- }
-
- response.setStatus(HttpServletResponse.SC_OK);
- response.addHeader("success", "success");
- JSONObject k = new JSONObject("{policyresult: " + policyList + "}");
- response.getWriter().write(k.toString());
- }catch(Exception e){
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
- PrintWriter out = response.getWriter();
- out.write(e.getMessage());
- LOGGER.error(e);
- }
- return null;
- }