From e10032c90bfcf5c56fc3200e89b142b782eac88f Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Tue, 28 Aug 2018 22:46:02 -0400 Subject: Controller Blueprints Microservice Add resource assignment json data to input property convertor utlity and their test cases. Change-Id: Ie4557048e85df38c75ac3d31ff62d4fce0662d9f Issue-ID: CCSDK-488 Signed-off-by: Brinda Santh --- .../core/service/BluePrintRuntimeService.kt | 143 +++++++++++---------- .../resource/dict/ResourceDictionaryConstants.java | 30 ----- .../resource/dict/ResourceDictionaryConstants.kt | 32 +++++ .../service/ResourceDefinitionValidationService.kt | 113 ++++++++++++++++ .../service/ResourceDictionaryValidationService.kt | 114 ---------------- .../resource/dict/utils/ResourceDictionaryUtils.kt | 15 +++ .../ResourceDefinitionValidationServiceTest.java | 56 ++++++++ .../ResourceDictionaryValidationServiceTest.java | 56 -------- .../dict/utils/ResourceDictionaryUtilsTest.java | 15 +++ .../resources/data/resource-assignment-input.json | 10 ++ .../ResourceDefinitionValidationService.java | 29 +++++ .../service/ResourceDictionaryService.java | 67 ++++------ .../ResourceDictionaryValidationService.java | 31 ----- 13 files changed, 370 insertions(+), 341 deletions(-) delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/data/resource-assignment-input.json create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java (limited to 'ms') diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt index b03fdf92b..5a8d5428a 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt @@ -26,6 +26,7 @@ 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.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.slf4j.Logger import org.slf4j.LoggerFactory /** @@ -33,14 +34,14 @@ import org.slf4j.LoggerFactory * * @author Brinda Santh */ -class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var context: MutableMap = hashMapOf()) { +open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var context: MutableMap = hashMapOf()) { private val logger: Logger = LoggerFactory.getLogger(this::class.toString()) /* Get the Node Type Definition for the Node Template, Then iterate Node Type Properties and resolve the expressing */ - fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap { + open fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap { logger.info("resolveNodeTemplatePropertyValues for node template ({})", nodeTemplateName) val propertyAssignmentValue: MutableMap = hashMapOf() @@ -76,7 +77,7 @@ class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var contex return propertyAssignmentValue } - fun resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName: String, + open fun resolveNodeTemplateInterfaceOperationInputs(nodeTemplateName: String, interfaceName: String, operationName: String): MutableMap { logger.info("nodeTemplateInterfaceOperationInputsResolvedExpression for node template ({}),interface name ({}), " + "operationName({})", nodeTemplateName, interfaceName, operationName) @@ -105,7 +106,7 @@ class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var contex var resolvedValue: JsonNode = NullNode.getInstance() if (propertyAssignment != null) { // Resolve the Expressing - val propertyAssignmentExpression = PropertyAssignmentService( context, this) + val propertyAssignmentExpression = PropertyAssignmentService(context, this) resolvedValue = propertyAssignmentExpression.resolveAssignmentExpression(nodeTemplateName, nodeTypePropertyName, propertyAssignment) } else { // Assign default value to the Operation @@ -122,8 +123,8 @@ class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var contex } - fun resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName: String, - interfaceName: String, operationName: String, componentContext: MutableMap): Unit { + open fun resolveNodeTemplateInterfaceOperationOutputs(nodeTemplateName: String, + interfaceName: String, operationName: String, componentContext: MutableMap) { logger.info("nodeTemplateInterfaceOperationInputsResolvedExpression for node template ({}),interface name ({}), " + "operationName({})", nodeTemplateName, interfaceName, operationName) @@ -150,125 +151,127 @@ class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var contex } } - fun resolveNodeTemplateArtifact(nodeTemplateName: String, + open fun resolveNodeTemplateArtifact(nodeTemplateName: String, artifactName: String): String { val nodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName) val artifactDefinition: ArtifactDefinition = nodeTemplate.artifacts?.get(artifactName) ?: throw BluePrintProcessorException(String.format("failed to get artifat definition {} from the node template" , artifactName)) - val propertyAssignmentExpression = PropertyAssignmentService( context, this) + val propertyAssignmentExpression = PropertyAssignmentService(context, this) return propertyAssignmentExpression.artifactContent(artifactDefinition) } - fun setInputValue(propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode): Unit { - val path = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_INPUTS) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun setInputValue(propertyName: String, propertyDefinition: PropertyDefinition, value: JsonNode) { + val path = StringBuilder(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() logger.trace("setting input path ({}), values ({})", path, value) context[path] = value } - fun setWorkflowInputValue(workflowName: String, propertyName: String, value: JsonNode): Unit { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_WORKFLOWS).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(workflowName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_INPUTS) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun setWorkflowInputValue(workflowName: String, propertyName: String, value: JsonNode) { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_WORKFLOWS).append(BluePrintConstants.PATH_DIVIDER).append(workflowName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() context[path] = value } - fun setNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String, value: JsonNode): Unit { + open fun setNodeTemplatePropertyValue(nodeTemplateName: String, propertyName: String, value: JsonNode) { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_TEMPLATES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() context[path] = value } - fun setNodeTemplateOperationPropertyValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, - value: JsonNode): Unit { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_TEMPLATES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_INTERFACES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(interfaceName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_OPERATIONS).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(operationName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun setNodeTemplateOperationPropertyValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, + value: JsonNode) { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(BluePrintConstants.PATH_DIVIDER).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() logger.trace("setting operation property path ({}), values ({})", path, value) context[path] = value } - fun setNodeTemplateOperationInputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, - value: JsonNode): Unit { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_TEMPLATES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_INTERFACES).append(interfaceName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_OPERATIONS).append(operationName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_INPUTS) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun setNodeTemplateOperationInputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, + value: JsonNode) { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() context[path] = value } - fun setNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, - value: JsonNode): Unit { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_TEMPLATES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_INTERFACES).append(interfaceName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_OPERATIONS).append(operationName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_OUTPUTS) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun setNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String, + value: JsonNode) { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OUTPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() context[path] = value } - fun getInputValue(propertyName: String): JsonNode { - val path = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_INPUTS) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun getInputValue(propertyName: String): JsonNode { + val path = StringBuilder(BluePrintConstants.PATH_INPUTS) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() return context[path] as? JsonNode ?: NullNode.instance } - fun getNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String): JsonNode { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_TEMPLATES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_INTERFACES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(interfaceName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_OPERATIONS).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(operationName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun getNodeTemplateOperationOutputValue(nodeTemplateName: String, interfaceName: String, operationName: String, propertyName: String): JsonNode { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_INTERFACES).append(BluePrintConstants.PATH_DIVIDER).append(interfaceName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_OPERATIONS).append(BluePrintConstants.PATH_DIVIDER).append(operationName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() return context[path] as JsonNode } - fun getPropertyValue(nodeTemplateName: String, propertyName: String): JsonNode? { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_TEMPLATES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun getPropertyValue(nodeTemplateName: String, propertyName: String): JsonNode? { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() return context[path] as JsonNode } - fun getRequirementPropertyValue(nodeTemplateName: String, requirementName: String, propertyName: String): JsonNode? { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_TEMPLATES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_REQUIREMENTS).append(requirementName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun getRequirementPropertyValue(nodeTemplateName: String, requirementName: String, propertyName: String): JsonNode? { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_REQUIREMENTS).append(requirementName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() return context[path] as JsonNode } - fun getCapabilityPropertyValue(nodeTemplateName: String, capabilityName: String, propertyName: String): JsonNode? { - val path: String = StringBuilder(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_NODE_TEMPLATES).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_CAPABILITIES).append(capabilityName) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_PROPERTIES) - .append(org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() + open fun getCapabilityPropertyValue(nodeTemplateName: String, capabilityName: String, propertyName: String): JsonNode? { + val path: String = StringBuilder(BluePrintConstants.PATH_NODE_TEMPLATES).append(BluePrintConstants.PATH_DIVIDER).append(nodeTemplateName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_CAPABILITIES).append(capabilityName) + .append(BluePrintConstants.PATH_DIVIDER).append(BluePrintConstants.PATH_PROPERTIES) + .append(BluePrintConstants.PATH_DIVIDER).append(propertyName).toString() return context[path] as JsonNode } - fun assignInputs(jsonNode: JsonNode): Unit { + open fun assignInputs(jsonNode: JsonNode) { logger.info("assignInputs from input JSON ({})", jsonNode.toString()) bluePrintContext.inputs?.forEach { propertyName, property -> - val valueNode: JsonNode = jsonNode.at("/" + propertyName) ?: NullNode.getInstance() + val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName) + ?: NullNode.getInstance() setInputValue(propertyName, property, valueNode) } } - fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode): Unit { + open fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode) { logger.info("assign workflow {} input value ({})", workflowName, jsonNode.toString()) bluePrintContext.workflowByName(workflowName)?.inputs?.forEach { propertyName, property -> - val valueNode: JsonNode = jsonNode.at("/" + propertyName) ?: NullNode.getInstance() + val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName) + ?: NullNode.getInstance() setWorkflowInputValue(workflowName, propertyName, valueNode) } } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java deleted file mode 100644 index 48b89bd6d..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications 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; - -public class ResourceDictionaryConstants { - public static final String SOURCE_INPUT= "input"; - public static final String SOURCE_DEFAULT = "default"; - public static final String SOURCE_DB = "db"; - public static final String SOURCE_MDSAL = "mdsal"; - - public static final String PROPERTY_TYPE = "type"; - public static final String PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping"; - public static final String PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping"; - public static final String PROPERTY_KEY_DEPENDENCIES = "key-dependencies"; -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt new file mode 100644 index 000000000..9b89f6f40 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt @@ -0,0 +1,32 @@ +/* + * 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 +/** + * ResourceDictionaryConstants + * + * @author Brinda Santh + */ +object ResourceDictionaryConstants { + const val SOURCE_INPUT = "input" + const val SOURCE_DEFAULT = "default" + const val SOURCE_DB = "db" + + const val PROPERTY_TYPE = "type" + const val PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping" + const val PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping" + const val PROPERTY_KEY_DEPENDENCIES = "key-dependencies" +} \ No newline at end of file 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 new file mode 100644 index 000000000..1defa538c --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt @@ -0,0 +1,113 @@ +/* + * 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.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.service.BluePrintExpressionService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import org.slf4j.LoggerFactory +import java.io.Serializable +/** + * ResourceDefinitionValidationService. + * + * @author Brinda Santh + */ +interface ResourceDefinitionValidationService : Serializable { + + @Throws(BluePrintException::class) + fun validate(resourceDefinition: ResourceDefinition) + +} +/** + * ResourceDefinitionValidationService. + * + * @author Brinda Santh + */ +open class ResourceDefinitionDefaultValidationService(private val bluePrintRepoService: BluePrintRepoService) : ResourceDefinitionValidationService { + + private val log = LoggerFactory.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)?.block() + ?: throw BluePrintException(format("Failed to get source({}) node type definition({})", name, 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, + properties: MutableMap) { + 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) + ?: throw BluePrintException(format("property({}) defined of data type({}) is not in repository", + propertyName, 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/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 deleted file mode 100644 index e4835a06d..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt +++ /dev/null @@ -1,114 +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.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.service.BluePrintExpressionService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition -import org.slf4j.LoggerFactory -import java.io.Serializable -/** - * ResourceDictionaryValidationService. - * - * @author Brinda Santh - */ -interface ResourceDictionaryValidationService : Serializable { - - @Throws(BluePrintException::class) - fun validate(resourceDefinition: ResourceDefinition) - -} -/** - * ResourceDictionaryDefaultValidationService. - * - * @author Brinda Santh - */ -open class ResourceDictionaryDefaultValidationService(private 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") - log.trace("Validating Resource Dictionary Definition {}", resourceDefinition.name) - - resourceDefinition.sources.forEach { (name, nodeTemplate) -> - val sourceType = nodeTemplate.type - - val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)?.block() - ?: throw BluePrintException(format("Failed to get source({}) node type definition({})", name, 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, - properties: MutableMap) { - 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 - var isValid = false - - 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) - ?: throw BluePrintException(format("property({}) defined of data type({}) is not in repository", - propertyName, 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/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt index e08c09c8e..733a443fd 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt @@ -16,8 +16,11 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.NullNode import org.apache.commons.collections.MapUtils import org.apache.commons.lang3.StringUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition @@ -59,4 +62,16 @@ object ResourceDictionaryUtils { } return source } + + @JvmStatic + fun assignInputs(data: JsonNode, context: MutableMap) { + log.trace("assignInputs from input JSON ({})", data.toString()) + data.fields().forEach { field -> + val valueNode: JsonNode = data.at("/".plus(field.key)) ?: NullNode.getInstance() + + val path = BluePrintConstants.PATH_INPUTS.plus(BluePrintConstants.PATH_DIVIDER).plus(field.key) + log.trace("setting path ({}), values ({})", path, valueNode) + context[path] = valueNode + } + } } \ 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 new file mode 100644 index 000000000..ef305627f --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java @@ -0,0 +1,56 @@ +/* + * 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 + "/db-source.json"; + testValidate(inputFileName); + + String dbFileName = dictionaryPath + "/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.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for type", resourceDefinition); + + ResourceDefinitionValidationService resourceDictionaryValidationService = + new ResourceDefinitionDefaultValidationService(bluePrintRepoFileService); + resourceDictionaryValidationService.validate(resourceDefinition); + Assert.assertNotNull(String.format("Failed to populate dictionaryDefinition for : %s", fileName), resourceDefinition); + } +} 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 deleted file mode 100644 index b50c0e44b..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java +++ /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 ResourceDictionaryValidationServiceTest { - private String basePath = "load/model_type"; - String dictionaryPath = "load/resource_dictionary"; - BluePrintRepoFileService bluePrintRepoFileService = new BluePrintRepoFileService(basePath); - - @Test - public void testValidateSource() throws Exception { - - String inputFileName = dictionaryPath + "/db-source.json"; - testValidate(inputFileName); - - String dbFileName = dictionaryPath + "/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.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for type", resourceDefinition); - - ResourceDictionaryValidationService resourceDictionaryValidationService = - new ResourceDictionaryDefaultValidationService(bluePrintRepoFileService); - resourceDictionaryValidationService.validate(resourceDefinition); - Assert.assertNotNull(String.format("Failed to populate dictionaryDefinition for : %s", fileName), resourceDefinition); - } -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java index 2a207e09b..5c22f6543 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java @@ -18,9 +18,12 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils; +import com.fasterxml.jackson.databind.JsonNode; import org.junit.Assert; import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate; +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.ResourceDefinition; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; @@ -76,4 +79,16 @@ public class ResourceDictionaryUtilsTest { } + @Test + public void testAssignInputs() { + JsonNode data = JacksonUtils.jsonNodeFromClassPathFile("data/resource-assignment-input.json"); + Map context = new HashMap<>(); + ResourceDictionaryUtils.assignInputs(data, context); + String path = BluePrintConstants.PATH_INPUTS.concat(BluePrintConstants.PATH_DIVIDER).concat("mapValue"); + log.info("populated context {}", context); + Assert.assertTrue(String.format("failed to get variable : %s",path),context.containsKey(path)); + + } + + } diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/data/resource-assignment-input.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/data/resource-assignment-input.json new file mode 100644 index 000000000..d79c90682 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/resources/data/resource-assignment-input.json @@ -0,0 +1,10 @@ +{ + "intValue" : 1, + "floatValue" : 1.34, + "booleanValue" : true, + "stringValue" : "sample-String", + "timeValue" : "2018-09-29", + "arrayStringValue" : ["one", "two"], + "mapValue" : {"profile_name1":"profile_name1", + "profile_name2":"profile_name2"} +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java new file mode 100644 index 000000000..d3bf42302 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java @@ -0,0 +1,29 @@ +/* + * 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.ResourceDefinitionDefaultValidationService; +import org.springframework.stereotype.Service; + +@Service +public class ResourceDefinitionValidationService extends ResourceDefinitionDefaultValidationService { + + public ResourceDefinitionValidationService(BluePrintRepoService bluePrintRepoService) { + super(bluePrintRepoService); + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java index 85e701b41..ccf4ffcc7 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; 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.data.PropertyDefinition; @@ -43,16 +44,16 @@ public class ResourceDictionaryService { private ResourceDictionaryRepository resourceDictionaryRepository; - private ResourceDictionaryValidationService resourceDictionaryValidationService; + private ResourceDefinitionValidationService resourceDictionaryValidationService; /** * This is a DataDictionaryService, used to save and get the Resource Mapping stored in database * - * @param dataDictionaryRepository - * @param resourceDictionaryValidationService + * @param dataDictionaryRepository dataDictionaryRepository + * @param resourceDictionaryValidationService resourceDictionaryValidationService */ public ResourceDictionaryService(ResourceDictionaryRepository dataDictionaryRepository, - ResourceDictionaryValidationService resourceDictionaryValidationService) { + ResourceDefinitionValidationService resourceDictionaryValidationService) { this.resourceDictionaryRepository = dataDictionaryRepository; this.resourceDictionaryValidationService = resourceDictionaryValidationService; } @@ -60,58 +61,49 @@ public class ResourceDictionaryService { /** * This is a getDataDictionaryByName service * - * @param name + * @param name name * @return DataDictionary - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public ResourceDictionary getResourceDictionaryByName(String name) throws BluePrintException { - if (StringUtils.isNotBlank(name)) { - return resourceDictionaryRepository.findByName(name).get(); + Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing."); + Optional resourceDictionaryDb = resourceDictionaryRepository.findByName(name); + if (resourceDictionaryDb.isPresent()) { + return resourceDictionaryDb.get(); } else { - throw new BluePrintException("Resource Mapping Name Information is missing."); + throw new BluePrintException(String.format("couldn't get resource dictionary for name (%s)", name)); } } /** * This is a searchResourceDictionaryByNames service * - * @param names + * @param names names * @return List - * @throws BluePrintException */ - public List searchResourceDictionaryByNames(List names) - throws BluePrintException { - if (names != null && !names.isEmpty()) { - return resourceDictionaryRepository.findByNameIn(names); - } else { - throw new BluePrintException("No Search Information provide"); - } + public List searchResourceDictionaryByNames(List names) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(names), "No Search Information provide"); + return resourceDictionaryRepository.findByNameIn(names); } /** * This is a searchResourceDictionaryByTags service * - * @param tags + * @param tags tags * @return List - * @throws BluePrintException */ - public List searchResourceDictionaryByTags(String tags) throws BluePrintException { - if (StringUtils.isNotBlank(tags)) { - return resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags); - } else { - throw new BluePrintException("No Search Information provide"); - } + public List searchResourceDictionaryByTags(String tags) { + Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No search tag information provide"); + return resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags); } /** * This is a saveDataDictionary service * - * @param resourceDictionary + * @param resourceDictionary resourceDictionary * @return DataDictionary - * @throws BluePrintException */ - public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) - throws BluePrintException { + public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) { Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing"); Preconditions.checkArgument(StringUtils.isNotBlank(resourceDictionary.getDefinition()), "Resource Dictionary definition information is missing"); @@ -130,7 +122,7 @@ public class ResourceDictionaryService { PropertyDefinition propertyDefinition = resourceDefinition.getProperty(); resourceDictionary.setDescription(propertyDefinition.getDescription()); resourceDictionary.setDataType(propertyDefinition.getType()); - if(propertyDefinition.getEntrySchema() != null){ + if (propertyDefinition.getEntrySchema() != null) { resourceDictionary.setEntrySchema(propertyDefinition.getEntrySchema().getType()); } @@ -164,15 +156,10 @@ public class ResourceDictionaryService { /** * This is a deleteResourceDictionary service * - * @param name - * @throws BluePrintException + * @param name name */ - public void deleteResourceDictionary(String name) throws BluePrintException { - if (name != null) { - resourceDictionaryRepository.deleteByName(name); - } else { - throw new BluePrintException("Resource Mapping Id Information is missing."); - } - + public void deleteResourceDictionary(String name) { + Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing."); + resourceDictionaryRepository.deleteByName(name); } } 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 deleted file mode 100644 index 7de7fc4c3..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java +++ /dev/null @@ -1,31 +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.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); - } -} -- cgit 1.2.3-korg