Add blueprint runtime validator 15/79315/7
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Thu, 28 Feb 2019 01:16:47 +0000 (20:16 -0500)
committerMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Mon, 11 Mar 2019 13:13:22 +0000 (09:13 -0400)
Change-Id: I9e2aa1aec392fc4191d547115fa90e8811f0f9e9
Issue-ID: CCSDK-1110
Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
30 files changed:
components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/node_types.json
components/model-catalog/definition-type/starter-type/node_type/source-primary-db.json
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
ms/blueprintsprocessor/modules/inbounds/pom.xml
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorService.kt [moved from ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintDesignTimeRuntimeValidatorService.kt with 50% similarity]
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/Mock.kt
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt [new file with mode: 0644]
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt
ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactDefinitionValidatorImpl.kt
ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorService.kt
ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidationConfiguration.kt [new file with mode: 0644]
ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ArtifactMappingResourceValidator.kt
ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ResourceDefinitionValidation.kt [new file with mode: 0644]
ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt
ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt
ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt [deleted file]
ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java [deleted file]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java [deleted file]
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java [deleted file]
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt

index 3912a47..b2ba348 100644 (file)
       },
       "derived_from": "tosca.nodes.ResourceSource"
     },
+    "source-primary-db": {
+      "description": "This is Database Resource Source Node Type",
+      "version": "1.0.0",
+      "properties": {
+        "type": {
+          "required": true,
+          "type": "string",
+          "constraints": [
+            {
+              "valid_values": [
+                "SQL",
+                "PLSQL"
+              ]
+            }
+          ]
+        },
+        "endpoint-selector": {
+          "required": false,
+          "type": "string"
+        },
+        "query": {
+          "required": true,
+          "type": "string"
+        },
+        "input-key-mapping": {
+          "required": false,
+          "type": "map",
+          "entry_schema": {
+            "type": "string"
+          }
+        },
+        "output-key-mapping": {
+          "required": false,
+          "type": "map",
+          "entry_schema": {
+            "type": "string"
+          }
+        },
+        "key-dependencies": {
+          "required": true,
+          "type": "list",
+          "entry_schema": {
+            "type": "string"
+          }
+        }
+      },
+      "derived_from": "tosca.nodes.ResourceSource"
+    },
     "source-rest": {
       "description": "This is Rest Resource Source Node Type",
       "version": "1.0.0",
           ],
           "default": "JSON"
         },
+        "endpoint-selector": {
+          "required": false,
+          "type": "string"
+        },
         "url-path": {
           "required": true,
           "type": "string"
index 661a950..702748f 100644 (file)
         }
       ]
     },
