Replace deprecated methods in aai-common
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / introspection / Introspector.java
index 9e599a6..87983d8 100644 (file)
 
 package org.onap.aai.introspection;
 
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
 import com.google.common.base.CaseFormat;
 
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.InvocationTargetException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
 import java.util.stream.Collectors;
 
-import org.apache.commons.lang.ClassUtils;
+import org.apache.commons.lang3.ClassUtils;
 import org.eclipse.persistence.exceptions.DynamicException;
 import org.onap.aai.config.SpringContextAware;
 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
@@ -42,10 +47,12 @@ import org.onap.aai.schema.enums.ObjectMetadata;
 import org.onap.aai.schema.enums.PropertyMetadata;
 import org.onap.aai.setup.SchemaVersion;
 import org.onap.aai.workarounds.NamingExceptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public abstract class Introspector implements Cloneable {
 
-    private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(Introspector.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(Introspector.class);
 
     protected String className;
     protected String uriChain = "";
@@ -54,6 +61,7 @@ public abstract class Introspector implements Cloneable {
     private Set<String> uniqueProperties = null;
     private Set<String> indexedProperties = null;
     private Set<String> allKeys = null;
+    private Set<String> dslStartNodeProperties = null;
 
     protected CaseFormatStore caseFormatStore = null;
     protected NodeIngestor nodeIngestor;
@@ -95,9 +103,10 @@ public abstract class Introspector implements Cloneable {
         Class<?> clazz = this.getClass(name);
         if (this.isListType(name) && result == null) {
             try {
-                this.set(convertedName, clazz.newInstance());
+                this.set(convertedName, clazz.getDeclaredConstructor().newInstance());
                 result = this.get(convertedName);
-            } catch (DynamicException | InstantiationException | IllegalAccessException e) {
+            } catch (DynamicException | InstantiationException | IllegalAccessException | IllegalArgumentException
+                    | InvocationTargetException | NoSuchMethodException | SecurityException e) {
                 LOGGER.warn(e.getMessage(), e);
             }
         }
@@ -119,9 +128,10 @@ public abstract class Introspector implements Cloneable {
         Class<?> clazz = this.getClass(name);
         if (this.isListType(name) && value == null) {
             try {
-                this.set(convertedName, clazz.newInstance());
+                this.set(convertedName, clazz.getDeclaredConstructor().newInstance());
                 value = this.get(convertedName);
-            } catch (DynamicException | InstantiationException | IllegalAccessException e) {
+            } catch (DynamicException | InstantiationException | IllegalAccessException | IllegalArgumentException
+                    | InvocationTargetException | NoSuchMethodException | SecurityException e) {
                 LOGGER.warn(e.getMessage(), e);
             }
         }
@@ -151,9 +161,10 @@ public abstract class Introspector implements Cloneable {
         Class<?> clazz = this.getClass(name);
         if (isListType && value == null) {
             try {
-                this.set(convertedName, clazz.newInstance());
+                this.set(convertedName, clazz.getDeclaredConstructor().newInstance());
                 value = this.get(convertedName);
-            } catch (DynamicException | InstantiationException | IllegalAccessException e) {
+            } catch (DynamicException | InstantiationException | IllegalAccessException | IllegalArgumentException
+                    | InvocationTargetException | NoSuchMethodException | SecurityException e) {
                 LOGGER.warn(e.getMessage(), e);
             }
         }
@@ -177,7 +188,7 @@ public abstract class Introspector implements Cloneable {
         if (obj != null) {
 
             try {
-                if (!obj.getClass().getName().equals(nameClass.getName())) {
+                if (!(obj.getClass().getCanonicalName().equals(nameClass.getCanonicalName()))) {
                     if (nameClass.isPrimitive()) {
                         nameClass = ClassUtils.primitiveToWrapper(nameClass);
                         result = nameClass.getConstructor(String.class).newInstance(obj.toString());
@@ -229,15 +240,8 @@ public abstract class Introspector implements Cloneable {
 
     public Set<String> getProperties(PropertyPredicate<Introspector, String> p) {
         final Set<String> temp = new LinkedHashSet<>();
-        this.getProperties().stream().filter(item -> {
-            return p.test(this, item);
-        }).forEach(item -> {
-            temp.add(item);
-        });
-        final Set<String> result = Collections.unmodifiableSet(temp);
-
-        return result;
-
+        this.getProperties().stream().filter(item -> p.test(this, item)).forEach(temp::add);
+        return Collections.unmodifiableSet(temp);
     }
 
     public Set<String> getSimpleProperties(PropertyPredicate<Introspector, String> p) {
@@ -301,6 +305,30 @@ public abstract class Introspector implements Cloneable {
         return result;
     }
 
+    public Set<String> getDslStartNodeProperties() {
+        Set<String> result = null;
+
+        if (this.dslStartNodeProperties == null) {
+            /*
+             * The dslStartNodeProperties will have keys by default
+             * If dslStartNodeProps exist in the oxm use it
+             * if not use the indexedProps
+             */
+            result = new LinkedHashSet<>(this.getKeys());
+
+            String dslKeys = this.getMetadata(ObjectMetadata.DSL_START_NODE_PROPS);
+            String indexedKeys = this.getMetadata(ObjectMetadata.INDEXED_PROPS);
+            if (dslKeys != null) {
+                Arrays.stream(dslKeys.split(",")).forEach(result::add);
+            } else if (indexedKeys != null) {
+                Arrays.stream(indexedKeys.split(",")).forEach(result::add);
+            }
+            this.dslStartNodeProperties = Collections.unmodifiableSet(result);
+        }
+        result = this.dslStartNodeProperties;
+        return result;
+    }
+
     public Set<String> getUniqueProperties() {
         Set<String> result = null;
         if (this.uniqueProperties == null) {
@@ -349,7 +377,7 @@ public abstract class Introspector implements Cloneable {
     /**
      * This will returned the generic parameterized type of the underlying
      * object if it exists
-     * 
+     *
      * @param name
      * @return the generic type of the java class of the underlying object
      */
@@ -414,7 +442,7 @@ public abstract class Introspector implements Cloneable {
 
     /**
      * Is this type not a Java String or primitive
-     * 
+     *
      * @param name
      * @return
      */