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=========================================================
24 package org.onap.aai.validation.edges;
26 import java.util.EnumSet;
28 import java.util.Map.Entry;
31 import org.onap.aai.edges.enums.EdgeField;
34 * Default core A&AI edge field validation
35 * All fields in EdgeField enum are required EXCEPT description
38 public class DefaultEdgeFieldsValidationModule implements EdgeFieldsValidationModule {
41 * @see org.onap.aai.edges.EdgeFieldsValidator#verifyFields(java.util.Map)
44 public String verifyFields(Map<String, String> rule) {
45 EnumSet<EdgeField> missingFields = EnumSet.complementOf(EnumSet.allOf(EdgeField.class));
47 for (EdgeField f : EdgeField.values()) {
48 if (!rule.containsKey(f.toString()) && (f != EdgeField.DESCRIPTION) && (f != EdgeField.PRIVATE)) { //description is optional
53 StringBuilder errorMsg = new StringBuilder();
54 if (!missingFields.isEmpty()) {
55 errorMsg.append("Rule ").append(ruleToString(rule)).append(" missing required fields: ");
56 for (EdgeField mf : missingFields) {
57 errorMsg.append(mf.toString()).append(" ");
61 return errorMsg.toString();
64 private String ruleToString(Map<String, String> rule) {
65 StringBuilder sb = new StringBuilder();
66 for (Entry<String, String> fields : rule.entrySet()) {
67 sb.append(fields.getKey()).append(":").append(fields.getValue()).append(" ");