aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Reehil <william.reehil@att.com>2021-07-08 13:34:54 +0000
committerGerrit Code Review <gerrit@onap.org>2021-07-08 13:34:54 +0000
commit03e4a9c48f9fe3ce7ed2ff2d7808eb7e62cbc573 (patch)
treec1f44e44cf9ad4f55d15d6fcae5717eb6dac63d5
parent89ea55bd33bffeca2a3f3781c0fcacaf18077002 (diff)
parenta2f7d11ca0bd58ec6c252111ddd3d5dfac0e4c70 (diff)
Merge "Fix all blocker sonar issues and some checkstyle"
-rw-r--r--aai-aaf-auth/src/main/java/org/onap/aai/aaf/auth/CertUtil.java30
-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
-rw-r--r--aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestClientLoggingInterceptor.java15
-rw-r--r--aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConfig.java2
-rw-r--r--aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/JsonSchemaProvider.java62
-rw-r--r--aai-schema-abstraction/src/test/java/org/onap/aai/schemaif/json/JsonSchemaProviderTest.java385
-rw-r--r--aai-schema-abstraction/src/test/java/org/onap/aai/schemaif/oxm/OxmSchemaServiceSetup.java3
-rw-r--r--aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeIngestor.java27
-rw-r--r--aai-schema-ingest/src/main/java/org/onap/aai/nodes/NodeIngestor.java25
-rw-r--r--aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java19
-rw-r--r--aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DefaultDuplicateNodeDefinitionValidationModule.java8
40 files changed, 711 insertions, 582 deletions
diff --git a/aai-aaf-auth/src/main/java/org/onap/aai/aaf/auth/CertUtil.java b/aai-aaf-auth/src/main/java/org/onap/aai/aaf/auth/CertUtil.java
index 334a3060..26273a6a 100644
--- a/aai-aaf-auth/src/main/java/org/onap/aai/aaf/auth/CertUtil.java
+++ b/aai-aaf-auth/src/main/java/org/onap/aai/aaf/auth/CertUtil.java
@@ -20,23 +20,27 @@
package org.onap.aai.aaf.auth;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
-import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.cert.X509Certificate;
-import java.util.*;
import java.util.stream.Collectors;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* The Class CertUtil provides cert related utility methods.
*/
public class CertUtil {
- public static final String DEFAULT_CADI_ISSUERS =
- "CN=ATT AAF CADI Test Issuing CA 01, OU=CSO, O=ATT, C=US:CN=ATT AAF CADI Test Issuing CA 02, OU=CSO, O=ATT, C=US";
+ public static final String DEFAULT_CADI_ISSUERS = "CN=ATT AAF CADI Test Issuing " +
+ "CA 01, OU=CSO, O=ATT, C=US:CN=ATT AAF CADI Test Issuing CA 02, OU=CSO, O=ATT, C=US";
public static final String CADI_PROP_FILES = "cadi_prop_files";
public static final String CADI_ISSUERS_PROP_NAME = "cadi_x509_issuers";
public static final String CADI_ISSUERS_SEPARATOR = ":";
@@ -119,11 +123,11 @@ public class CertUtil {
public static List<String> getCadiCertIssuers(Properties cadiProperties) {
- List<String> defaultList = new ArrayList<String>();
+ List<String> defaultList = new ArrayList<>();
List<String> resultList = new ArrayList<String>();
- String[] cIssuers = DEFAULT_CADI_ISSUERS.split(CADI_ISSUERS_SEPARATOR);
- for (String issuer : cIssuers) {
+ String[] cadiIssuers = DEFAULT_CADI_ISSUERS.split(CADI_ISSUERS_SEPARATOR);
+ for (String issuer : cadiIssuers) {
defaultList.add(issuer.replaceAll("\\s+", "").toUpperCase());
}
try {
@@ -131,12 +135,14 @@ public class CertUtil {
String configuredIssuers = DEFAULT_CADI_ISSUERS;
Properties certProperties = new Properties();
if (certPropFileName != null) {
- certProperties.load(new FileInputStream(new File(certPropFileName)));
+ try (FileInputStream fis = new FileInputStream(certPropFileName)) {
+ certProperties.load(fis);
+ }
configuredIssuers = certProperties.getProperty(CADI_ISSUERS_PROP_NAME);
}
if ((configuredIssuers != null) && (!configuredIssuers.isEmpty())) {
- cIssuers = configuredIssuers.split(CADI_ISSUERS_SEPARATOR);
- for (String issuer : cIssuers) {
+ cadiIssuers = configuredIssuers.split(CADI_ISSUERS_SEPARATOR);
+ for (String issuer : cadiIssuers) {
resultList.add(issuer.replaceAll("\\s+", "").toUpperCase());
}
}
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());
}
diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestClientLoggingInterceptor.java b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestClientLoggingInterceptor.java
index 51824b74..629587d5 100644
--- a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestClientLoggingInterceptor.java
+++ b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestClientLoggingInterceptor.java
@@ -19,22 +19,19 @@
*/
package org.onap.aai.aailog.filter;
+import java.io.IOException;
+import java.util.List;
+import java.util.UUID;
import org.onap.aai.aailog.logs.ServiceName;
import org.onap.logging.filter.base.AbstractMetricLogFilter;
import org.onap.logging.filter.base.Constants;
-import org.onap.logging.filter.base.MDCSetup;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.slf4j.MDC;
+import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
-import org.springframework.http.HttpHeaders;
-
-import javax.ws.rs.core.MultivaluedMap;
-import java.io.IOException;
-import java.util.List;
-import java.util.UUID;
public class RestClientLoggingInterceptor extends AbstractMetricLogFilter<HttpRequest, ClientHttpResponse, HttpHeaders> implements ClientHttpRequestInterceptor {
@Override
@@ -61,8 +58,8 @@ public class RestClientLoggingInterceptor extends AbstractMetricLogFilter<HttpRe
String requestId = extractRequestID(requestHeaders);
addHeader(requestHeaders, ONAPLogConstants.Headers.REQUEST_ID, requestId);
addHeader(requestHeaders, Constants.HttpHeaders.HEADER_REQUEST_ID, requestId);
- if (requestHeaders.getFirst(Constants.HttpHeaders.TRANSACTION_ID) == null ||
- requestHeaders.getFirst(Constants.HttpHeaders.TRANSACTION_ID).isEmpty()) {
+ String transactionId = requestHeaders.getFirst(Constants.HttpHeaders.TRANSACTION_ID);
+ if (transactionId == null || transactionId.isEmpty()) {
addHeader(requestHeaders, Constants.HttpHeaders.TRANSACTION_ID, requestId);
}
addHeader(requestHeaders, Constants.HttpHeaders.ECOMP_REQUEST_ID, requestId);
diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConfig.java b/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConfig.java
index 8d3e2cc8..2428f1e9 100644
--- a/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConfig.java
+++ b/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConfig.java
@@ -58,7 +58,7 @@ public class AAIConfig {
AAIConfig.getConfigFile();
AAIConfig.reloadConfig();
- if (AAIConstants.AAI_NODENAME == null || AAIConstants.AAI_NODENAME == "") {
+ if (AAIConstants.AAI_NODENAME == null || AAIConstants.AAI_NODENAME.equals("")) {
ErrorLogHelper.logError("AAI_4005", " AAI_NODENAME is not defined");
} else {
LOGGER.info("A&AI Server Node Name = " + AAIConstants.AAI_NODENAME);
diff --git a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/JsonSchemaProvider.java b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/JsonSchemaProvider.java
index 47cb2727..e7ee4b47 100644
--- a/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/JsonSchemaProvider.java
+++ b/aai-schema-abstraction/src/main/java/org/onap/aai/schemaif/json/JsonSchemaProvider.java
@@ -20,8 +20,9 @@
*/
package org.onap.aai.schemaif.json;
+import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
-import java.io.IOException;
+import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Arrays;
@@ -32,7 +33,6 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
-
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.schemaif.SchemaProvider;
@@ -162,7 +162,7 @@ public class JsonSchemaProvider implements SchemaProvider {
}
try {
- SchemaServiceResponse resp = SchemaServiceResponse.fromJson(unzipAndGetJSONString(response));
+ SchemaServiceResponse resp = SchemaServiceResponse.fromJson(unzipAndGetJSONString(response.getBody()));
loadSchema(resp.getData().toJson(), version);
}
catch (Exception ex) {
@@ -178,34 +178,42 @@ public class JsonSchemaProvider implements SchemaProvider {
logger.info(SchemaProviderMsgs.LOADED_SCHEMA_FILE, version);
}
- private String unzipAndGetJSONString(ResponseEntity<byte[]> response) throws IOException {
- StringBuffer sb = new StringBuffer("");
-
- ZipInputStream zipStream = null;
- try {
-
- zipStream = new ZipInputStream(new ByteArrayInputStream(response.getBody()));
- ZipEntry entry = null;
- while ((entry = zipStream.getNextEntry()) != null) {
- Scanner sc = new Scanner(zipStream);
- while (sc.hasNextLine()) {
- sb.append(sc.nextLine());
+ static final int BUFFER = 512;
+ static final long TOOBIG = 0x6400000; // Max size of unzipped data, 100MB
+ static final int TOOMANY = 1024; // Max number of files
+
+ protected String unzipAndGetJSONString(byte[] inputData) throws java.io.IOException {
+ ZipEntry entry;
+ String result = "";
+ int entries = 0;
+ long total = 0;
+ try (ByteArrayInputStream bis = new ByteArrayInputStream(inputData); ZipInputStream zis = new ZipInputStream(bis)) {
+ while ((entry = zis.getNextEntry()) != null) {
+ int count;
+ byte[] data = new byte[BUFFER];
+ if (entry.isDirectory()) {
+ continue;
}
-
- }
- } finally {
- try {
- if (zipStream != null) {
- zipStream.closeEntry();
- zipStream.close();
+ ByteArrayOutputStream fos = new ByteArrayOutputStream();
+ BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
+ while (total + BUFFER <= TOOBIG && (count = zis.read(data, 0, BUFFER)) != -1) {
+ dest.write(data, 0, count);
+ total += count;
+ }
+ dest.flush();
+ result = fos.toString();
+ dest.close();
+ zis.closeEntry();
+ entries++;
+ if (entries > TOOMANY) {
+ throw new IllegalStateException("Too many files to unzip.");
+ }
+ if (total + BUFFER > TOOBIG) {
+ throw new IllegalStateException("File being unzipped is too big.");
}
- } catch (Exception e) {
- logger.warn(SchemaProviderMsgs.SCHEMA_LOAD_ERROR, e.toString());
-
}
}
-
- return sb.toString();
+ return result;
}
private SchemaInstance getSchemaVersion(String version) throws SchemaProviderException {
diff --git a/aai-schema-abstraction/src/test/java/org/onap/aai/schemaif/json/JsonSchemaProviderTest.java b/aai-schema-abstraction/src/test/java/org/onap/aai/schemaif/json/JsonSchemaProviderTest.java
index 83ba9e33..332d6672 100644
--- a/aai-schema-abstraction/src/test/java/org/onap/aai/schemaif/json/JsonSchemaProviderTest.java
+++ b/aai-schema-abstraction/src/test/java/org/onap/aai/schemaif/json/JsonSchemaProviderTest.java
@@ -1,5 +1,5 @@
/**
- * ============LICENSE_START=======================================================
+ * ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
* Copyright © 2019 AT&T Intellectual Property. All rights reserved.
@@ -21,8 +21,14 @@
package org.onap.aai.schemaif.json;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -30,7 +36,8 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Set;
-
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.schemaif.SchemaProviderException;
@@ -53,7 +60,7 @@ public class JsonSchemaProviderTest {
JsonSchemaProviderConfig config = new JsonSchemaProviderConfig();
@Before
- public void init() throws Exception {
+ public void init() {
config.setSchemaServiceBaseUrl("https://testurl.com:8443");
config.setSchemaServiceCertFile("/c/certfile");
config.setSchemaServiceCertPwd("my-password");
@@ -61,6 +68,26 @@ public class JsonSchemaProviderTest {
}
@Test
+ public void testReadZipJson() throws IOException, SchemaProviderException {
+ JsonSchemaProvider jsonSchemaProvider = new JsonSchemaProvider(config);
+
+ ByteArrayOutputStream fos = new ByteArrayOutputStream();
+ ZipOutputStream zos = new ZipOutputStream(fos);
+ zos.putNextEntry(new ZipEntry("schemaServiceResponse.json"));
+ byte[] fileData = Files.readAllBytes(Paths.get("src/test/resources/json/schemaServiceResponse.json"));
+ zos.write(fileData, 0, fileData.length);
+ zos.closeEntry();
+ zos.close();
+
+ String testSchema = readFile("src/test/resources/json/schemaServiceResponse.json");
+ SchemaServiceResponse resp = SchemaServiceResponse.fromJson(testSchema);
+
+ String result = jsonSchemaProvider.unzipAndGetJSONString(fos.toByteArray());
+ SchemaServiceResponse resp2 = SchemaServiceResponse.fromJson(result);
+ assertEquals(resp.toJson(), resp2.toJson());
+ }
+
+ @Test
public void testJsonSchemaLoad() {
try {
String testSchema = readFile("src/test/resources/json/jsonSchema.json");
@@ -69,14 +96,15 @@ public class JsonSchemaProviderTest {
// Test Edge Schema
JsonEdgeSchema edgeSchema = null;
for (JsonEdgeSchema edge : jsonSchema.getRelationshipTypes()) {
- if ( (edge.getFrom().equals("onap.nodes.sdwan.uCPE"))
+ if ( (edge.getFrom().equals("onap.nodes.sdwan.uCPE"))
&& (edge.getTo().equals("onap.nodes.sdwan.service.SubscriberService")) ) {
edgeSchema = edge;
break;
}
}
- assertTrue(edgeSchema.getLabel().equals("onap.relationships.sdwan.BelongsTo"));
+ assertNotNull(edgeSchema);
+ assertEquals("onap.relationships.sdwan.BelongsTo", edgeSchema.getLabel());
// Test Node Schema
JsonVertexSchema vertexSchema = null;
@@ -87,7 +115,8 @@ public class JsonSchemaProviderTest {
}
}
- assertTrue(vertexSchema.getProperties().size() == 2);
+ assertNotNull(vertexSchema);
+ assertEquals(2, vertexSchema.getProperties().size());
JsonPropertySchema propSchema = null;
for (JsonPropertySchema p : vertexSchema.getProperties()) {
@@ -97,11 +126,12 @@ public class JsonSchemaProviderTest {
}
}
- assertTrue(propSchema.getRequired() == false);
- assertTrue(propSchema.getUnique() == false);
- assertTrue(propSchema.getDataType().equals("org.onap.datatypes.RuleList"));
- assertTrue(propSchema.getDefaultValue().equals(""));
- assertTrue(propSchema.getAnnotations().size() == 4);
+ assertNotNull(propSchema);
+ assertEquals(false, propSchema.getRequired());
+ assertEquals(false, propSchema.getUnique());
+ assertEquals("org.onap.datatypes.RuleList", propSchema.getDataType());
+ assertEquals("", propSchema.getDefaultValue());
+ assertEquals(4, propSchema.getAnnotations().size());
// Test DataType Schema
DataTypeDefinition dataType = null;
@@ -112,8 +142,9 @@ public class JsonSchemaProviderTest {
}
}
- assertTrue(dataType.getName().equals("org.onap.datatypes.network.VlanRequirements"));
- assertTrue(dataType.getProperties().size() == 4);
+ assertNotNull(dataType);
+ assertEquals("org.onap.datatypes.network.VlanRequirements", dataType.getName());
+ assertEquals(4, dataType.getProperties().size());
propSchema = null;
for (JsonPropertySchema p : dataType.getProperties()) {
@@ -123,16 +154,17 @@ public class JsonSchemaProviderTest {
}
}
- assertTrue(propSchema.getRequired() == false);
- assertTrue(propSchema.getDataType().equals("string"));
- assertTrue(propSchema.getDefaultValue().equals(""));
+ assertNotNull(propSchema);
+ assertEquals(false, propSchema.getRequired());
+ assertEquals("string", propSchema.getDataType());
+ assertEquals("", propSchema.getDefaultValue());
}
catch (Exception ex) {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
- System.out.println(writer.toString());
- assertTrue(false);
+ System.out.println(writer);
+ fail();
}
}
@@ -143,42 +175,42 @@ public class JsonSchemaProviderTest {
JsonSchemaProvider schemaProvider = new JsonSchemaProvider(config);
schemaProvider.loadSchema(testSchema, schemaProvider.getLatestSchemaVersion());
- VertexSchema vertSchema =
- schemaProvider.getVertexSchema("tosca.nodes.objectstorage",
+ VertexSchema vertSchema =
+ schemaProvider.getVertexSchema("tosca.nodes.objectstorage",
schemaProvider.getLatestSchemaVersion());
System.out.println(vertSchema.toString());
// Validate vertex schema
- assertTrue(vertSchema.getName().equals("tosca.nodes.ObjectStorage"));
- assertTrue(vertSchema.getAnnotationValue("searchable").equals("size,name"));
- assertTrue(vertSchema.getAnnotationValue("indexedProps").equals("aai-uuid,name"));
+ assertEquals("tosca.nodes.ObjectStorage", vertSchema.getName());
+ assertEquals("size,name", vertSchema.getAnnotationValue("searchable"));
+ assertEquals("aai-uuid,name", vertSchema.getAnnotationValue("indexedProps"));
PropertySchema propSchema = vertSchema.getPropertySchema("Name");
- assertTrue(propSchema.getName().equals("name"));
- assertTrue(propSchema.getDefaultValue().equals(""));
+ assertEquals("name", propSchema.getName());
+ assertEquals("", propSchema.getDefaultValue());
assertTrue(propSchema.isRequired());
- assertTrue(!propSchema.isKey());
- assertTrue(!propSchema.isReserved());
- assertTrue(propSchema.getDataType().getType().compareTo(Type.STRING) == 0);
- assertTrue(propSchema.getAnnotationValue("Source_of_truth_type").equals("AAI"));
+ assertFalse(propSchema.isKey());
+ assertFalse(propSchema.isReserved());
+ assertEquals(0, propSchema.getDataType().getType().compareTo(Type.STRING));
+ assertEquals("AAI", propSchema.getAnnotationValue("Source_of_truth_type"));
propSchema = vertSchema.getPropertySchema("Size");
- assertTrue(propSchema.getName().equals("size"));
- assertTrue(propSchema.getDefaultValue().equals("50"));
- assertTrue(propSchema.getDataType().getType().compareTo(Type.INT) == 0);
-
+ assertEquals("size", propSchema.getName());
+ assertEquals("50", propSchema.getDefaultValue());
+ assertEquals(0, propSchema.getDataType().getType().compareTo(Type.INT));
+
propSchema = vertSchema.getPropertySchema("source-of-truth");
- assertTrue(propSchema.getName().equals("source-of-truth"));
- assertTrue(!propSchema.isRequired());
+ assertEquals("source-of-truth", propSchema.getName());
+ assertFalse(propSchema.isRequired());
assertTrue(propSchema.isReserved());
- assertTrue(propSchema.getDataType().getType().compareTo(Type.STRING) == 0);
+ assertEquals(0, propSchema.getDataType().getType().compareTo(Type.STRING));
}
catch (Exception ex) {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
- System.out.println(writer.toString());
- assertTrue(false);
+ System.out.println(writer);
+ fail();
}
}
@@ -189,17 +221,17 @@ public class JsonSchemaProviderTest {
JsonSchemaProvider schemaProvider = new JsonSchemaProvider(config);
schemaProvider.loadSchema(testSchema, schemaProvider.getLatestSchemaVersion());
- EdgeSchema edgeSchema = schemaProvider.getEdgeSchema("tosca.relationships.hostedOn",
- "tosca.nodes.Softwarecomponent", "tosca.nodes.compute",
+ EdgeSchema edgeSchema = schemaProvider.getEdgeSchema("tosca.relationships.hostedOn",
+ "tosca.nodes.Softwarecomponent", "tosca.nodes.compute",
schemaProvider.getLatestSchemaVersion());
System.out.println(edgeSchema.toString());
// Validate edge schema
- assertTrue(edgeSchema.getName().equals("tosca.relationships.HostedOn"));
- assertTrue(edgeSchema.getSource().equals("tosca.nodes.SoftwareComponent"));
- assertTrue(edgeSchema.getTarget().equals("tosca.nodes.Compute"));
- assertTrue(edgeSchema.getMultiplicity().equals(EdgeSchema.Multiplicity.MANY_2_MANY));
- assertTrue(edgeSchema.getAnnotationValue("contains-other-v").equals("NONE"));
+ assertEquals("tosca.relationships.HostedOn", edgeSchema.getName());
+ assertEquals("tosca.nodes.SoftwareComponent", edgeSchema.getSource());
+ assertEquals("tosca.nodes.Compute", edgeSchema.getTarget());
+ assertEquals(edgeSchema.getMultiplicity(), EdgeSchema.Multiplicity.MANY_2_MANY);
+ assertEquals("NONE", edgeSchema.getAnnotationValue("contains-other-v"));
}
@@ -207,8 +239,8 @@ public class JsonSchemaProviderTest {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
- System.out.println(writer.toString());
- assertTrue(false);
+ System.out.println(writer);
+ fail();
}
}
@@ -219,32 +251,30 @@ public class JsonSchemaProviderTest {
JsonSchemaProvider schemaProvider = new JsonSchemaProvider(config);
schemaProvider.loadSchema(testSchema, schemaProvider.getLatestSchemaVersion());
- Set<EdgeSchema> edgeSchemaList =
- schemaProvider.getAdjacentEdgeSchema("tosca.nodes.Database",
+ Set<EdgeSchema> edgeSchemaList =
+ schemaProvider.getAdjacentEdgeSchema("tosca.nodes.Database",
schemaProvider.getLatestSchemaVersion());
// Validate edge schema
- assertTrue(edgeSchemaList.size() == 3);
+ assertEquals(3, edgeSchemaList.size());
for (EdgeSchema es : edgeSchemaList) {
System.out.println(es.toString());
- if (es.getName().equals("tosca.relationships.HostedOn")) {
- assertTrue(es.getSource().equals("tosca.nodes.Database"));
- assertTrue(es.getTarget().equals("tosca.nodes.DBMS"));
- assertTrue(es.getMultiplicity().equals(EdgeSchema.Multiplicity.MANY_2_MANY));
- }
- else if (es.getName().equals("tosca.relationships.RoutesTo")) {
- assertTrue(es.getSource().equals("tosca.nodes.LoadBalancer"));
- assertTrue(es.getTarget().equals("tosca.nodes.Database"));
- assertTrue(es.getMultiplicity().equals(EdgeSchema.Multiplicity.MANY_2_MANY));
- }
- else if (es.getName().equals("tosca.relationships.Uses")) {
- assertTrue(es.getSource().equals("tosca.nodes.LoadBalancer"));
- assertTrue(es.getTarget().equals("tosca.nodes.Database"));
- assertTrue(es.getMultiplicity().equals(EdgeSchema.Multiplicity.MANY_2_MANY));
- }
- else {
- assertTrue(false);
+ switch (es.getName()) {
+ case "tosca.relationships.HostedOn":
+ assertEquals("tosca.nodes.Database", es.getSource());
+ assertEquals("tosca.nodes.DBMS", es.getTarget());
+ assertEquals(es.getMultiplicity(), EdgeSchema.Multiplicity.MANY_2_MANY);
+ break;
+ case "tosca.relationships.RoutesTo":
+ case "tosca.relationships.Uses":
+ assertEquals("tosca.nodes.LoadBalancer", es.getSource());
+ assertEquals("tosca.nodes.Database", es.getTarget());
+ assertEquals(es.getMultiplicity(), EdgeSchema.Multiplicity.MANY_2_MANY);
+ break;
+ default:
+ fail();
+ break;
}
}
}
@@ -252,8 +282,8 @@ public class JsonSchemaProviderTest {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
- System.out.println(writer.toString());
- assertTrue(false);
+ System.out.println(writer);
+ fail();
}
}
@@ -264,28 +294,28 @@ public class JsonSchemaProviderTest {
JsonSchemaProvider schemaProvider = new JsonSchemaProvider(config);
schemaProvider.loadSchema(testSchema, schemaProvider.getLatestSchemaVersion());
- Set<EdgeSchema> edgeSchemaList =
- schemaProvider.getEdgeSchemaForSourceTarget("tosca.nodes.LoadBalancer",
- "tosca.nodes.Database",
+ Set<EdgeSchema> edgeSchemaList =
+ schemaProvider.getEdgeSchemaForSourceTarget("tosca.nodes.LoadBalancer",
+ "tosca.nodes.Database",
schemaProvider.getLatestSchemaVersion());
// Validate edge schema
- assertTrue(edgeSchemaList.size() == 2);
+ assertEquals(2, edgeSchemaList.size());
for (EdgeSchema es : edgeSchemaList) {
System.out.println(es.toString());
if (es.getName().equals("tosca.relationships.Uses")) {
- assertTrue(es.getSource().equals("tosca.nodes.LoadBalancer"));
- assertTrue(es.getTarget().equals("tosca.nodes.Database"));
- assertTrue(es.getMultiplicity().equals(EdgeSchema.Multiplicity.MANY_2_MANY));
+ assertEquals("tosca.nodes.LoadBalancer", es.getSource());
+ assertEquals("tosca.nodes.Database", es.getTarget());
+ assertEquals(es.getMultiplicity(), EdgeSchema.Multiplicity.MANY_2_MANY);
}
else if (es.getName().equals("tosca.relationships.RoutesTo")) {
- assertTrue(es.getSource().equals("tosca.nodes.LoadBalancer"));
- assertTrue(es.getTarget().equals("tosca.nodes.Database"));
- assertTrue(es.getMultiplicity().equals(EdgeSchema.Multiplicity.MANY_2_MANY));
+ assertEquals("tosca.nodes.LoadBalancer", es.getSource());
+ assertEquals("tosca.nodes.Database", es.getTarget());
+ assertEquals(es.getMultiplicity(), EdgeSchema.Multiplicity.MANY_2_MANY);
}
else {
- assertTrue(false);
+ fail();
}
}
}
@@ -293,8 +323,8 @@ public class JsonSchemaProviderTest {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
- System.out.println(writer.toString());
- assertTrue(false);
+ System.out.println(writer);
+ fail();
}
}
@@ -305,81 +335,81 @@ public class JsonSchemaProviderTest {
JsonSchemaProvider schemaProvider = new JsonSchemaProvider(config);
schemaProvider.loadSchema(testSchema, schemaProvider.getLatestSchemaVersion());
- EdgeSchema edgeSchema =
- schemaProvider.getEdgeSchema("amdocs.linkedTo", "service-instance",
+ EdgeSchema edgeSchema =
+ schemaProvider.getEdgeSchema("amdocs.linkedTo", "service-instance",
"onap.nodes.sdwan.ManagementDomain", schemaProvider.getLatestSchemaVersion());
- assertTrue(edgeSchema.getName().equals("amdocs.linkedTo"));
- assertTrue(edgeSchema.getSource().equals("service-instance"));
- assertTrue(edgeSchema.getTarget().equals("onap.nodes.sdwan.ManagementDomain"));
+ assertEquals("amdocs.linkedTo", edgeSchema.getName());
+ assertEquals("service-instance", edgeSchema.getSource());
+ assertEquals("onap.nodes.sdwan.ManagementDomain", edgeSchema.getTarget());
- edgeSchema = schemaProvider.getEdgeSchema("amdocs.linkedTo", "onap.nodes.sdwan.ManagementDomain",
+ edgeSchema = schemaProvider.getEdgeSchema("amdocs.linkedTo", "onap.nodes.sdwan.ManagementDomain",
"service-instance", schemaProvider.getLatestSchemaVersion());
- assertTrue(edgeSchema == null);
-
-
- edgeSchema =
- schemaProvider.getEdgeSchema("amdocs.unknownRelationship", "unknown",
+ assertNull(edgeSchema);
+
+
+ edgeSchema =
+ schemaProvider.getEdgeSchema("amdocs.unknownRelationship", "unknown",
"onap.nodes.sdwan.ManagementDomain", schemaProvider.getLatestSchemaVersion());
-
- assertTrue(edgeSchema.getName().equals("amdocs.unknownRelationship"));
- assertTrue(edgeSchema.getSource().equals("unknown"));
- assertTrue(edgeSchema.getTarget().equals("onap.nodes.sdwan.ManagementDomain"));
-
- edgeSchema =
- schemaProvider.getEdgeSchema("amdocs.unknownRelationship", "onap.nodes.sdwan.ManagementDomain",
+
+ assertEquals("amdocs.unknownRelationship", edgeSchema.getName());
+ assertEquals("unknown", edgeSchema.getSource());
+ assertEquals("onap.nodes.sdwan.ManagementDomain", edgeSchema.getTarget());
+
+ edgeSchema =
+ schemaProvider.getEdgeSchema("amdocs.unknownRelationship", "onap.nodes.sdwan.ManagementDomain",
"unknown", schemaProvider.getLatestSchemaVersion());
-
- assertTrue(edgeSchema.getName().equals("amdocs.unknownRelationship"));
- assertTrue(edgeSchema.getSource().equals("onap.nodes.sdwan.ManagementDomain"));
- assertTrue(edgeSchema.getTarget().equals("unknown"));
-
- Set<EdgeSchema> edgeSchemaList =
- schemaProvider.getEdgeSchemaForSourceTarget("service-instance",
- "onap.nodes.sdwan.ManagementDomain",
+
+ assertEquals("amdocs.unknownRelationship", edgeSchema.getName());
+ assertEquals("onap.nodes.sdwan.ManagementDomain", edgeSchema.getSource());
+ assertEquals("unknown", edgeSchema.getTarget());
+
+ Set<EdgeSchema> edgeSchemaList =
+ schemaProvider.getEdgeSchemaForSourceTarget("service-instance",
+ "onap.nodes.sdwan.ManagementDomain",
schemaProvider.getLatestSchemaVersion());
- assertTrue(edgeSchemaList.size() == 1);
-
- edgeSchemaList = schemaProvider.getEdgeSchemaForSourceTarget("unknown", "unknown",
+ assertEquals(1, edgeSchemaList.size());
+
+ edgeSchemaList = schemaProvider.getEdgeSchemaForSourceTarget("unknown", "unknown",
schemaProvider.getLatestSchemaVersion());
- assertTrue(edgeSchemaList.size() == 1);
-
- edgeSchemaList = schemaProvider.getEdgeSchemaForSourceTarget("service-instance", "service-instance",
+ assertEquals(1, edgeSchemaList.size());
+
+ edgeSchemaList = schemaProvider.getEdgeSchemaForSourceTarget("service-instance", "service-instance",
schemaProvider.getLatestSchemaVersion());
- assertTrue(edgeSchemaList.size() == 1);
-
-
+ assertEquals(1, edgeSchemaList.size());
+
+
edgeSchemaList = schemaProvider.getAdjacentEdgeSchema("service-instance", schemaProvider.getLatestSchemaVersion());
System.out.println("EDGE LIST: \n\n" + edgeSchemaList);
- assertTrue(edgeSchemaList.size() == 8);
+ assertEquals(8, edgeSchemaList.size());
}
catch (Exception ex) {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
- System.out.println(writer.toString());
- assertTrue(false);
+ System.out.println(writer);
+ fail();
}
}
-
+
@Test
- public void testInvalidVertexOrEdge() throws SchemaProviderException {
+ public void testInvalidVertexOrEdge() {
try {
String testSchema = readFile("src/test/resources/json/jsonSchema.json");
JsonSchemaProvider schemaProvider = new JsonSchemaProvider(config);
schemaProvider.loadSchema(testSchema, schemaProvider.getLatestSchemaVersion());
- VertexSchema vertSchema =
+ VertexSchema vertSchema =
schemaProvider.getVertexSchema("bad-node", schemaProvider.getLatestSchemaVersion());
- assertTrue(vertSchema == null);
+ assertNull(vertSchema);
- EdgeSchema edgeSchema = schemaProvider.getEdgeSchema("org.onap.relationships.inventory.LocatedIn",
+ EdgeSchema edgeSchema = schemaProvider.getEdgeSchema("org.onap.relationships.inventory.LocatedIn",
"cloud-region", "bad-node", schemaProvider.getLatestSchemaVersion());
- assertTrue(edgeSchema == null);
+ assertNull(edgeSchema);
- Set<EdgeSchema> edgeSchemaList =
- schemaProvider.getAdjacentEdgeSchema("org.onap.nodes.bad-node",
+ Set<EdgeSchema> edgeSchemaList =
+ schemaProvider.getAdjacentEdgeSchema("org.onap.nodes.bad-node",
schemaProvider.getLatestSchemaVersion());
assertTrue(edgeSchemaList.isEmpty());
}
@@ -387,8 +417,8 @@ public class JsonSchemaProviderTest {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
- System.out.println(writer.toString());
- assertTrue(false);
+ System.out.println(writer);
+ fail();
}
}
@@ -399,23 +429,23 @@ public class JsonSchemaProviderTest {
JsonSchemaProvider schemaProvider = new JsonSchemaProvider(config);
schemaProvider.loadSchema(testSchema, schemaProvider.getLatestSchemaVersion());
- VertexSchema vertSchema =
- schemaProvider.getVertexSchema("onap.nodes.sdwan.ManagementDomain",
+ VertexSchema vertSchema =
+ schemaProvider.getVertexSchema("onap.nodes.sdwan.ManagementDomain",
schemaProvider.getLatestSchemaVersion());
System.out.println(vertSchema.toString());
- // Validate schema
+ // Validate schema
PropertySchema propSchema = vertSchema.getPropertySchema("controllers");
- assertTrue(propSchema.getDataType().getType().compareTo(Type.LIST) == 0);
+ assertEquals(0, propSchema.getDataType().getType().compareTo(Type.LIST));
ListDataType listType = (ListDataType)propSchema.getDataType();
- assertTrue(listType.getListType().getType().compareTo(Type.STRING) == 0);
+ assertEquals(0, listType.getListType().getType().compareTo(Type.STRING));
}
catch (Exception ex) {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
- System.out.println(writer.toString());
- assertTrue(false);
+ System.out.println(writer);
+ fail();
}
}
@@ -426,26 +456,26 @@ public class JsonSchemaProviderTest {
JsonSchemaProvider schemaProvider = new JsonSchemaProvider(config);
schemaProvider.loadSchema(testSchema, schemaProvider.getLatestSchemaVersion());
- VertexSchema vertSchema =
- schemaProvider.getVertexSchema("onap.nodes.sdwan.ManagementDomain",
+ VertexSchema vertSchema =
+ schemaProvider.getVertexSchema("onap.nodes.sdwan.ManagementDomain",
schemaProvider.getLatestSchemaVersion());
System.out.println(vertSchema.toString());
- // Validate schema
+ // Validate schema
PropertySchema propSchema = vertSchema.getPropertySchema("analyticClusters");
- assertTrue(propSchema.getDataType().getType().compareTo(Type.MAP) == 0);
+ assertEquals(0, propSchema.getDataType().getType().compareTo(Type.MAP));
MapDataType mapType = (MapDataType)propSchema.getDataType();
- assertTrue(mapType.getMapType().getType().compareTo(Type.STRING) == 0);
+ assertEquals(0, mapType.getMapType().getType().compareTo(Type.STRING));
}
catch (Exception ex) {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
- System.out.println(writer.toString());
- assertTrue(false);
+ System.out.println(writer);
+ fail();
}
}
-
+
@Test
public void testJsonSchemaComplexAttribute() {
try {
@@ -453,21 +483,21 @@ public class JsonSchemaProviderTest {
JsonSchemaProvider schemaProvider = new JsonSchemaProvider(config);
schemaProvider.loadSchema(testSchema, schemaProvider.getLatestSchemaVersion());
- VertexSchema vertSchema =
- schemaProvider.getVertexSchema("org.onap.resource.extContrailCP",
+ VertexSchema vertSchema =
+ schemaProvider.getVertexSchema("org.onap.resource.extContrailCP",
schemaProvider.getLatestSchemaVersion());
System.out.println(vertSchema.toString());
System.out.println("\n\nSize: " + vertSchema.getPropertySchemaList().size());
System.out.println(vertSchema.getPropertySchemaList());
- assertTrue(vertSchema.getPropertySchemaList().size() == 22);
+ assertEquals(22, vertSchema.getPropertySchemaList().size());
- // Validate property schema
+ // Validate property schema
PropertySchema propSchema = vertSchema.getPropertySchema("exCP_naming");
- assertTrue(propSchema.getDataType().getType().compareTo(Type.COMPLEX) == 0);
+ assertEquals(0, propSchema.getDataType().getType().compareTo(Type.COMPLEX));
ComplexDataType complexType = (ComplexDataType)propSchema.getDataType();
List<PropertySchema> complexProps = complexType.getSubProperties();
- assertTrue(complexProps.size() == 4);
+ assertEquals(4, complexProps.size());
PropertySchema subProp = null;
for (PropertySchema p : complexProps) {
@@ -476,15 +506,16 @@ public class JsonSchemaProviderTest {
}
}
- assertTrue(!subProp.isRequired());
- assertTrue(subProp.getDataType().getType().compareTo(Type.STRING) == 0);
+ assertNotNull(subProp);
+ assertFalse(subProp.isRequired());
+ assertEquals(0, subProp.getDataType().getType().compareTo(Type.STRING));
}
catch (Exception ex) {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
- System.out.println(writer.toString());
- assertTrue(false);
+ System.out.println(writer);
+ fail();
}
}
@@ -495,22 +526,22 @@ public class JsonSchemaProviderTest {
SchemaServiceResponse resp = SchemaServiceResponse.fromJson(testSchema);
System.out.println(resp.toJson());
- assertTrue(resp.getVersion().equals("v1"));
+ assertEquals("v1", resp.getVersion());
JsonSchema jsonSchema = resp.getData();
System.out.println(jsonSchema.toJson());
- assertTrue(jsonSchema.getDataTypes().size() == 1);
+ assertEquals(1, jsonSchema.getDataTypes().size());
}
catch (Exception ex) {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
- System.out.println(writer.toString());
- assertTrue(false);
+ System.out.println(writer);
+ fail();
}
}
-
+
@Test
public void testSchemaValidateSuccess() {
try {
@@ -522,75 +553,75 @@ public class JsonSchemaProviderTest {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
- System.out.println(writer.toString());
- assertTrue(false);
+ System.out.println(writer);
+ fail();
}
- }
+ }
@Test(expected = SchemaProviderException.class)
public void testSchemaValidateBadEdge() throws SchemaProviderException {
- SchemaServiceResponse schema;
+ SchemaServiceResponse schema;
try {
String testSchema = readFile("src/test/resources/json/badEdgeSchema.json");
schema = SchemaServiceResponse.fromJson(testSchema);
}
catch (Exception ex) {
- assertTrue(false);
+ fail();
return;
}
schema.getData().validate();
}
-
+
@Test(expected = SchemaProviderException.class)
public void testSchemaValidateBadVertex() throws SchemaProviderException {
- SchemaServiceResponse schema;
+ SchemaServiceResponse schema;
try {
String testSchema = readFile("src/test/resources/json/badVertexSchema.json");
schema = SchemaServiceResponse.fromJson(testSchema);
}
catch (Exception ex) {
- assertTrue(false);
+ fail();
return;
}
System.out.println("Validate");
- schema.getData().validate();
+ schema.getData().validate();
System.out.println("Validate done");
}
-
+
@Test(expected = SchemaProviderException.class)
public void testSchemaValidateBadType() throws SchemaProviderException {
- SchemaServiceResponse schema;
+ SchemaServiceResponse schema;
try {
String testSchema = readFile("src/test/resources/json/badTypeSchema.json");
schema = SchemaServiceResponse.fromJson(testSchema);
}
catch (Exception ex) {
- assertTrue(false);
+ fail();
return;
}
- schema.getData().validate();
+ schema.getData().validate();
}
-
+
@Test(expected = SchemaProviderException.class)
public void testSchemaValidateBadProp() throws SchemaProviderException {
- SchemaServiceResponse schema;
+ SchemaServiceResponse schema;
try {
String testSchema = readFile("src/test/resources/json/badPropSchema.json");
schema = SchemaServiceResponse.fromJson(testSchema);
}
catch (Exception ex) {
- assertTrue(false);
+ fail();
return;
}
- schema.getData().validate();
+ schema.getData().validate();
}
static String readFile(String path) throws IOException {
diff --git a/aai-schema-abstraction/src/test/java/org/onap/aai/schemaif/oxm/OxmSchemaServiceSetup.java b/aai-schema-abstraction/src/test/java/org/onap/aai/schemaif/oxm/OxmSchemaServiceSetup.java
index b4c1ca2e..b0b76a21 100644
--- a/aai-schema-abstraction/src/test/java/org/onap/aai/schemaif/oxm/OxmSchemaServiceSetup.java
+++ b/aai-schema-abstraction/src/test/java/org/onap/aai/schemaif/oxm/OxmSchemaServiceSetup.java
@@ -27,8 +27,10 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Before;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
import org.onap.aai.edges.EdgeIngestor;
import org.onap.aai.nodes.NodeIngestor;
import org.onap.aai.setup.AAIConfigTranslator;
@@ -37,6 +39,7 @@ import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaConfigVersions;
import org.onap.aai.setup.Translator;
+@RunWith(MockitoJUnitRunner.class)
public class OxmSchemaServiceSetup {
@Mock
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeIngestor.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeIngestor.java
index 002ec1ee..207f7e0a 100644
--- a/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeIngestor.java
+++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeIngestor.java
@@ -239,8 +239,9 @@ public class EdgeIngestor {
public Multimap<String, EdgeRule> getRules(EdgeRuleQuery q) throws EdgeRuleNotFoundException {
Multimap<String, EdgeRule> found = null;
- if (q.getVersion().isPresent()) {
- found = extractRules(q.getFilter(), q.getVersion().get());
+ Optional<SchemaVersion> versionOpt = q.getVersion();
+ if (versionOpt.isPresent()) {
+ found = extractRules(q.getFilter(), versionOpt.get());
} else {
found = extractRules(q.getFilter(), schemaVersions.getDefaultVersion());
}
@@ -287,8 +288,9 @@ public class EdgeIngestor {
*/
public EdgeRule getRule(EdgeRuleQuery q) throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
Multimap<String, EdgeRule> found = null;
- if (q.getVersion().isPresent()) {
- found = extractRules(q.getFilter(), q.getVersion().get());
+ Optional<SchemaVersion> versionOpt = q.getVersion();
+ if (versionOpt.isPresent()) {
+ found = extractRules(q.getFilter(), versionOpt.get());
} else {
found = extractRules(q.getFilter(), schemaVersions.getDefaultVersion());
}
@@ -361,8 +363,9 @@ public class EdgeIngestor {
* @return boolean
*/
public boolean hasRule(EdgeRuleQuery q) {
- if (q.getVersion().isPresent()) {
- return !extractRules(q.getFilter(), q.getVersion().get()).isEmpty();
+ Optional<SchemaVersion> versionOpt = q.getVersion();
+ if (versionOpt.isPresent()) {
+ return !extractRules(q.getFilter(), versionOpt.get()).isEmpty();
} else {
return !extractRules(q.getFilter(), schemaVersions.getDefaultVersion()).isEmpty();
}
@@ -418,7 +421,7 @@ public class EdgeIngestor {
/**
* Returns if the given node type has any cousin relationships in the current version.
- *
+ *
* @param nodeType
* @return boolean
*/
@@ -428,7 +431,7 @@ public class EdgeIngestor {
/**
* Returns if the given node type has any cousin relationships in the given version.
- *
+ *
* @param nodeType
* @return boolean
*/
@@ -479,7 +482,7 @@ public class EdgeIngestor {
/**
* Returns if the given node type has any child relationships (ie it contains another node type) in the current
* version.
- *
+ *
* @param nodeType
* @return boolean
*/
@@ -490,7 +493,7 @@ public class EdgeIngestor {
/**
* Returns if the given node type has any child relationships (ie it contains another node type) in the given
* version.
- *
+ *
* @param nodeType
* @return boolean
*/
@@ -541,7 +544,7 @@ public class EdgeIngestor {
/**
* Returns if the given node type has any parent relationships (ie it is contained by another node type) in the
* current version.
- *
+ *
* @param nodeType
* @return boolean
*/
@@ -552,7 +555,7 @@ public class EdgeIngestor {
/**
* Returns if the given node type has any parent relationships (ie it is contained by another node type) in the
* given version.
- *
+ *
* @param nodeType
* @return boolean
*/
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/nodes/NodeIngestor.java b/aai-schema-ingest/src/main/java/org/onap/aai/nodes/NodeIngestor.java
index 139eb625..014a4442 100644
--- a/aai-schema-ingest/src/main/java/org/onap/aai/nodes/NodeIngestor.java
+++ b/aai-schema-ingest/src/main/java/org/onap/aai/nodes/NodeIngestor.java
@@ -22,23 +22,24 @@
package org.onap.aai.nodes;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.CaseFormat;
-
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.nio.charset.StandardCharsets;
-import java.util.*;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import javax.annotation.PostConstruct;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-
import org.eclipse.persistence.jaxb.JAXBContextProperties;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory;
@@ -46,6 +47,8 @@ import org.onap.aai.setup.ConfigTranslator;
import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaVersions;
import org.onap.aai.setup.Translator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
@@ -76,7 +79,7 @@ public class NodeIngestor {
/**
* Instantiates the NodeIngestor bean.
- *
+ *
* @param translatorSet
*/
@@ -158,6 +161,8 @@ public class NodeIngestor {
throws ParserConfigurationException, IOException, SAXException {
Set<String> types = new HashSet<>();
final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
+ docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+ docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
@@ -191,6 +196,8 @@ public class NodeIngestor {
InputStream inputStream = inputStreams.get(0);
inputStream.reset();
final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
+ docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+ docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
DocumentBuilder masterDocBuilder = docFactory.newDocumentBuilder();
return masterDocBuilder.parse(inputStream);
@@ -199,6 +206,8 @@ public class NodeIngestor {
private Document createCombinedSchema(List<InputStream> inputStreams, SchemaVersion version)
throws ParserConfigurationException, SAXException, IOException {
final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
+ docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+ docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
DocumentBuilder masterDocBuilder = docFactory.newDocumentBuilder();
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java
index 4ee93fad..10f1f542 100644
--- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java
+++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java
@@ -20,15 +20,15 @@
package org.onap.aai.setup;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.onap.aai.restclient.RestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-import java.io.*;
-import java.util.*;
-
-import javax.ws.rs.HttpMethod;
-
-import org.onap.aai.restclient.RestClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
@@ -82,7 +82,10 @@ public class SchemaServiceTranslator extends Translator {
ResponseEntity<Resource> schemaResponse = restClient.getGetResource(content, uri, headersMap);
verifySchemaServiceResponse(schemaResponse.getStatusCode());
LOGGER.debug("SchemaResponse Status code" + schemaResponse.getStatusCode());
- inputStreams.add(schemaResponse.getBody().getInputStream());
+ Resource resultBody = schemaResponse.getBody();
+ if (resultBody != null) {
+ inputStreams.add(resultBody.getInputStream());
+ }
return inputStreams;
}
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DefaultDuplicateNodeDefinitionValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DefaultDuplicateNodeDefinitionValidationModule.java
index 024525b9..6181c52d 100644
--- a/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DefaultDuplicateNodeDefinitionValidationModule.java
+++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DefaultDuplicateNodeDefinitionValidationModule.java
@@ -1,4 +1,4 @@
-/**
+/**
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
@@ -43,7 +43,7 @@ import org.xml.sax.SAXException;
* Default duplicate rules for A&AI -
* node types may never have a duplicate definition
* within the same Version's file set.
- *
+ *
* Finds all duplicates and what files they're in.
*
*/
@@ -51,13 +51,15 @@ public class DefaultDuplicateNodeDefinitionValidationModule implements Duplicate
/*
* (non-Javadoc)
- *
+ *
* @see org.onap.aai.nodes.validation.DuplicateNodeDefinitionValidationModule#findDuplicates(java.util.List)
*/
@Override
public String findDuplicates(List<String> files, SchemaVersion v) {
try {
final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
+ docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+ docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();