+    "endpoint-selector": {
+      "required": false,
+      "type": "string"
+    },
     "query": {
       "required": true,
       "type": "string"
index 8dd738d..b57b88b 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,8 +17,8 @@
 
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution
 
-class ResourceResolutionConstants {
-    companion object {
+object ResourceResolutionConstants {
+
         const val SERVICE_RESOURCE_RESOLUTION = "resource-resolution-service"
         const val PREFIX_RESOURCE_RESOLUTION_PROCESSOR = "rr-processor-"
         const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names"
@@ -25,6 +26,6 @@ class ResourceResolutionConstants {
         const val FILE_NAME_RESOURCE_DEFINITION_TYPES = "resources_definition_types.json"
         const val RESOURCE_RESOLUTION_INPUT_KEY = "resolution-key";
         const val RESOURCE_RESOLUTION_INPUT_STORE_RESULT = "store-result";
-    }
+
 
 }
\ No newline at end of file
index c6b7d77..c2dbd73 100644 (file)
@@ -19,6 +19,7 @@
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor
 
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.CapabilityResourceSource
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
@@ -32,7 +33,7 @@ import org.springframework.context.annotation.Scope
 import org.springframework.stereotype.Service
 import java.io.File
 
-@Service("rr-processor-source-capability")
+@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-capability")
 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 open class CapabilityResourceResolutionProcessor(private var applicationContext: ApplicationContext,
                                                  private val bluePrintScriptsService: BluePrintScriptsService,
@@ -40,7 +41,7 @@ open class CapabilityResourceResolutionProcessor(private var applicationContext:
         ResourceAssignmentProcessor() {
 
     override fun getName(): String {
-        return "resource-assignment-processor-capability"
+        return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-capability"
     }
 
     override fun process(resourceAssignment: ResourceAssignment) {
index 8f0f626..39be14c 100644 (file)
@@ -20,6 +20,7 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.pr
 import com.fasterxml.jackson.databind.node.JsonNodeFactory
 import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.DBLibGenericService
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.DatabaseResourceSource
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
 import org.onap.ccsdk.apps.controllerblueprints.core.*
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
@@ -37,7 +38,7 @@ import java.util.*
  *
  * @author Kapil Singal
  */
-@Service("rr-processor-source-primary-db")
+@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-primary-db")
 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService: DBLibGenericService)
     : ResourceAssignmentProcessor() {
@@ -45,7 +46,7 @@ open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService:
     private val logger = LoggerFactory.getLogger(DatabaseResourceAssignmentProcessor::class.java)
 
     override fun getName(): String {
-        return "rr-processor-source-primary-db"
+        return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-primary-db"
     }
 
     override fun process(resourceAssignment: ResourceAssignment) {
index a8e0ad8..528705f 100644 (file)
@@ -17,6 +17,8 @@
 
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor
 
+import com.fasterxml.jackson.databind.JsonNode
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
@@ -30,20 +32,20 @@ import org.springframework.stereotype.Service
  *
  * @author Kapil Singal
  */
-@Service("rr-processor-source-default")
+@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-default")
 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 open class DefaultResourceResolutionProcessor : ResourceAssignmentProcessor() {
 
     private val logger = LoggerFactory.getLogger(DefaultResourceResolutionProcessor::class.java)
 
     override fun getName(): String {
-        return "rr-processor-source-default"
+        return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-default"
     }
 
     override fun process(resourceAssignment: ResourceAssignment) {
         try {
             // Check if It has Input
-            var value: Any?
+            var value: JsonNode?
             try {
                 value = raRuntimeService.getInputValue(resourceAssignment.name)
             } catch (e: BluePrintProcessorException) {
@@ -60,7 +62,7 @@ open class DefaultResourceResolutionProcessor : ResourceAssignmentProcessor() {
         } catch (e: Exception) {
             ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
             throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}",
-                e)
+                    e)
         }
 
     }
index 66519f9..a662222 100644 (file)
@@ -19,6 +19,7 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.pr
 
 import com.fasterxml.jackson.databind.node.MissingNode
 import com.fasterxml.jackson.databind.node.NullNode
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
 import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty
@@ -33,14 +34,14 @@ import org.springframework.stereotype.Service
  *
  * @author Kapil Singal
  */
-@Service("rr-processor-source-input")
+@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-input")
 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 open class InputResourceResolutionProcessor : ResourceAssignmentProcessor() {
 
     private val logger = LoggerFactory.getLogger(InputResourceResolutionProcessor::class.java)
 
     override fun getName(): String {
-        return "rr-processor-source-input"
+        return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-input"
     }
 
     override fun process(resourceAssignment: ResourceAssignment) {
index d8472ed..37b4774 100644 (file)
 
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor
 
-import com.fasterxml.jackson.databind.node.*
+import com.fasterxml.jackson.databind.node.ArrayNode
+import com.fasterxml.jackson.databind.node.JsonNodeFactory
+import com.fasterxml.jackson.databind.node.MissingNode
+import com.fasterxml.jackson.databind.node.NullNode
+import com.fasterxml.jackson.databind.node.ObjectNode
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.RestResourceSource
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BlueprintWebClientService
-import org.onap.ccsdk.apps.controllerblueprints.core.*
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
+import org.onap.ccsdk.apps.controllerblueprints.core.checkEqualsOrThrow
+import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty
+import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow
+import org.onap.ccsdk.apps.controllerblueprints.core.nullToEmpty
+import org.onap.ccsdk.apps.controllerblueprints.core.returnNotEmptyOrThrow
 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
@@ -36,7 +47,7 @@ import org.springframework.stereotype.Service
  *
  * @author Kapil Singal
  */
-@Service("rr-processor-source-rest")
+@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-rest")
 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyService: BluePrintRestLibPropertyService)
     : ResourceAssignmentProcessor() {
@@ -44,7 +55,7 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
     private val logger = LoggerFactory.getLogger(RestResourceResolutionProcessor::class.java)
 
     override fun getName(): String {
-        return "rr-processor-source-rest"
+        return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-rest"
     }
 
     override fun process(resourceAssignment: ResourceAssignment) {
@@ -60,15 +71,19 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
                 val dName = resourceAssignment.dictionaryName
                 val dSource = resourceAssignment.dictionarySource
                 val resourceDefinition = resourceDictionaries[dName]
-                        ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dName")
+                    ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dName")
                 val resourceSource = resourceDefinition.sources[dSource]
-                        ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
-                val resourceSourceProperties = checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " }
-                val sourceProperties = JacksonUtils.getInstanceFromMap(resourceSourceProperties, RestResourceSource::class.java)
-
-                val urlPath = checkNotNull(sourceProperties.urlPath) { "failed to get request urlPath for $dName under $dSource properties" }
+                    ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
+                val resourceSourceProperties =
+                    checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " }
+                val sourceProperties =
+                    JacksonUtils.getInstanceFromMap(resourceSourceProperties, RestResourceSource::class.java)
+
+                val urlPath =
+                    checkNotNull(sourceProperties.urlPath) { "failed to get request urlPath for $dName under $dSource properties" }
                 val path = nullToEmpty(sourceProperties.path)
-                val inputKeyMapping = checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
+                val inputKeyMapping =
+                    checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
 
                 logger.info("$dSource dictionary information : ($urlPath), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})")
                 // Get the Rest Client Service
@@ -84,7 +99,8 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
             ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment)
         } catch (e: Exception) {
             ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
-            throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e)
+            throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}",
+                e)
         }
     }
 
@@ -99,16 +115,19 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
     }
 
     @Throws(BluePrintProcessorException::class)
-    private fun populateResource(resourceAssignment: ResourceAssignment, sourceProperties: RestResourceSource, restResponse: String, path: String) {
+    private fun populateResource(resourceAssignment: ResourceAssignment, sourceProperties: RestResourceSource,
+                                 restResponse: String, path: String) {
         val dName = resourceAssignment.dictionaryName
         val dSource = resourceAssignment.dictionarySource
         val type = nullToEmpty(resourceAssignment.property?.type)
         lateinit var entrySchemaType: String
 
-        val outputKeyMapping = checkNotNull(sourceProperties.outputKeyMapping) { "failed to get output-key-mappings for $dName under $dSource properties" }
+        val outputKeyMapping =
+            checkNotNull(sourceProperties.outputKeyMapping) { "failed to get output-key-mappings for $dName under $dSource properties" }
         logger.info("Response processing type($type)")
 
-        val responseNode = checkNotNull(JacksonUtils.jsonNode(restResponse).at(path)) { "Failed to find path ($path) in response ($restResponse)" }
+        val responseNode =
+            checkNotNull(JacksonUtils.jsonNode(restResponse).at(path)) { "Failed to find path ($path) in response ($restResponse)" }
         logger.info("populating value for output mapping ($outputKeyMapping), from json ($responseNode)")
 
 
@@ -119,7 +138,8 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
             }
             in BluePrintTypes.validCollectionTypes() -> {
                 // Array Types
-                entrySchemaType = returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" }
+                entrySchemaType =
+                    returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" }
                 val arrayNode = responseNode as ArrayNode
 
                 if (entrySchemaType !in BluePrintTypes.validPrimitiveTypes()) {
@@ -128,9 +148,13 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
                         val arrayChildNode = JsonNodeFactory.instance.objectNode()
                         outputKeyMapping.map {
                             val responseKeyValue = responseSingleJsonNode.get(it.key)
-                            val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key)
+                            val propertyTypeForDataType =
+                                ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key)
                             logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), type  ({$propertyTypeForDataType})")
-                            JacksonUtils.populateJsonNodeValues(it.value, responseKeyValue, propertyTypeForDataType, arrayChildNode)
+                            JacksonUtils.populateJsonNodeValues(it.value,
+                                responseKeyValue,
+                                propertyTypeForDataType,
+                                arrayChildNode)
                         }
                         arrayNode.add(arrayChildNode)
                     }
@@ -144,7 +168,8 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
                 val objectNode = responseNode as ObjectNode
                 outputKeyMapping.map {
                     val responseKeyValue = responseNode.get(it.key)
-                    val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key)
+                    val propertyTypeForDataType =
+                        ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key)
                     logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), type  ({$propertyTypeForDataType})")
                     JacksonUtils.populateJsonNodeValues(it.value, responseKeyValue, propertyTypeForDataType, objectNode)
                 }
