aboutsummaryrefslogtreecommitdiffstats
path: root/ajsc-aai/src/main/java/org/openecomp/aai/util/PojoUtils.java
blob: f7b195d592d4e070ce267c3e850f6ceab904ba86 (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
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
/*-
 * ============LICENSE_START=======================================================
 * org.openecomp.aai
 * ================================================================================
 * Copyright (C) 2017 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.openecomp.aai.util;

import java.io.IOException;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import java.util.Map.Entry;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import org.apache.commons.io.output.ByteArrayOutputStream;
import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.dynamic.DynamicType;
import org.eclipse.persistence.jaxb.MarshallerProperties;
import org.openecomp.aai.dbmodel.RestRules;
import org.openecomp.aai.domain.model.AAIResource;
import org.openecomp.aai.exceptions.AAIException;
import org.openecomp.aai.extensions.AAIExtensionMap;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
import com.google.common.base.CaseFormat;
import com.google.common.collect.Multimap;
import com.thinkaurelius.titan.core.TitanVertex;

public class PojoUtils {
	
	/**
	 * Gets the key value list.
	 *
	 * @param <T> the generic type
	 * @param e the e
	 * @param clazz the clazz
	 * @return the key value list
	 * @throws IllegalAccessException the illegal access exception
	 * @throws IllegalArgumentException the illegal argument exception
	 * @throws InvocationTargetException the invocation target exception
	 */
	public <T> List<KeyValueList> getKeyValueList(Entity e, T clazz) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		List<KeyValueList> kvList = e.getKeyValueList();
		Object value = null;
		Method[] methods = clazz.getClass().getDeclaredMethods();
		String propertyName = "";
		
		for (Method method : methods) { 
			if (method.getName().startsWith("get")) { 
				propertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,method.getName().substring(3));
				if (!(method.getReturnType().getName().contains("aai")) || method.getReturnType().getName().contains("java.util.List")) {
					value = method.invoke(clazz);
					KeyValueList kv = new KeyValueList();
					kv.setKey(propertyName);
					if (value != null) { 
						kv.setValue(value.toString());
					} else { 
						kv.setValue("");
					}
					kvList.add(kv);
				}
			}
		}
		return kvList;
	}
	
	/**
	 * Gets the json from object.
	 *
	 * @param <T> the generic type
	 * @param clazz the clazz
	 * @return the json from object
	 * @throws JsonGenerationException the json generation exception
	 * @throws JsonMappingException the json mapping exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 */
	public <T> String getJsonFromObject(T clazz) throws JsonGenerationException, JsonMappingException, IOException {
		return getJsonFromObject(clazz, false, true);
	}
	
	/**
	 * Gets the json from object.
	 *
	 * @param <T> the generic type
	 * @param clazz the clazz
	 * @param wrapRoot the wrap root
	 * @param indent the indent
	 * @return the json from object
	 * @throws JsonGenerationException the json generation exception
	 * @throws JsonMappingException the json mapping exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 */
	public <T> String getJsonFromObject(T clazz, boolean wrapRoot, boolean indent) throws JsonGenerationException, JsonMappingException, IOException {
		ObjectMapper mapper = new ObjectMapper();

        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        
        mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        mapper.configure(SerializationFeature.INDENT_OUTPUT, indent);
        mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, wrapRoot);

        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, wrapRoot);

        mapper.registerModule(new JaxbAnnotationModule());
        
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        
        mapper.writeValue(baos, clazz);
    
        return baos.toString();
	}
	
	/**
	 * Gets the json from dynamic object.
	 *
	 * @param ent the ent
	 * @param jaxbContext the jaxb context
	 * @param includeRoot the include root
	 * @return the json from dynamic object
	 * @throws JsonGenerationException the json generation exception
	 * @throws JsonMappingException the json mapping exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @throws JAXBException the JAXB exception
	 */
	public String getJsonFromDynamicObject(DynamicEntity ent, org.eclipse.persistence.jaxb.JAXBContext jaxbContext, boolean includeRoot) throws JsonGenerationException, JsonMappingException, IOException, JAXBException {
		org.eclipse.persistence.jaxb.JAXBMarshaller marshaller = jaxbContext.createMarshaller();
		
		marshaller.setProperty(org.eclipse.persistence.jaxb.JAXBMarshaller.JAXB_FORMATTED_OUTPUT, false);
		marshaller.setProperty(MarshallerProperties.JSON_MARSHAL_EMPTY_COLLECTIONS, Boolean.FALSE) ;
		marshaller.setProperty("eclipselink.json.include-root", includeRoot);
		marshaller.setProperty("eclipselink.media-type", "application/json");
		StringWriter writer = new StringWriter();
		marshaller.marshal(ent, writer);
        
		return writer.toString();
	}
	
	/**
	 * Gets the xml from object.
	 *
	 * @param <T> the generic type
	 * @param clazz the clazz
	 * @return the xml from object
	 * @throws JAXBException the JAXB exception
	 */
	public <T> String getXmlFromObject(T clazz) throws JAXBException {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		JAXBContext jc = JAXBContext.newInstance(clazz.getClass().getPackage().getName());

		Marshaller marshaller = jc.createMarshaller();
		marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
		marshaller.marshal(clazz, baos);
        
        return baos.toString();
	}
	
	/**
	 * Gets the uri.
	 *
	 * @param baseUrl the base url
	 * @param lookupHash the lookup hash
	 * @param keyProps the key props
	 * @param objectType the object type
	 * @return the uri
	 * @throws UnsupportedEncodingException the unsupported encoding exception
	 * @throws AAIException the AAI exception
	 */
	public String getUri (String baseUrl, HashMap<String,Object> lookupHash, Collection<String> keyProps, String objectType) throws UnsupportedEncodingException, AAIException { 
		int baseKeyLen = baseUrl.length();
		StringBuffer newUrl = new StringBuffer();
		if (baseKeyLen > 0) { 
			newUrl.append(baseUrl);
		}
		String plural = (String)RestRules.getResRules(objectType)[2];
		if (plural != null) { 
			newUrl.append("/" + plural);
		}
		
		if (objectType != null) { 
			newUrl.append("/" + objectType);
		}
		
		Iterator <String> keyPropI = keyProps.iterator();
		while( keyPropI.hasNext() ){
			String keyProp = keyPropI.next();
			String keyVal = "";
			Object obj = lookupHash.get(keyProp);
			if (obj instanceof String) { 
				keyVal = (String) obj;
			} else if (obj instanceof Long) { 
				Long val = (Long)obj;
				keyVal = val.toString();
			} else if (obj instanceof Short) { 
				Short val = (Short)obj;
				keyVal = val.toString();
			} else if (obj instanceof Integer) { 
				Integer val = (Integer)obj;
				keyVal = val.toString();
			} 
			newUrl.append("/" + RestURL.encodeURL(keyVal));
		}
		return newUrl.toString();
	}
	
	/**
	 * Gets the lookup key.
	 *
	 * @param baseKey the base key
	 * @param lookupHash the lookup hash
	 * @param keyProps the key props
	 * @return the lookup key
	 */
	public String getLookupKey (String baseKey, HashMap<String,Object> lookupHash, Collection<String> keyProps) { 
		int baseKeyLen = baseKey.length();
		StringBuffer newKey = new StringBuffer();
		if (baseKeyLen > 0) { 
			newKey.append(baseKey);
		}
		
		Iterator <String> keyPropI = keyProps.iterator();
		while( keyPropI.hasNext() ){
			String keyProp = keyPropI.next();
			if (baseKeyLen > 0) {
				newKey.append("&");
			}
			newKey.append(keyProp + "=" + lookupHash.get(keyProp));
		}
		return newKey.toString();
	}
	
	/**
	 * Gets the lookup keys.
	 *
	 * @param lookupHashes the lookup hashes
	 * @param _dbRulesNodeKeyProps the db rules node key props
	 * @return the lookup keys
	 */
	public String getLookupKeys (LinkedHashMap<String,HashMap<String,Object>> lookupHashes, Multimap<String, String> _dbRulesNodeKeyProps) { 
		Iterator<String> it = lookupHashes.keySet().iterator();
		String lookupKeys = "";
		while (it.hasNext()) {
			String objectType = (String)it.next();
			HashMap<String,Object> lookupHash = lookupHashes.get(objectType);
						
			Collection<String> keyProps = _dbRulesNodeKeyProps.get(objectType);
			Iterator <String> keyPropI = keyProps.iterator();
			while( keyPropI.hasNext() ){
				lookupKeys += lookupHash.get(keyPropI.next());
			}
		}
		return lookupKeys;
	}

	/**
	 * Sets the prop hash keys.
	 *
	 * @param aaiRes the aai res
	 * @param propHash the prop hash
	 * @param _propertyDataTypeMap the property data type map
	 * @param keysWithVals the keys with vals
	 * @param aaiExtMap the aai ext map
	 */
	public void setPropHashKeys(AAIResource aaiRes, HashMap<String, Object> propHash, 
			Map<String, String> _propertyDataTypeMap, LinkedHashMap<String, Object> keysWithVals, AAIExtensionMap aaiExtMap) {
		
		for (Entry<String,Object> ent : keysWithVals.entrySet()) { 
			propHash.put(ent.getKey(),  ent.getValue());
		}
				
	}
	
	/**
	 * Fill prop hash from object.
	 *
	 * @param <T> the generic type
	 * @param clazz the clazz
	 * @param propHash the prop hash
	 * @param _propertyDataTypeMap the property data type map
	 * @param aaiExtMap the aai ext map
	 * @throws IllegalAccessException the illegal access exception
	 * @throws IllegalArgumentException the illegal argument exception
	 * @throws InvocationTargetException the invocation target exception
	 */
	public <T> void fillPropHashFromObject(T clazz,
			HashMap<String, Object> propHash, Map<String, String> _propertyDataTypeMap, AAIExtensionMap aaiExtMap) 
					throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
			
		
		Method[] methods = clazz.getClass().getDeclaredMethods();
		String dnHypPropertyName = "";
		String dnHypTitanPropertyName = "";
		// couldn't i prechew this?
		for (Method method : methods) { 
			boolean go = false;
			if (method.getName().startsWith("get")) { 
				dnHypPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,method.getName().substring(3));
				go = true;
			} else if (method.getName().startsWith("is")) { 
				dnHypPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,method.getName().substring(2));
				go = true;
			}
			dnHypTitanPropertyName = dnHypPropertyName;
			if (dnHypPropertyName.equals("cvlan-tag-entry")) { 
				dnHypTitanPropertyName = "cvlan-tag";
			}
			
			if (propHash.containsKey(dnHypTitanPropertyName)) { 
				// maybe check to see if the payload matches the URL, but we're not doing that now...
				continue;
			}
			
			if (go) { 
				String retType = method.getReturnType().getName();
				if (!retType.contains("aai") && !retType.contains("java.util.List")) {
					// get the setter
												
					if (retType.contains("String")) { 
						String val = (String)method.invoke(clazz);
						if (val != null) { 
							propHash.put(dnHypTitanPropertyName, val);
						}
					} else if (retType.toLowerCase().contains("long")) {
						String titanType = _propertyDataTypeMap.get(dnHypTitanPropertyName);
						
						Long val = (Long)method.invoke(clazz);
						// we have a case where the type in titan is "Integer" but in the POJO it's Long or long
						if (val != null) { 
							if (titanType.toLowerCase().contains("int")) {
								propHash.put(dnHypTitanPropertyName, val.intValue());
							} else { 
								propHash.put(dnHypTitanPropertyName, val);
							}
						}
						
					} else if (retType.toLowerCase().contains("int")) { 
						Integer val = (Integer)method.invoke(clazz);
						if (val != null) { 
							propHash.put(dnHypTitanPropertyName, val);
						}
					} else if (retType.toLowerCase().contains("short")) { 
						Short val = (Short)method.invoke(clazz);
						if (val != null) { 
							propHash.put(dnHypTitanPropertyName, val);
						}
					} else if (retType.toLowerCase().contains("boolean")) { 
						Boolean val = (Boolean)method.invoke(clazz);
						if (val != null) { 
							propHash.put(dnHypTitanPropertyName, val);
						}
					}
				}
			}
		}
	}

	/**
	 * Gets the example object.
	 *
	 * @param <T> the generic type
	 * @param clazz the clazz
	 * @param singleton the singleton
	 * @return the example object
	 * @throws IllegalAccessException the illegal access exception
	 * @throws IllegalArgumentException the illegal argument exception
	 * @throws InvocationTargetException the invocation target exception
	 * @throws NoSuchMethodException the no such method exception
	 * @throws SecurityException the security exception
	 * @throws AAIException the AAI exception
	 */
	public <T> void getExampleObject(T clazz, boolean singleton) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, AAIException {
		Method[] methods = clazz.getClass().getDeclaredMethods();
		String dnHypPropertyName = "";
		String upCamPropertyName = "";
		Random rand = new Random();
		int randInt = rand.nextInt(10000000);

		for (Method method : methods) { 
			boolean go = false;
			if (method.getName().startsWith("get")) { 
				dnHypPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,method.getName().substring(3));
				upCamPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_CAMEL,method.getName().substring(3));
				go = true;
			} else if (method.getName().startsWith("is")) { 
				dnHypPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,method.getName().substring(2));
				upCamPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_CAMEL,method.getName().substring(2));
				go = true;
			}
			// don't return resource-version on a singleton
			if (singleton && dnHypPropertyName.equals("resource-version")) {
				go = false;
			}
			if (go) { 
				String retType = method.getReturnType().getName();
				if (!retType.contains("aai") && !retType.contains("java.util.List")) {
					// get the setter
					Method meth = clazz.getClass().getMethod("set" + upCamPropertyName, method.getReturnType());
					
					if (retType.contains("String")) { 
						String val = "example-" + dnHypPropertyName + "-val-" +  randInt;
						if (val != null) { 
							meth.invoke(clazz, val);
						}
					} else if (retType.toLowerCase().contains("long")) {
						Integer foo = rand.nextInt(100000);
						meth.invoke(clazz, foo.longValue());
					} else if (retType.toLowerCase().contains("int")) { 
						meth.invoke(clazz, rand.nextInt(100000));
					} else if (retType.toLowerCase().contains("short")) { 
						Integer randShort = rand.nextInt(10000);
						meth.invoke(clazz, randShort.shortValue());
					} else if (retType.toLowerCase().contains("boolean")) { 
						meth.invoke(clazz, true);
					}
				}
			}
		}
	}

	
	/**
	 * Gets the aai object from vertex.
	 *
	 * @param <T> the generic type
	 * @param clazz the clazz
	 * @param vert the vert
	 * @param _propertyDataTypeMap the property data type map
	 * @return the aai object from vertex
	 * @throws IllegalAccessException the illegal access exception
	 * @throws IllegalArgumentException the illegal argument exception
	 * @throws InvocationTargetException the invocation target exception
	 * @throws NoSuchMethodException the no such method exception
	 * @throws SecurityException the security exception
	 * @throws AAIException the AAI exception
	 */
	public <T> void getAaiObjectFromVertex(T clazz, TitanVertex vert, Map<String, String> _propertyDataTypeMap) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, AAIException {
		Method[] methods = clazz.getClass().getDeclaredMethods();
		String dnHypPropertyName = "";
		String upCamPropertyName = "";
		for (Method method : methods) { 
			boolean go = false;
			if (method.getName().startsWith("get")) { 
				dnHypPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,method.getName().substring(3));
				upCamPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_CAMEL,method.getName().substring(3));
				go = true;
			} else if (method.getName().startsWith("is")) { 
				dnHypPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,method.getName().substring(2));
				upCamPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_CAMEL,method.getName().substring(2));
				go = true;
			}
			if (go) { 
				String retType = method.getReturnType().getName();
				if (!retType.contains("aai") && !retType.contains("java.util.List")) {
					// get the setter
					Method meth = clazz.getClass().getMethod("set" + upCamPropertyName, method.getReturnType());
					
					if (retType.contains("String")) { 
						String val = (String)vert.<String>property(dnHypPropertyName).orElse(null);
						if (val != null) { 
							meth.invoke(clazz, val);
						}
					} else if (retType.toLowerCase().contains("long")) {
						String titanType = _propertyDataTypeMap.get(dnHypPropertyName);
						
						Long val = null;
						// we have a case where the type in titan is "Integer" but in the POJO it's Long or long
						if (titanType.toLowerCase().contains("int")) {
							Integer intVal = (Integer)vert.<Integer>property(dnHypPropertyName).orElse(null);
							if (intVal != null) { 
								val = intVal.longValue();
							}
						} else { 
							val = (Long)vert.<Long>property(dnHypPropertyName).orElse(null);
						}
						if (val != null) { 
							meth.invoke(clazz, val);
						}
					} else if (retType.toLowerCase().contains("int")) { 
						Integer val = (Integer)vert.<Integer>property(dnHypPropertyName).orElse(null);
						if (val != null) { 
							meth.invoke(clazz, val);
						}
					} else if (retType.toLowerCase().contains("short")) { 
						Short val = (Short)vert.<Short>property(dnHypPropertyName).orElse(null);
						if (val != null) { 
							meth.invoke(clazz, val);
						}
					} else if (retType.toLowerCase().contains("boolean")) { 
						Boolean val = (Boolean)vert.<Boolean>property(dnHypPropertyName).orElse(null);
						if (val != null) { 
							meth.invoke(clazz, val);
						}
					}
				}
			}
		}
	}

	/**
	 * Gets the topology object.
	 *
	 * @param <T> the generic type
	 * @param clazz the clazz
	 * @param _dbRulesNodeNameProps the db rules node name props
	 * @param _dbRulesNodeKeyProps the db rules node key props
	 * @param vert the vert
	 * @return the topology object
	 * @throws IllegalAccessException the illegal access exception
	 * @throws IllegalArgumentException the illegal argument exception
	 * @throws InvocationTargetException the invocation target exception
	 * @throws NoSuchMethodException the no such method exception
	 * @throws SecurityException the security exception
	 * @throws AAIException the AAI exception
	 */
	public <T> void getTopologyObject(T clazz, Multimap<String, String> _dbRulesNodeNameProps, Multimap<String, String> _dbRulesNodeKeyProps, TitanVertex vert) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, AAIException {
		Method[] methods = clazz.getClass().getDeclaredMethods();
		String dnHypPropertyName = "";
//		Object value = null;
		List<String> includeProps = new ArrayList<String>();
				
		if ("false".equals(AAIConfig.get("aai.notification.topology.allAttrs", "false"))) {
			for (Method method : methods) { 
				if (method.getName().startsWith("is")) { 
					dnHypPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,method.getName().substring(2));
					String upCamPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_CAMEL,method.getName().substring(2));
					String retType = method.getReturnType().getName();
					if (retType.equals("java.lang.Boolean")) {
						// get the setter
						Method setterMeth = clazz.getClass().getMethod("set" + upCamPropertyName, method.getReturnType());
						setterMeth.invoke(clazz, (Boolean)null);
					}
				}
			}
			String dnHypClassName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,clazz.getClass().getSimpleName());
			Collection<String> keepProps = _dbRulesNodeNameProps.get(dnHypClassName);
			Iterator <String> keepPropI = keepProps.iterator();
			while( keepPropI.hasNext() ){
				includeProps.add(keepPropI.next());
			}
			Collection<String> keepProps2 = _dbRulesNodeKeyProps.get(dnHypClassName);
			Iterator <String> keepPropI2 = keepProps2.iterator();
			while( keepPropI2.hasNext() ){
				includeProps.add(keepPropI2.next());
			}
		}
		
		for (Method method : methods) { 
			if (method.getName().startsWith("get")) { 
				dnHypPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,method.getName().substring(3));
				if (includeProps.size() > 0) { 
					if (!includeProps.contains(dnHypPropertyName)) {
						continue;
					}
				}
				String upCamPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_CAMEL,method.getName().substring(3));
				String retType = method.getReturnType().getName();
				if (!retType.contains("aai") && !retType.contains("java.util.List")) {
					// get the setter
					Method meth = clazz.getClass().getMethod("set" + upCamPropertyName, method.getReturnType());
					
					if (retType.contains("String")) { 
						String val = (String)vert.<String>property(dnHypPropertyName).orElse(null);
						if (val != null) { 
							meth.invoke(clazz, val);
						}
					} else if (retType.toLowerCase().contains("long")) {
						Long val = (Long)vert.<Long>property(dnHypPropertyName).orElse(null);
						if (val != null) { 
							meth.invoke(clazz, val);
						}
					} else if (retType.toLowerCase().contains("int")) { 
						Integer val = (Integer)vert.<Integer>property(dnHypPropertyName).orElse(null);
						if (val != null) { 
							meth.invoke(clazz, val);
						}
					} else if (retType.toLowerCase().contains("short")) { 
						Short val = (Short)vert.<Short>property(dnHypPropertyName).orElse(null);
						if (val != null) { 
							meth.invoke(clazz, val);
						}
					}
				}
			}
		}
	}

	/**
	 * Gets the dynamic topology object.
	 *
	 * @param aaiRes the aai res
	 * @param meObjectType the me object type
	 * @param _dbRulesNodeNameProps the db rules node name props
	 * @param _dbRulesNodeKeyProps the db rules node key props
	 * @param _propertyDataTypeMap the property data type map
	 * @param vert the vert
	 * @return the dynamic topology object
	 * @throws AAIException the AAI exception
	 */
	public DynamicEntity getDynamicTopologyObject(AAIResource aaiRes, DynamicType meObjectType, Multimap<String, String> _dbRulesNodeNameProps,
			Multimap<String, String> _dbRulesNodeKeyProps, Map<String, String> _propertyDataTypeMap, TitanVertex vert) throws AAIException {
		
		DynamicEntity meObject = meObjectType.newDynamicEntity();
		
		List<String> includeProps = new ArrayList<String>();
				
		if ("false".equals(AAIConfig.get("aai.notification.topology.allAttrs", "false"))) {
			String dnHypClassName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,meObjectType.getJavaClass().getSimpleName());
			Collection<String> keepProps = _dbRulesNodeNameProps.get(dnHypClassName);
			Iterator <String> keepPropI = keepProps.iterator();
			while( keepPropI.hasNext() ){
				includeProps.add(keepPropI.next());
			}
			Collection<String> keepProps2 = _dbRulesNodeKeyProps.get(dnHypClassName);
			Iterator <String> keepPropI2 = keepProps2.iterator();
			while( keepPropI2.hasNext() ) {
				includeProps.add(keepPropI2.next());
			}
		}
		
	
		
		for (String attrName : aaiRes.getStringFields()) { 
			if (includeProps.contains(attrName)) { 
				meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), vert.<String>property(attrName).orElse(null));
			}
		}
		// the attrName might need to be converted to camel case!!!
		for (String attrName : aaiRes.getLongFields()) {
			if (includeProps.contains(attrName)) { 
				String titanType = _propertyDataTypeMap.get(attrName);		

				Long val = null;
				// we have a case where the type in titan is "Integer" but in the POJO it's Long or long
				if (titanType.toLowerCase().contains("int")) {
					Integer intVal = (Integer)vert.<Integer>property(attrName).orElse(null);
					if (intVal != null) { 
						val = intVal.longValue();
					}
				} else { 
					val = (Long)vert.<Long>property(attrName).orElse(null);
				}
				meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), val);
			}
		}

		for (String attrName : aaiRes.getIntFields()) { 
			if (includeProps.contains(attrName)) { 
				Integer val = (Integer)vert.<Integer>property(attrName).orElse(null);
				meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), val);
			}
		}

		for (String attrName : aaiRes.getShortFields()) { 
			if (includeProps.contains(attrName)) { 
				String titanType = _propertyDataTypeMap.get(attrName);		

				Short val = null;
				// we have a case where the type in titan is "Integer" but in the POJO it's Long or long
				if (titanType.toLowerCase().contains("int")) {
					Integer intVal = (Integer)vert.<Integer>property(attrName).orElse(null);
					if (intVal != null) { 
						val = intVal.shortValue();
					}
				} else { 
					val = (Short)vert.<Short>property(attrName).orElse(null);
				}
				meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), val);
			}
		}

		for (String attrName : aaiRes.getBooleanFields()) {
			if (includeProps.contains(attrName)) { 
				Boolean val = (Boolean)vert.<Boolean>property(attrName).orElse(null);
				meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)),  val);
			}
		}
		return meObject;	
	}

	/**
	 * Gets the aai dynamic object from vertex.
	 *
	 * @param aaiRes the aai res
	 * @param meObject the me object
	 * @param vert the vert
	 * @param _propertyDataTypeMap the property data type map
	 * @return the aai dynamic object from vertex
	 */
	public void getAaiDynamicObjectFromVertex(AAIResource aaiRes, DynamicEntity meObject, TitanVertex vert,
			Map<String, String> _propertyDataTypeMap) {
		getAaiDynamicObjectFromVertex(aaiRes, meObject, vert, _propertyDataTypeMap, null);
	}
	
	/**
	 * Gets the aai dynamic object from vertex.
	 *
	 * @param aaiRes the aai res
	 * @param meObject the me object
	 * @param vert the vert
	 * @param _propertyDataTypeMap the property data type map
	 * @param propertyOverRideHash the property over ride hash
	 * @return the aai dynamic object from vertex
	 */
	@SuppressWarnings("unchecked")
	public void getAaiDynamicObjectFromVertex(AAIResource aaiRes, DynamicEntity meObject, TitanVertex vert,
			Map<String, String> _propertyDataTypeMap, HashMap<String, Object> propertyOverRideHash) {
			
		for (String attrName : aaiRes.getStringFields()) { 
			if (propertyOverRideHash == null || (propertyOverRideHash != null && propertyOverRideHash.containsKey(attrName))) {
				meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), vert.<String>property(attrName).orElse(null));
			}
		}
		
		for (String attrName : aaiRes.getStringListFields()) { 
			if (propertyOverRideHash == null || (propertyOverRideHash != null && propertyOverRideHash.containsKey(attrName))) {
				meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), vert.<ArrayList<String>>property(attrName).orElse(null));
			}
		}
		
		// the attrName might need to be converted to camel case!!!
		for (String attrName : aaiRes.getLongFields()) { 
			String titanType = _propertyDataTypeMap.get(attrName);		
			Long val = null;
			// we have a case where the type in titan is "Integer" but in the POJO it's Long or long
			if (titanType.toLowerCase().contains("int")) {
				Integer intVal = (Integer)vert.<Integer>property(attrName).orElse(null);
				if (intVal != null) { 
					val = intVal.longValue();
				}
			} else { 
				val = (Long)vert.<Long>property(attrName).orElse(null);
			}
			if (val != null) { 
				if (propertyOverRideHash == null || (propertyOverRideHash != null && propertyOverRideHash.containsKey(attrName))) {
					meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), val);
				}
			}
		}
		
		for (String attrName : aaiRes.getIntFields()) { 
			Integer val = (Integer)vert.<Integer>property(attrName).orElse(null);
			if (val != null) { 
				if (propertyOverRideHash == null || (propertyOverRideHash != null && propertyOverRideHash.containsKey(attrName))) {
					meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), val);
				}
			}
		}
		
		for (String attrName : aaiRes.getShortFields()) { 
			String titanType = _propertyDataTypeMap.get(attrName);		
			Short val = null;
			// we have a case where the type in titan is "Integer" but in the POJO it's Long or long
			if (titanType.toLowerCase().contains("int")) {
				Integer intVal = (Integer)vert.<Integer>property(attrName).orElse(null);
				if (intVal != null) { 
					val = intVal.shortValue();
				}
			} else { 
				val = (Short)vert.<Short>property(attrName).orElse(null);
			}
			if (val != null) { 
				if (propertyOverRideHash == null || (propertyOverRideHash != null && propertyOverRideHash.containsKey(attrName))) {
					meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), val);
				}
			}
		}
		
		for (String attrName : aaiRes.getBooleanFields()) {
			Boolean val = (Boolean)vert.<Boolean>property(attrName).orElse(null);
			// This is not ideal, but moxy isn't marshalling these attributes.
			// TODO: Figure out how to see the default-value from the OXM at startup (or at runtime).
			String dnHypClassName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,aaiRes.getSimpleName());
			if (val == null && AAIConfig.getDefaultBools().containsKey(dnHypClassName)) { 
				if (AAIConfig.getDefaultBools().get(dnHypClassName).contains(attrName)) { 
					val = false;
				}
			}
			if (val != null) { 
				if (propertyOverRideHash == null || (propertyOverRideHash != null && propertyOverRideHash.containsKey(attrName))) {
					meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)),  val);
				}
			}
		}
			
	}

	/**
	 * Fill prop hash from dynamic object.
	 *
	 * @param aaiRes the aai res
	 * @param meObject the me object
	 * @param propHash the prop hash
	 * @param _propertyDataTypeMap the property data type map
	 * @param aaiExtMap the aai ext map
	 */
	public void fillPropHashFromDynamicObject(AAIResource aaiRes, DynamicEntity meObject, HashMap<String, Object> propHash,
			Map<String, String> _propertyDataTypeMap, AAIExtensionMap aaiExtMap) {
		
		for (String dnHypAttrName : aaiRes.getStringFields()) { 
			String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
			if (propHash.containsKey(dnHypAttrName)) {
				continue;
			}
									
			String val = (String)meObject.get(dnCamAttrName);
			
			if (val == null && aaiRes.getAutoGenUuidFields().contains(dnHypAttrName)) {
				// Generate one here
				val = UUID.randomUUID().toString();
			}
					
			if (val != null) { 
				propHash.put(dnHypAttrName, val);
			}
		}
		
		for (String dnHypAttrName : aaiRes.getStringListFields()) { 
			String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
			if (propHash.containsKey(dnHypAttrName)) {
				continue;
			}
			
			@SuppressWarnings("unchecked")
			ArrayList<String> val = (ArrayList<String>)meObject.get(dnCamAttrName);
			if (val != null) { 
				propHash.put(dnHypAttrName, val);
			}
		}
		
		// the attrName might need to be converted to camel case!!!
		for (String dnHypAttrName : aaiRes.getLongFields()) { 
			String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
			if (propHash.containsKey(dnHypAttrName)) {
				continue;
			}
			
			String titanType = _propertyDataTypeMap.get(dnHypAttrName);
			
			Long val = (Long)meObject.get(dnCamAttrName);
			// we have a case where the type in titan is "Integer" but in the POJO it's Long or long
			if (val != null) { 
				if (titanType.toLowerCase().contains("int")) {
					propHash.put(dnHypAttrName, val.intValue());
				} else { 
					propHash.put(dnHypAttrName, val);
				}
			}
		}
		
		for (String dnHypAttrName : aaiRes.getIntFields()) { 
			String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
			if (propHash.containsKey(dnHypAttrName)) {
				continue;
			}
			Integer val = (Integer)meObject.get(dnCamAttrName);
			if (val != null) { 
				propHash.put(dnHypAttrName, val);
			}
		}
		
		for (String dnHypAttrName : aaiRes.getShortFields()) { 
			String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
			if (propHash.containsKey(dnHypAttrName)) {
				continue;
			}
			String titanType = _propertyDataTypeMap.get(dnHypAttrName);
			
			Short val = (Short)meObject.get(dnCamAttrName);
			// we have a case where the type in titan is "Integer" but in the POJO it's Long or long
			if (val != null) { 
				if (titanType.toLowerCase().contains("int")) {
					propHash.put(dnHypAttrName, val.intValue());
				} else { 
					propHash.put(dnHypAttrName, val);
				}
			}
		}
		
		for (String dnHypAttrName : aaiRes.getBooleanFields()) {
			String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
			if (propHash.containsKey(dnHypAttrName)) {
				continue;
			}
			Boolean val = (Boolean)meObject.get(dnCamAttrName);
			if (val != null) { 
				propHash.put(dnHypAttrName, val);
			} else {
				String dnHypClassName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,aaiRes.getSimpleName());
				if (AAIConfig.getDefaultBools().containsKey(dnHypClassName)) { 
					if (AAIConfig.getDefaultBools().get(dnHypClassName).contains(dnHypAttrName)) { 
						propHash.put(dnHypAttrName, false);
					}
				}
			}
		}
	}

	/**
	 * Gets the dynamic example object.
	 *
	 * @param childObject the child object
	 * @param aaiRes the aai res
	 * @param singleton the singleton
	 * @return the dynamic example object
	 */
	public void getDynamicExampleObject(DynamicEntity childObject, AAIResource aaiRes, boolean singleton) {
		// TODO Auto-generated method stub

		Random rand = new Random();
		Integer randInt = rand.nextInt(100000);
		long range = 100000000L;
		long randLong = (long)(rand.nextDouble()*range);
		Integer randShrt = rand.nextInt(20000);
		short randShort = randShrt.shortValue();

		for (String dnHypAttrName : aaiRes.getStringFields()) { 
			
			if (singleton && ("resource-version").equals(dnHypAttrName)) {
				continue;
			}
			
			String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
			childObject.set(dnCamAttrName, "example-" + dnHypAttrName + "-val-" +  randInt);

		}
		
		for (String dnHypAttrName : aaiRes.getStringListFields()) { 
			ArrayList<String> exampleList = new ArrayList<String>();
			exampleList.add("example-" + dnHypAttrName + "-val-" + randInt + "-" + 1);
			exampleList.add("example-" + dnHypAttrName + "-val-" + randInt + "-" + 2);
			String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
			childObject.set(dnCamAttrName, exampleList);
		}
		
		// the attrName might need to be converted to camel case!!!
		for (String dnHypAttrName : aaiRes.getLongFields()) { 
			String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
			childObject.set(dnCamAttrName, randLong);
		}

		for (String dnHypAttrName : aaiRes.getIntFields()) { 
			String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
			childObject.set(dnCamAttrName, randInt);
		}

		for (String dnHypAttrName : aaiRes.getShortFields()) { 
			String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
			childObject.set(dnCamAttrName, randShort);
		}

		for (String dnHypAttrName : aaiRes.getBooleanFields()) {
			String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
			childObject.set(dnCamAttrName, Boolean.TRUE);
		}
	}
}