AAI-1523 Batch reformat aai-schema-ingest
[aai/aai-common.git] / aai-schema-ingest / src / main / java / org / onap / aai / validation / DefaultVersionValidationModule.java
1 /** 
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 /**
22  * 
23  */
24
25 package org.onap.aai.validation;
26
27 import java.util.List;
28 import java.util.Map;
29
30 import org.onap.aai.setup.ConfigTranslator;
31 import org.onap.aai.setup.SchemaVersion;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.stereotype.Component;
34
35 /**
36  * By default, A&AI must have schema files for all current
37  * supported Versions in the Version enum
38  *
39  */
40 @Component
41 public class DefaultVersionValidationModule implements VersionValidationModule {
42
43     private ConfigTranslator config;
44
45     @Autowired
46     public DefaultVersionValidationModule(ConfigTranslator config) {
47
48         this.config = config;
49     }
50
51     /*
52      * (non-Javadoc)
53      * 
54      * @see org.onap.aai.validation.VersionValidationModule#validate(org.onap.aai.setup.ConfigTranslator)
55      */
56     @Override
57     public String validate() {
58         Map<SchemaVersion, List<String>> nodeConfig = config.getNodeFiles();
59         Map<SchemaVersion, List<String>> edgeConfig = config.getEdgeFiles();
60
61         StringBuilder missingVers = new StringBuilder().append("Missing schema for the following versions: ");
62         boolean isMissing = false;
63         for (SchemaVersion v : config.getSchemaVersions().getVersions()) {
64             if (nodeConfig.get(v) == null) {
65                 isMissing = true;
66                 missingVers.append(v.toString()).append(" has no OXM configured. ");
67             }
68             if (edgeConfig.get(v) == null) {
69                 isMissing = true;
70                 missingVers.append(v.toString()).append(" has no edge rules configured. ");
71             }
72         }
73
74         if (isMissing) {
75             return missingVers.toString();
76         } else {
77             return "";
78         }
79     }
80
81 }