From 42b670cfd17dab61dbd6632080c95572ea3b83c8 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 21 Aug 2018 04:11:57 +0000 Subject: Controller Blueprints Microservice Define Controllerblueprint API DataType and Error definitions for Config model, Service Template, Model Type and Resource Dictionary Services Change-Id: I12d8d87292ec101601b0cfb7ba9670730973e318 Issue-ID: CCSDK-469 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- ms/controllerblueprints/README.md | 9 +++ .../artifact_type/artifact-bpmn-camunda.json | 8 +++ .../artifact_type/artifact-directed-graph.json | 9 +++ .../opt/app/onap/config/application.properties | 3 + .../ApplicationExceptionHandler.java | 42 +++++++++++++ .../apps/controllerblueprints/CorsConfig.java | 27 +++++---- .../ControllerBluprintsApplicationTest.java | 22 +++++-- .../src/test/resources/application.properties | 2 +- .../application/src/test/resources/logback.xml | 3 +- .../artifact_type/artifact-bpmn-camunda.json | 8 +++ .../artifact_type/artifact-directed-graph.json | 9 +++ .../core/ConfigModelConstant.kt | 5 -- .../core/data/BluePrintModel.kt | 9 ++- .../core/utils/JacksonUtils.kt | 7 +++ .../load/resource_dictionary/db-source.json | 31 ++++++++++ .../load/resource_dictionary/default-source.json | 14 +++++ .../load/resource_dictionary/input-source.json | 17 ++++++ .../load/resource_dictionary/mdsal-source.json | 36 +++++++++++ .../resource/dict/ResourceAssignment.java | 6 +- .../resource/dict/ResourceDictionaryConstants.java | 24 ++++++++ .../resource/dict/data/DictionaryDefinition.java | 11 ++-- .../resource/dict/data/ResourceSource.java | 22 +++++++ .../resource/dict/data/SourceDb.java | 2 +- .../resource/dict/data/SourceDefault.java | 2 +- .../resource/dict/data/SourceDeserializer.java | 67 +++++++++++++++++++++ .../resource/dict/data/SourceInput.java | 3 +- .../resource/dict/data/SourceMdsal.java | 3 +- .../dict/utils/ResourceDictionaryUtils.java | 10 ++-- .../dict/util/DictionaryDefinitionTest.java | 70 ++++++++++++++++++++++ .../dict/util/ResourceDictionaryUtilsTest.java | 27 ++++----- .../load/resource_dictionary/action-name.json | 17 ------ .../load/resource_dictionary/bundle-id.json | 32 ---------- .../load/resource_dictionary/db-source.json | 31 ++++++++++ .../load/resource_dictionary/input-source.json | 17 ++++++ .../load/resource_dictionary/v4-ip-type.json | 4 +- .../service/ApplicationRegistrationService.java | 39 ++++++++++++ .../service/common/ErrorMessage.java | 32 ++++++---- .../service/domain/ConfigModel.java | 8 ++- .../service/domain/ConfigModelContent.java | 6 +- .../service/domain/ModelType.java | 12 +++- .../service/domain/ResourceDictionary.java | 11 ++++ .../service/rs/ConfigModelRest.java | 21 ++++--- .../service/rs/ModelTypeRest.java | 11 ++-- .../service/rs/ResourceDictionaryRest.java | 11 ++-- .../service/rs/ServiceTemplateRest.java | 13 ++-- .../service/rs/ResourceDictionaryRestTest.java | 6 +- 46 files changed, 625 insertions(+), 154 deletions(-) create mode 100644 ms/controllerblueprints/application/load/model_type/artifact_type/artifact-bpmn-camunda.json create mode 100644 ms/controllerblueprints/application/load/model_type/artifact_type/artifact-directed-graph.json create mode 100644 ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationExceptionHandler.java create mode 100644 ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-bpmn-camunda.json create mode 100644 ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-directed-graph.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json create mode 100644 ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDeserializer.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/DictionaryDefinitionTest.java delete mode 100644 ms/controllerblueprints/modules/service/load/resource_dictionary/action-name.json delete mode 100644 ms/controllerblueprints/modules/service/load/resource_dictionary/bundle-id.json create mode 100644 ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json create mode 100644 ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java (limited to 'ms/controllerblueprints') diff --git a/ms/controllerblueprints/README.md b/ms/controllerblueprints/README.md index e69de29b..070a5416 100755 --- a/ms/controllerblueprints/README.md +++ b/ms/controllerblueprints/README.md @@ -0,0 +1,9 @@ +Application VM Arguments : + +-Dlogging.config=etc/logback.xml +-Dspring.config.location=opt/app/onap/config/ +-Dspring.datasource.url=jdbc:mysql://127.0.0.1:3306/sdnctl +-Dspring.datasource.username=sdnctl +-Dspring.datasource.password=sdnctl +-Dblueprints.load.initial-data=true + diff --git a/ms/controllerblueprints/application/load/model_type/artifact_type/artifact-bpmn-camunda.json b/ms/controllerblueprints/application/load/model_type/artifact_type/artifact-bpmn-camunda.json new file mode 100644 index 00000000..ac76b4f4 --- /dev/null +++ b/ms/controllerblueprints/application/load/model_type/artifact_type/artifact-bpmn-camunda.json @@ -0,0 +1,8 @@ +{ + "description": " Camunda BPM File", + "version": "1.0.0", + "file_ext": [ + "bpmn" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/ms/controllerblueprints/application/load/model_type/artifact_type/artifact-directed-graph.json b/ms/controllerblueprints/application/load/model_type/artifact_type/artifact-directed-graph.json new file mode 100644 index 00000000..7ab3a543 --- /dev/null +++ b/ms/controllerblueprints/application/load/model_type/artifact_type/artifact-directed-graph.json @@ -0,0 +1,9 @@ +{ + "description": "Directed Graph File", + "version": "1.0.0", + "file_ext": [ + "json", + "xml" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/ms/controllerblueprints/application/opt/app/onap/config/application.properties b/ms/controllerblueprints/application/opt/app/onap/config/application.properties index 9fa8e04c..f075b578 100644 --- a/ms/controllerblueprints/application/opt/app/onap/config/application.properties +++ b/ms/controllerblueprints/application/opt/app/onap/config/application.properties @@ -20,6 +20,9 @@ logging.level.org.springframework.web=INFO logging.level.org.hibernate.SQL=warn logging.level.org.hibernate.type.descriptor.sql=debug +#To Remove Null in JSON API Response +spring.jackson.default-property-inclusion=non_null + spring.jpa.properties.hibernate.show_sql=true spring.jpa.properties.hibernate.use_sql_comments=true spring.jpa.properties.hibernate.format_sql=true diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationExceptionHandler.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationExceptionHandler.java new file mode 100644 index 00000000..d02be5c2 --- /dev/null +++ b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationExceptionHandler.java @@ -0,0 +1,42 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints; + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.service.common.ErrorMessage; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.context.request.WebRequest; + +@ControllerAdvice +@RestController +public class ApplicationExceptionHandler { + @ExceptionHandler(Exception.class) + public final ResponseEntity handleAllExceptions(Exception ex, WebRequest request) { + ErrorMessage exceptionResponse = new ErrorMessage( ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR.value(), ex.getLocalizedMessage()); + return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR); + } + + @ExceptionHandler(BluePrintException.class) + public final ResponseEntity handleBlueprintException(BluePrintException ex, WebRequest request) { + ErrorMessage exceptionResponse = new ErrorMessage( ex.getMessage(), ex.getCode(), ex.getLocalizedMessage()); + return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR); + } +} diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/CorsConfig.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/CorsConfig.java index 5d682ed5..d00d2c84 100644 --- a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/CorsConfig.java +++ b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/CorsConfig.java @@ -20,8 +20,9 @@ package org.onap.ccsdk.apps.controllerblueprints; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import org.springframework.web.filter.CorsFilter; +import org.springframework.web.cors.reactive.CorsWebFilter; +import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; +import java.util.Arrays; /** * CorsConfig.java Purpose: Provide Configuration Generator CorsConfig Information @@ -29,7 +30,7 @@ import org.springframework.web.filter.CorsFilter; * @author Brinda Santh * @version 1.0 */ -//@Configuration +@Configuration public class CorsConfig { /** * This is a CORS Implementation for different Orgin GUI to access. @@ -37,15 +38,17 @@ public class CorsConfig { * @return CorsFilter */ @Bean - public CorsFilter corsFilter() { - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - CorsConfiguration config = new CorsConfiguration(); - config.setAllowCredentials(true); - config.addAllowedOrigin("*"); - config.addAllowedHeader("*"); - config.addAllowedMethod("*"); - source.registerCorsConfiguration("/**", config); - return new CorsFilter(source); + CorsWebFilter corsWebFilter() { + CorsConfiguration corsConfig = new CorsConfiguration(); + corsConfig.setAllowedOrigins(Arrays.asList("*")); + corsConfig.setMaxAge(8000L); + corsConfig.addAllowedMethod("*"); + + UrlBasedCorsConfigurationSource source = + new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", corsConfig); + + return new CorsWebFilter(source); } diff --git a/ms/controllerblueprints/application/src/test/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplicationTest.java b/ms/controllerblueprints/application/src/test/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplicationTest.java index 95639bd3..26b943b6 100644 --- a/ms/controllerblueprints/application/src/test/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplicationTest.java +++ b/ms/controllerblueprints/application/src/test/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplicationTest.java @@ -16,17 +16,18 @@ package org.onap.ccsdk.apps.controllerblueprints; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; +import org.springframework.http.*; import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -46,8 +47,21 @@ public class ControllerBluprintsApplicationTest { @Test public void testConfigModel() { - ResponseEntity entity = this.restTemplate - .getForEntity("/api/v1/config-model/1", String.class); + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); + ResponseEntity entity = this.restTemplate + .exchange("/api/v1/config-model/1", HttpMethod.GET, new HttpEntity<>(headers),ConfigModel.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + Assert.assertNotNull("failed to get response Config model",entity.getBody()); + } + + @Test + public void testConfigModelFailure() { + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); + ResponseEntity entity = this.restTemplate + .exchange("/api/v1/config-model-not-found/1", HttpMethod.GET, new HttpEntity<>(headers),ConfigModel.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + Assert.assertNotNull("failed to get response Config model",entity.getBody()); } } diff --git a/ms/controllerblueprints/application/src/test/resources/application.properties b/ms/controllerblueprints/application/src/test/resources/application.properties index 55ffeaf1..a147034f 100644 --- a/ms/controllerblueprints/application/src/test/resources/application.properties +++ b/ms/controllerblueprints/application/src/test/resources/application.properties @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # - +spring.jackson.default-property-inclusion=non_null #Load Blueprints # blueprints.load.initial-data may be overridden by ENV variables blueprints.load.initial-data=true diff --git a/ms/controllerblueprints/application/src/test/resources/logback.xml b/ms/controllerblueprints/application/src/test/resources/logback.xml index b9b97dc8..53388bc9 100644 --- a/ms/controllerblueprints/application/src/test/resources/logback.xml +++ b/ms/controllerblueprints/application/src/test/resources/logback.xml @@ -24,8 +24,7 @@ - - + diff --git a/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-bpmn-camunda.json b/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-bpmn-camunda.json new file mode 100644 index 00000000..ac76b4f4 --- /dev/null +++ b/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-bpmn-camunda.json @@ -0,0 +1,8 @@ +{ + "description": " Camunda BPM File", + "version": "1.0.0", + "file_ext": [ + "bpmn" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-directed-graph.json b/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-directed-graph.json new file mode 100644 index 00000000..7ab3a543 --- /dev/null +++ b/ms/controllerblueprints/modules/core/load/model_type/artifact_type/artifact-directed-graph.json @@ -0,0 +1,9 @@ +{ + "description": "Directed Graph File", + "version": "1.0.0", + "file_ext": [ + "json", + "xml" + ], + "derived_from": "tosca.artifacts.Implementation" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt index bb5a78fd..97826912 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt @@ -42,11 +42,6 @@ object ConfigModelConstant { const val CAPABILITY_PROPERTY_MAPPING = "mapping" - const val SOURCE_INPUT = "input" - const val SOURCE_DEFAULT = "default" - const val SOURCE_MDSAL = "mdsal" - const val SOURCE_DB = "db" - const val PROPERTY_RECIPE_NAMES = "action-names" } diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt index 6d677ffa..a10f6d30 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt @@ -155,7 +155,7 @@ class PropertyDefinition { var id: String? = null var description: String? = null var required: Boolean? = null - var type: String? = null + lateinit var type: String @get:JsonProperty("default") var defaultValue: Any? = null var status: String? = null @@ -202,7 +202,7 @@ class OperationDefinition { } class Implementation { - var primary: String? = null + lateinit var primary: String var dependencies: MutableList? = null } @@ -240,6 +240,11 @@ class TriggerDefinition { var description: String? = null @get:JsonProperty("event_type") lateinit var eventType: String + @get:JsonProperty("target_filter") + var targetFilter: EventFilterDefinition? = null + var condition: ConditionClause? = null + var constraint: ConditionClause? = null + var method: String? = null lateinit var action: String } diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt index 95b2af7b..9621382c 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt @@ -49,6 +49,13 @@ object JacksonUtils { return jacksonObjectMapper().readValue(content, valueType) } + @JvmStatic + fun readValueFromFile(fileName: String, valueType: Class): T? { + val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) + ?: throw BluePrintException(format("Failed to read json file : {}", fileName)) + return readValue(content, valueType) + } + @JvmStatic fun jsonNodeFromObject(from: kotlin.Any): JsonNode = jacksonObjectMapper().convertValue(from, JsonNode::class.java) diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json new file mode 100644 index 00000000..8b97cdeb --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/db-source.json @@ -0,0 +1,31 @@ +{ + "name": "bundle-id", + "description": "name of the ", + "resource-type": "ONAP", + "resource-path": "vnf/bundle-id", + "updated-by": "brindasanth@onap.com", + "data-type": "String", + "tags": "bundle-id, brindasanth@onap.com", + "source": { + "db": { + "query": "SELECT db-country, db-state FROM DEVICE_PROFILE WHERE profile_name = :profile_name", + "input-key-mapping": { + "profile_name": "profile_name" + }, + "output-key-mapping": { + "db-country": "country", + "db-state": "state" + } + } + }, + "decryption-rules": [ + { + "sources": [ + "input" + ], + "path": "/.", + "rule": "LOCAL-Decrypt", + "decrypt-type": "AES128" + } + ] +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json new file mode 100644 index 00000000..ac23292e --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/default-source.json @@ -0,0 +1,14 @@ +{ + "tags": "v4-ip-type, tosca.datatypes.Root, data_type, brindasanth@onap.com", + "name": "v4-ip-type", + "description": "To be provided", + "updated-by": "brindasanth@onap.com", + "resource-type": "ONAP", + "resource-path": "vnf/v4-ip-type", + "data-type": "string", + "source": { + "default": { + + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json new file mode 100644 index 00000000..35736b66 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/input-source.json @@ -0,0 +1,17 @@ +{ + "name": "action-name", + "resource-path": "action-name", + "resource-type": "ONAP", + "description": "To be provided", + "valid-values": null, + "sample-value": null, + "updated-by": "brindasanth@onap.com", + "tags": null, + "default": null, + "data-type": "string", + "source": { + "input": { + "key": "action-name" + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json new file mode 100644 index 00000000..c103f94d --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/mdsal-source.json @@ -0,0 +1,36 @@ +{ + "tags": "oam-local-ipv4-address, tosca.datatypes.Root, data_type, st1848@att.com", + "name": "oam-local-ipv4-address", + "description": "based on service-instance-id,network-role,v4-ip-type and vm-type get the ipv4-gateway-prefix from the SDN-GC mdsal", + "updated-by": "st1848@att.com", + "resource-type": "ATT", + "resource-path": "vnf/oam-local-ipv4-address", + "data-type": "string", + "source": { + "mdsal": { + "base": "sdnc-gc", + "type": "JSON", + "url-path": "config/L3VNF-API:services/service-list/$service-instance-id/service-data/vnf-topology-information/vnf-assignments/vnf-vms/$vm-type/vm-networks/$network-role/v4-assigned-ip-list/$v4-ip-type", + "path": "/v4-assigned-ip-list/0/v4-ip-prefix", + "input-key-mapping": { + "service-instance-id": "service-instance-id", + "network-role": "network-role", + "v4-ip-type": "v4-ip-type", + "vm-type": "vm-type" + }, + "output-key-mapping": { + "oam-local-ipv4-address": "v4-ip-prefix" + } + } + }, + "candidate-dependency": { + "mdsal": { + "names": [ + "service-instance-id", + "network-role", + "v4-ip-type", + "vm-type" + ] + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignment.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignment.java index 15576b90..f85e5ebc 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignment.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignment.java @@ -30,10 +30,10 @@ import java.util.List; * @version 1.0 */ public class ResourceAssignment { - + @JsonProperty(value = "name", required = true) private String name; - @JsonProperty("property") + @JsonProperty(value = "property", required = true) private PropertyDefinition property; @JsonProperty("input-param") @@ -58,7 +58,7 @@ public class ResourceAssignment { private String message; @JsonProperty("updated-date") - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") private Date updatedDate; @JsonProperty("updated-by") diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java new file mode 100644 index 00000000..1af42c59 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java @@ -0,0 +1,24 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict; + +public class ResourceDictionaryConstants { + public static final String SOURCE_INPUT= "input"; + public static final String SOURCE_DEFAULT = "default"; + public static final String SOURCE_DB = "db"; + public static final String SOURCE_MDSAL = "mdsal"; +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDefinition.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDefinition.java index 4dc9c89a..7c2d926f 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDefinition.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDefinition.java @@ -17,7 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import java.util.List; import java.util.Map; @@ -29,6 +29,7 @@ import java.util.Map; public class DictionaryDefinition { @JsonProperty(value = "name", required = true) private String name; + @JsonProperty(value = "description") private String description; @@ -39,6 +40,7 @@ public class DictionaryDefinition { private String sampleValue; private String tags; + @JsonProperty(value = "updated-by") private String updatedBy; @@ -58,7 +60,8 @@ public class DictionaryDefinition { private Object defaultValue; @JsonProperty(value = "source", required = true) - private Map source; + @JsonDeserialize(using = SourceDeserializer.class, keyAs = String.class, contentAs = ResourceSource.class) + private Map source; @JsonProperty("candidate-dependency") private Map dependency; @@ -154,11 +157,11 @@ public class DictionaryDefinition { this.defaultValue = defaultValue; } - public Map getSource() { + public Map getSource() { return source; } - public void setSource(Map source) { + public void setSource(Map source) { this.source = source; } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java new file mode 100644 index 00000000..735832cb --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java @@ -0,0 +1,22 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data; + +import java.io.Serializable; + +public interface ResourceSource extends Serializable { +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDb.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDb.java index 23d40460..724d0224 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDb.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDb.java @@ -24,7 +24,7 @@ import java.util.Map; * SourceDb * @author Brinda Santh */ -public class SourceDb { +public class SourceDb implements ResourceSource{ @JsonProperty(value = "base", required = true) private String base; @JsonProperty(value = "type", required = true) diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDefault.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDefault.java index 0a4351cc..d165192e 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDefault.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDefault.java @@ -20,7 +20,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data; * SourceDefault * @author Brinda Santh */ -public class SourceDefault { +public class SourceDefault implements ResourceSource { private String key; diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDeserializer.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDeserializer.java new file mode 100644 index 00000000..86476e1c --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDeserializer.java @@ -0,0 +1,67 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.common.base.Preconditions; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class SourceDeserializer extends JsonDeserializer> { + + private static final Logger log = LoggerFactory.getLogger(SourceDeserializer.class); + + private Class keyAs; + + private Class contentAs; + + private static Map> registry = new HashMap>(); + + public static void registerSource(String uniqueAttribute, Class sourceClass) { + registry.put(uniqueAttribute, sourceClass); + } + + @Override + public Map deserialize(JsonParser p, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + + ObjectMapper mapper = (ObjectMapper) p.getCodec(); + ObjectNode root = (ObjectNode) mapper.readTree(p); + Map sources = new HashMap(); + root.fields().forEachRemaining((node) -> { + String key = node.getKey(); + JsonNode valueNode = node.getValue(); + Preconditions.checkArgument(StringUtils.isNotBlank(key), "missing source key"); + Preconditions.checkArgument(registry.containsKey(key), key +" source not registered"); + if (StringUtils.isNotBlank(key) && registry.containsKey(key)) { + Class sourceClass = registry.get(key); + ResourceSource resourceSource = JacksonUtils.readValue(valueNode.toString(), sourceClass); + sources.put(key, resourceSource); + } + }); + return sources; + } +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceInput.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceInput.java index 82cb769d..87184f22 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceInput.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceInput.java @@ -20,7 +20,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data; * SourceInput * @author Brinda Santh */ -public class SourceInput { +public class SourceInput implements ResourceSource { private String key; @@ -33,5 +33,4 @@ public class SourceInput { } - } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceMdsal.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceMdsal.java index 9eb233e7..8a066e91 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceMdsal.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceMdsal.java @@ -24,7 +24,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Map; -public class SourceMdsal { +public class SourceMdsal implements ResourceSource { @JsonProperty(value = "base", required = true) private String base; @@ -93,5 +93,4 @@ public class SourceMdsal { } - } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java index 9d51d821..4f9467f0 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java @@ -16,15 +16,15 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils; -import com.fasterxml.jackson.databind.JsonNode; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; import org.onap.ccsdk.apps.controllerblueprints.core.data.EntrySchema; import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDependency; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.ResourceSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,7 +63,7 @@ public class ResourceDictionaryUtils { // Overwrite the Property Definitions from Dictionary setProperty(resourceAssignment, dictionaryDefinition); - Map dictionarySource = dictionaryDefinition.getSource(); + Map dictionarySource = dictionaryDefinition.getSource(); Map dictionaryDependencyMap = dictionaryDefinition.getDependency(); if (MapUtils.isNotEmpty(dictionarySource)) { @@ -82,7 +82,7 @@ public class ResourceDictionaryUtils { } } } else { - resourceAssignment.setDictionarySource(ConfigModelConstant.SOURCE_INPUT); + resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_INPUT); } log.info("auto map resourceAssignment : {}", resourceAssignment); } @@ -98,7 +98,7 @@ public class ResourceDictionaryUtils { } } - private static String findFirstSource(Map dictionarySource) { + private static String findFirstSource(Map dictionarySource) { String source = null; if (MapUtils.isNotEmpty(dictionarySource)) { source = dictionarySource.keySet().stream().findFirst().get(); diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/DictionaryDefinitionTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/DictionaryDefinitionTest.java new file mode 100644 index 00000000..851ba125 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/DictionaryDefinitionTest.java @@ -0,0 +1,70 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict.util; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DictionaryDefinitionTest { + private Logger log = LoggerFactory.getLogger(DictionaryDefinitionTest.class); + String basePath = "load/resource_dictionary"; + + @Before + public void setup(){ + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_DB, SourceDb.class); + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_INPUT, SourceInput.class); + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_MDSAL, SourceMdsal.class); + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_DEFAULT,SourceDefault.class); + } + + @Test + public void testDictionaryDefinitionInputSource(){ + + String fileName = basePath + "/input-source.json"; + DictionaryDefinition dictionaryDefinition = JacksonUtils.readValueFromFile(fileName, DictionaryDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for input type", dictionaryDefinition); + } + + @Test + public void testDictionaryDefinitionDefaultSource(){ + + String fileName = basePath + "/default-source.json"; + DictionaryDefinition dictionaryDefinition = JacksonUtils.readValueFromFile(fileName, DictionaryDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for default type", dictionaryDefinition); + } + + @Test + public void testDictionaryDefinitionDBSource(){ + + String fileName = basePath + "/db-source.json"; + DictionaryDefinition dictionaryDefinition = JacksonUtils.readValueFromFile(fileName, DictionaryDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for db type", dictionaryDefinition); + } + + @Test + public void testDictionaryDefinitionMDSALSource(){ + String fileName = basePath + "/mdsal-source.json"; + DictionaryDefinition dictionaryDefinition = JacksonUtils.readValueFromFile(fileName, DictionaryDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for mdsal type", dictionaryDefinition); + } +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java index 22b01c4a..0c9a1c5d 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java @@ -17,13 +17,11 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.util; -import com.fasterxml.jackson.databind.JsonNode; import org.junit.Assert; import org.junit.Test; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; -import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.*; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils; import org.slf4j.Logger; @@ -45,9 +43,9 @@ public class ResourceDictionaryUtilsTest { DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); - Map source = new HashMap<>(); + Map source = new HashMap<>(); SourceInput sourceInput = new SourceInput(); - source.put(ConfigModelConstant.SOURCE_INPUT, JacksonUtils.jsonNodeFromObject(sourceInput)); + source.put(ResourceDictionaryConstants.SOURCE_INPUT, sourceInput); dictionaryDefinition.setSource(source); ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); @@ -72,15 +70,16 @@ public class ResourceDictionaryUtilsTest { DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); - Map source = new HashMap<>(); + Map source = new HashMap<>(); SourceDb sourceDb = new SourceDb(); - source.put(ConfigModelConstant.SOURCE_DB, JacksonUtils.jsonNodeFromObject(sourceDb)); + sourceDb.setBase("sdnc_connection"); + source.put(ResourceDictionaryConstants.SOURCE_DB, sourceDb); dictionaryDefinition.setSource(source); Map dependency = new HashMap<>(); DictionaryDependency dependencyDb = new DictionaryDependency(); dependencyDb.setNames(Arrays.asList("vnf-id", "vnf-name")); - dependency.put(ConfigModelConstant.SOURCE_DB, dependencyDb); + dependency.put(ResourceDictionaryConstants.SOURCE_DB, dependencyDb); dictionaryDefinition.setDependency(dependency); DecryptionRule decryptionRule = new DecryptionRule(); @@ -115,15 +114,15 @@ public class ResourceDictionaryUtilsTest { DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); - Map source = new HashMap<>(); + Map source = new HashMap<>(); SourceDefault sourceDefault = new SourceDefault(); - source.put(ConfigModelConstant.SOURCE_DEFAULT, JacksonUtils.jsonNodeFromObject(sourceDefault)); + source.put(ResourceDictionaryConstants.SOURCE_DEFAULT, sourceDefault); dictionaryDefinition.setSource(source); Map dependency = new HashMap<>(); DictionaryDependency dependencyDefault = new DictionaryDependency(); dependencyDefault.setNames(Arrays.asList(new String[]{"vnf-id", "vnf-name"})); - dependency.put(ConfigModelConstant.SOURCE_DEFAULT, dependencyDefault); + dependency.put(ResourceDictionaryConstants.SOURCE_DEFAULT, dependencyDefault); dictionaryDefinition.setDependency(dependency); ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); @@ -143,15 +142,15 @@ public class ResourceDictionaryUtilsTest { DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); - Map source = new HashMap<>(); + Map source = new HashMap<>(); SourceMdsal sourceMdsal = new SourceMdsal(); - source.put(ConfigModelConstant.SOURCE_MDSAL, JacksonUtils.jsonNodeFromObject(sourceMdsal)); + source.put(ResourceDictionaryConstants.SOURCE_MDSAL,sourceMdsal); dictionaryDefinition.setSource(source); Map dependency = new HashMap<>(); DictionaryDependency dependencyMdsal = new DictionaryDependency(); dependencyMdsal.setNames(Arrays.asList(new String[]{"vnf-id", "vnf-name"})); - dependency.put(ConfigModelConstant.SOURCE_MDSAL, dependencyMdsal); + dependency.put(ResourceDictionaryConstants.SOURCE_MDSAL, dependencyMdsal); dictionaryDefinition.setDependency(dependency); ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/action-name.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/action-name.json deleted file mode 100644 index 92b64e62..00000000 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/action-name.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "action-name", - "resource-path": "action-name", - "resource-type": "ONAP", - "description": "To be provided", - "valid-values": null, - "sample-value": null, - "updated-by": "ym9479@onap.com", - "tags": null, - "default": null, - "data-type": "string", - "source": { - "input": { - "key": "action-name" - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/bundle-id.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/bundle-id.json deleted file mode 100644 index f9678f5f..00000000 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/bundle-id.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "bundle-id", - "description": "name of the ", - "resource-type": "ONAP", - "resource-path": "vnf/bundle-id", - "updated-by": "ym9479@onap.com", - "data-type": "String", - "tags": "bundle-id, ym9479@onap.com", - "source": { - "db": { - "path": "$key-value", - "input-key-mapping": { - "key-value": "$resource-group-key" - }, - "output-key-mapping": { - "bundle-id": "bundle-id" - } - }, - "input": { - } - }, - "decryption-rules": [ - { - "sources": [ - "input" - ], - "path": "/.", - "rule": "LOCAL-Decrypt", - "decrypt-type": "AES128" - } - ] -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json new file mode 100644 index 00000000..86252354 --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json @@ -0,0 +1,31 @@ +{ + "name": "bundle-id", + "description": "name of the ", + "resource-type": "ONAP", + "resource-path": "vnf/bundle-id", + "updated-by": "brindasanth@onap.com", + "data-type": "String", + "tags": "bundle-id, brindasanth@onap.com", + "source": { + "db": { + "query": "SELECT bundle-id FROM DEVICE_PROFILE WHERE profile_name = :profile_name", + "input-key-mapping": { + "profile_name": "profile_name" + }, + "output-key-mapping": { + "db-country": "country", + "db-state": "state" + } + } + }, + "decryption-rules": [ + { + "sources": [ + "input" + ], + "path": "/.", + "rule": "LOCAL-Decrypt", + "decrypt-type": "AES128" + } + ] +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json new file mode 100644 index 00000000..35736b66 --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json @@ -0,0 +1,17 @@ +{ + "name": "action-name", + "resource-path": "action-name", + "resource-type": "ONAP", + "description": "To be provided", + "valid-values": null, + "sample-value": null, + "updated-by": "brindasanth@onap.com", + "tags": null, + "default": null, + "data-type": "string", + "source": { + "input": { + "key": "action-name" + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json index 03254b78..c6c0f985 100644 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json @@ -1,8 +1,8 @@ { - "tags": "v4-ip-type, tosca.datatypes.Root, data_type, ym9479@onap.com", + "tags": "v4-ip-type, tosca.datatypes.Root, data_type, brindasanth@onap.com", "name": "v4-ip-type", "description": "To be provided", - "updated-by": "ym9479@onap.com", + "updated-by": "brindasanth@onap.com", "resource-type": "ONAP", "resource-path": "vnf/v4-ip-type", "data-type": "string", diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java new file mode 100644 index 00000000..074f18d0 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java @@ -0,0 +1,39 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.service; + +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.*; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; + +@Component +public class ApplicationRegistrationService { + + @PostConstruct + public void register(){ + registerDictionarySources(); + } + + public void registerDictionarySources(){ + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_DB, SourceDb.class); + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_INPUT, SourceInput.class); + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_MDSAL, SourceMdsal.class); + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_DEFAULT,SourceDefault.class); + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java index f7a802e4..43164126 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java @@ -16,24 +16,25 @@ package org.onap.ccsdk.apps.controllerblueprints.service.common; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import java.io.Serializable; +import java.util.Date; @JsonInclude(Include.NON_NULL) public class ErrorMessage implements Serializable { - private Integer httpStatus; private String message; private Integer code; - private String developerMessage; + private String debugMessage; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + private Date timestamp = new Date(); - public Integer getHttpStatus() { - return httpStatus; - } - - public void setHttpStatus(Integer httpStatus) { - this.httpStatus = httpStatus; + public ErrorMessage(String message, Integer code, String debugMessage){ + this.message = message; + this.code = code; + this.debugMessage = debugMessage; } public String getMessage() { @@ -52,12 +53,19 @@ public class ErrorMessage implements Serializable { this.code = code; } - public String getDeveloperMessage() { - return developerMessage; + public String getDebugMessage() { + return debugMessage; } - public void setDeveloperMessage(String developerMessage) { - this.developerMessage = developerMessage; + public void setDebugMessage(String developerMessage) { + this.debugMessage = developerMessage; } + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java index 224960fa..45382815 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonManagedReference; +import io.swagger.annotations.ApiModelProperty; import org.hibernate.annotations.Proxy; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -82,6 +83,7 @@ public class ConfigModel implements Serializable { @NotNull @Column(name = "artifact_version") + @ApiModelProperty(required=true) private String artifactVersion; @Lob @@ -91,7 +93,7 @@ public class ConfigModel implements Serializable { @Column(name = "internal_version") private Integer internalVersion; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") @LastModifiedDate @Temporal(TemporalType.TIMESTAMP) @Column(name = "creation_date") @@ -99,19 +101,23 @@ public class ConfigModel implements Serializable { @NotNull @Column(name = "artifact_name") + @ApiModelProperty(required=true) private String artifactName; @NotNull @Column(name = "published") + @ApiModelProperty(required=true) private String published; @NotNull @Column(name = "updated_by") + @ApiModelProperty(required=true) private String updatedBy; @NotNull @Lob @Column(name = "tags") + @ApiModelProperty(required=true) private String tags; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java index f7bd554d..0c05ef95 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -46,10 +47,12 @@ public class ConfigModelContent { @NotNull @Column(name = "name") + @ApiModelProperty(required=true) private String name; @NotNull @Column(name = "content_type") + @ApiModelProperty(required=true) private String contentType; @@ -65,10 +68,11 @@ public class ConfigModelContent { @NotNull @Lob @Column(name = "content") + @ApiModelProperty(required=true) private String content; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") @LastModifiedDate @Temporal(TemporalType.TIMESTAMP) @Column(name = "updated_date") diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java index ed6340a6..61e4d118 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java @@ -16,6 +16,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -40,36 +42,43 @@ public class ModelType implements Serializable { @Id @NotNull @Column(name = "model_name", nullable = false) + @ApiModelProperty(required=true) private String modelName; @NotNull @Column(name = "derived_from") + @ApiModelProperty(required=true) private String derivedFrom; @NotNull @Column(name = "definition_type") + @ApiModelProperty(required=true) private String definitionType; @NotNull @Lob @Column(name = "definition") + @ApiModelProperty(required=true) private String definition; @NotNull @Lob @Column(name = "description") + @ApiModelProperty(required=true) private String description; @NotNull @Column(name = "version") + @ApiModelProperty(required=true) private String version; @NotNull @Lob @Column(name = "tags") + @ApiModelProperty(required=true) private String tags; - // @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") @LastModifiedDate @Temporal(TemporalType.TIMESTAMP) @Column(name = "creation_date") @@ -77,6 +86,7 @@ public class ModelType implements Serializable { @NotNull @Column(name = "updated_by") + @ApiModelProperty(required=true) private String updatedBy; @Override diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java index adb01884..0d5879db 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java @@ -16,6 +16,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -39,18 +41,22 @@ public class ResourceDictionary implements Serializable { @Id @NotNull @Column(name = "name") + @ApiModelProperty(required=true) private String name; @NotNull @Column(name = "resource_path") + @ApiModelProperty(required=true) private String resourcePath; @NotNull @Column(name = "resource_type") + @ApiModelProperty(required=true) private String resourceType; @NotNull @Column(name = "data_type") + @ApiModelProperty(required=true) private String dataType; @Column(name = "entry_schema") @@ -67,18 +73,22 @@ public class ResourceDictionary implements Serializable { @NotNull @Lob @Column(name = "definition") + @ApiModelProperty(required=true) private String definition; @NotNull @Lob @Column(name = "description") + @ApiModelProperty(required=true) private String description; @NotNull @Lob @Column(name = "tags") + @ApiModelProperty(required=true) private String tags; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") @LastModifiedDate @Temporal(TemporalType.TIMESTAMP) @Column(name = "creation_date") @@ -86,6 +96,7 @@ public class ResourceDictionary implements Serializable { @NotNull @Column(name = "updated_by") + @ApiModelProperty(required=true) private String updatedBy; @Override diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java index 94324a80..62b68303 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java @@ -19,8 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.service.ConfigModelService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -29,7 +28,7 @@ import java.util.List; * {@inheritDoc} */ @RestController -@RequestMapping("/api/v1/config-model") +@RequestMapping(value = "/api/v1/config-model") public class ConfigModelRest { private ConfigModelService configModelService; @@ -44,7 +43,7 @@ public class ConfigModelRest { } - @GetMapping(path = "/initial/{name}") + @GetMapping(path = "/initial/{name}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel getInitialConfigModel(@PathVariable(value = "name") String name) throws BluePrintException { try { @@ -54,7 +53,7 @@ public class ConfigModelRest { } } - @PostMapping(path = "/") + @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel saveConfigModel(@RequestBody ConfigModel configModel) throws BluePrintException { try { @@ -69,11 +68,11 @@ public class ConfigModelRest { try { this.configModelService.deleteConfigModel(id); } catch (Exception e) { - throw new BluePrintException(4000, e.getMessage(), e); + throw new BluePrintException(2400, e.getMessage(), e); } } - @GetMapping(path = "/publish/{id}") + @GetMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel publishConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { try { @@ -83,7 +82,7 @@ public class ConfigModelRest { } } - @GetMapping(path = "/{id}") + @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel getConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { try { @@ -93,7 +92,7 @@ public class ConfigModelRest { } } - @GetMapping(path = "/by-name/{name}/version/{version}") + @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel getConfigModelByNameAndVersion(@PathVariable(value = "name") String name, @PathVariable(value = "version") String version) throws BluePrintException { @@ -104,7 +103,7 @@ public class ConfigModelRest { } } - @GetMapping(path = "/search/{tags}") + @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List searchConfigModels(@PathVariable(value = "tags") String tags) throws BluePrintException { try { @@ -114,7 +113,7 @@ public class ConfigModelRest { } } - @GetMapping(path = "/clone/{id}") + @GetMapping(path = "/clone/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel getCloneConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { try { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java index 2fa64316..f6e5c274 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java @@ -19,6 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.service.ModelTypeService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; +import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.*; @@ -29,7 +30,7 @@ import java.util.List; * {@inheritDoc} */ @RestController -@RequestMapping("/api/v1/model-type") +@RequestMapping(value = "/api/v1/model-type") public class ModelTypeRest { private ModelTypeService modelTypeService; @@ -43,7 +44,7 @@ public class ModelTypeRest { this.modelTypeService = modelTypeService; } - @GetMapping(path = "/{name}") + @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE) public ModelType getModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException { try { return modelTypeService.getModelTypeByName(name); @@ -52,7 +53,7 @@ public class ModelTypeRest { } } - @GetMapping(path = "/search/{tags}") + @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) public List searchModelTypes(@PathVariable(value = "tags") String tags) throws BluePrintException { try { return modelTypeService.searchModelTypes(tags); @@ -61,7 +62,7 @@ public class ModelTypeRest { } } - @GetMapping(path = "/by-definition/{definitionType}") + @GetMapping(path = "/by-definition/{definitionType}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List getModelTypeByDefinitionType(@PathVariable(value = "definitionType") String definitionType) throws BluePrintException { try { @@ -71,7 +72,7 @@ public class ModelTypeRest { } } - @PostMapping(path = "/") + @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ModelType saveModelType(@RequestBody ModelType modelType) throws BluePrintException { try { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java index dfb06bba..795738cb 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java @@ -19,8 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDictionaryService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -44,7 +43,7 @@ public class ResourceDictionaryRest { this.resourceDictionaryService = dataDictionaryService; } - @PostMapping(path = "/") + @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary) throws BluePrintException { @@ -64,7 +63,7 @@ public class ResourceDictionaryRest { } } - @GetMapping(path = "/{name}") + @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ResourceDictionary getResourceDictionaryByName(@PathVariable(value = "name") String name) throws BluePrintException { try { @@ -74,7 +73,7 @@ public class ResourceDictionaryRest { } } - @PostMapping(path = "/by-names") + @PostMapping(path = "/by-names", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List searchResourceDictionaryByNames(@RequestBody List names) throws BluePrintException { @@ -85,7 +84,7 @@ public class ResourceDictionaryRest { } } - @GetMapping(path = "/search/{tags}") + @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List searchResourceDictionaryByTags(@PathVariable(value = "tags") String tags) throws BluePrintException { try { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java index d8ea1941..a22285b8 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java @@ -23,8 +23,7 @@ import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.apps.controllerblueprints.service.ServiceTemplateService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -47,7 +46,7 @@ public class ServiceTemplateRest { this.serviceTemplateService = serviceTemplateService; } - @PostMapping(path = "/enrich") + @PostMapping(path = "/enrich", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ServiceTemplate enrichServiceTemplate(@RequestBody ServiceTemplate serviceTemplate) throws BluePrintException { try { @@ -57,7 +56,7 @@ public class ServiceTemplateRest { } } - @PostMapping(path = "/validate") + @PostMapping(path = "/validate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ServiceTemplate validateServiceTemplate(@RequestBody ServiceTemplate serviceTemplate) throws BluePrintException { try { @@ -67,7 +66,7 @@ public class ServiceTemplateRest { } } - @PostMapping(path = "/resource-assignment/auto-map") + @PostMapping(path = "/resource-assignment/auto-map", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody AutoMapResponse autoMap(@RequestBody List resourceAssignments) throws BluePrintException { try { @@ -77,7 +76,7 @@ public class ServiceTemplateRest { } } - @PostMapping(path = "/resource-assignment/validate") + @PostMapping(path = "/resource-assignment/validate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List validateResourceAssignments(@RequestBody List resourceAssignments) throws BluePrintException { @@ -88,7 +87,7 @@ public class ServiceTemplateRest { } } - @PostMapping(path = "/resource-assignment/generate") + @PostMapping(path = "/resource-assignment/generate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List generateResourceAssignments(@RequestBody ConfigModelContent templateContent) throws BluePrintException { diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java index afe9b426..73d6eca9 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java @@ -24,6 +24,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.onap.ccsdk.apps.controllerblueprints.TestApplication; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.*; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,7 +52,10 @@ public class ResourceDictionaryRestTest { @Before public void setUp() { - + SourceDeserializer.registerSource("db", SourceDb.class); + SourceDeserializer.registerSource("input", SourceInput.class); + SourceDeserializer.registerSource("mdsal", SourceMdsal.class); + SourceDeserializer.registerSource("default", SourceDefault.class); } @Test -- cgit 1.2.3-korg