2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.rest.util;
24 import com.att.research.xacml.util.XACMLProperties;
25 import com.google.gson.Gson;
27 import java.io.FileInputStream;
28 import java.io.FileNotFoundException;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.Collections;
34 import java.util.HashMap;
35 import java.util.HashSet;
36 import java.util.Iterator;
37 import java.util.LinkedHashMap;
38 import java.util.List;
40 import java.util.Map.Entry;
43 import org.apache.commons.lang.StringUtils;
44 import org.apache.commons.logging.Log;
45 import org.apache.commons.logging.LogFactory;
46 import org.eclipse.emf.common.util.EList;
47 import org.eclipse.emf.common.util.EMap;
48 import org.eclipse.emf.common.util.Enumerator;
49 import org.eclipse.emf.common.util.TreeIterator;
50 import org.eclipse.emf.common.util.URI;
51 import org.eclipse.emf.ecore.EAnnotation;
52 import org.eclipse.emf.ecore.EClass;
53 import org.eclipse.emf.ecore.EClassifier;
54 import org.eclipse.emf.ecore.EEnum;
55 import org.eclipse.emf.ecore.EEnumLiteral;
56 import org.eclipse.emf.ecore.EObject;
57 import org.eclipse.emf.ecore.EPackage;
58 import org.eclipse.emf.ecore.EReference;
59 import org.eclipse.emf.ecore.EStructuralFeature;
60 import org.eclipse.emf.ecore.impl.EAttributeImpl;
61 import org.eclipse.emf.ecore.impl.EEnumImpl;
62 import org.eclipse.emf.ecore.resource.Resource;
63 import org.eclipse.emf.ecore.resource.ResourceSet;
64 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
65 import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
66 import org.json.JSONObject;
67 import org.onap.policy.rest.XACMLRestProperties;
68 import org.yaml.snakeyaml.Yaml;
71 public class MSModelUtils {
73 private static final Log logger = LogFactory.getLog(MSModelUtils.class);
75 private HashMap<String, MSAttributeObject> classMap = new HashMap<>();
76 private HashMap<String, String> enumMap = new HashMap<>();
77 private HashMap<String, String> matchingClass = new HashMap<>();
78 private String configuration = "configuration";
79 private String dictionary = "dictionary";
80 private String onap = "";
81 private String policy = "";
82 private String eProxyURI = "eProxyURI:";
83 private List<String> orderedElements = new ArrayList<>();
84 private String dataOrderInfo = "";
85 private Set<String> uniqueDataKeys = new HashSet<>();
86 private Set<String> uniqueKeys = new HashSet<>();
87 private String listConstraints = null;
88 private String referenceAttributes;
89 private LinkedHashMap<String, Object> retmap = new LinkedHashMap<>();
90 private Map<String, String> matchableValues;
91 private static final String PROPERTIES = ".properties.";
92 private static final String DATATYPE = "data_types.policy.data.";
93 private static final String TYPE = ".type";
94 private static final String REQUIRED = ".required";
95 private static final String MATCHABLE = ".matchable";
96 public static final String STRING = "string";
97 public static final String INTEGER = "integer";
98 private static final String BOOLEAN = "boolean";
99 public static final String LIST = "list";
100 public static final String MAP = "map";
101 private static final String DEFAULT = ".default";
102 private static final String MANYFALSE = ":MANY-false";
103 private static final String DESCRIPTION = ".description";
105 private static final String MANYTRUE = ":MANY-true";
106 private static final String DEFAULTVALUE = ":defaultValue-";
107 private static final String REQUIREDVALUE = ":required-";
108 private static final String MATCHABLEKEY = "matchable";
109 private static final String REQUIREDFALSE = ":required-false";
110 private static final String REQUIREDTRUE = ":required-true";
111 private static final String MATCHINGTRUE = "matching-true";
112 private static final String DESCRIPTION_KEY = "description";
113 private static final String DESCRIPTION_TOKEN =":description-";
114 private static final String PROPERTIES_KEY = "properties";
115 private static final String DATA_TYPE = "data_types";
116 private static final String ERROR = "error";
117 private static final String NODE_TYPE = "node_types";
118 private static final String TOSCA_DEFINITION_VERSION = "tosca_definitions_version";
119 private StringBuilder dataListBuffer = new StringBuilder();
120 private List<String> dataConstraints = new ArrayList<>();
121 private String attributeString = null;
122 private boolean isDuplicatedAttributes = false;
124 public MSModelUtils() {}
126 public MSModelUtils(String onap, String policy) {
128 this.policy = policy;
131 private enum ANNOTATION_TYPE {
132 MATCHING, VALIDATION, DICTIONARY
135 public enum MODEL_TYPE {
140 public Map<String, MSAttributeObject> processEpackage(String file, MODEL_TYPE model) {
141 if (model == MODEL_TYPE.XMI) {
142 processXMIEpackage(file);
148 private void processXMIEpackage(String xmiFile){
149 EPackage root = getEpackage(xmiFile);
150 TreeIterator<EObject> treeItr = root.eAllContents();
154 // Pulling out dependency from file
155 while (treeItr.hasNext()) {
156 EObject obj = treeItr.next();
157 if (obj instanceof EClassifier) {
158 EClassifier eClassifier = (EClassifier) obj;
159 className = eClassifier.getName();
161 if (obj instanceof EEnum) {
162 enumMap.putAll(getEEnum(obj));
163 }else if (obj instanceof EClass) {
164 String temp = getDependencyList(eClassifier).toString();
165 returnValue = StringUtils.replaceEach(temp, new String[]{"[", "]"}, new String[]{"", ""});
166 getAttributes(className, returnValue, root);
171 if (!enumMap.isEmpty()){
174 if (!matchingClass.isEmpty()){
175 checkForMatchingClass();
179 private void checkForMatchingClass() {
180 HashMap<String, String> tempAttribute = new HashMap<>();
182 for (Entry<String, String> set : matchingClass.entrySet()){
183 String key = set.getKey();
184 if (classMap.containsKey(key)){
185 Map<String, String> listAttributes = classMap.get(key).getAttribute();
186 Map<String, String> listRef = classMap.get(key).getRefAttribute();
187 for ( Entry<String, String> eSet : listAttributes.entrySet()){
188 String key2 = eSet.getKey();
189 tempAttribute.put(key2, MATCHINGTRUE);
191 for ( Entry<String, String> eSet : listRef.entrySet()){
192 String key3 = eSet.getKey();
193 tempAttribute.put(key3, MATCHINGTRUE);
197 updateMatching(tempAttribute, key);
204 private void updateMatching(HashMap<String, String> tempAttribute, String key) {
205 Map<String, MSAttributeObject> newClass = classMap;
207 for (Entry<String, MSAttributeObject> updateClass : newClass.entrySet()){
208 Map<String, String> valueMap = updateClass.getValue().getMatchingSet();
209 String keymap = updateClass.getKey();
210 if (valueMap.containsKey(key)){
211 Map<String, String> modifyMap = classMap.get(keymap).getMatchingSet();
212 modifyMap.remove(key);
213 modifyMap.putAll(tempAttribute);
214 classMap.get(keymap).setMatchingSet(modifyMap);
220 private void addEnumClassMap() {
221 for (Entry<String, MSAttributeObject> value :classMap.entrySet()){
222 value.getValue().setEnumType(enumMap);
226 private EPackage getEpackage(String xmiFile) {
227 ResourceSet resSet = new ResourceSetImpl();
228 Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
229 Map<String, Object> m = reg.getExtensionToFactoryMap();
230 m.put("xmi", new XMIResourceFactoryImpl());
231 Resource resource = resSet.getResource(URI.createFileURI(xmiFile), true);
233 resource.load(Collections.emptyMap());
234 } catch (IOException e) {
235 logger.error("Error loading Encore Resource for new Model" + e);
238 return (EPackage) resource.getContents().get(0);
241 private HashMap<String, String> getEEnum(EObject obj) {
242 List<String> valueList = new ArrayList<>();
243 HashMap<String, String> returnMap = new HashMap<>();
244 EEnum eenum = (EEnum)obj;
246 String name = eenum.getName();
247 for (EEnumLiteral eEnumLiteral : eenum.getELiterals())
249 Enumerator instance = eEnumLiteral.getInstance();
250 String value = instance.getLiteral();
251 valueList.add(value);
253 returnMap.put(name, valueList.toString());
257 public void getAttributes(String className, String dependency, EPackage root) {
258 List<String> dpendList = new ArrayList<>();
259 if (dependency!=null){
260 dpendList = new ArrayList<>(Arrays.asList(dependency.split(",")));
262 MSAttributeObject msAttributeObject = new MSAttributeObject();
263 msAttributeObject.setClassName(className);
264 String extendClass = getSubTypes(root, className);
265 Map<String, String> returnRefList = getRefAttributeList(root, className, extendClass);
266 Map<String, String> returnAttributeList = getAttributeList(root, className, extendClass);
267 Map<String, Object> returnSubList = getSubAttributeList(root, className, extendClass);
268 HashMap<String, String> returnAnnotation = getAnnotation(root, className, extendClass);
269 msAttributeObject.setAttribute(returnAttributeList);
270 msAttributeObject.setRefAttribute(returnRefList);
271 msAttributeObject.setSubClass(returnSubList);
272 msAttributeObject.setDependency(dpendList.toString());
273 msAttributeObject.addMatchingSet(returnAnnotation);
274 msAttributeObject.setPolicyTempalate(isPolicyTemplate(root, className));
276 this.classMap.put(className, msAttributeObject);
279 private HashMap<String, String> getAnnotation(EPackage root, String className, String extendClass) {
280 TreeIterator<EObject> treeItr = root.eAllContents();
281 boolean requiredAttribute = false;
282 boolean requiredMatchAttribute = false;
283 HashMap<String, String> annotationSet = new HashMap<>();
285 // Pulling out dependency from file
286 while (treeItr.hasNext()) {
287 EObject obj = treeItr.next();
288 if (obj instanceof EClassifier) {
289 requiredAttribute = isRequiredAttribute(obj, className );
290 requiredMatchAttribute = isRequiredAttribute(obj, extendClass );
293 if (requiredAttribute){
294 if (obj instanceof EStructuralFeature) {
295 checkAnnotation(annotationSet, (EStructuralFeature) obj);
297 } else if (requiredMatchAttribute && (obj instanceof EStructuralFeature)) {
298 findMatchingAnnotation(annotationSet, obj);
301 return annotationSet;
304 private void findMatchingAnnotation(HashMap<String, String> annotationSet, EObject obj) {
305 EStructuralFeature eStrucClassifier = (EStructuralFeature) obj;
306 if (eStrucClassifier.getEAnnotations().isEmpty()) {
309 String matching = annotationValue(eStrucClassifier, ANNOTATION_TYPE.MATCHING, policy);
311 if (obj instanceof EReference){
312 EClass refType = ((EReference) obj).getEReferenceType();
313 annotationSet.put(refType.getName(), matching);
314 matchingClass.put(refType.getName(), matching);
316 annotationSet.put(eStrucClassifier.getName(), matching);
322 private void checkAnnotation(HashMap<String, String> annotationSet, EStructuralFeature obj) {
323 EStructuralFeature eStrucClassifier = obj;
324 if (eStrucClassifier.getEAnnotations().isEmpty()) {
327 String matching = annotationValue(eStrucClassifier, ANNOTATION_TYPE.MATCHING, policy);
329 annotationSet.put(eStrucClassifier.getName(), matching);
331 String range = annotationValue(eStrucClassifier, ANNOTATION_TYPE.VALIDATION, policy);
333 annotationSet.put(eStrucClassifier.getName(), range);
335 String annotationDict = annotationValue(eStrucClassifier, ANNOTATION_TYPE.DICTIONARY, policy);
336 if (annotationDict!=null){
337 annotationSet.put(eStrucClassifier.getName(), annotationDict);
341 private Map<String, Object> getSubAttributeList(EPackage root, String className , String superClass) {
342 TreeIterator<EObject> treeItr = root.eAllContents();
343 boolean requiredAttribute = false;
344 Map<String, Object> subAttribute = new HashMap<>();
345 int rollingCount = 0;
346 int processClass = 0;
348 // Pulling out dependency from file
349 while (treeItr.hasNext() && rollingCount < 2) {
351 EObject obj = treeItr.next();
352 if (obj instanceof EClassifier) {
353 requiredAttribute = isRequiredAttribute(obj, className ) || isRequiredAttribute(obj, superClass );
354 if (requiredAttribute){
357 rollingCount = rollingCount+processClass;
360 if (requiredAttribute && (obj instanceof EStructuralFeature)) {
361 EStructuralFeature eStrucClassifier = (EStructuralFeature) obj;
362 if (!eStrucClassifier.getEAnnotations().isEmpty()) {
363 updateSubAttributes(subAttribute, obj, eStrucClassifier);
370 private void updateSubAttributes(Map<String, Object> subAttribute, EObject obj, EStructuralFeature eStrucClassifier) {
371 if (!(obj instanceof EReference)) {
374 if (annotationTest(eStrucClassifier, configuration, onap)) {
375 EClass refType = ((EReference) obj).getEReferenceType();
376 if(!refType.toString().contains(eProxyURI)){
377 String required = REQUIREDFALSE;
378 if(eStrucClassifier.getLowerBound() == 1){
379 required = REQUIREDTRUE;
381 subAttribute.put(eStrucClassifier.getName(), refType.getName() + required);
386 public String checkDefultValue(String defultValue) {
387 if (defultValue!=null){
388 return DEFAULTVALUE+ defultValue;
390 return ":defaultValue-NA";
394 public String checkRequiredPattern(int upper, int lower) {
395 String pattern = XACMLProperties.getProperty(XACMLRestProperties.PROP_XCORE_REQUIRED_PATTERN);
396 if (pattern!=null && upper == Integer.parseInt(pattern.split(",")[1]) && lower==Integer.parseInt(pattern.split(",")[0])){
399 return REQUIREDFALSE;
402 public JSONObject buildJavaObject(Map<String, String> map){
403 return new JSONObject(map);
406 public Map<String, String> getRefAttributeList(EPackage root, String className, String superClass){
408 TreeIterator<EObject> treeItr = root.eAllContents();
409 boolean requiredAttribute = false;
410 HashMap<String, String> refAttribute = new HashMap<>();
411 int rollingCount = 0;
412 int processClass = 0;
414 // Pulling out dependency from file
415 while (treeItr.hasNext()) {
416 EObject obj = treeItr.next();
417 if (obj instanceof EClassifier) {
418 requiredAttribute = isRequiredAttribute(obj, className ) || isRequiredAttribute(obj, superClass );
419 if (requiredAttribute){
422 rollingCount = rollingCount+processClass;
425 if (requiredAttribute && (obj instanceof EStructuralFeature)) {
426 EStructuralFeature eStrucClassifier = (EStructuralFeature) obj;
427 if (!eStrucClassifier.getEAnnotations().isEmpty()) {
428 annotation = annotationTest(eStrucClassifier, configuration, onap);
429 if ( annotation && obj instanceof EReference) {
430 updRefAttributes(refAttribute, (EStructuralFeature) obj, eStrucClassifier);
431 } else if (annotation && obj instanceof EAttributeImpl) {
432 updEnumTypeRefAttrib(refAttribute, (EStructuralFeature) obj, eStrucClassifier);
441 private void updEnumTypeRefAttrib(HashMap<String, String> refAttribute, EStructuralFeature obj, EStructuralFeature eStrucClassifier) {
442 EClassifier refType = ((EAttributeImpl) obj).getEType();
443 if (!(refType instanceof EEnumImpl)){
447 String array = arrayCheck(obj.getUpperBound());
448 String required = REQUIREDFALSE;
449 if(obj.getLowerBound() == 1){
450 required = REQUIREDTRUE;
452 refAttribute.put(eStrucClassifier.getName(), refType.getName() + array + required);
455 private void updRefAttributes(HashMap<String, String> refAttribute, EStructuralFeature obj, EStructuralFeature eStrucClassifier) {
456 EClass refType = ((EReference) obj).getEReferenceType();
457 if(refType.toString().contains(eProxyURI)){
458 String one = refType.toString().split(eProxyURI)[1];
459 String refValue = StringUtils.replaceEach(one.split("#")[1], new String[]{"//", ")"}, new String[]{"", ""});
460 refAttribute.put(eStrucClassifier.getName(), refValue);
462 String required = REQUIREDFALSE;
463 if(obj.getLowerBound() == 1){
464 required = REQUIREDTRUE;
466 refAttribute.put(eStrucClassifier.getName(), refType.getName() + arrayCheck(obj.getUpperBound()) + required);
470 private boolean annotationTest(EStructuralFeature eStrucClassifier, String annotation, String type) {
471 String annotationType;
472 EAnnotation eAnnotation;
476 EList<EAnnotation> value = eStrucClassifier.getEAnnotations();
478 for (int i = 0; i < value.size(); i++){
479 annotationType = value.get(i).getSource();
480 eAnnotation = eStrucClassifier.getEAnnotations().get(i);
481 onapType = eAnnotation.getDetails().get(0).getValue();
482 onapValue = eAnnotation.getDetails().get(0).getKey();
484 if (annotationType.contains(type) && onapType.contains(annotation)){
488 if (annotationType.contains(type) && onapValue.contains(annotation)){
497 private String annotationValue(EStructuralFeature eStrucClassifier, ANNOTATION_TYPE annotation, String type) {
498 String annotationType;
499 EAnnotation eAnnotation;
501 String onapValue = null;
503 EList<EAnnotation> value = eStrucClassifier.getEAnnotations();
505 for (int i = 0; i < value.size(); i++){
506 annotationType = value.get(i).getSource();
507 eAnnotation = eStrucClassifier.getEAnnotations().get(i);
508 onapType = eAnnotation.getDetails().get(0).getKey();
509 if (annotationType.contains(type) && onapType.compareToIgnoreCase(annotation.toString())==0){
510 onapValue = eAnnotation.getDetails().get(0).getValue();
511 if (annotation == ANNOTATION_TYPE.VALIDATION){
514 return onapType + "-" + onapValue;
521 public boolean isRequiredAttribute(EObject obj, String className){
522 EClassifier eClassifier = (EClassifier) obj;
523 String workingClass = eClassifier.getName().trim();
524 if (workingClass.equalsIgnoreCase(className)){
531 private boolean isPolicyTemplate(EPackage root, String className){
532 boolean result = false;
533 for (EClassifier classifier : root.getEClassifiers()){
534 if (classifier instanceof EClass) {
535 EClass eClass = (EClass)classifier;
536 if (eClass.getName().contentEquals(className)) {
537 result = checkPolicyTemplate(eClass);
545 private boolean checkPolicyTemplate(EClass eClass) {
546 EList<EAnnotation> value = eClass.getEAnnotations();
547 for (EAnnotation workingValue : value){
548 EMap<String, String> keyMap = workingValue.getDetails();
549 if (keyMap.containsKey("policyTemplate")){
556 private String getSubTypes(EPackage root, String className) {
557 String returnSubTypes = null;
558 for (EClassifier classifier : root.getEClassifiers()){
559 if (classifier instanceof EClass) {
560 returnSubTypes = findSubTypes(className, returnSubTypes, (EClass) classifier);
563 return returnSubTypes;
566 private String findSubTypes(String className, String returnSubTypes, EClass classifier) {
567 EClass eClass = classifier;
569 for (EClass eSuperType : eClass.getEAllSuperTypes())
571 if (eClass.getName().contentEquals(className)){
572 returnSubTypes = eSuperType.getName();
575 return returnSubTypes;
578 public Map<String, String> getAttributeList(EPackage root, String className, String superClass){
580 TreeIterator<EObject> treeItr = root.eAllContents();
581 boolean requiredAttribute = false;
582 HashMap<String, String> refAttribute = new HashMap<>();
584 // Pulling out dependency from file
585 while (treeItr.hasNext()) {
586 EObject obj = treeItr.next();
587 if (obj instanceof EClassifier) {
588 requiredAttribute = isRequiredAttribute(obj, className ) || isRequiredAttribute(obj, superClass );
591 if (requiredAttribute && (obj instanceof EStructuralFeature)) {
592 EStructuralFeature eStrucClassifier = (EStructuralFeature) obj;
593 if (!eStrucClassifier.getEAnnotations().isEmpty()) {
594 checkStrucClassifier(refAttribute, obj, eStrucClassifier);
602 private void checkStrucClassifier(HashMap<String, String> refAttribute, EObject obj, EStructuralFeature eStrucClassifier) {
603 EClassifier refType = ((EStructuralFeature) obj).getEType();
604 boolean annotation = annotationTest(eStrucClassifier, configuration, onap);
605 boolean dictionaryTest = annotationTest(eStrucClassifier, dictionary, policy);
606 if (annotation && !(obj instanceof EReference) && !(refType instanceof EEnumImpl)) {
607 updEReferenceAttrib(refAttribute, dictionaryTest, (EStructuralFeature) obj, eStrucClassifier);
611 private void updEReferenceAttrib(HashMap<String, String> refAttribute, boolean dictionaryTest, EStructuralFeature obj, EStructuralFeature eStrucClassifier) {
613 String name = eStrucClassifier.getName();
615 eType = annotationValue(eStrucClassifier, ANNOTATION_TYPE.DICTIONARY, policy);
617 eType = eStrucClassifier.getEType().getInstanceClassName();
619 String defaultValue = checkDefultValue(obj.getDefaultValueLiteral());
620 String array = arrayCheck(obj.getUpperBound());
621 String required = checkRequiredPattern(obj.getUpperBound(), obj.getLowerBound());
622 refAttribute.put(name, eType + defaultValue + required + array);
625 public String arrayCheck(int upperBound) {
627 if (upperBound == -1){
634 public List<String> getDependencyList(EClassifier eClassifier){
635 List<String> returnValue = new ArrayList<>();;
636 EList<EClass> somelist = ((EClass) eClassifier).getEAllSuperTypes();
637 if (somelist.isEmpty()){
640 for(EClass depend: somelist){
641 if (depend.toString().contains(eProxyURI)){
642 String one = depend.toString().split(eProxyURI)[1];
643 String value = StringUtils.replaceEach(one.split("#")[1], new String[]{"//", ")"}, new String[]{"", ""});
644 returnValue.add(value);
651 public Map<String, String> buildSubList(Map<String, String> subClassAttributes, Map<String, MSAttributeObject> classMap, String className){
652 Map<String, String> missingValues = new HashMap<>();
653 Map<String, String> workingMap;
656 for ( Entry<String, String> map : classMap.get(className).getRefAttribute().entrySet()){
657 String value = map.getValue().split(":")[0];
659 classMap.get(className).getEnumType();
660 enumType = classMap.get(className).getEnumType().containsKey(value);
662 workingMap = classMap.get(value).getRefAttribute();
663 for ( Entry<String, String> subMab : workingMap.entrySet()){
664 String value2 = subMab.getValue().split(":")[0];
665 if (!subClassAttributes.containsValue(value2)){
666 missingValues.put(subMab.getKey(), subMab.getValue());
674 return missingValues;
677 public Map<String, Map<String, String>> recursiveReference(Map<String, MSAttributeObject> classMap, String className){
679 Map<String, Map<String, String>> returnObject = new HashMap<>();
680 Map<String, String> returnClass = getRefclass(classMap, className);
681 returnObject.put(className, returnClass);
682 for (Entry<String, String> reAttribute :returnClass.entrySet()){
683 if (reAttribute.getValue().split(":")[1].contains("MANY") &&
684 classMap.get(reAttribute.getValue().split(":")[0]) != null){
685 returnObject.putAll(recursiveReference(classMap, reAttribute.getValue().split(":")[0]));
694 public String createJson(Map<String, MSAttributeObject> classMap, String className) {
696 Map<String, Map<String, String>> myObject = new HashMap<>();
697 for ( Entry<String, String> map : classMap.get(className).getRefAttribute().entrySet()){
698 String value = map.getValue().split(":")[0];
700 enumType = classMap.get(className).getEnumType().containsKey(value);
701 if (!enumType && map.getValue().split(":")[1].contains("MANY")){
702 Map<String, Map<String, String>> testRecursive = recursiveReference(classMap, map.getValue().split(":")[0] );
703 myObject.putAll(testRecursive);
708 Gson gson = new Gson();
709 return gson.toJson(myObject);
712 public Map<String, String> getRefclass(Map<String, MSAttributeObject> classMap, String className){
713 HashMap<String, String> missingValues = new HashMap<>();
715 if (classMap.get(className).getAttribute()!=null || !classMap.get(className).getAttribute().isEmpty()){
716 missingValues.putAll(classMap.get(className).getAttribute());
719 if (classMap.get(className).getRefAttribute()!=null || !classMap.get(className).getRefAttribute().isEmpty()){
720 missingValues.putAll(classMap.get(className).getRefAttribute());
723 return missingValues;
726 public String createSubAttributes(List<String> dependency, Map<String, MSAttributeObject> classMap, String modelName) {
728 HashMap <String, Object> workingMap = new HashMap<>();
729 MSAttributeObject tempObject;
730 if (dependency!=null){
731 if (dependency.isEmpty()){
734 dependency.add(modelName);
735 for (String element: dependency){
736 tempObject = classMap.get(element);
737 if (tempObject!=null){
738 workingMap.putAll(classMap.get(element).getSubClass());
743 return createJson(classMap, modelName);
746 public List<String> getFullDependencyList(List<String> dependency, Map<String,MSAttributeObject > classMap) {
747 ArrayList<String> returnList = new ArrayList<>();
748 ArrayList<String> workingList;
749 returnList.addAll(dependency);
750 for (String element : dependency ){
751 if (classMap.containsKey(element)){
752 MSAttributeObject value = classMap.get(element);
753 String rawValue = StringUtils.replaceEach(value.getDependency(), new String[]{"[", "]"}, new String[]{"", ""});
754 workingList = new ArrayList<>(Arrays.asList(rawValue.split(",")));
755 for(String depend : workingList) {
756 updDependencyList(returnList, depend);
764 private void updDependencyList(ArrayList<String> returnList, String depend) {
765 if (!returnList.contains(depend) && !depend.isEmpty()){
766 returnList.add(depend.trim());
773 public String parseTosca(String fileName) {
774 Map<String, String> map = new LinkedHashMap<>();
776 map = load(fileName);
777 if (map != null && map.get(ERROR) != null) {
778 return map.get(ERROR);
780 parseDataAndPolicyNodes(map);
781 LinkedHashMap<String, String> dataMapForJson = parseDataNodes(map);
782 constructJsonForDataFields(dataMapForJson);
783 LinkedHashMap<String, LinkedHashMap<String, String>> mapKey = parsePolicyNodes(map);
784 createAttributes(mapKey);
786 } catch (IOException e) {
788 } catch (ParserException e) {
790 return e.getMessage();
796 @SuppressWarnings("unchecked")
797 public Map<String, String> load(String fileName) throws IOException, ParserException {
798 File newConfiguration = new File(fileName);
799 StringBuilder orderInfo = new StringBuilder("[");
800 Yaml yaml = new Yaml();
801 LinkedHashMap<Object, Object> yamlMap = null;
802 try (InputStream is = new FileInputStream(newConfiguration)) {
803 yamlMap = (LinkedHashMap<Object, Object>) yaml.load(is);
804 } catch (FileNotFoundException e) {
806 } catch (Exception e) {
808 throw new ParserException("Invalid TOSCA Model format. Please make sure it is a valid YAML file");
811 StringBuilder sb = new StringBuilder();
812 LinkedHashMap<String, String> settings = new LinkedHashMap<>();
813 if (yamlMap == null) {
817 String message = validations(yamlMap);
819 if (message != null) {
820 settings.put(ERROR, message);
826 if (!isDuplicatedAttributes && orderedElements != null && !orderedElements.isEmpty()) {
827 orderedElements.stream().forEach(string -> {
828 orderInfo.append(string);
829 orderInfo.append(",");
830 logger.info("Content: " + string);
833 orderInfo.append("]");
835 dataOrderInfo = orderInfo.toString();
836 dataOrderInfo = dataOrderInfo.replace(",]", "]");
838 logger.info("dataOrderInfo :" + dataOrderInfo);
841 List<String> path = new ArrayList<>();
842 serializeMap(settings, sb, path, yamlMap);
846 @SuppressWarnings("unchecked")
847 private String validations(@SuppressWarnings("rawtypes") LinkedHashMap yamlMap) {
849 boolean isNoteTypeFound = false;
850 boolean isDataTypeFound = false;
851 boolean isToscaVersionKeyFound = false;
852 boolean isToscaVersionValueFound = false;
853 @SuppressWarnings("rawtypes")
854 Map m1 = new HashMap();
856 if (yamlMap != null) {
857 // Get a set of the entries
858 @SuppressWarnings("rawtypes")
859 Set set = yamlMap.entrySet();
861 @SuppressWarnings("rawtypes")
862 Iterator i = set.iterator();
864 while (i.hasNext()) {
865 @SuppressWarnings("rawtypes")
866 Map.Entry me = (Map.Entry) i.next();
868 if (TOSCA_DEFINITION_VERSION.equals(me.getKey())) {
869 isToscaVersionKeyFound = true;
871 m1.put(TOSCA_DEFINITION_VERSION, order);
874 if ("tosca_simple_yaml_1_0_0".equals(me.getValue())) {
875 isToscaVersionValueFound = true;
878 if (NODE_TYPE.equals(me.getKey())) {
879 isNoteTypeFound = true;
881 m1.put(NODE_TYPE, order);
884 if (DATA_TYPE.equals(me.getKey())) {
885 isDataTypeFound = true;
887 m1.put(DATA_TYPE, order);
892 if (!isToscaVersionKeyFound || !isToscaVersionValueFound) {
893 return "tosca_definitions_version is missing or invalid.";
896 if (!isNoteTypeFound) {
897 return "node_types are missing or invalid.";
900 short version = (short) m1.get(TOSCA_DEFINITION_VERSION);
903 return "tosca_definitions_version should be defined first.";
906 short data = (short) m1.get(DATA_TYPE);
907 short node = (short) m1.get(NODE_TYPE);
908 if (isDataTypeFound && node > data) {
909 return "node_types should be defined before data_types.";
917 @SuppressWarnings({"unchecked", "rawtypes"})
918 private void serializeMap(LinkedHashMap<String, String> settings, StringBuilder sb, List<String> path,
919 Map<Object, Object> yamlMap) {
920 for (Map.Entry<Object, Object> entry : yamlMap.entrySet()) {
922 if (entry.getValue() instanceof Map) {
923 path.add((String) entry.getKey());
924 serializeMap(settings, sb, path, (Map<Object, Object>) entry.getValue());
925 path.remove(path.size() - 1);
926 } else if (entry.getValue() instanceof List) {
927 path.add((String) entry.getKey());
928 serializeList(settings, sb, path, (List) entry.getValue());
929 path.remove(path.size() - 1);
931 serializeValue(settings, sb, path, (String) entry.getKey(), entry.getValue());
936 @SuppressWarnings("unchecked")
937 private void serializeList(LinkedHashMap<String, String> settings, StringBuilder sb, List<String> path,
938 List<String> yamlList) {
940 for (Object listEle : yamlList) {
941 if (listEle instanceof Map) {
942 path.add(Integer.toString(counter));
943 serializeMap(settings, sb, path, (Map<Object, Object>) listEle);
944 path.remove(path.size() - 1);
945 } else if (listEle instanceof List) {
946 path.add(Integer.toString(counter));
947 serializeList(settings, sb, path, (List<String>) listEle);
948 path.remove(path.size() - 1);
950 serializeValue(settings, sb, path, Integer.toString(counter), listEle);
956 private void serializeValue(LinkedHashMap<String, String> settings, StringBuilder sb, List<String> path,
957 String name, Object value) {
962 for (String pathEle : path) {
963 sb.append(pathEle).append('.');
966 settings.put(sb.toString(), value.toString());
970 void parseDataAndPolicyNodes(Map<String, String> map) {
971 for (String key : map.keySet()) {
972 if (key.contains("policy.nodes.Root")) {
974 } else if (key.contains("policy.nodes")) {
975 String wordToFind = "policy.nodes.";
976 int indexForPolicyNode = key.indexOf(wordToFind);
977 String subNodeString = key.substring(indexForPolicyNode + 13, key.length());
979 stringBetweenDots(subNodeString);
980 } else if (key.contains("policy.data")) {
981 String wordToFind = "policy.data.";
982 int indexForPolicyNode = key.indexOf(wordToFind);
983 String subNodeString = key.substring(indexForPolicyNode + 12, key.length());
985 stringBetweenDotsForDataFields(subNodeString);
990 // Second index of dot should be returned.
991 public int stringBetweenDots(String str) {
992 String stringToSearch = str;
993 String[] ss = stringToSearch.split("\\.");
997 uniqueKeys.add(ss[2]);
1001 return uniqueKeys.size();
1005 public void stringBetweenDotsForDataFields(String str) {
1006 String stringToSearch = str;
1007 String[] ss = stringToSearch.split("\\.");
1009 int len = ss.length;
1012 uniqueDataKeys.add(ss[0] + "%" + ss[2]);
1017 void constructJsonForDataFields(LinkedHashMap<String, String> dataMapForJson) {
1018 LinkedHashMap<String, LinkedHashMap<String, String>> dataMapKey = new LinkedHashMap<>();
1019 LinkedHashMap<String, String> hmSub;
1020 for (Map.Entry<String, String> entry : dataMapForJson.entrySet()) {
1021 String uniqueDataKey = entry.getKey();
1022 String[] uniqueDataKeySplit = uniqueDataKey.split("%");
1023 String value = dataMapForJson.get(uniqueDataKey);
1024 if (dataMapKey.containsKey(uniqueDataKeySplit[0])) {
1025 hmSub = dataMapKey.get(uniqueDataKeySplit[0]);
1026 hmSub.put(uniqueDataKeySplit[1], value);
1028 hmSub = new LinkedHashMap<>();
1029 hmSub.put(uniqueDataKeySplit[1], value);
1032 dataMapKey.put(uniqueDataKeySplit[0], hmSub);
1035 JSONObject mainObject = new JSONObject();
1037 for (Map.Entry<String, LinkedHashMap<String, String>> entry : dataMapKey.entrySet()) {
1038 String s = entry.getKey();
1039 json = new JSONObject();
1040 HashMap<String, String> jsonHm = dataMapKey.get(s);
1041 for (Map.Entry<String, String> entryMap : jsonHm.entrySet()) {
1042 String key = entryMap.getKey();
1043 json.put(key, jsonHm.get(key));
1045 mainObject.put(s, json);
1047 Iterator<String> keysItr = mainObject.keys();
1048 while (keysItr.hasNext()) {
1049 String key = keysItr.next();
1050 String value = mainObject.get(key).toString();
1051 retmap.put(key, value);
1054 logger.info("#############################################################################");
1055 logger.info(mainObject);
1056 logger.info("###############################################################################");
1059 LinkedHashMap<String, String> parseDataNodes(Map<String, String> map) {
1060 LinkedHashMap<String, String> dataMapForJson = new LinkedHashMap<>();
1061 matchableValues = new HashMap<>();
1062 for (String uniqueDataKey : uniqueDataKeys) {
1063 if (uniqueDataKey.contains("%")) {
1064 String[] uniqueDataKeySplit = uniqueDataKey.split("%");
1065 String findType = DATATYPE + uniqueDataKeySplit[0] + PROPERTIES + uniqueDataKeySplit[1] + TYPE;
1066 String typeValue = map.get(findType);
1067 logger.info(typeValue);
1069 String findRequired = DATATYPE + uniqueDataKeySplit[0] + PROPERTIES + uniqueDataKeySplit[1] + REQUIRED;
1070 String requiredValue = map.get(findRequired);
1072 String matchable = DATATYPE + uniqueDataKeySplit[0] + PROPERTIES + uniqueDataKeySplit[1] + MATCHABLE;
1074 String matchableValue = map.get(matchable);
1076 if ("true".equalsIgnoreCase(matchableValue)) {
1077 String key = uniqueDataKeySplit[uniqueDataKeySplit.length - 1];
1078 matchableValues.put(key, MATCHINGTRUE);
1081 if (requiredValue == null || requiredValue.isEmpty()) {
1082 requiredValue = "false";
1084 if (INTEGER.equalsIgnoreCase(typeValue) || STRING.equalsIgnoreCase(typeValue)
1085 || typeValue.equalsIgnoreCase(BOOLEAN)) {
1086 String findDefault =
1087 DATATYPE + uniqueDataKeySplit[0] + PROPERTIES + uniqueDataKeySplit[1] + DEFAULT;
1088 String findDescription =
1089 DATATYPE + uniqueDataKeySplit[0] + PROPERTIES + uniqueDataKeySplit[1] + DESCRIPTION;
1090 String defaultValue = map.get(findDefault);
1091 String descriptionDefined = map.get(findDescription);
1092 logger.info("defaultValue is:" + defaultValue);
1093 logger.info("requiredValue is:" + requiredValue);
1095 StringBuilder attributeIndividualStringBuilder = new StringBuilder();
1096 attributeIndividualStringBuilder.append(typeValue + DEFAULTVALUE);
1097 attributeIndividualStringBuilder.append(defaultValue + REQUIREDVALUE);
1098 attributeIndividualStringBuilder.append(requiredValue + MANYFALSE);
1099 attributeIndividualStringBuilder.append(DESCRIPTION_TOKEN + descriptionDefined);
1100 dataMapForJson.put(uniqueDataKey, attributeIndividualStringBuilder.toString());
1101 } else if (LIST.equalsIgnoreCase(typeValue) || MAP.equalsIgnoreCase(typeValue)) {
1102 logger.info("requiredValue is:" + requiredValue);
1104 DATATYPE + uniqueDataKeySplit[0] + PROPERTIES + uniqueDataKeySplit[1]
1105 + ".entry_schema.type";
1106 String findDefaultValue =
1107 DATATYPE + uniqueDataKeySplit[0] + PROPERTIES + uniqueDataKeySplit[1]
1108 + ".entry_schema.default";
1109 String findDescription =
1110 DATATYPE + uniqueDataKeySplit[0] + PROPERTIES + uniqueDataKeySplit[1]
1111 + ".entry_schema.description";
1112 String listValue = map.get(findList);
1113 String defaultValue = map.get(findDefaultValue);
1114 String description = map.get(findDescription);
1115 if (listValue != null) {
1116 logger.info("Type of list is:" + listValue);
1118 if (listValue.contains(".")) {
1119 String trimValue = listValue.substring(listValue.lastIndexOf('.') + 1);
1120 StringBuilder referenceIndividualStringBuilder = new StringBuilder();
1121 referenceIndividualStringBuilder.append(trimValue + REQUIREDVALUE);
1122 referenceIndividualStringBuilder.append(requiredValue + MANYTRUE);
1123 referenceIndividualStringBuilder.append(DESCRIPTION_TOKEN + description);
1124 dataMapForJson.put(uniqueDataKey, referenceIndividualStringBuilder.toString());
1125 } else { // Its string
1126 StringBuilder stringListItems = new StringBuilder();
1127 if (LIST.equalsIgnoreCase(typeValue)) {
1128 stringListItems.append(uniqueDataKeySplit[1].toUpperCase() + DEFAULTVALUE
1129 + defaultValue + REQUIREDVALUE + requiredValue + MANYFALSE + DESCRIPTION_TOKEN
1131 } else if (MAP.equalsIgnoreCase(typeValue)) {
1132 stringListItems.append(uniqueDataKeySplit[1].toUpperCase() + DEFAULTVALUE
1133 + defaultValue + REQUIREDVALUE + requiredValue + MANYTRUE + DESCRIPTION_TOKEN
1136 dataMapForJson.put(uniqueDataKey, stringListItems.toString());
1137 dataListBuffer.append(uniqueDataKeySplit[1].toUpperCase() + "=[");
1138 for (int i = 0; i < 10; i++) {
1139 String findConstraints =
1140 DATATYPE + uniqueDataKeySplit[0] + PROPERTIES + uniqueDataKeySplit[1]
1141 + ".entry_schema.constraints.0.valid_values." + i;
1142 String constraintsValue = map.get(findConstraints);
1143 logger.info(constraintsValue);
1144 if (constraintsValue == null) {
1147 logger.info("constraintsValue => " + constraintsValue);
1148 if (constraintsValue.contains("=")) {
1149 constraintsValue = constraintsValue.replace("=", "equal-sign");
1151 dataConstraints.add(constraintsValue);
1152 dataListBuffer.append(constraintsValue + ",");
1155 dataListBuffer.append("]#");
1156 logger.info(dataListBuffer);
1160 String findUserDefined =
1161 DATATYPE + uniqueDataKeySplit[0] + "." + PROPERTIES_KEY + "." + uniqueDataKeySplit[1]
1163 String findDescription =
1164 DATATYPE + uniqueDataKeySplit[0] + "." + PROPERTIES_KEY + "." + uniqueDataKeySplit[1]
1166 String userDefinedValue = map.get(findUserDefined);
1167 String description = map.get(findDescription);
1168 String trimValue = userDefinedValue.substring(userDefinedValue.lastIndexOf('.') + 1);
1169 StringBuilder referenceIndividualStringBuilder = new StringBuilder();
1170 referenceIndividualStringBuilder.append(trimValue + REQUIREDVALUE);
1171 referenceIndividualStringBuilder.append(requiredValue + MANYFALSE);
1172 referenceIndividualStringBuilder.append(DESCRIPTION_TOKEN + description);
1173 dataMapForJson.put(uniqueDataKey, referenceIndividualStringBuilder.toString());
1177 matchableValues.put(uniqueDataKey, MATCHINGTRUE);
1181 return dataMapForJson;
1184 LinkedHashMap<String, LinkedHashMap<String, String>> parsePolicyNodes(Map<String, String> map)
1185 throws ParserException {
1186 LinkedHashMap<String, LinkedHashMap<String, String>> mapKey = new LinkedHashMap<>();
1187 for (String uniqueKey : uniqueKeys) {
1188 LinkedHashMap<String, String> hm;
1190 for (Entry<String, String> entry : map.entrySet()) {
1191 String key = entry.getKey();
1192 if (key.contains(uniqueKey) && key.contains("policy.nodes")) {
1193 if (mapKey.containsKey(uniqueKey)) {
1194 hm = mapKey.get(uniqueKey);
1195 String keyStr = key.substring(key.lastIndexOf('.') + 1);
1196 String valueStr = map.get(key);
1197 if ("type".equalsIgnoreCase(keyStr)
1198 && key.contains("entry_schema.0.type") || key.contains("entry_schema.type")
1199 && valueStr.contains("policy.data.")) {
1200 throw new ParserException(
1201 "For user defined object type, Please make sure no space between 'type:' and object "
1205 if ("type".equals(keyStr)) {
1206 if (!key.contains("entry_schema")) {
1207 hm.put(keyStr, valueStr);
1210 hm.put(keyStr, valueStr);
1214 hm = new LinkedHashMap<>();
1215 String keyStr = key.substring(key.lastIndexOf('.') + 1);
1216 String valueStr = map.get(key);
1218 if (("type").equals(keyStr)) {
1219 if (!key.contains("entry_schema")) {
1220 hm.put(keyStr, valueStr);
1223 hm.put(keyStr, valueStr);
1225 mapKey.put(uniqueKey, hm);
1233 void createAttributes(LinkedHashMap<String, LinkedHashMap<String, String>> mapKey) {
1234 StringBuilder attributeStringBuilder = new StringBuilder();
1235 StringBuilder referenceStringBuilder = new StringBuilder();
1236 StringBuilder listBuffer = new StringBuilder();
1237 List<String> constraints = new ArrayList<>();
1238 for (Map.Entry<String, LinkedHashMap<String, String>> entry : mapKey.entrySet()) {
1239 String keySetString = entry.getKey();
1240 LinkedHashMap<String, String> keyValues = mapKey.get(keySetString);
1241 if (keyValues.get("type") != null && (STRING.equalsIgnoreCase(keyValues.get("type"))
1242 || INTEGER.equalsIgnoreCase(keyValues.get("type"))
1243 || BOOLEAN.equalsIgnoreCase(keyValues.get("type")))) {
1244 StringBuilder attributeIndividualStringBuilder = new StringBuilder();
1245 attributeIndividualStringBuilder.append(keySetString + "=");
1246 attributeIndividualStringBuilder.append(keyValues.get("type") + DEFAULTVALUE);
1247 attributeIndividualStringBuilder.append(keyValues.get("default") + REQUIREDVALUE);
1248 attributeIndividualStringBuilder.append(keyValues.get("required") + MANYFALSE);
1249 attributeIndividualStringBuilder.append(DESCRIPTION_TOKEN + keyValues.get(DESCRIPTION_KEY));
1250 attributeStringBuilder.append(attributeIndividualStringBuilder + ",");
1251 if (keyValues.get(MATCHABLEKEY) != null && "true".equalsIgnoreCase(keyValues.get(MATCHABLEKEY))) {
1252 matchableValues.put(keySetString, MATCHINGTRUE);
1254 } else if (LIST.equalsIgnoreCase(keyValues.get("type"))) {
1255 if ("true".equalsIgnoreCase(keyValues.get(MATCHABLEKEY))) {
1256 matchableValues.put(keySetString, MATCHINGTRUE);
1259 Set<String> keys = keyValues.keySet();
1260 Iterator<String> itr = keys.iterator();
1261 boolean isDefinedType = false;
1262 while (itr.hasNext()) {
1263 String key = itr.next();
1264 if ((!("type").equals(key) || ("required").equals(key))) {
1265 String value = keyValues.get(key);
1266 // The "." in the value determines if its a string or a user defined type.
1267 if (!value.contains(".")) {
1269 if (StringUtils.isNumeric(key)) { // only integer key for the value of Constrains
1270 constraints.add(keyValues.get(key));
1273 // This is user defined type
1274 String trimValue = value.substring(value.lastIndexOf('.') + 1);
1275 StringBuilder referenceIndividualStringBuilder = new StringBuilder();
1276 referenceIndividualStringBuilder.append(keySetString + "=" + trimValue + MANYTRUE
1277 + DESCRIPTION_TOKEN + keyValues.get(DESCRIPTION_KEY));
1278 referenceStringBuilder.append(referenceIndividualStringBuilder + ",");
1279 isDefinedType = true;
1285 if (!isDefinedType && LIST.equalsIgnoreCase(keyValues.get("type"))) {
1286 if (constraints == null || constraints.isEmpty()) {
1287 referenceStringBuilder.append(keySetString + "=MANY-true" + ",");
1291 // User defined Datatype.
1292 if ("true".equalsIgnoreCase(keyValues.get(MATCHABLEKEY))) {
1293 matchableValues.put(keySetString, MATCHINGTRUE);
1295 String value = keyValues.get("type");
1296 if (value != null && !value.isEmpty()) {
1297 String trimValue = value.substring(value.lastIndexOf('.') + 1);
1298 StringBuilder referenceIndividualStringBuilder = new StringBuilder();
1299 referenceIndividualStringBuilder.append(keySetString + "=" + trimValue + MANYFALSE
1300 + DESCRIPTION_TOKEN + keyValues.get(DESCRIPTION_KEY));
1301 referenceStringBuilder.append(referenceIndividualStringBuilder + ",");
1303 logger.info("keyValues.get(type) is null/empty");
1307 if (constraints != null && !constraints.isEmpty()) {
1309 listBuffer.append(keySetString.toUpperCase() + "=[");
1310 for (String str : constraints) {
1311 listBuffer.append(str + ",");
1313 listBuffer.append("]#");
1314 logger.info(listBuffer);
1317 StringBuilder referenceIndividualStringBuilder = new StringBuilder();
1318 referenceIndividualStringBuilder.append(keySetString + "=" + keySetString.toUpperCase() + MANYFALSE);
1319 referenceStringBuilder.append(referenceIndividualStringBuilder + ",");
1320 constraints.clear();
1324 dataListBuffer.append(listBuffer);
1327 logger.info("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
1328 logger.info("Whole attribute String is:" + attributeStringBuilder);
1329 logger.info("Whole reference String is:" + referenceStringBuilder);
1330 logger.info("List String is:" + listBuffer);
1331 logger.info("Data list buffer is:" + dataListBuffer);
1332 logger.info("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
1334 this.listConstraints = dataListBuffer.toString();
1335 this.referenceAttributes = referenceStringBuilder.toString();
1336 this.attributeString = attributeStringBuilder.toString();
1339 @SuppressWarnings("unchecked")
1340 private void findNode(LinkedHashMap<Object, Object> map) {
1342 map.forEach((key, value) -> {
1343 // if the value is properties and its type is map object, then save all the keys
1344 if (key.equals(PROPERTIES_KEY) && value instanceof Map) {
1345 saveNodes((LinkedHashMap<?, ?>) value);
1346 if (isDuplicatedAttributes) {
1347 orderedElements = new ArrayList<>();
1352 if (!"policy.nodes.Root".equals(key) && value instanceof Map) {
1353 // value is a Map object, then make a recursive call
1354 findNode((LinkedHashMap<Object, Object>) value);
1360 private void saveNodes(LinkedHashMap<?, ?> map) {
1362 for (Entry<?, ?> entry : map.entrySet()) {
1364 if (orderedElements.indexOf((String) entry.getKey()) >= 0) { // duplicated attribute names
1365 isDuplicatedAttributes = true;
1368 orderedElements.add((String) entry.getKey());
1373 public String getAttributeString() {
1374 return attributeString;
1377 public void setAttributeString(String attributeString) {
1378 this.attributeString = attributeString;
1381 public LinkedHashMap<String, Object> getRetmap() {
1385 public void setRetmap(LinkedHashMap<String, Object> retmap) {
1386 this.retmap = retmap;
1389 public Map<String, String> getMatchableValues() {
1390 return matchableValues;
1393 public void setMatchableValues(Map<String, String> matchableValues) {
1394 this.matchableValues = matchableValues;
1397 public String getReferenceAttributes() {
1398 return referenceAttributes;
1401 public void setReferenceAttributes(String referenceAttributes) {
1402 this.referenceAttributes = referenceAttributes;
1405 public String getListConstraints() {
1406 return listConstraints;
1409 public void setListConstraints(String listConstraints) {
1410 this.listConstraints = listConstraints;
1413 public String getDataOrderInfo() {
1414 return dataOrderInfo;
1417 public void setDataOrderInfo(String dataOrderInfo) {
1418 this.dataOrderInfo = dataOrderInfo;