AAI-1523 checkstyle warnings for aai-core auth
[aai/aai-common.git] / aai-schema-ingest / src / main / java / org / onap / aai / setup / SchemaVersions.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 package org.onap.aai.setup;
21
22 import org.onap.aai.validation.AAISchemaValidationException;
23 import org.springframework.beans.factory.annotation.Value;
24 import org.springframework.context.annotation.PropertySource;
25 import org.springframework.stereotype.Component;
26
27 import javax.annotation.PostConstruct;
28 import javax.xml.validation.Schema;
29 import java.util.List;
30 import java.util.stream.Collectors;
31
32 @Component
33 @PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true)
34 @PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true)
35 public class SchemaVersions {
36
37     @Value("#{'${schema.version.list}'.split(',')}")
38     private List<String> apiVersions;
39
40     @Value("${schema.version.api.default}")
41     private String defaultApiVersion;
42
43     @Value("${schema.version.edge.label.start}")
44     private String edgeLabelStartVersion;
45
46     @Value("${schema.version.depth.start}")
47     private String depthStartVersion;
48
49     @Value("${schema.version.app.root.start}")
50     private String appRootStartVersion;
51
52     @Value("${schema.version.related.link.start}")
53     private String relatedLinkStartVersion;
54
55     @Value("${schema.version.namespace.change.start}")
56     private String namespaceChangeStartVersion;
57
58     private List<SchemaVersion> versions;
59
60     private SchemaVersion edgeLabelVersion;
61     private SchemaVersion defaultVersion;
62     private SchemaVersion depthVersion;
63     private SchemaVersion appRootVersion;
64     private SchemaVersion relatedLinkVersion;
65     private SchemaVersion namespaceChangeVersion;
66
67     @PostConstruct
68     public void initialize() {
69         versions = apiVersions.stream().map(SchemaVersion::new).collect(Collectors.toList());
70
71         edgeLabelVersion       = new SchemaVersion(edgeLabelStartVersion);
72         defaultVersion         = new SchemaVersion(defaultApiVersion);
73         depthVersion           = new SchemaVersion(depthStartVersion);
74         appRootVersion         = new SchemaVersion(appRootStartVersion);
75         relatedLinkVersion     = new SchemaVersion(relatedLinkStartVersion);
76         namespaceChangeVersion = new SchemaVersion(namespaceChangeStartVersion);
77
78         if (!versions.contains(edgeLabelVersion)) {
79             throw new AAISchemaValidationException(
80                     "Invalid, edge label version is not in the api versions list"
81                     + ", please check schema.version.list and ensure that the"
82                     + " schema.version.edge.label.start is in that list"
83             );
84         }
85
86         if (!versions.contains(defaultVersion)) {
87             throw new AAISchemaValidationException(
88                     "Invalid, default version is not in the api versions list"
89                             + ", please check schema.version.list and ensure that the"
90                             + " schema.version.api.default is in that list"
91             );
92         }
93
94         if (!versions.contains(depthVersion)) {
95             throw new AAISchemaValidationException(
96                     "Invalid, depth version is not in the api versions list"
97                             + ", please check schema.version.list and ensure that the"
98                             + " schema.version.depth.start is in that list"
99             );
100         }
101
102         if(!versions.contains(appRootVersion)){
103             throw new AAISchemaValidationException(
104                     "Invalid, app root version is not in the api versions list"
105                             + ", please check schema.version.list and ensure that the"
106                             + " schema.version.app.root.start is in that list"
107             );
108         }
109
110         if(!versions.contains(relatedLinkVersion)){
111             throw new AAISchemaValidationException(
112                     "Invalid, related link version is not in the api versions list"
113                             + ", please check schema.version.list and ensure that the"
114                             + " schema.version.related.link.start is in that list"
115             );
116         }
117
118         if(!versions.contains(namespaceChangeVersion)){
119             throw new AAISchemaValidationException(
120                     "Invalid, namespace change start version is not in the api versions list"
121                             + ", please check schema.version.list and ensure that the"
122                             + " schema.version.related.link.start is in that list"
123             );
124         }
125     }
126
127     public List<SchemaVersion> getVersions() {
128         return versions;
129     }
130
131     public SchemaVersion getEdgeLabelVersion() {
132         return edgeLabelVersion;
133     }
134
135     public SchemaVersion getDefaultVersion() {
136         return defaultVersion;
137     }
138
139     public SchemaVersion getDepthVersion() {
140         return depthVersion;
141     }
142
143     public SchemaVersion getAppRootVersion(){
144         return appRootVersion;
145     }
146
147     public SchemaVersion getRelatedLinkVersion(){
148         return relatedLinkVersion;
149     }
150
151     public SchemaVersion getNamespaceChangeVersion() {
152         return namespaceChangeVersion;
153     }
154
155     public void setNamespaceChangeVersion(SchemaVersion namespaceChangeVersion) {
156         this.namespaceChangeVersion = namespaceChangeVersion;
157     }
158
159 }