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 {
35 * This is a validateModelTypeDefinition
37 * @param definitionType definitionType
38 * @param definitionContent definitionContent
41 fun validateModelTypeDefinition(definitionType: String, definitionContent: JsonNode): Boolean {
43 when (definitionType) {
44 BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE -> {
45 JacksonUtils.readValue(definitionContent, DataType::class.java)
46 ?: throw BluePrintException("Model type definition is not DataType valid content $definitionContent")
48 BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE -> {
49 JacksonUtils.readValue(definitionContent, NodeType::class.java)
50 ?: throw BluePrintException("Model type definition is not NodeType valid content $definitionContent")
52 BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE -> {
53 JacksonUtils.readValue(definitionContent, ArtifactType::class.java)
54 ?: throw BluePrintException("Model type definition is not ArtifactType valid content $definitionContent")
56 BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE -> {
57 JacksonUtils.readValue(definitionContent, CapabilityDefinition::class.java)
58 ?: throw BluePrintException("Model type definition is not CapabilityDefinition valid content $definitionContent")
60 BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE -> {
61 JacksonUtils.readValue(definitionContent, RelationshipType::class.java)
62 ?: throw BluePrintException("Model type definition is not RelationshipType valid content $definitionContent")
69 * This is a validateModelType method
71 * @param modelType modelType
74 fun validateModelType(modelType: ModelType?): Boolean {
75 checkNotNull(modelType) { "Model Type Information is missing." }
77 val validRootTypes = BluePrintTypes.validModelTypes()
79 check(validRootTypes.contains(modelType.definitionType)) {
80 "Not Valid Model Root Type(${modelType.definitionType}), It should be $validRootTypes"
83 validateModelTypeDefinition(modelType.definitionType, modelType.definition)