2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils
19 import com.fasterxml.jackson.databind.JsonNode
20 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType
21 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
22 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
23 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactType
25 import org.onap.ccsdk.cds.controllerblueprints.core.data.CapabilityDefinition
26 import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
27 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
28 import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType
29 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
31 class ModelTypeValidator {
34 * This is a validateModelTypeDefinition
36 * @param definitionType definitionType
37 * @param definitionContent definitionContent
40 fun validateModelTypeDefinition(definitionType: String, definitionContent: JsonNode): Boolean {
42 when (definitionType) {
43 BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE -> {
44 JacksonUtils.readValue(definitionContent, DataType::class.java)
45 ?: throw BluePrintException("Model type definition is not DataType valid content $definitionContent")
47 BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE -> {
48 JacksonUtils.readValue(definitionContent, NodeType::class.java)
49 ?: throw BluePrintException("Model type definition is not NodeType valid content $definitionContent")
51 BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE -> {
52 JacksonUtils.readValue(definitionContent, ArtifactType::class.java)
53 ?: throw BluePrintException("Model type definition is not ArtifactType valid content $definitionContent")
55 BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE -> {
56 JacksonUtils.readValue(definitionContent, CapabilityDefinition::class.java)
57 ?: throw BluePrintException("Model type definition is not CapabilityDefinition valid content $definitionContent")
59 BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE -> {
60 JacksonUtils.readValue(definitionContent, RelationshipType::class.java)
61 ?: throw BluePrintException("Model type definition is not RelationshipType valid content $definitionContent")
68 * This is a validateModelType method
70 * @param modelType modelType
73 fun validateModelType(modelType: ModelType?): Boolean {
74 checkNotNull(modelType) { "Model Type Information is missing." }
76 val validRootTypes = BluePrintTypes.validModelTypes()
78 check(validRootTypes.contains(modelType.definitionType)) {
79 "Not Valid Model Root Type(${modelType.definitionType}), It should be $validRootTypes"
82 validateModelTypeDefinition(modelType.definitionType, modelType.definition)