@SuppressWarnings("unchecked") @Test public void testActionParameterHandling() throws Exception { PolicyParameters parameters = createParametersObject(); parameters.setPolicyClass(PolicyClass.Action); PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper(); PolicyRestAdapter adapter = wrapper.populateRequestParameters((parameters)); assertTrue(adapter.getRuleAlgorithmschoices().isEmpty()); List<String> dynamicRuleAlgorithmLabels = new ArrayList<>(); parameters.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels); adapter = wrapper.populateRequestParameters((parameters)); assertTrue(adapter.getRuleAlgorithmschoices().isEmpty()); dynamicRuleAlgorithmLabels.add("Label0"); List<String> dynamicRuleAlgorithmFunctions = new ArrayList<>(); dynamicRuleAlgorithmFunctions.add("FirstAlgorithmFunction"); parameters.setDynamicRuleAlgorithmFunctions(dynamicRuleAlgorithmFunctions); List<String> dynamicRuleAlgorithmField1 = new ArrayList<>(); dynamicRuleAlgorithmField1.add("FirstAlgorithmFunctionField1"); parameters.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1); List<String> dynamicRuleAlgorithmField2 = new ArrayList<>(); dynamicRuleAlgorithmField2.add("FirstAlgorithmFunctionField2"); parameters.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2); parameters.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels); adapter = wrapper.populateRequestParameters((parameters)); assertEquals(1, adapter.getRuleAlgorithmschoices().size()); assertEquals("Label0", ((LinkedHashMap<String, String>) adapter.getRuleAlgorithmschoices().get(0)).get("id")); Map<String, String> matchingMap = new LinkedHashMap<>(); matchingMap.put("AKey", "AValue"); Map<AttributeType, Map<String, String>> attributes = new LinkedHashMap<>(); attributes.put(AttributeType.MATCHING, matchingMap); parameters.setAttributes(attributes); adapter = wrapper.populateRequestParameters((parameters)); assertEquals("AKey", ((LinkedHashMap<String, String>) adapter.getAttributes().get(0)).get("key")); }
public PolicyRestAdapter populateRequestParameters(HttpServletRequest request) { PolicyRestAdapter policyData = null; ClosedLoopFaultTrapDatas trapDatas = null; ClosedLoopFaultTrapDatas faultDatas = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); if (root.get("trapData") != null) { trapDatas = mapper.readValue(root.get("trapData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setTrapDatas(trapDatas); } if (root.get("faultData") != null) { faultDatas = mapper.readValue(root.get("faultData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setFaultDatas(faultDatas); } JsonObject json = stringToJsonObject(root.toString()); if (json.containsKey("policyJSON")) { policyData.setPolicyJSON(root.get("policyJSON")); } else { String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); policyData.setJsonBody(jsonBodyData); } } catch (Exception e) { LOGGER.error("Exception Occured while populating request parameters: " + e); } return policyData; }
PolicyValidationRequestWrapper { public PolicyRestAdapter populateRequestParameters(HttpServletRequest request) { PolicyRestAdapter policyData = null; ClosedLoopFaultTrapDatas trapDatas = null; ClosedLoopFaultTrapDatas faultDatas = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); if (root.get("trapData") != null) { trapDatas = mapper.readValue(root.get("trapData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setTrapDatas(trapDatas); } if (root.get("faultData") != null) { faultDatas = mapper.readValue(root.get("faultData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setFaultDatas(faultDatas); } JsonObject json = stringToJsonObject(root.toString()); if (json.containsKey("policyJSON")) { policyData.setPolicyJSON(root.get("policyJSON")); } else { String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); policyData.setJsonBody(jsonBodyData); } } catch (Exception e) { LOGGER.error("Exception Occured while populating request parameters: " + e); } return policyData; } }
PolicyValidationRequestWrapper { public PolicyRestAdapter populateRequestParameters(HttpServletRequest request) { PolicyRestAdapter policyData = null; ClosedLoopFaultTrapDatas trapDatas = null; ClosedLoopFaultTrapDatas faultDatas = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); if (root.get("trapData") != null) { trapDatas = mapper.readValue(root.get("trapData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setTrapDatas(trapDatas); } if (root.get("faultData") != null) { faultDatas = mapper.readValue(root.get("faultData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setFaultDatas(faultDatas); } JsonObject json = stringToJsonObject(root.toString()); if (json.containsKey("policyJSON")) { policyData.setPolicyJSON(root.get("policyJSON")); } else { String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); policyData.setJsonBody(jsonBodyData); } } catch (Exception e) { LOGGER.error("Exception Occured while populating request parameters: " + e); } return policyData; }  }
PolicyValidationRequestWrapper { public PolicyRestAdapter populateRequestParameters(HttpServletRequest request) { PolicyRestAdapter policyData = null; ClosedLoopFaultTrapDatas trapDatas = null; ClosedLoopFaultTrapDatas faultDatas = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); if (root.get("trapData") != null) { trapDatas = mapper.readValue(root.get("trapData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setTrapDatas(trapDatas); } if (root.get("faultData") != null) { faultDatas = mapper.readValue(root.get("faultData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setFaultDatas(faultDatas); } JsonObject json = stringToJsonObject(root.toString()); if (json.containsKey("policyJSON")) { policyData.setPolicyJSON(root.get("policyJSON")); } else { String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); policyData.setJsonBody(jsonBodyData); } } catch (Exception e) { LOGGER.error("Exception Occured while populating request parameters: " + e); } return policyData; }  PolicyRestAdapter populateRequestParameters(HttpServletRequest request); PolicyRestAdapter populateRequestParameters(PolicyParameters parameters); }
PolicyValidationRequestWrapper { public PolicyRestAdapter populateRequestParameters(HttpServletRequest request) { PolicyRestAdapter policyData = null; ClosedLoopFaultTrapDatas trapDatas = null; ClosedLoopFaultTrapDatas faultDatas = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); if (root.get("trapData") != null) { trapDatas = mapper.readValue(root.get("trapData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setTrapDatas(trapDatas); } if (root.get("faultData") != null) { faultDatas = mapper.readValue(root.get("faultData").toString(), ClosedLoopFaultTrapDatas.class); policyData.setFaultDatas(faultDatas); } JsonObject json = stringToJsonObject(root.toString()); if (json.containsKey("policyJSON")) { policyData.setPolicyJSON(root.get("policyJSON")); } else { String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); policyData.setJsonBody(jsonBodyData); } } catch (Exception e) { LOGGER.error("Exception Occured while populating request parameters: " + e); } return policyData; }  PolicyRestAdapter populateRequestParameters(HttpServletRequest request); PolicyRestAdapter populateRequestParameters(PolicyParameters parameters);  }