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