2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.aai.setup;
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;
27 import javax.annotation.PostConstruct;
28 import javax.xml.validation.Schema;
29 import java.util.List;
30 import java.util.stream.Collectors;
33 @PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true)
34 @PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true)
35 public class SchemaVersions {
37 @Value("#{'${schema.version.list}'.split(',')}")
38 private List<String> apiVersions;
40 @Value("${schema.version.api.default}")
41 private String defaultApiVersion;
43 @Value("${schema.version.edge.label.start}")
44 private String edgeLabelStartVersion;
46 @Value("${schema.version.depth.start}")
47 private String depthStartVersion;
49 @Value("${schema.version.app.root.start}")
50 private String appRootStartVersion;
52 @Value("${schema.version.related.link.start}")
53 private String relatedLinkStartVersion;
55 @Value("${schema.version.namespace.change.start}")
56 private String namespaceChangeStartVersion;
58 private List<SchemaVersion> versions;
60 private SchemaVersion edgeLabelVersion;
61 private SchemaVersion defaultVersion;
62 private SchemaVersion depthVersion;
63 private SchemaVersion appRootVersion;
64 private SchemaVersion relatedLinkVersion;
65 private SchemaVersion namespaceChangeVersion;
68 public void initialize() {
69 versions = apiVersions.stream().map(SchemaVersion::new).collect(Collectors.toList());
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);
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"
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"
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"
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"
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"
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"
127 public List<SchemaVersion> getVersions() {
131 public SchemaVersion getEdgeLabelVersion() {
132 return edgeLabelVersion;
135 public SchemaVersion getDefaultVersion() {
136 return defaultVersion;
139 public SchemaVersion getDepthVersion() {
143 public SchemaVersion getAppRootVersion(){
144 return appRootVersion;
147 public SchemaVersion getRelatedLinkVersion(){
148 return relatedLinkVersion;
151 public SchemaVersion getNamespaceChangeVersion() {
152 return namespaceChangeVersion;
155 public void setNamespaceChangeVersion(SchemaVersion namespaceChangeVersion) {
156 this.namespaceChangeVersion = namespaceChangeVersion;