added schema validation tools
[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 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22
23 /**
24  * 
25  */
26 package org.onap.aai.validation;
27
28 import java.util.List;
29 import java.util.Map;
30
31 import org.onap.aai.setup.ConfigTranslator;
32 import org.onap.aai.setup.Version;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
35
36 /**
37  * By default, A&AI must have schema files for all current
38  * supported Versions in the Version enum
39  *
40  */
41 @Component
42 public class DefaultVersionValidationModule implements VersionValidationModule {
43         private ConfigTranslator config;
44         
45         @Autowired
46         public DefaultVersionValidationModule(ConfigTranslator config) {
47                 this.config = config;
48         }
49
50         /* (non-Javadoc)
51          * @see org.onap.aai.validation.VersionValidationModule#validate(org.onap.aai.setup.ConfigTranslator)
52          */
53         @Override
54         public String validate() {
55                 Map<Version, List<String>> nodeConfig = config.getNodeFiles();
56                 Map<Version, List<String>> edgeConfig = config.getEdgeFiles();
57                 
58                 StringBuilder missingVers = new StringBuilder().append("Missing schema for the following versions: ");
59                 boolean isMissing = false;
60                 for (Version v : Version.values()) {
61                         if (nodeConfig.get(v) == null) {
62                                 isMissing = true;
63                                 missingVers.append(v.toString()).append(" has no OXM configured. ");
64                         }
65                         if (edgeConfig.get(v) == null) {
66                                 isMissing = true;
67                                 missingVers.append(v.toString()).append(" has no edge rules configured. ");
68                         }
69                 }
70                 
71                 if (isMissing) {
72                         return missingVers.toString();
73                 } else {
74                         return "";
75                 }
76         }
77
78 }