Update schema service to fail to start
[aai/aai-common.git] / aai-schema-ingest / src / main / java / org / onap / aai / setup / SchemaServiceVersions.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.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
23 import org.springframework.context.annotation.PropertySource;
24 import org.springframework.stereotype.Component;
25 import javax.annotation.PostConstruct;
26 import java.util.List;
27 import java.util.stream.Collectors;
28
29 @Component("schemaServiceVersions")
30 @ConditionalOnExpression("'${schema.translator.list}'.contains('schema-service')")
31 @PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true)
32 @PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true)
33 public class SchemaServiceVersions extends SchemaVersions {
34     private List<String> versions;
35     private String edgeVersion;
36     private String defaultVersion;
37     private String depthVersion;
38     private String appRootVersion;
39     private String relatedLinkVersion;
40     private String namespaceChangeVersion;
41
42     public List<String> getVersionsAll() {
43         return versions;
44     }
45
46     public void setVersions(List<String> versions) {
47         this.versions = versions;
48     }
49
50     @PostConstruct
51     public void initializeFromSchemaService() throws ExceptionInInitializerError{
52
53         versionsValue = versions.stream().map(SchemaVersion::new).collect(Collectors.toList());
54         edgeLabelVersionValue = new SchemaVersion(edgeVersion);
55         defaultVersionValue = new SchemaVersion(defaultVersion);
56         depthVersionValue = new SchemaVersion(depthVersion);
57         appRootVersionValue = new SchemaVersion(appRootVersion);
58         relatedLinkVersionValue = new SchemaVersion(relatedLinkVersion);
59         namespaceChangeVersionValue = new SchemaVersion(namespaceChangeVersion);
60
61         this.validate();
62     }
63
64     /*
65      * TODO Change Method names
66      */
67     public void initializeFromSchemaConfig(SchemaConfigVersions schemaConfigVersion) throws ExceptionInInitializerError{
68
69         versions = schemaConfigVersion.getApiVersions();
70         appRootVersion = schemaConfigVersion.getAppRootStartVersion();
71         defaultVersion = schemaConfigVersion.getDefaultApiVersion();
72         depthVersion = schemaConfigVersion.getDepthStartVersion();
73         edgeVersion = schemaConfigVersion.getEdgeLabelStartVersion();
74         namespaceChangeVersion = schemaConfigVersion.getNamespaceChangeStartVersion();
75         relatedLinkVersion = schemaConfigVersion.getRelatedLinkStartVersion();
76         this.initializeFromSchemaService();
77     }
78
79 }