aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java
blob: 18fd80c63595f6b2a0f1dfd0b9453721f099cf59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
/*-
 * ============LICENSE_START=======================================================
 * ONAP-REST
 * ================================================================================
 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.rest.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.common.util.Enumerator;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.impl.EAttributeImpl;
import org.eclipse.emf.ecore.impl.EEnumImpl;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.json.JSONObject;
import org.onap.policy.rest.XACMLRestProperties;

import com.att.research.xacml.util.XACMLProperties;
import com.google.gson.Gson;


public class MSModelUtils {

	private static final Log logger	= LogFactory.getLog(MSModelUtils.class);

	private HashMap<String,MSAttributeObject > classMap = new HashMap<>();
	private HashMap<String, String> enumMap = new HashMap<>();
	private HashMap<String, String> matchingClass = new HashMap<>();
	private String configuration = "configuration";
	private String dictionary = "dictionary";
	private String onap = "";
	private String policy = "";
	private String eProxyURI = "eProxyURI:";
	
	public MSModelUtils(String onap, String policy){
		this.onap = onap;
		this.policy = policy;
	}

	private enum ANNOTATION_TYPE{
		MATCHING, VALIDATION, DICTIONARY
	};

	public enum MODEL_TYPE {
		XMI
	};


	public Map<String, MSAttributeObject> processEpackage(String file, MODEL_TYPE model){
		if (model == MODEL_TYPE.XMI ){
			processXMIEpackage(file);
		}
		return classMap;

	} 

	private void processXMIEpackage(String xmiFile){
		EPackage root = getEpackage(xmiFile);
		TreeIterator<EObject> treeItr = root.eAllContents();
		String className;
		String returnValue;

		//    Pulling out dependency from file
		while (treeItr.hasNext()) {	    
			EObject obj = treeItr.next();
			if (obj instanceof EClassifier) {
				EClassifier eClassifier = (EClassifier) obj;
				className = eClassifier.getName();

				if (obj instanceof EEnum) {
					enumMap.putAll(getEEnum(obj));
				}else if (obj instanceof EClass) {
					String temp = getDependencyList(eClassifier, className).toString();
					returnValue = StringUtils.replaceEach(temp, new String[]{"[", "]"}, new String[]{"", ""});
					getAttributes(className, returnValue, root);
				}        		   		
			}
		}

		if (!enumMap.isEmpty()){
			addEnumClassMap();
		}
		if (!matchingClass.isEmpty()){
			CheckForMatchingClass();
		}
	}

	private void CheckForMatchingClass() {
		HashMap<String, String> tempAttribute = new HashMap<>();

		for (Entry<String, String> set : matchingClass.entrySet()){
			String key = set.getKey();
			if (classMap.containsKey(key)){
				Map<String, String> listAttributes = classMap.get(key).getAttribute();
				Map<String, String> listRef = classMap.get(key).getRefAttribute();
				for (  Entry<String, String> eSet : listAttributes.entrySet()){
					String key2 = eSet.getKey();
					tempAttribute.put(key2, "matching-true");
				}
				for (  Entry<String, String> eSet : listRef.entrySet()){
					String key3 = eSet.getKey();
					tempAttribute.put(key3, "matching-true");
				}

			}
			UpdateMatching(tempAttribute, key);
		}

	}



	private void UpdateMatching(HashMap<String, String> tempAttribute, String key) {
		Map<String, MSAttributeObject> newClass = classMap;

		for (Entry<String, MSAttributeObject> updateClass :  newClass.entrySet()){
			Map<String, String> valueMap = updateClass.getValue().getMatchingSet();
			String keymap = updateClass.getKey();
			if (valueMap.containsKey(key)){
				Map<String, String> modifyMap = classMap.get(keymap).getMatchingSet();
				modifyMap.remove(key);
				modifyMap.putAll(tempAttribute);
				classMap.get(keymap).setMatchingSet(modifyMap);
			}

		}
	}

	private void addEnumClassMap() {
		for (Entry<String, MSAttributeObject> value :classMap.entrySet()){
			value.getValue().setEnumType(enumMap);
		}
	}

	private EPackage getEpackage(String xmiFile) {
		ResourceSet resSet = new ResourceSetImpl();
		Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
		Map<String, Object> m = reg.getExtensionToFactoryMap();
		m.put("xmi", new XMIResourceFactoryImpl());
		Resource resource = resSet.getResource(URI.createFileURI(xmiFile), true);
		try {
			resource.load(Collections.emptyMap());
		} catch (IOException e) {
			logger.error("Error loading Encore Resource for new Model" + e);
		}

		return (EPackage) resource.getContents().get(0);
	}

	private HashMap<String, String> getEEnum(EObject obj) {
		List<String> valueList = new ArrayList<>();
		HashMap<String, String> returnMap = new HashMap<>();
		EEnum eenum = (EEnum)obj;

		String name = eenum.getName();
		for (EEnumLiteral eEnumLiteral : eenum.getELiterals())
		{
			Enumerator instance = eEnumLiteral.getInstance();
			String value = instance.getLiteral();
			valueList.add(value);
		}
		returnMap.put(name, valueList.toString());
		return returnMap;
	}

	public void getAttributes(String className, String dependency, EPackage root) {
		List<String> dpendList = new ArrayList<>();
		if (dependency!=null){
			dpendList = new ArrayList<>(Arrays.asList(dependency.split(",")));
		}
		MSAttributeObject msAttributeObject = new MSAttributeObject();
		msAttributeObject.setClassName(className);
		String extendClass = getSubTypes(root, className);
		Map<String, String> returnRefList = getRefAttributeList(root, className, extendClass);
		Map<String, String> returnAttributeList = getAttributeList(root, className, extendClass);
		Map<String, Object> returnSubList = getSubAttributeList(root, className, extendClass);
		HashMap<String, String> returnAnnotation = getAnnotation(root, className, extendClass);
		msAttributeObject.setAttribute(returnAttributeList);
		msAttributeObject.setRefAttribute(returnRefList);
		msAttributeObject.setSubClass(returnSubList);
		msAttributeObject.setDependency(dpendList.toString());
		msAttributeObject.addMatchingSet(returnAnnotation);
		msAttributeObject.setPolicyTempalate(isPolicyTemplate(root, className));

		this.classMap.put(className, msAttributeObject);	
	}

	private HashMap<String, String> getAnnotation(EPackage root, String className, String extendClass) {
		TreeIterator<EObject> treeItr = root.eAllContents();
		boolean requiredAttribute = false; 
		boolean requiredMatchAttribute = false;
		HashMap<String, String> annotationSet = new HashMap<>();
		String  matching;
		String range;
		String dictionary;

		//    Pulling out dependency from file
		while (treeItr.hasNext()) {	    
			EObject obj = treeItr.next();
			if (obj instanceof EClassifier) {
				requiredAttribute = isRequiredAttribute(obj,  className );
				requiredMatchAttribute = isRequiredAttribute(obj,  extendClass );
			}

			if (requiredAttribute){
				if (obj instanceof EStructuralFeature) {
					EStructuralFeature eStrucClassifier = (EStructuralFeature) obj;
					if (!eStrucClassifier.getEAnnotations().isEmpty()) {
						matching  = annotationValue(eStrucClassifier, ANNOTATION_TYPE.MATCHING, policy);
						if (matching!=null){
							annotationSet.put(eStrucClassifier.getName(), matching);
						}
						range  = annotationValue(eStrucClassifier, ANNOTATION_TYPE.VALIDATION, policy);
						if (range!=null){
							annotationSet.put(eStrucClassifier.getName(), range);
						}
						dictionary = annotationValue(eStrucClassifier, ANNOTATION_TYPE.DICTIONARY, policy);
						if (dictionary!=null){
							annotationSet.put(eStrucClassifier.getName(), dictionary);
						}
					}
				}
			} else if (requiredMatchAttribute){
				if (obj instanceof EStructuralFeature) {
					EStructuralFeature eStrucClassifier = (EStructuralFeature) obj;
					if (!eStrucClassifier.getEAnnotations().isEmpty()) {
						matching  = annotationValue(eStrucClassifier, ANNOTATION_TYPE.MATCHING, policy);
						if (matching!=null){
							if (obj instanceof EReference){
								EClass refType = ((EReference) obj).getEReferenceType();
								annotationSet.put(refType.getName(), matching);
								matchingClass.put(refType.getName(), matching);
							}else{
								annotationSet.put(eStrucClassifier.getName(), matching);
							}
						}
					}
				}
			}
		}
		return annotationSet;
	}

	private Map<String, Object> getSubAttributeList(EPackage root, String className , String superClass) {
		TreeIterator<EObject> treeItr = root.eAllContents();
		boolean requiredAttribute = false; 
		Map<String, Object> subAttribute = new HashMap<>();
		int rollingCount = 0;
		int processClass = 0;
		boolean annotation;

		//    Pulling out dependency from file
		while (treeItr.hasNext() && rollingCount < 2) {	 

			EObject obj = treeItr.next();
			if (obj instanceof EClassifier) {
				if (isRequiredAttribute(obj,  className ) || isRequiredAttribute(obj,  superClass )){
					requiredAttribute = true;
				}else {
					requiredAttribute = false;
				}
				if (requiredAttribute){
					processClass++;
				}
				rollingCount = rollingCount+processClass;
			}

			if (requiredAttribute)   {
				if (obj instanceof EStructuralFeature) {
					EStructuralFeature eStrucClassifier = (EStructuralFeature) obj;
					if (!eStrucClassifier.getEAnnotations().isEmpty()) {
						annotation = annotationTest(eStrucClassifier, configuration, onap);
						if (annotation &&  obj instanceof EReference) {
							EClass refType = ((EReference) obj).getEReferenceType();
							if(!refType.toString().contains(eProxyURI)){
								String required = ":required-false";
								if(eStrucClassifier.getLowerBound() == 1){
									required = ":required-true";
								}
								subAttribute.put(eStrucClassifier.getName(), refType.getName() + required);						
							}
						}	
					}
				}
			}
		}
		return subAttribute;
	}

	public String checkDefultValue(String defultValue) {
		if (defultValue!=null){
			return ":defaultValue-"+ defultValue;
		}
		return ":defaultValue-NA";

	}

	public String checkRequiredPattern(int upper, int lower) {	

		String pattern = XACMLProperties.getProperty(XACMLRestProperties.PROP_XCORE_REQUIRED_PATTERN);

		if (pattern!=null){
			if (upper == Integer.parseInt(pattern.split(",")[1]) && lower==Integer.parseInt(pattern.split(",")[0])){
				return ":required-true";
			}
		}

		return ":required-false";
	}

	public JSONObject buildJavaObject(Map<String, String> map){

		return  new JSONObject(map);
	}

	public Map<String, String> getRefAttributeList(EPackage root, String className, String superClass){

		TreeIterator<EObject> treeItr = root.eAllContents();
		boolean requiredAttribute = false; 
		HashMap<String, String> refAttribute = new HashMap<>();
		int rollingCount = 0;
		int processClass = 0;
		boolean annotation;
		//    Pulling out dependency from file
		while (treeItr.hasNext()) {	    
			EObject obj = treeItr.next();
			if (obj instanceof EClassifier) {
				if (isRequiredAttribute(obj,  className ) || isRequiredAttribute(obj,  superClass )){
					requiredAttribute = true;
				}else {
					requiredAttribute = false;
				}	
				if (requiredAttribute){
					processClass++;
				}
				rollingCount = rollingCount+processClass;
			}

			if (requiredAttribute)   {
				if (obj instanceof EStructuralFeature) {
					EStructuralFeature eStrucClassifier = (EStructuralFeature) obj;
					if (!eStrucClassifier.getEAnnotations().isEmpty()) {
						annotation = annotationTest(eStrucClassifier, configuration, onap);
						if ( annotation &&  obj instanceof EReference) {
							EClass refType = ((EReference) obj).getEReferenceType();
							if(refType.toString().contains(eProxyURI)){
								String one = refType.toString().split(eProxyURI)[1];
								String refValue = StringUtils.replaceEach(one.split("#")[1], new String[]{"//", ")"}, new String[]{"", ""});							
								refAttribute.put(eStrucClassifier.getName(), refValue);							
							} else {
								String array = arrayCheck(((EStructuralFeature) obj).getUpperBound());
								String required = ":required-false";
								if(((EStructuralFeature) obj).getLowerBound() == 1){
									required = ":required-true";
								}
								refAttribute.put(eStrucClassifier.getName(), refType.getName() + array + required);
							}
						} else if (annotation &&  obj instanceof EAttributeImpl){
							EClassifier refType = ((EAttributeImpl) obj).getEType();
							if (refType instanceof EEnumImpl){
								String array = arrayCheck(((EStructuralFeature) obj).getUpperBound());
								String required = ":required-false";
								if(((EStructuralFeature) obj).getLowerBound() == 1){
									required = ":required-true";
								}
								refAttribute.put(eStrucClassifier.getName(), refType.getName() + array + required);							
							}
						}	
					}
				}
			}
		}
		
		return refAttribute;
	}

	private boolean annotationTest(EStructuralFeature eStrucClassifier, String annotation, String type) {
		String annotationType;
		EAnnotation eAnnotation;
		String onapType;
		String onapValue;

		EList<EAnnotation> value = eStrucClassifier.getEAnnotations();

		for (int i = 0; i < value.size(); i++){
			annotationType = value.get(i).getSource();
			eAnnotation = eStrucClassifier.getEAnnotations().get(i);
			onapType = eAnnotation.getDetails().get(0).getValue();
			onapValue = eAnnotation.getDetails().get(0).getKey();
			if (annotationType.contains(type) && onapType.contains(annotation)){
				return true;
			} else if (annotationType.contains(type) && onapValue.contains(annotation)){
				return true;
			}
		}

		return false;
	}


	private String annotationValue(EStructuralFeature eStrucClassifier, ANNOTATION_TYPE annotation, String type) {
		String annotationType;
		EAnnotation eAnnotation;
		String onapType;
		String onapValue = null;

		EList<EAnnotation> value = eStrucClassifier.getEAnnotations();

		for (int i = 0; i < value.size(); i++){
			annotationType = value.get(i).getSource();
			eAnnotation = eStrucClassifier.getEAnnotations().get(i);
			onapType = eAnnotation.getDetails().get(0).getKey();
			if (annotationType.contains(type) && onapType.compareToIgnoreCase(annotation.toString())==0){
				onapValue = eAnnotation.getDetails().get(0).getValue();
				if (annotation == ANNOTATION_TYPE.VALIDATION){
					return onapValue;
				} else {
					return onapType + "-" + onapValue;
				}
			}
		}

		return onapValue;
	}
	public boolean isRequiredAttribute(EObject obj, String className){
		EClassifier eClassifier = (EClassifier) obj;
		String workingClass = eClassifier.getName();
		workingClass.trim();
		if (workingClass.equalsIgnoreCase(className)){
			return  true;
		}

		return false;
	} 

	private boolean isPolicyTemplate(EPackage root, String className){

		for (EClassifier classifier : root.getEClassifiers()){ 
			if (classifier instanceof EClass) { 
				EClass eClass = (EClass)classifier; 
				if (eClass.getName().contentEquals(className)){
					EList<EAnnotation> value = eClass.getEAnnotations();
					for (EAnnotation workingValue : value){
						EMap<String, String> keyMap = workingValue.getDetails();	
						if (keyMap.containsKey("policyTemplate")){
							return true;
						}
					}	
				}
			}
		}
		return false;
	}
	private String getSubTypes(EPackage root, String className) {
		String returnSubTypes = null;
		for (EClassifier classifier : root.getEClassifiers()){ 
			if (classifier instanceof EClass) { 
				EClass eClass = (EClass)classifier; 

				for (EClass eSuperType : eClass.getEAllSuperTypes()) 
				{ 
					if (eClass.getName().contentEquals(className)){
						returnSubTypes = eSuperType.getName();
					}
				} 
			} 
		} 
		return returnSubTypes;
	} 

	public Map<String, String> getAttributeList(EPackage root, String className, String superClass){

		TreeIterator<EObject> treeItr = root.eAllContents();
		boolean requiredAttribute = false; 
		HashMap<String, String> refAttribute = new HashMap<>();
		boolean annotation;
		boolean dictionaryTest;
		String defaultValue;
		String eType;

		//    Pulling out dependency from file
		while (treeItr.hasNext()) {	    
			EObject obj = treeItr.next();
			if (obj instanceof EClassifier) {
				if (isRequiredAttribute(obj,  className ) || isRequiredAttribute(obj,  superClass )){
					requiredAttribute = true;
				}else {
					requiredAttribute = false;
				}

			}

			if (requiredAttribute){
				if (obj instanceof EStructuralFeature) {
					EStructuralFeature eStrucClassifier = (EStructuralFeature) obj;
					if (!eStrucClassifier.getEAnnotations().isEmpty()) {
						annotation = annotationTest(eStrucClassifier, configuration, onap);
						dictionaryTest = annotationTest(eStrucClassifier, dictionary, policy);
						EClassifier refType = ((EStructuralFeature) obj).getEType();
						if (annotation && !(obj instanceof EReference) && !(refType instanceof EEnumImpl)) {
							String name = eStrucClassifier.getName();
							if (dictionaryTest){
								eType = annotationValue(eStrucClassifier, ANNOTATION_TYPE.DICTIONARY, policy);
							}else {
								eType = eStrucClassifier.getEType().getInstanceClassName();
							}
							defaultValue = checkDefultValue(((EStructuralFeature) obj).getDefaultValueLiteral());

							String array = arrayCheck(((EStructuralFeature) obj).getUpperBound());
							String required = checkRequiredPattern(((EStructuralFeature) obj).getUpperBound(), ((EStructuralFeature) obj).getLowerBound());
							String attributeValue =  eType + defaultValue + required + array;
							refAttribute.put(name, attributeValue);	
						}
					}
				}
			}
		}
		return refAttribute;

	}

	public String arrayCheck(int upperBound) {

		if (upperBound == -1){
			return ":MANY-true";
		}

		return ":MANY-false";
	}

	public List<String> getDependencyList(EClassifier eClassifier, String className){
		List<String> returnValue = new ArrayList<>();;
		EList<EClass> somelist = ((EClass) eClassifier).getEAllSuperTypes();
		if (somelist.isEmpty()){
			return returnValue;
		}
		for(EClass depend: somelist){
			if (depend.toString().contains(eProxyURI)){
				String one = depend.toString().split(eProxyURI)[1];
				String value = StringUtils.replaceEach(one.split("#")[1], new String[]{"//", ")"}, new String[]{"", ""});
				returnValue.add(value);
			}
		}

		return returnValue;
	}

	public Map<String, String> buildSubList(Map<String, String> subClassAttributes, Map<String, MSAttributeObject> classMap, String className){
		Map<String, String> missingValues = new HashMap<>();
		Map<String, String> workingMap;
		boolean enumType;

		for ( Entry<String, String> map : classMap.get(className).getRefAttribute().entrySet()){
			String value = map.getValue().split(":")[0];
			if (value!=null){
				classMap.get(className).getEnumType();
				enumType = classMap.get(className).getEnumType().containsKey(value);
				if (!enumType){
					workingMap =  classMap.get(value).getRefAttribute();
					for ( Entry<String, String> subMab : workingMap.entrySet()){
						String value2 = subMab.getValue().split(":")[0];
						if (!subClassAttributes.containsValue(value2)){
							missingValues.put(subMab.getKey(), subMab.getValue());
						}
					}

				}
			}
		}

		return missingValues;
	}

	public Map<String, Map<String, String>> recursiveReference(Map<String, MSAttributeObject> classMap, String className){

		Map<String, Map<String, String>> returnObject = new HashMap<>();
		Map<String, String> returnClass = getRefclass(classMap, className);
		returnObject.put(className, returnClass);
		for (Entry<String, String> reAttribute :returnClass.entrySet()){
			if (reAttribute.getValue().split(":")[1].contains("MANY")){
				if (classMap.get(reAttribute.getValue().split(":")[0]) != null){
					returnObject.putAll(recursiveReference(classMap, reAttribute.getValue().split(":")[0]));
				}
			}

		}

		return returnObject;

	}

	public String createJson(Map<String, Object> subClassAttributes, Map<String, MSAttributeObject> classMap, String className) {
		boolean enumType;
		Map<String, Map<String, String>> myObject = new HashMap<>();
		for ( Entry<String, String> map : classMap.get(className).getRefAttribute().entrySet()){
			String value = map.getValue().split(":")[0];
			if (value!=null){
				enumType = classMap.get(className).getEnumType().containsKey(value);
				if (!enumType){
					if (map.getValue().split(":")[1].contains("MANY")){
						Map<String, Map<String, String>> testRecursive = recursiveReference(classMap, map.getValue().split(":")[0] );
						myObject.putAll(testRecursive);
					}
				}
			}
		}

		Gson gson = new Gson(); 
		return gson.toJson(myObject);
	}

	public Map<String, String> getRefclass(Map<String, MSAttributeObject> classMap, String className){
		HashMap<String, String> missingValues = new HashMap<>();

		if (classMap.get(className).getAttribute()!=null || !classMap.get(className).getAttribute().isEmpty()){
			missingValues.putAll(classMap.get(className).getAttribute());
		}

		if (classMap.get(className).getRefAttribute()!=null || !classMap.get(className).getRefAttribute().isEmpty()){
			missingValues.putAll(classMap.get(className).getRefAttribute());
		}

		return missingValues;	
	}

	public String createSubAttributes(List<String> dependency, Map<String, MSAttributeObject> classMap, String modelName) {

		HashMap <String,  Object>  workingMap = new HashMap<>();
		MSAttributeObject tempObject;
		if (dependency!=null){
			if (dependency.isEmpty()){
				return "{}";
			}	
			dependency.add(modelName);
			for (String element: dependency){
				tempObject = classMap.get(element);
				if (tempObject!=null){
					workingMap.putAll(classMap.get(element).getSubClass());
				}
			}
		}

		return createJson(workingMap, classMap, modelName);
	}

	public List<String> getFullDependencyList(List<String> dependency, Map<String,MSAttributeObject > classMap) {
		ArrayList<String> returnList = new ArrayList<>();
		ArrayList<String> workingList;
		returnList.addAll(dependency);
		for (String element : dependency ){
			if (classMap.containsKey(element)){
				MSAttributeObject value = classMap.get(element);
				String rawValue = StringUtils.replaceEach(value.getDependency(), new String[]{"[", "]"}, new String[]{"", ""});
				workingList = new ArrayList<>(Arrays.asList(rawValue.split(",")));
				for(String depend : workingList){
					if (!returnList.contains(depend) && !depend.isEmpty()){
						returnList.add(depend.trim());
					}
				}
			}
		}

		return returnList;
	}
}