Fixed the Sonar technical debt.
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / util / MSModelUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-REST
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.rest.util;
22
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.Collections;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Map.Entry;
31
32 import org.apache.commons.lang.StringUtils;
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35 import org.eclipse.emf.common.util.EList;
36 import org.eclipse.emf.common.util.EMap;
37 import org.eclipse.emf.common.util.Enumerator;
38 import org.eclipse.emf.common.util.TreeIterator;
39 import org.eclipse.emf.common.util.URI;
40 import org.eclipse.emf.ecore.EAnnotation;
41 import org.eclipse.emf.ecore.EClass;
42 import org.eclipse.emf.ecore.EClassifier;
43 import org.eclipse.emf.ecore.EEnum;
44 import org.eclipse.emf.ecore.EEnumLiteral;
45 import org.eclipse.emf.ecore.EObject;
46 import org.eclipse.emf.ecore.EPackage;
47 import org.eclipse.emf.ecore.EReference;
48 import org.eclipse.emf.ecore.EStructuralFeature;
49 import org.eclipse.emf.ecore.impl.EAttributeImpl;
50 import org.eclipse.emf.ecore.impl.EEnumImpl;
51 import org.eclipse.emf.ecore.resource.Resource;
52 import org.eclipse.emf.ecore.resource.ResourceSet;
53 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
54 import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
55 import org.json.JSONObject;
56 import org.onap.policy.rest.XACMLRestProperties;
57
58 import com.att.research.xacml.util.XACMLProperties;
59 import com.google.gson.Gson;
60
61
62 public class MSModelUtils {
63
64         private static final Log logger = LogFactory.getLog(MSModelUtils.class);
65
66         private HashMap<String,MSAttributeObject > classMap = new HashMap<>();
67         private HashMap<String, String> enumMap = new HashMap<>();
68         private HashMap<String, String> matchingClass = new HashMap<>();
69         private String configuration = "configuration";
70         private String dictionary = "dictionary";
71         private String onap = "";
72         private String policy = "";
73         private String eProxyURI = "eProxyURI:";
74         
75         public MSModelUtils(String onap, String policy){
76                 this.onap = onap;
77                 this.policy = policy;
78         }
79
80         private enum ANNOTATION_TYPE{
81                 MATCHING, VALIDATION, DICTIONARY
82         };
83
84         public enum MODEL_TYPE {
85                 XMI
86         };
87
88
89         public Map<String, MSAttributeObject> processEpackage(String file, MODEL_TYPE model){
90                 if (model == MODEL_TYPE.XMI ){
91                         processXMIEpackage(file);
92                 }
93                 return classMap;
94
95         } 
96
97         private void processXMIEpackage(String xmiFile){
98                 EPackage root = getEpackage(xmiFile);
99                 TreeIterator<EObject> treeItr = root.eAllContents();
100                 String className;
101                 String returnValue;
102
103                 //    Pulling out dependency from file
104                 while (treeItr.hasNext()) {         
105                         EObject obj = (EObject) treeItr.next();
106                         if (obj instanceof EClassifier) {
107                                 EClassifier eClassifier = (EClassifier) obj;
108                                 className = eClassifier.getName();
109
110                                 if (obj instanceof EEnum) {
111                                         enumMap.putAll(getEEnum(obj));
112                                 }else if (obj instanceof EClass) {
113                                         String temp = getDependencyList(eClassifier, className).toString();
114                                         returnValue = StringUtils.replaceEach(temp, new String[]{"[", "]"}, new String[]{"", ""});
115                                         getAttributes(className, returnValue, root);
116                                 }                                       
117                         }
118                 }
119
120                 if (!enumMap.isEmpty()){
121                         addEnumClassMap();
122                 }
123                 if (!matchingClass.isEmpty()){
124                         CheckForMatchingClass();
125                 }
126         }
127
128         private void CheckForMatchingClass() {
129                 HashMap<String, String> tempAttribute = new HashMap<>();
130
131                 for (Entry<String, String> set : matchingClass.entrySet()){
132                         String key = set.getKey();
133                         if (classMap.containsKey(key)){
134                                 Map<String, String> listAttributes = classMap.get(key).getAttribute();
135                                 Map<String, String> listRef = classMap.get(key).getRefAttribute();
136                                 for (  Entry<String, String> eSet : listAttributes.entrySet()){
137                                         String key2 = eSet.getKey();
138                                         tempAttribute.put(key2, "matching-true");
139                                 }
140                                 for (  Entry<String, String> eSet : listRef.entrySet()){
141                                         String key3 = eSet.getKey();
142                                         tempAttribute.put(key3, "matching-true");
143                                 }
144
145                         }
146                         UpdateMatching(tempAttribute, key);
147                 }
148
149         }
150
151
152
153         private void UpdateMatching(HashMap<String, String> tempAttribute, String key) {
154                 Map<String, MSAttributeObject> newClass = classMap;
155
156                 for (Entry<String, MSAttributeObject> updateClass :  newClass.entrySet()){
157                         Map<String, String> valueMap = updateClass.getValue().getMatchingSet();
158                         String keymap = updateClass.getKey();
159                         if (valueMap.containsKey(key)){
160                                 Map<String, String> modifyMap = classMap.get(keymap).getMatchingSet();
161                                 modifyMap.remove(key);
162                                 modifyMap.putAll(tempAttribute);
163                                 classMap.get(keymap).setMatchingSet(modifyMap);
164                         }
165
166                 }
167         }
168
169         private void addEnumClassMap() {
170                 for (Entry<String, MSAttributeObject> value :classMap.entrySet()){
171                         value.getValue().setEnumType(enumMap);
172                 }
173         }
174
175         private EPackage getEpackage(String xmiFile) {
176                 ResourceSet resSet = new ResourceSetImpl();
177                 Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
178                 Map<String, Object> m = reg.getExtensionToFactoryMap();
179                 m.put("xmi", new XMIResourceFactoryImpl());
180                 Resource resource = resSet.getResource(URI.createFileURI(xmiFile), true);
181                 try {
182                         resource.load(Collections.emptyMap());
183                 } catch (IOException e) {
184                         logger.error("Error loading Encore Resource for new Model" + e);
185                 }
186
187                 EPackage root = (EPackage) resource.getContents().get(0);
188
189                 return root;
190         }
191
192         private HashMap<String, String> getEEnum(EObject obj) {
193                 List<String> valueList = new ArrayList<>();
194                 HashMap<String, String> returnMap = new HashMap<>();
195                 EEnum eenum = (EEnum)obj;
196
197                 String name = eenum.getName();
198                 for (EEnumLiteral eEnumLiteral : eenum.getELiterals())
199                 {
200                         Enumerator instance = eEnumLiteral.getInstance();
201                         String value = instance.getLiteral();
202                         valueList.add(value);
203                 }
204                 returnMap.put(name, valueList.toString());
205                 return returnMap;
206         }
207
208         public void getAttributes(String className, String dependency, EPackage root) {
209                 List<String> dpendList = new ArrayList<>();
210                 if (dependency!=null){
211                         dpendList = new ArrayList<>(Arrays.asList(dependency.split(",")));
212                 }
213                 MSAttributeObject msAttributeObject = new MSAttributeObject();
214                 msAttributeObject.setClassName(className);
215                 String extendClass = getSubTypes(root, className);
216                 Map<String, String> returnRefList = getRefAttributeList(root, className, extendClass);
217                 Map<String, String> returnAttributeList = getAttributeList(root, className, extendClass);
218                 Map<String, Object> returnSubList = getSubAttributeList(root, className, extendClass);
219                 HashMap<String, String> returnAnnotation = getAnnotation(root, className, extendClass);
220                 msAttributeObject.setAttribute(returnAttributeList);
221                 msAttributeObject.setRefAttribute(returnRefList);
222                 msAttributeObject.setSubClass(returnSubList);
223                 msAttributeObject.setDependency(dpendList.toString());
224                 msAttributeObject.addMatchingSet(returnAnnotation);
225                 msAttributeObject.setPolicyTempalate(isPolicyTemplate(root, className));
226
227                 this.classMap.put(className, msAttributeObject);        
228         }
229
230         private HashMap<String, String> getAnnotation(EPackage root, String className, String extendClass) {
231                 TreeIterator<EObject> treeItr = root.eAllContents();
232                 boolean requiredAttribute = false; 
233                 boolean requiredMatchAttribute = false;
234                 HashMap<String, String> annotationSet = new HashMap<>();
235                 String  matching;
236                 String range;
237                 String dictionary;
238
239                 //    Pulling out dependency from file
240                 while (treeItr.hasNext()) {         
241                         EObject obj = treeItr.next();
242                         if (obj instanceof EClassifier) {
243                                 requiredAttribute = isRequiredAttribute(obj,  className );
244                                 requiredMatchAttribute = isRequiredAttribute(obj,  extendClass );
245                         }
246
247                         if (requiredAttribute){
248                                 if (obj instanceof EStructuralFeature) {
249                                         EStructuralFeature eStrucClassifier = (EStructuralFeature) obj;
250                                         if (!eStrucClassifier.getEAnnotations().isEmpty()) {
251                                                 matching  = annotationValue(eStrucClassifier, ANNOTATION_TYPE.MATCHING, policy);
252                                                 if (matching!=null){
253                                                         annotationSet.put(eStrucClassifier.getName(), matching);
254                                                 }
255                                                 range  = annotationValue(eStrucClassifier, ANNOTATION_TYPE.VALIDATION, policy);
256                                                 if (range!=null){
257                                                         annotationSet.put(eStrucClassifier.getName(), range);
258                                                 }
259                                                 dictionary = annotationValue(eStrucClassifier, ANNOTATION_TYPE.DICTIONARY, policy);
260                                                 if (dictionary!=null){
261                                                         annotationSet.put(eStrucClassifier.getName(), dictionary);
262                                                 }
263                                         }
264                                 }
265                         } else if (requiredMatchAttribute){
266                                 if (obj instanceof EStructuralFeature) {
267                                         EStructuralFeature eStrucClassifier = (EStructuralFeature) obj;
268                                         if (!eStrucClassifier.getEAnnotations().isEmpty()) {
269                                                 matching  = annotationValue(eStrucClassifier, ANNOTATION_TYPE.MATCHING, policy);
270                                                 if (matching!=null){
271                                                         if (obj instanceof EReference){
272                                                                 EClass refType = ((EReference) obj).getEReferenceType();
273                                                                 annotationSet.put(refType.getName(), matching);
274                                                                 matchingClass.put(refType.getName(), matching);
275                                                         }else{
276                                                                 annotationSet.put(eStrucClassifier.getName(), matching);
277                                                         }
278                                                 }
279                                         }
280                                 }
281                         }
282                 }
283                 return annotationSet;
284         }
285
286         private Map<String, Object> getSubAttributeList(EPackage root, String className , String superClass) {
287                 TreeIterator<EObject> treeItr = root.eAllContents();
288                 boolean requiredAttribute = false; 
289                 Map<String, Object> subAttribute = new HashMap<>();
290                 int rollingCount = 0;
291                 int processClass = 0;
292                 boolean annotation;
293
294                 //    Pulling out dependency from file
295                 while (treeItr.hasNext() && rollingCount < 2) {  
296
297                         EObject obj = treeItr.next();
298                         if (obj instanceof EClassifier) {
299                                 if (isRequiredAttribute(obj,  className ) || isRequiredAttribute(obj,  superClass )){
300                                         requiredAttribute = true;
301                                 }else {
302                                         requiredAttribute = false;
303                                 }
304                                 if (requiredAttribute){
305                                         processClass++;
306                                 }
307                                 rollingCount = rollingCount+processClass;
308                         }
309
310                         if (requiredAttribute)   {
311                                 if (obj instanceof EStructuralFeature) {
312                                         EStructuralFeature eStrucClassifier = (EStructuralFeature) obj;
313                                         if (!eStrucClassifier.getEAnnotations().isEmpty()) {
314                                                 annotation = annotationTest(eStrucClassifier, configuration, onap);
315                                                 if (annotation &&  obj instanceof EReference) {
316                                                         EClass refType = ((EReference) obj).getEReferenceType();
317                                                         if(!refType.toString().contains(eProxyURI)){
318                                                                 subAttribute.put(eStrucClassifier.getName(), refType.getName());                                                
319                                                         }
320                                                 }       
321                                         }
322                                 }
323                         }
324                 }
325                 return subAttribute;
326         }
327
328         public String checkDefultValue(String defultValue) {
329                 if (defultValue!=null){
330                         return ":defaultValue-"+ defultValue;
331                 }
332                 return ":defaultValue-NA";
333
334         }
335
336         public String checkRequiredPattern(int upper, int lower) {      
337
338                 String pattern = XACMLProperties.getProperty(XACMLRestProperties.PROP_XCORE_REQUIRED_PATTERN);
339
340                 if (pattern!=null){
341                         if (upper == Integer.parseInt(pattern.split(",")[1]) && lower==Integer.parseInt(pattern.split(",")[0])){
342                                 return ":required-true";
343                         }
344                 }
345
346                 return ":required-false";
347         }
348
349         public JSONObject buildJavaObject(Map<String, String> map){
350
351                 JSONObject returnValue = new JSONObject(map);
352
353                 return returnValue;
354
355         }
356
357         public Map<String, String> getRefAttributeList(EPackage root, String className, String superClass){
358
359                 TreeIterator<EObject> treeItr = root.eAllContents();
360                 boolean requiredAttribute = false; 
361                 HashMap<String, String> refAttribute = new HashMap<>();
362                 int rollingCount = 0;
363                 int processClass = 0;
364                 boolean annotation;
365                 //    Pulling out dependency from file
366                 while (treeItr.hasNext()) {         
367                         EObject obj = treeItr.next();
368                         if (obj instanceof EClassifier) {
369                                 if (isRequiredAttribute(obj,  className ) || isRequiredAttribute(obj,  superClass )){
370                                         requiredAttribute = true;
371                                 }else {
372                                         requiredAttribute = false;
373                                 }       
374                                 if (requiredAttribute){
375                                         processClass++;
376                                 }
377                                 rollingCount = rollingCount+processClass;
378                         }
379
380                         if (requiredAttribute)   {
381                                 if (obj instanceof EStructuralFeature) {
382                                         EStructuralFeature eStrucClassifier = (EStructuralFeature) obj;
383                                         if (!eStrucClassifier.getEAnnotations().isEmpty()) {
384                                                 annotation = annotationTest(eStrucClassifier, configuration, onap);
385                                                 if ( annotation &&  obj instanceof EReference) {
386                                                         EClass refType = ((EReference) obj).getEReferenceType();
387                                                         if(refType.toString().contains(eProxyURI)){
388                                                                 String one = refType.toString().split(eProxyURI)[1];
389                                                                 String refValue = StringUtils.replaceEach(one.split("#")[1], new String[]{"//", ")"}, new String[]{"", ""});                                                    
390                                                                 refAttribute.put(eStrucClassifier.getName(), refValue);                                                 
391                                                         } else {
392                                                                 String array = arrayCheck(((EStructuralFeature) obj).getUpperBound());
393                                                                 refAttribute.put(eStrucClassifier.getName(), refType.getName() + array);
394                                                         }
395                                                 } else if (annotation &&  obj instanceof EAttributeImpl){
396                                                         EClassifier refType = ((EAttributeImpl) obj).getEType();
397                                                         if (refType instanceof EEnumImpl){
398                                                                 String array = arrayCheck(((EStructuralFeature) obj).getUpperBound());
399                                                                 refAttribute.put(eStrucClassifier.getName(), refType.getName() + array);                                                        }
400                                                 }       
401                                         }
402                                 }
403                         }
404                 }
405                 return refAttribute;
406         }
407
408         private boolean annotationTest(EStructuralFeature eStrucClassifier, String annotation, String type) {
409                 String annotationType;
410                 EAnnotation eAnnotation;
411                 String onapType;
412                 String onapValue;
413
414                 EList<EAnnotation> value = eStrucClassifier.getEAnnotations();
415
416                 for (int i = 0; i < value.size(); i++){
417                         annotationType = value.get(i).getSource();
418                         eAnnotation = eStrucClassifier.getEAnnotations().get(i);
419                         onapType = eAnnotation.getDetails().get(0).getValue();
420                         onapValue = eAnnotation.getDetails().get(0).getKey();
421                         if (annotationType.contains(type) && onapType.contains(annotation)){
422                                 return true;
423                         } else if (annotationType.contains(type) && onapValue.contains(annotation)){
424                                 return true;
425                         }
426                 }
427
428                 return false;
429         }
430
431
432         private String annotationValue(EStructuralFeature eStrucClassifier, ANNOTATION_TYPE annotation, String type) {
433                 String annotationType;
434                 EAnnotation eAnnotation;
435                 String onapType;
436                 String onapValue = null;
437
438                 EList<EAnnotation> value = eStrucClassifier.getEAnnotations();
439
440                 for (int i = 0; i < value.size(); i++){
441                         annotationType = value.get(i).getSource();
442                         eAnnotation = eStrucClassifier.getEAnnotations().get(i);
443                         onapType = eAnnotation.getDetails().get(0).getKey();
444                         if (annotationType.contains(type) && onapType.compareToIgnoreCase(annotation.toString())==0){
445                                 onapValue = eAnnotation.getDetails().get(0).getValue();
446                                 if (annotation == ANNOTATION_TYPE.VALIDATION){
447                                         return onapValue;
448                                 } else {
449                                         return onapType + "-" + onapValue;
450                                 }
451                         }
452                 }
453
454                 return onapValue;
455         }
456         public boolean isRequiredAttribute(EObject obj, String className){
457                 EClassifier eClassifier = (EClassifier) obj;
458                 String workingClass = eClassifier.getName();
459                 workingClass.trim();
460                 if (workingClass.equalsIgnoreCase(className)){
461                         return  true;
462                 }
463
464                 return false;
465         } 
466
467         private boolean isPolicyTemplate(EPackage root, String className){
468
469                 for (EClassifier classifier : root.getEClassifiers()){ 
470                         if (classifier instanceof EClass) { 
471                                 EClass eClass = (EClass)classifier; 
472                                 if (eClass.getName().contentEquals(className)){
473                                         EList<EAnnotation> value = eClass.getEAnnotations();
474                                         for (EAnnotation workingValue : value){
475                                                 EMap<String, String> keyMap = workingValue.getDetails();        
476                                                 if (keyMap.containsKey("policyTemplate")){
477                                                         return true;
478                                                 }
479                                         }       
480                                 }
481                         }
482                 }
483                 return false;
484         }
485         private String getSubTypes(EPackage root, String className) {
486                 String returnSubTypes = null;
487                 for (EClassifier classifier : root.getEClassifiers()){ 
488                         if (classifier instanceof EClass) { 
489                                 EClass eClass = (EClass)classifier; 
490
491                                 for (EClass eSuperType : eClass.getEAllSuperTypes()) 
492                                 { 
493                                         if (eClass.getName().contentEquals(className)){
494                                                 returnSubTypes = eSuperType.getName();
495                                         }
496                                 } 
497                         } 
498                 } 
499                 return returnSubTypes;
500         } 
501
502         public Map<String, String> getAttributeList(EPackage root, String className, String superClass){
503
504                 TreeIterator<EObject> treeItr = root.eAllContents();
505                 boolean requiredAttribute = false; 
506                 HashMap<String, String> refAttribute = new HashMap<>();
507                 boolean annotation;
508                 boolean dictionaryTest;
509                 String defaultValue;
510                 String eType;
511
512                 //    Pulling out dependency from file
513                 while (treeItr.hasNext()) {         
514                         EObject obj = treeItr.next();
515                         if (obj instanceof EClassifier) {
516                                 if (isRequiredAttribute(obj,  className ) || isRequiredAttribute(obj,  superClass )){
517                                         requiredAttribute = true;
518                                 }else {
519                                         requiredAttribute = false;
520                                 }
521
522                         }
523
524                         if (requiredAttribute){
525                                 if (obj instanceof EStructuralFeature) {
526                                         EStructuralFeature eStrucClassifier = (EStructuralFeature) obj;
527                                         if (!eStrucClassifier.getEAnnotations().isEmpty()) {
528                                                 annotation = annotationTest(eStrucClassifier, configuration, onap);
529                                                 dictionaryTest = annotationTest(eStrucClassifier, dictionary, policy);
530                                                 EClassifier refType = ((EStructuralFeature) obj).getEType();
531                                                 if (annotation && !(obj instanceof EReference) && !(refType instanceof EEnumImpl)) {
532                                                         String name = eStrucClassifier.getName();
533                                                         if (dictionaryTest){
534                                                                 eType = annotationValue(eStrucClassifier, ANNOTATION_TYPE.DICTIONARY, policy);
535                                                         }else {
536                                                                 eType = eStrucClassifier.getEType().getInstanceClassName();
537                                                         }
538                                                         defaultValue = checkDefultValue(((EStructuralFeature) obj).getDefaultValueLiteral());
539
540                                                         String array = arrayCheck(((EStructuralFeature) obj).getUpperBound());
541                                                         String required = checkRequiredPattern(((EStructuralFeature) obj).getUpperBound(), ((EStructuralFeature) obj).getLowerBound());
542                                                         String attributeValue =  eType + defaultValue + required + array;
543                                                         refAttribute.put(name, attributeValue); 
544                                                 }
545                                         }
546                                 }
547                         }
548                 }
549                 return refAttribute;
550
551         }
552
553         public String arrayCheck(int upperBound) {
554
555                 if (upperBound == -1){
556                         return ":MANY-true";
557                 }
558
559                 return ":MANY-false";
560         }
561
562         public List<String> getDependencyList(EClassifier eClassifier, String className){
563                 List<String> returnValue = new ArrayList<>();;
564                 EList<EClass> somelist = ((EClass) eClassifier).getEAllSuperTypes();
565                 if (somelist.isEmpty()){
566                         return returnValue;
567                 }
568                 for(EClass depend: somelist){
569                         if (depend.toString().contains(eProxyURI)){
570                                 String one = depend.toString().split(eProxyURI)[1];
571                                 String value = StringUtils.replaceEach(one.split("#")[1], new String[]{"//", ")"}, new String[]{"", ""});
572                                 returnValue.add(value);
573                         }
574                 }
575
576                 return returnValue;
577         }
578
579         public Map<String, String> buildSubList(Map<String, String> subClassAttributes, Map<String, MSAttributeObject> classMap, String className){
580                 Map<String, String> missingValues = new HashMap<>();
581                 Map<String, String> workingMap;
582                 boolean enumType;
583
584                 for ( Entry<String, String> map : classMap.get(className).getRefAttribute().entrySet()){
585                         String value = map.getValue().split(":")[0];
586                         if (value!=null){
587                                 classMap.get(className).getEnumType();
588                                 enumType = classMap.get(className).getEnumType().containsKey(value);
589                                 if (!enumType){
590                                         workingMap =  classMap.get(value).getRefAttribute();
591                                         for ( Entry<String, String> subMab : workingMap.entrySet()){
592                                                 String value2 = subMab.getValue().split(":")[0];
593                                                 if (!subClassAttributes.containsValue(value2)){
594                                                         missingValues.put(subMab.getKey(), subMab.getValue());
595                                                 }
596                                         }
597
598                                 }
599                         }
600                 }
601
602                 return missingValues;
603         }
604
605         public Map<String, Map<String, String>> recursiveReference(Map<String, MSAttributeObject> classMap, String className){
606
607                 Map<String, Map<String, String>> returnObject = new HashMap<>();
608                 Map<String, String> returnClass = getRefclass(classMap, className);
609                 returnObject.put(className, returnClass);
610                 for (Entry<String, String> reAttribute :returnClass.entrySet()){
611                         if (reAttribute.getValue().split(":")[1].contains("MANY")){
612                                 if (classMap.get(reAttribute.getValue().split(":")[0]) != null){
613                                         returnObject.putAll(recursiveReference(classMap, reAttribute.getValue().split(":")[0]));
614                                 }
615                         }
616
617                 }
618
619                 return returnObject;
620
621         }
622
623         public String createJson(Map<String, Object> subClassAttributes, Map<String, MSAttributeObject> classMap, String className) {
624                 boolean enumType;
625                 Map<String, Map<String, String>> myObject = new HashMap<>();
626                 for ( Entry<String, String> map : classMap.get(className).getRefAttribute().entrySet()){
627                         String value = map.getValue().split(":")[0];
628                         if (value!=null){
629                                 enumType = classMap.get(className).getEnumType().containsKey(value);
630                                 if (!enumType){
631                                         if (map.getValue().split(":")[1].contains("MANY")){
632                                                 Map<String, Map<String, String>> testRecursive = recursiveReference(classMap, map.getValue().split(":")[0] );
633                                                 myObject.putAll(testRecursive);
634                                         }
635                                 }
636                         }
637                 }
638
639                 Gson gson = new Gson(); 
640                 String json = gson.toJson(myObject); 
641
642                 return json;            
643         }
644
645         public Map<String, String> getRefclass(Map<String, MSAttributeObject> classMap, String className){
646                 HashMap<String, String> missingValues = new HashMap<>();
647
648                 if (classMap.get(className).getAttribute()!=null || !classMap.get(className).getAttribute().isEmpty()){
649                         missingValues.putAll(classMap.get(className).getAttribute());
650                 }
651
652                 if (classMap.get(className).getRefAttribute()!=null || !classMap.get(className).getRefAttribute().isEmpty()){
653                         missingValues.putAll(classMap.get(className).getRefAttribute());
654                 }
655
656                 return missingValues;   
657         }
658
659         public String createSubAttributes(List<String> dependency, Map<String, MSAttributeObject> classMap, String modelName) {
660
661                 HashMap <String,  Object>  workingMap = new HashMap<>();
662                 MSAttributeObject tempObject;
663                 if (dependency!=null){
664                         if (dependency.isEmpty()){
665                                 return "{}";
666                         }       
667                         dependency.add(modelName);
668                         for (String element: dependency){
669                                 tempObject = classMap.get(element);
670                                 if (tempObject!=null){
671                                         workingMap.putAll(classMap.get(element).getSubClass());
672                                 }
673                         }
674                 }
675
676                 String returnValue = createJson(workingMap, classMap, modelName);                       
677                 return returnValue;
678         }
679
680         public List<String> getFullDependencyList(List<String> dependency, Map<String,MSAttributeObject > classMap) {
681                 ArrayList<String> returnList = new ArrayList<>();
682                 ArrayList<String> workingList;
683                 returnList.addAll(dependency);
684                 for (String element : dependency ){
685                         if (classMap.containsKey(element)){
686                                 MSAttributeObject value = classMap.get(element);
687                                 String rawValue = StringUtils.replaceEach(value.getDependency(), new String[]{"[", "]"}, new String[]{"", ""});
688                                 workingList = new ArrayList<>(Arrays.asList(rawValue.split(",")));
689                                 for(String depend : workingList){
690                                         if (!returnList.contains(depend) && !depend.isEmpty()){
691                                                 returnList.add(depend.trim());
692                                         }
693                                 }
694                         }
695                 }
696
697                 return returnList;
698         }
699 }