Merge "Reduce the number of raw-type related warnings in aai-common"
authorWilliam Reehil <william.reehil@att.com>
Fri, 11 Nov 2022 13:37:39 +0000 (13:37 +0000)
committerGerrit Code Review <gerrit@onap.org>
Fri, 11 Nov 2022 13:37:39 +0000 (13:37 +0000)
1  2 
aai-core/src/main/java/org/onap/aai/introspection/JSONStrategy.java
aai-core/src/main/java/org/onap/aai/query/builder/GraphTraversalBuilder.java
aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java
aai-core/src/main/java/org/onap/aai/serialization/queryformats/Aggregate.java
aai-core/src/main/java/org/onap/aai/serialization/queryformats/GraphSON.java
aai-core/src/main/java/org/onap/aai/serialization/queryformats/HistoryFormat.java
aai-core/src/main/java/org/onap/aai/serialization/queryformats/SimpleFormat.java
aai-core/src/main/java/org/onap/aai/serialization/queryformats/TreeFormat.java
aai-core/src/main/java/org/onap/aai/util/RestController.java
aai-core/src/test/java/org/onap/aai/serialization/queryformats/SimpleFormatTest.java
aai-schema-ingest/src/test/java/org/onap/aai/restclient/MockRestClient.java

@@@ -21,7 -21,6 +21,7 @@@
  package org.onap.aai.introspection;
  
  import java.io.UnsupportedEncodingException;
 +import java.lang.reflect.InvocationTargetException;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
@@@ -151,7 -150,7 +151,7 @@@ public class JSONStrategy extends Intro
          Class<?> resultClass = null;
          Object resultObject = this.getValue(name);
          if (resultObject instanceof JSONArray) {
-             resultClass = ((List) resultObject).get(0).getClass();
+             resultClass = ((List<?>) resultObject).get(0).getClass();
          }
  
          return resultClass;
      @Override
      public Object newInstanceOfProperty(String name) {
          try {
 -            return this.getClass(name).newInstance();
 -        } catch (InstantiationException | IllegalAccessException e) {
 +            return this.getClass(name).getDeclaredConstructor().newInstance();
 +        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
 +                | NoSuchMethodException | SecurityException e) {
              return null;
          }
      }
      @Override
      public Object newInstanceOfNestedProperty(String name) {
          try {
 -            return this.getGenericTypeClass(name).newInstance();
 -        } catch (InstantiationException | IllegalAccessException e) {
 +            return this.getGenericTypeClass(name).getDeclaredConstructor().newInstance();
 +        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
 +                | NoSuchMethodException | SecurityException e) {
              return null;
          }
      }
