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;
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;
}
}
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 {
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();
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) {
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) {
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();
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;
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());
}
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
}
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();
}
@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())) {
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 {
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;
* @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();
}
/**
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;
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);
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;