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