@@ -159,11 +184,14 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
     @Throws(BluePrintProcessorException::class)
     private fun validate(resourceAssignment: ResourceAssignment) {
         checkNotEmptyOrThrow(resourceAssignment.name, "resource assignment template key is not defined")
-        checkNotEmptyOrThrow(resourceAssignment.dictionaryName, "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})")
-        checkEqualsOrThrow(ResourceDictionaryConstants.SOURCE_PRIMARY_CONFIG_DATA, resourceAssignment.dictionarySource) {
+        checkNotEmptyOrThrow(resourceAssignment.dictionaryName,
+            "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})")
+        checkEqualsOrThrow(ResourceDictionaryConstants.SOURCE_PRIMARY_CONFIG_DATA,
+            resourceAssignment.dictionarySource) {
             "resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PRIMARY_CONFIG_DATA} but it is ${resourceAssignment.dictionarySource}"
         }
-        checkNotEmptyOrThrow(resourceAssignment.dictionaryName, "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})")
+        checkNotEmptyOrThrow(resourceAssignment.dictionaryName,
+            "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})")
     }
 
     override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
index 1c9a905..b5b126a 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,13 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
 import com.fasterxml.jackson.databind.node.NullNode
 import com.fasterxml.jackson.databind.node.ObjectNode
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
-import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty
-import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow
-import org.onap.ccsdk.apps.controllerblueprints.core.nullToEmpty
-import org.onap.ccsdk.apps.controllerblueprints.core.returnNotEmptyOrThrow
+import org.onap.ccsdk.apps.controllerblueprints.core.*
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
@@ -40,9 +35,11 @@ class ResourceAssignmentUtils {
 
         private val logger: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentUtils::class.toString())
 
+        // TODO("Modify Value type from Any to JsonNode")
         @Synchronized
         @Throws(BluePrintProcessorException::class)
-        fun setResourceDataValue(resourceAssignment: ResourceAssignment, raRuntimeService: ResourceAssignmentRuntimeService, value: Any?) {
+        fun setResourceDataValue(resourceAssignment: ResourceAssignment,
+                                 raRuntimeService: ResourceAssignmentRuntimeService, value: Any?) {
 
             val resourceProp = checkNotNull(resourceAssignment.property) { "Failed in setting resource value for resource mapping $resourceAssignment" }
             checkNotEmptyOrThrow(resourceAssignment.name, "Failed in setting resource value for resource mapping $resourceAssignment")
@@ -111,10 +108,10 @@ class ResourceAssignmentUtils {
         @Synchronized
         @Throws(BluePrintProcessorException::class)
         fun generateResourceDataForAssignments(assignments: List<ResourceAssignment>): String {
-            var result = "{}"
+            val result: String
             try {
                 val mapper = ObjectMapper()
-                val root = mapper.readTree(result)
+                val root: ObjectNode = mapper.createObjectNode()
 
                 assignments.forEach {
                     if (checkNotEmpty(it.name) && it.property != null) {
@@ -122,23 +119,7 @@ class ResourceAssignmentUtils {
                         val type = nullToEmpty(it.property?.type).toLowerCase()
                         val value = it.property?.value
                         logger.info("Generating Resource name ($rName), type ($type), value ($value)")
-
-                        when (value) {
-                            null -> (root as ObjectNode).set(rName, null)
-                            is JsonNode -> (root as ObjectNode).set(rName, value)
-                            else -> {
-                                when (type) {
-                                    BluePrintConstants.DATA_TYPE_TIMESTAMP -> (root as ObjectNode).put(rName, value as String)
-                                    BluePrintConstants.DATA_TYPE_STRING -> (root as ObjectNode).put(rName, value as String)
-                                    BluePrintConstants.DATA_TYPE_BOOLEAN -> (root as ObjectNode).put(rName, value as Boolean)
-                                    BluePrintConstants.DATA_TYPE_INTEGER -> (root as ObjectNode).put(rName, value as Int)
-                                    BluePrintConstants.DATA_TYPE_FLOAT -> (root as ObjectNode).put(rName, value as Float)
-                                    else -> {
-                                        (root as ObjectNode).set(rName, JacksonUtils.getJsonNode(value))
-                                    }
-                                }
-                            }
-                        }
+                        root.set(rName, value)
                     }
                 }
                 result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root)
index fe824ca..905c8e0 100644 (file)
@@ -71,7 +71,7 @@ class ResourceResolutionServiceTest {
         val sources = resourceResolutionService.registeredResourceSources()
         assertNotNull(sources, "failed to get registered sources")
         assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-primary-db",
-                "source-rest")), "failed to get registered sources")
+                "source-rest")), "failed to get registered sources : $sources")
     }
 
     @Test
index 1384b8a..d7c0cc4 100644 (file)
             <artifactId>spring-boot-starter-actuator</artifactId>
         </dependency>
 
