- private Set<String> getAllKeys(JSONObject json, Set<String> keys) {
- for (String key : json.keySet()) {
- Object obj = json.get(key);
- if(obj instanceof String && ((String) obj).contains("MANY-true")){
- LOGGER.info("key : " + key);
- LOGGER.info("obj : " + obj);
- allManyTrueKeys.add(key);
- }
- if (obj instanceof JSONObject) keys.addAll(getAllKeys(json.getJSONObject(key)));
- if (obj instanceof JSONArray) keys.addAll(getAllKeys(json.getJSONArray(key)));
- }
-
- return keys;
- }
-
-
- @RequestMapping(value={"/policyController/getModelServiceVersioneData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView getModelServiceVersionData(HttpServletRequest request, HttpServletResponse response) throws IOException{
- 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];
- Set<String> returnList = getVersionList(servicename);
-
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
- List<Object> list = new ArrayList<>();
- PrintWriter out = response.getWriter();
- String responseString = mapper.writeValueAsString(returnList);
- JSONObject j = new JSONObject("{dcaeModelVersionData: " + responseString +"}");
- list.add(j);
- out.write(list.toString());
- return null;
- }
-
- private Set<String> getVersionList(String name) {
- MicroServiceModels workingModel;
- Set<String> list = new HashSet<>();
- List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
- for (int i = 0; i < microServiceModelsData.size(); i++) {
- workingModel = (MicroServiceModels) microServiceModelsData.get(i);
- if (workingModel.getVersion()!=null){
- list.add(workingModel.getVersion());
- }else{
- list.add("Default");
- }
- }
- return list;
- }
-
- private MicroServiceModels getAttributeObject(String name, String version) {
- MicroServiceModels workingModel = new MicroServiceModels();
- List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
- for (int i = 0; i < microServiceModelsData.size(); i++) {
- workingModel = (MicroServiceModels) microServiceModelsData.get(i);
- if(version != null){
- if (workingModel.getVersion()!=null){
- if (workingModel.getVersion().equals(version)){
- return workingModel;
- }
- }else{
- return workingModel;
- }
- }else{
- return workingModel;
- }
-
- }
- return workingModel;
- }
-
- private MicroserviceHeaderdeFaults getHeaderDefaultsObject(String modelName) {
- return (MicroserviceHeaderdeFaults) commonClassDao.getEntityItem(MicroserviceHeaderdeFaults.class, "modelName", modelName);
- }
-
- @RequestMapping(value={"/get_DCAEPriorityValues"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getDCAEPriorityValuesData(HttpServletRequest request, HttpServletResponse response){
- try{
- Map<String, Object> model = new HashMap<>();
- ObjectMapper mapper = new ObjectMapper();
- List<String> priorityList = new ArrayList<>();
- priorityCount = 10;
- for (int i = 1; i < priorityCount; i++) {
- priorityList.add(String.valueOf(i));
- }
- model.put("priorityDatas", mapper.writeValueAsString(priorityList));
- JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
- JSONObject j = new JSONObject(msg);
- response.getWriter().write(j.toString());
- }
- catch (Exception e){
- LOGGER.error(e);
- }
- }
-
- public void prePopulateDCAEMSPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
- if (policyAdapter.getPolicyData() instanceof PolicyType) {
- 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);
- // Get the target data under policy.
- TargetType target = policy.getTarget();
- if (target != null) {
- // Under target we have AnyOFType
- List<AnyOfType> anyOfList = target.getAnyOf();
- if (anyOfList != null) {
- Iterator<AnyOfType> iterAnyOf = anyOfList.iterator();
- while (iterAnyOf.hasNext()) {
- AnyOfType anyOf = iterAnyOf.next();
- // Under AnyOFType we have AllOFType
- List<AllOfType> allOfList = anyOf.getAllOf();
- if (allOfList != null) {
- Iterator<AllOfType> iterAllOf = allOfList.iterator();
- while (iterAllOf.hasNext()) {
- AllOfType allOf = iterAllOf.next();
- // Under AllOFType we have Match
- List<MatchType> matchList = allOf.getMatch();
- if (matchList != null) {
- Iterator<MatchType> iterMatch = matchList.iterator();
- while (matchList.size()>1 && iterMatch.hasNext()) {
- MatchType match = iterMatch.next();
- //
- // Under the match we have attribute value and
- // attributeDesignator. So,finally down to the actual attribute.
- //
- AttributeValueType attributeValue = match.getAttributeValue();
- String value = (String) attributeValue.getContent().get(0);
- AttributeDesignatorType designator = match.getAttributeDesignator();
- String attributeId = designator.getAttributeId();
- // First match in the target is OnapName, so set that value.
- if ("ONAPName".equals(attributeId)) {
- policyAdapter.setOnapName(value);
- }
- if ("ConfigName".equals(attributeId)){
- policyAdapter.setConfigName(value);
- }
- if ("uuid".equals(attributeId)){
- policyAdapter.setUuid(value);
- }
- if ("location".equals(attributeId)){
- policyAdapter.setLocation(value);
- }
- if ("RiskType".equals(attributeId)){
- policyAdapter.setRiskType(value);
- }
- if ("RiskLevel".equals(attributeId)){
- policyAdapter.setRiskLevel(value);
- }
- if ("guard".equals(attributeId)){
- policyAdapter.setGuard(value);
- }
- if ("TTLDate".equals(attributeId) && !value.contains("NA")){
- PolicyController controller = new PolicyController();
- String newDate = controller.convertDate(value);
- policyAdapter.setTtlDate(newDate);
- }
- }
- readFile(policyAdapter, entity);
- }
- }
- }
- }
- }
- }
- }
- }
-
- public static Map<String, String> convert(String str, String split) {
- Map<String, String> map = new HashMap<>();
- for(final String entry : str.split(split)) {
- String[] parts = entry.split("=");
- map.put(parts[0], parts[1]);
- }
- return map;
- }
-
-
- @SuppressWarnings("unchecked")
- private void readFile(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
- String policyScopeName = null;
- ObjectMapper mapper = new ObjectMapper();
- try {
- DCAEMicroServiceObject msBody = mapper.readValue(entity.getConfigurationData().getConfigBody(), DCAEMicroServiceObject.class);
- policyScopeName = getPolicyScope(msBody.getPolicyScope());
- policyAdapter.setPolicyScope(policyScopeName);
-
- policyAdapter.setPriority(msBody.getPriority());
-
- if (msBody.getVersion()!= null){
- policyAdapter.setServiceType(msBody.getService());
- policyAdapter.setVersion(msBody.getVersion());
- }else{
- policyAdapter.setServiceType(msBody.getService());
- }
- if(msBody.getContent() != null){
- LinkedHashMap<String, Object> data = new LinkedHashMap<>();
- LinkedHashMap<String, ?> map = (LinkedHashMap<String, ?>) msBody.getContent();
- readRecursivlyJSONContent(map, data);
- policyAdapter.setRuleData(data);
- }
-
- } catch (Exception e) {
- LOGGER.error(e);
- }
-
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public void readRecursivlyJSONContent(LinkedHashMap<String, ?> map, LinkedHashMap<String, Object> data){
- for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
- Object key = iterator.next();
- Object value = map.get(key);
- if(value instanceof LinkedHashMap<?, ?>){
- LinkedHashMap<String, Object> secondObjec = new LinkedHashMap<>();
- readRecursivlyJSONContent((LinkedHashMap<String, ?>) value, secondObjec);
- for( Entry<String, Object> entry : secondObjec.entrySet()){
- data.put(key+"." + entry.getKey(), entry.getValue());
- }
- }else if(value instanceof ArrayList){
- ArrayList<?> jsonArrayVal = (ArrayList<?>)value;
- for(int i = 0; i < jsonArrayVal.size(); i++){
- Object arrayvalue = jsonArrayVal.get(i);
- if(arrayvalue instanceof LinkedHashMap<?, ?>){
- LinkedHashMap<String, Object> newData = new LinkedHashMap<>();
- readRecursivlyJSONContent((LinkedHashMap<String, ?>) arrayvalue, newData);
- for(Entry<String, Object> entry: newData.entrySet()){
- data.put(key+"@"+i+"." +entry.getKey(), entry.getValue());
- }
- }else if(arrayvalue instanceof ArrayList){
- ArrayList<?> jsonArrayVal1 = (ArrayList<?>)value;
- for(int j = 0; j < jsonArrayVal1.size(); j++){
- Object arrayvalue1 = jsonArrayVal1.get(i);
- data.put(key+"@"+j, arrayvalue1.toString());
- }
- }else{
- data.put(key+"@"+i, arrayvalue.toString());
- }
- }
- }else{
- data.put(key.toString(), value.toString());
- }
- }
- }
-
- public String getPolicyScope(String value) {
- List<Object> groupList= commonClassDao.getDataById(GroupPolicyScopeList.class, "groupList", value);
- if(groupList != null && !groupList.isEmpty()){
- GroupPolicyScopeList pScope = (GroupPolicyScopeList) groupList.get(0);
- return pScope.getGroupName();
- }
- return null;
- }
-
- //Convert the map values and set into JSON body
- public Map<String, String> convertMap(Map<String, String> attributesMap, Map<String, String> attributesRefMap) {
- Map<String, String> attribute = new HashMap<>();
- StringBuilder temp;
- String key;
- String value;
- for (Entry<String, String> entry : attributesMap.entrySet()) {
- key = entry.getKey();
- value = entry.getValue();
- attribute.put(key, value);
- }
- for (Entry<String, String> entryRef : attributesRefMap.entrySet()) {
- key = entryRef.getKey();
- value = entryRef.getValue();
- attribute.put(key, value);
- }
- for (Entry<String, String> entryList : attributesListRefMap.entrySet()) {
- key = entryList.getKey();
- value = entryList.getValue();
- attribute.put(key, value);
- }
- for (Entry<String, LinkedList<String>> arrayList : arrayTextList.entrySet()){
- key = arrayList.getKey();
- temp = null;
- for (Object textList : arrayList.getValue()){
- if (temp == null){
- temp = new StringBuilder();
- temp.append("[" + textList);
- }else{
- temp.append("," + textList);
- }
- }
- attribute.put(key, temp+ "]");
- }
-
- return attribute;
- }
-
- @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()){
-
- PrintWriter out = response.getWriter();
-
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
-
- JSONObject j = new JSONObject();
- j.put("errorMsg", errorMsg);
- out.write(j.toString());
- return;
- }
-
- List<File> fileList = new ArrayList<>();
- MSModelUtils msMLUtils = new MSModelUtils();
- this.directory = "model";
- if (zip){
- extractFolder(this.newFile);
- fileList = listModelFiles(this.directory);
- }else if (yml==true){
-
- errorMsg = msMLUtils.parseTosca(this.newFile);
- if(errorMsg != null){
- PrintWriter out = response.getWriter();
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
- JSONObject j = new JSONObject();
- j.put("errorMsg", errorMsg);
- out.write(j.toString());
- return;
- }
-
- }else {
- File file = new File(this.newFile);
- fileList.add(file);
- }
- String modelType= "";
- if(!yml){
- modelType="xmi";
- //Process Main Model file first
- classMap = new LinkedHashMap<>();
- for (File file : fileList) {
- if(!file.isDirectory() && file.getName().endsWith(".xmi")){
- retreiveDependency(file.toString(), true);
- }
- }
-
- 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, msMLUtils.getAttributeString());
- msAttributes.setAttribute(returnAttributeList);
-
- msAttributes.setSubClass(msMLUtils.getRetmap());
-
- msAttributes.setMatchingSet(msMLUtils.getMatchableValues());
-
- LinkedHashMap<String, String> returnReferenceList =new LinkedHashMap<>();
-
- returnReferenceList.put(className, msMLUtils.getReferenceAttributes());
- msAttributes.setRefAttribute(returnReferenceList);
-
- if(msMLUtils.getListConstraints()!=""){
- LinkedHashMap<String, String> enumList =new LinkedHashMap<>();
- String[] listArray=msMLUtils.getListConstraints().split("#");
- for(String str:listArray){
- String[] strArr= str.split("=");
- if(strArr.length>1){
+ private Set<String> getAllKeys(JSONObject json, Set<String> keys) {
+ for (String key : json.keySet()) {
+ Object obj = json.get(key);
+ if (obj instanceof String && ((String) obj).contains("MANY-true")) {
+ LOGGER.info("key : " + key);
+ LOGGER.info("obj : " + obj);
+ allManyTrueKeys.add(key);
+ }
+ if (obj instanceof JSONObject)
+ keys.addAll(getAllKeys(json.getJSONObject(key)));
+ if (obj instanceof JSONArray)
+ keys.addAll(getAllKeys(json.getJSONArray(key)));
+ }
+
+ return keys;
+ }
+
+
+ @RequestMapping(value = {"/policyController/getModelServiceVersioneData.htm"},
+ method = {org.springframework.web.bind.annotation.RequestMethod.POST})
+ public ModelAndView getModelServiceVersionData(HttpServletRequest request, HttpServletResponse response)
+ throws IOException {
+ 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];
+ Set<String> returnList = getVersionList(servicename);
+
+ response.setCharacterEncoding("UTF-8");
+ response.setContentType("application / json");
+ request.setCharacterEncoding("UTF-8");
+ List<Object> list = new ArrayList<>();
+ PrintWriter out = response.getWriter();
+ String responseString = mapper.writeValueAsString(returnList);
+ JSONObject j = new JSONObject("{dcaeModelVersionData: " + responseString + "}");
+ list.add(j);
+ out.write(list.toString());
+ return null;
+ }
+
+ private Set<String> getVersionList(String name) {
+ MicroServiceModels workingModel;
+ Set<String> list = new HashSet<>();
+ List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
+ for (int i = 0; i < microServiceModelsData.size(); i++) {
+ workingModel = (MicroServiceModels) microServiceModelsData.get(i);
+ if (workingModel.getVersion() != null) {
+ list.add(workingModel.getVersion());
+ } else {
+ list.add("Default");
+ }
+ }
+ return list;
+ }
+
+ private MicroServiceModels getAttributeObject(String name, String version) {
+ MicroServiceModels workingModel = new MicroServiceModels();
+ List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
+ for (int i = 0; i < microServiceModelsData.size(); i++) {
+ workingModel = (MicroServiceModels) microServiceModelsData.get(i);
+ if (version != null) {
+ if (workingModel.getVersion() != null) {
+ if (workingModel.getVersion().equals(version)) {
+ return workingModel;
+ }
+ } else {
+ return workingModel;
+ }
+ } else {
+ return workingModel;
+ }
+
+ }
+ return workingModel;
+ }
+
+ private MicroserviceHeaderdeFaults getHeaderDefaultsObject(String modelName) {
+ return (MicroserviceHeaderdeFaults) commonClassDao.getEntityItem(MicroserviceHeaderdeFaults.class, "modelName",
+ modelName);
+ }
+
+ @RequestMapping(value = {"/get_DCAEPriorityValues"},
+ method = {org.springframework.web.bind.annotation.RequestMethod.GET},
+ produces = MediaType.APPLICATION_JSON_VALUE)
+ public void getDCAEPriorityValuesData(HttpServletRequest request, HttpServletResponse response) {
+ try {
+ Map<String, Object> model = new HashMap<>();
+ ObjectMapper mapper = new ObjectMapper();
+ List<String> priorityList = new ArrayList<>();
+ priorityCount = 10;
+ for (int i = 1; i < priorityCount; i++) {
+ priorityList.add(String.valueOf(i));
+ }
+ model.put("priorityDatas", mapper.writeValueAsString(priorityList));
+ JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
+ JSONObject j = new JSONObject(msg);
+ response.getWriter().write(j.toString());
+ } catch (Exception e) {
+ LOGGER.error(e);
+ }
+ }
+
+ public void prePopulateDCAEMSPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
+ if (policyAdapter.getPolicyData() instanceof PolicyType) {
+ 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);
+ // Get the target data under policy.
+ TargetType target = policy.getTarget();
+ if (target != null) {
+ // Under target we have AnyOFType
+ List<AnyOfType> anyOfList = target.getAnyOf();
+ if (anyOfList != null) {
+ Iterator<AnyOfType> iterAnyOf = anyOfList.iterator();
+ while (iterAnyOf.hasNext()) {
+ AnyOfType anyOf = iterAnyOf.next();
+ // Under AnyOFType we have AllOFType
+ List<AllOfType> allOfList = anyOf.getAllOf();
+ if (allOfList != null) {
+ Iterator<AllOfType> iterAllOf = allOfList.iterator();
+ while (iterAllOf.hasNext()) {
+ AllOfType allOf = iterAllOf.next();
+ // Under AllOFType we have Match
+ List<MatchType> matchList = allOf.getMatch();
+ if (matchList != null) {
+ Iterator<MatchType> iterMatch = matchList.iterator();
+ while (matchList.size() > 1 && iterMatch.hasNext()) {
+ MatchType match = iterMatch.next();
+ //
+ // Under the match we have attribute value and
+ // attributeDesignator. So,finally down to the actual attribute.
+ //
+ AttributeValueType attributeValue = match.getAttributeValue();
+ String value = (String) attributeValue.getContent().get(0);
+ AttributeDesignatorType designator = match.getAttributeDesignator();
+ String attributeId = designator.getAttributeId();
+ // First match in the target is OnapName, so set that value.
+ if ("ONAPName".equals(attributeId)) {
+ policyAdapter.setOnapName(value);
+ }
+ if ("ConfigName".equals(attributeId)) {
+ policyAdapter.setConfigName(value);
+ }
+ if ("uuid".equals(attributeId)) {
+ policyAdapter.setUuid(value);
+ }
+ if ("location".equals(attributeId)) {
+ policyAdapter.setLocation(value);
+ }
+ if ("RiskType".equals(attributeId)) {
+ policyAdapter.setRiskType(value);
+ }
+ if ("RiskLevel".equals(attributeId)) {
+ policyAdapter.setRiskLevel(value);
+ }
+ if ("guard".equals(attributeId)) {
+ policyAdapter.setGuard(value);
+ }
+ if ("TTLDate".equals(attributeId) && !value.contains("NA")) {
+ PolicyController controller = new PolicyController();
+ String newDate = controller.convertDate(value);
+ policyAdapter.setTtlDate(newDate);
+ }
+ }
+ readFile(policyAdapter, entity);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public static Map<String, String> convert(String str, String split) {
+ Map<String, String> map = new HashMap<>();
+ for (final String entry : str.split(split)) {
+ String[] parts = entry.split("=");
+ map.put(parts[0], parts[1]);
+ }
+ return map;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ private void readFile(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
+ String policyScopeName = null;
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ DCAEMicroServiceObject msBody =
+ mapper.readValue(entity.getConfigurationData().getConfigBody(), DCAEMicroServiceObject.class);
+ policyScopeName = getPolicyScope(msBody.getPolicyScope());
+ policyAdapter.setPolicyScope(policyScopeName);
+
+ policyAdapter.setPriority(msBody.getPriority());
+
+ if (msBody.getVersion() != null) {
+ policyAdapter.setServiceType(msBody.getService());
+ policyAdapter.setVersion(msBody.getVersion());
+ } else {
+ policyAdapter.setServiceType(msBody.getService());
+ }
+ if (msBody.getContent() != null) {
+ LinkedHashMap<String, Object> data = new LinkedHashMap<>();
+ LinkedHashMap<String, ?> map = (LinkedHashMap<String, ?>) msBody.getContent();
+ readRecursivlyJSONContent(map, data);
+ policyAdapter.setRuleData(data);
+ }
+
+ } catch (Exception e) {
+ LOGGER.error(e);
+ }
+
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public void readRecursivlyJSONContent(LinkedHashMap<String, ?> map, LinkedHashMap<String, Object> data) {
+ for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
+ Object key = iterator.next();
+ Object value = map.get(key);
+ if (value instanceof LinkedHashMap<?, ?>) {
+ LinkedHashMap<String, Object> secondObjec = new LinkedHashMap<>();
+ readRecursivlyJSONContent((LinkedHashMap<String, ?>) value, secondObjec);
+ for (Entry<String, Object> entry : secondObjec.entrySet()) {
+ data.put(key + "." + entry.getKey(), entry.getValue());
+ }
+ } else if (value instanceof ArrayList) {
+ ArrayList<?> jsonArrayVal = (ArrayList<?>) value;
+ for (int i = 0; i < jsonArrayVal.size(); i++) {
+ Object arrayvalue = jsonArrayVal.get(i);
+ if (arrayvalue instanceof LinkedHashMap<?, ?>) {
+ LinkedHashMap<String, Object> newData = new LinkedHashMap<>();
+ readRecursivlyJSONContent((LinkedHashMap<String, ?>) arrayvalue, newData);
+ for (Entry<String, Object> entry : newData.entrySet()) {
+ data.put(key + "@" + i + "." + entry.getKey(), entry.getValue());
+ }
+ } else if (arrayvalue instanceof ArrayList) {
+ ArrayList<?> jsonArrayVal1 = (ArrayList<?>) value;
+ for (int j = 0; j < jsonArrayVal1.size(); j++) {
+ Object arrayvalue1 = jsonArrayVal1.get(i);
+ data.put(key + "@" + j, arrayvalue1.toString());
+ }
+ } else {
+ data.put(key + "@" + i, arrayvalue.toString());
+ }
+ }
+ } else {
+ data.put(key.toString(), value.toString());
+ }
+ }
+ }
+
+ public String getPolicyScope(String value) {
+ List<Object> groupList = commonClassDao.getDataById(GroupPolicyScopeList.class, "groupList", value);
+ if (groupList != null && !groupList.isEmpty()) {
+ GroupPolicyScopeList pScope = (GroupPolicyScopeList) groupList.get(0);
+ return pScope.getGroupName();
+ }
+ return null;
+ }
+
+ // Convert the map values and set into JSON body
+ public Map<String, String> convertMap(Map<String, String> attributesMap, Map<String, String> attributesRefMap) {
+ Map<String, String> attribute = new HashMap<>();
+ StringBuilder temp;
+ String key;
+ String value;
+ for (Entry<String, String> entry : attributesMap.entrySet()) {
+ key = entry.getKey();
+ value = entry.getValue();
+ attribute.put(key, value);
+ }
+ for (Entry<String, String> entryRef : attributesRefMap.entrySet()) {
+ key = entryRef.getKey();
+ value = entryRef.getValue();
+ attribute.put(key, value);
+ }
+ for (Entry<String, String> entryList : attributesListRefMap.entrySet()) {
+ key = entryList.getKey();
+ value = entryList.getValue();
+ attribute.put(key, value);
+ }
+ for (Entry<String, LinkedList<String>> arrayList : arrayTextList.entrySet()) {
+ key = arrayList.getKey();
+ temp = null;
+ for (Object textList : arrayList.getValue()) {
+ if (temp == null) {
+ temp = new StringBuilder();
+ temp.append("[" + textList);
+ } else {
+ temp.append("," + textList);
+ }
+ }
+ attribute.put(key, temp + "]");
+ }
+
+ return attribute;
+ }
+
+ @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()) {
+
+ PrintWriter out = response.getWriter();
+
+ response.setCharacterEncoding("UTF-8");
+ response.setContentType("application / json");
+ request.setCharacterEncoding("UTF-8");
+
+ JSONObject j = new JSONObject();
+ j.put("errorMsg", errorMsg);
+ out.write(j.toString());
+ return;
+ }
+
+ List<File> fileList = new ArrayList<>();
+ MSModelUtils msMLUtils = new MSModelUtils();
+ this.directory = "model";
+ if (zip) {
+ extractFolder(this.newFile);
+ fileList = listModelFiles(this.directory);
+ } else if (yml == true) {
+
+ errorMsg = msMLUtils.parseTosca(this.newFile);
+ if (errorMsg != null) {
+ PrintWriter out = response.getWriter();
+ response.setCharacterEncoding("UTF-8");
+ response.setContentType("application / json");
+ request.setCharacterEncoding("UTF-8");
+ JSONObject j = new JSONObject();
+ j.put("errorMsg", errorMsg);
+ out.write(j.toString());
+ return;
+ }
+
+ } else {
+ File file = new File(this.newFile);
+ fileList.add(file);
+ }
+ String modelType = "";
+ if (!yml) {
+ modelType = "xmi";
+ // Process Main Model file first
+ classMap = new LinkedHashMap<>();
+ for (File file : fileList) {
+ if (!file.isDirectory() && file.getName().endsWith(".xmi")) {
+ retreiveDependency(file.toString(), true);
+ }
+ }
+
+ 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, msMLUtils.getAttributeString());
+ msAttributes.setAttribute(returnAttributeList);
+
+ msAttributes.setSubClass(msMLUtils.getRetmap());
+
+ msAttributes.setMatchingSet(msMLUtils.getMatchableValues());
+
+ LinkedHashMap<String, String> returnReferenceList = new LinkedHashMap<>();
+
+ returnReferenceList.put(className, msMLUtils.getReferenceAttributes());
+ msAttributes.setRefAttribute(returnReferenceList);
+
+ if (msMLUtils.getListConstraints() != "") {
+ LinkedHashMap<String, String> enumList = new LinkedHashMap<>();
+ String[] listArray = msMLUtils.getListConstraints().split("#");
+ for (String str : listArray) {
+ String[] strArr = str.split("=");
+ if (strArr.length > 1) {