eeea97c9b95cdefc77b6ebef6e3e6d656956eead
[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.springframework.boot.context.event.ApplicationReadyEvent
21 import org.springframework.context.event.EventListener
22 import org.springframework.stereotype.Service
23
24 @Service
25 open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration,
26                                         private val modelTypeLoadService: ModelTypeLoadService,
27                                         private val resourceDictionaryLoadService: ResourceDictionaryLoadService,
28                                         private val bluePrintCatalogLoadService: BluePrintCatalogLoadService) {
29
30     private val log = EELFManager.getInstance().getLogger(BluePrintDatabaseLoadService::class.java)
31
32
33     @EventListener(ApplicationReadyEvent::class)
34     open fun init() {
35         if (bluePrintLoadConfiguration.loadInitialData) {
36             initModelTypes()
37             initResourceDictionary()
38             initBluePrintCatalog()
39         } else {
40             log.info("Initial data load is disabled")
41         }
42     }
43
44     open fun initModelTypes() {
45         log.info("model types load configuration(${bluePrintLoadConfiguration.loadModelType}) " +
46                 "under paths(${bluePrintLoadConfiguration.loadModeTypePaths})")
47
48         if (bluePrintLoadConfiguration.loadModelType) {
49             val paths = bluePrintLoadConfiguration.loadModeTypePaths?.split(",")
50             paths?.let {
51                 modelTypeLoadService.loadPathsModelType(paths)
52             }
53         }
54     }
55
56     open fun initResourceDictionary() {
57         log.info("resource dictionary load configuration(${bluePrintLoadConfiguration.loadResourceDictionary}) " +
58                 "under paths(${bluePrintLoadConfiguration.loadResourceDictionaryPaths})")
59
60         if (bluePrintLoadConfiguration.loadResourceDictionary) {
61             val paths = bluePrintLoadConfiguration.loadResourceDictionaryPaths?.split(",")
62             paths?.let {
63                 resourceDictionaryLoadService.loadPathsResourceDictionary(paths)
64             }
65         }
66     }
67
68     open fun initBluePrintCatalog() {
69         log.info("blueprint load configuration(${bluePrintLoadConfiguration.loadBluePrint}) " +
70                 "under paths(${bluePrintLoadConfiguration.loadBluePrintPaths})")
71
72         if (bluePrintLoadConfiguration.loadBluePrint) {
73             val paths = bluePrintLoadConfiguration.loadBluePrintPaths?.split(",")
74             paths?.let {
75                 bluePrintCatalogLoadService.loadPathsBluePrintModelCatalog(paths)
76             }
77         }
78     }
79 }