Removed redundant timeout handling for executeCommand
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / designer-api / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / designer / api / enhancer / BluePrintRelationshipTypeEnhancerImpl.kt
1 /*
2  * Copyright © 2018-2019 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.cds.blueprintsprocessor.designer.api.enhancer
18
19 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
21 import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType
22 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRelationshipTypeEnhancer
23 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService
24 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
25 import org.onap.ccsdk.cds.controllerblueprints.core.logger
26 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
27 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
28 import org.springframework.beans.factory.config.ConfigurableBeanFactory
29 import org.springframework.context.annotation.Scope
30 import org.springframework.stereotype.Service
31
32 @Service
33 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
34 open class BluePrintRelationshipTypeEnhancerImpl(
35     private val bluePrintRepoService: BluePrintRepoService,
36     private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService
37 ) : BluePrintRelationshipTypeEnhancer {
38
39     private val log = logger(BluePrintRelationshipTypeEnhancerImpl::class)
40
41     lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
42     lateinit var bluePrintContext: BluePrintContext
43
44     override fun enhance(
45         bluePrintRuntimeService: BluePrintRuntimeService<*>,
46         name: String,
47         relationshipType: RelationshipType
48     ) {
49         this.bluePrintRuntimeService = bluePrintRuntimeService
50         this.bluePrintContext = bluePrintRuntimeService.bluePrintContext()
51
52         val derivedFrom = relationshipType.derivedFrom
53
54         if (!BluePrintTypes.rootRelationshipTypes().contains(derivedFrom)) {
55             val derivedFromRelationshipType =
56                 BluePrintEnhancerUtils.populateRelationshipType(bluePrintContext, bluePrintRepoService, name)
57             // Enrich RelationshipType
58             enhance(bluePrintRuntimeService, derivedFrom, derivedFromRelationshipType)
59         }
60
61         // NodeType Attribute Definitions
62         enrichRelationshipTypeAttributes(name, relationshipType)
63
64         // NodeType Property Definitions
65         enrichRelationshipTypeProperties(name, relationshipType)
66
67         // TODO("Interface Enrichment, If needed")
68     }
69
70     open fun enrichRelationshipTypeAttributes(nodeTypeName: String, relationshipType: RelationshipType) {
71         relationshipType.attributes?.let {
72             bluePrintTypeEnhancerService.enhanceAttributeDefinitions(
73                 bluePrintRuntimeService,
74                 relationshipType.attributes!!
75             )
76         }
77     }
78
79     open fun enrichRelationshipTypeProperties(nodeTypeName: String, relationshipType: RelationshipType) {
80         relationshipType.properties?.let {
81             bluePrintTypeEnhancerService.enhancePropertyDefinitions(
82                 bluePrintRuntimeService,
83                 relationshipType.properties!!
84             )
85         }
86     }
87 }