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=========================================================
21 package org.onap.aai.schemaservice.nodeschema;
23 import java.util.List;
24 import java.util.stream.Collectors;
26 import javax.annotation.PostConstruct;
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;
34 @PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true)
35 @PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true)
36 public class SchemaVersions {
38 @Value("#{'${schema.version.list}'.split(',')}")
39 private List<String> apiVersions;
41 @Value("${schema.version.api.default}")
42 private String defaultApiVersion;
44 @Value("${schema.version.edge.label.start}")
45 private String edgeLabelStartVersion;
47 @Value("${schema.version.depth.start}")
48 private String depthStartVersion;
50 @Value("${schema.version.app.root.start}")
51 private String appRootStartVersion;
53 @Value("${schema.version.related.link.start}")
54 private String relatedLinkStartVersion;
56 @Value("${schema.version.namespace.change.start}")
57 private String namespaceChangeStartVersion;
59 private List<SchemaVersion> versions;
61 private SchemaVersion edgeLabelVersion;
62 private SchemaVersion defaultVersion;
63 private SchemaVersion depthVersion;
64 private SchemaVersion appRootVersion;
65 private SchemaVersion relatedLinkVersion;
66 private SchemaVersion namespaceChangeVersion;
69 public void initialize() {
70 versions = apiVersions.stream().map(SchemaVersion::new).collect(Collectors.toList());
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);
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");
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");
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");
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");
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");
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");
122 public List<SchemaVersion> getVersions() {
126 public SchemaVersion getEdgeLabelVersion() {
127 return edgeLabelVersion;
130 public SchemaVersion getDefaultVersion() {
131 return defaultVersion;
134 public SchemaVersion getDepthVersion() {
138 public SchemaVersion getAppRootVersion() {
139 return appRootVersion;
142 public SchemaVersion getRelatedLinkVersion() {
143 return relatedLinkVersion;
146 public SchemaVersion getNamespaceChangeVersion() {
147 return namespaceChangeVersion;
150 public void setNamespaceChangeVersion(SchemaVersion namespaceChangeVersion) {
151 this.namespaceChangeVersion = namespaceChangeVersion;