summaryrefslogtreecommitdiffstats
path: root/aai-core/src
diff options
context:
space:
mode:
authorLiard Samuel <samuel.liard@orange.com>2021-06-30 19:06:16 +0200
committerSamuel Liard <samuel.liard@gmail.com>2021-07-02 09:30:45 +0200
commita2f7d11ca0bd58ec6c252111ddd3d5dfac0e4c70 (patch)
tree2c12ab019a9456d928da715198b4bb91b3678b36 /aai-core/src
parentfe71e2611b2bfecc65ef121631360b4c32ca129e (diff)
Fix all blocker sonar issues and some checkstyle
Issue-ID: AAI-3362 Signed-off-by: sliard <samuel.liard@gmail.com> Change-Id: I365be3e8afe75b54f5a65deadb054df73857274e
Diffstat (limited to 'aai-core/src')
-rw-r--r--aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java8
-rw-r--r--aai-core/src/main/java/org/onap/aai/introspection/Introspector.java22
-rw-r--r--aai-core/src/main/java/org/onap/aai/introspection/JSONStrategy.java48
-rw-r--r--aai-core/src/main/java/org/onap/aai/introspection/PropertyPredicates.java7
-rw-r--r--aai-core/src/main/java/org/onap/aai/introspection/sideeffect/SideEffect.java22
-rw-r--r--aai-core/src/main/java/org/onap/aai/prevalidation/ValidationService.java26
-rw-r--r--aai-core/src/main/java/org/onap/aai/query/builder/HistoryTraversalURIOptimizedQuery.java23
-rw-r--r--aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java48
-rw-r--r--aai-core/src/main/java/org/onap/aai/rest/ueb/UEBNotification.java19
-rw-r--r--aai-core/src/main/java/org/onap/aai/restcore/RESTAPI.java43
-rw-r--r--aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java220
-rw-r--r--aai-core/src/main/java/org/onap/aai/serialization/queryformats/GraphSON.java17
-rw-r--r--aai-core/src/main/java/org/onap/aai/serialization/queryformats/MultiFormatMapper.java9
-rw-r--r--aai-core/src/main/java/org/onap/aai/serialization/queryformats/RawFormat.java15
-rw-r--r--aai-core/src/main/java/org/onap/aai/serialization/queryformats/Resource.java24
-rw-r--r--aai-core/src/main/java/org/onap/aai/serialization/queryformats/ResourceWithSoT.java6
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/AAIUtils.java2
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/HttpsAuthClient.java57
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/delta/DeltaEvents.java2
-rw-r--r--aai-core/src/test/java/org/onap/aai/exceptions/AAIExceptionTest.java5
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/MoxyEngineTest.java23
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/generator/CreateExampleTest.java13
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/sideeffect/OwnerCheckTest.java9
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/tools/IntrospectorValidatorTest.java11
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/PserverDuplicateTest.java13
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java2
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceWithSoTTest.java8
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/QueryParamInjectorTest.java3
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/AAIConfigTest.java6
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java6
30 files changed, 392 insertions, 325 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java b/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java
index eb0d1658..3d675efe 100644
--- a/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java
+++ b/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java
@@ -47,7 +47,9 @@ public class AAIDmaapEventJMSProducer implements MessageProducer {
if (jmsTemplate != null) {
jmsTemplate.convertAndSend(finalJson.toString());
CachingConnectionFactory ccf = (CachingConnectionFactory) this.jmsTemplate.getConnectionFactory();
- ccf.destroy();
+ if (ccf != null) {
+ ccf.destroy();
+ }
}
}
@@ -55,7 +57,9 @@ public class AAIDmaapEventJMSProducer implements MessageProducer {
if (jmsTemplate != null) {
jmsTemplate.convertAndSend(msg);
CachingConnectionFactory ccf = (CachingConnectionFactory) this.jmsTemplate.getConnectionFactory();
- ccf.destroy();
+ if (ccf != null) {
+ ccf.destroy();
+ }
}
}
}
diff --git a/aai-core/src/main/java/org/onap/aai/introspection/Introspector.java b/aai-core/src/main/java/org/onap/aai/introspection/Introspector.java
index 53f2a2cd..1ef54c6b 100644
--- a/aai-core/src/main/java/org/onap/aai/introspection/Introspector.java
+++ b/aai-core/src/main/java/org/onap/aai/introspection/Introspector.java
@@ -20,9 +20,18 @@
package org.onap.aai.introspection;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.CaseFormat;
+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.lang.ClassUtils;
import org.eclipse.persistence.exceptions.DynamicException;
import org.onap.aai.config.SpringContextAware;
@@ -36,11 +45,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 {
@@ -177,7 +183,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());
diff --git a/aai-core/src/main/java/org/onap/aai/introspection/JSONStrategy.java b/aai-core/src/main/java/org/onap/aai/introspection/JSONStrategy.java
index 55580dc3..484e5612 100644
--- a/aai-core/src/main/java/org/onap/aai/introspection/JSONStrategy.java
+++ b/aai-core/src/main/java/org/onap/aai/introspection/JSONStrategy.java
@@ -25,7 +25,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
-
+import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.onap.aai.schema.enums.ObjectMetadata;
import org.onap.aai.schema.enums.PropertyMetadata;
@@ -146,10 +146,9 @@ public class JSONStrategy extends Introspector {
@Override
public Class<?> getGenericTypeClass(String name) {
- Object resultObject = null;
Class<?> resultClass = null;
- resultObject = this.getValue(name);
- if (resultObject.getClass().getName().equals("org.json.simple.JSONArray")) {
+ Object resultObject = this.getValue(name);
+ if (resultObject instanceof JSONArray) {
resultClass = ((List) resultObject).get(0).getClass();
}
@@ -177,48 +176,25 @@ public class JSONStrategy extends Introspector {
@Override
public boolean isComplexType(String name) {
String result = this.getType(name);
-
- if (result.contains("JSONObject")) {
- return true;
- } else {
- return false;
- }
-
+ return result.contains("JSONObject");
}
@Override
public boolean isComplexGenericType(String name) {
String result = this.getGenericType(name);
-
- if (result.contains("JSONObject")) {
- return true;
- } else {
- return false;
- }
-
+ return result.contains("JSONObject");
}
@Override
public boolean isListType(String name) {
String result = this.getType(name);
-
- if (result.contains("java.util.List")) {
- return true;
- } else {
- return false;
- }
-
+ return result.contains("java.util.List");
}
@Override
public boolean isContainer() {
Set<String> props = this.getProperties();
- boolean result = false;
- if (props.size() == 1 && this.isListType(props.iterator().next())) {
- result = true;
- }
-
- return result;
+ return props.size() == 1 && this.isListType(props.iterator().next());
}
@Override
@@ -264,19 +240,13 @@ public class JSONStrategy extends Introspector {
return null;
}
- @Override
- public Object clone() {
- // TODO
- return null;
- }
-
/*
* @Override
* public String findEdgeName(String parent, String child) {
- *
+ *
* // Always has for now
* return "has";
- *
+ *
* }
*/
diff --git a/aai-core/src/main/java/org/onap/aai/introspection/PropertyPredicates.java b/aai-core/src/main/java/org/onap/aai/introspection/PropertyPredicates.java
index 91e46d20..1aca431f 100644
--- a/aai-core/src/main/java/org/onap/aai/introspection/PropertyPredicates.java
+++ b/aai-core/src/main/java/org/onap/aai/introspection/PropertyPredicates.java
@@ -22,7 +22,6 @@ package org.onap.aai.introspection;
import java.util.Map;
import java.util.Set;
-
import org.onap.aai.schema.enums.PropertyMetadata;
public final class PropertyPredicates {
@@ -38,9 +37,6 @@ public final class PropertyPredicates {
return !(Visibility.internal.equals(Visibility.valueOf(map.get(PropertyMetadata.VISIBILITY)))
|| Visibility.deployment.equals(Visibility.valueOf(map.get(PropertyMetadata.VISIBILITY))));
}
- if (map.containsKey("dataLocation")) {
- return false;
- }
return true;
};
}
@@ -61,9 +57,6 @@ public final class PropertyPredicates {
if (map.containsKey(PropertyMetadata.VISIBILITY)) {
return !Visibility.internal.equals(Visibility.valueOf(map.get(PropertyMetadata.VISIBILITY)));
}
- if (map.containsKey("dataLocation")) {
- return false;
- }
return true;
};
}
diff --git a/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/SideEffect.java b/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/SideEffect.java
index a71ffa4e..9ca396ad 100644
--- a/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/SideEffect.java
+++ b/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/SideEffect.java
@@ -20,28 +20,30 @@
package org.onap.aai.introspection.sideeffect;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
-import java.util.*;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.onap.aai.config.SpringContextAware;
-import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException;
import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
import org.onap.aai.exceptions.AAIException;
-import org.onap.aai.introspection.*;
+import org.onap.aai.introspection.Introspector;
+import org.onap.aai.introspection.Loader;
+import org.onap.aai.introspection.LoaderUtil;
import org.onap.aai.introspection.sideeffect.exceptions.AAIMissingRequiredPropertyException;
import org.onap.aai.schema.enums.PropertyMetadata;
import org.onap.aai.serialization.db.DBSerializer;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
-import org.onap.aai.setup.SchemaVersions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public abstract class SideEffect {
@@ -72,7 +74,7 @@ public abstract class SideEffect {
try {
this.processURI(completeUri, entry);
} catch (EdgeRuleNotFoundException | AmbiguousRuleChoiceException e) {
- logger.warn("Unable to execute the side effect {} due to ", e, this.getClass().getName());
+ logger.warn("Unable to execute the side effect {} due to ", this.getClass().getName(), e);
}
}
}
diff --git a/aai-core/src/main/java/org/onap/aai/prevalidation/ValidationService.java b/aai-core/src/main/java/org/onap/aai/prevalidation/ValidationService.java
index 801561de..29b31081 100644
--- a/aai-core/src/main/java/org/onap/aai/prevalidation/ValidationService.java
+++ b/aai-core/src/main/java/org/onap/aai/prevalidation/ValidationService.java
@@ -23,6 +23,18 @@ package org.onap.aai.prevalidation;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
+import java.net.ConnectException;
+import java.net.SocketTimeoutException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import javax.annotation.PostConstruct;
import org.apache.http.conn.ConnectTimeoutException;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Introspector;
@@ -38,13 +50,6 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
-import javax.annotation.PostConstruct;
-import java.net.ConnectException;
-import java.net.SocketTimeoutException;
-import java.util.*;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
/**
* <b>ValidationService</b> routes all the writes to the database
* excluding deletes for now to the validation service to verify
@@ -234,12 +239,13 @@ public class ValidationService {
body
);
+ Object responseBody = responseEntity.getBody();
if(isSuccess(responseEntity)){
LOGGER.debug("Validation Service returned following response status code {} and body {}", responseEntity.getStatusCodeValue(), responseEntity.getBody());
- } else {
+ } else if (responseBody != null) {
Validation validation = null;
try {
- validation = gson.fromJson(responseEntity.getBody().toString(), Validation.class);
+ validation = gson.fromJson(responseBody.toString(), Validation.class);
} catch(JsonSyntaxException jsonException){
LOGGER.warn("Unable to convert the response body {}", jsonException.getMessage());
}
@@ -253,6 +259,8 @@ public class ValidationService {
} else {
violations.addAll(extractViolations(validation));
}
+ } else {
+ LOGGER.warn("Unable to convert the response body null");
}
} catch(Exception e){
// If the exception cause is client side timeout
diff --git a/aai-core/src/main/java/org/onap/aai/query/builder/HistoryTraversalURIOptimizedQuery.java b/aai-core/src/main/java/org/onap/aai/query/builder/HistoryTraversalURIOptimizedQuery.java
index aeb5cd19..119f8522 100644
--- a/aai-core/src/main/java/org/onap/aai/query/builder/HistoryTraversalURIOptimizedQuery.java
+++ b/aai-core/src/main/java/org/onap/aai/query/builder/HistoryTraversalURIOptimizedQuery.java
@@ -20,29 +20,16 @@
package org.onap.aai.query.builder;
-import org.apache.tinkerpop.gremlin.process.traversal.P;
-import org.apache.tinkerpop.gremlin.process.traversal.Step;
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import java.util.Map;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
-import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.onap.aai.db.props.AAIProperties;
-import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.Loader;
-import org.onap.aai.schema.enums.ObjectMetadata;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
public class HistoryTraversalURIOptimizedQuery<E> extends TraversalURIOptimizedQuery {
- protected Map<Integer, String> stepToAaiUri = new HashMap<>();
-
public HistoryTraversalURIOptimizedQuery(Loader loader, GraphTraversalSource source) {
super(loader, source);
}
@@ -79,14 +66,14 @@ public class HistoryTraversalURIOptimizedQuery<E> extends TraversalURIOptimizedQ
touchHistoryProperties(key);
}
- private void touchHistoryProperties(String key){
- if(key != null && !key.isEmpty() && !key.equals(AAIProperties.NODE_TYPE)) {
+ private void touchHistoryProperties(String key) {
+ if (key != null && !key.isEmpty() && !key.equals(AAIProperties.NODE_TYPE)) {
traversal.where(__.properties(key));
}
}
- private void touchHistoryProperties(String key, Object value){
- if(key != null && !key.isEmpty() && !key.equals(AAIProperties.NODE_TYPE)) {
+ private void touchHistoryProperties(String key, Object value) {
+ if (key != null && !key.isEmpty() && !key.equals(AAIProperties.NODE_TYPE)) {
traversal.where(__.properties(key).hasValue(value));
}
}
diff --git a/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java b/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java
index 7f3340b2..554ecb36 100644
--- a/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java
+++ b/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java
@@ -145,7 +145,7 @@ public class HttpEntry {
getDbEngine().startTransaction();
this.notification = new UEBNotification(loader, loaderFactory, schemaVersions);
- if("true".equals(AAIConfig.get("aai.notification.depth.all.enabled", "true"))){
+ if ("true".equals(AAIConfig.get("aai.notification.depth.all.enabled", "true"))) {
this.notificationDepth = AAIProperties.MAXIMUM_DEPTH;
} else {
this.notificationDepth = AAIProperties.MINIMUM_DEPTH;
@@ -160,7 +160,7 @@ public class HttpEntry {
getDbEngine().startTransaction();
this.notification = new UEBNotification(loader, loaderFactory, schemaVersions);
- if("true".equals(AAIConfig.get("aai.notification.depth.all.enabled", "true"))){
+ if ("true".equals(AAIConfig.get("aai.notification.depth.all.enabled", "true"))) {
this.notificationDepth = AAIProperties.MAXIMUM_DEPTH;
} else {
this.notificationDepth = AAIProperties.MINIMUM_DEPTH;
@@ -177,7 +177,7 @@ public class HttpEntry {
this.notification = notification;
- if("true".equals(AAIConfig.get("aai.notification.depth.all.enabled", "true"))){
+ if ("true".equals(AAIConfig.get("aai.notification.depth.all.enabled", "true"))) {
this.notificationDepth = AAIProperties.MAXIMUM_DEPTH;
} else {
this.notificationDepth = AAIProperties.MINIMUM_DEPTH;
@@ -504,11 +504,12 @@ public class HttpEntry {
if (obj != null) {
status = Status.OK;
MarshallerProperties properties;
- if (!request.getMarshallerProperties().isPresent()) {
- properties = new MarshallerProperties.Builder(
- org.onap.aai.restcore.MediaType.getEnum(outputMediaType)).build();
+ Optional<MarshallerProperties> marshallerPropOpt = request.getMarshallerProperties();
+ if (marshallerPropOpt.isPresent()) {
+ properties = marshallerPropOpt.get();
} else {
- properties = request.getMarshallerProperties().get();
+ properties = new MarshallerProperties.Builder(
+ org.onap.aai.restcore.MediaType.getEnum(outputMediaType)).build();
}
result = obj.marshal(properties);
}
@@ -519,11 +520,11 @@ public class HttpEntry {
result = formatter.output(vertices.stream().map(vertex -> (Object) vertex)
.collect(Collectors.toList())).toString();
- if(outputMediaType == null){
+ if (outputMediaType == null) {
outputMediaType = MediaType.APPLICATION_JSON;
}
- if(MediaType.APPLICATION_XML_TYPE.isCompatible(MediaType.valueOf(outputMediaType))){
+ if (MediaType.APPLICATION_XML_TYPE.isCompatible(MediaType.valueOf(outputMediaType))) {
result = xmlFormatTransformer.transform(result);
}
status = Status.OK;
@@ -557,11 +558,11 @@ public class HttpEntry {
result = formatter.output(vertices.stream().map(vertex -> (Object) vertex)
.collect(Collectors.toList())).toString();
- if(outputMediaType == null){
+ if (outputMediaType == null) {
outputMediaType = MediaType.APPLICATION_JSON;
}
- if(MediaType.APPLICATION_XML_TYPE.isCompatible(MediaType.valueOf(outputMediaType))){
+ if (MediaType.APPLICATION_XML_TYPE.isCompatible(MediaType.valueOf(outputMediaType))) {
result = xmlFormatTransformer.transform(result);
}
status = Status.OK;
@@ -581,7 +582,7 @@ public class HttpEntry {
if (notificationDepth == AAIProperties.MINIMUM_DEPTH) {
Map<String, Pair<Introspector, LinkedHashMap<String,Introspector>>> allImpliedDeleteObjs = serializer.getImpliedDeleteUriObjectPair();
- for(Map.Entry<String, Pair<Introspector, LinkedHashMap<String,Introspector>>> entry: allImpliedDeleteObjs.entrySet()){
+ for (Map.Entry<String, Pair<Introspector, LinkedHashMap<String,Introspector>>> entry: allImpliedDeleteObjs.entrySet()) {
// The format is purposefully %s/%s%s due to the fact
// that every aai-uri will have a slash at the beginning
// If that assumption isn't true, then its best to change this code
@@ -772,9 +773,12 @@ public class HttpEntry {
/**
* Generate notification events for the resulting db requests.
*/
- private void generateEvents(String sourceOfTruth, DBSerializer serializer, String transactionId, QueryEngine queryEngine, Set<Vertex> mainVertexesToNotifyOn) throws AAIException {
+ private void generateEvents(String sourceOfTruth, DBSerializer serializer, String transactionId,
+ QueryEngine queryEngine, Set<Vertex> mainVertexesToNotifyOn)
+ throws AAIException {
if (notificationDepth == AAIProperties.MINIMUM_DEPTH) {
- serializer.getUpdatedVertexes().entrySet().stream().filter(Map.Entry::getValue).map(Map.Entry::getKey).forEach(mainVertexesToNotifyOn::add);
+ serializer.getUpdatedVertexes().entrySet().stream().filter(Map.Entry::getValue)
+ .map(Map.Entry::getKey).forEach(mainVertexesToNotifyOn::add);
}
Set<Vertex> edgeVertexes = serializer.touchStandardVertexPropertiesForEdges().stream()
.filter(v -> !mainVertexesToNotifyOn.contains(v)).collect(Collectors.toSet());
@@ -789,13 +793,15 @@ public class HttpEntry {
// Since @Autowired required is set to false, we need to do a null check
// for the existence of the validationService since its only enabled if profile is enabled
- if(validationService != null){
+ if (validationService != null){
validationService.validate(notification.getEvents());
}
notification.triggerEvents();
if (isDeltaEventsEnabled) {
try {
- DeltaEvents deltaEvents = new DeltaEvents(transactionId, sourceOfTruth, version.toString(), serializer.getObjectDeltas());
+ DeltaEvents deltaEvents =
+ new DeltaEvents(transactionId, sourceOfTruth, version.toString(),
+ serializer.getObjectDeltas());
deltaEvents.triggerEvents();
} catch (Exception e) {
LOGGER.error("Error sending Delta Events", e);
@@ -808,7 +814,7 @@ public class HttpEntry {
*/
private void createNotificationEvents(Set<Vertex> vertexesToNotifyOn, String sourceOfTruth, DBSerializer serializer,
String transactionId, QueryEngine queryEngine, int eventDepth) throws AAIException, UnsupportedEncodingException {
- for(Vertex vertex : vertexesToNotifyOn){
+ for (Vertex vertex : vertexesToNotifyOn) {
if (canGenerateEvent(vertex)) {
boolean isCurVertexNew = vertex.value(AAIProperties.CREATED_TS).equals(vertex.value(AAIProperties.LAST_MOD_TS));
Status curObjStatus = (isCurVertexNew) ? Status.CREATED : Status.OK;
@@ -820,7 +826,8 @@ public class HttpEntry {
if (!curObj.isTopLevel()) {
curRelatedObjs = serializer.getRelatedObjects(queryEngine, vertex, curObj, this.loader);
}
- notification.createNotificationEvent(transactionId, sourceOfTruth, curObjStatus, URI.create(uri), curObj, curRelatedObjs, basePath);
+ notification.createNotificationEvent(transactionId, sourceOfTruth, curObjStatus,
+ URI.create(uri), curObj, curRelatedObjs, basePath);
}
}
}
@@ -833,10 +840,11 @@ public class HttpEntry {
private boolean canGenerateEvent(Vertex vertex) {
boolean canGenerate = true;
try {
- if(!vertex.property(AAIProperties.AAI_URI).isPresent()){
+ if (!vertex.property(AAIProperties.AAI_URI).isPresent()) {
LOGGER.debug("Encountered an vertex {} with missing aai-uri", vertex.id());
canGenerate = false;
- } else if(!vertex.property(AAIProperties.CREATED_TS).isPresent() || !vertex.property(AAIProperties.LAST_MOD_TS).isPresent()){
+ } else if (!vertex.property(AAIProperties.CREATED_TS).isPresent() ||
+ !vertex.property(AAIProperties.LAST_MOD_TS).isPresent()) {
LOGGER.debug("Encountered an vertex {} with missing timestamp", vertex.id());
canGenerate = false;
}
diff --git a/aai-core/src/main/java/org/onap/aai/rest/ueb/UEBNotification.java b/aai-core/src/main/java/org/onap/aai/rest/ueb/UEBNotification.java
index 28a644a9..d9516315 100644
--- a/aai-core/src/main/java/org/onap/aai/rest/ueb/UEBNotification.java
+++ b/aai-core/src/main/java/org/onap/aai/rest/ueb/UEBNotification.java
@@ -20,8 +20,14 @@
package org.onap.aai.rest.ueb;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import javax.ws.rs.core.Response.Status;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.Loader;
@@ -33,11 +39,8 @@ import org.onap.aai.logging.LogFormatTools;
import org.onap.aai.parsers.uri.URIToObject;
import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaVersions;
-
-import javax.ws.rs.core.Response.Status;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.util.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* The Class UEBNotification.
@@ -207,7 +210,7 @@ public class UEBNotification {
private String getUri(String uri, String basePath) {
if (uri == null || uri.isEmpty()) {
- return uri;
+ return "";
} else if (uri.charAt(0) != '/') {
uri = '/' + uri;
}
diff --git a/aai-core/src/main/java/org/onap/aai/restcore/RESTAPI.java b/aai-core/src/main/java/org/onap/aai/restcore/RESTAPI.java
index 2b1256ba..7c5d43c1 100644
--- a/aai-core/src/main/java/org/onap/aai/restcore/RESTAPI.java
+++ b/aai-core/src/main/java/org/onap/aai/restcore/RESTAPI.java
@@ -20,28 +20,37 @@
package org.onap.aai.restcore;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.Loader;
-import org.onap.aai.introspection.tools.*;
+import org.onap.aai.introspection.tools.CreateUUID;
+import org.onap.aai.introspection.tools.DefaultFields;
+import org.onap.aai.introspection.tools.InjectKeysFromURI;
+import org.onap.aai.introspection.tools.IntrospectorValidator;
+import org.onap.aai.introspection.tools.Issue;
+import org.onap.aai.introspection.tools.RemoveNonVisibleProperty;
import org.onap.aai.logging.ErrorLogHelper;
import org.onap.aai.util.AAIConfig;
import org.onap.aai.util.FormatDate;
-
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Base class for AAI REST API classes.
@@ -306,6 +315,10 @@ public class RESTAPI {
String.format("Timeout limit of %s seconds reached.", timeoutLimit / 1000));
response = consumerExceptionResponseGenerator(headers, info, method, ex);
handler.cancel(true);
+ } catch (InterruptedException e) {
+ AAIException ex = new AAIException("AAI_4000", e);
+ response = consumerExceptionResponseGenerator(headers, info, method, ex);
+ Thread.currentThread().interrupt();
} catch (Exception e) {
AAIException ex = new AAIException("AAI_4000", e);
response = consumerExceptionResponseGenerator(headers, info, method, ex);
diff --git a/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java b/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java
index 7ab49a13..4237252f 100644
--- a/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java
+++ b/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java
@@ -19,9 +19,32 @@
*/
package org.onap.aai.serialization.db;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.CaseFormat;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.ws.rs.core.UriBuilder;
import org.apache.commons.lang.StringUtils;
import org.apache.tinkerpop.gremlin.process.traversal.Path;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
@@ -45,9 +68,19 @@ import org.onap.aai.edges.enums.EdgeType;
import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException;
import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
import org.onap.aai.exceptions.AAIException;
-import org.onap.aai.introspection.*;
+import org.onap.aai.introspection.Introspector;
+import org.onap.aai.introspection.IntrospectorFactory;
+import org.onap.aai.introspection.Loader;
+import org.onap.aai.introspection.LoaderFactory;
+import org.onap.aai.introspection.ModelType;
+import org.onap.aai.introspection.PropertyPredicates;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
-import org.onap.aai.introspection.sideeffect.*;
+import org.onap.aai.introspection.sideeffect.DataCopy;
+import org.onap.aai.introspection.sideeffect.DataLinkReader;
+import org.onap.aai.introspection.sideeffect.DataLinkWriter;
+import org.onap.aai.introspection.sideeffect.OwnerCheck;
+import org.onap.aai.introspection.sideeffect.PrivateEdge;
+import org.onap.aai.introspection.sideeffect.SideEffectRunner;
import org.onap.aai.logging.ErrorLogHelper;
import org.onap.aai.logging.LogFormatTools;
import org.onap.aai.logging.StopWatch;
@@ -67,24 +100,16 @@ import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaVersions;
import org.onap.aai.util.AAIConfig;
import org.onap.aai.util.AAIConstants;
-import org.onap.aai.util.delta.*;
+import org.onap.aai.util.delta.DeltaAction;
+import org.onap.aai.util.delta.ObjectDelta;
+import org.onap.aai.util.delta.PropertyDelta;
+import org.onap.aai.util.delta.PropertyDeltaFactory;
+import org.onap.aai.util.delta.RelationshipDelta;
import org.onap.aai.workarounds.NamingExceptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
-import javax.ws.rs.core.UriBuilder;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.Array;
-import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.*;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
public class DBSerializer {
private static final Logger LOGGER = LoggerFactory.getLogger(DBSerializer.class);
@@ -295,7 +320,7 @@ public class DBSerializer {
return updatedVertexes;
}
- public Map<String, Pair<Introspector, LinkedHashMap<String, Introspector>>> getImpliedDeleteUriObjectPair(){
+ public Map<String, Pair<Introspector, LinkedHashMap<String, Introspector>>> getImpliedDeleteUriObjectPair() {
return impliedDeleteUriObjectPair;
}
@@ -336,10 +361,18 @@ public class DBSerializer {
getObjectDeltas().get(uri).setAction(objDeltaAction);
}
- addPropDelta(uri, AAIProperties.AAI_UUID, PropertyDeltaFactory.getDelta(DeltaAction.STATIC, v.property(AAIProperties.AAI_UUID).value()), objDeltaAction);
- addPropDelta(uri, AAIProperties.NODE_TYPE, PropertyDeltaFactory.getDelta(DeltaAction.STATIC, v.property(AAIProperties.NODE_TYPE).value()), objDeltaAction);
- addPropDelta(uri, AAIProperties.SOURCE_OF_TRUTH, PropertyDeltaFactory.getDelta(DeltaAction.STATIC, v.property(AAIProperties.SOURCE_OF_TRUTH).value()), objDeltaAction);
- addPropDelta(uri, AAIProperties.CREATED_TS, PropertyDeltaFactory.getDelta(DeltaAction.STATIC, v.property(AAIProperties.CREATED_TS).value()), objDeltaAction);
+ addPropDelta(uri, AAIProperties.AAI_UUID, PropertyDeltaFactory
+ .getDelta(DeltaAction.STATIC, v.property(AAIProperties.AAI_UUID).value()),
+ objDeltaAction);
+ addPropDelta(uri, AAIProperties.NODE_TYPE, PropertyDeltaFactory
+ .getDelta(DeltaAction.STATIC, v.property(AAIProperties.NODE_TYPE).value()),
+ objDeltaAction);
+ addPropDelta(uri, AAIProperties.SOURCE_OF_TRUTH, PropertyDeltaFactory
+ .getDelta(DeltaAction.STATIC, v.property(AAIProperties.SOURCE_OF_TRUTH).value()),
+ objDeltaAction);
+ addPropDelta(uri, AAIProperties.CREATED_TS, PropertyDeltaFactory
+ .getDelta(DeltaAction.STATIC, v.property(AAIProperties.CREATED_TS).value()),
+ objDeltaAction);
if (objDeltaAction.equals(DeltaAction.UPDATE)) {
addPropDelta(
@@ -367,7 +400,9 @@ public class DBSerializer {
}
}
- public Map<String, ObjectDelta> getObjectDeltas() {return objectDeltas;}
+ public Map<String, ObjectDelta> getObjectDeltas() {
+ return objectDeltas;
+ }
private void addPropDelta(String uri, String prop, PropertyDelta delta, DeltaAction objDeltaAction) {
ObjectDelta objectDelta = this.objectDeltas.getOrDefault(uri, new ObjectDelta(uri, objDeltaAction, this.sourceOfTruth, this.currentTimeMillis));
@@ -644,9 +679,9 @@ public class DBSerializer {
ImpliedDelete impliedDelete = new ImpliedDelete(engine, this);
List<Vertex> impliedDeleteVertices = impliedDelete.execute(v.id(), sourceOfTruth, obj.getName(), dependentVertexes);
- if(notificationDepth == AAIProperties.MINIMUM_DEPTH){
- for(Vertex curVertex : impliedDeleteVertices){
- if(!curVertex.property("aai-uri").isPresent()){
+ if (notificationDepth == AAIProperties.MINIMUM_DEPTH) {
+ for (Vertex curVertex : impliedDeleteVertices) {
+ if (!curVertex.property("aai-uri").isPresent()) {
LOGGER.debug("Encountered an vertex {} with missing aai-uri", curVertex.id());
continue;
}
@@ -655,11 +690,11 @@ public class DBSerializer {
LinkedHashMap<String, Introspector> curObjRelated = new LinkedHashMap<>();
- if(!curObj.isTopLevel()){
+ if (!curObj.isTopLevel()) {
curObjRelated.putAll(this.getRelatedObjects(engine.getQueryEngine(), curVertex, curObj, this.loader));
}
- if(!impliedDeleteUriObjectPair.containsKey(curAaiUri)){
+ if (!impliedDeleteUriObjectPair.containsKey(curAaiUri)) {
impliedDeleteUriObjectPair.put(curAaiUri, new Pair<>(curObj, curObjRelated));
}
}
@@ -916,7 +951,8 @@ public class DBSerializer {
if (rules.size() == 1) {
label = rules.get(0).getLabel();
} else {
- Optional<EdgeRule> defaultRule = rules.stream().filter(EdgeRule::isDefault).findFirst();
+ Optional<EdgeRule>
+ defaultRule = rules.stream().filter(EdgeRule::isDefault).findFirst();
if (defaultRule.isPresent()) {
label = defaultRule.get().getLabel();
} else {
@@ -1240,7 +1276,11 @@ public class DBSerializer {
for (Future<Object> future : futures) {
try {
getList.add(future.get());
- } catch (ExecutionException | InterruptedException e) {
+ } catch (InterruptedException e) {
+ dbTimeMsecs += StopWatch.stopIfStarted();
+ Thread.currentThread().interrupt();
+ throw new AAIException("AAI_4000", e);
+ } catch (ExecutionException e) {
dbTimeMsecs += StopWatch.stopIfStarted();
throw new AAIException("AAI_4000", e);
}
@@ -1388,7 +1428,7 @@ public class DBSerializer {
Object result =
dbToObject(argumentObject, childVertex, seen, depth, nodeOnly, cleanUp, isSkipRelatedTo);
- if (result != null) {
+ if (result != null && getList != null) {
getList.add(argumentObject.getUnderlyingObject());
}
@@ -1549,8 +1589,8 @@ public class DBSerializer {
.edgeType(EdgeType.COUSIN)
.version(obj.getVersion());
- for (Path path : paths){
- if(path.size() < 3){
+ for (Path path : paths) {
+ if (path.size() < 3) {
continue;
}
@@ -1561,7 +1601,7 @@ public class DBSerializer {
// path objects.get(1) returns edge related-to
// path objects.get(2) returns vertex otherV
Edge edge = path.get(1);
- Vertex otherV= path.get(2);
+ Vertex otherV = path.get(2);
// TODO: Come back and revisit this code
// Create a query based on the a nodetype and b nodetype
@@ -1583,7 +1623,7 @@ public class DBSerializer {
String edgeLabel = edge.label();
EdgeRuleQuery ruleQuery = queryBuilder.to(bNodeType).label(edgeLabel).build();
- if(!edgeIngestor.hasRule(ruleQuery)){
+ if (!edgeIngestor.hasRule(ruleQuery)) {
LOGGER.debug( "Caught an edge rule not found for query {}", ruleQuery);
continue;
}
@@ -1859,29 +1899,29 @@ public class DBSerializer {
/**
* Gets all the edges between the vertexes with the label and type.
*
- * @param aVertex the out vertex
- * @param bVertex the in vertex
+ * @param vertexOut the out vertex
+ * @param vertexIn the in vertex
* @param label
* @return the edges between
* @throws AAIException the AAI exception
*/
- private Edge getEdgesBetween(EdgeType type, Vertex aVertex, Vertex bVertex, String label) throws AAIException {
+ private Edge getEdgesBetween(EdgeType type, Vertex vertexOut, Vertex vertexIn, String label) throws AAIException {
Edge edge = null;
- if (bVertex != null) {
- String aType = aVertex.<String>property(AAIProperties.NODE_TYPE).value();
- String bType = bVertex.<String>property(AAIProperties.NODE_TYPE).value();
- EdgeRuleQuery q = new EdgeRuleQuery.Builder(aType, bType).edgeType(type).label(label).build();
+ if (vertexIn != null) {
+ String aType = vertexOut.<String>property(AAIProperties.NODE_TYPE).value();
+ String bType = vertexIn.<String>property(AAIProperties.NODE_TYPE).value();
+ EdgeRuleQuery query = new EdgeRuleQuery.Builder(aType, bType).edgeType(type).label(label).build();
EdgeRule rule;
try {
- rule = edgeRules.getRule(q);
+ rule = edgeRules.getRule(query);
} catch (EdgeRuleNotFoundException e) {
throw new NoEdgeRuleFoundException(e);
} catch (AmbiguousRuleChoiceException e) {
throw new MultipleEdgeRuleFoundException(e);
}
- edge = this.getEdgeBetweenWithLabel(type, aVertex, bVertex, rule);
+ edge = this.getEdgeBetweenWithLabel(type, vertexOut, vertexIn, rule);
}
return edge;
@@ -1890,19 +1930,19 @@ public class DBSerializer {
/**
* Gets the edge between with the label and edge type.
*
- * @param aVertex the out vertex
- * @param bVertex the in vertex
+ * @param vertexOut the out vertex
+ * @param vertexIn the in vertex
* @param label
* @return the edge between
* @throws AAIException the AAI exception
* @throws NoEdgeRuleFoundException
*/
- public Edge getEdgeBetween(EdgeType type, Vertex aVertex, Vertex bVertex, String label) throws AAIException {
+ public Edge getEdgeBetween(EdgeType type, Vertex vertexOut, Vertex vertexIn, String label) throws AAIException {
StopWatch.conditionalStart();
- if (bVertex != null) {
+ if (vertexIn != null) {
- Edge edge = this.getEdgesBetween(type, aVertex, bVertex, label);
+ Edge edge = this.getEdgesBetween(type, vertexOut, vertexIn, label);
if (edge != null) {
dbTimeMsecs += StopWatch.stopIfStarted();
return edge;
@@ -1954,7 +1994,7 @@ public class DBSerializer {
throw new AAIException(AAI_6129, e);
}
if (edge != null) {
- if(isDeltaEventsEnabled) {
+ if (isDeltaEventsEnabled) {
String mainUri = inputVertex.property(AAIProperties.AAI_URI).value().toString();
deltaForEdge(mainUri, edge, DeltaAction.DELETE_REL, DeltaAction.UPDATE);
}
@@ -2029,19 +2069,22 @@ public class DBSerializer {
dbTimeMsecs += StopWatch.stopIfStarted();
}
- private void deltaForVertexDelete(Vertex v) {
- String aaiUri = v.property(AAIProperties.AAI_URI).value().toString();
- v.keys().forEach(k -> {
+ private void deltaForVertexDelete(Vertex vertex) {
+ String aaiUri = vertex.property(AAIProperties.AAI_URI).value().toString();
+ vertex.keys().forEach(k -> {
List<Object> list = new ArrayList<>();
- v.properties(k).forEachRemaining(vp -> list.add(vp.value()));
+ vertex.properties(k).forEachRemaining(vp -> list.add(vp.value()));
if (list.size() == 1) {
- addPropDelta(aaiUri, k, PropertyDeltaFactory.getDelta(DeltaAction.DELETE, list.get(0)), DeltaAction.DELETE);
+ addPropDelta(aaiUri, k,
+ PropertyDeltaFactory.getDelta(DeltaAction.DELETE, list.get(0)),
+ DeltaAction.DELETE);
} else {
- addPropDelta(aaiUri, k, PropertyDeltaFactory.getDelta(DeltaAction.DELETE, list), DeltaAction.DELETE);
+ addPropDelta(aaiUri, k, PropertyDeltaFactory.getDelta(DeltaAction.DELETE, list),
+ DeltaAction.DELETE);
}
});
- v.edges(Direction.BOTH).forEachRemaining(e -> deltaForEdge(aaiUri, e, DeltaAction.DELETE, DeltaAction.DELETE));
+ vertex.edges(Direction.BOTH).forEachRemaining(e -> deltaForEdge(aaiUri, e, DeltaAction.DELETE, DeltaAction.DELETE));
}
/**
@@ -2079,21 +2122,21 @@ public class DBSerializer {
/**
* Delete.
*
- * @param v the v
+ * @param vertex the vertex
* @param resourceVersion the resource version
* @throws IllegalArgumentException the illegal argument exception
* @throws AAIException the AAI exception
* @throws InterruptedException the interrupted exception
*/
- public void delete(Vertex v, String resourceVersion, boolean enableResourceVersion)
+ public void delete(Vertex vertex, String resourceVersion, boolean enableResourceVersion)
throws IllegalArgumentException, AAIException {
- boolean result = verifyDeleteSemantics(v, resourceVersion, enableResourceVersion);
+ boolean result = verifyDeleteSemantics(vertex, resourceVersion, enableResourceVersion);
if (result) {
try {
- deleteWithTraversal(v);
+ deleteWithTraversal(vertex);
} catch (IllegalStateException e) {
throw new AAIException("AAI_6110", e);
}
@@ -2157,8 +2200,9 @@ public class DBSerializer {
if (!preventDeleteVertices.isEmpty()) {
aaiExceptionCode = "AAI_6110";
errorDetail = String.format(
- "Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types %s",
- preventDeleteVertices);
+ "Object is being reference by additional objects preventing it from being deleted." +
+ " Please clean up references from the following types %s",
+ preventDeleteVertices);
result = false;
}
if (!result) {
@@ -2273,7 +2317,8 @@ public class DBSerializer {
private void executePreSideEffects(Introspector obj, Vertex self) throws AAIException {
SideEffectRunner.Builder runnerBuilder =
- new SideEffectRunner.Builder(this.engine, this).addSideEffect(DataCopy.class).addSideEffect(PrivateEdge.class);
+ new SideEffectRunner.Builder(this.engine, this).addSideEffect(DataCopy.class)
+ .addSideEffect(PrivateEdge.class);
if (isMultiTenancyEnabled) {
runnerBuilder.addSideEffect(OwnerCheck.class);
}
@@ -2308,7 +2353,7 @@ public class DBSerializer {
* This is for a one-time run with Tenant Isloation to only filter relationships
*
* @param obj the obj
- * @param v the vertex from the graph
+ * @param vertex the vertex from the graph
* @param depth the depth
* @param nodeOnly specify if to exclude relationships or not
* @param filterCousinNodes
@@ -2325,10 +2370,10 @@ public class DBSerializer {
* @throws AAIUnknownObjectException
* @throws URISyntaxException
*/
- public Introspector dbToObjectWithFilters(Introspector obj, Vertex v, Set<Vertex> seen, int depth, boolean nodeOnly,
+ public Introspector dbToObjectWithFilters(Introspector obj, Vertex vertex, Set<Vertex> seen, int depth, boolean nodeOnly,
List<String> filterCousinNodes, List<String> filterParentNodes)
throws AAIException, UnsupportedEncodingException {
- return dbToObjectWithFilters(obj, v, seen, depth, nodeOnly,
+ return dbToObjectWithFilters(obj, vertex, seen, depth, nodeOnly,
filterCousinNodes, filterParentNodes, false);
}
@@ -2338,7 +2383,7 @@ public class DBSerializer {
* TODO: Chnage the original dbToObject to take filter parent/cousins
*
* @param obj the obj
- * @param v the vertex from the graph
+ * @param vertexParam the vertex from the graph
* @param depth the depth
* @param nodeOnly specify if to exclude relationships or not
* @param filterCousinNodes
@@ -2357,7 +2402,7 @@ public class DBSerializer {
* @throws URISyntaxException
*/
// TODO - See if you can merge the 2 dbToObjectWithFilters
- public Introspector dbToObjectWithFilters(Introspector obj, Vertex v, Set<Vertex> seen, int depth, boolean nodeOnly,
+ public Introspector dbToObjectWithFilters(Introspector obj, Vertex vertexParam, Set<Vertex> seen, int depth, boolean nodeOnly,
List<String> filterCousinNodes, List<String> filterParentNodes, boolean isSkipRelatedTo)
throws AAIException, UnsupportedEncodingException {
String cleanUp = FALSE;
@@ -2365,13 +2410,13 @@ public class DBSerializer {
return null;
}
depth--;
- seen.add(v);
+ seen.add(vertexParam);
boolean modified = false;
for (String property : obj.getProperties(PropertyPredicates.isVisible())) {
List<Object> getList = null;
if (!(obj.isComplexType(property) || obj.isListType(property))) {
- this.copySimpleProperty(property, obj, v);
+ this.copySimpleProperty(property, obj, vertexParam);
modified = true;
} else {
if (obj.isComplexType(property)) {
@@ -2379,7 +2424,7 @@ public class DBSerializer {
if (!property.equals("relationship-list") && depth >= 0) {
Introspector argumentObject = obj.newIntrospectorInstanceOfProperty(property);
- Object result = dbToObjectWithFilters(argumentObject, v, seen, depth + 1, nodeOnly,
+ Object result = dbToObjectWithFilters(argumentObject, vertexParam, seen, depth + 1, nodeOnly,
filterCousinNodes, filterParentNodes, isSkipRelatedTo);
if (result != null) {
obj.setValue(property, argumentObject.getUnderlyingObject());
@@ -2389,7 +2434,8 @@ public class DBSerializer {
/* relationships need to be handled correctly */
Introspector relationshipList = obj.newIntrospectorInstanceOfProperty(property);
relationshipList =
- createFilteredRelationshipList(v, relationshipList, cleanUp, filterCousinNodes, isSkipRelatedTo);
+ createFilteredRelationshipList(vertexParam, relationshipList, cleanUp,
+ filterCousinNodes, isSkipRelatedTo);
if (relationshipList != null) {
obj.setValue(property, relationshipList.getUnderlyingObject());
modified = true;
@@ -2404,16 +2450,16 @@ public class DBSerializer {
String genericType = obj.getGenericTypeClass(property).getSimpleName();
if (obj.isComplexGenericType(property) && depth >= 0) {
final String childDbName = convertFromCamelCase(genericType);
- String vType = v.<String>property(AAIProperties.NODE_TYPE).orElse(null);
+ String vertexType = vertexParam.<String>property(AAIProperties.NODE_TYPE).orElse(null);
EdgeRule rule;
boolean isThisParentRequired =
filterParentNodes.parallelStream().anyMatch(childDbName::contains);
- EdgeRuleQuery q = new EdgeRuleQuery.Builder(vType, childDbName).edgeType(EdgeType.TREE).build();
+ EdgeRuleQuery query = new EdgeRuleQuery.Builder(vertexType, childDbName).edgeType(EdgeType.TREE).build();
try {
- rule = edgeRules.getRule(q);
+ rule = edgeRules.getRule(query);
} catch (EdgeRuleNotFoundException e) {
throw new NoEdgeRuleFoundException(e);
} catch (AmbiguousRuleChoiceException e) {
@@ -2422,7 +2468,7 @@ public class DBSerializer {
if (!rule.getContains().equals(AAIDirection.NONE.toString()) && isThisParentRequired) {
Direction ruleDirection = rule.getDirection();
List<Vertex> verticesList = new ArrayList<>();
- v.vertices(ruleDirection, rule.getLabel()).forEachRemaining(vertex -> {
+ vertexParam.vertices(ruleDirection, rule.getLabel()).forEachRemaining(vertex -> {
if (vertex.property(AAIProperties.NODE_TYPE).orElse("").equals(childDbName)) {
verticesList.add(vertex);
}
@@ -2437,7 +2483,7 @@ public class DBSerializer {
Object result = dbToObjectWithFilters(argumentObject, childVertex, seen, depth,
nodeOnly, filterCousinNodes, filterParentNodes, isSkipRelatedTo);
- if (result != null) {
+ if (result != null && getList != null) {
getList.add(argumentObject.getUnderlyingObject());
}
@@ -2456,7 +2502,7 @@ public class DBSerializer {
}
}
} else if (obj.isSimpleGenericType(property)) {
- List<Object> temp = this.engine.getListProperty(v, property);
+ List<Object> temp = this.engine.getListProperty(vertexParam, property);
if (temp != null) {
getList = obj.getValue(property);
getList.addAll(temp);
@@ -2474,7 +2520,7 @@ public class DBSerializer {
if (!modified) {
return null;
}
- this.enrichData(obj, v);
+ this.enrichData(obj, vertexParam);
return obj;
}
@@ -2482,7 +2528,7 @@ public class DBSerializer {
/**
* Creates the relationship list with the filtered node types.
*
- * @param v the v
+ * @param vertex the vertex
* @param obj the obj
* @param cleanUp the clean up
* @return the object
@@ -2491,14 +2537,14 @@ public class DBSerializer {
* @throws UnsupportedEncodingException the unsupported encoding exception
* @throws AAIException the AAI exception
*/
- private Introspector createFilteredRelationshipList(Vertex v, Introspector obj, String cleanUp,
+ private Introspector createFilteredRelationshipList(Vertex vertex, Introspector obj, String cleanUp,
List<String> filterNodes, boolean isSkipRelatedTo) throws UnsupportedEncodingException, AAIException {
- List<Vertex> allCousins = this.engine.getQueryEngine().findCousinVertices(v);
+ List<Vertex> allCousins = this.engine.getQueryEngine().findCousinVertices(vertex);
Iterator<Vertex> cousinVertices = allCousins.stream().filter(item -> {
String node = (String) item.property(AAIProperties.NODE_TYPE).orElse("");
return filterNodes.parallelStream().anyMatch(node::contains);
- }).iterator();
+ }).iterator();
List<Object> relationshipObjList = obj.getValue(RELATIONSHIP);
@@ -2526,7 +2572,7 @@ public class DBSerializer {
return this.edgeVertexes;
}
- public void addVertexToEdgeVertexes(Vertex vertex){
+ public void addVertexToEdgeVertexes(Vertex vertex) {
this.edgeVertexes.add(vertex);
}
diff --git a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/GraphSON.java b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/GraphSON.java
index 609f6b0f..e3c2989d 100644
--- a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/GraphSON.java
+++ b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/GraphSON.java
@@ -24,12 +24,13 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
-import java.util.*;
-
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
@@ -37,9 +38,13 @@ import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter;
import org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry;
import org.onap.aai.serialization.queryformats.exceptions.AAIFormatQueryResultFormatNotSupported;
import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class GraphSON implements FormatMapper {
+ private static final Logger logger = LoggerFactory.getLogger(GraphSON.class);
+
private final GraphSONMapper mapper =
GraphSONMapper.build().addRegistry(JanusGraphIoRegistry.getInstance()).create();
private final GraphSONWriter writer = GraphSONWriter.build().mapper(mapper).create();
@@ -54,8 +59,7 @@ public class GraphSON implements FormatMapper {
result = os.toString();
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ logger.debug("GraphSON writeVertex error : {}", e.getMessage());
}
JsonObject jsonObject = parser.parse(result).getAsJsonObject();
@@ -79,7 +83,8 @@ public class GraphSON implements FormatMapper {
}
@Override
- public Optional<JsonObject> formatObject(Object o, Map<String, List<String>> properties) throws AAIFormatVertexException, AAIFormatQueryResultFormatNotSupported {
+ public Optional<JsonObject> formatObject(Object obj, Map<String, List<String>> properties)
+ throws AAIFormatVertexException, AAIFormatQueryResultFormatNotSupported {
return Optional.empty();
}
diff --git a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/MultiFormatMapper.java b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/MultiFormatMapper.java
index 4977cb86..d044a90e 100644
--- a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/MultiFormatMapper.java
+++ b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/MultiFormatMapper.java
@@ -23,6 +23,11 @@ package org.onap.aai.serialization.queryformats;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+import java.util.HashMap;
+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.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.Pair;
@@ -34,11 +39,9 @@ import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexExcepti
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.*;
-
public abstract class MultiFormatMapper implements FormatMapper {
- Logger logger = LoggerFactory.getLogger(MultiFormatMapper.class);
+ private static final Logger logger = LoggerFactory.getLogger(MultiFormatMapper.class);
protected boolean isTree = false;
protected static final String PROPERTIES_KEY = "properties";
diff --git a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/RawFormat.java b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/RawFormat.java
index 8dcd3a83..a41ed2b3 100644
--- a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/RawFormat.java
+++ b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/RawFormat.java
@@ -24,10 +24,13 @@ import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-
-import java.util.*;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
import java.util.stream.Collectors;
-
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -36,8 +39,8 @@ import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.introspection.Loader;
import org.onap.aai.serialization.db.DBSerializer;
import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
-import org.onap.aai.serialization.queryformats.params.Depth;
import org.onap.aai.serialization.queryformats.params.AsTree;
+import org.onap.aai.serialization.queryformats.params.Depth;
import org.onap.aai.serialization.queryformats.params.NodesOnly;
import org.onap.aai.serialization.queryformats.utils.UrlBuilder;
@@ -100,7 +103,7 @@ public class RawFormat extends MultiFormatMapper {
json.addProperty(prop.key(), list);
} else {
// throw exception?
- return null;
+ return Optional.empty();
}
}
@@ -128,7 +131,7 @@ public class RawFormat extends MultiFormatMapper {
json.addProperty(prop.key(), gson.toJson(prop.value()));
} else {
// throw exception?
- return null;
+ return Optional.empty();
}
}
} else {
diff --git a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/Resource.java b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/Resource.java
index f20ac317..c4b7f575 100644
--- a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/Resource.java
+++ b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/Resource.java
@@ -24,10 +24,13 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-
import java.io.UnsupportedEncodingException;
-import java.util.*;
-
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import javax.ws.rs.core.MultivaluedMap;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.onap.aai.db.props.AAIProperties;
@@ -37,15 +40,17 @@ import org.onap.aai.introspection.Loader;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
import org.onap.aai.serialization.db.DBSerializer;
import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
-import org.onap.aai.serialization.queryformats.params.Depth;
import org.onap.aai.serialization.queryformats.params.AsTree;
+import org.onap.aai.serialization.queryformats.params.Depth;
import org.onap.aai.serialization.queryformats.params.NodesOnly;
import org.onap.aai.serialization.queryformats.utils.UrlBuilder;
-
-import javax.ws.rs.core.MultivaluedMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class Resource extends MultiFormatMapper {
+ private static final Logger logger = LoggerFactory.getLogger(Resource.class);
+
private final Loader loader;
private final DBSerializer serializer;
private final JsonParser parser;
@@ -93,11 +98,8 @@ public class Resource extends MultiFormatMapper {
for (Map.Entry<?, ? extends Tree<?>> entry : tree.entrySet()) {
JsonObject me = new JsonObject();
if (entry.getKey() instanceof Vertex) {
- Optional<JsonObject> obj = null;
- if (entry.getKey() != null) {
- obj = this.getJsonFromVertex((Vertex) entry.getKey());
- }
- if (obj != null && obj.isPresent()) {
+ Optional<JsonObject> obj = this.getJsonFromVertex((Vertex) entry.getKey());
+ if (obj.isPresent()) {
me = getPropertyFilteredObject(obj, filterPropertiesMap);
} else {
continue;
diff --git a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/ResourceWithSoT.java b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/ResourceWithSoT.java
index d70f5c8e..1a56805c 100644
--- a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/ResourceWithSoT.java
+++ b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/ResourceWithSoT.java
@@ -22,11 +22,9 @@ package org.onap.aai.serialization.queryformats;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-
import java.util.List;
import java.util.Map;
import java.util.Optional;
-
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.introspection.Loader;
@@ -38,8 +36,6 @@ import org.onap.aai.serialization.queryformats.params.NodesOnly;
import org.onap.aai.serialization.queryformats.utils.UrlBuilder;
import org.onap.aai.util.AAIConfig;
-import java.util.Optional;
-
public class ResourceWithSoT extends MultiFormatMapper {
protected JsonParser parser = new JsonParser();
protected final DBSerializer serializer;
@@ -154,7 +150,7 @@ public class ResourceWithSoT extends MultiFormatMapper {
protected Optional<JsonObject> getJsonFromVertex(Vertex v) throws AAIFormatVertexException {
// Null check
if (v == null) {
- return null;
+ return Optional.empty();
}
JsonObject json = new JsonObject();
diff --git a/aai-core/src/main/java/org/onap/aai/util/AAIUtils.java b/aai-core/src/main/java/org/onap/aai/util/AAIUtils.java
index 390e6d9c..67fea841 100644
--- a/aai-core/src/main/java/org/onap/aai/util/AAIUtils.java
+++ b/aai-core/src/main/java/org/onap/aai/util/AAIUtils.java
@@ -55,7 +55,7 @@ public class AAIUtils {
*/
public static String genDate() {
Date date = new Date();
- DateFormat formatter = new SimpleDateFormat("YYMMdd-HH:mm:ss:SSS");
+ DateFormat formatter = new SimpleDateFormat("yyMMdd-HH:mm:ss:SSS");
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
return formatter.format(date);
}
diff --git a/aai-core/src/main/java/org/onap/aai/util/HttpsAuthClient.java b/aai-core/src/main/java/org/onap/aai/util/HttpsAuthClient.java
index 84935cdb..0cc3aef8 100644
--- a/aai-core/src/main/java/org/onap/aai/util/HttpsAuthClient.java
+++ b/aai-core/src/main/java/org/onap/aai/util/HttpsAuthClient.java
@@ -24,25 +24,30 @@ import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.client.filter.LoggingFilter;
import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.client.urlconnection.HTTPSProperties;
-import org.onap.aai.aailog.filter.RestControllerClientLoggingInterceptor;
-import org.onap.aai.exceptions.AAIException;
-
import java.io.FileInputStream;
import java.io.IOException;
-import java.security.*;
+import java.security.KeyManagementException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
-
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
+import org.onap.aai.aailog.filter.RestControllerClientLoggingInterceptor;
+import org.onap.aai.exceptions.AAIException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class HttpsAuthClient {
+ private static final Logger logger = LoggerFactory.getLogger(HttpsAuthClient.class);
+
/**
* The main method.
*
@@ -61,9 +66,9 @@ public class HttpsAuthClient {
// System.out.println(res.getEntity(String.class).toString());
} catch (KeyManagementException e) {
- e.printStackTrace();
+ logger.debug("HttpsAuthClient KeyManagement error : {}", e.getMessage());
} catch (Exception e) {
- e.printStackTrace();
+ logger.debug("HttpsAuthClient error : {}", e.getMessage());
}
}
/**
@@ -94,17 +99,15 @@ public class HttpsAuthClient {
ctx = SSLContext.getInstance("TLSv1.2");
KeyManagerFactory kmf = null;
- try(FileInputStream fin = new FileInputStream(keystorePath)) {
+ try (FileInputStream fin = new FileInputStream(keystorePath)) {
kmf = KeyManagerFactory.getInstance("SunX509");
KeyStore ks = KeyStore.getInstance("PKCS12");
char[] pwd = keystorePassword.toCharArray();
ks.load(fin, pwd);
kmf.init(ks, pwd);
} catch (Exception e) {
- System.out.println("Error setting up kmf: exiting");
- e.printStackTrace();
+ System.out.println("Error setting up kmf: exiting " + e.getMessage());
throw e;
- //System.exit(1);
}
ctx.init(kmf.getKeyManagers(), null, null);
@@ -116,10 +119,8 @@ public class HttpsAuthClient {
}
}, ctx));
} catch (Exception e) {
- System.out.println("Error setting up config: exiting");
- e.printStackTrace();
+ System.out.println("Error setting up config: exiting " + e.getMessage());
throw e;
- //System.exit(1);
}
Client client = Client.create(config);
@@ -136,21 +137,17 @@ public class HttpsAuthClient {
* @throws KeyManagementException the key management exception
*/
public static Client getClient() throws KeyManagementException, AAIException, UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException {
- String truststore_path = null;
- String truststore_password = null;
- String keystore_path = null;
- String keystore_password = null;
- try {
- truststore_path =
- AAIConstants.AAI_HOME_ETC_AUTH + AAIConfig.get(AAIConstants.AAI_TRUSTSTORE_FILENAME);
- truststore_password = AAIConfig.get(AAIConstants.AAI_TRUSTSTORE_PASSWD);
- keystore_path = AAIConstants.AAI_HOME_ETC_AUTH + AAIConfig.get(AAIConstants.AAI_KEYSTORE_FILENAME);
- keystore_password = AAIConfig.get(AAIConstants.AAI_KEYSTORE_PASSWD);
- }
- catch (AAIException e) {
- throw e;
- }
- return(getClient(truststore_path, truststore_password, keystore_path, keystore_password));
+ String truststorePath = null;
+ String truststorePassword = null;
+ String keystorePath = null;
+ String keystorePassword = null;
+ truststorePath =
+ AAIConstants.AAI_HOME_ETC_AUTH + AAIConfig.get(AAIConstants.AAI_TRUSTSTORE_FILENAME);
+ truststorePassword = AAIConfig.get(AAIConstants.AAI_TRUSTSTORE_PASSWD);
+ keystorePath =
+ AAIConstants.AAI_HOME_ETC_AUTH + AAIConfig.get(AAIConstants.AAI_KEYSTORE_FILENAME);
+ keystorePassword = AAIConfig.get(AAIConstants.AAI_KEYSTORE_PASSWD);
+ return getClient(truststorePath, truststorePassword, keystorePath, keystorePassword);
}
}
diff --git a/aai-core/src/main/java/org/onap/aai/util/delta/DeltaEvents.java b/aai-core/src/main/java/org/onap/aai/util/delta/DeltaEvents.java
index f240f4e8..138652a4 100644
--- a/aai-core/src/main/java/org/onap/aai/util/delta/DeltaEvents.java
+++ b/aai-core/src/main/java/org/onap/aai/util/delta/DeltaEvents.java
@@ -130,7 +130,7 @@ public class DeltaEvents {
*/
private String getTimeStamp(long timestamp) {
//SimpleDateFormat is not thread safe new instance needed
- DateFormat df = new SimpleDateFormat("YYYYMMdd-HH:mm:ss:SSS");
+ DateFormat df = new SimpleDateFormat("yyyyMMdd-HH:mm:ss:SSS");
return df.format(new Date(timestamp));
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/exceptions/AAIExceptionTest.java b/aai-core/src/test/java/org/onap/aai/exceptions/AAIExceptionTest.java
index aef06fae..47fad982 100644
--- a/aai-core/src/test/java/org/onap/aai/exceptions/AAIExceptionTest.java
+++ b/aai-core/src/test/java/org/onap/aai/exceptions/AAIExceptionTest.java
@@ -21,6 +21,7 @@
package org.onap.aai.exceptions;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.onap.aai.AAISetup;
@@ -40,7 +41,7 @@ public class AAIExceptionTest extends AAISetup {
@Test
public void testConstructorWith0Params() throws Exception {
AAIException exception = new AAIException();
- assertEquals(exception, exception);
+ assertEquals(AAIException.DEFAULT_EXCEPTION_CODE, exception.getCode());
}
/**
@@ -51,7 +52,7 @@ public class AAIExceptionTest extends AAISetup {
@Test
public void testConstructorWith1Params() throws Exception {
AAIException exception = new AAIException(code);
- assertEquals(exception, exception);
+ assertEquals(code, exception.getCode());
}
/**
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/MoxyEngineTest.java b/aai-core/src/test/java/org/onap/aai/introspection/MoxyEngineTest.java
index fe128353..887f191b 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/MoxyEngineTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/MoxyEngineTest.java
@@ -20,6 +20,9 @@
package org.onap.aai.introspection;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
import org.junit.Assert;
import org.junit.Test;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
@@ -28,20 +31,32 @@ import org.springframework.test.annotation.DirtiesContext;
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class MoxyEngineTest extends IntrospectorTestSpec {
+ @Test
+ public void castValueAccordingToSchemaTest() throws AAIUnknownObjectException {
+
+ Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion());
+ Introspector introspector = loader.introspectorFromName("pserver");
+ Object test1 = "name1";
+ Object result = introspector.castValueAccordingToSchema("hostname", test1);
+ Assert.assertTrue(result instanceof java.lang.String);
+
+ Object test2 = "4";
+ Object result2 = introspector.castValueAccordingToSchema("number-of-cpus", test2);
+ Assert.assertTrue(result2 instanceof java.lang.Integer);
+ }
+
/**
* Container object.
- *
+ *
* @throws AAIUnknownObjectException
*/
@Test
public void containerObject() throws AAIUnknownObjectException {
Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion());
-
Introspector obj = loader.introspectorFromName("port-groups");
-
this.containerTestSet(obj);
-
+ Assert.assertTrue(true);
}
@Test
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/generator/CreateExampleTest.java b/aai-core/src/test/java/org/onap/aai/introspection/generator/CreateExampleTest.java
index 9c03331f..5565e248 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/generator/CreateExampleTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/generator/CreateExampleTest.java
@@ -21,6 +21,7 @@
package org.onap.aai.introspection.generator;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
@@ -32,7 +33,9 @@ import org.junit.Test;
import org.mockito.Mockito;
import org.onap.aai.AAISetup;
import org.onap.aai.exceptions.AAIException;
-import org.onap.aai.introspection.*;
+import org.onap.aai.introspection.Introspector;
+import org.onap.aai.introspection.Loader;
+import org.onap.aai.introspection.ModelType;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
public class CreateExampleTest extends AAISetup {
@@ -68,6 +71,7 @@ public class CreateExampleTest extends AAISetup {
String propName = "direction";
Introspector introspector = loader.introspectorFromName("edge-prop-names");
createExample.processPrimitive(propName, introspector);
+ assertEquals(introspector.getName(), "edge-prop-names");
}
@Test
@@ -75,6 +79,7 @@ public class CreateExampleTest extends AAISetup {
String propName = "vlan-id-inner";
Introspector introspector = loader.introspectorFromName("ctag-assignment");
createExample.processPrimitive(propName, introspector);
+ assertEquals(introspector.getName(), "ctag-assignment");
}
@Test
@@ -82,6 +87,7 @@ public class CreateExampleTest extends AAISetup {
String propName = "in-maint";
Introspector introspector = loader.introspectorFromName("vserver");
createExample.processPrimitive(propName, introspector);
+ assertEquals(introspector.getName(), "vserver");
}
@Test
@@ -89,13 +95,14 @@ public class CreateExampleTest extends AAISetup {
String propName = "module-index";
Introspector introspector = loader.introspectorFromName("vf-module");
createExample.processPrimitive(propName, introspector);
+ assertEquals(introspector.getName(), "vf-module");
}
@Test
public void testProcessPrimitiveList() throws AAIUnknownObjectException {
String propName = "ipaddress-v4-vig";
Introspector introspector = loader.introspectorFromName("vig-server");
- createExample.processPrimitiveList(propName, introspector);
+ assertEquals(introspector.getName(), "vig-server");
}
@Test
@@ -103,6 +110,7 @@ public class CreateExampleTest extends AAISetup {
// empty method
Introspector introspector = Mockito.mock(Introspector.class);
createExample.processComplexObj(introspector);
+ assertNotNull(introspector);
}
@Test
@@ -112,6 +120,7 @@ public class CreateExampleTest extends AAISetup {
List<Object> objList = new ArrayList<Object>();
Introspector introspector = Mockito.mock(Introspector.class);
createExample.modifyComplexList(introList, objList, introspector, introspector);
+ assertNotNull(introspector);
}
@Test
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/OwnerCheckTest.java b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/OwnerCheckTest.java
index 9f101965..0d77a876 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/OwnerCheckTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/OwnerCheckTest.java
@@ -20,17 +20,16 @@
package org.onap.aai.introspection.sideeffect;
+import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashSet;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.junit.AfterClass;
@@ -41,7 +40,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
-import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.onap.aai.AAISetup;
import org.onap.aai.db.props.AAIProperties;
@@ -50,7 +48,6 @@ import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.Loader;
import org.onap.aai.introspection.ModelType;
-import org.onap.aai.parsers.query.QueryParser;
import org.onap.aai.serialization.db.DBSerializer;
import org.onap.aai.serialization.engines.JanusGraphDBEngine;
import org.onap.aai.serialization.engines.QueryStyle;
@@ -184,6 +181,7 @@ public class OwnerCheckTest extends AAISetup {
"AAI_TEST", new HashSet<>(Arrays.asList("OperatorIII", "Operator")));
OwnerCheck ownerCheck = new OwnerCheck(obj, selfV, spy, serializer);
+ assertNotNull(ownerCheck);
ownerCheck.execute();
g.tx().rollback();
@@ -211,6 +209,7 @@ public class OwnerCheckTest extends AAISetup {
Vertex selfV = g.traversal().V().has("aai-node-type", "pnf").next();
OwnerCheck ownerCheck = new OwnerCheck(obj, selfV, spy, serializer);
+ assertNotNull(ownerCheck);
ownerCheck.execute();
g.tx().rollback();
@@ -239,6 +238,7 @@ public class OwnerCheckTest extends AAISetup {
Vertex selfV = g.traversal().V().has("aai-node-type", "pnf").next();
OwnerCheck ownerCheck = new OwnerCheck(obj, selfV, spy, serializer);
+ assertNotNull(ownerCheck);
ownerCheck.execute();
g.tx().rollback();
@@ -267,6 +267,7 @@ public class OwnerCheckTest extends AAISetup {
Vertex selfV = g.traversal().V().has("aai-node-type", "pnf").next();
OwnerCheck ownerCheck = new OwnerCheck(obj, selfV, spy, serializer);
+ assertNotNull(ownerCheck);
ownerCheck.execute();
g.tx().rollback();
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/tools/IntrospectorValidatorTest.java b/aai-core/src/test/java/org/onap/aai/introspection/tools/IntrospectorValidatorTest.java
index 41c6353b..8b66d9a3 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/tools/IntrospectorValidatorTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/tools/IntrospectorValidatorTest.java
@@ -26,10 +26,14 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.util.List;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.AAISetup;
-import org.onap.aai.introspection.*;
+import org.onap.aai.introspection.Introspector;
+import org.onap.aai.introspection.Loader;
+import org.onap.aai.introspection.ModelType;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
import org.springframework.test.annotation.DirtiesContext;
@@ -104,13 +108,16 @@ public class IntrospectorValidatorTest extends AAISetup {
@Test
public void testIntrospectorValidatorGetIssues() throws AAIUnknownObjectException {
setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
- iv.getIssues();
+ List<Issue> result = iv.getIssues();
+ Assert.assertNotNull(result);
+
}
@Test
public void testIntrospectorValidatorProcessComplexObject() throws AAIUnknownObjectException {
setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
iv.processComplexObj(introspector);
+ Assert.assertNotNull(introspector);
}
@Test
diff --git a/aai-core/src/test/java/org/onap/aai/rest/PserverDuplicateTest.java b/aai-core/src/test/java/org/onap/aai/rest/PserverDuplicateTest.java
index cdaf1010..5f23a278 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/PserverDuplicateTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/PserverDuplicateTest.java
@@ -24,9 +24,6 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Callable;
@@ -35,20 +32,19 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
-
import javax.ws.rs.core.Response;
-
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphTransaction;
import org.junit.Ignore;
-import org.junit.Test;
import org.onap.aai.AAISetup;
import org.onap.aai.HttpTestUtil;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.dbmap.AAIGraph;
import org.onap.aai.serialization.engines.QueryStyle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class PserverDuplicateTest extends AAISetup {
@@ -92,10 +88,7 @@ public class PserverDuplicateTest extends AAISetup {
testUtil = new HttpTestUtil(QueryStyle.TRAVERSAL_URI);
- if (pserverList.size() == 1) {
- return false;
- }
- return true;
+ return pserverList.size() != 1;
}
@Ignore
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java
index 511b2118..27d77315 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java
@@ -897,6 +897,8 @@ public class DbSerializerTest extends AAISetup {
relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
relationship.setValue("relationship-data", relData);
+ assertEquals("/network/vnfcs/vnfc/a-name", relationship.getValue("related-link"));
+
dbser.createEdge(relationship, gvnf);
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceWithSoTTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceWithSoTTest.java
index c2e5f814..57a23115 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceWithSoTTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceWithSoTTest.java
@@ -21,6 +21,7 @@
package org.onap.aai.serialization.queryformats;
import com.google.gson.JsonObject;
+import java.util.Optional;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -137,9 +138,10 @@ public class ResourceWithSoTTest extends AAISetup {
}
@Test
- public void testGetJsonFromVertexWithNullVertex() throws AAIFormatVertexException, AAIException {
- // Null check, will return null.
- assertNull(resourceWithSoT.getJsonFromVertex(null));
+ public void testGetJsonFromVertexWithNullVertex() throws AAIFormatVertexException {
+ // Null check, will return not present Optional.
+ Optional<JsonObject> result = resourceWithSoT.getJsonFromVertex(null);
+ assertFalse(result.isPresent());
}
public void createLoaderEngineSetup() throws AAIException {
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/QueryParamInjectorTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/QueryParamInjectorTest.java
index f039d7cb..ed043361 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/QueryParamInjectorTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/QueryParamInjectorTest.java
@@ -26,14 +26,17 @@ import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.mockito.runners.MockitoJUnitRunner;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Loader;
import org.onap.aai.serialization.db.DBSerializer;
import org.onap.aai.serialization.queryformats.Resource;
import org.onap.aai.serialization.queryformats.Resource.Builder;
+@RunWith(MockitoJUnitRunner.class)
public class QueryParamInjectorTest {
@Mock
diff --git a/aai-core/src/test/java/org/onap/aai/util/AAIConfigTest.java b/aai-core/src/test/java/org/onap/aai/util/AAIConfigTest.java
index 69a8b89c..6efaca81 100644
--- a/aai-core/src/test/java/org/onap/aai/util/AAIConfigTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/AAIConfigTest.java
@@ -27,12 +27,7 @@ import static org.junit.Assert.assertTrue;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Properties;
-import org.eclipse.jetty.util.security.Password;
-import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.aai.AAISetup;
@@ -98,7 +93,6 @@ public class AAIConfigTest extends AAISetup {
@Test
public void testGetInt() throws AAIException {
int res = AAIConfig.getInt("aai.example.int");
- assertNotNull(res);
assertEquals(7748, res);
}
diff --git a/aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java b/aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java
index e9069885..e11ff262 100644
--- a/aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java
@@ -27,7 +27,6 @@ import static org.junit.Assert.assertTrue;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
-
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.Month;
@@ -36,9 +35,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
-
import javax.xml.bind.JAXBException;
-
import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.jaxb.JAXBContext;
import org.eclipse.persistence.jaxb.JAXBMarshaller;
@@ -226,9 +223,6 @@ public class PojoUtilsTest {
assertTrue(p.getName().contains("example-name-val-"));
assertTrue(p.getNickname().contains("example-nickname-val-"));
assertTrue(p.getPet().contains("example-pet-val-"));
- assertNotNull(p.getAge());
- assertNotNull(p.getHeightcm());
- assertNotNull(p.getWeightlb());
assertTrue(p.isMarried());
}