Fix sonar issues :
[aai/sparky-be.git] / sparkybe-onap-service / src / main / java / org / onap / aai / sparky / viewinspect / sync / ViewInspectSyncController.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.sparky.viewinspect.sync;
22
23 import org.onap.aai.sparky.config.oxm.CrossEntityReferenceLookup;
24 import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
25 import org.onap.aai.sparky.config.oxm.SearchableEntityLookup;
26 import org.onap.aai.sparky.crossentityreference.sync.CrossEntityReferenceSynchronizer;
27 import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
28 import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig;
29 import org.onap.aai.sparky.search.SearchServiceAdapter;
30 import org.onap.aai.sparky.sync.ElasticSearchSchemaFactory;
31 import org.onap.aai.sparky.sync.IndexIntegrityValidator;
32 import org.onap.aai.sparky.sync.SyncControllerImpl;
33 import org.onap.aai.sparky.sync.SyncControllerRegistrar;
34 import org.onap.aai.sparky.sync.SyncControllerRegistry;
35 import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig;
36 import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
37 import org.onap.aai.sparky.sync.config.SyncControllerConfig;
38
39 public class ViewInspectSyncController extends SyncControllerImpl
40     implements SyncControllerRegistrar {
41
42   private SyncControllerRegistry syncControllerRegistry;
43   private ActiveInventoryAdapter aaiAdapter;
44   private SearchServiceAdapter searchServiceAdapter;
45   private ElasticSearchSchemaConfig schemaConfig;
46   private RestEndpointConfig endpointConfig;
47
48   public ViewInspectSyncController(SyncControllerConfig syncControllerConfig,
49       ActiveInventoryAdapter aaiAdapter, SearchServiceAdapter searchServiceAdapter,
50       ElasticSearchSchemaConfig schemaConfig, RestEndpointConfig endpointConfig,
51       NetworkStatisticsConfig aaiStatConfig, NetworkStatisticsConfig esStatConfig,
52       CrossEntityReferenceLookup crossEntityReferenceLookup, OxmEntityLookup oxmEntityLookup,
53       SearchableEntityLookup searchableEntityLookup,
54       ElasticSearchSchemaFactory elasticSearchSchemaFactory) throws Exception {
55     super(syncControllerConfig);
56
57
58     // final String controllerName = "View and Inspect Entity Synchronizer";
59
60      this.aaiAdapter = aaiAdapter; 
61      this.searchServiceAdapter = searchServiceAdapter; 
62      this.schemaConfig = schemaConfig; 
63      this.endpointConfig = endpointConfig; 
64     IndexIntegrityValidator indexValidator = new IndexIntegrityValidator(searchServiceAdapter, schemaConfig,
65         endpointConfig, elasticSearchSchemaFactory.getIndexSchema(schemaConfig));
66
67     registerIndexValidator(indexValidator);
68
69
70     ViewInspectEntitySynchronizer ses = new ViewInspectEntitySynchronizer(schemaConfig,
71         syncControllerConfig.getNumInternalSyncWorkers(),
72         syncControllerConfig.getNumSyncActiveInventoryWorkers(),
73         syncControllerConfig.getNumSyncElasticWorkers(), aaiStatConfig, esStatConfig,
74         oxmEntityLookup, searchableEntityLookup);
75     
76     ses.setAaiAdapter(aaiAdapter);
77     ses.setSearchServiceAdapter(searchServiceAdapter);
78
79     registerEntitySynchronizer(ses);
80
81     CrossEntityReferenceSynchronizer cers = new CrossEntityReferenceSynchronizer(schemaConfig,
82         syncControllerConfig.getNumInternalSyncWorkers(),
83         syncControllerConfig.getNumSyncActiveInventoryWorkers(),
84         syncControllerConfig.getNumSyncElasticWorkers(),aaiStatConfig,esStatConfig,
85         crossEntityReferenceLookup, oxmEntityLookup, searchableEntityLookup);
86
87     cers.setAaiAdapter(aaiAdapter);
88     cers.setSearchServiceAdapter(searchServiceAdapter);
89
90     registerEntitySynchronizer(cers);
91
92
93   }
94
95   public SyncControllerRegistry getSyncControllerRegistry() {
96     return syncControllerRegistry;
97   }
98
99   public void setSyncControllerRegistry(SyncControllerRegistry syncControllerRegistry) {
100     this.syncControllerRegistry = syncControllerRegistry;
101   }
102   
103   @Override
104   public void registerController() {
105     if ( syncControllerRegistry != null ) {
106       if ( syncControllerConfig.isEnabled()) { 
107         syncControllerRegistry.registerSyncController(this);
108       }
109     }
110
111   }
112 }