aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/application.properties35
-rw-r--r--config/logback.xml30
-rw-r--r--pom.xml356
-rw-r--r--src/main/docker/Dockerfile19
-rw-r--r--src/main/docker/startService.sh8
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/AAIConfiguration.java96
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/Application.java44
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/JerseyConfiguration.java68
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/WebConfiguration.java44
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/common/LogMessages.java32
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/datatype/RelatedToProperty.java91
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/datatype/Relationship.java121
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/datatype/RelationshipDatum.java91
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/datatype/RelationshipList.java81
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/datatype/ServiceInstance.java231
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/datatype/VfModule.java210
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/datatype/VfModules.java81
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/datatype/VnfInstance.java440
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/datatype/VnfcInstance.java231
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/exception/AuditError.java32
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/exception/AuditException.java60
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/model/GenericResponse.java56
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/reader/JsonReader.java186
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/service/ConsumerService.java40
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringService.java27
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringServiceImpl.java66
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestService.java62
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestServiceImpl.java89
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java431
-rw-r--r--src/test/java/org/onap/logging_analytics/pomba/pomba_aai_context_builder/AppTest.java55
30 files changed, 3413 insertions, 0 deletions
diff --git a/config/application.properties b/config/application.properties
new file mode 100644
index 0000000..34a9167
--- /dev/null
+++ b/config/application.properties
@@ -0,0 +1,35 @@
+
+spring.jersey.type=filter
+spring.mvc.urls=swagger,docs,prometheus,auditevents,info,heapdump,autoconfig,beans,loggers,dump,env,trace,health,configprops,mappings,metrics,webjars
+
+
+server.contextPath=/aaicontextbuilder
+spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
+
+#This property is used to set the Tomcat connector attributes.developers can define multiple attributes separated by comma
+#tomcat.connector.attributes=allowTrace-true
+#The max number of active threads in this pool
+server.tomcat.max-threads=200
+#The minimum number of threads always kept alive
+server.tomcat.min-spare-threads=25
+
+# AAI REST Client Configuration
+aai.host=10.147.57.139
+aai.port=8080
+aai.httpProtocol=http
+aai.trustStorePath=tomcat_keystore
+aai.keyStorePath=aai-client-cert.p12
+aai.keyStorePassword=OBF:1i9a1u2a1unz1lr61wn51wn11lss1unz1u301i6o
+aai.keyManagerFactoryAlgorithm=SunX509
+aai.keyStoreType=PKCS12
+aai.securityProtocol=TLS
+aai.connectionTimeout=5000
+aai.readTimeout=1000
+
+# {0} = customerId {1} = serviceType {2} = serviceInstanceId
+aai.serviceInstancePath=/aai/v11/business/customers/customer/{0}/service-subscriptions/service-subscription/{1}/service-instances/service-instance/{2}
+
+
+
+#Servlet context parameters
+server.context_parameters.p-name=value #context parameter with p-name as key and value as value.
diff --git a/config/logback.xml b/config/logback.xml
new file mode 100644
index 0000000..fffaf18
--- /dev/null
+++ b/config/logback.xml
@@ -0,0 +1,30 @@
+<configuration>
+ <property name="p_tim" value="%d{&quot;yyyy-MM-dd'T'HH:mm:ss.SSSXXX&quot;, UTC}"/>
+ <property name="p_lvl" value="%level"/>
+ <property name="p_log" value="%logger"/>
+ <property name="p_mdc" value="%replace(%replace(%mdc){'\t','\\\\t'}){'\n', '\\\\n'}"/>
+ <property name="p_msg" value="%replace(%replace(%msg){'\t', '\\\\t'}){'\n','\\\\n'}"/>
+ <property name="p_exc" value="%replace(%replace(%rootException){'\t', '\\\\t'}){'\n','\\\\n'}"/>
+ <!-- tabs -->
+ <property name="p_mak" value="%replace(%replace(%marker){'\t', '\\\\t'}){'\n','\\\\n'}"/>
+ <property name="p_thr" value="%thread"/>
+ <property name="pattern" value="%nopexception${p_tim}\t${p_thr}\t${p_lvl}\t${p_log}\t${p_mdc}\t${p_msg}\t${p_exc}\t${p_mak}\t%n"/>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>${pattern}</pattern>
+ </encoder>
+ </appender>
+ <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+ <file>output.log</file>
+ <encoder>
+ <pattern>${pattern}</pattern>
+ </encoder>
+ </appender>
+ <logger level="INFO" name="org.onap.logging.ref.slf4j" additivity="false">
+ <appender-ref ref="STDOUT" />
+ <appender-ref ref="FILE" />
+ </logger>
+ <root level="INFO">
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration> \ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..890c471
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,356 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.onap.logging-analytics.pomba</groupId>
+ <artifactId>pomba-aai-context-builder</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+
+ <parent>
+ <groupId>org.onap.oparent</groupId>
+ <artifactId>oparent</artifactId>
+ <version>1.1.1</version>
+ <relativePath />
+ </parent>
+
+ <properties>
+ <aai.rest.client.version>1.2.1</aai.rest.client.version>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <logback.version>1.2.3</logback.version>
+ <swagger.directory>${project.build.directory}/generated-resources/swagger</swagger.directory>
+ <!--docker -->
+ <docker.tag>${project.version}-${timestamp}</docker.tag>
+ <docker.latest.tag>${project.version}-latest</docker.latest.tag>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>1.5.12.RELEASE</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-security</artifactId>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-jersey</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-actuator</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.logging-analytics.pomba</groupId>
+ <artifactId>pomba-audit-common</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </dependency>
+ <!-- logging dependencies -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-slf4j</artifactId>
+ <version>1.2.2-SNAPSHOT</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.att.eelf</groupId>
+ <artifactId>eelf-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.jayway.jsonpath</groupId>
+ <artifactId>json-path</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.aai</groupId>
+ <artifactId>rest-client</artifactId>
+ <version>${aai.rest.client.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.aai</groupId>
+ <artifactId>rest-client</artifactId>
+ <version>${aai.rest.client.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>io.swagger</groupId>
+ <artifactId>swagger-core</artifactId>
+ <version>1.5.9</version>
+ </dependency>
+ <dependency>
+ <groupId>io.swagger</groupId>
+ <artifactId>swagger-annotations</artifactId>
+ <version>1.5.9</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+
+ <resources>
+ <resource>
+ <targetPath>config</targetPath>
+ <directory>config</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ </resources>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>docker</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>io.fabric8</groupId>
+ <artifactId>docker-maven-plugin</artifactId>
+ <version>0.19.1</version>
+ <configuration>
+ <verbose>true</verbose>
+ <apiVersion>1.23</apiVersion>
+ <images>
+ <image>
+ <name>onap/${project.artifactId}</name>
+ <alias>${project.artifactId}</alias>
+ <build>
+ <cleanup>try</cleanup>
+ <dockerFileDir>${project.basedir}/target/docker-stage</dockerFileDir>
+ <tags>
+ <tag>${docker.snapshot.tag}</tag>
+ <tag>${docker.latest.tag}</tag>
+ </tags>
+ </build>
+ </image>
+ </images>
+ </configuration>
+ <executions>
+ <execution>
+ <id>generate-images</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>push-images</id>
+ <phase>deploy</phase>
+ <goals>
+ <goal>build</goal>
+ <goal>push</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>3.1.0</version>
+ <executions>
+ <execution>
+ <id>copy-resources</id>
+ <!-- here the phase you need -->
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.outputDirectory}</outputDirectory>
+ <resources>
+ <resource>
+ <directory>
+ ${project.build.directory}/generated-resources/swagger
+ </directory>
+ <targetPath>META-INF/resources/swagger</targetPath>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>com.github.kongchen</groupId>
+ <artifactId>swagger-maven-plugin</artifactId>
+ <version>3.1.3</version>
+ <configuration>
+ <apiSources>
+ <apiSource>
+ <locations>org.onap.pomba.contextbuilder.aai.service.rs</locations>
+ <basePath>/aaicontextbuilder</basePath>
+ <info>
+ <title>${project.artifactId} Service</title>
+ <version>${project.version}</version>
+ </info>
+ <swaggerDirectory>${swagger.directory}</swaggerDirectory>
+ </apiSource>
+ </apiSources>
+ </configuration>
+ <executions>
+ <execution>
+ <!-- <phase>compile</phase> -->
+ <phase>package</phase>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.6</version>
+ <executions>
+ <execution>
+ <id>copy-dockerfile</id>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals><!-- here the phase you need -->
+ <phase>package</phase>
+ <configuration>
+ <outputDirectory>${project.basedir}/target/docker-stage</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/docker</directory>
+ <includes>
+ <include>Dockerfile</include>
+ </includes>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>copy-properties</id>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <phase>validate</phase>
+ <configuration>
+ <outputDirectory>${project.basedir}/target/docker-stage/config</outputDirectory>
+ <resources>
+ <resource>
+ <directory>config</directory>
+ <includes>
+ <include>*.properties</include>
+ <include>*.xml</include>
+ </includes>
+ <filtering>false</filtering>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>copy-script</id>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <outputDirectory>${project.basedir}/target/docker-stage/</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/docker</directory>
+ <includes>
+ <include>*.sh</include>
+ </includes>
+ <filtering>false</filtering>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>copy-jar</id>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <outputDirectory>${project.basedir}/target/docker-stage/</outputDirectory>
+ <resources>
+ <resource>
+ <directory>target</directory>
+ <includes>
+ <include>*.jar</include>
+ </includes>
+ <filtering>false</filtering>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
diff --git a/src/main/docker/Dockerfile b/src/main/docker/Dockerfile
new file mode 100644
index 0000000..b8a58f8
--- /dev/null
+++ b/src/main/docker/Dockerfile
@@ -0,0 +1,19 @@
+FROM anapsix/alpine-java:jre8
+
+ARG MICROSERVICE_HOME=/opt/app/
+
+# Build up the deployment folder structure
+RUN mkdir -p $MICROSERVICE_HOME
+RUN mkdir -p $MICROSERVICE_HOME/config/
+RUN mkdir -p $MICROSERVICE_HOME/lib/
+RUN mkdir -p $MICROSERVICE_HOME/bin/
+
+ADD pomba-aai-context-builder.jar $MICROSERVICE_HOME/lib/
+COPY config/ $MICROSERVICE_HOME/config/
+ADD startService.sh $MICROSERVICE_HOME/bin/
+
+RUN chmod 755 $MICROSERVICE_HOME/config/*
+RUN chmod 755 $MICROSERVICE_HOME/lib/*
+RUN chmod 755 $MICROSERVICE_HOME/bin/*
+
+CMD ["/opt/app/bin/startService.sh"] \ No newline at end of file
diff --git a/src/main/docker/startService.sh b/src/main/docker/startService.sh
new file mode 100644
index 0000000..88dccf1
--- /dev/null
+++ b/src/main/docker/startService.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+cd /opt/app
+if [ -z "${java_runtime_arguments}" ]; then
+ java -Dlogging.config=config/logback.xml -Xms128m -Xmx512m -jar /opt/app/lib/pomba-aai-context-builder.jar
+else
+ java -Dlogging.config=config/logback.xml $java_runtime_arguments -jar /opt/app/lib/pomba-aai-context-builder.jar
+fi \ No newline at end of file
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/AAIConfiguration.java b/src/main/java/org/onap/pomba/contextbuilder/aai/AAIConfiguration.java
new file mode 100644
index 0000000..7836d6b
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/AAIConfiguration.java
@@ -0,0 +1,96 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai;
+
+
+import org.onap.aai.restclient.client.RestClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+
+//@Component
+@Configuration
+//@ApplicationPath("/")
+public class AAIConfiguration {
+ @Autowired
+ @Value("${aai.host}")
+ private String host;
+ @Autowired
+ @Value("${aai.port}")
+ private String port;
+ @Autowired
+ @Value("${aai.httpProtocol}")
+ private String httpProtocol;
+
+ @Autowired
+ @Value("${aai.trustStorePath}")
+ private String trustStorePath;
+ @Autowired
+ @Value("${aai.keyStorePath}")
+ private String keyStorePath;
+ @Autowired
+ @Value("${aai.keyStorePassword}")
+ private String keyStorePassword;
+
+ @Autowired
+ @Value("${aai.keyManagerFactoryAlgorithm}")
+ private String keyManagerFactoryAlgorithm;
+ @Autowired
+ @Value("${aai.keyStoreType}")
+ private String keyStoreType;
+ @Autowired
+ @Value("${aai.securityProtocol}")
+ private String securityProtocol;
+
+ @Autowired
+ @Value("${aai.connectionTimeout}")
+ private Integer connectionTimeout;
+ @Autowired
+ @Value("${aai.readTimeout}")
+ private Integer readTimeout;
+
+ @Autowired
+ @Value("${aai.serviceInstancePath}")
+ private String serviceInstancePath;
+
+
+
+ @Bean(name="aaiClient")
+ public RestClient restClient() {
+ RestClient restClient = new RestClient();
+ if (httpProtocol.equals("https"))
+ restClient.validateServerHostname(false).validateServerCertChain(false).trustStore(trustStorePath).clientCertFile(keyStorePath).clientCertPassword(keyStorePassword).connectTimeoutMs(connectionTimeout).readTimeoutMs(readTimeout);
+ else
+ restClient.validateServerHostname(false).validateServerCertChain(false).connectTimeoutMs(connectionTimeout).readTimeoutMs(readTimeout);
+ return restClient;
+ }
+
+ @Bean(name="aaiBaseUrl")
+ public String getURL() {
+ return httpProtocol + "://" + host + ":" + port;
+
+ }
+
+ @Bean(name="aaiServiceInstancePath")
+ public String getserviceInstancePathL() {
+ return serviceInstancePath;
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/Application.java b/src/main/java/org/onap/pomba/contextbuilder/aai/Application.java
new file mode 100644
index 0000000..04a063c
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/Application.java
@@ -0,0 +1,44 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.support.SpringBootServletInitializer;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.scheduling.annotation.EnableAsync;
+
+@SpringBootApplication
+@ComponentScan(basePackages = {"org.onap.pomba.contextbuilder.aai"})
+@EnableAsync
+@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
+public class Application extends SpringBootServletInitializer {
+
+ @Override
+ protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
+ return application.sources(Application.class);
+ }
+
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/JerseyConfiguration.java b/src/main/java/org/onap/pomba/contextbuilder/aai/JerseyConfiguration.java
new file mode 100644
index 0000000..58f886a
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/JerseyConfiguration.java
@@ -0,0 +1,68 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.MapperFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import java.util.logging.Logger;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.servlet.ServletProperties;
+import org.onap.pomba.contextbuilder.aai.service.rs.RestServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Component;
+
+@Component
+@ApplicationPath("/")
+public class JerseyConfiguration extends ResourceConfig {
+ private static final Logger log = Logger.getLogger(JerseyConfiguration.class.getName());
+
+ @Bean
+ @Primary
+ public ObjectMapper objectMapper() {
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
+ objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
+ objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
+ return objectMapper;
+ }
+
+ @Autowired
+ public JerseyConfiguration() {
+ register(RestServiceImpl.class);
+ property(ServletProperties.FILTER_FORWARD_ON_404, true);
+ register(new LoggingFeature(log));
+ }
+
+ @Bean
+ public Client jerseyClient() {
+ return ClientBuilder.newClient(
+ new ClientConfig());
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/WebConfiguration.java b/src/main/java/org/onap/pomba/contextbuilder/aai/WebConfiguration.java
new file mode 100644
index 0000000..cd9b7b4
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/WebConfiguration.java
@@ -0,0 +1,44 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+@Configuration
+public class WebConfiguration {
+
+ @Bean
+ public WebMvcConfigurerAdapter forwardToIndex() {
+ return new WebMvcConfigurerAdapter() {
+ @Override
+ public void addViewControllers(ViewControllerRegistry registry) {
+ registry.addViewController("/swagger").setViewName(
+ "redirect:/swagger/index.html");
+ registry.addViewController("/swagger/").setViewName(
+ "redirect:/swagger/index.html");
+ registry.addViewController("/docs").setViewName(
+ "redirect:/docs/html/index.html");
+ registry.addViewController("/docs/").setViewName(
+ "redirect:/docs/html/index.html");
+ }
+ };
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/common/LogMessages.java b/src/main/java/org/onap/pomba/contextbuilder/aai/common/LogMessages.java
new file mode 100644
index 0000000..2e44530
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/common/LogMessages.java
@@ -0,0 +1,32 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.common;
+
+public class LogMessages {
+
+ private LogMessages() {}
+
+ public static final String AAI_CONTEXT_BUILDER_URL = "AAI Context Builder URL ";
+ public static final String HEADER_MESSAGE = "Header {} not present in request, generating new value: {}";
+ public static final String NOT_FOUND = "{} {} is not found from AAI";
+ public static final String NUMBER_OF_API_CALLS = "The number of API calls for {} is {}";
+ public static final String API_CALL_LIST = "API call list for {} is: \n {}";
+ public static final String NUMBER_OF_RELATIONSHIPS_FOUND = "Number of relationships found for: {} are: {}";
+ public static final String RESOURCE_NOT_FOUND = "Resource for {} is not found: {}";
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/RelatedToProperty.java b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/RelatedToProperty.java
new file mode 100644
index 0000000..88b9d7a
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/RelatedToProperty.java
@@ -0,0 +1,91 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.datatype;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+public class RelatedToProperty {
+
+ @SerializedName("property-key")
+ @Expose
+ private String propertyKey;
+ @SerializedName("property-value")
+ @Expose
+ private String propertyValue;
+
+ /**
+ * No args constructor for use in serialization
+ *
+ */
+ public RelatedToProperty() {
+ }
+
+ /**
+ *
+ * @param propertyKey
+ * @param propertyValue
+ */
+ public RelatedToProperty(String propertyKey, String propertyValue) {
+ super();
+ this.propertyKey = propertyKey;
+ this.propertyValue = propertyValue;
+ }
+
+ public String getPropertyKey() {
+ return propertyKey;
+ }
+
+ public void setPropertyKey(String propertyKey) {
+ this.propertyKey = propertyKey;
+ }
+
+ public String getPropertyValue() {
+ return propertyValue;
+ }
+
+ public void setPropertyValue(String propertyValue) {
+ this.propertyValue = propertyValue;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("propertyKey", propertyKey).append("propertyValue", propertyValue).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder().append(propertyKey).append(propertyValue).toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof RelatedToProperty)) {
+ return false;
+ }
+ RelatedToProperty rhs = ((RelatedToProperty) other);
+ return new EqualsBuilder().append(propertyKey, rhs.propertyKey).append(propertyValue, rhs.propertyValue).isEquals();
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/Relationship.java b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/Relationship.java
new file mode 100644
index 0000000..edf9d84
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/Relationship.java
@@ -0,0 +1,121 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.datatype;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import java.util.List;
+import javax.validation.Valid;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+public class Relationship {
+
+ @SerializedName("related-to")
+ @Expose
+ private String relatedTo;
+ @SerializedName("related-link")
+ @Expose
+ private String relatedLink;
+ @SerializedName("relationship-data")
+ @Expose
+ @Valid
+ private List<RelationshipDatum> relationshipData = null;
+ @SerializedName("related-to-property")
+ @Expose
+ @Valid
+ private List<RelatedToProperty> relatedToProperty = null;
+
+ /**
+ * No args constructor for use in serialization
+ *
+ */
+ public Relationship() {
+ }
+
+ /**
+ *
+ * @param relatedToProperty
+ * @param relatedLink
+ * @param relationshipData
+ * @param relatedTo
+ */
+ public Relationship(String relatedTo, String relatedLink, List<RelationshipDatum> relationshipData, List<RelatedToProperty> relatedToProperty) {
+ super();
+ this.relatedTo = relatedTo;
+ this.relatedLink = relatedLink;
+ this.relationshipData = relationshipData;
+ this.relatedToProperty = relatedToProperty;
+ }
+
+ public String getRelatedTo() {
+ return relatedTo;
+ }
+
+ public void setRelatedTo(String relatedTo) {
+ this.relatedTo = relatedTo;
+ }
+
+ public String getRelatedLink() {
+ return relatedLink;
+ }
+
+ public void setRelatedLink(String relatedLink) {
+ this.relatedLink = relatedLink;
+ }
+
+ public List<RelationshipDatum> getRelationshipData() {
+ return relationshipData;
+ }
+
+ public void setRelationshipData(List<RelationshipDatum> relationshipData) {
+ this.relationshipData = relationshipData;
+ }
+
+ public List<RelatedToProperty> getRelatedToProperty() {
+ return relatedToProperty;
+ }
+
+ public void setRelatedToProperty(List<RelatedToProperty> relatedToProperty) {
+ this.relatedToProperty = relatedToProperty;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("relatedTo", relatedTo).append("relatedLink", relatedLink).append("relationshipData", relationshipData).append("relatedToProperty", relatedToProperty).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder().append(relatedToProperty).append(relatedLink).append(relationshipData).append(relatedTo).toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof Relationship)) {
+ return false;
+ }
+ Relationship rhs = ((Relationship) other);
+ return new EqualsBuilder().append(relatedToProperty, rhs.relatedToProperty).append(relatedLink, rhs.relatedLink).append(relationshipData, rhs.relationshipData).append(relatedTo, rhs.relatedTo).isEquals();
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/RelationshipDatum.java b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/RelationshipDatum.java
new file mode 100644
index 0000000..9d50ed9
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/RelationshipDatum.java
@@ -0,0 +1,91 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.datatype;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+public class RelationshipDatum {
+
+ @SerializedName("relationship-key")
+ @Expose
+ private String relationshipKey;
+ @SerializedName("relationship-value")
+ @Expose
+ private String relationshipValue;
+
+ /**
+ * No args constructor for use in serialization
+ *
+ */
+ public RelationshipDatum() {
+ }
+
+ /**
+ *
+ * @param relationshipValue
+ * @param relationshipKey
+ */
+ public RelationshipDatum(String relationshipKey, String relationshipValue) {
+ super();
+ this.relationshipKey = relationshipKey;
+ this.relationshipValue = relationshipValue;
+ }
+
+ public String getRelationshipKey() {
+ return relationshipKey;
+ }
+
+ public void setRelationshipKey(String relationshipKey) {
+ this.relationshipKey = relationshipKey;
+ }
+
+ public String getRelationshipValue() {
+ return relationshipValue;
+ }
+
+ public void setRelationshipValue(String relationshipValue) {
+ this.relationshipValue = relationshipValue;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("relationshipKey", relationshipKey).append("relationshipValue", relationshipValue).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder().append(relationshipValue).append(relationshipKey).toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof RelationshipDatum)) {
+ return false;
+ }
+ RelationshipDatum rhs = ((RelationshipDatum) other);
+ return new EqualsBuilder().append(relationshipValue, rhs.relationshipValue).append(relationshipKey, rhs.relationshipKey).isEquals();
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/RelationshipList.java b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/RelationshipList.java
new file mode 100644
index 0000000..3899257
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/RelationshipList.java
@@ -0,0 +1,81 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.datatype;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import java.util.List;
+import javax.validation.Valid;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+public class RelationshipList {
+
+ @SerializedName("relationship")
+ @Expose
+ @Valid
+ private List<Relationship> relationship = null;
+
+ /**
+ * No args constructor for use in serialization
+ *
+ */
+ public RelationshipList() {
+ }
+
+ /**
+ *
+ * @param relationship
+ */
+ public RelationshipList(List<Relationship> relationship) {
+ super();
+ this.relationship = relationship;
+ }
+
+ public List<Relationship> getRelationship() {
+ return relationship;
+ }
+
+ public void setRelationship(List<Relationship> relationship) {
+ this.relationship = relationship;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("relationship", relationship).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder().append(relationship).toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof RelationshipList)) {
+ return false;
+ }
+ RelationshipList rhs = ((RelationshipList) other);
+ return new EqualsBuilder().append(relationship, rhs.relationship).isEquals();
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/ServiceInstance.java b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/ServiceInstance.java
new file mode 100644
index 0000000..bd67d63
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/ServiceInstance.java
@@ -0,0 +1,231 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.datatype;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import javax.validation.Valid;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.onap.pomba.contextbuilder.aai.exception.AuditError;
+import org.onap.pomba.contextbuilder.aai.exception.AuditException;
+
+public class ServiceInstance {
+
+ @SerializedName("service-instance-id")
+ @Expose
+ private String serviceInstanceId;
+ @SerializedName("service-instance-name")
+ @Expose
+ private String serviceInstanceName;
+ @SerializedName("service-type")
+ @Expose
+ private String serviceType;
+ @SerializedName("service-role")
+ @Expose
+ private String serviceRole;
+ @SerializedName("environment-context")
+ @Expose
+ private String environmentContext;
+ @SerializedName("workload-context")
+ @Expose
+ private String workloadContext;
+ @SerializedName("model-invariant-id")
+ @Expose
+ private String modelInvariantId;
+ @SerializedName("model-version-id")
+ @Expose
+ private String modelVersionId;
+ @SerializedName("resource-version")
+ @Expose
+ private String resourceVersion;
+ @SerializedName("orchestration-status")
+ @Expose
+ private String orchestrationStatus;
+ @SerializedName("relationship-list")
+ @Expose
+ @Valid
+ private RelationshipList relationshipList;
+
+ private static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
+
+ public String toJson() {
+ return gson.toJson(this);
+ }
+
+ public static ServiceInstance fromJson(String payload) throws AuditException {
+ try {
+ if (payload == null || payload.isEmpty()) {
+ throw new AuditException("Empty Json response");
+ }
+ return gson.fromJson(payload, ServiceInstance.class);
+ } catch (Exception ex) {
+ throw new AuditException(AuditError.JSON_READER_PARSE_ERROR, ex);
+ }
+ }
+
+ /**
+ * No args constructor for use in serialization
+ *
+ */
+ public ServiceInstance() {
+ }
+
+ /**
+ *
+ * @param serviceRole
+ * @param serviceInstanceName
+ * @param orchestrationStatus
+ * @param serviceType
+ * @param modelInvariantId
+ * @param workloadContext
+ * @param environmentContext
+ * @param resourceVersion
+ * @param relationshipList
+ * @param modelVersionId
+ * @param serviceInstanceId
+ */
+ public ServiceInstance(String serviceInstanceId, String serviceInstanceName, String serviceType, String serviceRole, String environmentContext, String workloadContext, String modelInvariantId, String modelVersionId, String resourceVersion, String orchestrationStatus, RelationshipList relationshipList) {
+ super();
+ this.serviceInstanceId = serviceInstanceId;
+ this.serviceInstanceName = serviceInstanceName;
+ this.serviceType = serviceType;
+ this.serviceRole = serviceRole;
+ this.environmentContext = environmentContext;
+ this.workloadContext = workloadContext;
+ this.modelInvariantId = modelInvariantId;
+ this.modelVersionId = modelVersionId;
+ this.resourceVersion = resourceVersion;
+ this.orchestrationStatus = orchestrationStatus;
+ this.relationshipList = relationshipList;
+ }
+
+ public String getServiceInstanceId() {
+ return serviceInstanceId;
+ }
+
+ public void setServiceInstanceId(String serviceInstanceId) {
+ this.serviceInstanceId = serviceInstanceId;
+ }
+
+ public String getServiceInstanceName() {
+ return serviceInstanceName;
+ }
+
+ public void setServiceInstanceName(String serviceInstanceName) {
+ this.serviceInstanceName = serviceInstanceName;
+ }
+
+ public String getServiceType() {
+ return serviceType;
+ }
+
+ public void setServiceType(String serviceType) {
+ this.serviceType = serviceType;
+ }
+
+ public String getServiceRole() {
+ return serviceRole;
+ }
+
+ public void setServiceRole(String serviceRole) {
+ this.serviceRole = serviceRole;
+ }
+
+ public String getEnvironmentContext() {
+ return environmentContext;
+ }
+
+ public void setEnvironmentContext(String environmentContext) {
+ this.environmentContext = environmentContext;
+ }
+
+ public String getWorkloadContext() {
+ return workloadContext;
+ }
+
+ public void setWorkloadContext(String workloadContext) {
+ this.workloadContext = workloadContext;
+ }
+
+ public String getModelInvariantId() {
+ return modelInvariantId;
+ }
+
+ public void setModelInvariantId(String modelInvariantId) {
+ this.modelInvariantId = modelInvariantId;
+ }
+
+ public String getModelVersionId() {
+ return modelVersionId;
+ }
+
+ public void setModelVersionId(String modelVersionId) {
+ this.modelVersionId = modelVersionId;
+ }
+
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
+
+ public String getOrchestrationStatus() {
+ return orchestrationStatus;
+ }
+
+ public void setOrchestrationStatus(String orchestrationStatus) {
+ this.orchestrationStatus = orchestrationStatus;
+ }
+
+ public RelationshipList getRelationshipList() {
+ return relationshipList;
+ }
+
+ public void setRelationshipList(RelationshipList relationshipList) {
+ this.relationshipList = relationshipList;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("serviceInstanceId", serviceInstanceId).append("serviceInstanceName", serviceInstanceName).append("serviceType", serviceType).append("serviceRole", serviceRole).append("environmentContext", environmentContext).append("workloadContext", workloadContext).append("modelInvariantId", modelInvariantId).append("modelVersionId", modelVersionId).append("resourceVersion", resourceVersion).append("orchestrationStatus", orchestrationStatus).append("relationshipList", relationshipList).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder().append(serviceRole).append(serviceInstanceName).append(orchestrationStatus).append(serviceType).append(modelInvariantId).append(workloadContext).append(environmentContext).append(resourceVersion).append(relationshipList).append(modelVersionId).append(serviceInstanceId).toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof ServiceInstance)) {
+ return false;
+ }
+ ServiceInstance rhs = ((ServiceInstance) other);
+ return new EqualsBuilder().append(serviceRole, rhs.serviceRole).append(serviceInstanceName, rhs.serviceInstanceName).append(orchestrationStatus, rhs.orchestrationStatus).append(serviceType, rhs.serviceType).append(modelInvariantId, rhs.modelInvariantId).append(workloadContext, rhs.workloadContext).append(environmentContext, rhs.environmentContext).append(resourceVersion, rhs.resourceVersion).append(relationshipList, rhs.relationshipList).append(modelVersionId, rhs.modelVersionId).append(serviceInstanceId, rhs.serviceInstanceId).isEquals();
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/VfModule.java b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/VfModule.java
new file mode 100644
index 0000000..33312ee
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/VfModule.java
@@ -0,0 +1,210 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.datatype;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import javax.validation.Valid;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+public class VfModule {
+
+ @SerializedName("vf-module-id")
+ @Expose
+ private String vfModuleId;
+ @SerializedName("vf-module-name")
+ @Expose
+ private String vfModuleName;
+ @SerializedName("heat-stack-id")
+ @Expose
+ private String heatStackId;
+ @SerializedName("orchestration-status")
+ @Expose
+ private String orchestrationStatus;
+ @SerializedName("is-base-vf-module")
+ @Expose
+ private Boolean isBaseVfModule;
+ @SerializedName("resource-version")
+ @Expose
+ private String resourceVersion;
+ @SerializedName("model-invariant-id")
+ @Expose
+ private String modelInvariantId;
+ @SerializedName("model-version-id")
+ @Expose
+ private String modelVersionId;
+ @SerializedName("model-customization-id")
+ @Expose
+ private String modelCustomizationId;
+ @SerializedName("module-index")
+ @Expose
+ private Integer moduleIndex;
+ @SerializedName("relationship-list")
+ @Expose
+ @Valid
+ private RelationshipList relationshipList;
+
+ /**
+ * No args constructor for use in serialization
+ *
+ */
+ public VfModule() {
+ }
+
+ /**
+ *
+ * @param modelCustomizationId
+ * @param moduleIndex
+ * @param vfModuleName
+ * @param orchestrationStatus
+ * @param vfModuleId
+ * @param modelInvariantId
+ * @param heatStackId
+ * @param isBaseVfModule
+ * @param resourceVersion
+ * @param relationshipList
+ * @param modelVersionId
+ */
+ public VfModule(String vfModuleId, String vfModuleName, String heatStackId, String orchestrationStatus, Boolean isBaseVfModule, String resourceVersion, String modelInvariantId, String modelVersionId, String modelCustomizationId, Integer moduleIndex, RelationshipList relationshipList) {
+ super();
+ this.vfModuleId = vfModuleId;
+ this.vfModuleName = vfModuleName;
+ this.heatStackId = heatStackId;
+ this.orchestrationStatus = orchestrationStatus;
+ this.isBaseVfModule = isBaseVfModule;
+ this.resourceVersion = resourceVersion;
+ this.modelInvariantId = modelInvariantId;
+ this.modelVersionId = modelVersionId;
+ this.modelCustomizationId = modelCustomizationId;
+ this.moduleIndex = moduleIndex;
+ this.relationshipList = relationshipList;
+ }
+
+ public String getVfModuleId() {
+ return vfModuleId;
+ }
+
+ public void setVfModuleId(String vfModuleId) {
+ this.vfModuleId = vfModuleId;
+ }
+
+ public String getVfMduleName() {
+ return vfModuleName;
+ }
+
+ public void setVfModuleName(String vfModuleName) {
+ this.vfModuleName = vfModuleName;
+ }
+
+ public String getHeatStackId() {
+ return heatStackId;
+ }
+
+ public void setHeatStackId(String heatStackId) {
+ this.heatStackId = heatStackId;
+ }
+
+ public String getOrchestrationStatus() {
+ return orchestrationStatus;
+ }
+
+ public void setOrchestrationStatus(String orchestrationStatus) {
+ this.orchestrationStatus = orchestrationStatus;
+ }
+
+ public Boolean getIsBaseVfModule() {
+ return isBaseVfModule;
+ }
+
+ public void setIsBaseVfModule(Boolean isBaseVfModule) {
+ this.isBaseVfModule = isBaseVfModule;
+ }
+
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
+
+ public String getModelInvariantId() {
+ return modelInvariantId;
+ }
+
+ public void setModelInvariantId(String modelInvariantId) {
+ this.modelInvariantId = modelInvariantId;
+ }
+
+ public String getModelVersionId() {
+ return modelVersionId;
+ }
+
+ public void setModelVersionId(String modelVersionId) {
+ this.modelVersionId = modelVersionId;
+ }
+
+ public String getModelCustomizationId() {
+ return modelCustomizationId;
+ }
+
+ public void setModelCustomizationId(String modelCustomizationId) {
+ this.modelCustomizationId = modelCustomizationId;
+ }
+
+ public Integer getModuleIndex() {
+ return moduleIndex;
+ }
+
+ public void setModuleIndex(Integer moduleIndex) {
+ this.moduleIndex = moduleIndex;
+ }
+
+ public RelationshipList getRelationshipList() {
+ return relationshipList;
+ }
+
+ public void setRelationshipList(RelationshipList relationshipList) {
+ this.relationshipList = relationshipList;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("vfModuleId", vfModuleId).append("vfModuleName", vfModuleName).append("heatStackId", heatStackId).append("orchestrationStatus", orchestrationStatus).append("isBaseVfModule", isBaseVfModule).append("resourceVersion", resourceVersion).append("modelInvariantId", modelInvariantId).append("modelVersionId", modelVersionId).append("modelCustomizationId", modelCustomizationId).append("moduleIndex", moduleIndex).append("relationshipList", relationshipList).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder().append(modelCustomizationId).append(moduleIndex).append(vfModuleName).append(orchestrationStatus).append(vfModuleId).append(modelInvariantId).append(heatStackId).append(isBaseVfModule).append(resourceVersion).append(relationshipList).append(modelVersionId).toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof VfModule)) {
+ return false;
+ }
+ VfModule rhs = ((VfModule) other);
+ return new EqualsBuilder().append(modelCustomizationId, rhs.modelCustomizationId).append(moduleIndex, rhs.moduleIndex).append(vfModuleName, rhs.vfModuleName).append(orchestrationStatus, rhs.orchestrationStatus).append(vfModuleId, rhs.vfModuleId).append(modelInvariantId, rhs.modelInvariantId).append(heatStackId, rhs.heatStackId).append(isBaseVfModule, rhs.isBaseVfModule).append(resourceVersion, rhs.resourceVersion).append(relationshipList, rhs.relationshipList).append(modelVersionId, rhs.modelVersionId).isEquals();
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/VfModules.java b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/VfModules.java
new file mode 100644
index 0000000..d81f3c5
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/VfModules.java
@@ -0,0 +1,81 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.datatype;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import java.util.List;
+import javax.validation.Valid;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+public class VfModules {
+
+ @SerializedName("vf-module")
+ @Expose
+ @Valid
+ private List<VfModule> vfModule = null;
+
+ /**
+ * No args constructor for use in serialization
+ *
+ */
+ public VfModules() {
+ }
+
+ /**
+ *
+ * @param vf_module
+ */
+ public VfModules(List<VfModule> vfModule) {
+ super();
+ this.vfModule = vfModule;
+ }
+
+ public List<VfModule> getVfModule() {
+ return vfModule;
+ }
+
+ public void setVfModule(List<VfModule> vfModule) {
+ this.vfModule = vfModule;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("vfModule", vfModule).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder().append(vfModule).toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof VfModules)) {
+ return false;
+ }
+ VfModules rhs = ((VfModules) other);
+ return new EqualsBuilder().append(vfModule, rhs.vfModule).isEquals();
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/VnfInstance.java b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/VnfInstance.java
new file mode 100644
index 0000000..26949ed
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/VnfInstance.java
@@ -0,0 +1,440 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.datatype;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import javax.validation.Valid;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.onap.pomba.contextbuilder.aai.exception.AuditError;
+import org.onap.pomba.contextbuilder.aai.exception.AuditException;
+
+public class VnfInstance {
+
+ @SerializedName("vnf-id")
+ @Expose
+ private String vnfId;
+ @SerializedName("vnf-name")
+ @Expose
+ private String vnfName;
+ @SerializedName("vnf-name2")
+ @Expose
+ private String vnfName2;
+ @SerializedName("vnf-type")
+ @Expose
+ private String vnfType;
+ @SerializedName("service-id")
+ @Expose
+ private String serviceId;
+ @SerializedName("prov-status")
+ @Expose
+ private String provisionStatus;
+ @SerializedName("license-key")
+ @Expose
+ private String licenseKey;
+ @SerializedName("equipment-role")
+ @Expose
+ private String equipmentRole;
+ @SerializedName("orchestration-status")
+ @Expose
+ private String orchestrationStatus;
+ @SerializedName("heat-stack-id")
+ @Expose
+ private String heatStackId;
+ @SerializedName("mso-catalog-key")
+ @Expose
+ private String msoCatalogKey;
+ @SerializedName("ipv4-oam-address")
+ @Expose
+ private String ipv4OamAddress;
+ @SerializedName("ipv4-loopback0-address")
+ @Expose
+ private String ipv4Loopback0Address;
+ @SerializedName("nm-lan-v6-address")
+ @Expose
+ private String nmLanV6Address;
+ @SerializedName("management-v6-address")
+ @Expose
+ private String managementV6Address;
+ @SerializedName("in-maint")
+ @Expose
+ private Boolean inMaintenance;
+ @SerializedName("is-closed-loop-disabled")
+ @Expose
+ private Boolean isClosedLoopDisabled;
+ @SerializedName("resource-version")
+ @Expose
+ private String resourceVersion;
+ @SerializedName("model-invariant-id")
+ @Expose
+ private String modelInvariantId;
+ @SerializedName("model-version-id")
+ @Expose
+ private String modelVersionId;
+ @SerializedName("model-customization-id")
+ @Expose
+ private String modelCustomizationId;
+ @SerializedName("nf-type")
+ @Expose
+ private String nfType;
+ @SerializedName("nf-function")
+ @Expose
+ private String nfFunction;
+ @SerializedName("nf-role")
+ @Expose
+ private String nfRole;
+ @SerializedName("nf-naming-code")
+ @Expose
+ private String nfNamingCode;
+ @SerializedName("relationship-list")
+ @Expose
+ @Valid
+ private RelationshipList relationshipList;
+ @SerializedName("vf-modules")
+ @Expose
+ @Valid
+ private VfModules vfModules;
+
+ private static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
+
+ public String toJson() {
+ return gson.toJson(this);
+ }
+
+ public static VnfInstance fromJson(String payload) throws AuditException {
+ try {
+ if (payload == null || payload.isEmpty()) {
+ throw new AuditException("Empty Json response");
+ }
+ return gson.fromJson(payload, VnfInstance.class);
+ } catch (Exception ex) {
+ throw new AuditException(AuditError.JSON_READER_PARSE_ERROR, ex);
+ }
+ }
+
+ /**
+ * No args constructor for use in serialization
+ *
+ */
+ public VnfInstance() {
+ }
+
+ /**
+ *
+ * @param serviceId
+ * @param modelCustomizationId
+ * @param vnfType
+ * @param ipv4Loopback0Address
+ * @param nfFunction
+ * @param modelInvariantId
+ * @param resourceVersion
+ * @param vnfName2
+ * @param relationshipList
+ * @param nmLanV6Address
+ * @param nfRole
+ * @param nfType
+ * @param modelVersionId
+ * @param ipv4OamAddress
+ * @param vnfName
+ * @param inMaintenance
+ * @param msoCatalogKey
+ * @param provisionStatus
+ * @param vfModules
+ * @param equipmentRole
+ * @param vnfId
+ * @param orchestrationStatus
+ * @param nfNamingCode
+ * @param heatStackId
+ * @param isClosedLoopDisabled
+ * @param licenseKey
+ * @param managementV6Address
+ */
+ public VnfInstance(String vnfId, String vnfName, String vnfName2, String vnfType, String serviceId, String provisionStatus, String licenseKey, String equipmentRole, String orchestrationStatus, String heatStackId, String msoCatalogKey, String ipv4OamAddress, String ipv4Loopback0Address, String nmLanV6Address, String managementV6Address, Boolean inMaintenance, Boolean isClosedLoopDisabled, String resourceVersion, String modelInvariantId, String modelVersionId, String modelCustomizationId, String nfType, String nfFunction, String nfRole, String nfNamingCode, RelationshipList relationshipList, VfModules vfModules) {
+ super();
+ this.vnfId = vnfId;
+ this.vnfName = vnfName;
+ this.vnfName2 = vnfName2;
+ this.vnfType = vnfType;
+ this.serviceId = serviceId;
+ this.provisionStatus = provisionStatus;
+ this.licenseKey = licenseKey;
+ this.equipmentRole = equipmentRole;
+ this.orchestrationStatus = orchestrationStatus;
+ this.heatStackId = heatStackId;
+ this.msoCatalogKey = msoCatalogKey;
+ this.ipv4OamAddress = ipv4OamAddress;
+ this.ipv4Loopback0Address = ipv4Loopback0Address;
+ this.nmLanV6Address = nmLanV6Address;
+ this.managementV6Address = managementV6Address;
+ this.inMaintenance = inMaintenance;
+ this.isClosedLoopDisabled = isClosedLoopDisabled;
+ this.resourceVersion = resourceVersion;
+ this.modelInvariantId = modelInvariantId;
+ this.modelVersionId = modelVersionId;
+ this.modelCustomizationId = modelCustomizationId;
+ this.nfType = nfType;
+ this.nfFunction = nfFunction;
+ this.nfRole = nfRole;
+ this.nfNamingCode = nfNamingCode;
+ this.relationshipList = relationshipList;
+ this.vfModules = vfModules;
+ }
+
+ public String getVnfId() {
+ return vnfId;
+ }
+
+ public void setVnfId(String vnfId) {
+ this.vnfId = vnfId;
+ }
+
+ public String getVnfName() {
+ return vnfName;
+ }
+
+ public void setVnfName(String vnfName) {
+ this.vnfName = vnfName;
+ }
+
+ public String getVnfName2() {
+ return vnfName2;
+ }
+
+ public void setVnfName2(String vnfName2) {
+ this.vnfName2 = vnfName2;
+ }
+
+ public String getVnfType() {
+ return vnfType;
+ }
+
+ public void setVnfType(String vnfType) {
+ this.vnfType = vnfType;
+ }
+
+ public String getServiceId() {
+ return serviceId;
+ }
+
+ public void setServiceId(String serviceId) {
+ this.serviceId = serviceId;
+ }
+
+ public String getProvisionStatus() {
+ return provisionStatus;
+ }
+
+ public void setProvisionStatus(String provisionStatus) {
+ this.provisionStatus = provisionStatus;
+ }
+
+ public String getLicenseKey() {
+ return licenseKey;
+ }
+
+ public void setLicenseKey(String licenseKey) {
+ this.licenseKey = licenseKey;
+ }
+
+ public String getEquipmentRole() {
+ return equipmentRole;
+ }
+
+ public void setEquipmentRole(String equipmentRole) {
+ this.equipmentRole = equipmentRole;
+ }
+
+ public String getOrchestrationStatus() {
+ return orchestrationStatus;
+ }
+
+ public void setoOrchestrationStatus(String orchestrationStatus) {
+ this.orchestrationStatus = orchestrationStatus;
+ }
+
+ public String getHeatStackId() {
+ return heatStackId;
+ }
+
+ public void setHeatStackId(String heatStackId) {
+ this.heatStackId = heatStackId;
+ }
+
+ public String getMsoCatalogKey() {
+ return msoCatalogKey;
+ }
+
+ public void setMsoCatalogKey(String msoCatalogKey) {
+ this.msoCatalogKey = msoCatalogKey;
+ }
+
+ public String getIpv4OamAddress() {
+ return ipv4OamAddress;
+ }
+
+ public void setIpv4OamAddress(String ipv4OamAddress) {
+ this.ipv4OamAddress = ipv4OamAddress;
+ }
+
+ public String getIpv4Loopback0Address() {
+ return ipv4Loopback0Address;
+ }
+
+ public void setIpv4Loopback0Address(String ipv4Loopback0Address) {
+ this.ipv4Loopback0Address = ipv4Loopback0Address;
+ }
+
+ public String getNmLanV6Address() {
+ return nmLanV6Address;
+ }
+
+ public void setNmLanV6Address(String nmLanV6Address) {
+ this.nmLanV6Address = nmLanV6Address;
+ }
+
+ public String getManagementV6Address() {
+ return managementV6Address;
+ }
+
+ public void setManagementV6Address(String managementV6Address) {
+ this.managementV6Address = managementV6Address;
+ }
+
+ public Boolean getInMaintenance() {
+ return inMaintenance;
+ }
+
+ public void setInMaintenance(Boolean inMaintenance) {
+ this.inMaintenance = inMaintenance;
+ }
+
+ public Boolean getIsClosedLoopDisabled() {
+ return isClosedLoopDisabled;
+ }
+
+ public void setIsClosedLoopDisabled(Boolean isClosedLoopDisabled) {
+ this.isClosedLoopDisabled = isClosedLoopDisabled;
+ }
+
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
+
+ public String getModelInvariantId() {
+ return modelInvariantId;
+ }
+
+ public void setModelInvariantId(String modelInvariantId) {
+ this.modelInvariantId = modelInvariantId;
+ }
+
+ public String getModelVersionId() {
+ return modelVersionId;
+ }
+
+ public void setModelVersionId(String modelVersionId) {
+ this.modelVersionId = modelVersionId;
+ }
+
+ public String getModelCustomizationId() {
+ return modelCustomizationId;
+ }
+
+ public void setModelCustomizationId(String modelCustomizationId) {
+ this.modelCustomizationId = modelCustomizationId;
+ }
+
+ public String getNfType() {
+ return nfType;
+ }
+
+ public void setNfType(String nfType) {
+ this.nfType = nfType;
+ }
+
+ public String getNfFunction() {
+ return nfFunction;
+ }
+
+ public void setNfFunction(String nfFunction) {
+ this.nfFunction = nfFunction;
+ }
+
+ public String getNfRole() {
+ return nfRole;
+ }
+
+ public void setNfRole(String nfRole) {
+ this.nfRole = nfRole;
+ }
+
+ public String getNfNamingCode() {
+ return nfNamingCode;
+ }
+
+ public void setNfNamingCode(String nfNamingCode) {
+ this.nfNamingCode = nfNamingCode;
+ }
+
+ public RelationshipList getRelationshipList() {
+ return relationshipList;
+ }
+
+ public void setRelationshipList(RelationshipList relationshipList) {
+ this.relationshipList = relationshipList;
+ }
+
+ public VfModules getVfModules() {
+ return vfModules;
+ }
+
+ public void setVfModules(VfModules vfModules) {
+ this.vfModules = vfModules;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("vnfId", vnfId).append("vnfName", vnfName).append("vnfName2", vnfName2).append("vnfType", vnfType).append("serviceId", serviceId).append("provisionStatus", provisionStatus).append("licenseKey", licenseKey).append("equipmentRole", equipmentRole).append("orchestrationStatus", orchestrationStatus).append("heatStackId", heatStackId).append("msoCatalogKey", msoCatalogKey).append("ipv4OamAddress", ipv4OamAddress).append("ipv4Loopback0Address", ipv4Loopback0Address).append("nmLanV6Address", nmLanV6Address).append("managementV6Address", managementV6Address).append("inMaintenance", inMaintenance).append("isClosedLoopDisabled", isClosedLoopDisabled).append("resourceVersion", resourceVersion).append("modelInvariantId", modelInvariantId).append("modelVersionId", modelVersionId).append("modelCustomizationId", modelCustomizationId).append("nfType", nfType).append("nfFunction", nfFunction).append("nfRole", nfRole).append("nfNamingCode", nfNamingCode).append("relationshipList", relationshipList).append("vfModules", vfModules).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder().append(modelCustomizationId).append(serviceId).append(ipv4Loopback0Address).append(vnfType).append(nfFunction).append(modelInvariantId).append(resourceVersion).append(vnfName2).append(relationshipList).append(nmLanV6Address).append(nfRole).append(nfType).append(modelVersionId).append(ipv4OamAddress).append(vnfName).append(inMaintenance).append(msoCatalogKey).append(provisionStatus).append(vfModules).append(equipmentRole).append(vnfId).append(orchestrationStatus).append(nfNamingCode).append(isClosedLoopDisabled).append(heatStackId).append(licenseKey).append(managementV6Address).toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof VnfInstance)) {
+ return false;
+ }
+ VnfInstance rhs = ((VnfInstance) other);
+ return new EqualsBuilder().append(modelCustomizationId, rhs.modelCustomizationId).append(serviceId, rhs.serviceId).append(ipv4Loopback0Address, rhs.ipv4Loopback0Address).append(vnfType, rhs.vnfType).append(nfFunction, rhs.nfFunction).append(modelInvariantId, rhs.modelInvariantId).append(resourceVersion, rhs.resourceVersion).append(vnfName2, rhs.vnfName2).append(relationshipList, rhs.relationshipList).append(nmLanV6Address, rhs.nmLanV6Address).append(nfRole, rhs.nfRole).append(nfType, rhs.nfType).append(modelVersionId, rhs.modelVersionId).append(ipv4OamAddress, rhs.ipv4OamAddress).append(vnfName, rhs.vnfName).append(inMaintenance, rhs.inMaintenance).append(msoCatalogKey, rhs.msoCatalogKey).append(provisionStatus, rhs.provisionStatus).append(vfModules, rhs.vfModules).append(equipmentRole, rhs.equipmentRole).append(vnfId, rhs.vnfId).append(orchestrationStatus, rhs.orchestrationStatus).append(nfNamingCode, rhs.nfNamingCode).append(isClosedLoopDisabled, rhs.isClosedLoopDisabled).append(heatStackId, rhs.heatStackId).append(licenseKey, rhs.licenseKey).append(managementV6Address, rhs.managementV6Address).isEquals();
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/VnfcInstance.java b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/VnfcInstance.java
new file mode 100644
index 0000000..3790d52
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/VnfcInstance.java
@@ -0,0 +1,231 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.datatype;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import javax.validation.Valid;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.onap.pomba.contextbuilder.aai.exception.AuditError;
+import org.onap.pomba.contextbuilder.aai.exception.AuditException;
+
+public class VnfcInstance {
+
+ @SerializedName("vnfc-name")
+ @Expose
+ private String vnfcName;
+ @SerializedName("nfc-naming-code")
+ @Expose
+ private String nfcNamingCode;
+ @SerializedName("nfc-function")
+ @Expose
+ private String nfcFunction;
+ @SerializedName("prov-status")
+ @Expose
+ private String provisionStatus;
+ @SerializedName("orchestration-status")
+ @Expose
+ private String orchestrationStatus;
+ @SerializedName("in-maint")
+ @Expose
+ private Boolean inMaintenance;
+ @SerializedName("is-closed-loop-disabled")
+ @Expose
+ private Boolean isClosedLoopDisabled;
+ @SerializedName("resource-version")
+ @Expose
+ private String resourceVersion;
+ @SerializedName("model-invariant-id")
+ @Expose
+ private String modelInvariantId;
+ @SerializedName("model-version-id")
+ @Expose
+ private String modelVersionId;
+ @SerializedName("relationship-list")
+ @Expose
+ @Valid
+ private RelationshipList relationshipList;
+
+ private static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
+
+ public String toJson() {
+ return gson.toJson(this);
+ }
+
+ public static VnfcInstance fromJson(String payload) throws AuditException {
+ try {
+ if (payload == null || payload.isEmpty()) {
+ throw new AuditException("Empty Json response");
+ }
+ return gson.fromJson(payload, VnfcInstance.class);
+ } catch (Exception ex) {
+ throw new AuditException(AuditError.JSON_READER_PARSE_ERROR, ex);
+ }
+ }
+
+ /**
+ * No args constructor for use in serialization
+ *
+ */
+ public VnfcInstance() {
+ }
+
+ /**
+ *
+ * @param nfcNamingCode
+ * @param inMaintenance
+ * @param nfcFunction
+ * @param orchestrationStatus
+ * @param modelInvariantId
+ * @param isClosedLoopDisabled
+ * @param resourceVersion
+ * @param provisionStatus
+ * @param relationshipList
+ * @param modelVersionId
+ * @param vnfcName
+ */
+ public VnfcInstance(String vnfcName, String nfcNamingCode, String nfcFunction, String provisionStatus, String orchestrationStatus, Boolean inMaintenance, Boolean isClosedLoopDisabled, String resourceVersion, String modelInvariantId, String modelVersionId, RelationshipList relationshipList) {
+ super();
+ this.vnfcName = vnfcName;
+ this.nfcNamingCode = nfcNamingCode;
+ this.nfcFunction = nfcFunction;
+ this.provisionStatus = provisionStatus;
+ this.orchestrationStatus = orchestrationStatus;
+ this.inMaintenance = inMaintenance;
+ this.isClosedLoopDisabled = isClosedLoopDisabled;
+ this.resourceVersion = resourceVersion;
+ this.modelInvariantId = modelInvariantId;
+ this.modelVersionId = modelVersionId;
+ this.relationshipList = relationshipList;
+ }
+
+ public String getVnfcName() {
+ return vnfcName;
+ }
+
+ public void setVnfcName(String vnfcName) {
+ this.vnfcName = vnfcName;
+ }
+
+ public String getNfcNamingCode() {
+ return nfcNamingCode;
+ }
+
+ public void setNfcNamingCode(String nfcNamingCode) {
+ this.nfcNamingCode = nfcNamingCode;
+ }
+
+ public String getNfcFunction() {
+ return nfcFunction;
+ }
+
+ public void setNfcFunction(String nfcFunction) {
+ this.nfcFunction = nfcFunction;
+ }
+
+ public String getProvisionStatus() {
+ return provisionStatus;
+ }
+
+ public void setProvisionStatus(String provisionStatus) {
+ this.provisionStatus = provisionStatus;
+ }
+
+ public String getOrchestrationStatus() {
+ return orchestrationStatus;
+ }
+
+ public void setOrchestrationStatus(String orchestrationStatus) {
+ this.orchestrationStatus = orchestrationStatus;
+ }
+
+ public Boolean getInMaintenance() {
+ return inMaintenance;
+ }
+
+ public void setInMaintenance(Boolean inMaintenance) {
+ this.inMaintenance = inMaintenance;
+ }
+
+ public Boolean getIsClosedLoopDisabled() {
+ return isClosedLoopDisabled;
+ }
+
+ public void setIsClosedLoopDisabled(Boolean isClosedLoopDisabled) {
+ this.isClosedLoopDisabled = isClosedLoopDisabled;
+ }
+
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
+
+ public String getModelInvariantId() {
+ return modelInvariantId;
+ }
+
+ public void setModelInvariantId(String modelInvariantId) {
+ this.modelInvariantId = modelInvariantId;
+ }
+
+ public String getModelVersionId() {
+ return modelVersionId;
+ }
+
+ public void setModelVersionId(String modelVersionId) {
+ this.modelVersionId = modelVersionId;
+ }
+
+ public RelationshipList getRelationshipList() {
+ return relationshipList;
+ }
+
+ public void setRelationshipList(RelationshipList relationshipList) {
+ this.relationshipList = relationshipList;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("vnfcName", vnfcName).append("nfcNamingCode", nfcNamingCode).append("nfcFunction", nfcFunction).append("provisionStatus", provisionStatus).append("orchestration_status", orchestrationStatus).append("inMaintenance", inMaintenance).append("isClosedLoopDisabled", isClosedLoopDisabled).append("resourceVersion", resourceVersion).append("modelInvariantId", modelInvariantId).append("modelVersionId", modelVersionId).append("relationshipList", relationshipList).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder().append(nfcNamingCode).append(inMaintenance).append(nfcFunction).append(orchestrationStatus).append(modelInvariantId).append(isClosedLoopDisabled).append(resourceVersion).append(provisionStatus).append(relationshipList).append(modelVersionId).append(vnfcName).toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof VnfcInstance)) {
+ return false;
+ }
+ VnfcInstance rhs = ((VnfcInstance) other);
+ return new EqualsBuilder().append(nfcNamingCode, rhs.nfcNamingCode).append(inMaintenance, rhs.inMaintenance).append(nfcFunction, rhs.nfcFunction).append(orchestrationStatus, rhs.orchestrationStatus).append(modelInvariantId, rhs.modelInvariantId).append(isClosedLoopDisabled, rhs.isClosedLoopDisabled).append(resourceVersion, rhs.resourceVersion).append(provisionStatus, rhs.provisionStatus).append(relationshipList, rhs.relationshipList).append(modelVersionId, rhs.modelVersionId).append(vnfcName, rhs.vnfcName).isEquals();
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/exception/AuditError.java b/src/main/java/org/onap/pomba/contextbuilder/aai/exception/AuditError.java
new file mode 100644
index 0000000..40d8bcc
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/exception/AuditError.java
@@ -0,0 +1,32 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.exception;
+
+public class AuditError {
+
+ private AuditError() {}
+
+ public static final String INTERNAL_SERVER_ERROR = "Internal Server Error";
+ public static final String JSON_READER_PARSE_ERROR ="Json Reader Parse Error";
+
+ public static final String GENERIC_VNF_NOT_FOUND = "Generic VNF not Found";
+ public static final String VNFC_NOT_FOUND = "VNFC not Found";
+
+ public static final String INVALID_REQUEST_URL_MISSING_PARAMETER = "Invalid request URL, missing parameter: ";
+ public static final String MISSING_HEADER_PARAMETER = "Missing header parameter: ";
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/exception/AuditException.java b/src/main/java/org/onap/pomba/contextbuilder/aai/exception/AuditException.java
new file mode 100644
index 0000000..d78ff84
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/exception/AuditException.java
@@ -0,0 +1,60 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.exception;
+
+import javax.ws.rs.core.Response.Status;
+
+public class AuditException extends Exception {
+
+ private static final long serialVersionUID = 4452739729613610454L;
+
+ private Status httpStatus;
+
+ public AuditException() {
+ }
+
+ public AuditException(String message) {
+ super(message);
+ }
+
+ public AuditException(String message, Status httpStatus) {
+ super(message);
+ this.setHttpStatus(httpStatus);
+ }
+
+ public AuditException(Throwable cause) {
+ super(cause);
+ }
+
+ public AuditException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public AuditException(String message, Throwable cause, boolean enableSuppression,
+ boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
+
+ public Status getHttpStatus() {
+ return httpStatus;
+ }
+
+ public void setHttpStatus(Status httpStatus) {
+ this.httpStatus = httpStatus;
+ }
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/model/GenericResponse.java b/src/main/java/org/onap/pomba/contextbuilder/aai/model/GenericResponse.java
new file mode 100644
index 0000000..0356388
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/model/GenericResponse.java
@@ -0,0 +1,56 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.model;
+
+import java.io.Serializable;
+
+public class GenericResponse implements Serializable{
+
+ private static final long serialVersionUID = 1L;
+
+ private Object responseObj;
+
+ private String status;
+
+ private String failureReason;
+
+ public String getFailureReason() {
+ return failureReason;
+ }
+
+ public void setFailureReason(String failureReason) {
+ this.failureReason = failureReason;
+ }
+
+ public Object getResponseObj() {
+ return responseObj;
+ }
+
+ public void setResponseObj(Object responseObj) {
+ this.responseObj = responseObj;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/reader/JsonReader.java b/src/main/java/org/onap/pomba/contextbuilder/aai/reader/JsonReader.java
new file mode 100644
index 0000000..5866705
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/reader/JsonReader.java
@@ -0,0 +1,186 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.reader;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.jayway.jsonpath.Configuration;
+import com.jayway.jsonpath.DocumentContext;
+import com.jayway.jsonpath.JsonPath;
+import com.jayway.jsonpath.Option;
+import com.jayway.jsonpath.ReadContext;
+import com.jayway.jsonpath.spi.json.GsonJsonProvider;
+import com.jayway.jsonpath.spi.json.JsonProvider;
+import com.jayway.jsonpath.spi.mapper.GsonMappingProvider;
+import com.jayway.jsonpath.spi.mapper.MappingProvider;
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Set;
+import org.onap.pomba.contextbuilder.aai.exception.AuditError;
+import org.onap.pomba.contextbuilder.aai.exception.AuditException;
+
+/**
+ * Reads JSON objects. Supported by the JayWay JsonPath library.
+ */
+public class JsonReader {
+
+ private Configuration jsonPathConfig;
+
+ /**
+ * Initialize the JSON reader.
+ */
+ public JsonReader() {
+ setJsonProvider();
+ this.jsonPathConfig = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build();
+ }
+
+ /**
+ * Parse the JSON.
+ *
+ * @param json
+ * the JSON object
+ * @return a {@link ReadContext} the parsed JSON.
+ * @throws ValidationServiceException
+ */
+ public DocumentContext parse(String json) throws AuditException {
+ DocumentContext document = null;
+ try {
+ document = JsonPath.using(jsonPathConfig).parse(json);
+ } catch (Exception e) {
+ throw new AuditException(AuditError.JSON_READER_PARSE_ERROR, e);
+ }
+ return document;
+ }
+
+ /**
+ * Gets values from JSON objects.
+ *
+ * @param json
+ * the JSON object
+ * @param path
+ * the path to property values. The format must comply with the JayWay JsonPath definition.
+ * @return a List of values found by evaluating the path.
+ * @throws ValidationServiceException
+ */
+ public List<String> get(String json, String path) throws AuditException {
+ return getAsList(parse(json), path);
+ }
+
+ /**
+ * Gets values from JSON objects. Used in combination with {@link JsonReader#parse(String)} it reduces the number of
+ * times the JSON document is parsed.
+ *
+ * @param document
+ * a {@link DocumentContext} object with the parsed JSON
+ * @param path
+ * the path to property values. The format must comply with the JayWay JsonPath definition.
+ * @return a List of values found by evaluating the path, or an empty list if no values were found
+ */
+ public List<String> getAsList(DocumentContext document, String path) {
+ List<String> result = new ArrayList<>();
+ JsonElement jsonElement = document.read(path);
+ if (jsonElement != null) {
+ if (jsonElement.isJsonPrimitive()) {
+ result.add(jsonElement.getAsString());
+ } else if (jsonElement.isJsonObject()) {
+ result.add(jsonElement.getAsJsonObject().toString());
+ } else if (jsonElement.isJsonArray()) {
+ for (JsonElement obj : jsonElement.getAsJsonArray()) {
+ Object object = jsonElementToObject(obj);
+ result.add(object == null ? null : object.toString());
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Get the value(s) from the specified JSON document
+ *
+ * @param document
+ * a {@link DocumentContext} object with the parsed JSON
+ * @param path
+ * the path to property value(s). The format must comply with the JayWay JsonPath definition.
+ * @return either all the values found by evaluating the path (e.g. as an array), or a String object (only) where
+ * the path evaluates to a single primitive value
+ */
+ public Object getObject(DocumentContext document, String path) {
+ return jsonElementToObject(document.read(path));
+ }
+
+ /**
+ * Convert the JSON element to a String or Array where possible, otherwise return the JSON object.
+ *
+ * @param jsonElement
+ * @return the jsonElement converted to a Java Object
+ */
+ private Object jsonElementToObject(JsonElement jsonElement) {
+ if (jsonElement == null) {
+ return null;
+ } else if (jsonElement.isJsonPrimitive()) {
+ return jsonElement.getAsString();
+ } else if (jsonElement.isJsonObject()) {
+ return jsonElement.getAsJsonObject();
+ } else if (jsonElement.isJsonArray()) {
+ // Convert to a List for simplified handling within rules
+ return jsonArrayToList(jsonElement.getAsJsonArray());
+ } else {
+ return jsonElement;
+ }
+ }
+
+ private List<Object> jsonArrayToList(JsonArray jsonArray) {
+ List<Object> result = new ArrayList<>();
+ for (JsonElement obj : jsonArray) {
+ result.add(jsonElementToObject(obj));
+ }
+ return result;
+ }
+
+ /**
+ * @param document
+ * @param path
+ * @return a JsonElement from the document
+ */
+ public JsonElement getJsonElement(DocumentContext document, String path) {
+ return document.read(path);
+ }
+
+ private void setJsonProvider() {
+ Configuration.setDefaults(new Configuration.Defaults() {
+ private final JsonProvider jsonProvider = new GsonJsonProvider();
+ private final MappingProvider mappingProvider = new GsonMappingProvider();
+
+ @Override
+ public JsonProvider jsonProvider() {
+ return jsonProvider;
+ }
+
+ @Override
+ public MappingProvider mappingProvider() {
+ return mappingProvider;
+ }
+
+ @Override
+ public Set<Option> options() {
+ return EnumSet.noneOf(Option.class);
+ }
+ });
+ }
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/service/ConsumerService.java b/src/main/java/org/onap/pomba/contextbuilder/aai/service/ConsumerService.java
new file mode 100644
index 0000000..c23a6dc
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/service/ConsumerService.java
@@ -0,0 +1,40 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.service;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpMethod;
+import org.springframework.web.client.RestTemplate;
+/*Used for the PACT Contract verification only*/
+public class ConsumerService {
+
+ private String url;
+ private RestTemplate restTemplate;
+
+ @Autowired
+ public ConsumerService(@Value("${producer}") String url) {
+ this.url = url;
+ this.restTemplate = new RestTemplate();
+ }
+
+ public Object getWelcomeMsg() {
+ return restTemplate.exchange(url+ "/aaicontextbuilder/service/hello?name=User",HttpMethod.GET, null, String.class).getBody();
+ }
+
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringService.java b/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringService.java
new file mode 100644
index 0000000..aa28e2b
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringService.java
@@ -0,0 +1,27 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.service;
+
+
+import org.onap.pomba.common.datatypes.ModelContext;
+import org.onap.pomba.contextbuilder.aai.exception.AuditException;
+
+public interface SpringService {
+
+ public ModelContext getContext(String serviceInstanceId, String modelVersionId, String modelInvariantId, String serviceType, String customerId, String transactionId) throws AuditException;
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringServiceImpl.java b/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringServiceImpl.java
new file mode 100644
index 0000000..60ad231
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringServiceImpl.java
@@ -0,0 +1,66 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.service;
+
+import org.onap.aai.restclient.client.RestClient;
+import org.onap.pomba.common.datatypes.ModelContext;
+import org.onap.pomba.contextbuilder.aai.common.LogMessages;
+import org.onap.pomba.contextbuilder.aai.exception.AuditException;
+import org.onap.pomba.contextbuilder.aai.util.RestUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class SpringServiceImpl implements SpringService {
+ private static Logger log = LoggerFactory.getLogger(SpringServiceImpl.class);
+
+ @Autowired
+ private RestClient aaiClient;
+ @Autowired
+ private String aaiBaseUrl;
+ @Autowired
+ private String aaiServiceInstancePath;
+
+
+ public SpringServiceImpl() {
+ // needed for instantiation
+ }
+
+ @Override
+ public ModelContext getContext(String serviceInstanceId, String modelVersionId, String modelInvariantId, String serviceType, String customerId, String tranId) throws AuditException {
+
+ String url = "serviceInstanceId=" + serviceInstanceId + " modelVersion="+modelVersionId +
+ " modelInvariantId="+ modelInvariantId + " serviceType="+serviceType + " customerId="+ customerId;
+ log.info(LogMessages.AAI_CONTEXT_BUILDER_URL + url);
+
+ ModelContext context = null;
+
+ // Retrieve the service instance information from AAI
+ try {
+ context= RestUtil.retrieveAAIModelData(aaiClient, aaiBaseUrl, aaiServiceInstancePath, tranId, serviceInstanceId, modelVersionId, modelInvariantId, serviceType, customerId);
+ } catch (AuditException ae) {
+ throw ae;
+ } catch (Exception e) {
+ throw new AuditException(e.getLocalizedMessage());
+ }
+ return context;
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestService.java b/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestService.java
new file mode 100644
index 0000000..dcc3382
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestService.java
@@ -0,0 +1,62 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.service.rs;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.onap.pomba.contextbuilder.aai.model.GenericResponse;
+
+
+@Api
+@Path("/service")
+@Produces({MediaType.APPLICATION_JSON})
+public interface RestService {
+
+ @GET
+ @Path("/context")
+ @Produces({ MediaType.APPLICATION_JSON })
+ @ApiOperation(
+ value = "Respond AAIContext Model Data",
+ notes = "Returns a JSON object which represents the AAIConetxt model data",
+ response = GenericResponse.class
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(code = 200, message = "OK"),
+ @ApiResponse(code = 400, message = "Bad Request"),
+ @ApiResponse(code = 404, message = "Service not available"),
+ @ApiResponse(code = 500, message = "Unexpected Runtime error")
+ })
+ public Response getContext(@Context HttpHeaders headers,
+ @QueryParam("serviceInstanceId") String serviceInstanceId,
+ @QueryParam("modelVersionId") String modelVersionId,
+ @QueryParam("modelInvariantId") String modelInvariantId,
+ @QueryParam("serviceType") String serviceType,
+ @QueryParam("customerId") String customerId
+ );
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestServiceImpl.java b/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestServiceImpl.java
new file mode 100644
index 0000000..38f7510
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestServiceImpl.java
@@ -0,0 +1,89 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.service.rs;
+
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.onap.pomba.common.datatypes.ModelContext;
+import org.onap.pomba.contextbuilder.aai.common.LogMessages;
+import org.onap.pomba.contextbuilder.aai.exception.AuditException;
+import org.onap.pomba.contextbuilder.aai.service.SpringService;
+import org.onap.pomba.contextbuilder.aai.util.RestUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class RestServiceImpl implements RestService {
+ private static Logger log = LoggerFactory.getLogger(RestService.class);
+ private static final String EMPTY_JSON_STRING = "{}";
+
+
+ @Autowired
+ private SpringService service;
+
+ @Override
+ public Response getContext(HttpHeaders headers, String serviceInstanceId, String modelVersionId, String modelInvariantId, String serviceType, String customerId) {
+
+ String url = "serviceInstanceId=" + serviceInstanceId + " modelVersion="+modelVersionId +
+ " modelInvariantId="+ modelInvariantId + " serviceType="+serviceType + " customerId="+ customerId;
+ if(log.isDebugEnabled()) {
+ log.debug(LogMessages.AAI_CONTEXT_BUILDER_URL + url);
+ }
+
+
+ Response response = null;
+ String transactionId = null;
+ ModelContext aaiContext= null;
+
+ Gson gson = new GsonBuilder().create();
+
+ try {
+ // Do some validation on Http headers and URL parameters
+ RestUtil.validateHeader(headers);
+ RestUtil.validateURL(serviceInstanceId, modelVersionId, modelInvariantId, serviceType, customerId);
+
+ // Keep the same transaction id for logging purpose
+ transactionId= RestUtil.extractTranIdHeader(headers);
+
+ aaiContext = service.getContext(serviceInstanceId, modelVersionId, modelInvariantId, serviceType, customerId, transactionId);
+
+ if (aaiContext==null) {
+ // Return empty JSON
+ response = Response.ok().entity(EMPTY_JSON_STRING).build();
+ }else {
+ response = Response.ok().entity(gson.toJson(aaiContext)).build();
+ }
+ } catch (AuditException ce) {
+ if (ce.getHttpStatus() !=null) {
+ response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
+ }else {
+ // No response received, could be the cases of network issue: i.e. unreachable host
+ response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(ce.getMessage()).build();
+ }
+ } catch (Exception e) {
+ response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
+ }
+
+ return response;
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java b/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java
new file mode 100644
index 0000000..240a55b
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java
@@ -0,0 +1,431 @@
+/*
+ * ============LICENSE_START=================================================== Copyright (c) 2018
+ * Amdocs ============================================================================ 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License. ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.aai.util;
+
+
+
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+//import com.sun.jersey.core.util.MultivaluedMapImpl;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response.Status;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.onap.aai.restclient.client.OperationResult;
+import org.onap.aai.restclient.client.RestClient;
+import org.onap.pomba.common.datatypes.ModelContext;
+import org.onap.pomba.common.datatypes.Service;
+import org.onap.pomba.common.datatypes.VF;
+import org.onap.pomba.common.datatypes.VFModule;
+import org.onap.pomba.common.datatypes.VNFC;
+import org.onap.pomba.contextbuilder.aai.common.LogMessages;
+import org.onap.pomba.contextbuilder.aai.datatype.ServiceInstance;
+import org.onap.pomba.contextbuilder.aai.datatype.VfModule;
+import org.onap.pomba.contextbuilder.aai.datatype.VnfInstance;
+import org.onap.pomba.contextbuilder.aai.datatype.VnfcInstance;
+import org.onap.pomba.contextbuilder.aai.exception.AuditError;
+import org.onap.pomba.contextbuilder.aai.exception.AuditException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class RestUtil {
+
+ private RestUtil() {}
+
+ private static Logger log = LoggerFactory.getLogger(RestUtil.class);
+ // Parameters for Query AAI Model Data API
+ private static final String SERVICE_INSTANCE_ID = "serviceInstanceId";
+ private static final String MODEL_VERSION_ID = "modelVersionId";
+ private static final String MODEL_INVARIANT_ID = "modelInvariantId";
+ private static final String CUSTOMER_ID = "customerId";
+ private static final String SERVICE_TYPE = "serviceType";
+
+ // HTTP headers
+ private static final String TRANSACTION_ID = "X-TransactionId";
+ private static final String FROM_APP_ID = "X-FromAppId";
+
+ private static final String APP_NAME = "aaiCtxBuilder";
+
+ // Service Catalog
+ private static final String CATALOG_GENERIC_VNF = "generic-vnf";
+ private static final String CATALOG_VNFC = "vnfc";
+ // Relationship Json Path
+ private static final String RELATIONSHIP_LIST = "relationship-list";
+ private static final String RELATIONSHIP = "relationship";
+
+ private static final String JSON_ATT_RELATED_TO = "related-to";
+ private static final String JSON_ATT_RELATED_LINK = "related-link";
+
+ private static final String EMPTY_JSON_STRING = "{}";
+ private static final String DELIMITER = "$";
+ private static final String DEPTH = "?depth=2";
+
+ /**
+ * Validates the URL parameter.
+ *
+ * @throws AuditException if there is missing parameter
+ */
+ public static void validateURL(String serviceInstanceId, String modelVersionId, String modelInvariantId,
+ String serviceType, String customerId) throws AuditException {
+
+ if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
+ throw new AuditException(AuditError.INVALID_REQUEST_URL_MISSING_PARAMETER + SERVICE_INSTANCE_ID,
+ Status.BAD_REQUEST);
+ }
+ // modelVersionId
+ if (modelVersionId == null || modelVersionId.isEmpty()) {
+ throw new AuditException(AuditError.INVALID_REQUEST_URL_MISSING_PARAMETER + MODEL_VERSION_ID, Status.BAD_REQUEST);
+ }
+ // modelInvariantId
+ if (modelInvariantId == null || modelInvariantId.isEmpty()) {
+ throw new AuditException(AuditError.INVALID_REQUEST_URL_MISSING_PARAMETER + MODEL_INVARIANT_ID,
+ Status.BAD_REQUEST);
+ }
+ // serviceType
+ if (serviceType == null || serviceType.isEmpty()) {
+ throw new AuditException(AuditError.INVALID_REQUEST_URL_MISSING_PARAMETER + SERVICE_TYPE, Status.BAD_REQUEST);
+ }
+ // customerId
+ if (customerId == null || customerId.isEmpty()) {
+ throw new AuditException(AuditError.INVALID_REQUEST_URL_MISSING_PARAMETER + CUSTOMER_ID, Status.BAD_REQUEST);
+ }
+ }
+
+
+ public static void validateHeader(HttpHeaders headers) throws AuditException {
+ String fromAppId = null;
+ String transactionId = null;
+
+ fromAppId = headers.getRequestHeaders().getFirst(FROM_APP_ID);
+ if ((fromAppId == null) || fromAppId.trim().isEmpty()) {
+ throw new AuditException(AuditError.MISSING_HEADER_PARAMETER + FROM_APP_ID, Status.BAD_REQUEST);
+ }
+
+ transactionId = headers.getRequestHeaders().getFirst(TRANSACTION_ID);
+ if ((transactionId == null) || transactionId.trim().isEmpty()) {
+ transactionId = UUID.randomUUID().toString();
+ log.info(LogMessages.HEADER_MESSAGE, TRANSACTION_ID, transactionId);
+ }
+ }
+
+ /*
+ * The purpose is to keep same transaction Id from north bound interface to south bound interface
+ */
+ public static String extractTranIdHeader(HttpHeaders headers) {
+ String transactionId = null;
+ transactionId = headers.getRequestHeaders().getFirst(TRANSACTION_ID);
+ if ((transactionId == null) || transactionId.trim().isEmpty()) {
+ transactionId = UUID.randomUUID().toString();
+ log.info(LogMessages.HEADER_MESSAGE, TRANSACTION_ID, transactionId);
+ }
+ return transactionId;
+ }
+
+ /*
+ * Trigger external API call to AAI to retrieve Service Instance data (i.e. genericVNF and VNFC)
+ */
+ public static ModelContext retrieveAAIModelData(RestClient aaiClient, String baseURL, String aaiServiceInstancePath,
+ String transactionId, String serviceInstanceId, String modelVersionId, String modelInvariantId,
+ String serviceType, String customerId) throws AuditException {
+ String serviceInstancePayload = null;
+ String genericVNFPayload = null;
+ String vnfcPayload = null;
+
+ // Follow two variables for transform purpose
+ List<VnfInstance> vnfLst = new ArrayList<VnfInstance>(); // List of the VNF POJO object
+ Map<String, List<VnfcInstance>> vnfMap = new HashMap<String, List<VnfcInstance>>(); // MAP the vnf-id as the
+ // key, and list of the vNFC
+ // pojo object
+
+ String url = baseURL
+ + generateServiceInstanceURL(aaiServiceInstancePath, customerId, serviceType, serviceInstanceId);
+ // Response from service instance API call
+ serviceInstancePayload =
+ getResource(aaiClient, url, transactionId, MediaType.valueOf(MediaType.APPLICATION_XML));
+
+ // Handle the case if the service instance is not found in AAI
+ if (isEmptyJson(serviceInstancePayload)) {
+ log.info(LogMessages.NOT_FOUND, "Service Instance" , serviceInstanceId);
+ // Only return the empty Json on the root level. i.e service instance
+ return null;
+ }
+
+ List<String> genericVNFLinkLst = extractRelatedLink(serviceInstancePayload, CATALOG_GENERIC_VNF);
+ log.info(LogMessages.NUMBER_OF_API_CALLS, "genericVNF", genericVNFLinkLst.size());
+ log.info(LogMessages.API_CALL_LIST, "genericVNF", printOutAPIList(genericVNFLinkLst));
+
+
+ for (String genericVNFLink : genericVNFLinkLst) {
+ // With latest AAI development, in order to retrieve the both generic VNF + vf_module, we can use
+ // one API call but with depth=2
+ String genericVNFURL = baseURL + genericVNFLink + DEPTH;
+ // Response from generic VNF API call
+ genericVNFPayload =
+ getResource(aaiClient, genericVNFURL, transactionId, MediaType.valueOf(MediaType.APPLICATION_XML));
+
+ if (isEmptyJson(genericVNFPayload)) {
+ log.info(LogMessages.NOT_FOUND, "GenericVNF with url ", genericVNFLink);
+ } else {
+
+ // Logic to Create the Generic VNF Instance POJO object
+ VnfInstance vnfInstance = VnfInstance.fromJson(genericVNFPayload);
+ vnfLst.add(vnfInstance);
+
+ List<String> vnfcLinkLst = extractRelatedLink(genericVNFPayload, CATALOG_VNFC);
+ log.info(LogMessages.NUMBER_OF_API_CALLS, "vnfc", vnfcLinkLst.size());
+ log.info(LogMessages.API_CALL_LIST, "vnfc", printOutAPIList(vnfcLinkLst));
+
+ List<VnfcInstance> vnfcLst = new ArrayList<VnfcInstance>();
+ for (String vnfcLink : vnfcLinkLst) {
+ String vnfcURL = baseURL + vnfcLink;
+ vnfcPayload = getResource(aaiClient, vnfcURL, transactionId,
+ MediaType.valueOf(MediaType.APPLICATION_XML));
+
+ if (isEmptyJson(vnfcPayload)) {
+ log.info(LogMessages.NOT_FOUND, "VNFC with url", vnfcLink);
+ } else {
+ // Logic to Create the VNFC POJO object
+ VnfcInstance vnfcInstance = VnfcInstance.fromJson(vnfcPayload);
+ vnfcLst.add(vnfcInstance);
+ }
+ }
+
+ // Assume the vnf-id is unique as a key
+ vnfMap.put(vnfInstance.getVnfId(), vnfcLst);
+ }
+ }
+ // Transform to common model and return
+ return transform(ServiceInstance.fromJson(serviceInstancePayload), vnfLst, vnfMap);
+ }
+
+
+ /*
+ * Transform AAI Representation to Common Model
+ */
+ private static ModelContext transform(ServiceInstance svcInstance, List<VnfInstance> vnfLst,
+ Map<String, List<VnfcInstance>> vnfMap) {
+ ModelContext context = new ModelContext();
+ Service service = new Service();
+ service.setInvariantUuid(svcInstance.getModelInvariantId());
+ service.setName(svcInstance.getServiceInstanceName());
+ service.setUuid(svcInstance.getModelVersionId());
+
+ List<VF> vfLst = new ArrayList<VF>();
+
+ for (VnfInstance vnf : vnfLst) {
+ VF vf = new VF();
+ vf.setInvariantUuid(vnf.getModelInvariantId());
+ vf.setName(vnf.getVnfName());
+ vf.setUuid(vnf.getModelVersionId());
+ vf.setType(vnf.getVnfType());
+ vf.setNfNamingCode(vnf.getNfNamingCode());
+
+ String key = vnf.getVnfId();
+ List<VNFC> vnfcLst = new ArrayList<VNFC>();
+
+ for (Map.Entry<String, List<VnfcInstance>> entry : vnfMap.entrySet()) {
+
+ if (key.equals(entry.getKey())) {
+ List<VnfcInstance> vnfcInstanceLst = entry.getValue();
+
+ for (VnfcInstance vnfc : vnfcInstanceLst) {
+ VNFC vnfcModel = new VNFC();
+ vnfcModel.setInvariantUuid(vnfc.getModelInvariantId());
+ vnfcModel.setName(vnfc.getVnfcName());
+ vnfcModel.setNfcNamingCode(vnfc.getNfcNamingCode());
+ vnfcModel.setUuid(vnfc.getModelVersionId());
+ vnfcLst.add(vnfcModel);
+ }
+ }
+ }
+
+ vf.setVnfc(vnfcLst);
+ // Add the vfModule
+ List<VFModule> vfModuleLst = new ArrayList<VFModule>();
+
+ if (vnf.getVfModules() != null) {
+ ConcurrentMap<String, AtomicInteger> vnfModulemap =
+ buildMaxInstanceMap(vnf.getVfModules().getVfModule());
+
+ for (Map.Entry<String, AtomicInteger> entry : vnfModulemap.entrySet()) {
+
+ String[] s = entry.getKey().split("\\" + DELIMITER);
+
+ String modelVersionId = s[0];
+ String modelInvariantId = s[1];
+ VFModule vfModule = new VFModule();
+ vfModule.setUuid(modelVersionId);
+ vfModule.setInvariantUuid(modelInvariantId);
+ vfModule.setMaxInstances(entry.getValue().intValue());
+ vfModuleLst.add(vfModule);
+ }
+ }
+ vf.setVfModules(vfModuleLst);
+
+ vfLst.add(vf);
+
+ } // done the vnfInstance
+
+ context.setService(service);
+ context.setVf(vfLst);
+
+ return context;
+ }
+
+
+
+ /*
+ * Build the map with key (model_version_id and model_invariant_id), and with the max occurrences of
+ * the value in the map
+ *
+ * @param vfModuleList
+ *
+ * @return
+ */
+ private static ConcurrentMap<String, AtomicInteger> buildMaxInstanceMap(List<VfModule> vfModuleList) {
+
+ ConcurrentMap<String, AtomicInteger> map = new ConcurrentHashMap<>();
+
+ for (VfModule vfModule : vfModuleList) {
+ // group the key by model_version_id and model_invariant_id
+ String key = new StringBuilder().append(vfModule.getModelVersionId()).append(DELIMITER)
+ .append(vfModule.getModelInvariantId()).toString();
+
+ if (key.length() > 0) {
+ map.putIfAbsent(key, new AtomicInteger(0));
+ map.get(key).incrementAndGet();
+ }
+
+ }
+
+ return map;
+
+ }
+
+
+
+ public static boolean isEmptyJson(String serviceInstancePayload) {
+
+ return (serviceInstancePayload.equals(EMPTY_JSON_STRING));
+ }
+
+
+ private static String printOutAPIList(List<String> relatedLinkLst) {
+ StringBuilder builder = new StringBuilder();
+
+ // Loop and append values.
+ for (String s : relatedLinkLst) {
+ builder.append(s).append("\n");
+ }
+ return builder.toString();
+
+ }
+
+
+ /*
+ * Extract the related-Link from Json payload. For example
+ * {
+ * "related-to": "vnfc",
+ * "related-link": "/aai/v11/network/vnfcs/vnfc/zrdm5aepdg01vmg003",
+ * "relationship-data": [
+ * { "relationship-key": "vnfc.vnfc-name",
+ * "relationship-value": "zrdm5aepdg01vmg003" }
+ * ]
+ * },
+ */
+ private static List<String> extractRelatedLink(String payload, String catalog) throws AuditException {
+ JSONObject jsonPayload = new JSONObject(payload);
+ JSONArray relationships = null;
+ List<String> relatedLinkList = new ArrayList<String>();
+ log.info("Fetching the vnfc related link");
+
+ try {
+ JSONObject relationshipList = jsonPayload.getJSONObject(RELATIONSHIP_LIST);
+ if (relationshipList != null) {
+ relationships = relationshipList.getJSONArray(RELATIONSHIP);
+ }
+ } catch (Exception e) {
+ log.error(e.getMessage());
+ throw new AuditException(AuditError.JSON_READER_PARSE_ERROR + " " + e.getMessage());
+ }
+
+ if (relationships != null && relationships.length() > 0) {
+ for (int i = 0; i < relationships.length(); i++) {
+ Object relatedToObj = null;
+ Object relatedLinkObj = null;
+
+ JSONObject obj = relationships.optJSONObject(i);
+ relatedToObj = obj.get(JSON_ATT_RELATED_TO);
+
+ if (relatedToObj.toString().equals(catalog)) {
+ relatedLinkObj = obj.get(JSON_ATT_RELATED_LINK);
+ if (relatedLinkObj != null) {
+ relatedLinkList.add(relatedLinkObj.toString());
+ }
+ }
+ }
+ }
+
+ log.info(LogMessages.NUMBER_OF_RELATIONSHIPS_FOUND, catalog, relatedLinkList.size());
+
+ return relatedLinkList;
+ }
+
+
+
+ @SuppressWarnings("unchecked")
+ private static Map<String, List<String>> buildHeaders(String transactionId) {
+ MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+ headers.put(TRANSACTION_ID, Collections.singletonList(transactionId));
+ headers.put(FROM_APP_ID, Collections.singletonList(APP_NAME));
+ return headers;
+ }
+
+
+ private static String getResource(RestClient client, String url, String transId, MediaType mediaType)
+ throws AuditException {
+ OperationResult result = client.get(url, buildHeaders(transId), MediaType.valueOf(MediaType.APPLICATION_JSON));
+
+ if (result.getResultCode() == 200) {
+ return result.getResult();
+ } else if (result.getResultCode() == 404) {
+ // Resource not found, generate empty JSON format
+ log.info(LogMessages.RESOURCE_NOT_FOUND, url, "return empty Json format");
+ return new JSONObject().toString();
+
+ } else {
+ throw new AuditException(AuditError.INTERNAL_SERVER_ERROR + " with " + result.getFailureCause());
+ }
+ }
+
+
+ private static String generateServiceInstanceURL(String siPath, String customerId, String serviceType,
+ String serviceInstanceId) {
+ return MessageFormat.format(siPath, customerId, serviceType, serviceInstanceId);
+ }
+
+
+}
diff --git a/src/test/java/org/onap/logging_analytics/pomba/pomba_aai_context_builder/AppTest.java b/src/test/java/org/onap/logging_analytics/pomba/pomba_aai_context_builder/AppTest.java
new file mode 100644
index 0000000..cb631cc
--- /dev/null
+++ b/src/test/java/org/onap/logging_analytics/pomba/pomba_aai_context_builder/AppTest.java
@@ -0,0 +1,55 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.logging_analytics.pomba.pomba_aai_context_builder;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}