CreateDcaeMicroServiceController extends RestrictedBaseController { @RequestMapping( value = {"/ms_dictionary/set_MSModelData"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST}) public void SetMSModelData(HttpServletRequest request, HttpServletResponse response) throws IOException, FileUploadException { modelList = new ArrayList<>(); dirDependencyList = new ArrayList<>(); classMap = new LinkedHashMap<>(); List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); boolean zip = false; boolean yml = false; String errorMsg = ""; for (FileItem item : items) { if (item.getName().endsWith(".zip") || item.getName().endsWith(".xmi") || item.getName().endsWith(".yml")) { this.newModel = new MicroServiceModels(); try { File file = new File(item.getName()); OutputStream outputStream = new FileOutputStream(file); IOUtils.copy(item.getInputStream(), outputStream); outputStream.close(); this.newFile = file.toString(); this.newModel.setModelName(this.newFile.split("-v")[0]); if (this.newFile.contains("-v")) { if (item.getName().endsWith(".zip")) { this.newModel.setVersion(this.newFile.split("-v")[1].replace(".zip", "")); zip = true; } else if (item.getName().endsWith(".yml")) { this.newModel.setVersion(this.newFile.split("-v")[1].replace(".yml", "")); yml = true; } else { this.newModel.setVersion(this.newFile.split("-v")[1].replace(".xmi", "")); } } } catch (Exception e) { LOGGER.error("Upload error : ", e); errorMsg = "Upload error:" + e.getMessage(); } } } if (!errorMsg.isEmpty()) { response.setCharacterEncoding("UTF-8"); response.setContentType("application / json"); request.setCharacterEncoding("UTF-8"); JSONObject json = new JSONObject(); json.put("errorMsg", errorMsg); response.getWriter().write(json.toString()); return; } List<File> fileList = new ArrayList<>(); MsModelUtils msModelUtils = new MsModelUtils(commonClassDao); this.directory = "model"; if (zip) { extractFolder(this.newFile); fileList = listModelFiles(this.directory); } else if (yml) { errorMsg = msModelUtils.parseTosca(this.newFile); if (errorMsg != null) { response.setCharacterEncoding("UTF-8"); response.setContentType("application / json"); request.setCharacterEncoding("UTF-8"); JSONObject json = new JSONObject(); json.put("errorMsg", errorMsg); response.getWriter().write(json.toString()); return; } } else { File file = new File(this.newFile); fileList.add(file); } String modelType = ""; if (!yml) { modelType = "xmi"; classMap = new LinkedHashMap<>(); for (File file : fileList) { if (!file.isDirectory() && file.getName().endsWith(".xmi")) { retrieveDependency(file.toString()); } } modelList = createList(); cleanUp(this.newFile); cleanUp(directory); } else { modelType = "yml"; modelList.add(this.newModel.getModelName()); String className = this.newModel.getModelName(); MsAttributeObject msAttributes = new MsAttributeObject(); msAttributes.setClassName(className); LinkedHashMap<String, String> returnAttributeList = new LinkedHashMap<>(); returnAttributeList.put(className, msModelUtils.getAttributeString()); msAttributes.setAttribute(returnAttributeList); msAttributes.setSubClass(msModelUtils.getRetmap()); msAttributes.setMatchingSet(msModelUtils.getMatchableValues()); LinkedHashMap<String, String> returnReferenceList = new LinkedHashMap<>(); returnReferenceList.put(className, msModelUtils.getReferenceAttributes()); msAttributes.setRefAttribute(returnReferenceList); if (msModelUtils.getListConstraints() != "") { LinkedHashMap<String, String> enumList = new LinkedHashMap<>(); String[] listArray = msModelUtils.getListConstraints().split("#"); for (String str : listArray) { String[] strArr = str.split("="); if (strArr.length > 1) { enumList.put(strArr[0], strArr[1]); } } msAttributes.setEnumType(enumList); } classMap = new LinkedHashMap<>(); classMap.put(className, msAttributes); } response.setCharacterEncoding("UTF-8"); response.setContentType("application / json"); request.setCharacterEncoding("UTF-8"); ObjectMapper mapper = new ObjectMapper(); JSONObject json = new JSONObject(); json.put("classListDatas", modelList); json.put("modelDatas", mapper.writeValueAsString(classMap)); json.put("modelType", modelType); json.put("dataOrderInfo", msModelUtils.getDataOrderInfo()); json.put("ruleFormation", msModelUtils.getJsonRuleFormation()); response.getWriter().write(json.toString()); } @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 testSetMsModelData() { logger.debug("testSetMSModelData: enter"); HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getContentType()) .andReturn("multipart/form-data; boundary=----WebKitFormBoundaryWcRUaIbC8kXgjr3p"); expect(request.getMethod()).andReturn("post"); expect(request.getHeader("Content-length")).andReturn("7809"); expect(request.getContentLength()).andReturn(7809); try { String fileName = ""; try { ClassLoader classLoader = getClass().getClassLoader(); fileName = new File(classLoader.getResource("schedulerPolicies-v1707.xmi").getFile()).getAbsolutePath(); } catch (Exception e1) { logger.error("Exception Occured while loading file" + e1); } expect(request.getInputStream()).andReturn(new MockServletInputStream(fileName)); expect(request.getCharacterEncoding()).andReturn("UTF-8"); expect(request.getContentLength()).andReturn(1024); replay(request); } catch (Exception e) { logger.error("testSetMSModelData" + e); e.printStackTrace(); } logger.debug("testSetMSModelData: exit"); }