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