[AAI] Fix doc config files
[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-18 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.setup;
22
23 import java.util.List;
24 import java.util.stream.Collectors;
25
26 import javax.annotation.PostConstruct;
27
28 import org.onap.aai.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 @PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true)
34 @PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true)
35 public class SchemaVersions {
36
37     protected List<SchemaVersion> versionsValue;
38     protected SchemaVersion edgeLabelVersionValue;
39     protected SchemaVersion defaultVersionValue;
40     protected SchemaVersion depthVersionValue;
41     protected SchemaVersion appRootVersionValue;
42     protected SchemaVersion relatedLinkVersionValue;
43     protected SchemaVersion namespaceChangeVersionValue;
44
45     protected void validate() {
46         String errorMessage = "Invalid, edge label version is not in the api versions list"
47                 + ", please check schema.version.list and ensure that the"
48                 + " schema.version.edge.label.start is in that list";
49         if (!versionsValue.contains(edgeLabelVersionValue)) {
50             throw new AAISchemaValidationException(errorMessage);
51         }
52
53         if (!versionsValue.contains(defaultVersionValue)) {
54             throw new AAISchemaValidationException(errorMessage);
55         }
56
57         if (!versionsValue.contains(depthVersionValue)) {
58             throw new AAISchemaValidationException(errorMessage);
59         }
60
61         if (!versionsValue.contains(appRootVersionValue)) {
62             throw new AAISchemaValidationException(errorMessage);
63         }
64
65         if (!versionsValue.contains(relatedLinkVersionValue)) {
66             throw new AAISchemaValidationException(errorMessage);
67         }
68
69         if (!versionsValue.contains(namespaceChangeVersionValue)) {
70             throw new AAISchemaValidationException(errorMessage);
71         }
72     }
73
74     public List<SchemaVersion> getVersions() {
75         return versionsValue;
76     }
77
78     public SchemaVersion getEdgeLabelVersion() {
79         return edgeLabelVersionValue;
80     }
81
82     public SchemaVersion getDefaultVersion() {
83         return defaultVersionValue;
84     }
85
86     public SchemaVersion getDepthVersion() {
87         return depthVersionValue;
88     }
89
90     public SchemaVersion getAppRootVersion() {
91         return appRootVersionValue;
92     }
93
94     public SchemaVersion getRelatedLinkVersion() {
95         return relatedLinkVersionValue;
96     }
97
98     public SchemaVersion getNamespaceChangeVersion() {
99         return namespaceChangeVersionValue;
100     }
101
102     public void setNamespaceChangeVersion(SchemaVersion namespaceChangeVersion) {
103         this.namespaceChangeVersionValue = namespaceChangeVersion;
104     }
105
106 }