@@@ -293,7 -293,7 +293,7 @@@ public abstract class GraphTraversalBui
              if (val != null) {
                  // this is because the index is registered as an Integer
                  if (val.getClass().equals(Long.class)) {
 -                    this.vertexHas(key, new Integer(val.toString()));
 +                    this.vertexHas(key, Integer.valueOf(val.toString()));
                  } else {
                      this.vertexHas(key, val);
                  }
                      }
                      // this is because the index is registered as an Integer
                      if (val.getClass().equals(Long.class)) {
 -                        this.vertexHas(prop, new Integer(val.toString()));
 +                        this.vertexHas(prop, Integer.valueOf(val.toString()));
                      } else {
                          this.vertexHas(prop, val);
                      }
  
      protected void executeQuery() {
  
-         Admin admin;
+         Admin<Vertex, Vertex> admin;
          if (start != null) {
              this.completeTraversal = traversal.asAdmin();
          } else {
@@@ -575,7 -575,7 +575,7 @@@ public class DBSerializer 
                      if (value != null) {
                          if (!value.equals(oldValue)) {
                              if (propertyType.toLowerCase().contains(".long")) {
 -                                v.property(dbProperty, new Integer(((Long) value).toString()));
 +                                v.property(dbProperty, Integer.valueOf(((Long) value).toString()));
                              } else {
                                  v.property(dbProperty, value);
                              }
              throws IllegalArgumentException, SecurityException, UnsupportedEncodingException, AAIException {
  
          HashMap<String, Introspector> relatedVertices = new HashMap<>();
-         VertexProperty aaiUriProperty = v.property(AAIProperties.AAI_URI);
+         VertexProperty<Object> aaiUriProperty = v.property(AAIProperties.AAI_URI);
  
          if (!aaiUriProperty.isPresent()) {
              if (LOGGER.isDebugEnabled()) {
              throw new AAIException("AAI_6136",
                      "query object mismatch: this object cannot hold multiple items." + obj.getDbName());
          } else if (obj.isContainer()) {
-             final List getList;
+             final List<Object> getList;
              String listProperty = null;
              for (String property : obj.getProperties()) {
                  if (obj.isListType(property) && obj.isComplexGenericType(property)) {
              throws UnsupportedEncodingException, AAIException {
  
          List<Object> relationshipObjList = obj.getValue(RELATIONSHIP);
-         VertexProperty nodeTypeProperty = v.property(AAIProperties.NODE_TYPE);
+         VertexProperty<Object> nodeTypeProperty = v.property(AAIProperties.NODE_TYPE);
  
          if (!nodeTypeProperty.isPresent()) {
              LOGGER.warn("Not processing the vertex {} because its missing required property aai-node-type", v.id());
      private Object processEdgeRelationship(Introspector relationshipObj, Vertex cousin, String cleanUp,
              String edgeLabel, boolean isSkipRelatedTo) throws UnsupportedEncodingException, AAIUnknownObjectException {
  
-         VertexProperty aaiUriProperty = cousin.property("aai-uri");
+         VertexProperty<Object> aaiUriProperty = cousin.property("aai-uri");
  
          if (!aaiUriProperty.isPresent()) {
              return null;
              return null;
          }
  
-         VertexProperty cousinVertexNodeType = cousin.property(AAIProperties.NODE_TYPE);
+         VertexProperty<Object> cousinVertexNodeType = cousin.property(AAIProperties.NODE_TYPE);
  
          if (cousinVertexNodeType.isPresent()) {
              String cousinType = cousinVertexNodeType.value().toString();
@@@ -56,6 -56,7 +56,6 @@@ import org.slf4j.LoggerFactory
  
  public class Aggregate extends MultiFormatMapper {
      private static final Logger LOGGER = LoggerFactory.getLogger(LifecycleFormat.class);
 -    protected JsonParser parser = new JsonParser();
      protected final DBSerializer serializer;
      protected final Loader loader;
      protected final UrlBuilder urlBuilder;
              }
  
              final String json = obj.marshal(false);
 -            return Optional.of(parser.parse(json).getAsJsonObject());
 +            return Optional.of(JsonParser.parseString(json).getAsJsonObject());
          } catch (AAIUnknownObjectException e) {
              return Optional.empty();
          }
          return Optional.of(json);
      }
  
-     private Optional<JsonArray> processInput(Object input, Map properties) throws AAIFormatVertexException {
+     private Optional<JsonArray> processInput(Object input, Map<String, List<String>> properties)
+             throws AAIFormatVertexException {
          JsonArray json = new JsonArray();
          for (Object l : (ArrayList) input) {
              if (l instanceof ArrayList) {
@@@ -50,6 -50,7 +50,6 @@@ public class GraphSON implements Format
      private final GraphSONMapper mapper =
              GraphSONMapper.build().addRegistry(JanusGraphIoRegistry.getInstance()).create();
      private final GraphSONWriter writer = GraphSONWriter.build().mapper(mapper).create();
 -    protected JsonParser parser = new JsonParser();
  
      @Override
      public Optional<JsonObject> formatObject(Object v) {
@@@ -63,7 -64,7 +63,7 @@@
              logger.debug("GraphSON writeVertex error : {}", e.getMessage());
          }
  
 -        JsonObject jsonObject = parser.parse(result).getAsJsonObject();
 +        JsonObject jsonObject = JsonParser.parseString(result).getAsJsonObject();
  
          if (jsonObject != null) {
  
       */
      private void removePrivateEdges(JsonObject jsonObject, JsonObject edges, String edgeDirection) {
  
-         Iterator it = edges.entrySet().iterator();
+         Iterator<Map.Entry<String, JsonElement>> it = edges.entrySet().iterator();
          while (it.hasNext()) {
              Map.Entry<String, JsonElement> outEntry = (Map.Entry<String, JsonElement>) it.next();
              JsonArray edgePropertiesArray = outEntry.getValue().getAsJsonArray();
@@@ -23,6 -23,7 +23,6 @@@ package org.onap.aai.serialization.quer
  import com.google.gson.Gson;
  import com.google.gson.JsonArray;
  import com.google.gson.JsonObject;
 -import com.google.gson.JsonParser;
  
  import java.util.Iterator;
  import java.util.List;
@@@ -64,6 -65,7 +64,6 @@@ public abstract class HistoryFormat ext
      protected static final String RELATED_TO = "related-to";
      protected static final String NODE_ACTIONS = "node-actions";
  
 -    protected JsonParser parser = new JsonParser();
      protected final DBSerializer serializer;
      protected final Loader loader;
      protected final UrlBuilder urlBuilder;
  
      protected JsonObject createMetaPropertiesObject(VertexProperty<Object> prop) {
          JsonObject json = new JsonObject();
-         Iterator iter = prop.properties();
+         Iterator<Property<Object>> iter = prop.properties();
  
          while (iter.hasNext()) {
-             Property<Object> metaProp = (Property) iter.next();
+             Property<Object> metaProp = iter.next();
              mapPropertyValues(json, metaProp.key(), metaProp.value());
          }
  
@@@ -22,7 -22,6 +22,7 @@@ package org.onap.aai.serialization.quer
  
  import com.google.gson.JsonArray;
  import com.google.gson.JsonObject;
 +import com.google.gson.JsonParser;
  
  import java.io.UnsupportedEncodingException;
  import java.util.ArrayList;
@@@ -68,7 -67,7 +68,7 @@@ public class SimpleFormat extends RawFo
              }
  
              final String json = obj.marshal(false);
 -            return Optional.of(parser.parse(json).getAsJsonObject());
 +            return Optional.of(JsonParser.parseString(json).getAsJsonObject());
          } catch (AAIUnknownObjectException e) {
              return Optional.empty();
          }
@@@ -78,7 -77,7 +78,7 @@@
      @Override
      protected void addEdge(Edge e, Vertex v, JsonArray array) throws AAIFormatVertexException {
  
-         Property property = e.property("private");
+         Property<Object> property = e.property("private");
  
          if (property.isPresent()) {
              if ("true".equals(e.property("private").value().toString())) {
@@@ -52,6 -52,7 +52,6 @@@ import org.onap.aai.serialization.query
  
  public class TreeFormat extends MultiFormatMapper {
      private static final EELFLogger TREE_FORMAT_LOGGER = EELFManager.getInstance().getLogger(TreeFormat.class);
 -    protected JsonParser parser = new JsonParser();
      protected final DBSerializer serializer;
      protected final Loader loader;
      protected final UrlBuilder urlBuilder;
  
              // DSL Query
              if (o instanceof BulkSet) {
-                 BulkSet bs = (BulkSet) o;
-                 for (Object o1 : bs) {
-                     Optional<JsonObject> obj = this.getJsonFromVertex((Vertex) o1);
+                 BulkSet<Vertex> bs = (BulkSet<Vertex>) o;
+                 for (Vertex o1 : bs) {
+                     Optional<JsonObject> obj = this.getJsonFromVertex(o1);
                      if (obj.isPresent()) {
                          jsonObject = obj.get();
                          for (Map.Entry<String, JsonElement> mapEntry : jsonObject.entrySet()) {
  
              final String json = obj.marshal(false);
  
 -            return Optional.of(getParser().parse(json).getAsJsonObject());
 +            return Optional.of(JsonParser.parseString(json).getAsJsonObject());
          } catch (AAIUnknownObjectException e) {
              return Optional.empty();
          }
          return serializer;
      }
  
 -    private JsonParser getParser() {
 -        return parser;
 -    }
 -
      @Override
      protected Optional<JsonObject> getJsonFromVertex(Vertex input, Map<String, List<String>> properties)
              throws AAIFormatVertexException {
@@@ -27,7 -27,6 +27,7 @@@ import com.sun.jersey.api.client.Client
  import com.sun.jersey.api.client.ClientResponse;
  
  import java.io.IOException;
 +import java.lang.reflect.InvocationTargetException;
  import java.security.KeyManagementException;
  import java.security.KeyStoreException;
  import java.security.NoSuchAlgorithmException;
@@@ -257,7 -256,7 +257,7 @@@ public class RestController implements 
       * @return the list
       * @throws Exception the exception
       */
-     private <T> List<T> mapJsonToObjectList(T typeDef, String json, Class clazz) throws Exception {
+     private <T> List<T> mapJsonToObjectList(T typeDef, String json, Class<?> clazz) throws Exception {
          List<T> list;
          ObjectMapper mapper = new ObjectMapper();
          System.out.println(json);
       * @return single instance of RestController
       * @throws IllegalAccessException the illegal access exception
       * @throws InstantiationException the instantiation exception
 +     * @throws SecurityException
 +     * @throws NoSuchMethodException
 +     * @throws InvocationTargetException
 +     * @throws IllegalArgumentException
       */
 -    public <T> T getInstance(Class<T> clazz) throws IllegalAccessException, InstantiationException {
 -        return clazz.newInstance();
 +    public <T> T getInstance(Class<T> clazz) throws IllegalAccessException, InstantiationException,
 +            IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
 +        return clazz.getDeclaredConstructor().newInstance();
      }
  
      /**
@@@ -23,9 -23,9 +23,9 @@@ package org.onap.aai.serialization.quer
  import static org.junit.Assert.assertFalse;
  import static org.junit.Assert.assertNotNull;
  import static org.junit.Assert.assertTrue;
 +import static org.mockito.ArgumentMatchers.any;
  import static org.mockito.ArgumentMatchers.anyBoolean;
  import static org.mockito.ArgumentMatchers.anyInt;
 -import static org.mockito.ArgumentMatchers.anyObject;
  import static org.mockito.ArgumentMatchers.anyString;
  import static org.mockito.Mockito.mock;
  import static org.mockito.Mockito.spy;
@@@ -142,7 -142,7 +142,7 @@@ public class SimpleFormatTest extends A
  
          FormatFactory ff =
                  new FormatFactory(loader, serializer, schemaVersions, basePath, "https://localhost:8447/aai/");
-         MultivaluedMap mvm = new MultivaluedHashMap();
+         MultivaluedMap<String, String> mvm = new MultivaluedHashMap<>();
          mvm.add("depth", "0");
          Formatter formatter = ff.get(Format.simple, mvm);
  
  
          simpleFormat = new RawFormat.Builder(loader, serializer, urlBuilder).nodesOnly(true).depth(0).build();
  
 -        when(serializer.dbToObject(anyObject(), anyObject(), anyInt(), anyBoolean(), anyString()))
 +        when(serializer.dbToObject(any(), any(), anyInt(), anyBoolean(), anyString()))
                  .thenThrow(new AAIException("Test Exception"));
  
          simpleFormat.createPropertiesObject(vfModule);
@@@ -179,16 -179,19 +179,16 @@@ public class MockRestClient extends Res
      public JsonObject getPayload(String filename) throws IOException {
          InputStream inputStream = getClass().getClassLoader().getResourceAsStream(filename);
  
 -        // InputStream inputStream = new FileInputStream(filename);
 -
          String result = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
          String message = String.format("Unable to find the %s in src/test/resources", filename);
          assertNotNull(message, inputStream);
  
 -        JsonParser parser = new JsonParser();
 -        JsonObject payload = parser.parse(result).getAsJsonObject();
 +        JsonObject payload = JsonParser.parseString(result).getAsJsonObject();
          return payload;
      }
  
      @Override
-     public ResponseEntity execute(String uri, HttpMethod method, Map<String, String> headers, String body) {
+     public ResponseEntity<String> execute(String uri, HttpMethod method, Map<String, String> headers, String body) {
  
          String url = "https://localhost:8447/aai/v14/" + uri;
  
          headersMap.add("X-FromAppId", "JUNIT");
          headersMap.add("X-TransactionId", "JUNIT");
  
-         HttpEntity httpEntity = new HttpEntity(headers);
+         HttpEntity<String> httpEntity = new HttpEntity(headers);
  
-         ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class);
+         ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class);
  
          // mockRestServiceServer.verify();
          return responseEntity;
      }
  
      @Override
-     public ResponseEntity executeResource(String uri, HttpMethod method, Map<String, String> headers, String body) {
+     public ResponseEntity<Resource> executeResource(String uri, HttpMethod method, Map<String, String> headers,
+             String body) {
  
          String url = "https://localhost:8447/aai/v14/" + uri;
  
          headersMap.add("X-FromAppId", "JUNIT");
          headersMap.add("X-TransactionId", "JUNIT");
  
-         HttpEntity httpEntity = new HttpEntity(headers);
+         HttpEntity<String> httpEntity = new HttpEntity(headers);
  
-         ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, Resource.class);
+         ResponseEntity<Resource> responseEntity =
+                 restTemplate.exchange(url, HttpMethod.GET, httpEntity, Resource.class);
  
          // mockRestServiceServer.verify();
          return responseEntity;