<modelVersion>4.0.0</modelVersion>
<artifactId>cps-tbdmt-application</artifactId>
+
+ <properties>
+ <app>org.onap.cps.tbdmt.Application</app>
+ <image.name>cps-tbdmt</image.name>
+ <image.version>${project.version}</image.version>
+ <jib-maven-plugin.version>2.6.0</jib-maven-plugin.version>
+ <minimum-coverage>0.0</minimum-coverage>
+ <nexus.repository>nexus3.onap.org:10003/onap/</nexus.repository>
+ <openjdk11.base.image>nexus3.onap.org:10001/onap/integration</openjdk11.base.image>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-tomcat</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-actuator</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-starter-sleuth</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>cps-tbdmt-rest</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.google.cloud.tools</groupId>
+ <artifactId>jib-maven-plugin</artifactId>
+ <version>${jib-maven-plugin.version}</version>
+ <configuration>
+ <container>
+ <mainClass>${app}</mainClass>
+ <creationTime>USE_CURRENT_TIMESTAMP</creationTime>
+ </container>
+ <from>
+ <image>${base.image}</image>
+ </from>
+ <to>
+ <tags>
+ <tag>latest</tag>
+ </tags>
+ <image>${nexus.repository}${image.name}:${image.version}</image>
+ </to>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <id>build</id>
+ <goals>
+ <goal>dockerBuild</goal>
+ </goals>
+ </execution>
+ <execution>
+ <phase>deploy</phase>
+ <id>buildAndPush</id>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
\ No newline at end of file
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+
+ public static void main(final String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+}
<description>This artifact contains dependencyManagement declarations of upstream versions.</description>
<properties>
+ <hibernate-jpa-api.version>1.0.1.Final</hibernate-jpa-api.version>
+ <jinjava.version>2.5.6</jinjava.version>
+ <lombok.version>1.18.16</lombok.version>
<nexusproxy>https://nexus.onap.org</nexusproxy>
+ <openpojo.version>0.8.13</openpojo.version>
+ <postgresql.version>42.2.5</postgresql.version>
<releaseNexusPath>/content/repositories/releases/</releaseNexusPath>
<snapshotNexusPath>/content/repositories/snapshots/</snapshotNexusPath>
<sonar.skip>true</sonar.skip>
<dependencyManagement>
<dependencies>
-
+ <dependency>
+ <groupId>org.postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>${postgresql.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate.javax.persistence</groupId>
+ <artifactId>hibernate-jpa-2.0-api</artifactId>
+ <version>${hibernate-jpa-api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>${lombok.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.hubspot.jinjava</groupId>
+ <artifactId>jinjava</artifactId>
+ <version>${jinjava.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.fasterxml.jackson.dataformat</groupId>
+ <artifactId>jackson-dataformat-yaml</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.openpojo</groupId>
+ <artifactId>openpojo</artifactId>
+ <version>${openpojo.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</dependencyManagement>
</project>
\ No newline at end of file
<relativePath/>
</parent>
- <groupId>org.onap.cps</groupId>
<artifactId>cps-tbdmt-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
swagger: "2.0"
info:
- description: ""
+ description: "APIS for Template based Data Model Transformer"
version: "1.0.0"
title: "Template based Data Model Transformer APIs"
license:
name: "Apache 2.0"
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "localhost"
-basePath: "/v1"
tags:
- name: "templates"
description: "CRUD APIs for xpath templates"
schemes:
-- "https"
- "http"
paths:
/templates:
tags:
- "templates"
summary: "Add a new template"
- description: ""
+ description: "Creates a template in the database"
operationId: "addTemplate"
consumes:
- "application/json"
tags:
- "templates"
summary: "Get all templates"
- description: ""
+ description: "Retrieves all the templates stored in database"
operationId: "getAllTemplates"
consumes:
- "application/json"
description: "No templates found"
"500":
description: "Internal server error"
- /templates/{schemaSet}/{id}:
+ /templates/{model}/{template-id}:
get:
tags:
- "templates"
- summary: "Find template by ID"
- description: "Returns a single template"
+ summary: "Find template by ID and model"
+ description: "Returns a single template identified by template-id and model"
operationId: "getTemplateById"
produces:
- "application/json"
parameters:
- - name: "id"
+ - name: "template-id"
in: "path"
description: "ID of template to return"
required: true
type: "string"
- - name: "schemaSet"
+ - name: "model"
in: "path"
- description: "schema set"
+ description: "represents the yang model"
required: true
type: "string"
responses:
tags:
- "templates"
summary: "Deletes a template"
- description: ""
+ description: "Deletes a template by id and model from the database"
operationId: "deleteTemplate"
produces:
- "application/json"
parameters:
- - name: "id"
+ - name: "template-id"
in: "path"
required: true
type: "string"
- - name: "schemaSet"
+ - name: "model"
in: "path"
- description: "schema set"
+ description: "represents the yang model"
required: true
type: "string"
responses:
description: "Invalid ID supplied"
"404":
description: "Template not found"
- /execute/{schemaSet}/{id}:
+ /execute/{model}/{template-id}:
post:
tags:
- "template executions"
produces:
- "application/json"
parameters:
- - name: "id"
+ - name: "template-id"
in: "path"
description: "ID of template to execute"
required: true
type: "string"
- - name: "schemaSet"
+ - name: "model"
in: "path"
- description: "schema set"
+ description: "represents the yang model"
required: true
type: "string"
- in: "body"
Template:
type: "object"
required:
- - "id"
- - "schemaSet"
- - "xpathTemplate"
+ - "template-id"
+ - "model"
+ - "xpath-template"
properties:
- id:
+ template-id:
type: "string"
- schemaSet:
+ model:
type: "string"
- xpathTemplate:
+ xpath-template:
type: "string"
ApiRequest:
type: "object"
<modelVersion>4.0.0</modelVersion>
<artifactId>cps-tbdmt-rest</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>cps-tbdmt-service</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-tomcat</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-jetty</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
\ No newline at end of file
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.exception;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.onap.cps.tbdmt.model.ErrorResponse;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.validation.ObjectError;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.context.request.WebRequest;
+import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
+
+@ControllerAdvice
+public class TemplateExceptionHandler extends ResponseEntityExceptionHandler {
+
+ /**
+ * Handle TemplateNotFoundException.
+ *
+ * @param templateNotFoundException Exception
+ * @param request web request
+ * @return response entity
+ */
+ @ExceptionHandler(TemplateNotFoundException.class)
+ public final ResponseEntity<Object> handleTemplateNotFoundException(
+ final TemplateNotFoundException templateNotFoundException,
+ final WebRequest request) {
+ final List<String> details = new ArrayList<>();
+ details.add(templateNotFoundException.getLocalizedMessage());
+ final ErrorResponse error = new ErrorResponse("Template Not found", details);
+ return new ResponseEntity<>(error, HttpStatus.NOT_FOUND);
+ }
+
+ /**
+ * Handle ExecuteException.
+ *
+ * @param executeException Exception
+ * @param request web request
+ * @return response entity
+ */
+ @ExceptionHandler(ExecuteException.class)
+ public final ResponseEntity<Object> handleExecutionException(
+ final ExecuteException executeException,
+ final WebRequest request) {
+ final List<String> details = new ArrayList<>();
+ details.add(executeException.getLocalizedMessage());
+ final ErrorResponse error = new ErrorResponse("Error while executing template", details);
+ return new ResponseEntity<>(error, HttpStatus.OK);
+ }
+
+ @Override
+ protected ResponseEntity<Object> handleMethodArgumentNotValid(
+ final MethodArgumentNotValidException methodArgumentNotValidException,
+ final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
+ final List<String> details = new ArrayList<>();
+ for (final ObjectError error : methodArgumentNotValidException.getBindingResult().getAllErrors()) {
+ details.add(error.getDefaultMessage());
+ }
+ final ErrorResponse error = new ErrorResponse("Validation Failed", details);
+ return new ResponseEntity<>(error, HttpStatus.BAD_REQUEST);
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.rest;
+
+import javax.validation.Valid;
+import org.onap.cps.tbdmt.model.ExecutionRequest;
+import org.onap.cps.tbdmt.service.ExecutionBusinessLogic;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class ExecutionController {
+
+ @Autowired
+ private ExecutionBusinessLogic executionBusinessLogic;
+
+ /**
+ * Execute a template by model and templateId.
+ *
+ * @param templateId Id to find the template
+ * @param model schema set to find the template
+ * @return result of the execution
+ */
+ @PostMapping(path = "/execute/{model}/{templateId}")
+ public ResponseEntity<String> executeTemplate(@Valid @PathVariable final String model,
+ @Valid @PathVariable final String templateId,
+ @Valid @RequestBody final ExecutionRequest executionRequest) {
+ final String result = executionBusinessLogic.executeTemplate(model,
+ templateId, executionRequest);
+ return new ResponseEntity<>(result, HttpStatus.OK);
+ }
+
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.rest;
+
+import java.util.Collection;
+import javax.validation.Valid;
+import org.onap.cps.tbdmt.exception.TemplateNotFoundException;
+import org.onap.cps.tbdmt.model.Template;
+import org.onap.cps.tbdmt.model.TemplateKey;
+import org.onap.cps.tbdmt.model.TemplateRequest;
+import org.onap.cps.tbdmt.service.TemplateBusinessLogic;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class TemplateController {
+
+ @Autowired
+ private TemplateBusinessLogic templateBusinessLogic;
+
+ @PostMapping(path = "/templates")
+ public ResponseEntity<Template> createTemplate(@Valid @RequestBody final TemplateRequest request) {
+ return new ResponseEntity<>(templateBusinessLogic.createTemplate(request),
+ HttpStatus.CREATED);
+ }
+
+ /**
+ * Get All Templates.
+ *
+ * @return templates
+ */
+ @GetMapping(path = "/templates")
+ public ResponseEntity<Collection<Template>> getAllTemplates() {
+ final Collection<Template> templates = templateBusinessLogic.getAllTemplates();
+ if (templates.isEmpty()) {
+ throw new TemplateNotFoundException("Template repository is empty");
+ }
+ return new ResponseEntity<>(templates, HttpStatus.OK);
+ }
+
+ /**
+ * Get Template by model and templateId.
+ *
+ * @param templateId Id to find the template
+ * @param model schema set to find the template
+ * @return template
+ */
+ @GetMapping(path = "/templates/{model}/{templateId}")
+ public ResponseEntity<Template> getTemplate(@PathVariable final String templateId,
+ @PathVariable final String model) {
+ return new ResponseEntity<>(
+ templateBusinessLogic.getTemplate(new TemplateKey(templateId, model)),
+ HttpStatus.OK);
+
+ }
+
+ /**
+ * Delete Template by model and templateId.
+ *
+ * @param templateId Id to find the template
+ * @param model schema set to find the template
+ */
+ @DeleteMapping(path = "/templates/{model}/{templateId}")
+ public void deleteTemplate(@PathVariable final String templateId, @PathVariable final String model) {
+ templateBusinessLogic.deleteTemplate(new TemplateKey(templateId, model));
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class TestApplication {
+ public static void main(final String[] args) {
+ SpringApplication.run(TestApplication.class, args);
+ }
+
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.rest;
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mockito;
+import org.onap.cps.tbdmt.exception.ExecuteException;
+import org.onap.cps.tbdmt.exception.TemplateNotFoundException;
+import org.onap.cps.tbdmt.model.ExecutionRequest;
+import org.onap.cps.tbdmt.service.ExecutionBusinessLogic;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+
+
+@RunWith(SpringRunner.class)
+@WebMvcTest(ExecutionController.class)
+public class ExecutionControllerTest {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @MockBean
+ private ExecutionBusinessLogic executionBusinessLogic;
+
+ private ObjectMapper mapper;
+ private String requestJson;
+ private String executePath;
+
+ /**
+ * Setup variables before test.
+ *
+ */
+ @Before
+ public void setup() throws Exception {
+ executePath = "/execute/ran-network/getNbr";
+ final Map<String, String> input = new HashMap<>();
+ input.put("coverageArea", "Zone 1");
+ final ExecutionRequest request = new ExecutionRequest(input);
+ mapper = new ObjectMapper();
+ requestJson = mapper.writeValueAsString(request);
+ }
+
+ @Test
+ public void testExecuteTemplate() throws Exception {
+ final String result = "{\"key\": \"value\"}";
+ Mockito.when(executionBusinessLogic
+ .executeTemplate(ArgumentMatchers.any(), ArgumentMatchers.any(),
+ ArgumentMatchers.any()))
+ .thenReturn(result);
+ mockMvc.perform(post(executePath).contentType(MediaType.APPLICATION_JSON)
+ .characterEncoding("utf-8")
+ .content(requestJson).accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string(result));
+
+ Mockito.when(executionBusinessLogic
+ .executeTemplate(ArgumentMatchers.any(), ArgumentMatchers.any(),
+ ArgumentMatchers.any()))
+ .thenThrow(new TemplateNotFoundException("Template does not exist"));
+ mockMvc.perform(post(executePath).contentType(MediaType.APPLICATION_JSON)
+ .characterEncoding("utf-8")
+ .content(requestJson).accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound());
+
+ mockMvc.perform(post(executePath).contentType(MediaType.APPLICATION_JSON)
+ .characterEncoding("utf-8")
+ .content("{\"bad\": \"request\"").accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void testExecuteTemplateException() throws Exception {
+ final String responseJson = "{\n"
+ + " \"message\": \"Error while executing template\",\n"
+ + " \"details\": [\"Response from CPS other than 200: 404\"]\n"
+ + "}";
+
+ Mockito.when(executionBusinessLogic
+ .executeTemplate(ArgumentMatchers.any(), ArgumentMatchers.any(),
+ ArgumentMatchers.any()))
+ .thenThrow(new ExecuteException("Response from CPS other than 200: 404"));
+ mockMvc.perform(post(executePath).contentType(MediaType.APPLICATION_JSON)
+ .characterEncoding("utf-8")
+ .content(requestJson).accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().json(responseJson));
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.rest;
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mockito;
+import org.onap.cps.tbdmt.exception.TemplateNotFoundException;
+import org.onap.cps.tbdmt.model.Template;
+import org.onap.cps.tbdmt.model.TemplateRequest;
+import org.onap.cps.tbdmt.service.TemplateBusinessLogic;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+
+@RunWith(SpringRunner.class)
+@WebMvcTest(TemplateController.class)
+public class TemplateControllerTest {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @MockBean
+ private TemplateBusinessLogic templateBusinessLogic;
+
+ private ObjectMapper mapper;
+
+ private Template template;
+
+ @Before
+ public void setup() {
+ mapper = new ObjectMapper();
+ template = new Template("getNbr", "ran-network", "sample");
+ }
+
+ @Test
+ public void testCreateTemplate() throws Exception {
+ final TemplateRequest emptyTemplateRequest = new TemplateRequest();
+ emptyTemplateRequest.setTemplateId("getNbr");
+ emptyTemplateRequest.setModel("ran-network");
+ final String emptyTemplateJson = mapper.writeValueAsString(emptyTemplateRequest);
+ mockMvc.perform(
+ post("/templates").contentType(MediaType.APPLICATION_JSON).characterEncoding("utf-8")
+ .content(emptyTemplateJson).accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isBadRequest());
+
+ final TemplateRequest request = new TemplateRequest("getNbr", "ran-network", "sample");
+ final String templateJson = mapper.writeValueAsString(request);
+ Mockito.when(templateBusinessLogic.createTemplate(ArgumentMatchers.any()))
+ .thenReturn(template);
+ mockMvc.perform(
+ post("/templates").contentType(MediaType.APPLICATION_JSON).characterEncoding("utf-8")
+ .content(templateJson).accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isCreated())
+ .andExpect(content().json(templateJson));
+ }
+
+ @Test
+ public void testGetAllTemplates() throws Exception {
+ final List<Template> templates = new ArrayList<>();
+ templates.add(template);
+ final String templatesJson = mapper.writeValueAsString(templates);
+ Mockito.when(templateBusinessLogic.getAllTemplates()).thenReturn(templates);
+ mockMvc.perform(get("/templates").accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().json(templatesJson));
+
+ Mockito.when(templateBusinessLogic.getAllTemplates()).thenReturn(new ArrayList<>());
+ mockMvc.perform(get("/templates").accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound());
+
+ }
+
+ @Test
+ public void testGetTemplate() throws Exception {
+ final String templateJson = mapper.writeValueAsString(template);
+ Mockito.when(templateBusinessLogic.getTemplate(ArgumentMatchers.any()))
+ .thenReturn(template);
+ mockMvc.perform(get("/templates/ran-network/getNbr").accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().json(templateJson));
+
+ Mockito.when(templateBusinessLogic.getTemplate(ArgumentMatchers.any()))
+ .thenThrow(new TemplateNotFoundException("Template not found"));
+ mockMvc.perform(get("/templates/ran-network/getNbr").accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound());
+ }
+
+ @Test
+ public void testDeleteTemplate() throws Exception {
+ Mockito.doNothing().when(templateBusinessLogic).deleteTemplate(ArgumentMatchers.any());
+ mockMvc.perform(delete("/templates/ran-network/getNbr").accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk());
+
+ Mockito.doThrow(new TemplateNotFoundException("Template not found"))
+ .when(templateBusinessLogic)
+ .deleteTemplate(ArgumentMatchers.any());
+ mockMvc.perform(delete("/templates/ran-network/getNbr").accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isNotFound());
+ }
+
+}
<artifactId>cps-tbdmt-service</artifactId>
<packaging>jar</packaging>
+ <properties>
+ <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.data</groupId>
+ <artifactId>spring-data-commons</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-jpa</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.hubspot.jinjava</groupId>
+ <artifactId>jinjava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-json</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-validation</artifactId>
+ </dependency>
+ <!--Test dependencies-->
+ <dependency>
+ <groupId>com.openpojo</groupId>
+ <artifactId>openpojo</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
\ No newline at end of file
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.client;
+
+import java.util.Arrays;
+import org.onap.cps.tbdmt.exception.CpsClientException;
+import org.onap.cps.tbdmt.model.AppConfiguration;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+@Component
+public class CpsRestClient {
+
+ private static final String NODES_API_PATH = "%s/anchors/%s/nodes?cps-path=%s";
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ @Autowired
+ private AppConfiguration appConfiguration;
+
+ /**
+ * Fetch node from the CPS using xpath.
+ *
+ * @param anchor anchor
+ * @param xpath xpath query
+ * @return result Response string from CPS
+ */
+ public String fetchNode(final String anchor, final String xpath) throws CpsClientException {
+ final String url = appConfiguration.getXnfProxyUrl();
+
+ final String uri = String.format(NODES_API_PATH, url, anchor, xpath);
+
+ final HttpHeaders headers = new HttpHeaders();
+ headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
+ final HttpEntity<String> entity = new HttpEntity<>(headers);
+
+ ResponseEntity<String> responseEntity = null;
+ try {
+ responseEntity = restTemplate.exchange(uri, HttpMethod.GET, entity, String.class);
+ } catch (final Exception e) {
+ throw new CpsClientException(e.getLocalizedMessage());
+ }
+
+ final int statusCode = responseEntity.getStatusCodeValue();
+
+ if (statusCode == 200) {
+ return responseEntity.getBody();
+ } else {
+ throw new CpsClientException(
+ String.format("Response code from CPS other than 200: %d", statusCode));
+ }
+ }
+
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.db;
+
+import org.onap.cps.tbdmt.model.Template;
+import org.onap.cps.tbdmt.model.TemplateKey;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface TemplateRepository extends CrudRepository<Template, TemplateKey> {
+
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.exception;
+
+public class CpsClientException extends Exception {
+
+ public CpsClientException(final String exception) {
+ super(exception);
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.exception;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+@ResponseStatus(HttpStatus.OK)
+public class ExecuteException extends RuntimeException {
+
+ public ExecuteException(final String exception) {
+ super(exception);
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.exception;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+@ResponseStatus(HttpStatus.NOT_FOUND)
+public class TemplateNotFoundException extends RuntimeException {
+
+ public TemplateNotFoundException(final String exception) {
+ super(exception);
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.model;
+
+import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+
+@Getter
+@Setter
+@Configuration
+@EnableConfigurationProperties
+@ConfigurationProperties(prefix = "app")
+public class AppConfiguration {
+
+ private String xnfProxyUrl;
+ private Map<String, String> schemaToAnchor;
+
+ @Bean
+ public RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.model;
+
+import java.util.List;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+@AllArgsConstructor
+public class ErrorResponse {
+
+ private String message;
+ private List<String> details;
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.model;
+
+import java.util.Map;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+public class ExecutionRequest {
+
+ private Map<String, String> input;
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.model;
+
+import lombok.AllArgsConstructor;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+@EqualsAndHashCode
+@AllArgsConstructor
+public class ExecutionResponse {
+
+ private Object result;
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.model;
+
+import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.Table;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+@Entity
+@Table(name = "Template")
+@IdClass(TemplateKey.class)
+public class Template implements Serializable {
+
+ private static final long serialVersionUID = 345L;
+
+ @Id
+ private String templateId;
+
+ @Id
+ private String model;
+
+ private String xpathTemplate;
+
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.model;
+
+import java.io.Serializable;
+import lombok.AllArgsConstructor;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@Getter
+@Setter
+@EqualsAndHashCode
+@AllArgsConstructor
+@NoArgsConstructor
+public class TemplateKey implements Serializable {
+
+ private static final long serialVersionUID = 400L;
+
+ private String templateId;
+
+ private String model;
+
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.model;
+
+import java.io.Serializable;
+import javax.validation.constraints.NotEmpty;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+public class TemplateRequest implements Serializable {
+
+ private static final long serialVersionUID = 543L;
+
+ @NotEmpty(message = "template id missing")
+ private String templateId;
+
+ @NotEmpty(message = "model missing")
+ private String model;
+
+ @NotEmpty(message = "template missing")
+ private String xpathTemplate;
+
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.service;
+
+import com.hubspot.jinjava.Jinjava;
+import java.util.Map;
+import java.util.Optional;
+import org.onap.cps.tbdmt.client.CpsRestClient;
+import org.onap.cps.tbdmt.db.TemplateRepository;
+import org.onap.cps.tbdmt.exception.CpsClientException;
+import org.onap.cps.tbdmt.exception.ExecuteException;
+import org.onap.cps.tbdmt.exception.TemplateNotFoundException;
+import org.onap.cps.tbdmt.model.AppConfiguration;
+import org.onap.cps.tbdmt.model.ExecutionRequest;
+import org.onap.cps.tbdmt.model.Template;
+import org.onap.cps.tbdmt.model.TemplateKey;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class ExecutionBusinessLogic {
+
+ @Autowired
+ private TemplateRepository templateRepository;
+
+ @Autowired
+ private AppConfiguration appConfiguration;
+
+ @Autowired
+ private CpsRestClient cpsRestClient;
+
+ /**
+ * Execute a template stored in the database.
+ *
+ * @param schemaSet schema set
+ * @param id id
+ * @param executionRequest inputs to be applied to the templates
+ * @return result response from the execution of template
+ */
+ public String executeTemplate(final String schemaSet, final String id, final ExecutionRequest executionRequest) {
+
+ final Optional<Template> templateOptional = templateRepository.findById(new TemplateKey(id, schemaSet));
+ if (templateOptional.isPresent()) {
+ return execute(templateOptional.get(), executionRequest.getInput());
+ }
+ throw new TemplateNotFoundException("Template does not exist");
+ }
+
+ private String execute(final Template template, final Map<String, String> input) {
+ final String anchor = appConfiguration.getSchemaToAnchor().get(template.getModel());
+ if (anchor == null) {
+ throw new ExecuteException("Anchor not found for the schema");
+ }
+ final Jinjava jinja = new Jinjava();
+ final String xpath = jinja.render(template.getXpathTemplate(), input);
+ try {
+ return cpsRestClient.fetchNode(anchor, xpath);
+ } catch (final CpsClientException e) {
+ throw new ExecuteException(e.getLocalizedMessage());
+ }
+ }
+
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.service;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Optional;
+import org.onap.cps.tbdmt.db.TemplateRepository;
+import org.onap.cps.tbdmt.exception.TemplateNotFoundException;
+import org.onap.cps.tbdmt.model.Template;
+import org.onap.cps.tbdmt.model.TemplateKey;
+import org.onap.cps.tbdmt.model.TemplateRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class TemplateBusinessLogic {
+
+ private static final String TEMPLATE_NOT_FOUND_ERROR = "Template not found for given id: %s";
+
+ @Autowired
+ private TemplateRepository templateRepository;
+
+ /**
+ * Create Template.
+ *
+ * @param templateRequest request object
+ * @return template
+ */
+ public Template createTemplate(final TemplateRequest templateRequest) {
+ final Template template = new Template(templateRequest.getTemplateId(),
+ templateRequest.getModel(),
+ templateRequest.getXpathTemplate());
+ return templateRepository.save(template);
+ }
+
+ /**
+ * Get All Templates.
+ *
+ * @return templates
+ */
+ public Collection<Template> getAllTemplates() {
+ final Collection<Template> templates = new HashSet<>();
+ templateRepository.findAll().forEach(templates::add);
+ return templates;
+ }
+
+ /**
+ * Get Template by Id.
+ *
+ * @param templateKey template id to find the template
+ * @return template
+ */
+ public Template getTemplate(final TemplateKey templateKey) {
+ final Optional<Template> template = templateRepository.findById(templateKey);
+ if (template.isPresent()) {
+ return template.get();
+ } else {
+ final String errorMessage = String.format(TEMPLATE_NOT_FOUND_ERROR,
+ templateKey.getTemplateId());
+ throw new TemplateNotFoundException(errorMessage);
+ }
+ }
+
+ /**
+ * Delete Template.
+ *
+ * @param templateKey template id to find the template
+ */
+ public void deleteTemplate(final TemplateKey templateKey) {
+ if (templateRepository.existsById(templateKey)) {
+ templateRepository.deleteById(templateKey);
+ } else {
+ final String errorMessage = String.format(TEMPLATE_NOT_FOUND_ERROR,
+ templateKey.getTemplateId());
+ throw new TemplateNotFoundException(errorMessage);
+ }
+ }
+}
--- /dev/null
+CREATE TABLE Template(
+ templateId TEXT NOT NULL,
+ model TEXT NOT NULL,
+ xpathTemplate TEXT NOT NULL,
+ PRIMARY KEY(id, schema_set)
+);
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.client;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mockito;
+import org.onap.cps.tbdmt.exception.CpsClientException;
+import org.onap.cps.tbdmt.model.AppConfiguration;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.web.client.RestClientException;
+import org.springframework.web.client.RestTemplate;
+
+@RunWith(SpringRunner.class)
+@EnableConfigurationProperties(AppConfiguration.class)
+@TestPropertySource("classpath:application-test.properties")
+public class CpsRestClientTest {
+
+ @TestConfiguration
+ static class CpsRestClientTestContextConfiguration {
+
+ @Bean
+ public CpsRestClient cpsRestClient() {
+ return new CpsRestClient();
+ }
+ }
+
+ @Autowired
+ private CpsRestClient cpsRestClient;
+
+ @MockBean
+ private RestTemplate restTemplate;
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+ @Test
+ public void testFetchNode() throws Exception {
+ final HttpHeaders responseHeaders = new HttpHeaders();
+ responseHeaders.setContentType(MediaType.APPLICATION_JSON);
+ final ResponseEntity<String> response = new ResponseEntity<>("sample response", responseHeaders,
+ HttpStatus.OK);
+ Mockito.when(restTemplate.exchange(ArgumentMatchers.anyString(),
+ ArgumentMatchers.any(HttpMethod.class),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.<Class<String>>any()))
+ .thenReturn(response);
+ assertEquals("sample response", cpsRestClient.fetchNode("coverage-area-onap", "sample"));
+
+ final ResponseEntity<String> errorResponse = new ResponseEntity<>("sample response",
+ responseHeaders, HttpStatus.NOT_FOUND);
+ Mockito.when(restTemplate.exchange(ArgumentMatchers.anyString(),
+ ArgumentMatchers.any(HttpMethod.class),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.<Class<String>>any()))
+ .thenReturn(errorResponse);
+ exception.expect(CpsClientException.class);
+ exception.expectMessage("Response code from CPS other than 200: 404");
+ cpsRestClient.fetchNode("coverage-area-onap", "sample");
+
+ }
+
+ @Test
+ public void testFetchNodeException() throws Exception {
+ Mockito.when(restTemplate.exchange(ArgumentMatchers.anyString(),
+ ArgumentMatchers.any(HttpMethod.class),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.<Class<String>>any()))
+ .thenThrow(new RestClientException("Connection refused"));
+ exception.expect(CpsClientException.class);
+ exception.expectMessage("Connection refused");
+ cpsRestClient.fetchNode("coverage-area-onap", "sample");
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.model;
+
+import com.openpojo.reflection.filters.FilterPackageInfo;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.rule.impl.GetterMustExistRule;
+import com.openpojo.validation.rule.impl.SetterMustExistRule;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+import org.junit.Test;
+
+public class ModelTest {
+
+ private static final String POJO_PACKAGE = "org.onap.cps.tbdmt.model";
+
+ @Test
+ public void testModels() {
+ final Validator validator = ValidatorBuilder.create()
+ .with(new GetterMustExistRule())
+ .with(new SetterMustExistRule())
+ .with(new SetterTester())
+ .with(new GetterTester())
+ .build();
+
+ validator.validate(POJO_PACKAGE, new FilterPackageInfo());
+
+ }
+
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.service;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mockito;
+import org.onap.cps.tbdmt.client.CpsRestClient;
+import org.onap.cps.tbdmt.db.TemplateRepository;
+import org.onap.cps.tbdmt.exception.CpsClientException;
+import org.onap.cps.tbdmt.exception.ExecuteException;
+import org.onap.cps.tbdmt.exception.TemplateNotFoundException;
+import org.onap.cps.tbdmt.model.AppConfiguration;
+import org.onap.cps.tbdmt.model.ExecutionRequest;
+import org.onap.cps.tbdmt.model.Template;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@EnableConfigurationProperties(AppConfiguration.class)
+@TestPropertySource("classpath:application-test.properties")
+public class ExecutionBusinessLogicTest {
+
+ @TestConfiguration
+ static class ExecutionBusinessLogicTestContextConfiguration {
+
+ @Bean
+ public ExecutionBusinessLogic executionBusinessLogic() {
+ return new ExecutionBusinessLogic();
+ }
+ }
+
+ @Autowired
+ private ExecutionBusinessLogic executionBusinessLogic;
+
+ @MockBean
+ private TemplateRepository templateRepository;
+
+ @MockBean
+ private CpsRestClient cpsRestClient;
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+ private ExecutionRequest request;
+
+ private Template template;
+
+ /**
+ * Setup variables before test.
+ *
+ */
+ @Before
+ public void setup() {
+ final Map<String, String> input = new HashMap<>();
+ input.put("coverageArea", "Zone 1");
+ request = new ExecutionRequest(input);
+ final String xpathTemplate = "/ran-coverage-area/pLMNIdList[@mcc='310' and @mnc='410']"
+ + "/coverage-area[@coverageArea='{{coverageArea}}']";
+ template = new Template("getNbr", "ran-network", xpathTemplate);
+ }
+
+ @Test
+ public void testExecuteTemplate() throws Exception {
+ final String resultString = "[{\"key\": \"value\"}]";
+ Mockito.when(cpsRestClient
+ .fetchNode("ran-network", "/ran-coverage-area/pLMNIdList[@mcc='310' and @mnc='410']"
+ + "/coverage-area[@coverageArea='Zone 1']"))
+ .thenReturn(resultString);
+ Mockito.when(templateRepository.findById(ArgumentMatchers.any()))
+ .thenReturn(Optional.of(template));
+ assertEquals(resultString,
+ executionBusinessLogic.executeTemplate("ran-network", "getNbr", request));
+
+ Mockito.when(templateRepository.findById(ArgumentMatchers.any()))
+ .thenReturn(Optional.empty());
+ exception.expect(TemplateNotFoundException.class);
+ exception.expectMessage("Template does not exist");
+ executionBusinessLogic.executeTemplate("ran-network", "getNbr", request);
+
+ }
+
+ @Test
+ public void testExecuteTemplateException() throws Exception {
+ final String exceptionMessage = "Response from CPS other than 200: 404";
+ Mockito.when(cpsRestClient
+ .fetchNode("ran-network", "/ran-coverage-area/pLMNIdList[@mcc='310' and @mnc='410']"
+ + "/coverage-area[@coverageArea='Zone 1']"))
+ .thenThrow(new CpsClientException(exceptionMessage));
+ Mockito.when(templateRepository.findById(ArgumentMatchers.any()))
+ .thenReturn(Optional.of(template));
+ exception.expect(ExecuteException.class);
+ exception.expectMessage(exceptionMessage);
+ executionBusinessLogic.executeTemplate("ran-network", "getNbr", request);
+
+ final Template template1 = new Template("getNbr", "ran-net", "sample");
+ Mockito.when(templateRepository.findById(ArgumentMatchers.any()))
+ .thenReturn(Optional.of(template1));
+ exception.expect(ExecuteException.class);
+ exception.expectMessage("Anchor not found for the schema");
+ executionBusinessLogic.executeTemplate("ran-net", "getNbr", request);
+
+ }
+
+ @Test
+ public void testExecuteTemplateNoAnchor() {
+ final Template template = new Template("getNbr", "ran-net", "sample");
+ Mockito.when(templateRepository.findById(ArgumentMatchers.any()))
+ .thenReturn(Optional.of(template));
+ exception.expect(ExecuteException.class);
+ exception.expectMessage("Anchor not found for the schema");
+ executionBusinessLogic.executeTemplate("ran-net", "getNbr", request);
+ }
+
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.service;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Optional;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mockito;
+import org.onap.cps.tbdmt.db.TemplateRepository;
+import org.onap.cps.tbdmt.exception.TemplateNotFoundException;
+import org.onap.cps.tbdmt.model.Template;
+import org.onap.cps.tbdmt.model.TemplateKey;
+import org.onap.cps.tbdmt.model.TemplateRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+public class TemplateBusinessLogicTest {
+
+ @TestConfiguration
+ static class TemplateBusinessLogicTestContextConfiguration {
+
+ @Bean
+ public TemplateBusinessLogic templateBusinessLogic() {
+ return new TemplateBusinessLogic();
+ }
+ }
+
+ @Autowired
+ private TemplateBusinessLogic templateBusinessLogic;
+
+ @MockBean
+ private TemplateRepository templateRepository;
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+ private Template template;
+ private TemplateKey templateKey;
+
+ @Before
+ public void setup() {
+ template = new Template("getNbr", "ran-network", "sample");
+ final TemplateKey templateKey = new TemplateKey("getNbr", "ran-network");
+ }
+
+ @Test
+ public void testCreateTemplate() throws Exception {
+ final TemplateRequest templateRequest = new TemplateRequest("getNbr", "ran-network", "sample");
+ Mockito.when(templateRepository.save(ArgumentMatchers.any())).thenReturn(template);
+ assertEquals(template, templateBusinessLogic.createTemplate(templateRequest));
+ }
+
+ @Test
+ public void testGetAllTemplates() throws Exception {
+ final Collection<Template> templates = new HashSet<>();
+ templates.add(template);
+ Mockito.when(templateRepository.findAll()).thenReturn(templates);
+ assertEquals(templates, templateBusinessLogic.getAllTemplates());
+ }
+
+ @Test
+ public void testGetTemplate() throws Exception {
+ Mockito.when(templateRepository.findById(templateKey)).thenReturn(Optional.of(template));
+ assertEquals(template, templateBusinessLogic.getTemplate(templateKey));
+
+ Mockito.when(templateRepository.findById(ArgumentMatchers.any()))
+ .thenReturn(Optional.empty());
+ exception.expect(TemplateNotFoundException.class);
+ exception.expectMessage("Template not found for given id: getNbr");
+ templateBusinessLogic.getTemplate(new TemplateKey("getNbr", "empty-schema"));
+ }
+
+ @Test
+ public void testDeleteTemplate() throws Exception {
+ Mockito.when(templateRepository.existsById(templateKey)).thenReturn(true);
+ templateBusinessLogic.deleteTemplate(templateKey);
+ verify(templateRepository, times(1)).deleteById(templateKey);
+
+ Mockito.when(templateRepository.existsById(ArgumentMatchers.any())).thenReturn(false);
+ exception.expect(TemplateNotFoundException.class);
+ exception.expectMessage("Template not found for given id: getNbr");
+ templateBusinessLogic.deleteTemplate(new TemplateKey("getNbr", "empty-schema"));
+ }
+}
--- /dev/null
+app.xnfProxyUrl=http://localhost:8000/
+app.schemaToAnchor.ran-coverage-area=coverage-area-onap
+app.schemaToAnchor.ran-network=ran-network
\ No newline at end of file
--- /dev/null
+###############################################################################
+# ============LICENSE_START=======================================================
+# ONAP
+# ================================================================================
+# Copyright (C) 2021 Wipro Limited.
+# ==============================================================================
+# 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=========================================================
+#
+###############################################################################
+
+spring:
+ datasource:
+ initialization-mode: always
+ initialize: true
+ url: jdbc:postgresql://postgres:5432/cps_template_db
+ username: postgres
+ password: postgres
+ continue-on-error: true
+ jpa:
+ hibernate:
+ ddl-auto: update
+ properties:
+ hibernate:
+ temp:
+ use_jdbc_metadata_defaults: false
+ database-platform: org.hibernate.dialect.PostgreSQLDialect
+app:
+ xnfProxyUrl: http://localhost:8000/
+ schemaToAnchor:
+ ran-coverage-area: coverage-area-onap
--- /dev/null
+# ============LICENSE_START=======================================================
+# cps-tdmt
+# ================================================================================
+# Copyright (C) 2021 Wipro Limited.
+# ==============================================================================
+# 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=========================================================
+version: '3.7'
+networks:
+ cps-tbdmt-default:
+ driver: bridge
+ driver_opts:
+ com.docker.network.driver.mtu: 1400
+services:
+ postgres:
+ image: 'postgres:12.4-alpine'
+ container_name: cps-tbdmt-postgres
+ hostname: postgres
+ environment:
+ - POSTGRES_USER=postgres
+ - POSTGRES_PASSWORD=postgres
+ - POSTGRES_DB=cps_template_db
+ ports:
+ - 5432
+ healthcheck:
+ test: ["CMD", "nc", "-z", "localhost", "5432"]
+ interval: 30s
+ timeout: 10s
+ retries: 5
+ networks:
+ - cps-tbdmt-default
+ cps-tdmt:
+ image: "cps-tbdmt:latest"
+ container_name: cps-tbdmt
+ hostname: cps-tbdmt
+ ports:
+ - "8080:8080"
+ volumes:
+ - "./application.yml:/app/resources/application.yml"
+ depends_on:
+ - postgres
+ networks:
+ - cps-tbdmt-default
\ No newline at end of file
</properties>
<modules>
- <module>cps-tbdmt-service</module>
- <module>cps-tbdmt-rest</module>
<module>cps-tbdmt-dependencies</module>
<module>cps-tbdmt-bom</module>
<module>cps-tbdmt-parent</module>
+ <module>cps-tbdmt-service</module>
+ <module>cps-tbdmt-rest</module>
<module>cps-tbdmt-application</module>
</modules>