17dfb1b7b6603a5387d26984de1400de14b4a95c
[ccsdk/cds.git] /
1 /*\r
2  * Copyright © 2017-2018 AT&T Intellectual Property.\r
3  * Modifications Copyright © 2018 IBM.\r
4  *\r
5  * Licensed under the Apache License, Version 2.0 (the "License");\r
6  * you may not use this file except in compliance with the License.\r
7  * You may obtain a copy of the License at\r
8  *\r
9  *     http://www.apache.org/licenses/LICENSE-2.0\r
10  *\r
11  * Unless required by applicable law or agreed to in writing, software\r
12  * distributed under the License is distributed on an "AS IS" BASIS,\r
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14  * See the License for the specific language governing permissions and\r
15  * limitations under the License.\r
16  */\r
17 \r
18 package org.onap.ccsdk.apps.controllerblueprints.service.enhancer\r
19 \r
20 import com.att.eelf.configuration.EELFLogger\r
21 import com.att.eelf.configuration.EELFManager\r
22 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError\r
23 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException\r
24 import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate\r
25 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService\r
26 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService\r
27 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService\r
28 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext\r
29 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils\r
30 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils\r
31 import org.springframework.stereotype.Service\r
32 \r
33 @Service\r
34 open class BluePrintEnhancerServiceImpl(private val bluePrintRepoService: BluePrintRepoService,\r
35                                         private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintEnhancerService {\r
36 \r
37     private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerServiceImpl::class.toString())\r
38 \r
39     override fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext {\r
40         BluePrintFileUtils.copyBluePrint(basePath, enrichedBasePath)\r
41         BluePrintFileUtils.deleteBluePrintTypes(enrichedBasePath)\r
42         val enhancedBluePrintContext = enhance(enrichedBasePath)\r
43         BluePrintFileUtils.writeBluePrintTypes(enhancedBluePrintContext)\r
44         return enhancedBluePrintContext\r
45     }\r
46 \r
47     @Throws(BluePrintException::class)\r
48     override fun enhance(basePath: String): BluePrintContext {\r
49         log.info("Enhancing blueprint($basePath)")\r
50         val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(basePath)\r
51         val error = BluePrintError()\r
52         bluePrintTypeEnhancerService.enhanceServiceTemplate(bluePrintContext, error, "service_template",\r
53                 bluePrintContext.serviceTemplate)\r
54         return bluePrintContext\r
55     }\r
56 \r
57     @Throws(BluePrintException::class)\r
58     override fun enhance(serviceTemplate: ServiceTemplate): ServiceTemplate {\r
59         val bluePrintContext = BluePrintContext(serviceTemplate)\r
60         val error = BluePrintError()\r
61         bluePrintTypeEnhancerService.enhanceServiceTemplate(bluePrintContext, error, "service_template",\r
62                 bluePrintContext.serviceTemplate)\r
63         return bluePrintContext.serviceTemplate\r
64     }\r
65 }\r
66 \r