2 * ============LICENSE_START=======================================================
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
11 http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.aai.util;
23 import com.fasterxml.jackson.annotation.JsonInclude;
24 import com.fasterxml.jackson.core.JsonGenerationException;
25 import com.fasterxml.jackson.databind.DeserializationFeature;
26 import com.fasterxml.jackson.databind.JsonMappingException;
27 import com.fasterxml.jackson.databind.ObjectMapper;
28 import com.fasterxml.jackson.databind.SerializationFeature;
29 import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
30 import com.google.common.base.CaseFormat;
31 import com.google.common.collect.Multimap;
32 import com.thinkaurelius.titan.core.TitanVertex;
33 import org.apache.commons.io.output.ByteArrayOutputStream;
34 import org.eclipse.persistence.dynamic.DynamicEntity;
35 import org.eclipse.persistence.dynamic.DynamicType;
36 import org.eclipse.persistence.jaxb.MarshallerProperties;
37 import org.openecomp.aai.domain.model.AAIResource;
38 import org.openecomp.aai.exceptions.AAIException;
40 import javax.xml.bind.JAXBContext;
41 import javax.xml.bind.JAXBException;
42 import javax.xml.bind.Marshaller;
43 import java.io.IOException;
44 import java.io.StringWriter;
45 import java.lang.reflect.InvocationTargetException;
46 import java.lang.reflect.Method;
48 import java.util.Map.Entry;
50 public class PojoUtils {
53 * Gets the key value list.
55 * @param <T> the generic type
57 * @param clazz the clazz
58 * @return the key value list
59 * @throws IllegalAccessException the illegal access exception
60 * @throws IllegalArgumentException the illegal argument exception
61 * @throws InvocationTargetException the invocation target exception
63 public <T> List<KeyValueList> getKeyValueList(Entity e, T clazz) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
64 List<KeyValueList> kvList = e.getKeyValueList();
66 Method[] methods = clazz.getClass().getDeclaredMethods();
67 String propertyName = "";
69 for (Method method : methods) {
70 if (method.getName().startsWith("get")) {
71 propertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,method.getName().substring(3));
72 if (!(method.getReturnType().getName().contains("aai")) || method.getReturnType().getName().contains("java.util.List")) {
73 value = method.invoke(clazz);
74 KeyValueList kv = new KeyValueList();
75 kv.setKey(propertyName);
77 kv.setValue(value.toString());
89 * Gets the json from object.
91 * @param <T> the generic type
92 * @param clazz the clazz
93 * @return the json from object
94 * @throws JsonGenerationException the json generation exception
95 * @throws JsonMappingException the json mapping exception
96 * @throws IOException Signals that an I/O exception has occurred.
98 public <T> String getJsonFromObject(T clazz) throws JsonGenerationException, JsonMappingException, IOException {
99 return getJsonFromObject(clazz, false, true);
103 * Gets the json from object.
105 * @param <T> the generic type
106 * @param clazz the clazz
107 * @param wrapRoot the wrap root
108 * @param indent the indent
109 * @return the json from object
110 * @throws JsonGenerationException the json generation exception
111 * @throws JsonMappingException the json mapping exception
112 * @throws IOException Signals that an I/O exception has occurred.
114 public <T> String getJsonFromObject(T clazz, boolean wrapRoot, boolean indent) throws JsonGenerationException, JsonMappingException, IOException {
115 ObjectMapper mapper = new ObjectMapper();
117 mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
119 mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
120 mapper.configure(SerializationFeature.INDENT_OUTPUT, indent);
121 mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, wrapRoot);
123 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
124 mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, wrapRoot);
126 mapper.registerModule(new JaxbAnnotationModule());
128 ByteArrayOutputStream baos = new ByteArrayOutputStream();
130 mapper.writeValue(baos, clazz);
132 return baos.toString();
136 * Gets the json from dynamic object.
139 * @param jaxbContext the jaxb context
140 * @param includeRoot the include root
141 * @return the json from dynamic object
142 * @throws JsonGenerationException the json generation exception
143 * @throws JsonMappingException the json mapping exception
144 * @throws IOException Signals that an I/O exception has occurred.
145 * @throws JAXBException the JAXB exception
147 public String getJsonFromDynamicObject(DynamicEntity ent, org.eclipse.persistence.jaxb.JAXBContext jaxbContext, boolean includeRoot) throws JsonGenerationException, JsonMappingException, IOException, JAXBException {
148 org.eclipse.persistence.jaxb.JAXBMarshaller marshaller = jaxbContext.createMarshaller();
150 marshaller.setProperty(org.eclipse.persistence.jaxb.JAXBMarshaller.JAXB_FORMATTED_OUTPUT, false);
151 marshaller.setProperty(MarshallerProperties.JSON_MARSHAL_EMPTY_COLLECTIONS, Boolean.FALSE) ;
152 marshaller.setProperty("eclipselink.json.include-root", includeRoot);
153 marshaller.setProperty("eclipselink.media-type", "application/json");
154 StringWriter writer = new StringWriter();
155 marshaller.marshal(ent, writer);
157 return writer.toString();
161 * Gets the xml from object.
163 * @param <T> the generic type
164 * @param clazz the clazz
165 * @return the xml from object
166 * @throws JAXBException the JAXB exception
168 public <T> String getXmlFromObject(T clazz) throws JAXBException {
169 ByteArrayOutputStream baos = new ByteArrayOutputStream();
170 JAXBContext jc = JAXBContext.newInstance(clazz.getClass().getPackage().getName());
172 Marshaller marshaller = jc.createMarshaller();
173 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
174 marshaller.marshal(clazz, baos);
176 return baos.toString();
180 * Gets the lookup key.
182 * @param baseKey the base key
183 * @param lookupHash the lookup hash
184 * @param keyProps the key props
185 * @return the lookup key
187 public String getLookupKey (String baseKey, HashMap<String,Object> lookupHash, Collection<String> keyProps) {
188 int baseKeyLen = baseKey.length();
189 StringBuffer newKey = new StringBuffer();
190 if (baseKeyLen > 0) {
191 newKey.append(baseKey);
194 Iterator <String> keyPropI = keyProps.iterator();
195 while( keyPropI.hasNext() ){
196 String keyProp = keyPropI.next();
197 if (baseKeyLen > 0) {
200 newKey.append(keyProp + "=" + lookupHash.get(keyProp));
202 return newKey.toString();
206 * Gets the lookup keys.
208 * @param lookupHashes the lookup hashes
209 * @param _dbRulesNodeKeyProps the db rules node key props
210 * @return the lookup keys
212 public String getLookupKeys (LinkedHashMap<String,HashMap<String,Object>> lookupHashes, Multimap<String, String> _dbRulesNodeKeyProps) {
213 Iterator<String> it = lookupHashes.keySet().iterator();
214 String lookupKeys = "";
215 while (it.hasNext()) {
216 String objectType = (String)it.next();
217 HashMap<String,Object> lookupHash = lookupHashes.get(objectType);
219 Collection<String> keyProps = _dbRulesNodeKeyProps.get(objectType);
220 Iterator <String> keyPropI = keyProps.iterator();
221 while( keyPropI.hasNext() ){
222 lookupKeys += lookupHash.get(keyPropI.next());
229 * Gets the example object.
231 * @param <T> the generic type
232 * @param clazz the clazz
233 * @param singleton the singleton
234 * @return the example object
235 * @throws IllegalAccessException the illegal access exception
236 * @throws IllegalArgumentException the illegal argument exception
237 * @throws InvocationTargetException the invocation target exception
238 * @throws NoSuchMethodException the no such method exception
239 * @throws SecurityException the security exception
240 * @throws AAIException the AAI exception
242 public <T> void getExampleObject(T clazz, boolean singleton) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, AAIException {
243 Method[] methods = clazz.getClass().getDeclaredMethods();
244 String dnHypPropertyName = "";
245 String upCamPropertyName = "";
246 Random rand = new Random();
247 int randInt = rand.nextInt(10000000);
249 for (Method method : methods) {
251 if (method.getName().startsWith("get")) {
252 dnHypPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,method.getName().substring(3));
253 upCamPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_CAMEL,method.getName().substring(3));
255 } else if (method.getName().startsWith("is")) {
256 dnHypPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,method.getName().substring(2));
257 upCamPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_CAMEL,method.getName().substring(2));
260 // don't return resource-version on a singleton
261 if (singleton && dnHypPropertyName.equals("resource-version")) {
265 String retType = method.getReturnType().getName();
266 if (!retType.contains("aai") && !retType.contains("java.util.List")) {
268 Method meth = clazz.getClass().getMethod("set" + upCamPropertyName, method.getReturnType());
270 if (retType.contains("String")) {
271 String val = "example-" + dnHypPropertyName + "-val-" + randInt;
273 meth.invoke(clazz, val);
275 } else if (retType.toLowerCase().contains("long")) {
276 Integer foo = rand.nextInt(100000);
277 meth.invoke(clazz, foo.longValue());
278 } else if (retType.toLowerCase().contains("int")) {
279 meth.invoke(clazz, rand.nextInt(100000));
280 } else if (retType.toLowerCase().contains("short")) {
281 Integer randShort = rand.nextInt(10000);
282 meth.invoke(clazz, randShort.shortValue());
283 } else if (retType.toLowerCase().contains("boolean")) {
284 meth.invoke(clazz, true);
293 * Gets the aai object from vertex.
295 * @param <T> the generic type
296 * @param clazz the clazz
297 * @param vert the vert
298 * @param _propertyDataTypeMap the property data type map
299 * @return the aai object from vertex
300 * @throws IllegalAccessException the illegal access exception
301 * @throws IllegalArgumentException the illegal argument exception
302 * @throws InvocationTargetException the invocation target exception
303 * @throws NoSuchMethodException the no such method exception
304 * @throws SecurityException the security exception
305 * @throws AAIException the AAI exception
307 public <T> void getAaiObjectFromVertex(T clazz, TitanVertex vert, Map<String, String> _propertyDataTypeMap) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, AAIException {
308 Method[] methods = clazz.getClass().getDeclaredMethods();
309 String dnHypPropertyName = "";
310 String upCamPropertyName = "";
311 for (Method method : methods) {
313 if (method.getName().startsWith("get")) {
314 dnHypPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,method.getName().substring(3));
315 upCamPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_CAMEL,method.getName().substring(3));
317 } else if (method.getName().startsWith("is")) {
318 dnHypPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,method.getName().substring(2));
319 upCamPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_CAMEL,method.getName().substring(2));
323 String retType = method.getReturnType().getName();
324 if (!retType.contains("aai") && !retType.contains("java.util.List")) {
326 Method meth = clazz.getClass().getMethod("set" + upCamPropertyName, method.getReturnType());
328 if (retType.contains("String")) {
329 String val = (String)vert.<String>property(dnHypPropertyName).orElse(null);
331 meth.invoke(clazz, val);
333 } else if (retType.toLowerCase().contains("long")) {
334 String titanType = _propertyDataTypeMap.get(dnHypPropertyName);
337 // we have a case where the type in titan is "Integer" but in the POJO it's Long or long
338 if (titanType.toLowerCase().contains("int")) {
339 Integer intVal = (Integer)vert.<Integer>property(dnHypPropertyName).orElse(null);
340 if (intVal != null) {
341 val = intVal.longValue();
344 val = (Long)vert.<Long>property(dnHypPropertyName).orElse(null);
347 meth.invoke(clazz, val);
349 } else if (retType.toLowerCase().contains("int")) {
350 Integer val = (Integer)vert.<Integer>property(dnHypPropertyName).orElse(null);
352 meth.invoke(clazz, val);
354 } else if (retType.toLowerCase().contains("short")) {
355 Short val = (Short)vert.<Short>property(dnHypPropertyName).orElse(null);
357 meth.invoke(clazz, val);
359 } else if (retType.toLowerCase().contains("boolean")) {
360 Boolean val = (Boolean)vert.<Boolean>property(dnHypPropertyName).orElse(null);
362 meth.invoke(clazz, val);
371 * Gets the topology object.
373 * @param <T> the generic type
374 * @param clazz the clazz
375 * @param _dbRulesNodeNameProps the db rules node name props
376 * @param _dbRulesNodeKeyProps the db rules node key props
377 * @param vert the vert
378 * @return the topology object
379 * @throws IllegalAccessException the illegal access exception
380 * @throws IllegalArgumentException the illegal argument exception
381 * @throws InvocationTargetException the invocation target exception
382 * @throws NoSuchMethodException the no such method exception
383 * @throws SecurityException the security exception
384 * @throws AAIException the AAI exception
386 public <T> void getTopologyObject(T clazz, Multimap<String, String> _dbRulesNodeNameProps, Multimap<String, String> _dbRulesNodeKeyProps, TitanVertex vert) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, AAIException {
387 Method[] methods = clazz.getClass().getDeclaredMethods();
388 String dnHypPropertyName = "";
389 // Object value = null;
390 List<String> includeProps = new ArrayList<String>();
392 if ("false".equals(AAIConfig.get("aai.notification.topology.allAttrs", "false"))) {
393 for (Method method : methods) {
394 if (method.getName().startsWith("is")) {
395 dnHypPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,method.getName().substring(2));
396 String upCamPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_CAMEL,method.getName().substring(2));
397 String retType = method.getReturnType().getName();
398 if (retType.equals("java.lang.Boolean")) {
400 Method setterMeth = clazz.getClass().getMethod("set" + upCamPropertyName, method.getReturnType());
401 setterMeth.invoke(clazz, (Boolean)null);
405 String dnHypClassName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,clazz.getClass().getSimpleName());
406 Collection<String> keepProps = _dbRulesNodeNameProps.get(dnHypClassName);
407 Iterator <String> keepPropI = keepProps.iterator();
408 while( keepPropI.hasNext() ){
409 includeProps.add(keepPropI.next());
411 Collection<String> keepProps2 = _dbRulesNodeKeyProps.get(dnHypClassName);
412 Iterator <String> keepPropI2 = keepProps2.iterator();
413 while( keepPropI2.hasNext() ){
414 includeProps.add(keepPropI2.next());
418 for (Method method : methods) {
419 if (method.getName().startsWith("get")) {
420 dnHypPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,method.getName().substring(3));
421 if (includeProps.size() > 0) {
422 if (!includeProps.contains(dnHypPropertyName)) {
426 String upCamPropertyName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_CAMEL,method.getName().substring(3));
427 String retType = method.getReturnType().getName();
428 if (!retType.contains("aai") && !retType.contains("java.util.List")) {
430 Method meth = clazz.getClass().getMethod("set" + upCamPropertyName, method.getReturnType());
432 if (retType.contains("String")) {
433 String val = (String)vert.<String>property(dnHypPropertyName).orElse(null);
435 meth.invoke(clazz, val);
437 } else if (retType.toLowerCase().contains("long")) {
438 Long val = (Long)vert.<Long>property(dnHypPropertyName).orElse(null);
440 meth.invoke(clazz, val);
442 } else if (retType.toLowerCase().contains("int")) {
443 Integer val = (Integer)vert.<Integer>property(dnHypPropertyName).orElse(null);
445 meth.invoke(clazz, val);
447 } else if (retType.toLowerCase().contains("short")) {
448 Short val = (Short)vert.<Short>property(dnHypPropertyName).orElse(null);
450 meth.invoke(clazz, val);
459 * Gets the dynamic topology object.
461 * @param aaiRes the aai res
462 * @param meObjectType the me object type
463 * @param _dbRulesNodeNameProps the db rules node name props
464 * @param _dbRulesNodeKeyProps the db rules node key props
465 * @param _propertyDataTypeMap the property data type map
466 * @param vert the vert
467 * @return the dynamic topology object
468 * @throws AAIException the AAI exception
470 public DynamicEntity getDynamicTopologyObject(AAIResource aaiRes, DynamicType meObjectType, Multimap<String, String> _dbRulesNodeNameProps,
471 Multimap<String, String> _dbRulesNodeKeyProps, Map<String, String> _propertyDataTypeMap, TitanVertex vert) throws AAIException {
473 DynamicEntity meObject = meObjectType.newDynamicEntity();
475 List<String> includeProps = new ArrayList<String>();
477 if ("false".equals(AAIConfig.get("aai.notification.topology.allAttrs", "false"))) {
478 String dnHypClassName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,meObjectType.getJavaClass().getSimpleName());
479 Collection<String> keepProps = _dbRulesNodeNameProps.get(dnHypClassName);
480 Iterator <String> keepPropI = keepProps.iterator();
481 while( keepPropI.hasNext() ){
482 includeProps.add(keepPropI.next());
484 Collection<String> keepProps2 = _dbRulesNodeKeyProps.get(dnHypClassName);
485 Iterator <String> keepPropI2 = keepProps2.iterator();
486 while( keepPropI2.hasNext() ) {
487 includeProps.add(keepPropI2.next());
493 for (String attrName : aaiRes.getStringFields()) {
494 if (includeProps.contains(attrName)) {
495 meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), vert.<String>property(attrName).orElse(null));
498 // the attrName might need to be converted to camel case!!!
499 for (String attrName : aaiRes.getLongFields()) {
500 if (includeProps.contains(attrName)) {
501 String titanType = _propertyDataTypeMap.get(attrName);
504 // we have a case where the type in titan is "Integer" but in the POJO it's Long or long
505 if (titanType.toLowerCase().contains("int")) {
506 Integer intVal = (Integer)vert.<Integer>property(attrName).orElse(null);
507 if (intVal != null) {
508 val = intVal.longValue();
511 val = (Long)vert.<Long>property(attrName).orElse(null);
513 meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), val);
517 for (String attrName : aaiRes.getIntFields()) {
518 if (includeProps.contains(attrName)) {
519 Integer val = (Integer)vert.<Integer>property(attrName).orElse(null);
520 meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), val);
524 for (String attrName : aaiRes.getShortFields()) {
525 if (includeProps.contains(attrName)) {
526 String titanType = _propertyDataTypeMap.get(attrName);
529 // we have a case where the type in titan is "Integer" but in the POJO it's Long or long
530 if (titanType.toLowerCase().contains("int")) {
531 Integer intVal = (Integer)vert.<Integer>property(attrName).orElse(null);
532 if (intVal != null) {
533 val = intVal.shortValue();
536 val = (Short)vert.<Short>property(attrName).orElse(null);
538 meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), val);
542 for (String attrName : aaiRes.getBooleanFields()) {
543 if (includeProps.contains(attrName)) {
544 Boolean val = (Boolean)vert.<Boolean>property(attrName).orElse(null);
545 meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), val);
552 * Gets the aai dynamic object from vertex.
554 * @param aaiRes the aai res
555 * @param meObject the me object
556 * @param vert the vert
557 * @param _propertyDataTypeMap the property data type map
558 * @return the aai dynamic object from vertex
560 public void getAaiDynamicObjectFromVertex(AAIResource aaiRes, DynamicEntity meObject, TitanVertex vert,
561 Map<String, String> _propertyDataTypeMap) {
562 getAaiDynamicObjectFromVertex(aaiRes, meObject, vert, _propertyDataTypeMap, null);
566 * Gets the aai dynamic object from vertex.
568 * @param aaiRes the aai res
569 * @param meObject the me object
570 * @param vert the vert
571 * @param _propertyDataTypeMap the property data type map
572 * @param propertyOverRideHash the property over ride hash
573 * @return the aai dynamic object from vertex
575 @SuppressWarnings("unchecked")
576 public void getAaiDynamicObjectFromVertex(AAIResource aaiRes, DynamicEntity meObject, TitanVertex vert,
577 Map<String, String> _propertyDataTypeMap, HashMap<String, Object> propertyOverRideHash) {
579 for (String attrName : aaiRes.getStringFields()) {
580 if (propertyOverRideHash == null || (propertyOverRideHash != null && propertyOverRideHash.containsKey(attrName))) {
581 meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), vert.<String>property(dbAliasWorkaround(attrName)).orElse(null));
585 for (String attrName : aaiRes.getStringListFields()) {
586 if (propertyOverRideHash == null || (propertyOverRideHash != null && propertyOverRideHash.containsKey(attrName))) {
587 meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), vert.<ArrayList<String>>property(attrName).orElse(null));
591 // the attrName might need to be converted to camel case!!!
592 for (String attrName : aaiRes.getLongFields()) {
593 String titanType = _propertyDataTypeMap.get(attrName);
595 // we have a case where the type in titan is "Integer" but in the POJO it's Long or long
596 if (titanType.toLowerCase().contains("int")) {
597 Object vertexVal = vert.property(attrName).orElse(null);
598 if (vertexVal != null) {
599 if (vertexVal instanceof Integer) {
600 val = ((Integer)vertexVal).longValue();
603 val = (Long)vert.<Long>property(attrName).orElse(null);
607 val = (Long)vert.<Long>property(attrName).orElse(null);
610 if (propertyOverRideHash == null || (propertyOverRideHash != null && propertyOverRideHash.containsKey(attrName))) {
611 meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), val);
616 for (String attrName : aaiRes.getIntFields()) {
617 Integer val = (Integer)vert.<Integer>property(attrName).orElse(null);
619 if (propertyOverRideHash == null || (propertyOverRideHash != null && propertyOverRideHash.containsKey(attrName))) {
620 meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), val);
625 for (String attrName : aaiRes.getShortFields()) {
626 String titanType = _propertyDataTypeMap.get(attrName);
628 // we have a case where the type in titan is "Integer" but in the POJO it's Long or long
629 if (titanType.toLowerCase().contains("int")) {
630 Integer intVal = (Integer)vert.<Integer>property(attrName).orElse(null);
631 if (intVal != null) {
632 val = intVal.shortValue();
635 val = (Short)vert.<Short>property(attrName).orElse(null);
638 if (propertyOverRideHash == null || (propertyOverRideHash != null && propertyOverRideHash.containsKey(attrName))) {
639 meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), val);
644 for (String attrName : aaiRes.getBooleanFields()) {
645 Boolean val = (Boolean)vert.<Boolean>property(attrName).orElse(null);
646 // This is not ideal, but moxy isn't marshalling these attributes.
647 // TODO: Figure out how to see the default-value from the OXM at startup (or at runtime).
648 String dnHypClassName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,aaiRes.getSimpleName());
649 if (val == null && AAIConfig.getDefaultBools().containsKey(dnHypClassName)) {
650 if (AAIConfig.getDefaultBools().get(dnHypClassName).contains(attrName)) {
655 if (propertyOverRideHash == null || (propertyOverRideHash != null && propertyOverRideHash.containsKey(attrName))) {
656 meObject.set((CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,attrName)), val);
663 private String dbAliasWorkaround(String propName) {
664 final String modelInvariantIdLocal = "model-invariant-id-local";
665 final String modelVersionIdLocal = "model-version-id-local";
666 final String modelInvariantId = "model-invariant-id";
667 final String modelVersionId = "model-version-id";
669 if (propName.equals(modelInvariantId)) {
670 return modelInvariantIdLocal;
672 if (propName.equals(modelVersionId)) {
673 return modelVersionIdLocal;
681 * Gets the dynamic example object.
683 * @param childObject the child object
684 * @param aaiRes the aai res
685 * @param singleton the singleton
686 * @return the dynamic example object
688 public void getDynamicExampleObject(DynamicEntity childObject, AAIResource aaiRes, boolean singleton) {
689 // TODO Auto-generated method stub
691 Random rand = new Random();
692 Integer randInt = rand.nextInt(100000);
693 long range = 100000000L;
694 long randLong = (long)(rand.nextDouble()*range);
695 Integer randShrt = rand.nextInt(20000);
696 short randShort = randShrt.shortValue();
698 for (String dnHypAttrName : aaiRes.getStringFields()) {
700 if (singleton && ("resource-version").equals(dnHypAttrName)) {
704 String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
705 childObject.set(dnCamAttrName, "example-" + dnHypAttrName + "-val-" + randInt);
709 for (String dnHypAttrName : aaiRes.getStringListFields()) {
710 ArrayList<String> exampleList = new ArrayList<String>();
711 exampleList.add("example-" + dnHypAttrName + "-val-" + randInt + "-" + 1);
712 exampleList.add("example-" + dnHypAttrName + "-val-" + randInt + "-" + 2);
713 String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
714 childObject.set(dnCamAttrName, exampleList);
717 // the attrName might need to be converted to camel case!!!
718 for (String dnHypAttrName : aaiRes.getLongFields()) {
719 String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
720 childObject.set(dnCamAttrName, randLong);
723 for (String dnHypAttrName : aaiRes.getIntFields()) {
724 String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
725 childObject.set(dnCamAttrName, randInt);
728 for (String dnHypAttrName : aaiRes.getShortFields()) {
729 String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
730 childObject.set(dnCamAttrName, randShort);
733 for (String dnHypAttrName : aaiRes.getBooleanFields()) {
734 String dnCamAttrName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL,dnHypAttrName);
735 childObject.set(dnCamAttrName, Boolean.TRUE);