summaryrefslogtreecommitdiffstats
path: root/aai-core
diff options
context:
space:
mode:
Diffstat (limited to 'aai-core')
-rw-r--r--aai-core/pom.xml23
-rw-r--r--aai-core/src/main/java/org/onap/aai/auth/AAIUser.java84
-rw-r--r--aai-core/src/main/java/org/onap/aai/auth/exceptions/AAIUnrecognizedFunctionException.java25
-rw-r--r--aai-core/src/main/java/org/onap/aai/config/IntrospectionConfig.java35
-rw-r--r--aai-core/src/main/java/org/onap/aai/config/RestBeanConfig.java31
-rw-r--r--aai-core/src/main/java/org/onap/aai/config/SchemaConfiguration.java26
-rw-r--r--aai-core/src/main/java/org/onap/aai/config/SwaggerGenerationConfiguration.java43
-rw-r--r--aai-core/src/main/java/org/onap/aai/db/props/AAIProperties.java30
-rw-r--r--aai-core/src/main/java/org/onap/aai/dbmap/AAIGraph.java299
-rw-r--r--aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java164
-rw-r--r--aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java26
-rw-r--r--aai-core/src/main/java/org/onap/aai/domain/responseMessage/AAIResponseMessageData.java58
-rw-r--r--aai-core/src/main/java/org/onap/aai/exceptions/AAIException.java234
-rw-r--r--aai-core/src/main/java/org/onap/aai/query/builder/GremlinQueryBuilder.java1420
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/AAIConstants.java155
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/AAIUtils.java51
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/AutoGenerateHtml.java77
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/MapperUtil.java48
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/MapperUtilTest.java85
19 files changed, 1495 insertions, 1419 deletions
diff --git a/aai-core/pom.xml b/aai-core/pom.xml
index 4715bcf6..6ba76996 100644
--- a/aai-core/pom.xml
+++ b/aai-core/pom.xml
@@ -45,10 +45,11 @@
<eelf.core.version>1.0.0</eelf.core.version>
<logback.version>1.2.3</logback.version>
<freemarker.version>2.3.21</freemarker.version>
- <activemq.version>5.15.3</activemq.version>
+ <activemq.version>5.15.6</activemq.version>
<jacoco.line.coverage.limit>0.50</jacoco.line.coverage.limit>
<gremlin.version>3.2.2</gremlin.version>
- <jetty.version>9.4.6.v20170531</jetty.version>
+ <groovy.version>2.4.15</groovy.version>
+ <jetty.version>9.4.11.v20180605</jetty.version>
<!-- Start of Default ONAP Schema Properties -->
<aai.wiki.link>https://wiki.onap.org/</aai.wiki.link>
@@ -781,6 +782,10 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
@@ -796,12 +801,12 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
- <version>4.3.6.RELEASE</version>
+ <version>4.3.18.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
- <version>4.3.6.RELEASE</version>
+ <version>4.3.18.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
@@ -943,10 +948,16 @@
<artifactId>json-patch</artifactId>
<version>1.9</version>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy</artifactId>
+ <version>${groovy.version}</version>
+ <classifier>indy</classifier>
+ </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
- <version>4.3.16.RELEASE</version>
+ <version>4.3.18.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -980,7 +991,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
- <version>4.3.16.RELEASE</version>
+ <version>4.3.18.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
diff --git a/aai-core/src/main/java/org/onap/aai/auth/AAIUser.java b/aai-core/src/main/java/org/onap/aai/auth/AAIUser.java
index d0f7456e..499c6858 100644
--- a/aai-core/src/main/java/org/onap/aai/auth/AAIUser.java
+++ b/aai-core/src/main/java/org/onap/aai/auth/AAIUser.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -23,56 +25,56 @@ import java.util.*;
public class AAIUser {
- private String username;
+ private String username;
- private boolean isWildcard = false;
- private Set<String> roles;
- private Map<String, Set<String>> aaiFunctionToHttpMethod;
+ private boolean isWildcard = false;
+ private Set<String> roles;
+ private Map<String, Set<String>> aaiFunctionToHttpMethod;
- public AAIUser(String username) {
- this(username, false);
- }
+ public AAIUser(String username) {
+ this(username, false);
+ }
- public AAIUser(String username, boolean isWildcard) {
- this.username = username;
- this.roles = new HashSet<>();
- this.aaiFunctionToHttpMethod = new HashMap<>();
- this.isWildcard = isWildcard;
- }
+ public AAIUser(String username, boolean isWildcard) {
+ this.username = username;
+ this.roles = new HashSet<>();
+ this.aaiFunctionToHttpMethod = new HashMap<>();
+ this.isWildcard = isWildcard;
+ }
- public boolean isWildcard() {
- return isWildcard;
- }
+ public boolean isWildcard() {
+ return isWildcard;
+ }
- public String getUsername() {
- return username;
- }
+ public String getUsername() {
+ return username;
+ }
- public void addRole(String role) {
- this.roles.add(role);
- }
+ public void addRole(String role) {
+ this.roles.add(role);
+ }
- public boolean hasRole(String role) {
- return this.roles.contains(role);
- }
+ public boolean hasRole(String role) {
+ return this.roles.contains(role);
+ }
- public void setUserAccess(String aaiMethod, String... httpMethods) {
- for (String httpMethod : httpMethods) {
- this.addUserAccess(aaiMethod, httpMethod);
- }
- }
+ public void setUserAccess(String aaiMethod, String... httpMethods) {
+ for (String httpMethod : httpMethods) {
+ this.addUserAccess(aaiMethod, httpMethod);
+ }
+ }
- private void addUserAccess(String aaiMethod, String httpMethod) {
- Set<String> httpMethods = new HashSet<>();
- if (this.aaiFunctionToHttpMethod.containsKey(aaiMethod)) {
- httpMethods = this.aaiFunctionToHttpMethod.get(aaiMethod);
- }
- httpMethods.add(httpMethod);
- this.aaiFunctionToHttpMethod.put(aaiMethod, httpMethods);
- }
+ private void addUserAccess(String aaiMethod, String httpMethod) {
+ Set<String> httpMethods = new HashSet<>();
+ if (this.aaiFunctionToHttpMethod.containsKey(aaiMethod)) {
+ httpMethods = this.aaiFunctionToHttpMethod.get(aaiMethod);
+ }
+ httpMethods.add(httpMethod);
+ this.aaiFunctionToHttpMethod.put(aaiMethod, httpMethods);
+ }
- public boolean hasAccess(String aaiMethod, String httpMethod) {
- return this.aaiFunctionToHttpMethod.getOrDefault(aaiMethod, Collections.EMPTY_SET).contains(httpMethod);
- }
+ public boolean hasAccess(String aaiMethod, String httpMethod) {
+ return this.aaiFunctionToHttpMethod.getOrDefault(aaiMethod, Collections.emptySet()).contains(httpMethod);
+ }
}
diff --git a/aai-core/src/main/java/org/onap/aai/auth/exceptions/AAIUnrecognizedFunctionException.java b/aai-core/src/main/java/org/onap/aai/auth/exceptions/AAIUnrecognizedFunctionException.java
index c77fbfe9..01be1c27 100644
--- a/aai-core/src/main/java/org/onap/aai/auth/exceptions/AAIUnrecognizedFunctionException.java
+++ b/aai-core/src/main/java/org/onap/aai/auth/exceptions/AAIUnrecognizedFunctionException.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -23,19 +25,20 @@ import org.onap.aai.exceptions.AAIException;
public class AAIUnrecognizedFunctionException extends AAIException {
- private static final long serialVersionUID = 3297064867724071290L;
+ private static final String AAI_3012 = "AAI_3012";
+ private static final long serialVersionUID = 3297064867724071290L;
- public AAIUnrecognizedFunctionException() {}
+ public AAIUnrecognizedFunctionException() {}
- public AAIUnrecognizedFunctionException(String message) {
- super("AAI_3012", message);
- }
+ public AAIUnrecognizedFunctionException(String message) {
+ super(AAI_3012, message);
+ }
- public AAIUnrecognizedFunctionException(Throwable cause) {
- super("AAI_3012",cause);
- }
+ public AAIUnrecognizedFunctionException(Throwable cause) {
+ super(AAI_3012,cause);
+ }
- public AAIUnrecognizedFunctionException(String message, Throwable cause) {
- super("AAI_3012", cause, message);
- }
+ public AAIUnrecognizedFunctionException(String message, Throwable cause) {
+ super(AAI_3012, cause, message);
+ }
}
diff --git a/aai-core/src/main/java/org/onap/aai/config/IntrospectionConfig.java b/aai-core/src/main/java/org/onap/aai/config/IntrospectionConfig.java
index e0ce203d..aa4ec1a1 100644
--- a/aai-core/src/main/java/org/onap/aai/config/IntrospectionConfig.java
+++ b/aai-core/src/main/java/org/onap/aai/config/IntrospectionConfig.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -35,23 +37,22 @@ import org.onap.aai.nodes.NodeIngestor;
@Configuration
public class IntrospectionConfig {
- private Map<SchemaVersion, MoxyLoader> MOXYINSTANCEMAP = new ConcurrentHashMap<>();
- @Autowired
- NodeIngestor nodeIngestor;
+ private Map<SchemaVersion, MoxyLoader> moxyInstanceMap = new ConcurrentHashMap<>();
+ @Autowired
+ NodeIngestor nodeIngestor;
- @Bean
- public LoaderFactory loaderFactory(SchemaVersions schemaVersions) {
- LoaderFactory loaderFactory = new LoaderFactory(moxyLoaderInstance(schemaVersions));
- return loaderFactory;
- }
+ @Bean
+ public LoaderFactory loaderFactory(SchemaVersions schemaVersions) {
+ return new LoaderFactory(moxyLoaderInstance(schemaVersions));
+ }
- @Bean
- public Map<SchemaVersion, MoxyLoader> moxyLoaderInstance(SchemaVersions schemaVersions) {
- for(SchemaVersion version : schemaVersions.getVersions()){
- if (!MOXYINSTANCEMAP.containsKey(version)) {
- MOXYINSTANCEMAP.put(version, new MoxyLoader(version, nodeIngestor));
- }
- }
- return MOXYINSTANCEMAP;
- }
+ @Bean
+ public Map<SchemaVersion, MoxyLoader> moxyLoaderInstance(SchemaVersions schemaVersions) {
+ for(SchemaVersion version : schemaVersions.getVersions()){
+ if (!moxyInstanceMap.containsKey(version)) {
+ moxyInstanceMap.put(version, new MoxyLoader(version, nodeIngestor));
+ }
+ }
+ return moxyInstanceMap;
+ }
}
diff --git a/aai-core/src/main/java/org/onap/aai/config/RestBeanConfig.java b/aai-core/src/main/java/org/onap/aai/config/RestBeanConfig.java
index 29763291..6c56ff69 100644
--- a/aai-core/src/main/java/org/onap/aai/config/RestBeanConfig.java
+++ b/aai-core/src/main/java/org/onap/aai/config/RestBeanConfig.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -31,21 +33,18 @@ import org.springframework.context.annotation.Scope;
@Configuration
public class RestBeanConfig {
- @Bean(name = "traversalUriHttpEntry")
- @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
- public HttpEntry traversalUriHttpEntry() {
- HttpEntry httpEntry = new HttpEntry(ModelType.MOXY, QueryStyle.TRAVERSAL_URI);
- return httpEntry;
- }
-
- @Bean(name = "traversalHttpEntry")
- @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
- public HttpEntry traversalHttpEntry() {
- HttpEntry httpEntry = new HttpEntry(ModelType.MOXY, QueryStyle.TRAVERSAL);
-
- return httpEntry;
- }
-
-
+ @Bean(name = "traversalUriHttpEntry")
+ @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+ public HttpEntry traversalUriHttpEntry() {
+ return new HttpEntry(ModelType.MOXY, QueryStyle.TRAVERSAL_URI);
+ }
+
+ @Bean(name = "traversalHttpEntry")
+ @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+ public HttpEntry traversalHttpEntry() {
+ return new HttpEntry(ModelType.MOXY, QueryStyle.TRAVERSAL);
+ }
+
+
}
diff --git a/aai-core/src/main/java/org/onap/aai/config/SchemaConfiguration.java b/aai-core/src/main/java/org/onap/aai/config/SchemaConfiguration.java
index 20112bde..b00ecfb7 100644
--- a/aai-core/src/main/java/org/onap/aai/config/SchemaConfiguration.java
+++ b/aai-core/src/main/java/org/onap/aai/config/SchemaConfiguration.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -43,20 +45,18 @@ public class SchemaConfiguration {
return new EdgeSerializer(edgeIngestor);
}
- @Bean(name = "nodeIngestor")
- public NodeIngestor nodeIngestor(ConfigTranslator configTranslator) {
- NodeIngestor nodeIngestor = new NodeIngestor(configTranslator);
- return nodeIngestor;
- }
+ @Bean(name = "nodeIngestor")
+ public NodeIngestor nodeIngestor(ConfigTranslator configTranslator) {
+ return new NodeIngestor(configTranslator);
+ }
- @Bean(name = "configTranslator")
- public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean, SchemaVersions schemaVersions) {
- ConfigTranslator aaiConfigTranslator = new AAIConfigTranslator(schemaLocationsBean, schemaVersions);
- return aaiConfigTranslator;
- }
+ @Bean(name = "configTranslator")
+ public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean, SchemaVersions schemaVersions) {
+ return new AAIConfigTranslator(schemaLocationsBean, schemaVersions);
+ }
- @Bean
- public SchemaErrorStrategy schemaErrorStrategy(){
+ @Bean
+ public SchemaErrorStrategy schemaErrorStrategy(){
return new CheckEverythingStrategy();
- }
+ }
}
diff --git a/aai-core/src/main/java/org/onap/aai/config/SwaggerGenerationConfiguration.java b/aai-core/src/main/java/org/onap/aai/config/SwaggerGenerationConfiguration.java
index a09018ad..fbbb703a 100644
--- a/aai-core/src/main/java/org/onap/aai/config/SwaggerGenerationConfiguration.java
+++ b/aai-core/src/main/java/org/onap/aai/config/SwaggerGenerationConfiguration.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -35,28 +37,25 @@ import org.springframework.context.annotation.Scope;
@Configuration
public class SwaggerGenerationConfiguration {
- @Value("${schema.uri.base.path}")
- private String basePath;
+ @Value("${schema.uri.base.path}")
+ private String basePath;
- @Bean
- @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
- public NodesYAMLfromOXM nodesYamlFromOXM(SchemaVersions schemaVersions, NodeIngestor nodeIngestor, EdgeIngestor edgeIngestor) {
- NodesYAMLfromOXM nodesYamlFromOXM = new NodesYAMLfromOXM(basePath, schemaVersions, nodeIngestor, edgeIngestor);
- return nodesYamlFromOXM;
- }
-
- @Bean
- @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
- public HTMLfromOXM htmlFromOXM(SchemaVersions schemaVersions, NodeIngestor nodeIngestor, EdgeIngestor edgeIngestor) {
- HTMLfromOXM htmlFromOXM = new HTMLfromOXM(schemaVersions, nodeIngestor, edgeIngestor);
- return htmlFromOXM;
- }
-
- @Bean
- @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
- public YAMLfromOXM yamlFromOXM(SchemaVersions schemaVersions, NodeIngestor nodeIngestor, EdgeIngestor edgeIngestor) {
- YAMLfromOXM yamlFromOXM = new YAMLfromOXM(basePath, schemaVersions, nodeIngestor, edgeIngestor);
- return yamlFromOXM;
- }
+ @Bean
+ @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+ public NodesYAMLfromOXM nodesYamlFromOXM(SchemaVersions schemaVersions, NodeIngestor nodeIngestor, EdgeIngestor edgeIngestor) {
+ return new NodesYAMLfromOXM(basePath, schemaVersions, nodeIngestor, edgeIngestor);
+ }
+
+ @Bean
+ @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+ public HTMLfromOXM htmlFromOXM(SchemaVersions schemaVersions, NodeIngestor nodeIngestor, EdgeIngestor edgeIngestor) {
+ return new HTMLfromOXM(schemaVersions, nodeIngestor, edgeIngestor);
+ }
+
+ @Bean
+ @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+ public YAMLfromOXM yamlFromOXM(SchemaVersions schemaVersions, NodeIngestor nodeIngestor, EdgeIngestor edgeIngestor) {
+ return new YAMLfromOXM(basePath, schemaVersions, nodeIngestor, edgeIngestor);
+ }
}
diff --git a/aai-core/src/main/java/org/onap/aai/db/props/AAIProperties.java b/aai-core/src/main/java/org/onap/aai/db/props/AAIProperties.java
index 47e79a39..6b4035c6 100644
--- a/aai-core/src/main/java/org/onap/aai/db/props/AAIProperties.java
+++ b/aai-core/src/main/java/org/onap/aai/db/props/AAIProperties.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -20,17 +22,21 @@
package org.onap.aai.db.props;
public class AAIProperties {
- public static final String NODE_TYPE = "aai-node-type";
- public static final String LAST_MOD_SOURCE_OF_TRUTH = "last-mod-source-of-truth";
- public static final String SOURCE_OF_TRUTH = "source-of-truth";
- public static final String LAST_MOD_TS = "aai-last-mod-ts";
- public static final String UNIQUE_KEY = "aai-unique-key";
- public static final String CREATED_TS = "aai-created-ts";
- public static final String RESOURCE_VERSION = "resource-version";
- public static final String AAI_URI = "aai-uri";
- public static final Integer MAXIMUM_DEPTH = 10000;
- public static final String LINKED = "linked";
- public static final String DB_ALIAS_SUFFIX = "-local";
- public static final String AAI_UUID = "aai-uuid";
+ public static final String NODE_TYPE = "aai-node-type";
+ public static final String LAST_MOD_SOURCE_OF_TRUTH = "last-mod-source-of-truth";
+ public static final String SOURCE_OF_TRUTH = "source-of-truth";
+ public static final String LAST_MOD_TS = "aai-last-mod-ts";
+ public static final String UNIQUE_KEY = "aai-unique-key";
+ public static final String CREATED_TS = "aai-created-ts";
+ public static final String RESOURCE_VERSION = "resource-version";
+ public static final String AAI_URI = "aai-uri";
+ public static final Integer MAXIMUM_DEPTH = 10000;
+ public static final String LINKED = "linked";
+ public static final String DB_ALIAS_SUFFIX = "-local";
+ public static final String AAI_UUID = "aai-uuid";
+
+ private AAIProperties() {
+
+ }
}
diff --git a/aai-core/src/main/java/org/onap/aai/dbmap/AAIGraph.java b/aai-core/src/main/java/org/onap/aai/dbmap/AAIGraph.java
index aae3aaae..84218e85 100644
--- a/aai-core/src/main/java/org/onap/aai/dbmap/AAIGraph.java
+++ b/aai-core/src/main/java/org/onap/aai/dbmap/AAIGraph.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -54,151 +56,154 @@ import org.janusgraph.core.schema.JanusGraphManagement;
*/
public class AAIGraph {
- private static final EELFLogger logger = EELFManager.getInstance().getLogger(AAIGraph.class);
- protected static final String COMPONENT = "aaidbmap";
- protected Map<String, JanusGraph> graphs = new HashMap<>();
- private static final String REALTIME_DB = "realtime";
- private static final String CACHED_DB = "cached";
- private static boolean isInit = false;
-
-
-
- /**
- * Instantiates a new AAI graph.
- */
- private AAIGraph() {
- try {
- String serviceName = System.getProperty("aai.service.name", "NA");
- String rtConfig = System.getProperty("realtime.db.config");
- String cachedConfig = System.getProperty("cached.db.config");
- if (rtConfig == null) {
- rtConfig = AAIConstants.REALTIME_DB_CONFIG;
- }
- if (cachedConfig == null) {
- cachedConfig = AAIConstants.CACHED_DB_CONFIG;
- }
- this.loadGraph(REALTIME_DB, rtConfig, serviceName);
- this.loadGraph(CACHED_DB, cachedConfig, serviceName);
- } catch (Exception e) {
- throw new RuntimeException("Failed to instantiate graphs", e);
- }
- }
-
- private static class Helper {
- private static final AAIGraph INSTANCE = new AAIGraph();
- }
-
- /**
- * Gets the single instance of AAIGraph.
- *
- * @return single instance of AAIGraph
- */
- public static AAIGraph getInstance() {
- isInit = true;
- return Helper.INSTANCE;
- }
-
- public static boolean isInit() {
- return isInit;
- }
-
- private void loadGraph(String name, String configPath, String serviceName) throws Exception {
- // Graph being opened by JanusGraphFactory is being placed in hashmap to be used later
- // These graphs shouldn't be closed until the application shutdown
- try {
- PropertiesConfiguration propertiesConfiguration = new AAIGraphConfig.Builder(configPath).forService(serviceName).withGraphType(name).buildConfiguration();
- JanusGraph graph = JanusGraphFactory.open(propertiesConfiguration);
-
- Properties graphProps = new Properties();
- propertiesConfiguration.getKeys().forEachRemaining(k -> graphProps.setProperty(k, propertiesConfiguration.getString(k)));
-
- if ("inmemory".equals(graphProps.get("storage.backend"))) {
- // Load the propertyKeys, indexes and edge-Labels into the DB
- loadSchema(graph);
- loadSnapShotToInMemoryGraph(graph, graphProps);
- }
-
- if (graph == null) {
- throw new AAIException("AAI_5102");
- }
-
- graphs.put(name, graph);
- } catch (FileNotFoundException fnfe) {
- throw new AAIException("AAI_4001");
- } catch (IOException e) {
- throw new AAIException("AAI_4002");
- }
- }
-
- private void loadSnapShotToInMemoryGraph(JanusGraph graph, Properties graphProps) {
- if (logger.isDebugEnabled()) {
- logger.debug("Load Snapshot to InMemory Graph");
- }
- if (graphProps.containsKey("load.snapshot.file")) {
- String value = graphProps.getProperty("load.snapshot.file");
- if ("true".equals(value)) {
- try (Graph transaction = graph.newTransaction()) {
- String location = System.getProperty("snapshot.location");
- logAndPrint(logger, "Loading snapshot to inmemory graph.");
- transaction.io(IoCore.graphson()).readGraph(location);
- transaction.tx().commit();
- logAndPrint(logger, "Snapshot loaded to inmemory graph.");
- } catch (Exception e) {
- logAndPrint(logger,
- "ERROR: Could not load datasnapshot to in memory graph. \n"
- + ExceptionUtils.getFullStackTrace(e));
- throw new RuntimeException(e);
- }
- }
- }
- }
-
- private void loadSchema(JanusGraph graph) {
- // Load the propertyKeys, indexes and edge-Labels into the DB
- JanusGraphManagement graphMgt = graph.openManagement();
-
- System.out.println("-- loading schema into JanusGraph");
- SchemaGenerator.loadSchemaIntoJanusGraph( graph, graphMgt, "inmemory");
- }
-
- /**
- * Close all of the graph connections made in the instance.
- */
- public void graphShutdown() {
- graphs.values().stream().filter(JanusGraph::isOpen).forEach(JanusGraph::close);
- }
-
- /**
- * Gets the graph.
- *
- * @return the graph
- */
- public JanusGraph getGraph() {
- return graphs.get(REALTIME_DB);
- }
-
- public void graphShutdown(DBConnectionType connectionType) {
-
- graphs.get(this.getGraphName(connectionType)).close();
- }
-
- public JanusGraph getGraph(DBConnectionType connectionType) {
- return graphs.get(this.getGraphName(connectionType));
- }
-
- private String getGraphName(DBConnectionType connectionType) {
- String graphName = "";
- if (DBConnectionType.CACHED.equals(connectionType)) {
- graphName = this.CACHED_DB;
- } else if (DBConnectionType.REALTIME.equals(connectionType)) {
- graphName = this.REALTIME_DB;
- }
-
- return graphName;
- }
-
- private void logAndPrint(EELFLogger logger, String msg) {
- System.out.println(msg);
- logger.info(msg);
- }
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(AAIGraph.class);
+ protected static final String COMPONENT = "aaidbmap";
+ protected Map<String, JanusGraph> graphs = new HashMap<>();
+ private static final String REALTIME_DB = "realtime";
+ private static final String CACHED_DB = "cached";
+ private static boolean isInit = false;
+
+
+
+ /**
+ * Instantiates a new AAI graph.
+ */
+ private AAIGraph() {
+ try {
+ String serviceName = System.getProperty("aai.service.name", "NA");
+ String rtConfig = System.getProperty("realtime.db.config");
+ String cachedConfig = System.getProperty("cached.db.config");
+ if (rtConfig == null) {
+ rtConfig = AAIConstants.REALTIME_DB_CONFIG;
+ }
+ if (cachedConfig == null) {
+ cachedConfig = AAIConstants.CACHED_DB_CONFIG;
+ }
+ this.loadGraph(REALTIME_DB, rtConfig, serviceName);
+ this.loadGraph(CACHED_DB, cachedConfig, serviceName);
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to instantiate graphs", e);
+ }
+ }
+
+ private static class Helper {
+ private static final AAIGraph INSTANCE = new AAIGraph();
+ private Helper() {
+
+ }
+ }
+
+ /**
+ * Gets the single instance of AAIGraph.
+ *
+ * @return single instance of AAIGraph
+ */
+ public static AAIGraph getInstance() {
+ isInit = true;
+ return Helper.INSTANCE;
+ }
+
+ public static boolean isInit() {
+ return isInit;
+ }
+
+ private void loadGraph(String name, String configPath, String serviceName) throws Exception {
+ // Graph being opened by JanusGraphFactory is being placed in hashmap to be used later
+ // These graphs shouldn't be closed until the application shutdown
+ try {
+ PropertiesConfiguration propertiesConfiguration = new AAIGraphConfig.Builder(configPath).forService(serviceName).withGraphType(name).buildConfiguration();
+ JanusGraph graph = JanusGraphFactory.open(propertiesConfiguration);
+
+ Properties graphProps = new Properties();
+ propertiesConfiguration.getKeys().forEachRemaining(k -> graphProps.setProperty(k, propertiesConfiguration.getString(k)));
+
+ if ("inmemory".equals(graphProps.get("storage.backend"))) {
+ // Load the propertyKeys, indexes and edge-Labels into the DB
+ loadSchema(graph);
+ loadSnapShotToInMemoryGraph(graph, graphProps);
+ }
+
+ if (graph == null) {
+ throw new AAIException("AAI_5102");
+ }
+
+ graphs.put(name, graph);
+ } catch (FileNotFoundException fnfe) {
+ throw new AAIException("AAI_4001");
+ } catch (IOException e) {
+ throw new AAIException("AAI_4002");
+ }
+ }
+
+ private void loadSnapShotToInMemoryGraph(JanusGraph graph, Properties graphProps) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Load Snapshot to InMemory Graph");
+ }
+ if (graphProps.containsKey("load.snapshot.file")) {
+ String value = graphProps.getProperty("load.snapshot.file");
+ if ("true".equals(value)) {
+ try (Graph transaction = graph.newTransaction()) {
+ String location = System.getProperty("snapshot.location");
+ logAndPrint(logger, "Loading snapshot to inmemory graph.");
+ transaction.io(IoCore.graphson()).readGraph(location);
+ transaction.tx().commit();
+ logAndPrint(logger, "Snapshot loaded to inmemory graph.");
+ } catch (Exception e) {
+ logAndPrint(logger,
+ "ERROR: Could not load datasnapshot to in memory graph. \n"
+ + ExceptionUtils.getFullStackTrace(e));
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ }
+
+ private void loadSchema(JanusGraph graph) {
+ // Load the propertyKeys, indexes and edge-Labels into the DB
+ JanusGraphManagement graphMgt = graph.openManagement();
+
+ System.out.println("-- loading schema into JanusGraph");
+ SchemaGenerator.loadSchemaIntoJanusGraph( graph, graphMgt, "inmemory");
+ }
+
+ /**
+ * Close all of the graph connections made in the instance.
+ */
+ public void graphShutdown() {
+ graphs.values().stream().filter(JanusGraph::isOpen).forEach(JanusGraph::close);
+ }
+
+ /**
+ * Gets the graph.
+ *
+ * @return the graph
+ */
+ public JanusGraph getGraph() {
+ return graphs.get(REALTIME_DB);
+ }
+
+ public void graphShutdown(DBConnectionType connectionType) {
+
+ graphs.get(this.getGraphName(connectionType)).close();
+ }
+
+ public JanusGraph getGraph(DBConnectionType connectionType) {
+ return graphs.get(this.getGraphName(connectionType));
+ }
+
+ private String getGraphName(DBConnectionType connectionType) {
+ String graphName = "";
+ if (DBConnectionType.CACHED.equals(connectionType)) {
+ graphName = this.CACHED_DB;
+ } else if (DBConnectionType.REALTIME.equals(connectionType)) {
+ graphName = this.REALTIME_DB;
+ }
+
+ return graphName;
+ }
+
+ private void logAndPrint(EELFLogger logger, String msg) {
+ System.out.println(msg);
+ logger.info(msg);
+ }
}
diff --git a/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java b/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java
index 49cc0e90..2803f69b 100644
--- a/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java
+++ b/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -41,85 +43,87 @@ import org.springframework.web.client.RestTemplate;
public class AAIDmaapEventJMSConsumer implements MessageListener {
- private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIDmaapEventJMSConsumer.class);
-
- private RestTemplate restTemplate;
-
- private HttpHeaders httpHeaders;
-
- private Environment environment;
-
- public AAIDmaapEventJMSConsumer(Environment environment, RestTemplate restTemplate, HttpHeaders httpHeaders) {
- Objects.nonNull(environment);
- Objects.nonNull(restTemplate);
- Objects.nonNull(httpHeaders);
- this.environment = environment;
- this.restTemplate = restTemplate;
- this.httpHeaders = httpHeaders;
- }
-
- @Override
- public void onMessage(Message message) {
-
- if(restTemplate == null){
- return;
- }
-
- String jsmMessageTxt = "";
- String aaiEvent = "";
- String eventName = "";
-
- if (message instanceof TextMessage) {
- try {
- jsmMessageTxt = ((TextMessage) message).getText();
- JSONObject jo = new JSONObject(jsmMessageTxt);
-
- if (jo.has("aaiEventPayload")) {
- aaiEvent = jo.getJSONObject("aaiEventPayload").toString();
- } else {
- return;
- }
- if (jo.getString("transId") != null) {
- MDC.put("requestId", jo.getString("transId"));
- }
- if (jo.getString("fromAppId") != null) {
- MDC.put("partnerName", jo.getString("fromAppId"));
- }
- if (jo.getString("event-topic") != null) {
- eventName = jo.getString("event-topic");
- }
-
- MDC.put ("targetEntity", "DMAAP");
- if (jo.getString("event-topic") != null) {
- eventName = jo.getString("event-topic");
- MDC.put ("targetServiceName", eventName);
- }
- MDC.put ("serviceName", "AAI");
- MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.COMPLETE.toString());
- MDC.put(LoggingField.RESPONSE_CODE.toString(), "0");
- LOGGER.info(eventName + "|" + aaiEvent);
- HttpEntity httpEntity = new HttpEntity(aaiEvent, httpHeaders);
-
- String transportType = environment.getProperty("dmaap.ribbon.transportType", "http");
- String baseUrl = transportType + "://" + environment.getProperty("dmaap.ribbon.listOfServers");
- String endpoint = "/events/" + eventName;
-
- if ("AAI-EVENT".equals(eventName)) {
+ private static final String EVENT_TOPIC = "event-topic";
+
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIDmaapEventJMSConsumer.class);
+
+ private RestTemplate restTemplate;
+
+ private HttpHeaders httpHeaders;
+
+ private Environment environment;
+
+ public AAIDmaapEventJMSConsumer(Environment environment, RestTemplate restTemplate, HttpHeaders httpHeaders) {
+ Objects.nonNull(environment);
+ Objects.nonNull(restTemplate);
+ Objects.nonNull(httpHeaders);
+ this.environment = environment;
+ this.restTemplate = restTemplate;
+ this.httpHeaders = httpHeaders;
+ }
+
+ @Override
+ public void onMessage(Message message) {
+
+ if(restTemplate == null){
+ return;
+ }
+
+ String jsmMessageTxt = "";
+ String aaiEvent = "";
+ String eventName = "";
+
+ if (message instanceof TextMessage) {
+ try {
+ jsmMessageTxt = ((TextMessage) message).getText();
+ JSONObject jo = new JSONObject(jsmMessageTxt);
+
+ if (jo.has("aaiEventPayload")) {
+ aaiEvent = jo.getJSONObject("aaiEventPayload").toString();
+ } else {
+ return;
+ }
+ if (jo.getString("transId") != null) {
+ MDC.put("requestId", jo.getString("transId"));
+ }
+ if (jo.getString("fromAppId") != null) {
+ MDC.put("partnerName", jo.getString("fromAppId"));
+ }
+ if (jo.getString(EVENT_TOPIC) != null) {
+ eventName = jo.getString(EVENT_TOPIC);
+ }
+
+ MDC.put ("targetEntity", "DMAAP");
+ if (jo.getString(EVENT_TOPIC) != null) {
+ eventName = jo.getString(EVENT_TOPIC);
+ MDC.put ("targetServiceName", eventName);
+ }
+ MDC.put ("serviceName", "AAI");
+ MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.COMPLETE.toString());
+ MDC.put(LoggingField.RESPONSE_CODE.toString(), "0");
+ LOGGER.info(eventName + "|" + aaiEvent);
+ HttpEntity httpEntity = new HttpEntity(aaiEvent, httpHeaders);
+
+ String transportType = environment.getProperty("dmaap.ribbon.transportType", "http");
+ String baseUrl = transportType + "://" + environment.getProperty("dmaap.ribbon.listOfServers");
+ String endpoint = "/events/" + eventName;
+
+ if ("AAI-EVENT".equals(eventName)) {
restTemplate.exchange(baseUrl + endpoint, HttpMethod.POST, httpEntity, String.class);
- } else {
- LoggingContext.statusCode(StatusCode.ERROR);
- LOGGER.error(eventName + "|Event Topic invalid.");
- }
- } catch (JMSException | JSONException e) {
- MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString());
- MDC.put(LoggingField.RESPONSE_CODE.toString(), "200");
- LOGGER.error("AAI_7350 Error parsing aaievent jsm message for sending to dmaap. {} {}", jsmMessageTxt, LogFormatTools.getStackTop(e));
- } catch (Exception e) {
- MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString());
- MDC.put(LoggingField.RESPONSE_CODE.toString(), "200");
- LOGGER.error("AAI_7350 Error sending message to dmaap. {} {}" , jsmMessageTxt, LogFormatTools.getStackTop(e));
- }
- }
-
- }
+ } else {
+ LoggingContext.statusCode(StatusCode.ERROR);
+ LOGGER.error(eventName + "|Event Topic invalid.");
+ }
+ } catch (JMSException | JSONException e) {
+ MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString());
+ MDC.put(LoggingField.RESPONSE_CODE.toString(), "200");
+ LOGGER.error("AAI_7350 Error parsing aaievent jsm message for sending to dmaap. {} {}", jsmMessageTxt, LogFormatTools.getStackTop(e));
+ } catch (Exception e) {
+ MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString());
+ MDC.put(LoggingField.RESPONSE_CODE.toString(), "200");
+ LOGGER.error("AAI_7350 Error sending message to dmaap. {} {}" , jsmMessageTxt, LogFormatTools.getStackTop(e));
+ }
+ }
+
+ }
}
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 851a22fe..35e1a4a5 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
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -28,22 +30,22 @@ import org.springframework.jms.core.JmsTemplate;
public class AAIDmaapEventJMSProducer implements MessageProducer {
- private JmsTemplate jmsTemplate;
+ private JmsTemplate jmsTemplate;
- public AAIDmaapEventJMSProducer() {
- if(AAIConfig.get("aai.jms.enable", "true").equals("true")){
+ public AAIDmaapEventJMSProducer() {
+ if("true".equals(AAIConfig.get("aai.jms.enable", "true"))){
this.jmsTemplate = new JmsTemplate();
String activeMqTcpUrl = System.getProperty("activemq.tcp.url", "tcp://localhost:61547");
this.jmsTemplate.setConnectionFactory(new CachingConnectionFactory(new ActiveMQConnectionFactory(activeMqTcpUrl)));
this.jmsTemplate.setDefaultDestination(new ActiveMQQueue("IN_QUEUE"));
- }
- }
+ }
+ }
- public void sendMessageToDefaultDestination(JSONObject finalJson) {
- if(jmsTemplate != null){
- jmsTemplate.convertAndSend(finalJson.toString());
- CachingConnectionFactory ccf = (CachingConnectionFactory) this.jmsTemplate.getConnectionFactory();
- ccf.destroy();
- }
- }
+ public void sendMessageToDefaultDestination(JSONObject finalJson) {
+ if(jmsTemplate != null){
+ jmsTemplate.convertAndSend(finalJson.toString());
+ CachingConnectionFactory ccf = (CachingConnectionFactory) this.jmsTemplate.getConnectionFactory();
+ ccf.destroy();
+ }
+ }
}
diff --git a/aai-core/src/main/java/org/onap/aai/domain/responseMessage/AAIResponseMessageData.java b/aai-core/src/main/java/org/onap/aai/domain/responseMessage/AAIResponseMessageData.java
index 49fb0c1e..1f40906f 100644
--- a/aai-core/src/main/java/org/onap/aai/domain/responseMessage/AAIResponseMessageData.java
+++ b/aai-core/src/main/java/org/onap/aai/domain/responseMessage/AAIResponseMessageData.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -39,39 +41,39 @@ import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
- "aaiResponseMessageDatum",
- "any"
+ "aaiResponseMessageDatum",
+ "any"
})
@XmlRootElement(name = "aai-response-message-data", namespace = "http://org.onap.aai.inventory")
public class AAIResponseMessageData {
- @XmlElement(name = "aai-response-message-datum")
- protected List<AAIResponseMessageDatum> aaiResponseMessageDatum;
- @XmlAnyElement(lax = true)
- protected List<Object> any;
+ @XmlElement(name = "aai-response-message-datum")
+ protected List<AAIResponseMessageDatum> aaiResponseMessageDatum;
+ @XmlAnyElement(lax = true)
+ protected List<Object> any;
- /**
- * Gets the AAI response message datum.
- *
- * @return the AAI response message datum
- */
- public List<AAIResponseMessageDatum> getAAIResponseMessageDatum() {
- if (aaiResponseMessageDatum == null) {
- aaiResponseMessageDatum = new ArrayList<AAIResponseMessageDatum>();
- }
- return this.aaiResponseMessageDatum;
- }
+ /**
+ * Gets the AAI response message datum.
+ *
+ * @return the AAI response message datum
+ */
+ public List<AAIResponseMessageDatum> getAAIResponseMessageDatum() {
+ if (aaiResponseMessageDatum == null) {
+ aaiResponseMessageDatum = new ArrayList<>();
+ }
+ return this.aaiResponseMessageDatum;
+ }
- /**
- * Gets the any.
- *
- * @return the any
- */
- public List<Object> getAny() {
- if (any == null) {
- any = new ArrayList<Object>();
- }
- return this.any;
- }
+ /**
+ * Gets the any.
+ *
+ * @return the any
+ */
+ public List<Object> getAny() {
+ if (any == null) {
+ any = new ArrayList<>();
+ }
+ return this.any;
+ }
}
diff --git a/aai-core/src/main/java/org/onap/aai/exceptions/AAIException.java b/aai-core/src/main/java/org/onap/aai/exceptions/AAIException.java
index f2253a30..0851e719 100644
--- a/aai-core/src/main/java/org/onap/aai/exceptions/AAIException.java
+++ b/aai-core/src/main/java/org/onap/aai/exceptions/AAIException.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -28,119 +30,121 @@ import org.onap.aai.logging.ErrorObjectNotFoundException;
public class AAIException extends Exception {
- public static final String DEFAULT_EXCEPTION_CODE = "AAI_4000";
- private static final long serialVersionUID = 1L;
-
- private final String code;
- private final ErrorObject errorObject;
- private final Collection<String> templateVars;
-
- /**
- * Instantiates a new AAI exception.
- */
- public AAIException() {
- super();
- this.code = DEFAULT_EXCEPTION_CODE;
- this.templateVars = new LinkedList<String> ();
-
- try {
- this.errorObject = ErrorLogHelper.getErrorObject(getCode());
- } catch (ErrorObjectNotFoundException e) {
- throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode()
- + " - update error.properties before using this exception code");
- }
- }
-
- /**
- * Instantiates a new AAI exception.
- *
- * @param code the code
- */
- public AAIException(String code) {
- super();
-
- this.code = code;
- this.templateVars = new LinkedList<String> ();
-
- try {
- this.errorObject = ErrorLogHelper.getErrorObject(getCode());
- } catch (ErrorObjectNotFoundException e) {
- throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode()
- + " - update error.properties before using this exception code");
- }
- }
-
- /**
- * Instantiates a new AAI exception.
- *
- * @param code the code
- * @param details the details
- */
- public AAIException(String code, String details) {
- super(details);
-
- this.code = code;
- this.templateVars = new LinkedList<String> ();
-
- try {
- this.errorObject = ErrorLogHelper.getErrorObject(getCode());
- errorObject.setDetails(details);
- } catch (ErrorObjectNotFoundException e) {
- throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode()
- + " - update error.properties before using this exception code");
- }
- }
-
- /**
- * Instantiates a new AAI exception.
- *
- * @param code the code
- * @param cause the cause
- */
- public AAIException(String code, Throwable cause) {
- super(cause);
-
- this.code = code;
- this.templateVars = new LinkedList<String> ();
-
- try {
- this.errorObject = ErrorLogHelper.getErrorObject(getCode());
- } catch (ErrorObjectNotFoundException e) {
- throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode()
- + " - update error.properties before using this exception code");
- }
- }
-
- /**
- * Instantiates a new AAI exception.
- *
- * @param code the code
- * @param cause the cause
- * @param details the details
- */
- public AAIException(String code, Throwable cause, String details) {
- super(details, cause);
-
- this.code = code;
- this.templateVars = new LinkedList<String> ();
-
- try {
- this.errorObject = ErrorLogHelper.getErrorObject(getCode());
- } catch (ErrorObjectNotFoundException e) {
- throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode()
- + " - update error.properties before using this exception code");
- }
- }
-
- public String getCode() {
- return code;
- }
-
- public ErrorObject getErrorObject() {
- return errorObject;
- }
-
- public Collection<String> getTemplateVars() {
- return templateVars;
- }
+ private static final String UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE = " - update error.properties before using this exception code";
+ private static final String FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE = "Failed to instantiate AAIException with code=";
+ public static final String DEFAULT_EXCEPTION_CODE = "AAI_4000";
+ private static final long serialVersionUID = 1L;
+
+ private final String code;
+ private final ErrorObject errorObject;
+ private final Collection<String> templateVars;
+
+ /**
+ * Instantiates a new AAI exception.
+ */
+ public AAIException() {
+ super();
+ this.code = DEFAULT_EXCEPTION_CODE;
+ this.templateVars = new LinkedList<String> ();
+
+ try {
+ this.errorObject = ErrorLogHelper.getErrorObject(getCode());
+ } catch (ErrorObjectNotFoundException e) {
+ throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode()
+ + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE);
+ }
+ }
+
+ /**
+ * Instantiates a new AAI exception.
+ *
+ * @param code the code
+ */
+ public AAIException(String code) {
+ super();
+
+ this.code = code;
+ this.templateVars = new LinkedList<String> ();
+
+ try {
+ this.errorObject = ErrorLogHelper.getErrorObject(getCode());
+ } catch (ErrorObjectNotFoundException e) {
+ throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode()
+ + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE);
+ }
+ }
+
+ /**
+ * Instantiates a new AAI exception.
+ *
+ * @param code the code
+ * @param details the details
+ */
+ public AAIException(String code, String details) {
+ super(details);
+
+ this.code = code;
+ this.templateVars = new LinkedList<String> ();
+
+ try {
+ this.errorObject = ErrorLogHelper.getErrorObject(getCode());
+ errorObject.setDetails(details);
+ } catch (ErrorObjectNotFoundException e) {
+ throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode()
+ + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE);
+ }
+ }
+
+ /**
+ * Instantiates a new AAI exception.
+ *
+ * @param code the code
+ * @param cause the cause
+ */
+ public AAIException(String code, Throwable cause) {
+ super(cause);
+
+ this.code = code;
+ this.templateVars = new LinkedList<String> ();
+
+ try {
+ this.errorObject = ErrorLogHelper.getErrorObject(getCode());
+ } catch (ErrorObjectNotFoundException e) {
+ throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode()
+ + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE);
+ }
+ }
+
+ /**
+ * Instantiates a new AAI exception.
+ *
+ * @param code the code
+ * @param cause the cause
+ * @param details the details
+ */
+ public AAIException(String code, Throwable cause, String details) {
+ super(details, cause);
+
+ this.code = code;
+ this.templateVars = new LinkedList<String> ();
+
+ try {
+ this.errorObject = ErrorLogHelper.getErrorObject(getCode());
+ } catch (ErrorObjectNotFoundException e) {
+ throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode()
+ + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE);
+ }
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public ErrorObject getErrorObject() {
+ return errorObject;
+ }
+
+ public Collection<String> getTemplateVars() {
+ return templateVars;
+ }
}
diff --git a/aai-core/src/main/java/org/onap/aai/query/builder/GremlinQueryBuilder.java b/aai-core/src/main/java/org/onap/aai/query/builder/GremlinQueryBuilder.java
index 683f4729..2cc78f44 100644
--- a/aai-core/src/main/java/org/onap/aai/query/builder/GremlinQueryBuilder.java
+++ b/aai-core/src/main/java/org/onap/aai/query/builder/GremlinQueryBuilder.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -49,100 +51,102 @@ import java.util.*;
*/
public abstract class GremlinQueryBuilder<E> extends QueryBuilder<E> {
- private GremlinGroovyShellSingleton gremlinGroovy = GremlinGroovyShellSingleton.getInstance();
- private GraphTraversal<?, ?> completeTraversal = null;
- protected List<String> list = null;
-
- /**
- * Instantiates a new gremlin query builder.
- *
- * @param loader the loader
- */
- public GremlinQueryBuilder(Loader loader, GraphTraversalSource source) {
- super(loader, source);
- list = new ArrayList<>();
- }
-
- /**
- * Instantiates a new gremlin query builder.
- *
- * @param loader the loader
- * @param start the start
- */
- public GremlinQueryBuilder(Loader loader, GraphTraversalSource source, Vertex start) {
- super(loader, source, start);
- list = new ArrayList<>();
- }
-
- @Override
- public QueryBuilder<Vertex> exactMatchQuery(Introspector obj) {
- // TODO not implemented because this is implementation is no longer used
- this.createKeyQuery(obj);
- this.createContainerQuery(obj);
- return (QueryBuilder<Vertex>) this;
- }
-
- /**
- * @{inheritDoc}
- */
- @Override
- public QueryBuilder<Vertex> getVerticesByProperty(String key, Object value) {
-
- String term = "";
- if (value != null && !(value instanceof String) ) {
- term = value.toString();
- } else {
- term = "'" + value + "'";
- }
- list.add(".has('" + key + "', " + term + ")");
- stepIndex++;
- return (QueryBuilder<Vertex>) this;
- }
-
- @Override
- public QueryBuilder<Vertex> getVerticesByBooleanProperty(String key, Object value) {
- boolean bValue = false;
-
- if(value instanceof String){
- bValue = Boolean.valueOf(value.toString());
- } else if(value instanceof Boolean){
- bValue = (Boolean) value;
- }
-
- list.add(".has('" + key + "', " + bValue + ")");
- stepIndex++;
- return (QueryBuilder<Vertex>) this;
- }
-
- /**
- * @{inheritDoc}
- */
- @Override
- public QueryBuilder<Vertex> getVerticesByProperty(String key, List<?> values) {
-
- String predicate = "P.within(#!#argument#!#)";
- List<String> arguments = new ArrayList<>();
- for (Object item : values) {
- if (item != null && !(item instanceof String)) {
- arguments.add(item.toString());
- } else {
- arguments.add("'" + item + "'");
- }
- }
- String argument = Joiner.on(",").join(arguments);
- predicate = predicate.replace("#!#argument#!#", argument);
- list.add(".has('" + key + "', " + predicate + ")");
- stepIndex++;
- return (QueryBuilder<Vertex>) this;
- }
-
- /**
+ private static final String ARGUMENT2 = "#!#argument#!#";
+ private static final String HAS = ".has('";
+ private GremlinGroovyShellSingleton gremlinGroovy = GremlinGroovyShellSingleton.getInstance();
+ private GraphTraversal<?, ?> completeTraversal = null;
+ protected List<String> list = null;
+
+ /**
+ * Instantiates a new gremlin query builder.
+ *
+ * @param loader the loader
+ */
+ public GremlinQueryBuilder(Loader loader, GraphTraversalSource source) {
+ super(loader, source);
+ list = new ArrayList<>();
+ }
+
+ /**
+ * Instantiates a new gremlin query builder.
+ *
+ * @param loader the loader
+ * @param start the start
+ */
+ public GremlinQueryBuilder(Loader loader, GraphTraversalSource source, Vertex start) {
+ super(loader, source, start);
+ list = new ArrayList<>();
+ }
+
+ @Override
+ public QueryBuilder<Vertex> exactMatchQuery(Introspector obj) {
+ // TODO not implemented because this is implementation is no longer used
+ this.createKeyQuery(obj);
+ this.createContainerQuery(obj);
+ return (QueryBuilder<Vertex>) this;
+ }
+
+ /**
+ * @{inheritDoc}
+ */
+ @Override
+ public QueryBuilder<Vertex> getVerticesByProperty(String key, Object value) {
+
+ String term = "";
+ if (value != null && !(value instanceof String) ) {
+ term = value.toString();
+ } else {
+ term = "'" + value + "'";
+ }
+ list.add(HAS + key + "', " + term + ")");
+ stepIndex++;
+ return (QueryBuilder<Vertex>) this;
+ }
+
+ @Override
+ public QueryBuilder<Vertex> getVerticesByBooleanProperty(String key, Object value) {
+ boolean bValue = false;
+
+ if(value instanceof String){
+ bValue = Boolean.valueOf(value.toString());
+ } else if(value instanceof Boolean){
+ bValue = (Boolean) value;
+ }
+
+ list.add(HAS + key + "', " + bValue + ")");
+ stepIndex++;
+ return (QueryBuilder<Vertex>) this;
+ }
+
+ /**
+ * @{inheritDoc}
+ */
+ @Override
+ public QueryBuilder<Vertex> getVerticesByProperty(String key, List<?> values) {
+
+ String predicate = "P.within(#!#argument#!#)";
+ List<String> arguments = new ArrayList<>();
+ for (Object item : values) {
+ if (item != null && !(item instanceof String)) {
+ arguments.add(item.toString());
+ } else {
+ arguments.add("'" + item + "'");
+ }
+ }
+ String argument = Joiner.on(",").join(arguments);
+ predicate = predicate.replace(ARGUMENT2, argument);
+ list.add(HAS + key + "', " + predicate + ")");
+ stepIndex++;
+ return (QueryBuilder<Vertex>) this;
+ }
+
+ /**
* @{inheritDoc}
*/
@Override
public QueryBuilder<Vertex> getVerticesByProperty(String key) {
- list.add(".has('" + key + "')");
+ list.add(HAS + key + "')");
stepIndex++;
return (QueryBuilder<Vertex>) this;
}
@@ -153,72 +157,71 @@ public abstract class GremlinQueryBuilder<E> extends QueryBuilder<E> {
@Override
public QueryBuilder<Vertex> getVerticesExcludeByProperty(String key) {
- String term = "";
list.add(".hasNot('" + key + "')");
stepIndex++;
return (QueryBuilder<Vertex>) this;
}
- /**
- * @{inheritDoc}
- */
- @Override
- public QueryBuilder<Vertex> getVerticesStartsWithProperty(String key, Object value) {
-
- String term = "";
- String predicate = "org.janusgraph.core.attribute.Text.textPrefix(#!#argument#!#)";
- if (value != null && !(value instanceof String) ) {
- term = value.toString();
- } else {
- term = "'" + value + "'";
- }
- predicate = predicate.replace("#!#argument#!#", term);
- list.add(".has('" + key + "', " + predicate + ")");
- stepIndex++;
- return (QueryBuilder<Vertex>) this;
- }
-
- /**
- * @{inheritDoc}
- */
- @Override
- public QueryBuilder<Vertex> getVerticesExcludeByProperty(String key, Object value) {
-
- String term = "";
- String predicate = "P.neq(#!#argument#!#)";
- if (value != null && !(value instanceof String) ) {
- term = value.toString();
- } else {
- term = "'" + value + "'";
- }
- predicate = predicate.replace("#!#argument#!#", term);
- list.add(".has('" + key + "', " + predicate + ")");
- stepIndex++;
- return (QueryBuilder<Vertex>) this;
- }
-
- /**
- * @{inheritDoc}
- */
- @Override
- public QueryBuilder<Vertex> getVerticesExcludeByProperty(String key, List<?> values) {
-
- String predicate = "P.without(#!#argument#!#)";
- List<String> arguments = new ArrayList<>();
- for (Object item : values) {
- if (item != null && !(item instanceof String)) {
- arguments.add(item.toString());
- } else {
- arguments.add("'" + item + "'");
- }
- }
- String argument = Joiner.on(",").join(arguments);
- predicate = predicate.replace("#!#argument#!#", argument);
- list.add(".has('" + key + "', " + predicate + ")");
- stepIndex++;
- return (QueryBuilder<Vertex>) this;
- }
-
+ /**
+ * @{inheritDoc}
+ */
+ @Override
+ public QueryBuilder<Vertex> getVerticesStartsWithProperty(String key, Object value) {
+
+ String term = "";
+ String predicate = "org.janusgraph.core.attribute.Text.textPrefix(#!#argument#!#)";
+ if (value != null && !(value instanceof String) ) {
+ term = value.toString();
+ } else {
+ term = "'" + value + "'";
+ }
+ predicate = predicate.replace(ARGUMENT2, term);
+ list.add(HAS + key + "', " + predicate + ")");
+ stepIndex++;
+ return (QueryBuilder<Vertex>) this;
+ }
+
+ /**
+ * @{inheritDoc}
+ */
+ @Override
+ public QueryBuilder<Vertex> getVerticesExcludeByProperty(String key, Object value) {
+
+ String term = "";
+ String predicate = "P.neq(#!#argument#!#)";
+ if (value != null && !(value instanceof String) ) {
+ term = value.toString();
+ } else {
+ term = "'" + value + "'";
+ }
+ predicate = predicate.replace(ARGUMENT2, term);
+ list.add(HAS + key + "', " + predicate + ")");
+ stepIndex++;
+ return (QueryBuilder<Vertex>) this;
+ }
+
+ /**
+ * @{inheritDoc}
+ */
+ @Override
+ public QueryBuilder<Vertex> getVerticesExcludeByProperty(String key, List<?> values) {
+
+ String predicate = "P.without(#!#argument#!#)";
+ List<String> arguments = new ArrayList<>();
+ for (Object item : values) {
+ if (item != null && !(item instanceof String)) {
+ arguments.add(item.toString());
+ } else {
+ arguments.add("'" + item + "'");
+ }
+ }
+ String argument = Joiner.on(",").join(arguments);
+ predicate = predicate.replace(ARGUMENT2, argument);
+ list.add(HAS + key + "', " + predicate + ")");
+ stepIndex++;
+ return (QueryBuilder<Vertex>) this;
+ }
+
@Override
public QueryBuilder<Vertex> getVerticesGreaterThanProperty(String key, Object value) {
String predicate = "P.gte(#!#argument1#!#)";
@@ -229,7 +232,7 @@ public abstract class GremlinQueryBuilder<E> extends QueryBuilder<E> {
term = "'" + value + "'";
}
predicate = predicate.replace("#!#argument1#!#", term);
- list.add(".has('" + key + "', " + predicate + ")");
+ list.add(HAS + key + "', " + predicate + ")");
stepIndex++;
return (QueryBuilder<Vertex>) this;
}
@@ -244,7 +247,7 @@ public abstract class GremlinQueryBuilder<E> extends QueryBuilder<E> {
term = "'" + value + "'";
}
predicate = predicate.replace("#!#argument1#!#", term);
- list.add(".has('" + key + "', " + predicate + ")");
+ list.add(HAS + key + "', " + predicate + ")");
stepIndex++;
return (QueryBuilder<Vertex>) this;
}
@@ -252,563 +255,558 @@ public abstract class GremlinQueryBuilder<E> extends QueryBuilder<E> {
- /**
- * @{inheritDoc}
- */
- @Override
- public QueryBuilder<Vertex> getChildVerticesFromParent(String parentKey, String parentValue, String childType) {
- /*
- String query = ".has('aai-node-type', '" + childType + "')";
-
- return this.processGremlinQuery(parentKey, parentValue, query);
- */
- //TODO
- return (QueryBuilder<Vertex>) this;
- }
-
- /**
- * @{inheritDoc}
- */
- @Override
- public QueryBuilder<Vertex> getTypedVerticesByMap(String type, Map<String, String> map) {
-
- for (Map.Entry<String, String> es : map.entrySet()) {
- list.add(".has('" + es.getKey() + "', '" + es.getValue() + "')");
- stepIndex++;
- }
- list.add(".has('aai-node-type', '" + type + "')");
- stepIndex++;
- return (QueryBuilder<Vertex>) this;
- }
-
- /**
- * @{inheritDoc}
- */
- @Override
- public QueryBuilder<Vertex> createKeyQuery(Introspector obj) {
- Set<String> keys = obj.getKeys();
-
- for (String key : keys) {
-
- this.getVerticesByProperty(key, obj.<Object>getValue(key));
-
- }
- return (QueryBuilder<Vertex>) this;
- }
-
- /**
- * @throws NoEdgeRuleFoundException
- * @throws AAIException
- * @{inheritDoc}
- */
- @Override
- public QueryBuilder createEdgeTraversal(EdgeType type, Introspector parent, Introspector child) throws AAIException {
- String parentName = parent.getDbName();
- String childName = child.getDbName();
- if (parent.isContainer()) {
- parentName = parent.getChildDBName();
- }
- if (child.isContainer()) {
- childName = child.getChildDBName();
- }
- this.edgeQueryToVertex(type, parentName, childName, null);
- return this;
-
- }
-
- @Override
- public QueryBuilder createPrivateEdgeTraversal(EdgeType type, Introspector parent, Introspector child) throws AAIException{
- String parentName = parent.getDbName();
- String childName = child.getDbName();
- if (parent.isContainer()) {
- parentName = parent.getChildDBName();
- }
- if (child.isContainer()) {
- childName = child.getChildDBName();
- }
- this.edgeQueryToVertex(type, parentName, childName, null, true);
- return this;
- }
-
- /**
- *
- * @{inheritDoc}
- */
- @Override
- public QueryBuilder<Vertex> createEdgeTraversalWithLabels(EdgeType type, Introspector out, Introspector in, List<String> labels) throws AAIException {
- String parentName = out.getDbName();
- String childName = in.getDbName();
- if (out.isContainer()) {
- parentName = out.getChildDBName();
- }
- if (in.isContainer()) {
- childName = in.getChildDBName();
- }
- this.edgeQueryToVertex(type, parentName, childName, labels);
- return (QueryBuilder<Vertex>) this;
- }
-
-
- public QueryBuilder<Edge> getEdgesBetweenWithLabels(EdgeType type, String outNodeType, String inNodeType, List<String> labels) throws AAIException {
- this.edgeQuery(type, outNodeType, inNodeType, labels);
- return (QueryBuilder<Edge>)this;
- }
-
- private void edgeQueryToVertex(EdgeType type, String outType, String inType, List<String> labels) throws AAIException {
- this.edgeQueryToVertex(type, outType, inType, labels, false);
- }
-
- /**
- * Edge query.
- *
- * @param outType the out type
- * @param inType the in type
- * @throws NoEdgeRuleFoundException
- * @throws AAIException
- */
- private void edgeQueryToVertex(EdgeType type, String outType, String inType, List<String> labels, boolean isPrivateEdge) throws AAIException {
- markParentBoundary();
- Multimap<String, EdgeRule> rules = ArrayListMultimap.create();
- EdgeRuleQuery.Builder qB = new EdgeRuleQuery.Builder(outType, inType).edgeType(type).setPrivate(isPrivateEdge);
-
- try {
- if (labels == null) {
- rules.putAll(edgeRules.getRules(qB.build()));
- } else {
- for (String label : labels) {
- rules.putAll(edgeRules.getRules(qB.label(label).build()));
- }
- }
- } catch (EdgeRuleNotFoundException e) {
- throw new NoEdgeRuleFoundException(e);
- }
-
- final List<String> inLabels = new ArrayList<>();
- final List<String> outLabels = new ArrayList<>();
-
- for (EdgeRule rule : rules.values()) {
- if (labels != null && !labels.contains(rule.getLabel())) {
- return;
- } else {
- if (Direction.IN.equals(rule.getDirection())) {
- inLabels.add(rule.getLabel());
- } else {
- outLabels.add(rule.getLabel());
- }
- }
- }
-
- if(inLabels.isEmpty() && outLabels.isEmpty()) {
- throw new NoEdgeRuleFoundException("no " + type.toString() + " edge rule between " + outType + " and " + inType );
- } else if (inLabels.isEmpty() && !outLabels.isEmpty()) {
- list.add(".out('" + String.join("','", outLabels) + "')");
- } else if (outLabels.isEmpty() && !inLabels.isEmpty()) {
- list.add(".in('" + String.join("','", inLabels) + "')");
- } else {
- list.add(".union(__.in('" + String.join("','", inLabels) + "')" + ", __.out('" + String.join("','", outLabels) + "'))");
- }
- stepIndex++;
- list.add(".has('" + AAIProperties.NODE_TYPE + "', '" + inType + "')");
- stepIndex++;
-
- }
-
- /**
- * Edge query.
- *
- * @param outType the out type
- * @param inType the in type
- * @throws NoEdgeRuleFoundException
- * @throws AAIException
- */
- private void edgeQuery(EdgeType type, String outType, String inType, List<String> labels) throws AAIException {
- markParentBoundary();
- Multimap<String, EdgeRule> rules = ArrayListMultimap.create();
- EdgeRuleQuery.Builder qB = new EdgeRuleQuery.Builder(outType, inType).edgeType(type);
- try {
- if (labels == null) {
- rules.putAll(edgeRules.getRules(qB.build()));
- } else {
- for (String label : labels) {
- rules.putAll(edgeRules.getRules(qB.label(label).build()));
- }
- }
- } catch (EdgeRuleNotFoundException e) {
- throw new NoEdgeRuleFoundException(e);
- }
-
- final List<String> inLabels = new ArrayList<>();
- final List<String> outLabels = new ArrayList<>();
-
- for (EdgeRule rule : rules.values()) {
- if (labels != null && !labels.contains(rule.getLabel())) {
- return;
- } else {
- if (Direction.IN.equals(rule.getDirection())) {
- inLabels.add(rule.getLabel());
- } else {
- outLabels.add(rule.getLabel());
- }
- }
- }
-
- if(inLabels.isEmpty() && outLabels.isEmpty()) {
- throw new NoEdgeRuleFoundException("no " + type.toString() + " edge rule between " + outType + " and " + inType );
- } else if (inLabels.isEmpty() && !outLabels.isEmpty()) {
- list.add(".outE('" + String.join("','", outLabels) + "')");
- } else if (outLabels.isEmpty() && !inLabels.isEmpty()) {
- list.add(".inE('" + String.join("','", inLabels) + "')");
- } else {
- list.add(".union(__.inE('" + String.join("','", inLabels) + "')" + ", __.outE('" + String.join("','", outLabels) + "'))");
- }
-
- stepIndex++;
-
- }
- @Override
- public QueryBuilder<E> limit(long amount) {
- list.add(".limit(" + amount + ")");
- return this;
- }
- /**
- * @{inheritDoc}
- */
- @Override
- public QueryBuilder<Vertex> createContainerQuery(Introspector obj) {
- String type = obj.getChildDBName();
- String abstractType = obj.getMetadata(ObjectMetadata.ABSTRACT);
- if (abstractType != null) {
- String[] inheritors = obj.getMetadata(ObjectMetadata.INHERITORS).split(",");
- String[] wrapped = new String[inheritors.length];
- StringBuilder command = new StringBuilder();
- command.append("P.within(");
- for (int i = 0; i < inheritors.length; i++) {
- wrapped[i] = "'" + inheritors[i] + "'";
- }
- command.append(Joiner.on(",").join(wrapped));
- command.append(")");
- list.add(".has('aai-node-type', " + command + ")");
-
- } else {
- list.add(".has('aai-node-type', '" + type + "')");
- }
- stepIndex++;
- this.markContainer();
- return (QueryBuilder<Vertex>) this;
- }
-
- @Override
- public QueryBuilder<E> union(QueryBuilder<E>... builder) {
- markParentBoundary();
- String[] traversals = new String[builder.length];
- StringBuilder command = new StringBuilder();
- for (int i = 0; i < builder.length; i++) {
- traversals[i] = "__" + builder[i].getQuery();
- }
- command.append(".union(");
- command.append(Joiner.on(",").join(traversals));
- command.append(")");
- list.add(command.toString());
- stepIndex++;
-
- return this;
- }
-
- @Override
- public QueryBuilder<E> where(QueryBuilder<E>... builder) {
- markParentBoundary();
- List<String> traversals = new ArrayList<>();
- for (int i = 0; i < builder.length; i++) {
- traversals.add(".where(__" + builder[i].getQuery() + ")");
- stepIndex++;
- }
- list.addAll(traversals);
-
-
- return this;
- }
-
- @Override
- public QueryBuilder<E> or(QueryBuilder<E>... builder) {
- markParentBoundary();
- String[] traversals = new String[builder.length];
- StringBuilder command = new StringBuilder();
- for (int i = 0; i < builder.length; i++) {
- traversals[i] = "__" + builder[i].getQuery();
- }
- command.append(".or(");
- command.append(Joiner.on(",").join(traversals));
- command.append(")");
- list.add(command.toString());
- stepIndex++;
-
- return this;
- }
-
- @Override
- public QueryBuilder<E> store(String name) {
- this.list.add(".store('"+ name + "')");
- stepIndex++;
-
- return this;
- }
-
- @Override
- public QueryBuilder<E> cap(String name) {
- this.list.add(".cap('"+ name + "')");
- stepIndex++;
-
- return this;
- }
-
- @Override
- public QueryBuilder<E> unfold() {
- this.list.add(".unfold()");
- stepIndex++;
-
- return this;
- }
-
- @Override
- public QueryBuilder<E> dedup() {
- this.list.add(".dedup()");
- stepIndex++;
-
- return this;
- }
-
- @Override
- public QueryBuilder<E> emit() {
- this.list.add(".emit()");
- stepIndex++;
-
- return this;
- }
-
- @Override
- public QueryBuilder<E> repeat(QueryBuilder<E> builder) {
- this.list.add(".repeat(__" + builder.getQuery() + ")");
- stepIndex++;
-
- return this;
- }
-
- @Override
- public QueryBuilder<E> until(QueryBuilder<E> builder) {
- this.list.add(".until(__" + builder.getQuery() + ")");
- stepIndex++;
-
- return this;
- }
-
- @Override
- public QueryBuilder<E> groupCount() {
- this.list.add(".groupCount()");
- stepIndex++;
-
- return this;
- }
-
- @Override
- public QueryBuilder<E> both() {
- this.list.add(".both()");
- stepIndex++;
-
- return this;
- }
-
- @Override
- public QueryBuilder<Tree> tree() {
- this.list.add(".tree()");
- stepIndex++;
-
- return (QueryBuilder<Tree>)this;
- }
-
- @Override
- public QueryBuilder<E> by(String name) {
- this.list.add(".by('"+ name + "')");
- stepIndex++;
-
- return this;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public QueryBuilder<E> simplePath(){
- this.list.add(".simplePath()");
- stepIndex++;
- return this;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public QueryBuilder<Path> path(){
- this.list.add(".path()");
- stepIndex++;
- return (QueryBuilder<Path>)this;
- }
-
- @Override
- public QueryBuilder<Edge> outE() {
- this.list.add(".outE()");
- stepIndex++;
-
- return (QueryBuilder<Edge>)this;
- }
-
- @Override
- public QueryBuilder<Edge> inE() {
- this.list.add(".inE()");
- stepIndex++;
-
- return (QueryBuilder<Edge>)this;
- }
-
- @Override
- public QueryBuilder<Vertex> outV() {
- this.list.add(".outV()");
- stepIndex++;
-
- return (QueryBuilder<Vertex>)this;
- }
-
- @Override
- public QueryBuilder<Vertex> inV() {
- this.list.add(".inV()");
- stepIndex++;
-
- return (QueryBuilder<Vertex>)this;
- }
-
- @Override
- public QueryBuilder<E> not(QueryBuilder<E> builder) {
- this.list.add(".not(" + "__" + builder.getQuery() + ")");
- stepIndex++;
-
- return this;
- }
-
- @Override
- public QueryBuilder<E> as(String name) {
- this.list.add(".as('" + name + "')");
- stepIndex++;
-
- return this;
- }
-
- @Override
- public QueryBuilder<E> select(String name) {
- this.list.add(".select('" + name + "')");
- stepIndex++;
-
- return this;
- }
- /**
- * @{inheritDoc}
- */
- @Override
- public QueryBuilder<E> getParentQuery() {
- return cloneQueryAtStep(parentStepIndex);
- }
-
- @Override
- public QueryBuilder<E> getContainerQuery() {
- return cloneQueryAtStep(containerStepIndex);
- }
-
- /**
- * @{inheritDoc}
- */
- @Override
- public <T2> T2 getQuery() {
- StringBuilder sb = new StringBuilder();
-
- for (String piece : this.list) {
- sb.append(piece);
- }
-
- return (T2)sb.toString();
- }
-
- /**
- * @{inheritDoc}
- */
- @Override
- public void markParentBoundary() {
- parentStepIndex = stepIndex;
- }
-
- @Override
- public void markContainer() {
- this.containerStepIndex = stepIndex;
- }
-
- /**
- * @{inheritDoc}
- */
- @Override
- public Vertex getStart() {
- return this.start;
- }
-
- protected int getParentStepIndex() {
- return parentStepIndex;
- }
-
- protected int getContainerStepIndex() {
- return containerStepIndex;
- }
-
- protected int getStepIndex() {
- return stepIndex;
- }
-
- private void executeQuery() {
- String queryString = "g" + Joiner.on("").join(list);
- Map<String, Object> params = new HashMap<>();
- if (this.start == null) {
- params.put("g", source.V());
- } else {
- params.put("g", source.V(this.start));
- }
- this.completeTraversal = this.gremlinGroovy.executeTraversal(queryString, params);
- }
- @Override
- public boolean hasNext() {
- if (this.completeTraversal == null) {
- executeQuery();
- }
-
- return this.completeTraversal.hasNext();
- }
-
- @Override
- public E next() {
- if (this.completeTraversal == null) {
- executeQuery();
- }
-
- return (E)this.completeTraversal.next();
- }
-
- @Override
- public List<E> toList() {
- if (this.completeTraversal == null) {
- executeQuery();
- }
-
- return (List<E>)this.completeTraversal.toList();
- }
-
- protected QueryBuilder<Edge> has(String key, String value) {
- this.list.add(".has('" + key + "','" + value + "')");
-
- return (QueryBuilder<Edge>)this;
- }
-
+ /**
+ * @{inheritDoc}
+ */
+ @Override
+ public QueryBuilder<Vertex> getChildVerticesFromParent(String parentKey, String parentValue, String childType) {
+ //TODO
+ return (QueryBuilder<Vertex>) this;
+ }
+
+ /**
+ * @{inheritDoc}
+ */
+ @Override
+ public QueryBuilder<Vertex> getTypedVerticesByMap(String type, Map<String, String> map) {
+
+ for (Map.Entry<String, String> es : map.entrySet()) {
+ list.add(HAS + es.getKey() + "', '" + es.getValue() + "')");
+ stepIndex++;
+ }
+ list.add(".has('aai-node-type', '" + type + "')");
+ stepIndex++;
+ return (QueryBuilder<Vertex>) this;
+ }
+
+ /**
+ * @{inheritDoc}
+ */
+ @Override
+ public QueryBuilder<Vertex> createKeyQuery(Introspector obj) {
+ Set<String> keys = obj.getKeys();
+
+ for (String key : keys) {
+
+ this.getVerticesByProperty(key, obj.<Object>getValue(key));
+
+ }
+ return (QueryBuilder<Vertex>) this;
+ }
+
+ /**
+ * @throws NoEdgeRuleFoundException
+ * @throws AAIException
+ * @{inheritDoc}
+ */
+ @Override
+ public QueryBuilder createEdgeTraversal(EdgeType type, Introspector parent, Introspector child) throws AAIException {
+ String parentName = parent.getDbName();
+ String childName = child.getDbName();
+ if (parent.isContainer()) {
+ parentName = parent.getChildDBName();
+ }
+ if (child.isContainer()) {
+ childName = child.getChildDBName();
+ }
+ this.edgeQueryToVertex(type, parentName, childName, null);
+ return this;
+
+ }
+
+ @Override
+ public QueryBuilder createPrivateEdgeTraversal(EdgeType type, Introspector parent, Introspector child) throws AAIException{
+ String parentName = parent.getDbName();
+ String childName = child.getDbName();
+ if (parent.isContainer()) {
+ parentName = parent.getChildDBName();
+ }
+ if (child.isContainer()) {
+ childName = child.getChildDBName();
+ }
+ this.edgeQueryToVertex(type, parentName, childName, null, true);
+ return this;
+ }
+
+ /**
+ *
+ * @{inheritDoc}
+ */
+ @Override
+ public QueryBuilder<Vertex> createEdgeTraversalWithLabels(EdgeType type, Introspector out, Introspector in, List<String> labels) throws AAIException {
+ String parentName = out.getDbName();
+ String childName = in.getDbName();
+ if (out.isContainer()) {
+ parentName = out.getChildDBName();
+ }
+ if (in.isContainer()) {
+ childName = in.getChildDBName();
+ }
+ this.edgeQueryToVertex(type, parentName, childName, labels);
+ return (QueryBuilder<Vertex>) this;
+ }
+
+
+ public QueryBuilder<Edge> getEdgesBetweenWithLabels(EdgeType type, String outNodeType, String inNodeType, List<String> labels) throws AAIException {
+ this.edgeQuery(type, outNodeType, inNodeType, labels);
+ return (QueryBuilder<Edge>)this;
+ }
+
+ private void edgeQueryToVertex(EdgeType type, String outType, String inType, List<String> labels) throws AAIException {
+ this.edgeQueryToVertex(type, outType, inType, labels, false);
+ }
+
+ /**
+ * Edge query.
+ *
+ * @param outType the out type
+ * @param inType the in type
+ * @throws NoEdgeRuleFoundException
+ * @throws AAIException
+ */
+ private void edgeQueryToVertex(EdgeType type, String outType, String inType, List<String> labels, boolean isPrivateEdge) throws AAIException {
+ markParentBoundary();
+ Multimap<String, EdgeRule> rules = ArrayListMultimap.create();
+ EdgeRuleQuery.Builder qB = new EdgeRuleQuery.Builder(outType, inType).edgeType(type).setPrivate(isPrivateEdge);
+
+ try {
+ if (labels == null) {
+ rules.putAll(edgeRules.getRules(qB.build()));
+ } else {
+ for (String label : labels) {
+ rules.putAll(edgeRules.getRules(qB.label(label).build()));
+ }
+ }
+ } catch (EdgeRuleNotFoundException e) {
+ throw new NoEdgeRuleFoundException(e);
+ }
+
+ final List<String> inLabels = new ArrayList<>();
+ final List<String> outLabels = new ArrayList<>();
+
+ for (EdgeRule rule : rules.values()) {
+ if (labels != null && !labels.contains(rule.getLabel())) {
+ return;
+ } else {
+ if (Direction.IN.equals(rule.getDirection())) {
+ inLabels.add(rule.getLabel());
+ } else {
+ outLabels.add(rule.getLabel());
+ }
+ }
+ }
+
+ if(inLabels.isEmpty() && outLabels.isEmpty()) {
+ throw new NoEdgeRuleFoundException("no " + type.toString() + " edge rule between " + outType + " and " + inType );
+ } else if (inLabels.isEmpty() && !outLabels.isEmpty()) {
+ list.add(".out('" + String.join("','", outLabels) + "')");
+ } else if (outLabels.isEmpty() && !inLabels.isEmpty()) {
+ list.add(".in('" + String.join("','", inLabels) + "')");
+ } else {
+ list.add(".union(__.in('" + String.join("','", inLabels) + "')" + ", __.out('" + String.join("','", outLabels) + "'))");
+ }
+ stepIndex++;
+ list.add(HAS + AAIProperties.NODE_TYPE + "', '" + inType + "')");
+ stepIndex++;
+
+ }
+
+ /**
+ * Edge query.
+ *
+ * @param outType the out type
+ * @param inType the in type
+ * @throws NoEdgeRuleFoundException
+ * @throws AAIException
+ */
+ private void edgeQuery(EdgeType type, String outType, String inType, List<String> labels) throws AAIException {
+ markParentBoundary();
+ Multimap<String, EdgeRule> rules = ArrayListMultimap.create();
+ EdgeRuleQuery.Builder qB = new EdgeRuleQuery.Builder(outType, inType).edgeType(type);
+ try {
+ if (labels == null) {
+ rules.putAll(edgeRules.getRules(qB.build()));
+ } else {
+ for (String label : labels) {
+ rules.putAll(edgeRules.getRules(qB.label(label).build()));
+ }
+ }
+ } catch (EdgeRuleNotFoundException e) {
+ throw new NoEdgeRuleFoundException(e);
+ }
+
+ final List<String> inLabels = new ArrayList<>();
+ final List<String> outLabels = new ArrayList<>();
+
+ for (EdgeRule rule : rules.values()) {
+ if (labels != null && !labels.contains(rule.getLabel())) {
+ return;
+ } else {
+ if (Direction.IN.equals(rule.getDirection())) {
+ inLabels.add(rule.getLabel());
+ } else {
+ outLabels.add(rule.getLabel());
+ }
+ }
+ }
+
+ if(inLabels.isEmpty() && outLabels.isEmpty()) {
+ throw new NoEdgeRuleFoundException("no " + type.toString() + " edge rule between " + outType + " and " + inType );
+ } else if (inLabels.isEmpty() && !outLabels.isEmpty()) {
+ list.add(".outE('" + String.join("','", outLabels) + "')");
+ } else if (outLabels.isEmpty() && !inLabels.isEmpty()) {
+ list.add(".inE('" + String.join("','", inLabels) + "')");
+ } else {
+ list.add(".union(__.inE('" + String.join("','", inLabels) + "')" + ", __.outE('" + String.join("','", outLabels) + "'))");
+ }
+
+ stepIndex++;
+
+ }
+ @Override
+ public QueryBuilder<E> limit(long amount) {
+ list.add(".limit(" + amount + ")");
+ return this;
+ }
+ /**
+ * @{inheritDoc}
+ */
+ @Override
+ public QueryBuilder<Vertex> createContainerQuery(Introspector obj) {
+ String type = obj.getChildDBName();
+ String abstractType = obj.getMetadata(ObjectMetadata.ABSTRACT);
+ if (abstractType != null) {
+ String[] inheritors = obj.getMetadata(ObjectMetadata.INHERITORS).split(",");
+ String[] wrapped = new String[inheritors.length];
+ StringBuilder command = new StringBuilder();
+ command.append("P.within(");
+ for (int i = 0; i < inheritors.length; i++) {
+ wrapped[i] = "'" + inheritors[i] + "'";
+ }
+ command.append(Joiner.on(",").join(wrapped));
+ command.append(")");
+ list.add(".has('aai-node-type', " + command + ")");
+
+ } else {
+ list.add(".has('aai-node-type', '" + type + "')");
+ }
+ stepIndex++;
+ this.markContainer();
+ return (QueryBuilder<Vertex>) this;
+ }
+
+ @Override
+ public QueryBuilder<E> union(QueryBuilder<E>... builder) {
+ markParentBoundary();
+ String[] traversals = new String[builder.length];
+ StringBuilder command = new StringBuilder();
+ for (int i = 0; i < builder.length; i++) {
+ traversals[i] = "__" + builder[i].getQuery();
+ }
+ command.append(".union(");
+ command.append(Joiner.on(",").join(traversals));
+ command.append(")");
+ list.add(command.toString());
+ stepIndex++;
+
+ return this;
+ }
+
+ @Override
+ public QueryBuilder<E> where(QueryBuilder<E>... builder) {
+ markParentBoundary();
+ List<String> traversals = new ArrayList<>();
+ for (int i = 0; i < builder.length; i++) {
+ traversals.add(".where(__" + builder[i].getQuery() + ")");
+ stepIndex++;
+ }
+ list.addAll(traversals);
+
+
+ return this;
+ }
+
+ @Override
+ public QueryBuilder<E> or(QueryBuilder<E>... builder) {
+ markParentBoundary();
+ String[] traversals = new String[builder.length];
+ StringBuilder command = new StringBuilder();
+ for (int i = 0; i < builder.length; i++) {
+ traversals[i] = "__" + builder[i].getQuery();
+ }
+ command.append(".or(");
+ command.append(Joiner.on(",").join(traversals));
+ command.append(")");
+ list.add(command.toString());
+ stepIndex++;
+
+ return this;
+ }
+
+ @Override
+ public QueryBuilder<E> store(String name) {
+ this.list.add(".store('"+ name + "')");
+ stepIndex++;
+
+ return this;
+ }
+
+ @Override
+ public QueryBuilder<E> cap(String name) {
+ this.list.add(".cap('"+ name + "')");
+ stepIndex++;
+
+ return this;
+ }
+
+ @Override
+ public QueryBuilder<E> unfold() {
+ this.list.add(".unfold()");
+ stepIndex++;
+
+ return this;
+ }
+
+ @Override
+ public QueryBuilder<E> dedup() {
+ this.list.add(".dedup()");
+ stepIndex++;
+
+ return this;
+ }
+
+ @Override
+ public QueryBuilder<E> emit() {
+ this.list.add(".emit()");
+ stepIndex++;
+
+ return this;
+ }
+
+ @Override
+ public QueryBuilder<E> repeat(QueryBuilder<E> builder) {
+ this.list.add(".repeat(__" + builder.getQuery() + ")");
+ stepIndex++;
+
+ return this;
+ }
+
+ @Override
+ public QueryBuilder<E> until(QueryBuilder<E> builder) {
+ this.list.add(".until(__" + builder.getQuery() + ")");
+ stepIndex++;
+
+ return this;
+ }
+
+ @Override
+ public QueryBuilder<E> groupCount() {
+ this.list.add(".groupCount()");
+ stepIndex++;
+
+ return this;
+ }
+
+ @Override
+ public QueryBuilder<E> both() {
+ this.list.add(".both()");
+ stepIndex++;
+
+ return this;
+ }
+
+ @Override
+ public QueryBuilder<Tree> tree() {
+ this.list.add(".tree()");
+ stepIndex++;
+
+ return (QueryBuilder<Tree>)this;
+ }
+
+ @Override
+ public QueryBuilder<E> by(String name) {
+ this.list.add(".by('"+ name + "')");
+ stepIndex++;
+
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public QueryBuilder<E> simplePath(){
+ this.list.add(".simplePath()");
+ stepIndex++;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public QueryBuilder<Path> path(){
+ this.list.add(".path()");
+ stepIndex++;
+ return (QueryBuilder<Path>)this;
+ }
+
+ @Override
+ public QueryBuilder<Edge> outE() {
+ this.list.add(".outE()");
+ stepIndex++;
+
+ return (QueryBuilder<Edge>)this;
+ }
+
+ @Override
+ public QueryBuilder<Edge> inE() {
+ this.list.add(".inE()");
+ stepIndex++;
+
+ return (QueryBuilder<Edge>)this;
+ }
+
+ @Override
+ public QueryBuilder<Vertex> outV() {
+ this.list.add(".outV()");
+ stepIndex++;
+
+ return (QueryBuilder<Vertex>)this;
+ }
+
+ @Override
+ public QueryBuilder<Vertex> inV() {
+ this.list.add(".inV()");
+ stepIndex++;
+
+ return (QueryBuilder<Vertex>)this;
+ }
+
+ @Override
+ public QueryBuilder<E> not(QueryBuilder<E> builder) {
+ this.list.add(".not(" + "__" + builder.getQuery() + ")");
+ stepIndex++;
+
+ return this;
+ }
+
+ @Override
+ public QueryBuilder<E> as(String name) {
+ this.list.add(".as('" + name + "')");
+ stepIndex++;
+
+ return this;
+ }
+
+ @Override
+ public QueryBuilder<E> select(String name) {
+ this.list.add(".select('" + name + "')");
+ stepIndex++;
+
+ return this;
+ }
+ /**
+ * @{inheritDoc}
+ */
+ @Override
+ public QueryBuilder<E> getParentQuery() {
+ return cloneQueryAtStep(parentStepIndex);
+ }
+
+ @Override
+ public QueryBuilder<E> getContainerQuery() {
+ return cloneQueryAtStep(containerStepIndex);
+ }
+
+ /**
+ * @{inheritDoc}
+ */
+ @Override
+ public <T2> T2 getQuery() {
+ StringBuilder sb = new StringBuilder();
+
+ for (String piece : this.list) {
+ sb.append(piece);
+ }
+
+ return (T2)sb.toString();
+ }
+
+ /**
+ * @{inheritDoc}
+ */
+ @Override
+ public void markParentBoundary() {
+ parentStepIndex = stepIndex;
+ }
+
+ @Override
+ public void markContainer() {
+ this.containerStepIndex = stepIndex;
+ }
+
+ /**
+ * @{inheritDoc}
+ */
+ @Override
+ public Vertex getStart() {
+ return this.start;
+ }
+
+ protected int getParentStepIndex() {
+ return parentStepIndex;
+ }
+
+ protected int getContainerStepIndex() {
+ return containerStepIndex;
+ }
+
+ protected int getStepIndex() {
+ return stepIndex;
+ }
+
+ private void executeQuery() {
+ String queryString = "g" + Joiner.on("").join(list);
+ Map<String, Object> params = new HashMap<>();
+ if (this.start == null) {
+ params.put("g", source.V());
+ } else {
+ params.put("g", source.V(this.start));
+ }
+ this.completeTraversal = this.gremlinGroovy.executeTraversal(queryString, params);
+ }
+ @Override
+ public boolean hasNext() {
+ if (this.completeTraversal == null) {
+ executeQuery();
+ }
+
+ return this.completeTraversal.hasNext();
+ }
+
+ @Override
+ public E next() {
+ if (this.completeTraversal == null) {
+ executeQuery();
+ }
+
+ return (E)this.completeTraversal.next();
+ }
+
+ @Override
+ public List<E> toList() {
+ if (this.completeTraversal == null) {
+ executeQuery();
+ }
+
+ return (List<E>)this.completeTraversal.toList();
+ }
+
+ protected QueryBuilder<Edge> has(String key, String value) {
+ this.list.add(HAS + key + "','" + value + "')");
+
+ return (QueryBuilder<Edge>)this;
+ }
+
}
diff --git a/aai-core/src/main/java/org/onap/aai/util/AAIConstants.java b/aai-core/src/main/java/org/onap/aai/util/AAIConstants.java
index cbcbd46e..c7a7b4a1 100644
--- a/aai-core/src/main/java/org/onap/aai/util/AAIConstants.java
+++ b/aai-core/src/main/java/org/onap/aai/util/AAIConstants.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -20,90 +22,91 @@
package org.onap.aai.util;
public final class AAIConstants {
- //
- //
- /** Default to unix file separator if system property file.separator is null */
- public static final String AAI_FILESEP = (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
- //
- /** Default to opt aai if system property aai.home is null, using file.separator */
- public static final String AAI_HOME = (System.getProperty("AJSC_HOME") == null) ? AAI_FILESEP + "opt" + AAI_FILESEP + "app" + AAI_FILESEP +"aai" : System.getProperty("AJSC_HOME");
- public static final String AAI_BUNDLECONFIG_NAME = (System.getProperty("BUNDLECONFIG_DIR") == null) ? "bundleconfig" : System.getProperty("BUNDLECONFIG_DIR");
- public static final String AAI_HOME_BUNDLECONFIG = (System.getProperty("AJSC_HOME") == null) ? AAI_FILESEP + "opt" + AAI_FILESEP + "app" + AAI_FILESEP + "aai" + AAI_FILESEP + AAI_BUNDLECONFIG_NAME : System.getProperty("AJSC_HOME")+ AAI_FILESEP + AAI_BUNDLECONFIG_NAME;
-
- /** etc directory, relative to AAI_HOME */
- public static final String AAI_HOME_ETC = AAI_HOME_BUNDLECONFIG + AAI_FILESEP + "etc" + AAI_FILESEP;
- public static final String AAI_HOME_ETC_APP_PROPERTIES = AAI_HOME_ETC + "appprops" + AAI_FILESEP;
- public static final String AAI_HOME_ETC_AUTH = AAI_HOME_ETC + "auth" + AAI_FILESEP;
- public static final String AAI_CONFIG_FILENAME = AAI_HOME_ETC_APP_PROPERTIES + "aaiconfig.properties";
- public static final String AAI_AUTH_CONFIG_FILENAME = AAI_HOME_ETC_AUTH + "aai_policy.json";
- public static final String REALTIME_DB_CONFIG = AAI_HOME_ETC_APP_PROPERTIES + "janusgraph-realtime.properties";
- public static final String CACHED_DB_CONFIG = AAI_HOME_ETC_APP_PROPERTIES + "janusgraph-cached.properties";
- public static final String AAI_HOME_ETC_OXM = AAI_HOME_ETC + "oxm" + AAI_FILESEP;
- public static final String AAI_EVENT_DMAAP_PROPS = AAI_HOME_ETC_APP_PROPERTIES + "aaiEventDMaaPPublisher.properties";
- public static final String AAI_HOME_ETC_SCRIPT = AAI_HOME_ETC + AAI_FILESEP + "scriptdata" + AAI_FILESEP;
-
- public static final String AAI_LOGBACK_PROPS = "logback.xml";
- public static final String AAI_SCHEMA_MOD_LOGBACK_PROPS = "schemaMod-logback.xml";
- public static final String AAI_FORCE_DELETE_LOGBACK_PROPS = "forceDelete-logback.xml";
-
- public static final String AAI_TRUSTSTORE_FILENAME = "aai.truststore.filename";
- public static final String AAI_TRUSTSTORE_PASSWD = "aai.truststore.passwd";
- public static final String AAI_KEYSTORE_FILENAME = "aai.keystore.filename";
- public static final String AAI_KEYSTORE_PASSWD = "aai.keystore.passwd";
-
- public static final String AAI_SERVER_URL_BASE = "aai.server.url.base";
- public static final String AAI_SERVER_URL = "aai.server.url";
- public static final String AAI_OLDSERVER_URL = "aai.oldserver.url";
- public static final String AAI_LOCAL_REST = "https://localhost:%d/aai/%s/";
-
- public static final int AAI_RESOURCES_PORT = 8447;
- public static final int AAI_QUERY_PORT = 8446;
- public static final int AAI_LEGACY_PORT = 8443;
-
- public static final String AAI_DEFAULT_API_VERSION = "v7";
- public static final String AAI_DEFAULT_API_VERSION_PROP = "aai.default.api.version";
- public static final String AAI_NOTIFICATION_CURRENT_VERSION = "aai.notification.current.version";
-
+ private static final String AJSC_HOME = "AJSC_HOME";
+ //
+ //
+ /** Default to unix file separator if system property file.separator is null */
+ public static final String AAI_FILESEP = (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
+ //
+ /** Default to opt aai if system property aai.home is null, using file.separator */
+ public static final String AAI_HOME = (System.getProperty(AJSC_HOME) == null) ? AAI_FILESEP + "opt" + AAI_FILESEP + "app" + AAI_FILESEP +"aai" : System.getProperty(AJSC_HOME);
+ public static final String AAI_BUNDLECONFIG_NAME = (System.getProperty("BUNDLECONFIG_DIR") == null) ? "bundleconfig" : System.getProperty("BUNDLECONFIG_DIR");
+ public static final String AAI_HOME_BUNDLECONFIG = (System.getProperty(AJSC_HOME) == null) ? AAI_FILESEP + "opt" + AAI_FILESEP + "app" + AAI_FILESEP + "aai" + AAI_FILESEP + AAI_BUNDLECONFIG_NAME : System.getProperty(AJSC_HOME)+ AAI_FILESEP + AAI_BUNDLECONFIG_NAME;
+
+ /** etc directory, relative to AAI_HOME */
+ public static final String AAI_HOME_ETC = AAI_HOME_BUNDLECONFIG + AAI_FILESEP + "etc" + AAI_FILESEP;
+ public static final String AAI_HOME_ETC_APP_PROPERTIES = AAI_HOME_ETC + "appprops" + AAI_FILESEP;
+ public static final String AAI_HOME_ETC_AUTH = AAI_HOME_ETC + "auth" + AAI_FILESEP;
+ public static final String AAI_CONFIG_FILENAME = AAI_HOME_ETC_APP_PROPERTIES + "aaiconfig.properties";
+ public static final String AAI_AUTH_CONFIG_FILENAME = AAI_HOME_ETC_AUTH + "aai_policy.json";
+ public static final String REALTIME_DB_CONFIG = AAI_HOME_ETC_APP_PROPERTIES + "janusgraph-realtime.properties";
+ public static final String CACHED_DB_CONFIG = AAI_HOME_ETC_APP_PROPERTIES + "janusgraph-cached.properties";
+ public static final String AAI_HOME_ETC_OXM = AAI_HOME_ETC + "oxm" + AAI_FILESEP;
+ public static final String AAI_EVENT_DMAAP_PROPS = AAI_HOME_ETC_APP_PROPERTIES + "aaiEventDMaaPPublisher.properties";
+ public static final String AAI_HOME_ETC_SCRIPT = AAI_HOME_ETC + AAI_FILESEP + "scriptdata" + AAI_FILESEP;
+
+ public static final String AAI_LOGBACK_PROPS = "logback.xml";
+ public static final String AAI_SCHEMA_MOD_LOGBACK_PROPS = "schemaMod-logback.xml";
+ public static final String AAI_FORCE_DELETE_LOGBACK_PROPS = "forceDelete-logback.xml";
+
+ public static final String AAI_TRUSTSTORE_FILENAME = "aai.truststore.filename";
+ public static final String AAI_TRUSTSTORE_PASSWD = "aai.truststore.passwd";
+ public static final String AAI_KEYSTORE_FILENAME = "aai.keystore.filename";
+ public static final String AAI_KEYSTORE_PASSWD = "aai.keystore.passwd";
+
+ public static final String AAI_SERVER_URL_BASE = "aai.server.url.base";
+ public static final String AAI_SERVER_URL = "aai.server.url";
+ public static final String AAI_OLDSERVER_URL = "aai.oldserver.url";
+ public static final String AAI_LOCAL_REST = "https://localhost:%d/aai/%s/";
+
+ public static final int AAI_RESOURCES_PORT = 8447;
+ public static final int AAI_QUERY_PORT = 8446;
+ public static final int AAI_LEGACY_PORT = 8443;
+
+ public static final String AAI_DEFAULT_API_VERSION = "v7";
+ public static final String AAI_DEFAULT_API_VERSION_PROP = "aai.default.api.version";
+ public static final String AAI_NOTIFICATION_CURRENT_VERSION = "aai.notification.current.version";
+
public static final String AAI_NODENAME = "aai.config.nodename";
- public static final String AAI_BULKCONSUMER_LIMIT = "aai.bulkconsumer.payloadlimit";
- public static final String AAI_BULKCONSUMER_OVERRIDE_LIMIT = "aai.bulkconsumer.payloadoverride";
+ public static final String AAI_BULKCONSUMER_LIMIT = "aai.bulkconsumer.payloadlimit";
+ public static final String AAI_BULKCONSUMER_OVERRIDE_LIMIT = "aai.bulkconsumer.payloadoverride";
- public static final String AAI_TRAVERSAL_TIMEOUT_LIMIT = "aai.traversal.timeoutlimit";
- public static final String AAI_TRAVERSAL_TIMEOUT_ENABLED = "aai.traversal.timeoutenabled";
- public static final String AAI_TRAVERSAL_TIMEOUT_APP = "aai.traversal.timeout.appspecific";
+ public static final String AAI_TRAVERSAL_TIMEOUT_LIMIT = "aai.traversal.timeoutlimit";
+ public static final String AAI_TRAVERSAL_TIMEOUT_ENABLED = "aai.traversal.timeoutenabled";
+ public static final String AAI_TRAVERSAL_TIMEOUT_APP = "aai.traversal.timeout.appspecific";
- public static final String AAI_GRAPHADMIN_TIMEOUT_LIMIT = "aai.graphadmin.timeoutlimit";
- public static final String AAI_GRAPHADMIN_TIMEOUT_ENABLED = "aai.graphadmin.timeoutenabled";
- public static final String AAI_GRAPHADMIN_TIMEOUT_APP = "aai.graphadmin.timeout.appspecific";
+ public static final String AAI_GRAPHADMIN_TIMEOUT_LIMIT = "aai.graphadmin.timeoutlimit";
+ public static final String AAI_GRAPHADMIN_TIMEOUT_ENABLED = "aai.graphadmin.timeoutenabled";
+ public static final String AAI_GRAPHADMIN_TIMEOUT_APP = "aai.graphadmin.timeout.appspecific";
- public static final String AAI_CRUD_TIMEOUT_LIMIT = "aai.crud.timeoutlimit";
- public static final String AAI_CRUD_TIMEOUT_ENABLED = "aai.crud.timeoutenabled";
- public static final String AAI_CRUD_TIMEOUT_APP = "aai.crud.timeout.appspecific";
+ public static final String AAI_CRUD_TIMEOUT_LIMIT = "aai.crud.timeoutlimit";
+ public static final String AAI_CRUD_TIMEOUT_ENABLED = "aai.crud.timeoutenabled";
+ public static final String AAI_CRUD_TIMEOUT_APP = "aai.crud.timeout.appspecific";
public static final String AAI_RESVERSION_ENABLEFLAG = "aai.resourceversion.enableflag";
- public static final int AAI_GROOMING_DEFAULT_MAX_FIX = 150;
- public static final int AAI_GROOMING_DEFAULT_SLEEP_MINUTES = 7;
-
- public static final int AAI_DUPETOOL_DEFAULT_MAX_FIX = 25;
- public static final int AAI_DUPETOOL_DEFAULT_SLEEP_MINUTES = 7;
-
+ public static final int AAI_GROOMING_DEFAULT_MAX_FIX = 150;
+ public static final int AAI_GROOMING_DEFAULT_SLEEP_MINUTES = 7;
+
+ public static final int AAI_DUPETOOL_DEFAULT_MAX_FIX = 25;
+ public static final int AAI_DUPETOOL_DEFAULT_SLEEP_MINUTES = 7;
+
public static final long HISTORY_MAX_HOURS = 192;
-
- public static final String LOGGING_MAX_STACK_TRACE_ENTRIES = "aai.logging.maxStackTraceEntries";
-
- /*** UEB ***/
- public static final String UEB_PUB_PARTITION_AAI = "AAI";
-
- /** Micro-service Names */
- public static final String AAI_TRAVERSAL_MS = "aai-traversal";
- public static final String AAI_RESOURCES_MS = "aai-resources";
- /**
- * Instantiates a new AAI constants.
- */
- private AAIConstants() {
- // prevent instantiation
- }
+
+ public static final String LOGGING_MAX_STACK_TRACE_ENTRIES = "aai.logging.maxStackTraceEntries";
+
+ /*** UEB ***/
+ public static final String UEB_PUB_PARTITION_AAI = "AAI";
+
+ /** Micro-service Names */
+ public static final String AAI_TRAVERSAL_MS = "aai-traversal";
+ public static final String AAI_RESOURCES_MS = "aai-resources";
+ /**
+ * Instantiates a new AAI constants.
+ */
+ private AAIConstants() {
+ // prevent instantiation
+ }
}
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 ce53d86e..ba2cf9e2 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
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -26,27 +28,34 @@ import java.util.Date;
import java.util.TimeZone;
public class AAIUtils {
+
+ /**
+ * Instantiates AAIUtils.
+ */
+ private AAIUtils() {
+ // prevent instantiation
+ }
- /**
- * Null check.
- *
- * @param <T> the generic type
- * @param iterable the iterable
- * @return the iterable
- */
- public static <T> Iterable<T> nullCheck(Iterable<T> iterable) {
- return iterable == null ? Collections.<T>emptyList() : iterable;
- }
+ /**
+ * Null check.
+ *
+ * @param <T> the generic type
+ * @param iterable the iterable
+ * @return the iterable
+ */
+ public static <T> Iterable<T> nullCheck(Iterable<T> iterable) {
+ return iterable == null ? Collections.<T>emptyList() : iterable;
+ }
- /**
- * Gen date.
- *
- * @return the string
- */
- public static String genDate() {
- Date date = new Date();
- DateFormat formatter = new SimpleDateFormat("YYMMdd-HH:mm:ss:SSS");
- formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
- return formatter.format(date);
- }
+ /**
+ * Gen date.
+ *
+ * @return the string
+ */
+ public static String genDate() {
+ Date date = new Date();
+ 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/AutoGenerateHtml.java b/aai-core/src/main/java/org/onap/aai/util/AutoGenerateHtml.java
index c54f85d1..1745bb04 100644
--- a/aai-core/src/main/java/org/onap/aai/util/AutoGenerateHtml.java
+++ b/aai-core/src/main/java/org/onap/aai/util/AutoGenerateHtml.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -33,45 +35,46 @@ import freemarker.template.TemplateException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class AutoGenerateHtml {
-
- public static final String DEFAULT_SCHEMA_DIR = "../aai-schema";
- //if the program is run from aai-common, use this directory as default"
- public static final String ALT_SCHEMA_DIR = "aai-schema";
- //used to check to see if program is run from aai-core
- public static final String DEFAULT_RUN_DIR = "aai-core";
+
+ private static final String AAI_GENERATE_VERSION = "aai.generate.version";
+ public static final String DEFAULT_SCHEMA_DIR = "../aai-schema";
+ //if the program is run from aai-common, use this directory as default"
+ public static final String ALT_SCHEMA_DIR = "aai-schema";
+ //used to check to see if program is run from aai-core
+ public static final String DEFAULT_RUN_DIR = "aai-core";
- public static void main(String[] args) throws IOException, TemplateException {
- String savedProperty = System.getProperty("aai.generate.version");
+ public static void main(String[] args) throws IOException, TemplateException {
+ String savedProperty = System.getProperty(AAI_GENERATE_VERSION);
- AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
- "org.onap.aai.config",
- "org.onap.aai.setup"
- );
+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
+ "org.onap.aai.config",
+ "org.onap.aai.setup"
+ );
- SchemaVersions schemaVersions = ctx.getBean(SchemaVersions.class);
-
- List<SchemaVersion> versionsToGen = schemaVersions.getVersions();
- Collections.sort(versionsToGen);
- Collections.reverse(versionsToGen);
- ListIterator<SchemaVersion> versionIterator = versionsToGen.listIterator();
- String schemaDir;
- if(System.getProperty("user.dir") != null && !System.getProperty("user.dir").contains(DEFAULT_RUN_DIR)) {
- schemaDir = ALT_SCHEMA_DIR;
- }
- else {
- schemaDir = DEFAULT_SCHEMA_DIR;
- }
- String release = System.getProperty("aai.release", "onap");
- while (versionIterator.hasNext()) {
- System.setProperty("aai.generate.version", versionIterator.next().toString());
- String yamlFile = schemaDir + "/src/main/resources/" + release + "/aai_swagger_yaml/aai_swagger_" + System.getProperty("aai.generate.version")+ ".yaml";
- File swaggerYamlFile = new File(yamlFile);
- if(swaggerYamlFile.exists()) {
- GenerateSwagger.schemaVersions = schemaVersions;
- GenerateSwagger.main(args);
- }
- }
- String versionToGenerate = System.setProperty("aai.generate.version", savedProperty);
- }
+ SchemaVersions schemaVersions = ctx.getBean(SchemaVersions.class);
+
+ List<SchemaVersion> versionsToGen = schemaVersions.getVersions();
+ Collections.sort(versionsToGen);
+ Collections.reverse(versionsToGen);
+ ListIterator<SchemaVersion> versionIterator = versionsToGen.listIterator();
+ String schemaDir;
+ if(System.getProperty("user.dir") != null && !System.getProperty("user.dir").contains(DEFAULT_RUN_DIR)) {
+ schemaDir = ALT_SCHEMA_DIR;
+ }
+ else {
+ schemaDir = DEFAULT_SCHEMA_DIR;
+ }
+ String release = System.getProperty("aai.release", "onap");
+ while (versionIterator.hasNext()) {
+ System.setProperty(AAI_GENERATE_VERSION, versionIterator.next().toString());
+ String yamlFile = schemaDir + "/src/main/resources/" + release + "/aai_swagger_yaml/aai_swagger_" + System.getProperty(AAI_GENERATE_VERSION)+ ".yaml";
+ File swaggerYamlFile = new File(yamlFile);
+ if(swaggerYamlFile.exists()) {
+ GenerateSwagger.schemaVersions = schemaVersions;
+ GenerateSwagger.main(args);
+ }
+ }
+ System.setProperty(AAI_GENERATE_VERSION, savedProperty);
+ }
}
diff --git a/aai-core/src/main/java/org/onap/aai/util/MapperUtil.java b/aai-core/src/main/java/org/onap/aai/util/MapperUtil.java
index 70534d82..4fed0666 100644
--- a/aai-core/src/main/java/org/onap/aai/util/MapperUtil.java
+++ b/aai-core/src/main/java/org/onap/aai/util/MapperUtil.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -26,7 +28,13 @@ import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
public class MapperUtil {
-
+ /**
+ * Instantiates MapperUtil.
+ */
+ private MapperUtil() {
+ // prevent instantiation
+ }
+
/**
* Read as object of.
*
@@ -37,9 +45,9 @@ public class MapperUtil {
* @throws AAIException the AAI exception
*/
public static <T> T readAsObjectOf(Class<T> clazz, String value) throws AAIException {
- ObjectMapper MAPPER = new ObjectMapper();
+ ObjectMapper mapper = new ObjectMapper();
try {
- return MAPPER.readValue(value, clazz);
+ return mapper.readValue(value, clazz);
} catch (Exception e) {
throw new AAIException("AAI_4007", e);
}
@@ -55,13 +63,13 @@ public class MapperUtil {
* @throws AAIException the AAI exception
*/
public static <T> T readWithDashesAsObjectOf(Class<T> clazz, String value) throws AAIException {
- ObjectMapper MAPPER = new ObjectMapper();
+ ObjectMapper mapper = new ObjectMapper();
try {
- MAPPER.registerModule(new JaxbAnnotationModule());
- MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- MAPPER.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);
+ mapper.registerModule(new JaxbAnnotationModule());
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);
- return MAPPER.readValue(value, clazz);
+ return mapper.readValue(value, clazz);
} catch (Exception e) {
throw new AAIException("AAI_4007", e);
}
@@ -75,10 +83,9 @@ public class MapperUtil {
* @throws AAIException the AAI exception
*/
public static String writeAsJSONString(Object obj) throws AAIException {
- ObjectMapper MAPPER = new ObjectMapper();
+ ObjectMapper mapper = new ObjectMapper();
try {
- String s = MAPPER.writeValueAsString(obj);
- return s;
+ return mapper.writeValueAsString(obj);
} catch (Exception e) {
throw new AAIException("AAI_4008", e);
}
@@ -92,20 +99,19 @@ public class MapperUtil {
* @throws AAIException the AAI exception
*/
public static String writeAsJSONStringWithDashes(Object obj) throws AAIException {
- ObjectMapper MAPPER = new ObjectMapper();
+ ObjectMapper mapper = new ObjectMapper();
try {
- MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
- MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
- MAPPER.configure(SerializationFeature.INDENT_OUTPUT, false);
- MAPPER.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
+ mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
+ mapper.configure(SerializationFeature.INDENT_OUTPUT, false);
+ mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
- MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- MAPPER.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);
- MAPPER.registerModule(new JaxbAnnotationModule());
- String s = MAPPER.writeValueAsString(obj);
- return s;
+ mapper.registerModule(new JaxbAnnotationModule());
+ return mapper.writeValueAsString(obj);
} catch (Exception e) {
throw new AAIException("AAI_4008", e);
}
diff --git a/aai-core/src/test/java/org/onap/aai/util/MapperUtilTest.java b/aai-core/src/test/java/org/onap/aai/util/MapperUtilTest.java
index 309d1333..2d68f833 100644
--- a/aai-core/src/test/java/org/onap/aai/util/MapperUtilTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/MapperUtilTest.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -27,44 +29,61 @@ import static org.junit.Assert.assertEquals;
public class MapperUtilTest {
- public class SampleClass {
- private String color;
- private String shape;
-
- public SampleClass(String c, String s){
- color = c;
- shape = s;
- }
+
- public String getColor() {
- return color;
- }
+ private JSONObject expectedJson;
+ private JSONObject sampleJson;
- public void setColor(String color) {
- this.color = color;
- }
+ @Before
+ public void setup(){
+ expectedJson = new JSONObject();
+ sampleJson = new JSONObject();
+ }
- public String getShape() {
- return shape;
- }
+ @Test
+ public void writeAsJSONStringTest() throws Exception {
+ expectedJson.put("color", "black");
+ expectedJson.put("shape", "box");
+ SampleClass sample = new SampleClass("black", "box");
+ assertEquals(expectedJson.toString(), MapperUtil.writeAsJSONString(sample));
+ }
+
+ @Test
+ public void readAsObjectOfTest() throws Exception {
+ sampleJson.put("color", "black");
+ sampleJson.put("shape", "box");
+ SampleClass expectedObject = new SampleClass("black", "box");
+ SampleClass actualObject = MapperUtil.readAsObjectOf(SampleClass.class, sampleJson.toString());
+ assertEquals(expectedObject.getColor(), actualObject.getColor());
+ assertEquals(expectedObject.getShape(), actualObject.getShape());
+ }
+}
- public void setShape(String shape) {
- this.shape = shape;
- }
- }
+class SampleClass {
+ private String color;
+ private String shape;
- private JSONObject expectedJson;
+ public SampleClass() {
+
+ }
+ public SampleClass(String c, String s){
+ color = c;
+ shape = s;
+ }
- @Before
- public void setup(){
- expectedJson = new JSONObject();
- }
+ public String getColor() {
+ return color;
+ }
+
+ public void setColor(String color) {
+ this.color = color;
+ }
+
+ public String getShape() {
+ return shape;
+ }
- @Test
- public void writeAsJSONStringTest() throws Exception {
- expectedJson.put("color", "black");
- expectedJson.put("shape", "box");
- SampleClass sample = new SampleClass("black", "box");
- assertEquals(expectedJson.toString(), MapperUtil.writeAsJSONString(sample));
- }
+ public void setShape(String shape) {
+ this.shape = shape;
+ }
}