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