Controller Blueprints Microservice
authorBrinda Santh <brindasanth@in.ibm.com>
Mon, 27 Aug 2018 02:10:50 +0000 (22:10 -0400)
committerBrinda Santh <brindasanth@in.ibm.com>
Mon, 27 Aug 2018 02:10:50 +0000 (22:10 -0400)
Add resource dictionary validation implementation services, validation repository services and Junit Test cases.

Change-Id: Ia746b86b7d9098eabe5e643dcba558ef9aa7160f
Issue-ID: CCSDK-487
Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
15 files changed:
ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/ConfigModelConstant.kt
ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt
ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt [moved from ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerRepoService.kt with 93% similarity]
ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt
ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt
ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt [moved from ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerRepoFileServiceTest.kt with 78% similarity]
ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java
ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt [new file with mode: 0644]
ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java [new file with mode: 0644]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java [moved from ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerRepoDBService.java with 92% similarity]
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/ResourceDictionaryValidationService.java [new file with mode: 0644]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.java

index 1bdd530..85f1579 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\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
@@ -73,12 +74,21 @@ object BluePrintConstants {
     const val MODEL_TYPE_RELATIONSHIPS_ATTACH_TO = "tosca.relationships.AttachesTo"\r
     const val MODEL_TYPE_RELATIONSHIPS_ROUTES_TO = "tosca.relationships.RoutesTo"\r
 \r
+    const val MODEL_TYPE_NODE_DG = "tosca.nodes.DG"\r
+    const val MODEL_TYPE_NODE_COMPONENT = "tosca.nodes.Component"\r
+    const val MODEL_TYPE_NODE_VNF = "tosca.nodes.Vnf"\r
+    @Deprecated("Artifacts will be attached to Node Template")\r
+    const val MODEL_TYPE_NODE_ARTIFACT = "tosca.nodes.Artifact"\r
+    const val MODEL_TYPE_NODE_RESOURCE_SOURCE = "tosca.nodes.ResourceSource"\r
+\r
     const val MODEL_TYPE_NODES_COMPONENT_JAVA: String = "tosca.nodes.component.Java"\r
     const val MODEL_TYPE_NODES_COMPONENT_BUNDLE: String = "tosca.nodes.component.Bundle"\r
     const val MODEL_TYPE_NODES_COMPONENT_SCRIPT: String = "tosca.nodes.component.Script"\r
     const val MODEL_TYPE_NODES_COMPONENT_PYTHON: String = "tosca.nodes.component.Python"\r
     const val MODEL_TYPE_NODES_COMPONENT_JAVA_SCRIPT: String = "tosca.nodes.component.JavaScript"\r
 \r
+    const val MODEL_TYPE_DATA_TYPE_DYNAMIC = "tosca.datatypes.Dynamic"\r
+\r
     const val EXPRESSION_GET_INPUT: String = "get_input"\r
     const val EXPRESSION_GET_ATTRIBUTE: String = "get_attribute"\r
     const val EXPRESSION_GET_ARTIFACT: String = "get_artifact"\r
index 9782691..8459220 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\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
@@ -26,12 +27,8 @@ object ConfigModelConstant {
     const val MODEL_CONTENT_TYPE_TOSCA_JSON = "TOSCA_JSON"\r
     const val MODEL_CONTENT_TYPE_TEMPLATE = "TEMPLATE"\r
 \r
-    const val MODEL_TYPE_DATA_TYPE = "tosca.datatypes.Root"\r
     const val MODEL_TYPE_DATA_TYPE_DYNAMIC = "tosca.datatypes.Dynamic"\r
 \r
-    const val MODEL_TYPE_NODE_DG = "tosca.nodes.DG"\r
-    const val MODEL_TYPE_NODE_COMPONENT = "tosca.nodes.Component"\r
-    const val MODEL_TYPE_NODE_VNF = "tosca.nodes.Vnf"\r
     const val MODEL_TYPE_NODE_ARTIFACT = "tosca.nodes.Artifact"\r
 \r
     const val MODEL_TYPE_CAPABILITY_NETCONF = "tosca.capability.Netconf"\r
index 8f17287..64fc57f 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\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
@@ -44,7 +45,7 @@ interface BluePrintEnhancerService : Serializable {
     fun enhance(fileName: String, basePath: String): ServiceTemplate\r
 }\r
 \r
-open class BluePrintEnhancerDefaultService(val bluePrintEnhancerRepoService: BluePrintEnhancerRepoService) : BluePrintEnhancerService {\r
+open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRepoService) : BluePrintEnhancerService {\r
 \r
     private val log: Logger = LoggerFactory.getLogger(BluePrintEnhancerDefaultService::class.java)\r
 \r
@@ -216,21 +217,21 @@ open class BluePrintEnhancerDefaultService(val bluePrintEnhancerRepoService: Blu
     }\r
 \r
     open fun populateNodeType(nodeTypeName: String): NodeType {\r
-        val nodeType = bluePrintEnhancerRepoService.getNodeType(nodeTypeName)\r
+        val nodeType = bluePrintRepoService.getNodeType(nodeTypeName)\r
                 ?: throw BluePrintException(format("Couldn't get NodeType({}) from repo.", nodeTypeName))\r
         serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType)\r
         return nodeType\r
     }\r
 \r
     open fun populateArtifactType(artifactTypeName: String): ArtifactType {\r
-        val artifactType = bluePrintEnhancerRepoService.getArtifactType(artifactTypeName)\r
+        val artifactType = bluePrintRepoService.getArtifactType(artifactTypeName)\r
                 ?: throw BluePrintException(format("Couldn't get ArtifactType({}) from repo.", artifactTypeName))\r
         serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType)\r
         return artifactType\r
     }\r
 \r
     open fun populateDataTypes(dataTypeName: String): DataType {\r
-        val dataType = bluePrintEnhancerRepoService.getDataType(dataTypeName)\r
+        val dataType = bluePrintRepoService.getDataType(dataTypeName)\r
                 ?: throw BluePrintException(format("Couldn't get DataType({}) from repo.", dataTypeName))\r
         serviceTemplate.dataTypes?.put(dataTypeName, dataType)\r
         return dataType\r
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\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
@@ -26,12 +27,12 @@ import java.io.Serializable
 import java.nio.charset.Charset\r
 \r
 /**\r
- * BluePrintEnhancerRepoFileService\r
+ * BluePrintRepoFileService\r
  * @author Brinda Santh\r
  *\r
  */\r
 \r
-interface BluePrintEnhancerRepoService : Serializable {\r
+interface BluePrintRepoService : Serializable {\r
 \r
     @Throws(BluePrintException::class)\r
     fun getNodeType(nodeTypeName: String): NodeType?\r
@@ -51,7 +52,7 @@ interface BluePrintEnhancerRepoService : Serializable {
 }\r
 \r
 \r
-class BluePrintEnhancerRepoFileService(val basePath: String) : BluePrintEnhancerRepoService {\r
+class BluePrintRepoFileService(val basePath: String) : BluePrintRepoService {\r
 \r
     val dataTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)\r
     val nodeTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE)\r
index 0815231..b03fdf9 100644 (file)
@@ -65,8 +65,8 @@ class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var contex
                 resolvedValue = propertyAssignmentExpression.resolveAssignmentExpression(nodeTemplateName, nodeTypePropertyName, propertyAssignment)\r
             } else {\r
                 // Assign default value to the Operation\r
-                nodeTypeProperty.defaultValue?.let {\r
-                    resolvedValue = JacksonUtils.jsonNodeFromObject(nodeTypeProperty.defaultValue!!)\r
+                nodeTypeProperty.defaultValue?.let { defaultValue ->\r
+                    resolvedValue = defaultValue\r
                 }\r
             }\r
             // Set for Return of method\r
index 6fc1853..8e6d5ef 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\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
@@ -30,7 +31,7 @@ class BluePrintEnhancerServiceTest {
 \r
     @Test\r
     fun testEnrichBlueprint() {\r
-        val bluePrintEnhancerRepoFileService = BluePrintEnhancerRepoFileService(basePath)\r
+        val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath)\r
         val bluePrintEnhancerService: BluePrintEnhancerService = BluePrintEnhancerDefaultService(bluePrintEnhancerRepoFileService)\r
 \r
         val serviceTemplate = ServiceTemplateUtils.getServiceTemplate("load/blueprints/simple-baseconfig/Definitions/simple-baseconfig.json")\r
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\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
@@ -20,31 +21,31 @@ import org.junit.Test
 import kotlin.test.assertNotNull\r
 \r
 /**\r
- * BluePrintEnhancerRepoFileServiceTest\r
+ * BluePrintRepoFileServiceTest\r
  * @author Brinda Santh\r
  *\r
  */\r
-class BluePrintEnhancerRepoFileServiceTest {\r
+class BluePrintRepoFileServiceTest {\r
 \r
     val basePath = "load/model_type"\r
 \r
     @Test\r
     fun testGetDataType() {\r
-        val bluePrintEnhancerRepoFileService = BluePrintEnhancerRepoFileService(basePath)\r
+        val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath)\r
         val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-v4-aggregate")\r
         assertNotNull(dataType, "Failed to get DataType from repo")\r
     }\r
 \r
     @Test\r
     fun testGetNodeType() {\r
-        val bluePrintEnhancerRepoFileService = BluePrintEnhancerRepoFileService(basePath)\r
+        val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath)\r
         val nodeType = bluePrintEnhancerRepoFileService.getNodeType("component-resource-assignment")\r
         assertNotNull(nodeType, "Failed to get NodeType from repo")\r
     }\r
 \r
     @Test\r
     fun testGetArtifactType() {\r
-        val bluePrintEnhancerRepoFileService = BluePrintEnhancerRepoFileService(basePath)\r
+        val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath)\r
         val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity")\r
         assertNotNull(nodeType, "Failed to get ArtifactType from repo")\r
     }\r
index 96ab1ee..ddbd88b 100644 (file)
@@ -23,6 +23,7 @@ public class ResourceDictionaryConstants {
     public static final String SOURCE_DB = "db";\r
     public static final String SOURCE_MDSAL = "mdsal";\r
 \r
+    public static final String PROPERTY_TYPE = "type";\r
     public static final String PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping";\r
     public static final String PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping";\r
     public static final String PROPERTY_KEY_DEPENDENCY = "key-dependency";\r
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt
new file mode 100644 (file)
index 0000000..cef1f15
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ *  Copyright © 2018 IBM.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      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.service
+
+import com.fasterxml.jackson.databind.JsonNode
+import com.google.common.base.Preconditions
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
+import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType
+import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
+import org.onap.ccsdk.apps.controllerblueprints.core.format
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintExpressionService
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
+import org.slf4j.LoggerFactory
+import java.io.Serializable
+
+interface ResourceDictionaryValidationService : Serializable {
+
+    @Throws(BluePrintException::class)
+    fun validate(resourceDefinition: ResourceDefinition)
+
+}
+
+open class ResourceDictionaryDefaultValidationService(val bluePrintRepoService: BluePrintRepoService) : ResourceDictionaryValidationService {
+
+    private val log = LoggerFactory.getLogger(ResourceDictionaryDefaultValidationService::class.java)
+
+    override fun validate(resourceDefinition: ResourceDefinition) {
+        Preconditions.checkNotNull(resourceDefinition, "Failed to get Resource Definition")
+
+        resourceDefinition.sources.forEach { (name, nodeTemplate) ->
+            val sourceType = nodeTemplate.type
+
+            val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)
+                    ?: throw BluePrintException(format("Failed to get node type definition for source({})", sourceType))
+
+            // Validate Property Name, expression, values and Data Type
+            validateNodeTemplateProperties(nodeTemplate, sourceNodeType)
+        }
+    }
+
+
+    open fun validateNodeTemplateProperties(nodeTemplate: NodeTemplate, nodeType: NodeType) {
+        nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) }
+    }
+
+
+    open fun validatePropertyAssignments(nodeTypeProperties: MutableMap<String, PropertyDefinition>,
+                                    properties: MutableMap<String, JsonNode>) {
+        properties.forEach { propertyName, propertyAssignment ->
+            val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName]
+                    ?: throw BluePrintException(format("failed to get definition for the property ({})", propertyName))
+            // Check and Validate if Expression Node
+            val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment)
+            if (!expressionData.isExpression) {
+                checkPropertyValue(propertyDefinition, propertyName, propertyAssignment)
+            }
+        }
+    }
+
+    open fun checkPropertyValue(propertyDefinition: PropertyDefinition, propertyName: String, jsonNode: JsonNode) {
+        //log.info("validating Property {}, name ({}) value ({})", propertyDefinition, propertyName, jsonNode)
+        //TODO
+    }
+}
\ No newline at end of file
diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java
new file mode 100644 (file)
index 0000000..6eebdb2
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ *  Copyright © 2018 IBM.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      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.service;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoFileService;
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;
+
+public class ResourceDictionaryValidationServiceTest {
+    private String basePath = "load/model_type";
+    String dictionaryPath = "load/resource_dictionary";
+
+    @Test
+    public void testValidate() throws Exception {
+        BluePrintRepoFileService bluePrintRepoFileService = new BluePrintRepoFileService(basePath);
+
+        String fileName = dictionaryPath + "/db-source.json";
+        ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class);
+        Assert.assertNotNull("Failed to populate dictionaryDefinition for db type", resourceDefinition);
+
+        ResourceDictionaryValidationService resourceDictionaryValidationService =
+                new ResourceDictionaryDefaultValidationService(bluePrintRepoFileService);
+        resourceDictionaryValidationService.validate(resourceDefinition);
+
+    }
+}
index afd12f2..0cf846c 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\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
@@ -24,7 +25,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
 import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.data.*;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerDefaultService;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerRepoService;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;\r
 import org.slf4j.Logger;\r
