CreateDcaeMicroServiceController extends RestrictedBaseController { public void prePopulateDCAEMSPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) { if (! (policyAdapter.getPolicyData() instanceof PolicyType)) { return; } Object policyData = policyAdapter.getPolicyData(); PolicyType policy = (PolicyType) policyData; policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("MS_") + 3); policyAdapter.setPolicyName(policyNameValue); String description = ""; try { description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); } catch (Exception e) { LOGGER.error("Error while collecting the desciption tag in ActionPolicy " + policyNameValue, e); description = policy.getDescription(); } policyAdapter.setPolicyDescription(description); TargetType target = policy.getTarget(); if (target == null) { return; } for (AnyOfType anyOf : target.getAnyOf()) { for (AllOfType allOf : anyOf.getAllOf()) { List<MatchType> matchList = allOf.getMatch(); if (matchList == null) { continue; } Iterator<MatchType> iterMatch = matchList.iterator(); while (matchList.size() > 1 && iterMatch.hasNext()) { MatchType match = iterMatch.next(); policyAdapter.setupUsingAttribute(match.getAttributeDesignator().getAttributeId(), (String) match.getAttributeValue().getContent().get(0)); } readFile(policyAdapter, entity); } } } @Autowired private  CreateDcaeMicroServiceController(CommonClassDao commonClassDao);  CreateDcaeMicroServiceController(); static CommonClassDao getCommonClassDao(); static void setCommonClassDao(CommonClassDao commonClassDao); PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter policyData, JsonNode root); boolean checkPattern(String patternString); void constructRule(StringBuilder sb, String jsonNode, Map<String, String> sigRules2); void parseData(JsonNode jsonNode, String string); String removeNullAttributes(String cleanJson); JsonArray removeNull(JsonArray array); JsonObject removeNull(JsonObject obj); String cleanUpJson(String json); JSONObject decodeContent(JsonNode jsonNode); @RequestMapping( value = {"/policyController/getDCAEMSTemplateData.htm"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST}) ModelAndView getDCAEMSTemplateData(HttpServletRequest request, HttpServletResponse response); JSONObject convertToArrayElement(JSONObject json, String keyValue); Set<String> getManyTrueProperties(String referAttributes); @RequestMapping( value = {"/policyController/getModelServiceVersioneData.htm"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST}) ModelAndView getModelServiceVersionData(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_DCAEPriorityValues"}, method = {org.springframework.web.bind.annotation.RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getDCAEPriorityValuesData(HttpServletRequest request, HttpServletResponse response); void prePopulateDCAEMSPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity); Map<String, String> convert(String str, String split); @SuppressWarnings("unchecked") void readFile(PolicyRestAdapter policyAdapter, PolicyEntity entity); @SuppressWarnings({"rawtypes", "unchecked"}) void readRecursivlyJSONContent(Map<String, ?> map, Map<String, Object> data); String getPolicyScope(String value); Map<String, String> convertMap(Map<String, String> attributesMap, Map<String, String> attributesRefMap); @RequestMapping( value = {"/ms_dictionary/set_MSModelData"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST}) void SetMSModelData(HttpServletRequest request, HttpServletResponse response); void cleanUp(String path); void checkZipDirectory(String zipDirectory); Map<String, String> getAttributesListRefMap(); Map<String, LinkedList<String>> getArrayTextList(); Map<String, String> getSigRules(); void setSigRules(Map<String, String> sigRules); static final String DATATYPE; static final String PROPERTIES; static final String TYPE; static final String STRING; static final String INTEGER; static final String LIST; static final String DEFAULT; static final String REQUIRED; static final String MATCHABLE; static final String MANYFALSE; }
@Test public void testPrePopulateDcaeMsPolicyData() { logger.debug("testPrePopulateDCAEMSPolicyData: enter"); CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); PolicyEntity entity = new PolicyEntity(); ConfigurationDataEntity configData = new ConfigurationDataEntity(); configData.setConfigBody(configBodyString); entity.setConfigurationData(configData); JsonNode root = null; ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); PolicyRestAdapter restAdapter = null; try { root = JsonLoader.fromString(jsonString); restAdapter = mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class); MatchType matchType = new MatchType(); AttributeValueType attributeValue1 = new AttributeValueType(); attributeValue1.getContent().add("True"); matchType.setAttributeValue(attributeValue1); AttributeDesignatorType designator = new AttributeDesignatorType(); designator.setAttributeId("guard"); matchType.setAttributeDesignator(designator); AllOfType alltype = new AllOfType(); alltype.getMatch().add(matchType); MatchType matchDummy = new MatchType(); AttributeValueType dummyValue = new AttributeValueType(); dummyValue.getContent().add("dummy"); matchDummy.setAttributeValue(dummyValue); AttributeDesignatorType designatorDummy = new AttributeDesignatorType(); designatorDummy.setAttributeId("dummyId"); matchDummy.setAttributeDesignator(designatorDummy); alltype.getMatch().add(matchDummy); AnyOfType anyOfType = new AnyOfType(); anyOfType.getAllOf().add(alltype); TargetType target = new TargetType(); target.getAnyOf().add(anyOfType); AnyOfType anyRiskType = new AnyOfType(); AllOfType allRiskType = new AllOfType(); MatchType matchRiskType = new MatchType(); AttributeValueType riskTypeValue = new AttributeValueType(); riskTypeValue.getContent().add("test"); matchRiskType.setAttributeValue(riskTypeValue); AttributeDesignatorType designatorRiskType = new AttributeDesignatorType(); designatorRiskType.setAttributeId("RiskType"); matchRiskType.setAttributeDesignator(designatorRiskType); allRiskType.getMatch().add(matchRiskType); MatchType matchDummy1 = new MatchType(); AttributeValueType dummy1Value = new AttributeValueType(); dummy1Value.getContent().add("dummy"); matchDummy1.setAttributeValue(dummy1Value); AttributeDesignatorType designatorDummy1 = new AttributeDesignatorType(); designatorDummy1.setAttributeId("dummyId"); matchDummy1.setAttributeDesignator(designatorDummy1); allRiskType.getMatch().add(matchDummy1); anyRiskType.getAllOf().add(allRiskType); target.getAnyOf().add(anyRiskType); MatchType matchRiskLevel = new MatchType(); AttributeValueType riskLevel = new AttributeValueType(); riskLevel.getContent().add("3"); matchRiskLevel.setAttributeValue(riskLevel); AttributeDesignatorType designatorRiskLevel = new AttributeDesignatorType(); designatorRiskLevel.setAttributeId("RiskLevel"); matchRiskLevel.setAttributeDesignator(designatorRiskLevel); AllOfType allRiskLevel = new AllOfType(); allRiskLevel.getMatch().add(matchRiskLevel); MatchType matchDummy2 = new MatchType(); AttributeValueType dummy2Value = new AttributeValueType(); dummy2Value.getContent().add("dummy"); matchDummy2.setAttributeValue(dummy2Value); AttributeDesignatorType designatorDummy2 = new AttributeDesignatorType(); designatorDummy2.setAttributeId("dummyId"); matchDummy2.setAttributeDesignator(designatorDummy2); allRiskLevel.getMatch().add(matchDummy2); AnyOfType anyRiskLevel = new AnyOfType(); anyRiskLevel.getAllOf().add(allRiskLevel); target.getAnyOf().add(anyRiskLevel); PolicyType policyType = new PolicyType(); policyType.setTarget(target); restAdapter.setPolicyData(policyType); controller.prePopulateDCAEMSPolicyData(restAdapter, entity); logger.error("restAdapter.getRiskType() : " + restAdapter.getRiskType()); logger.error("restAdapter.getRiskLevel() : " + restAdapter.getRiskLevel()); logger.error("restAdapter.getGuard() : " + restAdapter.getGuard()); assertEquals("True", restAdapter.getGuard()); assertEquals("3", restAdapter.getRiskLevel()); assertEquals("test", restAdapter.getRiskType()); } catch (Exception e) { logger.error("testPrePopulateDCAEMSPolicyData", e); fail("testPrePopulateDCAEMSPolicyData failed due to: " + e); } logger.debug("testPrePopulateDCAEMSPolicyData: exit"); }