2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-18 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aai.validation.edges;
24 import org.onap.aai.nodes.NodeIngestor;
25 import org.onap.aai.setup.SchemaVersion;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.stereotype.Component;
29 import java.util.Collection;
30 import java.util.HashSet;
34 * Validates that the node types appearing in the edge rules are valid
35 * against the ingested OXM.
37 * (This is why the node validation has to be run before the edge validation)
40 public class NodeTypesValidationModule {
41 private NodeIngestor ni;
44 public NodeTypesValidationModule(NodeIngestor ni) {
49 * Validate that every node type in the given set is defined in
50 * the OXM for the given version
52 * @param nodeTypePairs - all the node types in
53 * the edge rules for the given version being validated
54 * @param v - the version being validated
55 * @return empty string if all types are present in the given version's ingested OXM, else
56 * appropriate error message
58 public String validate(Collection<String> nodeTypePairs, SchemaVersion v) {
60 Set<String> nodeTypes = new HashSet<>();
61 for (String pair : nodeTypePairs) {
62 String[] types = pair.split("\\|");
64 for (String type : types) {
65 if (!"".equals(type)) {
72 Set<String> badTypes = new HashSet<>();
73 for (String type : nodeTypes) {
74 if (!ni.hasNodeType(type, v)) {
79 if (badTypes.isEmpty()) {
82 StringBuilder errorBase = new StringBuilder().append("Invalid node type(s) found: ");
83 for (String bt : badTypes) {
84 errorBase.append(bt).append(" ");
86 return errorBase.toString();