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