CreateDcaeMicroServiceController extends RestrictedBaseController { @RequestMapping( value = {"/policyController/getDCAEMSTemplateData.htm"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView getDCAEMSTemplateData(HttpServletRequest request, HttpServletResponse response) throws IOException { allManyTrueKeys = new TreeSet<>(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); String value = root.get("policyData").toString().replaceAll("^\"|\"$", ""); String servicename = value.split("-v")[0]; String version = null; if (value.contains("-v")) { version = value.split("-v")[1]; } MicroServiceModels returnModel = getAttributeObject(servicename, version); MicroserviceHeaderdeFaults returnHeaderDefauls = getHeaderDefaultsObject(value); JSONObject jsonHdDefaultObj = null; if (returnHeaderDefauls != null) { jsonHdDefaultObj = new JSONObject(); jsonHdDefaultObj.put("onapName", returnHeaderDefauls.getOnapName()); jsonHdDefaultObj.put("guard", returnHeaderDefauls.getGuard()); jsonHdDefaultObj.put("riskLevel", returnHeaderDefauls.getRiskLevel()); jsonHdDefaultObj.put("riskType", returnHeaderDefauls.getRiskType()); jsonHdDefaultObj.put("priority", returnHeaderDefauls.getPriority()); } String headDefautlsData = ""; if (jsonHdDefaultObj != null) { headDefautlsData = jsonHdDefaultObj.toString(); } else { headDefautlsData = "null"; } Set<String> allkeys = null; if (returnModel.getSubAttributes() != null && !returnModel.getSubAttributes().isEmpty()) { JSONObject json = new JSONObject(returnModel.getSubAttributes()); getAllKeys(json); allkeys = allManyTrueKeys; allManyTrueKeys = new TreeSet<>(); LOGGER.info("allkeys : " + allkeys); } String dataOrderInfo = returnModel.getDataOrderInfo(); if (dataOrderInfo != null && !dataOrderInfo.startsWith("\"")) { dataOrderInfo = "\"" + dataOrderInfo + "\""; } LOGGER.info("dataOrderInfo : " + dataOrderInfo); String allMnyTrueKeys = ""; if (allkeys != null) { allMnyTrueKeys = allkeys.toString(); } String jsonModel = createMicroSeriveJson(returnModel); JSONObject jsonObject = new JSONObject(jsonModel); JSONObject finalJsonObject = null; if (allkeys != null) { Iterator<String> iter = allkeys.iterator(); while (iter.hasNext()) { finalJsonObject = convertToArrayElement(jsonObject, iter.next()); jsonObject = finalJsonObject; } } if (finalJsonObject != null) { LOGGER.info(finalJsonObject.toString()); jsonModel = finalJsonObject.toString(); } Set<String> manyTrueProperties = getManyTrueProperties(returnModel.getRefAttributes()); if (manyTrueProperties != null) { JSONObject jsonObj = new JSONObject(jsonModel); for (String s : manyTrueProperties) { LOGGER.info(s); finalJsonObject = convertToArrayElement(jsonObj, s.trim()); jsonObj = finalJsonObject; } if (finalJsonObject != null) { LOGGER.info(finalJsonObject.toString()); jsonModel = finalJsonObject.toString(); } } response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING); response.setContentType(PolicyUtils.APPLICATION_JSON); request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING); List<Object> list = new ArrayList<>(); String responseString = mapper.writeValueAsString(returnModel); JSONObject json = null; if ("".equals(allMnyTrueKeys)) { json = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + ",dataOrderInfo:" + dataOrderInfo + ",headDefautlsData:" + headDefautlsData + "}"); } else { json = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + ",allManyTrueKeys: " + allMnyTrueKeys + ",dataOrderInfo:" + dataOrderInfo + ",headDefautlsData:" + headDefautlsData + "}"); } list.add(json); response.getWriter().write(list.toString()); return null; } @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 testGetDcaeMsTemplateData() { logger.debug("testGetDCAEMSTemplateData: enter"); CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); MockHttpServletResponse response = new MockHttpServletResponse(); String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}"; try { CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao); BufferedReader br = new BufferedReader(new StringReader(msModelJson)); when(request.getReader()).thenReturn(br); List<Object> microServiceModelsData = new ArrayList<Object>(); MicroServiceModels testData = new MicroServiceModels(); testData.setVersion("1707.4.1.2-Junit"); microServiceModelsData.add(testData); when(commonClassDao.getDataById(MicroServiceModels.class, "modelName", "DkatPolicyBody")) .thenReturn(microServiceModelsData); controller.getDCAEMSTemplateData(request, response); assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeModelData")); logger.debug("response: " + response.getContentAsString()); } catch (Exception e) { logger.error("testGetDCAEMSTemplateData", e); } logger.debug("testGetDCAEMSTemplateData: exit"); }