Update aai-core use new schema ingest library
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / config / SchemaConfiguration.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright © 2018 IBM.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *    http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22 package org.onap.aai.config;
23
24 import org.onap.aai.edges.EdgeIngestor;
25 import org.onap.aai.nodes.NodeIngestor;
26 import org.onap.aai.setup.AAIConfigTranslator;
27 import org.onap.aai.serialization.db.EdgeSerializer;
28 import org.onap.aai.setup.ConfigTranslator;
29 import org.onap.aai.setup.SchemaLocationsBean;
30 import org.onap.aai.setup.SchemaVersions;
31 import org.onap.aai.validation.CheckEverythingStrategy;
32 import org.onap.aai.validation.SchemaErrorStrategy;
33 import org.onap.aai.validation.nodes.DefaultDuplicateNodeDefinitionValidationModule;
34 import org.onap.aai.validation.nodes.DuplicateNodeDefinitionValidationModule;
35 import org.onap.aai.validation.nodes.NodeValidator;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
38 import org.springframework.context.annotation.*;
39 @Import({NodesConfiguration.class, EdgesConfiguration.class})
40 @Configuration
41 @PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true)
42 @PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true)
43 public class SchemaConfiguration {
44
45     @Autowired(required = false)
46     NodesConfiguration nodesConfiguration;
47
48     @Autowired(required = false)
49     EdgesConfiguration edgesConfiguration;
50
51     @Bean
52     public EdgeIngestor edgeIngestor(){
53         return edgesConfiguration.edgeIngestor();
54     }
55
56     @Bean
57     public EdgeSerializer edgeSerializer(EdgeIngestor edgeIngestor){
58         return new EdgeSerializer(edgeIngestor);
59     }
60
61     @Bean(name = "nodeIngestor")
62     public NodeIngestor nodeIngestor() {
63         return nodesConfiguration.nodeIngestor();
64     }
65
66
67     @Bean(name = "configTranslator")
68     @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true)
69     public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean, SchemaVersions schemaVersions) {
70         return new AAIConfigTranslator(schemaLocationsBean, schemaVersions);
71     }
72
73     @Bean
74     @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true)
75     public SchemaErrorStrategy schemaErrorStrategy(){
76         return new CheckEverythingStrategy();
77         }
78
79         @Bean
80         @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true)
81         public DuplicateNodeDefinitionValidationModule duplicateNodeDefinitionValidationModule(){
82         return new DefaultDuplicateNodeDefinitionValidationModule();
83         }
84
85         @Bean
86         @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true)
87         public NodeValidator nodeValidator(
88                         ConfigTranslator configTranslator,
89                         SchemaErrorStrategy schemaErrorStrategy,
90                         DuplicateNodeDefinitionValidationModule duplicateNodeDefinitionValidationModule
91         ){
92         return new NodeValidator(configTranslator, schemaErrorStrategy, duplicateNodeDefinitionValidationModule);
93         }
94 }