Update schema service to fail to start
[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.setup.ConfigTranslator;
28 import org.onap.aai.setup.SchemaLocationsBean;
29 import org.onap.aai.setup.SchemaConfigVersions;
30 import org.onap.aai.serialization.db.EdgeSerializer;
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     //TODO : Inject this directly into nodeIngestor
46     @Autowired(required = false)
47     NodesConfiguration nodesConfiguration;
48
49     @Autowired(required = false)
50     EdgesConfiguration edgesConfiguration;
51
52     @Bean
53     public EdgeIngestor edgeIngestor(){
54         return edgesConfiguration.edgeIngestor();
55     }
56
57     @Bean
58     public EdgeSerializer edgeSerializer(EdgeIngestor edgeIngestor){
59         return new EdgeSerializer(edgeIngestor);
60     }
61
62     @Bean(name = "nodeIngestor")
63     public NodeIngestor nodeIngestor() {
64         return nodesConfiguration.nodeIngestor();
65     }
66
67
68     @Bean(name = "configTranslator")
69     @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true)
70     public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean, SchemaConfigVersions schemaVersions) {
71         return new AAIConfigTranslator(schemaLocationsBean, schemaVersions);
72     }
73
74     @Bean
75     @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true)
76     public SchemaErrorStrategy schemaErrorStrategy(){
77         return new CheckEverythingStrategy();
78         }
79
80         @Bean
81         @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true)
82         public DuplicateNodeDefinitionValidationModule duplicateNodeDefinitionValidationModule(){
83         return new DefaultDuplicateNodeDefinitionValidationModule();
84         }
85
86         @Bean
87         @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true)
88         public NodeValidator nodeValidator(
89                         ConfigTranslator configTranslator,
90                         SchemaErrorStrategy schemaErrorStrategy,
91                         DuplicateNodeDefinitionValidationModule duplicateNodeDefinitionValidationModule
92         ){
93         return new NodeValidator(configTranslator, schemaErrorStrategy, duplicateNodeDefinitionValidationModule);
94         }
95 }