+        <!-- Test Dependencies -->
+        <dependency>
+            <groupId>io.mockk</groupId>
+            <artifactId>mockk</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.powermock</groupId>
+            <artifactId>powermock-api-mockito2</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
             <artifactId>kotlin-test-junit</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.powermock</groupId>
-            <artifactId>powermock-api-mockito2</artifactId>
+            <groupId>org.jetbrains.kotlinx</groupId>
+            <artifactId>kotlinx-coroutines-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.projectreactor</groupId>
+            <artifactId>reactor-test</artifactId>
+            <scope>test</scope>
         </dependency>
     </dependencies>
 </project>
 
 package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.validation
 
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
 import org.onap.ccsdk.apps.controllerblueprints.validation.BluePrintDesignTimeValidatorService
+import org.onap.ccsdk.apps.controllerblueprints.validation.extension.ResourceDefinitionValidator
 import org.springframework.stereotype.Service
 
 @Service
-open class BluePrintRuntimeValidatorService(
-        private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintDesignTimeValidatorService(bluePrintTypeValidatorService) {
-
-    override fun validateBluePrints(bluePrintRuntimeService: BluePrintRuntimeService<*>): Boolean {
-
-        bluePrintTypeValidatorService.validateServiceTemplate(bluePrintRuntimeService, "service_template",
-                bluePrintRuntimeService.bluePrintContext().serviceTemplate)
-        if (bluePrintRuntimeService.getBluePrintError().errors.size > 0) {
-            throw BluePrintException("failed in blueprint validation : ${bluePrintRuntimeService.getBluePrintError().errors.joinToString("\n")}")
-        }
-        return true
-    }
-}
\ No newline at end of file
+open class BluePrintRuntimeValidatorService(bluePrintTypeValidatorService: BluePrintTypeValidatorService,
+                                            resourceDefinitionValidator: ResourceDefinitionValidator)
+    : BluePrintDesignTimeValidatorService(bluePrintTypeValidatorService, resourceDefinitionValidator)
index c54e617..19c624b 100644 (file)
@@ -15,7 +15,9 @@
  */
 package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock
 
+import io.mockk.mockk
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
 import org.slf4j.LoggerFactory
@@ -45,4 +47,16 @@ class MockComponentFunction : AbstractComponentFunction() {
     override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
         log.info("Recovering component..")
     }
+}
+
+open class MockResourceSource {
+    @Bean(name = [
+        "rr-processor-source-input",
+        "rr-processor-source-default",
+        "rr-processor-source-primary-db",
+        "rr-processor-source-rest"])
+    open fun sourceInstance(): ResourceAssignmentProcessor {
+        return mockk<ResourceAssignmentProcessor>()
+    }
+
 }
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt
new file mode 100644 (file)
index 0000000..1cafead
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ *  Copyright © 2019 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.blueprintsprocessor.selfservice.api.validation
+
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock.MockResourceSource
+import org.onap.ccsdk.apps.controllerblueprints.validation.BluePrintValidationConfiguration
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.junit4.SpringRunner
+import kotlin.test.assertNotNull
+
+@RunWith(SpringRunner::class)
+@ContextConfiguration(classes = [BluePrintRuntimeValidatorService::class,
+    BluePrintValidationConfiguration::class, MockResourceSource::class])
+class BluePrintRuntimeValidatorServiceTest {
+
+    @Autowired
+    lateinit var bluePrintRuntimeValidatorService: BluePrintRuntimeValidatorService
+
+    @Test
+    fun testBlueprintRuntimeValidation() {
+        val blueprintBasePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
+        assertNotNull(bluePrintRuntimeValidatorService, " failed to initilize bluePrintRuntimeValidatorService")
+
+        bluePrintRuntimeValidatorService.validateBluePrints(blueprintBasePath)
+
+    }
+}
\ No newline at end of file
index b2f1b72..cf400fa 100644 (file)
@@ -98,16 +98,9 @@ object BluePrintTypes {
     @JvmStatic
     fun validPropertyTypes(): List<String> {
         val validTypes: MutableList<String> = arrayListOf()
-        validTypes.add(BluePrintConstants.DATA_TYPE_STRING)
-        validTypes.add(BluePrintConstants.DATA_TYPE_INTEGER)
-        validTypes.add(BluePrintConstants.DATA_TYPE_FLOAT)
-        validTypes.add(BluePrintConstants.DATA_TYPE_DOUBLE)
-        validTypes.add(BluePrintConstants.DATA_TYPE_BOOLEAN)
-        validTypes.add(BluePrintConstants.DATA_TYPE_TIMESTAMP)
-        validTypes.add(BluePrintConstants.DATA_TYPE_NULL)
-        validTypes.add(BluePrintConstants.DATA_TYPE_LIST)
-        validTypes.add(BluePrintConstants.DATA_TYPE_MAP)
-        validTypes.add(BluePrintConstants.DATA_TYPE_JSON)
+        validTypes.addAll(validPrimitiveTypes())
+        validTypes.addAll(validComplexTypes())
+        validTypes.addAll(validCollectionTypes())
         return validTypes
     }
 
@@ -124,6 +117,13 @@ object BluePrintTypes {
         return validTypes
     }
 
+    @JvmStatic
+    fun validComplexTypes(): List<String> {
+        val validTypes: MutableList<String> = arrayListOf()
+        validTypes.add(BluePrintConstants.DATA_TYPE_JSON)
+        return validTypes
+    }
+
     @JvmStatic
     fun validCollectionTypes(): List<String> {
         val validTypes: MutableList<String> = arrayListOf()
index 80ad3f2..c582807 100644 (file)
@@ -29,7 +29,6 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition
 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
 import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
 import java.io.File
 
 interface BluePrintRuntimeService<T> {
@@ -234,7 +233,7 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl
             } else {
                 // Assign default value to the Operation
                 nodeTypeProperty.defaultValue?.let {
-                    resolvedValue = JacksonUtils.jsonNodeFromObject(nodeTypeProperty.defaultValue!!)
+                    resolvedValue = nodeTypeProperty.defaultValue!!
                 }
             }
             // Set for Return of method
index 1bc2500..932f0ed 100644 (file)
@@ -68,12 +68,14 @@ class JacksonUtils {
             }
         }
 
-        fun getContent(fileName: String): String = runBlocking {
+        fun getContent(fileName: String): String = getContent(File(fileName))
+
+        fun getContent(file: File): String = runBlocking {
             async {
                 try {
-                    File(fileName).readText(Charsets.UTF_8)
+                    file.readText(Charsets.UTF_8)
                 } catch (e: Exception) {
-                    throw BluePrintException("couldn't get file ($fileName) content : ${e.message}")
+                    throw BluePrintException("couldn't get file (${file.absolutePath}) content : ${e.message}")
                 }
             }.await()
         }
@@ -167,17 +169,19 @@ class JacksonUtils {
             return getListFromJson(content, valueType)
         }
 
-        fun <T> getMapFromJson(content: String, valueType: Class<T>): MutableMap<String, T>? {
+        fun <T> getMapFromJson(content: String, valueType: Class<T>): MutableMap<String, T> {
             val objectMapper = jacksonObjectMapper()
             val mapType = objectMapper.typeFactory.constructMapType(Map::class.java, String::class.java, valueType)
             return objectMapper.readValue(content, mapType)
         }
 
-        fun <T> getMapFromFile(fileName: String, valueType: Class<T>): MutableMap<String, T>? {
-            val content: String = getContent(fileName)
+        fun <T> getMapFromFile(file: File, valueType: Class<T>): MutableMap<String, T> {
+            val content: String = getContent(file)
             return getMapFromJson(content, valueType)
         }
 
+        fun <T> getMapFromFile(fileName: String, valueType: Class<T>): MutableMap<String, T> = getMapFromFile(File(fileName), valueType)
+
         fun <T> getInstanceFromMap(properties: MutableMap<String, JsonNode>, classType: Class<T>): T {
             return readValue(getJson(properties), classType)
                     ?: throw BluePrintProcessorException("failed to transform content ($properties) to type ($classType)")
index 4ea5ab5..a43bf45 100644 (file)
@@ -49,7 +49,7 @@ open class BluePrintArtifactDefinitionValidatorImpl(
 
         paths.add(name)
         val type: String = artifactDefinition.type
-        log.info("Validation ArtifactDefinition of type {$type}")
+        log.trace("Validation ArtifactDefinition of type {$type}")
         // Check Artifact Type
         checkValidArtifactType(name, type)
 
index 84073ff..c898577 100644 (file)
@@ -19,17 +19,25 @@ package org.onap.ccsdk.apps.controllerblueprints.validation
 
 import com.att.eelf.configuration.EELFLogger
 import com.att.eelf.configuration.EELFManager
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants
+import org.onap.ccsdk.apps.controllerblueprints.validation.extension.ResourceDefinitionValidator
 import org.springframework.stereotype.Service
+import java.io.File
 import java.util.*
 
 
 @Service
-open class BluePrintDesignTimeValidatorService(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintValidatorService {
+open class BluePrintDesignTimeValidatorService(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService,
+                                               private val resourceDefinitionValidator: ResourceDefinitionValidator)
+    : BluePrintValidatorService {
 
     private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintDesignTimeValidatorService::class.toString())
 
@@ -43,9 +51,32 @@ open class BluePrintDesignTimeValidatorService(private val bluePrintTypeValidato
 
         bluePrintTypeValidatorService.validateServiceTemplate(bluePrintRuntimeService, "service_template",
                 bluePrintRuntimeService.bluePrintContext().serviceTemplate)
+
+        // Validate Resource Definitions
+        validateResourceDefinitions(bluePrintRuntimeService)
+
         if (bluePrintRuntimeService.getBluePrintError().errors.size > 0) {
             throw BluePrintException("failed in blueprint validation : ${bluePrintRuntimeService.getBluePrintError().errors.joinToString("\n")}")
         }
         return true
     }
+
+    private fun validateResourceDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>) {
+        // Validate Resource Dictionary
+        val blueprintBasePath = bluePrintRuntimeService.bluePrintContext().rootPath
+
+        val resourceDefinitionsPath = blueprintBasePath.plus(File.separator)
+                .plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR).plus(File.separator)
+                .plus("${ResourceDictionaryConstants.PATH_RESOURCE_DEFINITION_TYPE}.json")
+
+        val resourceDefinitionFile = File(resourceDefinitionsPath)
+
+        if (resourceDefinitionFile.exists()) {
+            val resourceDefinitionMap = JacksonUtils.getMapFromFile(resourceDefinitionFile, ResourceDefinition::class.java)
+
+            resourceDefinitionMap?.forEach { resourceDefinitionName, resourceDefinition ->
+                resourceDefinitionValidator.validate(bluePrintRuntimeService, resourceDefinitionName, resourceDefinition)
+            }
+        }
+    }
 }
diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidationConfiguration.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidationConfiguration.kt
new file mode 100644 (file)
index 0000000..bad1479
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ *  Copyright © 2019 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.validation
+
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.context.annotation.Configuration
+
+@Configuration
+@ComponentScan
+open class BluePrintValidationConfiguration
\ No newline at end of file
index 6fe4fa3..002dd9f 100644 (file)
@@ -40,7 +40,7 @@ open class ArtifactMappingResourceValidator(private val bluePrintTypeValidatorSe
         val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
         val file: String = artifactDefinition.file
         val completePath = bluePrintContext.rootPath.plus(File.separator).plus(file)
-        log.info("Validation artifact-mapping-resource($completePath)")
+        log.trace("Validation artifact-mapping-resource($completePath)")
         val resourceAssignment = JacksonUtils.getListFromFile(completePath, ResourceAssignment::class.java)
         val resourceAssignmentValidationService = ResourceAssignmentValidationServiceImpl()
         resourceAssignmentValidationService.validate(resourceAssignment)
diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ResourceDefinitionValidation.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ResourceDefinitionValidation.kt
new file mode 100644 (file)
index 0000000..6975ec6
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ *  Copyright © 2019 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.validation.extension
+
+import com.att.eelf.configuration.EELFLogger
+import com.att.eelf.configuration.EELFManager
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidator
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
+import org.springframework.beans.factory.config.ConfigurableBeanFactory
+import org.springframework.context.annotation.Scope
+import org.springframework.stereotype.Service
+
+interface ResourceDefinitionValidator : BluePrintValidator<ResourceDefinition>
+
+@Service
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class ResourceDefinitionValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : ResourceDefinitionValidator {
+
+    private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDefinitionValidatorImpl::class.java)
+
+    override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String,
+                          resourceDefinition: ResourceDefinition) {
+        log.trace("validating resource definition($name)")
+        resourceDefinition.sources.forEach { name, nodeTemplate ->
+            bluePrintTypeValidatorService.validateNodeTemplate(bluePrintRuntimeService, name, nodeTemplate)
+        }
+    }
+}
\ No newline at end of file
index 43c3e0e..3fc918e 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -27,6 +28,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
 import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.apps.controllerblueprints.validation.extension.ResourceDefinitionValidator
 import kotlin.test.assertEquals
 import kotlin.test.assertTrue
 
@@ -35,11 +37,14 @@ class BluePrintDesignTimeValidatorServiceTest {
     private val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
     private val bluePrintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
     private val mockBluePrintTypeValidatorService = MockBluePrintTypeValidatorService()
-    private val defaultBluePrintValidatorService = BluePrintDesignTimeValidatorService(mockBluePrintTypeValidatorService)
+    private val resourceDefinitionValidator = mockk<ResourceDefinitionValidator>()
+    private val defaultBluePrintValidatorService = BluePrintDesignTimeValidatorService(mockBluePrintTypeValidatorService, resourceDefinitionValidator)
     private val workflowValidator = BluePrintWorkflowValidatorImpl(mockBluePrintTypeValidatorService)
 
     @Test
     fun testValidateOfType() {
+        every { resourceDefinitionValidator.validate(bluePrintRuntime, any(), any()) } returns Unit
+
         val valid = defaultBluePrintValidatorService.validateBluePrints(bluePrintRuntime)
         assertTrue(valid, "failed in blueprint Validation")
     }
index d71fbbf..b35bca7 100644 (file)
@@ -23,10 +23,8 @@ import org.apache.commons.collections.CollectionUtils
 import org.apache.commons.lang3.StringUtils
 import org.apache.commons.lang3.text.StrBuilder
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
-import org.onap.ccsdk.apps.controllerblueprints.core.format
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory
 import java.io.Serializable
 
 /**
@@ -53,7 +51,6 @@ open class ResourceAssignmentValidationServiceImpl : ResourceAssignmentValidatio
 
     override fun validate(resourceAssignments: List<ResourceAssignment>): Boolean {
         try {
-            validateSources(resourceAssignments)
             validateTemplateNDictionaryKeys(resourceAssignments)
             validateCyclicDependency(resourceAssignments)
             if (StringUtils.isNotBlank(validationMessage)) {
@@ -65,17 +62,6 @@ open class ResourceAssignmentValidationServiceImpl : ResourceAssignmentValidatio
         return true
     }
 
-    open fun validateSources(resourceAssignments: List<ResourceAssignment>) {
-        log.info("validating resource assignment sources")
-        // Check the Resource Assignment Source(Dynamic Instance) is valid.
-        resourceAssignments.forEach { resourceAssignment ->
-            try {
-                ResourceSourceMappingFactory.getRegisterSourceMapping(resourceAssignment.dictionarySource!!)
-            } catch (e: BluePrintException) {
-                validationMessage.appendln(e.message + format(" for resource assignment({})", resourceAssignment.name))
-            }
-        }
-    }
 
     open fun validateTemplateNDictionaryKeys(resourceAssignments: List<ResourceAssignment>) {
 
@@ -121,7 +107,7 @@ open class ResourceAssignmentValidationServiceImpl : ResourceAssignmentValidatio
         resourceAssignmentMap.map { it.value }.map { resourceAssignment ->
             if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) {
                 resourceAssignment.dependencies!!.map {
-                    log.info("Topological Graph link from {} to {}", it, resourceAssignment.name)
+                    log.trace("Topological Graph link from {} to {}", it, resourceAssignment.name)
                     topologySorting.add(resourceAssignmentMap[it]!!, resourceAssignment)
                 }
             } else {
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt
deleted file mode 100644 (file)
index 9541a7b..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- *  Copyright © 2018 IBM.
- *  Modifications 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.service
-
-import com.att.eelf.configuration.EELFLogger
-import com.att.eelf.configuration.EELFManager
-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.BluePrintTypes
-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.interfaces.BluePrintRepoService
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintExpressionService
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
-import java.io.Serializable
-
-/**
- * ResourceDefinitionValidationService.
- *
- * @author Brinda Santh
- */
-interface ResourceDefinitionValidationService : Serializable {
-
-    @Throws(BluePrintException::class)
-    fun validate(resourceDefinition: ResourceDefinition)
-
-}
-
-/**
- * ResourceDefinitionValidationService.
- *
- * @author Brinda Santh
- */
-open class ResourceDefinitionValidationServiceImpl(private val bluePrintRepoService: BluePrintRepoService) : ResourceDefinitionValidationService {
-
-    private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDefinitionValidationService::class.java)
-
-    override fun validate(resourceDefinition: ResourceDefinition) {
-        Preconditions.checkNotNull(resourceDefinition, "Failed to get Resource Definition")
-        log.trace("Validating Resource Dictionary Definition {}", resourceDefinition.name)
-
-        resourceDefinition.sources.forEach { name, nodeTemplate ->
-            val sourceType = nodeTemplate.type
-
-            val sourceNodeType = bluePrintRepoService.getNodeType(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)
-            } else {
-                throw BluePrintException(format("property({}) of expression ({}) is not supported",
-                        propertyName, propertyAssignment))
-            }
-        }
-    }
-
-    open fun checkPropertyValue(propertyDefinition: PropertyDefinition, propertyName: String, propertyAssignment: JsonNode) {
-        val propertyType = propertyDefinition.type
-        val isValid: Boolean
-
-        if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) {
-            isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment)
-
-        } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) {
-
-            isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment)
-        } else {
-            bluePrintRepoService.getDataType(propertyType)
-            isValid = true
-        }
-
-        check(isValid) {
-            throw BluePrintException(format("property({}) defined of type({}) is not compatable with the value ({})",
-                    propertyName, propertyType, propertyAssignment))
-        }
-    }
-}
\ 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/ResourceDefinitionValidationServiceTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java
deleted file mode 100644 (file)
index 7f040b2..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- *  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 ResourceDefinitionValidationServiceTest {
-    private String basePath = "load/model_type";
-    private String dictionaryPath = "load/resource_dictionary";
-    private BluePrintRepoFileService bluePrintRepoFileService = new BluePrintRepoFileService(basePath);
-
-    @Test
-    public void testValidateSource() throws Exception {
-
-        String inputFileName = dictionaryPath + "/input-source.json";
-        testValidate(inputFileName);
-
-        String dbFileName = dictionaryPath + "/primary-db-source.json";
-        testValidate(dbFileName);
-
-        String defaultFileName = dictionaryPath + "/default-source.json";
-        testValidate(defaultFileName);
-
-        String restFileName = dictionaryPath + "/mdsal-source.json";
-        testValidate(restFileName);
-    }
-
-    private void testValidate(String fileName) throws Exception {
-
-        ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class);
-        Assert.assertNotNull("Failed to populate dictionaryDefinition for  type", resourceDefinition);
-
-        ResourceDefinitionValidationService resourceDictionaryValidationService =
-                new ResourceDefinitionValidationServiceImpl(bluePrintRepoFileService);
-        resourceDictionaryValidationService.validate(resourceDefinition);
-        Assert.assertNotNull(String.format("Failed to populate dictionaryDefinition for : %s", fileName), resourceDefinition);
-    }
-}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java
deleted file mode 100644 (file)
index 57330d9..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*\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
- * 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.validator;\r
-\r
-import com.google.common.base.Preconditions;\r
-import org.apache.commons.lang3.StringUtils;\r
-import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;\r
-\r
-/**\r
- * ResourceDictionaryValidator.java Purpose: Provide Validation Service for Model Type Resource\r
- * Dictionary Validator\r
- *\r
- * @author Brinda Santh\r
- * @version 1.0\r
- */\r
-public class ResourceDictionaryValidator {\r
-\r
-    private ResourceDictionaryValidator() {}\r
-\r
-    /**\r
-     * This is a validateResourceDictionary method\r
-     * \r
-     * @param resourceDictionary\r
-     * @return boolean\r
-     *\r
-     */\r
-    public static boolean validateResourceDictionary(ResourceDictionary resourceDictionary) {\r
-\r
-        Preconditions.checkNotNull(resourceDictionary,"ResourceDictionary Information is missing." );\r
-\r
-        Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getName()),\r
-                "DataDictionary Alias Name Information is missing.");\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
-        Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getTags()),\r
-                "DataDictionary Tags Information is missing.");\r
-        Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getUpdatedBy()),\r
-                "DataDictionary Updated By Information is missing.");\r
-        return true;\r
-\r
-    }\r
-\r
-}\r
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java
deleted file mode 100644 (file)
index 5d15e08..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-/*\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.validator;\r
-\r
-import com.google.common.base.Preconditions;\r
-import org.apache.commons.collections.MapUtils;\r
-import org.apache.commons.lang3.StringUtils;\r
-import org.jetbrains.annotations.NotNull;\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.CapabilityAssignment;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorDefaultService;\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.service.ResourceAssignmentValidationService;\r
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl;\r
-\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-/**\r
- * ServiceTemplateValidator.java Purpose: Provide Configuration Generator ServiceTemplateValidator\r
- *\r
- * @author Brinda Santh\r
- * @version 1.0\r
- */\r
-\r
-public class ServiceTemplateValidator extends BluePrintValidatorDefaultService {\r
-\r
-    StringBuilder message = new StringBuilder();\r
-    private Map<String, String> metaData = new HashMap<>();\r
-\r
-    /**\r
-     * This is a validateServiceTemplate\r
-     *\r
-     * @param serviceTemplateContent serviceTemplateContent\r
-     * @return boolean\r
-     * @throws BluePrintException BluePrintException\r
-     */\r
-    public boolean validateServiceTemplate(String serviceTemplateContent) throws BluePrintException {\r
-        if (StringUtils.isNotBlank(serviceTemplateContent)) {\r
-            ServiceTemplate serviceTemplate =\r
-                    JacksonUtils.Companion.readValue(serviceTemplateContent, ServiceTemplate.class);\r
-            return validateServiceTemplate(serviceTemplate);\r
-        } else {\r
-            throw new BluePrintException(\r
-                    "Service Template Content is  (" + serviceTemplateContent + ") not Defined.");\r
-        }\r
-    }\r
-\r
-    /**\r
-     * This is a validateServiceTemplate\r
-     *\r
-     * @param serviceTemplate serviceTemplate\r
-     * @return boolean\r
-     * @throws BluePrintException BluePrintException\r
-     */\r
-    @SuppressWarnings("squid:S00112")\r
-    public boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException {\r
-        Map<String, Object> properties = new HashMap<>();\r
-        super.validateBlueprint(serviceTemplate, properties);\r
-        return true;\r
-    }\r
-\r
-    /**\r
-     * This is a getMetaData to get the key information during the\r
-     *\r
-     * @return Map<String                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               String>\r
-     */\r
-    public Map<String, String> getMetaData() {\r
-        return metaData;\r
-    }\r
-\r
-    @Override\r
-    public void validateMetadata(@NotNull Map<String, String> metaDataMap) throws BluePrintException {\r
-\r
-        Preconditions.checkNotNull(serviceTemplate.getMetadata(), "Service Template Metadata Information is missing.");\r
-        super.validateMetadata(metaDataMap);\r
-\r
-        this.metaData.putAll(serviceTemplate.getMetadata());\r
-    }\r
-\r
-\r
-    @Override\r
-    public void validateNodeTemplate(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate)\r
-            throws BluePrintException {\r
-        super.validateNodeTemplate(nodeTemplateName, nodeTemplate);\r
-        validateNodeTemplateCustom(nodeTemplateName, nodeTemplate);\r
-\r
-    }\r
-\r
-    @Deprecated()\r
-    private void validateNodeTemplateCustom(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate)\r
-            throws BluePrintException {\r
-        String derivedFrom = getBluePrintContext().nodeTemplateNodeType(nodeTemplateName).getDerivedFrom();\r
-\r
-        if (BluePrintConstants.MODEL_TYPE_NODE_ARTIFACT.equals(derivedFrom)) {\r
-            List<ResourceAssignment> resourceAssignment = getResourceAssignments(nodeTemplate);\r
-            ResourceAssignmentValidationService resourceAssignmentValidationService = new ResourceAssignmentValidationServiceImpl();\r
-            resourceAssignmentValidationService.validate(resourceAssignment);\r
-        }\r
-    }\r
-\r
-    private List<ResourceAssignment> getResourceAssignments(@NotNull NodeTemplate nodeTemplate) {\r
-\r
-        List<ResourceAssignment> resourceAssignment = null;\r
-\r
-        if (MapUtils.isNotEmpty(nodeTemplate.getCapabilities())) {\r
-\r
-            CapabilityAssignment capabilityAssignment =\r
-                    nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);\r
-            if (capabilityAssignment != null && capabilityAssignment.getProperties() != null) {\r
-                Object mappingObject =\r
-                        capabilityAssignment.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);\r
-                if (mappingObject != null) {\r
-                    String mappingContent = JacksonUtils.Companion.getJson(mappingObject);\r
-                    Preconditions.checkArgument(StringUtils.isNotBlank(mappingContent),\r
-                            String.format("Failed to get capability mapping property (%s) ", ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING));\r
-\r
-                    resourceAssignment = JacksonUtils.Companion.getListFromJson(mappingContent, ResourceAssignment.class);\r
-\r
-                    Preconditions.checkNotNull(resourceAssignment,\r
-                            String.format("Failed to get resource assignment info from the content (%s) ", mappingContent));\r
-                }\r
-            }\r
-        }\r
-        return resourceAssignment;\r
-    }\r
-}\r
index f856b9e..88589eb 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,21 +25,10 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.*
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionValidationServiceImpl
 import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository
 import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository
 import org.springframework.stereotype.Service
 
