Replace deprecated methods in aai-common
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / introspection / Introspector.java
index 53f2a2c..87983d8 100644 (file)
 
 package org.onap.aai.introspection;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import com.google.common.base.CaseFormat;
-import org.apache.commons.lang.ClassUtils;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+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.lang3.ClassUtils;
 import org.eclipse.persistence.exceptions.DynamicException;
 import org.onap.aai.config.SpringContextAware;
 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
@@ -36,11 +47,8 @@ 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 java.io.UnsupportedEncodingException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.*;
-import java.util.stream.Collectors;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public abstract class Introspector implements Cloneable {
 
@@ -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());
@@ -309,8 +320,7 @@ public abstract class Introspector implements Cloneable {
             String indexedKeys = this.getMetadata(ObjectMetadata.INDEXED_PROPS);
             if (dslKeys != null) {
                 Arrays.stream(dslKeys.split(",")).forEach(result::add);
-            }
-            else if(indexedKeys != null){
+            } else if (indexedKeys != null) {
                 Arrays.stream(indexedKeys.split(",")).forEach(result::add);
             }
             this.dslStartNodeProperties = Collections.unmodifiableSet(result);