2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
3 * Modifications Copyright © 2018 IBM.
\r
5 * Licensed under the Apache License, Version 2.0 (the "License");
\r
6 * you may not use this file except in compliance with the License.
\r
7 * You may obtain a copy of the License at
\r
9 * http://www.apache.org/licenses/LICENSE-2.0
\r
11 * Unless required by applicable law or agreed to in writing, software
\r
12 * distributed under the License is distributed on an "AS IS" BASIS,
\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 * See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
18 package org.onap.ccsdk.apps.controllerblueprints.service.validator;
\r
20 import com.fasterxml.jackson.databind.JsonNode;
\r
21 import org.apache.commons.lang3.StringUtils;
\r
22 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
\r
23 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
\r
24 import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType;
\r
25 import org.onap.ccsdk.apps.controllerblueprints.core.data.CapabilityDefinition;
\r
26 import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType;
\r
27 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType;
\r
28 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
\r
29 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;
\r
31 import java.util.ArrayList;
\r
32 import java.util.List;
\r
35 * ModelTypeValidation.java Purpose: Provide Validation Service for Model Type ModelTypeValidation
\r
37 * @author Brinda Santh
\r
41 public class ModelTypeValidator {
\r
43 private ModelTypeValidator() {
\r
47 private static List<String> getValidModelDefinitionType() {
\r
48 List<String> validTypes = new ArrayList<>();
\r
49 validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);
\r
50 validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE);
\r
51 validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE);
\r
52 validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE);
\r
53 validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE);
\r
58 * This is a validateModelTypeDefinition
\r
60 * @param definitionType definitionType
\r
61 * @param definitionContent definitionContent
\r
63 * @throws BluePrintException BluePrintException
\r
65 public static boolean validateModelTypeDefinition(String definitionType, JsonNode definitionContent)
\r
66 throws BluePrintException {
\r
67 if (definitionContent != null) {
\r
68 if (BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE.equalsIgnoreCase(definitionType)) {
\r
69 DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class);
\r
70 if (dataType == null) {
\r
71 throw new BluePrintException(
\r
72 "Model type definition is not DataType valid content " + definitionContent);
\r
74 } else if (BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE.equalsIgnoreCase(definitionType)) {
\r
75 NodeType nodeType = JacksonUtils.readValue(definitionContent, NodeType.class);
\r
76 if (nodeType == null) {
\r
77 throw new BluePrintException(
\r
78 "Model type definition is not NodeType valid content " + definitionContent);
\r
80 } else if (BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE.equalsIgnoreCase(definitionType)) {
\r
81 ArtifactType artifactType = JacksonUtils.readValue(definitionContent, ArtifactType.class);
\r
82 if (artifactType == null) {
\r
83 throw new BluePrintException(
\r
84 "Model type definition is not ArtifactType valid content " + definitionContent);
\r
86 }else if (BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE.equalsIgnoreCase(definitionType)) {
\r
87 CapabilityDefinition capabilityDefinition =
\r
88 JacksonUtils.readValue(definitionContent, CapabilityDefinition.class);
\r
89 if (capabilityDefinition == null) {
\r
90 throw new BluePrintException(
\r
91 "Model type definition is not CapabilityDefinition valid content " + definitionContent);
\r
100 * This is a validateModelType method
\r
102 * @param modelType modelType
\r
104 * @throws BluePrintException BluePrintException
\r
106 public static boolean validateModelType(ModelType modelType) throws BluePrintException {
\r
107 if (modelType != null) {
\r
109 if (StringUtils.isBlank(modelType.getModelName())) {
\r
110 throw new BluePrintException("Model Name Information is missing.");
\r
113 if (StringUtils.isBlank(modelType.getDefinitionType())) {
\r
114 throw new BluePrintException("Model Root Type Information is missing.");
\r
116 if (StringUtils.isBlank(modelType.getDerivedFrom())) {
\r
117 throw new BluePrintException("Model Type Information is missing.");
\r
120 if (modelType.getDefinition() == null) {
\r
121 throw new BluePrintException("Model Definition Information is missing.");
\r
123 if (StringUtils.isBlank(modelType.getDescription())) {
\r
124 throw new BluePrintException("Model Description Information is missing.");
\r
127 if (StringUtils.isBlank(modelType.getVersion())) {
\r
128 throw new BluePrintException("Model Version Information is missing.");
\r
131 if (StringUtils.isBlank(modelType.getUpdatedBy())) {
\r
132 throw new BluePrintException("Model Updated By Information is missing.");
\r
135 List<String> validRootTypes = getValidModelDefinitionType();
\r
136 if (!validRootTypes.contains(modelType.getDefinitionType())) {
\r
137 throw new BluePrintException("Not Valid Model Root Type(" + modelType.getDefinitionType()
\r
138 + "), It should be " + validRootTypes);
\r
141 validateModelTypeDefinition(modelType.getDefinitionType(), modelType.getDefinition());
\r
144 throw new BluePrintException("Model Type Information is missing.");
\r