-// Resource Dictionary Validation Services
-
-@Service
-class DefaultResourceAssignmentValidationService : ResourceAssignmentValidationServiceImpl()
-
-@Service
-class DefalutResourceDefinitionValidationService(bluePrintRepoService: BluePrintRepoService)
-    : ResourceDefinitionValidationServiceImpl(bluePrintRepoService)
-
 interface ResourceDefinitionRepoService : BluePrintRepoService {
 
     @Throws(BluePrintException::class)
index c249314..ec7d8ae 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,17 +21,15 @@ import com.google.common.base.Preconditions
 import org.apache.commons.collections.CollectionUtils
 import org.apache.commons.lang3.StringUtils
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionValidationService
 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary
 import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository
-import org.onap.ccsdk.apps.controllerblueprints.service.validator.ResourceDictionaryValidator
 import org.springframework.stereotype.Service
 
 @Service
-class ResourceDictionaryHandler(private val resourceDictionaryRepository: ResourceDictionaryRepository,
-                                private val resourceDictionaryValidationService: ResourceDefinitionValidationService) {
+class ResourceDictionaryHandler(private val resourceDictionaryRepository: ResourceDictionaryRepository) {
 
 
     /**
@@ -86,7 +85,8 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour
         val resourceDefinition = resourceDictionary.definition
         Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content")
         // Validate the Resource Definitions
-        resourceDictionaryValidationService.validate(resourceDefinition)
+        //TODO( Save Validator)
+        //validate(resourceDefinition)
 
         resourceDictionary.tags = resourceDefinition.tags
         resourceDefinition.updatedBy = resourceDictionary.updatedBy
@@ -98,7 +98,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour
             resourceDictionary.entrySchema = propertyDefinition.entrySchema!!.type
         }
 
-        ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary)
+        validateResourceDictionary(resourceDictionary)
 
         val dbResourceDictionaryData = resourceDictionaryRepository.findByName(resourceDictionary.name)
         if (dbResourceDictionaryData.isPresent) {
@@ -135,4 +135,14 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour
     fun getResourceSourceMapping(): ResourceSourceMapping {
         return ResourceSourceMappingFactory.getRegisterSourceMapping()
     }
+
+    private fun validateResourceDictionary(resourceDictionary: ResourceDictionary): Boolean {
+        checkNotEmptyOrThrow(resourceDictionary.name, "DataDictionary Definition name is missing.")
+        checkNotNull(resourceDictionary.definition) { "DataDictionary Definition Information is missing." }
+        checkNotEmptyOrThrow(resourceDictionary.description, "DataDictionary Definition Information is missing.")
+        checkNotEmptyOrThrow(resourceDictionary.tags, "DataDictionary Definition tags is missing.")
+        checkNotEmptyOrThrow(resourceDictionary.updatedBy, "DataDictionary Definition updatedBy is missing.")
+        return true
+
+    }
 }
\ No newline at end of file