@@ -48,7 +49,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService {
 \r
     private HashMap<String, DataType> recipeDataTypes = new HashMap<>();\r
 \r
-    public BluePrintEnhancerService(BluePrintEnhancerRepoService bluePrintEnhancerRepoDBService) {\r
+    public BluePrintEnhancerService(BluePrintRepoService bluePrintEnhancerRepoDBService) {\r
         super(bluePrintEnhancerRepoDBService);\r
     }\r
 \r
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\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
@@ -20,7 +21,7 @@ import com.google.common.base.Preconditions;
 import org.apache.commons.lang3.StringUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.data.*;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerRepoService;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository;\r
@@ -29,16 +30,16 @@ import org.springframework.stereotype.Service;
 import java.util.Optional;\r
 \r
 /**\r
- * BluePrintEnhancerRepoDBService\r
+ * BluePrintRepoDBService\r
  *\r
  * @author Brinda Santh\r
  */\r
 @Service\r
-public class BluePrintEnhancerRepoDBService implements BluePrintEnhancerRepoService {\r
+public class BluePrintRepoDBService implements BluePrintRepoService {\r
 \r
     private ModelTypeRepository modelTypeRepository;\r
 \r
-    public BluePrintEnhancerRepoDBService(ModelTypeRepository modelTypeRepository) {\r
+    public BluePrintRepoDBService(ModelTypeRepository modelTypeRepository) {\r
         this.modelTypeRepository = modelTypeRepository;\r
     }\r
 \r
index 4bb87d7..5420dd3 100644 (file)
@@ -43,19 +43,23 @@ public class ResourceDictionaryService {
 \r
     private ResourceDictionaryRepository resourceDictionaryRepository;\r
 \r
+    private ResourceDictionaryValidationService resourceDictionaryValidationService;\r
+\r
     /**\r
      * This is a DataDictionaryService, used to save and get the Resource Mapping stored in database\r
-     * \r
+     *\r
      * @param dataDictionaryRepository\r
-     * \r
+     * @param resourceDictionaryValidationService\r
      */\r
-    public ResourceDictionaryService(ResourceDictionaryRepository dataDictionaryRepository) {\r
+    public ResourceDictionaryService(ResourceDictionaryRepository dataDictionaryRepository,\r
+                                     ResourceDictionaryValidationService resourceDictionaryValidationService) {\r
         this.resourceDictionaryRepository = dataDictionaryRepository;\r
+        this.resourceDictionaryValidationService = resourceDictionaryValidationService;\r
     }\r
 \r
     /**\r
      * This is a getDataDictionaryByName service\r
-     * \r
+     *\r
      * @param name\r
      * @return DataDictionary\r
      * @throws BluePrintException\r
@@ -70,7 +74,7 @@ public class ResourceDictionaryService {
 \r
     /**\r
      * This is a searchResourceDictionaryByNames service\r
-     * \r
+     *\r
      * @param names\r
      * @return List<ResourceDictionary>\r
      * @throws BluePrintException\r
@@ -86,7 +90,7 @@ public class ResourceDictionaryService {
 \r
     /**\r
      * This is a searchResourceDictionaryByTags service\r
-     * \r
+     *\r
      * @param tags\r
      * @return List<ResourceDictionary>\r
      * @throws BluePrintException\r
@@ -101,7 +105,7 @@ public class ResourceDictionaryService {
 \r
     /**\r
      * This is a saveDataDictionary service\r
-     * \r
+     *\r
      * @param resourceDictionary\r
      * @return DataDictionary\r
      * @throws BluePrintException\r
@@ -113,6 +117,8 @@ public class ResourceDictionaryService {
 \r
             ResourceDefinition resourceDefinition =\r
                     JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class);\r
+            // Check the Source already Present\r
+            resourceDictionaryValidationService.validate(resourceDefinition);\r
 \r
             if (resourceDefinition == null) {\r
                 throw new BluePrintException(\r
@@ -126,11 +132,11 @@ public class ResourceDictionaryService {
             PropertyDefinition propertyDefinition = new PropertyDefinition();\r
             propertyDefinition.setType(resourceDictionary.getDataType());\r
             propertyDefinition.setDescription(resourceDictionary.getDescription());\r
-            if(StringUtils.isNotBlank(resourceDictionary.getEntrySchema())){\r
+            if (StringUtils.isNotBlank(resourceDictionary.getEntrySchema())) {\r
                 EntrySchema entrySchema = new EntrySchema();\r
                 entrySchema.setType(resourceDictionary.getEntrySchema());\r
                 propertyDefinition.setEntrySchema(entrySchema);\r
-            }else{\r
+            } else {\r
                 propertyDefinition.setEntrySchema(null);\r
             }\r
             resourceDefinition.setTags(resourceDictionary.getTags());\r
@@ -165,7 +171,7 @@ public class ResourceDictionaryService {
 \r
     /**\r
      * This is a deleteResourceDictionary service\r
-     * \r
+     *\r
      * @param name\r
      * @throws BluePrintException\r
      */\r
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java
new file mode 100644 (file)
index 0000000..7de7fc4
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ *  Copyright © 2018 IBM.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      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.core.service.BluePrintRepoService;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDictionaryDefaultValidationService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class ResourceDictionaryValidationService extends ResourceDictionaryDefaultValidationService {
+
+    private BluePrintRepoService bluePrintRepoService;
+
+    public ResourceDictionaryValidationService(BluePrintRepoService bluePrintRepoService) {
+        super(bluePrintRepoService);
+    }
+}
index 85f256e..1201f6b 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\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
@@ -19,7 +20,6 @@ package org.onap.ccsdk.apps.controllerblueprints.service.validator;
 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
-import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.data.CapabilityDefinition;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType;\r
@@ -53,54 +53,6 @@ public class ModelTypeValidator {
         return validTypes;\r
     }\r
 \r
-    @Deprecated\r
-    private static List<String> getValidModelDerivedFrom(String definitionType) {\r
-        List<String> validTypes = new ArrayList<>();\r
-        if (StringUtils.isNotBlank(definitionType)) {\r
-            if (BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE.equalsIgnoreCase(definitionType)) {\r
-                validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_DG);\r
-                validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_COMPONENT);\r
-                validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_VNF);\r
-                validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_ARTIFACT);\r
-            } else if (BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE.equalsIgnoreCase(definitionType)) {\r
-                validTypes.add(ConfigModelConstant.MODEL_TYPE_CAPABILITY_NETCONF);\r
-                validTypes.add(ConfigModelConstant.MODEL_TYPE_CAPABILITY_SSH);\r
-                validTypes.add(ConfigModelConstant.MODEL_TYPE_CAPABILITY_SFTP);\r
-                validTypes.add(ConfigModelConstant.MODEL_TYPE_CAPABILITY_CHEF);\r
-                validTypes.add(ConfigModelConstant.MODEL_TYPE_CAPABILITY_ANSIBLEF);\r
-            } else if (BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE.equalsIgnoreCase(definitionType)) {\r
-                validTypes.add(BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_DEPENDS_ON);\r
-                validTypes.add(BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_HOSTED_ON);\r
-                validTypes.add(BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO);\r
-                validTypes.add(BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ATTACH_TO);\r
-                validTypes.add(BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROUTES_TO);\r
-            }\r
-\r
-        }\r
-        return validTypes;\r
-    }\r
-\r
-    /**\r
-     * This is a validateNodeType\r
-     * \r
-     * @param definitionType\r
-     * @param derivedFrom\r
-     * @return boolean\r
-     * @throws BluePrintException\r
-     */\r
-    public static boolean validateNodeType(String definitionType, String derivedFrom) throws BluePrintException {\r
-        boolean valid = true;\r
-        if (!BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE.equalsIgnoreCase(definitionType)\r
-                && !BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE.equalsIgnoreCase(definitionType)) {\r
-            List<String> validTypes = getValidModelDerivedFrom(definitionType);\r
-            if (!validTypes.contains(derivedFrom)) {\r
-                throw new BluePrintException(\r
-                        "Not Valid Model Type (" + derivedFrom + "), It sould be " + validTypes);\r
-            }\r
-        }\r
-        return valid;\r
-    }\r
-\r
     /**\r
      * This is a validateModelTypeDefinition\r
      * \r
@@ -187,8 +139,6 @@ public class ModelTypeValidator {
 \r
             validateModelTypeDefinition(modelType.getDefinitionType(), modelType.getDefinition());\r
 \r
-            validateNodeType(modelType.getDefinitionType(), modelType.getDerivedFrom());\r
-\r
         } else {\r
             throw new BluePrintException("Model Type Information is missing.");\r
         }\r