885790cef41b5913ffab296706f519c06ab30fff
[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
23 package org.onap.aai.config;
24
25 import org.onap.aai.edges.EdgeIngestor;
26 import org.onap.aai.nodes.NodeIngestor;
27 import org.onap.aai.serialization.db.EdgeSerializer;
28 import org.onap.aai.setup.AAIConfigTranslator;
29 import org.onap.aai.setup.ConfigTranslator;
30 import org.onap.aai.setup.SchemaConfigVersions;
31 import org.onap.aai.setup.SchemaLocationsBean;
32 import org.onap.aai.validation.CheckEverythingStrategy;
33 import org.onap.aai.validation.SchemaErrorStrategy;
34 import org.onap.aai.validation.nodes.DefaultDuplicateNodeDefinitionValidationModule;
35 import org.onap.aai.validation.nodes.DuplicateNodeDefinitionValidationModule;
36 import org.onap.aai.validation.nodes.NodeValidator;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
39 import org.springframework.context.annotation.*;
40
41 @Import({NodesConfiguration.class, EdgesConfiguration.class})
42 @Configuration
43 @PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true)
44 @PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true)
45 public class SchemaConfiguration {
46
47     // TODO : Inject this directly into nodeIngestor
48     @Autowired(required = false)
49     NodesConfiguration nodesConfiguration;
50
51     @Autowired(required = false)
52     EdgesConfiguration edgesConfiguration;
53
54     @Bean
55     public EdgeIngestor edgeIngestor() {
56         return edgesConfiguration.edgeIngestor();
57     }
58
59     @Bean
60     public EdgeSerializer edgeSerializer(EdgeIngestor edgeIngestor) {
61         return new EdgeSerializer(edgeIngestor);
62     }
63
64     @Bean(name = "nodeIngestor")
65     public NodeIngestor nodeIngestor() {
66         return nodesConfiguration.nodeIngestor();
67     }
68
69     @Bean(name = "configTranslator")
70     @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true)
71     public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean,
72             SchemaConfigVersions schemaVersions) {
73         return new AAIConfigTranslator(schemaLocationsBean, schemaVersions);
74     }
75
76     @Bean
77     @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true)
78     public SchemaErrorStrategy schemaErrorStrategy() {
79         return new CheckEverythingStrategy();
80     }
81
82     @Bean
83     @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true)
84     public DuplicateNodeDefinitionValidationModule duplicateNodeDefinitionValidationModule() {
85         return new DefaultDuplicateNodeDefinitionValidationModule();
86     }
87
88     @Bean
89     @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true)
90     public NodeValidator nodeValidator(ConfigTranslator configTranslator, SchemaErrorStrategy schemaErrorStrategy,
91             DuplicateNodeDefinitionValidationModule duplicateNodeDefinitionValidationModule) {
92         return new NodeValidator(configTranslator, schemaErrorStrategy, duplicateNodeDefinitionValidationModule);
93     }
94 }