Update schema ingest library call schema service
[aai/aai-common.git] / aai-schema-ingest / src / main / java / org / onap / aai / setup / SchemaLocationsBean.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 org.springframework.beans.factory.annotation.Value;
24 import org.springframework.context.annotation.Bean;
25 import org.springframework.context.annotation.Configuration;
26 import org.springframework.context.annotation.PropertySource;
27 import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
28
29 import java.util.List;
30
31 @Configuration
32 @PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound=true)
33 @PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound=true)
34 public class SchemaLocationsBean {
35         /*
36          * Per Spring documentation, the last PropertySource that works will
37          * be applied. Here, schema.ingest.file will be an environment variable
38          * set on install that tells Spring where to look for the schema
39          * ingest properties file (and the actual filename), but the former
40          * PropertySource gives the default of looking on the classpath for
41          * schema-ingest.properties in case that second one doesn't work.
42          * 
43          * The schema-ingest.properties file (or its equivalent if you choose
44          * to name it otherwise) must contain the entries the below @Value
45          * annotations are looking for.
46          */
47         
48         @Value("${schema.configuration.location}")
49         private String schemaConfigLoc;
50         
51         @Value("${schema.nodes.location}")
52         private String nodeDirectory;
53         
54         @Value("${schema.edges.location}")
55         private String edgeDirectory;
56
57         @Value("${schema.nodes.inclusion.list:}#{T(java.util.Arrays).asList(\".*oxm(.*).xml\")}")
58         private List<String> nodesInclusionPattern;
59
60         @Value("${schema.nodes.exclusion.list:}#{T(java.util.Collections).emptyList()}")
61         private List<String> nodesExclusionPattern;
62
63         @Value("${schema.edges.inclusion.list:}#{T(java.util.Arrays).asList(\"DbEdgeRules_.*.json\")}")
64         private List<String> edgesInclusionPattern;
65
66         @Value("${schema.edges.exclusion.list:}#{T(java.util.Collections).emptyList()}")
67         private List<String> edgesExclusionPattern;
68
69         /**
70          * @return the file name/location with the list of schema files to be ingested
71          */
72         public String getSchemaConfigLocation() {
73                 return schemaConfigLoc;
74         }
75         
76         /**
77          * Sets the name/location of the file with the list of schema files to ingest
78          * 
79          * @param schemaConfigLoc - the file name/location
80          */
81         public void setSchemaConfigLocation(String schemaConfigLoc) {
82                 this.schemaConfigLoc = schemaConfigLoc;
83         }
84         
85         /**
86          * @return the location of the OXM files
87          */
88         public String getNodeDirectory() {
89                 return nodeDirectory;
90         }
91         
92         /**
93          * Sets the location of the OXM files
94          * 
95          * @param nodeDirectory - the location of the OXM files
96          */
97         public void setNodeDirectory(String nodeDirectory) {
98                 this.nodeDirectory = nodeDirectory;
99         }
100         
101         /**
102          * @return the location of the edge rule json files
103          */
104         public String getEdgeDirectory() {
105                 return edgeDirectory;
106         }
107         
108         /**
109          * Sets the location of the edge rule json files
110          * 
111          * @param edgeDirectory - the location of the edge rule files
112          */
113         public void setEdgeDirectory(String edgeDirectory) {
114                 this.edgeDirectory = edgeDirectory;
115         }
116
117         public List<String> getNodesExclusionPattern(){
118                 return this.nodesExclusionPattern;
119         }
120
121         public List<String> getNodesInclusionPattern(){
122                 return this.nodesInclusionPattern;
123         }
124
125         public List<String> getEdgesExclusionPattern(){
126                 return this.edgesExclusionPattern;
127         }
128
129         public List<String> getEdgesInclusionPattern(){
130                 return this.edgesInclusionPattern;
131         }
132
133         //this allows the code to actually read the value from the config file
134         //without this those strings get set to literally "${edgeDir}" etc
135         @Bean
136         public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
137                 return new PropertySourcesPlaceholderConfigurer();
138         }
139 }