8b6e54af9eccbd33dea1b0d6260e65e96343d6cd
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.ccsdk.apps.controllerblueprints.service.load
18
19 import com.att.eelf.configuration.EELFManager
20 import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
21 import org.springframework.boot.context.event.ApplicationReadyEvent
22 import org.springframework.context.event.EventListener
23 import org.springframework.stereotype.Service
24
25 @Service
26 open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration,
27                                         private val modelTypeLoadService: ModelTypeLoadService,
28                                         private val resourceDictionaryLoadService: ResourceDictionaryLoadService,
29                                         private val bluePrintCatalogLoadService: BluePrintCatalogLoadService) {
30
31     private val log = EELFManager.getInstance().getLogger(BluePrintDatabaseLoadService::class.java)
32
33
34     @EventListener(ApplicationReadyEvent::class)
35     open fun init() {
36         if (bluePrintLoadConfiguration.loadInitialData) {
37             initModelTypes()
38             initResourceDictionary()
39             initBluePrintCatalog()
40         } else {
41             log.info("Initial data load is disabled")
42         }
43     }
44
45     open fun initModelTypes() {
46         log.info("model types load configuration(${bluePrintLoadConfiguration.loadModelType}) " +
47                 "under paths(${bluePrintLoadConfiguration.loadModeTypePaths})")
48
49         if (bluePrintLoadConfiguration.loadModelType) {
50             val paths = bluePrintLoadConfiguration.loadModeTypePaths?.split(",")
51             paths?.let {
52                 modelTypeLoadService.loadPathsModelType(paths)
53             }
54         }
55     }
56
57     open fun initResourceDictionary() {
58         log.info("resource dictionary load configuration(${bluePrintLoadConfiguration.loadResourceDictionary}) " +
59                 "under paths(${bluePrintLoadConfiguration.loadResourceDictionaryPaths})")
60
61         if (bluePrintLoadConfiguration.loadResourceDictionary) {
62             val paths = bluePrintLoadConfiguration.loadResourceDictionaryPaths?.split(",")
63             paths?.let {
64                 resourceDictionaryLoadService.loadPathsResourceDictionary(paths)
65             }
66         }
67     }
68
69     open fun initBluePrintCatalog() {
70         log.info("blueprint load configuration(${bluePrintLoadConfiguration.loadBluePrint}) " +
71                 "under paths(${bluePrintLoadConfiguration.loadBluePrintPaths})")
72
73         if (bluePrintLoadConfiguration.loadBluePrint) {
74             val paths = bluePrintLoadConfiguration.loadBluePrintPaths?.split(",")
75             paths?.let {
76                 bluePrintCatalogLoadService.loadPathsBluePrintModelCatalog(paths)
77             }
78         }
79     }
80 }