Controller Blueprints Microservice 25/64825/1
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Wed, 5 Sep 2018 17:42:22 +0000 (17:42 +0000)
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Wed, 5 Sep 2018 17:42:22 +0000 (17:42 +0000)
Modify Model Type and Resource Defintions persistance and access from String to JSON type for easy handling.

Change-Id: Icfe7e95abad715b0ccad16c681ed057d289a6229
Issue-ID: CCSDK-431
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
13 files changed:
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java [new file with mode: 0644]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java [new file with mode: 0644]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java
ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestTest.java
ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java

index 5075e72..cf5f9e2 100644 (file)
@@ -49,6 +49,11 @@ object JacksonUtils {
         return jacksonObjectMapper().readValue(content, valueType)\r
     }\r
 \r
+    @JvmStatic\r
+    fun <T> readValue(node: JsonNode, valueType: Class<T>): T? {\r
+        return jacksonObjectMapper().treeToValue(node, valueType)\r
+    }\r
+\r
     @JvmStatic\r
     fun getContent(fileName: String): String {\r
         return File(fileName).readText(Charsets.UTF_8)\r
index 428c524..a763d50 100644 (file)
@@ -22,7 +22,6 @@ import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils;\r
@@ -100,9 +99,9 @@ public class AutoResourceMappingService {
 \r
     private void populateDictionaryMapping(Map<String, ResourceDictionary> dictionaryMap, ResourceAssignment resourceAssignment) {\r
         ResourceDictionary dbDataDictionary = dictionaryMap.get(resourceAssignment.getName());\r
-        if (dbDataDictionary != null && StringUtils.isNotBlank(dbDataDictionary.getDefinition())) {\r
+        if (dbDataDictionary != null && dbDataDictionary.getDefinition() != null) {\r
 \r
-            ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(dbDataDictionary.getDefinition(), ResourceDefinition.class);\r
+            ResourceDefinition dictionaryDefinition = dbDataDictionary.getDefinition();\r
 \r
             if (dictionaryDefinition != null && StringUtils.isNotBlank(dictionaryDefinition.getName())\r
                     && StringUtils.isBlank(resourceAssignment.getDictionaryName())) {\r
@@ -185,7 +184,7 @@ public class AutoResourceMappingService {
         }\r
         if (dictionaries != null) {\r
             for (ResourceDictionary resourcedictionary : dictionaries) {\r
-                ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), ResourceDefinition.class);\r
+                ResourceDefinition dictionaryDefinition = resourcedictionary.getDefinition();\r
                 Preconditions.checkNotNull(dictionaryDefinition, "failed to get Resource Definition from dictionary definition");\r
                 PropertyDefinition property = new PropertyDefinition();\r
                 property.setRequired(true);\r
index c4aebe5..5510e48 100644 (file)
@@ -17,6 +17,7 @@
 \r
 package org.onap.ccsdk.apps.controllerblueprints.service;\r
 \r
+import com.fasterxml.jackson.databind.JsonNode;\r
 import com.google.common.base.Preconditions;\r
 import org.apache.commons.lang3.StringUtils;\r
 import org.jetbrains.annotations.NotNull;\r
@@ -75,16 +76,16 @@ public class BluePrintRepoDBService implements BluePrintRepoService {
         Preconditions.checkArgument(StringUtils.isNotBlank(modelName),\r
                 "Failed to get model from repo, model name is missing");\r
 \r
-        return getModelDefinition(modelName).map(content -> {\r
-                    Preconditions.checkArgument(StringUtils.isNotBlank(content),\r
+        return getModelDefinition(modelName).map(modelDefinition -> {\r
+                    Preconditions.checkNotNull(modelDefinition,\r
                             String.format("Failed to get model content for model name (%s)", modelName));\r
-                    return JacksonUtils.readValue(content, valueClass);\r
+                    return JacksonUtils.readValue(modelDefinition, valueClass);\r
                 }\r
         );\r
     }\r
 \r
-    private Mono<String> getModelDefinition(String modelName) throws BluePrintException {\r
-        String modelDefinition;\r
+    private Mono<JsonNode> getModelDefinition(String modelName) throws BluePrintException {\r
+        JsonNode modelDefinition;\r
         Optional<ModelType> modelTypeDb = modelTypeRepository.findByModelName(modelName);\r
         if (modelTypeDb.isPresent()) {\r
             modelDefinition = modelTypeDb.get().getDefinition();\r
index 4e7c391..8868092 100644 (file)
@@ -168,7 +168,7 @@ public class DataBaseInitService {
                             ResourceDictionary resourceDictionary = new ResourceDictionary();\r
                             resourceDictionary.setResourcePath(dictionaryDefinition.getResourcePath());\r
                             resourceDictionary.setName(dictionaryDefinition.getName());\r
-                            resourceDictionary.setDefinition(definitionContent);\r
+                            resourceDictionary.setDefinition(dictionaryDefinition);\r
 \r
                             resourceDictionary.setResourceType(dictionaryDefinition.getResourceType());\r
                             resourceDictionary.setDescription(dictionaryDefinition.getProperty().getDescription());\r
@@ -252,7 +252,7 @@ public class DataBaseInitService {
             modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE);\r
             modelType.setDerivedFrom(nodeType.getDerivedFrom());\r
             modelType.setDescription(nodeType.getDescription());\r
-            modelType.setDefinition(definitionContent);\r
+            modelType.setDefinition(JacksonUtils.jsonNode(definitionContent));\r
             modelType.setModelName(nodeKey);\r
             modelType.setVersion(nodeType.getVersion());\r
             modelType.setUpdatedBy("System");\r
@@ -276,7 +276,7 @@ public class DataBaseInitService {
             modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);\r
             modelType.setDerivedFrom(dataType.getDerivedFrom());\r
             modelType.setDescription(dataType.getDescription());\r
-            modelType.setDefinition(definitionContent);\r
+            modelType.setDefinition(JacksonUtils.jsonNode(definitionContent));\r
             modelType.setModelName(dataKey);\r
             modelType.setVersion(dataType.getVersion());\r
             modelType.setUpdatedBy("System");\r
@@ -300,7 +300,7 @@ public class DataBaseInitService {
             modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE);\r
             modelType.setDerivedFrom(artifactType.getDerivedFrom());\r
             modelType.setDescription(artifactType.getDescription());\r
-            modelType.setDefinition(definitionContent);\r
+            modelType.setDefinition(JacksonUtils.jsonNode(definitionContent));\r
             modelType.setModelName(dataKey);\r
             modelType.setVersion(artifactType.getVersion());\r
             modelType.setUpdatedBy("System");\r
index ccf4ffc..70e43d6 100644 (file)
@@ -105,11 +105,9 @@ public class ResourceDictionaryService {
      */\r
     public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) {\r
         Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing");\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(resourceDictionary.getDefinition()),\r
-                "Resource Dictionary definition information is missing");\r
+        Preconditions.checkNotNull(resourceDictionary.getDefinition(),"Resource Dictionary definition information is missing");\r
 \r
-        ResourceDefinition resourceDefinition =\r
-                JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class);\r
+        ResourceDefinition resourceDefinition = resourceDictionary.getDefinition();\r
         Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content");\r
         // Validate the Resource Definitions\r
         resourceDictionaryValidationService.validate(resourceDefinition);\r
@@ -126,9 +124,6 @@ public class ResourceDictionaryService {
             resourceDictionary.setEntrySchema(propertyDefinition.getEntrySchema().getType());\r
         }\r
 \r
-        String definitionContent = JacksonUtils.getJson(resourceDefinition, true);\r
-        resourceDictionary.setDefinition(definitionContent);\r
-\r
         ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary);\r
 \r
         Optional<ResourceDictionary> dbResourceDictionaryData =\r
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java
new file mode 100644 (file)
index 0000000..05f822d
--- /dev/null
@@ -0,0 +1,40 @@
+/*\r
+ *  Copyright © 2017-2018 AT&T Intellectual Property.\r
+ *\r
+ *  Licensed under the Apache License, Version 2.0 (the "License");\r
+ *  you may not use this file except in compliance with the License.\r
+ *  You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.apps.controllerblueprints.service.domain;\r
+\r
+import javax.persistence.AttributeConverter;\r
+import javax.persistence.Converter;\r
+\r
+import com.fasterxml.jackson.databind.JsonNode;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
+/**\r
+ * @author Brinda Santh\r
+ */\r
+@Converter\r
+public class JpaJsonNodeConverter implements\r
+        AttributeConverter<JsonNode, String> {\r
+\r
+    @Override\r
+    public String convertToDatabaseColumn(JsonNode node) {\r
+        return JacksonUtils.getJson(node, true);\r
+    }\r
+\r
+    @Override\r
+    public JsonNode convertToEntityAttribute(String dbData) {\r
+        return JacksonUtils.jsonNode(dbData);\r
+    }\r
+}
\ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java
new file mode 100644 (file)
index 0000000..18672f1
--- /dev/null
@@ -0,0 +1,39 @@
+/*\r
+ *  Copyright © 2017-2018 AT&T Intellectual Property.\r
+ *\r
+ *  Licensed under the Apache License, Version 2.0 (the "License");\r
+ *  you may not use this file except in compliance with the License.\r
+ *  You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.apps.controllerblueprints.service.domain;\r
+\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;\r
+\r
+import javax.persistence.AttributeConverter;\r
+import javax.persistence.Converter;\r
+/**\r
+ * @author Brinda Santh\r
+ */\r
+@Converter\r
+public class JpaResourceDefinitionConverter implements\r
+        AttributeConverter<ResourceDefinition, String> {\r
+    @Override\r
+    public String convertToDatabaseColumn(ResourceDefinition resourceDefinition) {\r
+        return JacksonUtils.getJson(resourceDefinition);\r
+    }\r
+\r
+    @Override\r
+    public ResourceDefinition convertToEntityAttribute(String content) {\r
+        return JacksonUtils.readValue(content, ResourceDefinition.class);\r
+    }\r
+}\r
index cb8d229..d8fea60 100644 (file)
@@ -17,6 +17,7 @@
 package org.onap.ccsdk.apps.controllerblueprints.service.domain;\r
 \r
 import com.fasterxml.jackson.annotation.JsonFormat;\r
+import com.fasterxml.jackson.databind.JsonNode;\r
 import io.swagger.annotations.ApiModelProperty;\r
 import org.springframework.data.annotation.LastModifiedDate;\r
 import org.springframework.data.jpa.domain.support.AuditingEntityListener;\r
@@ -52,9 +53,10 @@ public class ModelType implements Serializable {
     private String definitionType;\r
 \r
     @Lob\r
+    @Convert(converter  = JpaJsonNodeConverter.class)\r
     @Column(name = "definition", nullable = false)\r
     @ApiModelProperty(required=true)\r
-    private String definition;\r
+    private JsonNode definition;\r
 \r
     @Lob\r
     @Column(name = "description", nullable = false)\r
@@ -118,11 +120,11 @@ public class ModelType implements Serializable {
         this.definitionType = definitionType;\r
     }\r
 \r
-    public String getDefinition() {\r
+    public JsonNode getDefinition() {\r
         return definition;\r
     }\r
 \r
-    public void setDefinition(String definition) {\r
+    public void setDefinition(JsonNode definition) {\r
         this.definition = definition;\r
     }\r
 \r
index c884622..7af9972 100644 (file)
@@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain;
 \r
 import com.fasterxml.jackson.annotation.JsonFormat;\r
 import io.swagger.annotations.ApiModelProperty;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;\r
 import org.springframework.data.annotation.LastModifiedDate;\r
 import org.springframework.data.jpa.domain.support.AuditingEntityListener;\r
 \r
@@ -66,9 +67,10 @@ public class ResourceDictionary implements Serializable {
     private String sampleValue;\r
 \r
     @Lob\r
+    @Convert(converter  = JpaResourceDefinitionConverter.class)\r
     @Column(name = "definition", nullable = false)\r
     @ApiModelProperty(required=true)\r
-    private String definition;\r
+    private ResourceDefinition definition;\r
 \r
     @Lob\r
     @Column(name = "description", nullable = false)\r
@@ -163,11 +165,11 @@ public class ResourceDictionary implements Serializable {
         this.sampleValue = sampleValue;\r
     }\r
 \r
-    public String getDefinition() {\r
+    public ResourceDefinition getDefinition() {\r
         return definition;\r
     }\r
 \r
-    public void setDefinition(String definition) {\r
+    public void setDefinition(ResourceDefinition definition) {\r
         this.definition = definition;\r
     }\r
 \r
index aaa445a..9641f89 100644 (file)
@@ -17,6 +17,7 @@
 \r
 package org.onap.ccsdk.apps.controllerblueprints.service.validator;\r
 \r
+import com.fasterxml.jackson.databind.JsonNode;\r
 import org.apache.commons.lang3.StringUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
@@ -56,14 +57,14 @@ public class ModelTypeValidator {
     /**\r
      * This is a validateModelTypeDefinition\r
      * \r
-     * @param definitionType\r
-     * @param definitionContent\r
+     * @param definitionType definitionType\r
+     * @param definitionContent definitionContent\r
      * @return boolean\r
-     * @throws BluePrintException\r
+     * @throws BluePrintException BluePrintException\r
      */\r
-    public static boolean validateModelTypeDefinition(String definitionType, String definitionContent)\r
+    public static boolean validateModelTypeDefinition(String definitionType, JsonNode definitionContent)\r
             throws BluePrintException {\r
-        if (StringUtils.isNotBlank(definitionContent)) {\r
+        if (definitionContent != null) {\r
             if (BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE.equalsIgnoreCase(definitionType)) {\r
                 DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class);\r
                 if (dataType == null) {\r
@@ -98,8 +99,9 @@ public class ModelTypeValidator {
     /**\r
      * This is a validateModelType method\r
      * \r
-     * @param modelType\r
+     * @param modelType modelType\r
      * @return boolean\r
+     * @throws BluePrintException BluePrintException\r
      */\r
     public static boolean validateModelType(ModelType modelType) throws BluePrintException {\r
         if (modelType != null) {\r
@@ -115,7 +117,7 @@ public class ModelTypeValidator {
                 throw new BluePrintException("Model Type Information is missing.");\r
             }\r
 \r
-            if (StringUtils.isBlank(modelType.getDefinition())) {\r
+            if (modelType.getDefinition() == null) {\r
                 throw new BluePrintException("Model Definition Information is missing.");\r
             }\r
             if (StringUtils.isBlank(modelType.getDescription())) {\r
@@ -133,7 +135,7 @@ public class ModelTypeValidator {
             List<String> validRootTypes = getValidModelDefinitionType();\r
             if (!validRootTypes.contains(modelType.getDefinitionType())) {\r
                 throw new BluePrintException("Not Valid Model Root Type(" + modelType.getDefinitionType()\r
-                        + "), It sould be " + validRootTypes);\r
+                        + "), It should be " + validRootTypes);\r
             }\r
 \r
             validateModelTypeDefinition(modelType.getDefinitionType(), modelType.getDefinition());\r
index ff0b4ac..1c2a733 100644 (file)
@@ -49,7 +49,7 @@ public class ResourceDictionaryValidator {
                 "DataDictionary Resource Name Information is missing.");\r
         Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getResourceType()),\r
                 "DataDictionary Resource Type Information is missing.");\r
-        Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getDefinition()),\r
+        Preconditions.checkNotNull( resourceDictionary.getDefinition(),\r
                 "DataDictionary Definition Information is missing.");\r
         Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getDescription()),\r
                 "DataDictionary Description Information is missing.");\r
index 8e88f0a..c28abe2 100644 (file)
@@ -22,6 +22,7 @@ import org.junit.runner.RunWith;
 import org.junit.runners.MethodSorters;\r
 import org.onap.ccsdk.apps.controllerblueprints.TestApplication;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;\r
 import com.att.eelf.configuration.EELFLogger;\r
 import com.att.eelf.configuration.EELFManager;\r
@@ -64,7 +65,7 @@ public class ModelTypeRestTest {
         modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);\r
         modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT);\r
         modelType.setDescription("Definition for Sample Datatype ");\r
-        modelType.setDefinition(content);\r
+        modelType.setDefinition(JacksonUtils.jsonNode(content));\r
         modelType.setModelName(modelName);\r
         modelType.setVersion("1.0.0");\r
         modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + ","\r
index 8bb1f0b..8234695 100644 (file)
@@ -24,6 +24,8 @@ import org.junit.Test;
 import org.junit.runner.RunWith;\r
 import org.junit.runners.MethodSorters;\r
 import org.onap.ccsdk.apps.controllerblueprints.TestApplication;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;\r
 import com.att.eelf.configuration.EELFLogger;\r
 import com.att.eelf.configuration.EELFManager;\r
@@ -58,7 +60,7 @@ public class ResourceDictionaryRestTest {
         ResourceDictionary dataDictionary = new ResourceDictionary();\r
         dataDictionary.setResourcePath("test/vnf/ipaddress");\r
         dataDictionary.setName("test-name");\r
-        dataDictionary.setDefinition(definition);\r
+        dataDictionary.setDefinition(JacksonUtils.readValue(definition, ResourceDefinition.class));\r
         dataDictionary.setValidValues("127.0.0.1");\r
         dataDictionary.setResourceType("ONAP");\r
         dataDictionary.setDataType("string");\r