e1d1eac7161d86bea04ddb9a27aa7a21ff95ce43
[ccsdk/apps.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.core.service\r
19 \r
20 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
21 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException\r
22 import org.onap.ccsdk.apps.controllerblueprints.core.data.*\r
23 import com.att.eelf.configuration.EELFLogger\r
24 import com.att.eelf.configuration.EELFManager\r
25 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils\r
26 import reactor.core.publisher.Mono\r
27 import java.io.File\r
28 import java.io.Serializable\r
29 import java.nio.charset.Charset\r
30 \r
31 /**\r
32  * BluePrintRepoFileService\r
33  * @author Brinda Santh\r
34  *\r
35  */\r
36 \r
37 interface BluePrintRepoService : Serializable {\r
38 \r
39     @Throws(BluePrintException::class)\r
40     fun getNodeType(nodeTypeName: String): Mono<NodeType>?\r
41 \r
42     @Throws(BluePrintException::class)\r
43     fun getDataType(dataTypeName: String): Mono<DataType>?\r
44 \r
45     @Throws(BluePrintException::class)\r
46     fun getArtifactType(artifactTypeName: String): Mono<ArtifactType>?\r
47 \r
48     @Throws(BluePrintException::class)\r
49     fun getRelationshipType(relationshipTypeName: String): Mono<RelationshipType>?\r
50 \r
51     @Throws(BluePrintException::class)\r
52     fun getCapabilityDefinition(capabilityDefinitionName: String): Mono<CapabilityDefinition>?\r
53 \r
54 }\r
55 \r
56 \r
57 open class BluePrintRepoFileService(modelTypePath: String) : BluePrintRepoService {\r
58 \r
59     private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintRepoFileService::class.toString())\r
60 \r
61     private val dataTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)\r
62     private val nodeTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE)\r
63     private val artifactTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE)\r
64     private val capabilityTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE)\r
65     private val relationshipTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE)\r
66     private val extension = ".json"\r
67 \r
68     override fun getDataType(dataTypeName: String): Mono<DataType>? {\r
69         val fileName = dataTypePath.plus(BluePrintConstants.PATH_DIVIDER)\r
70                 .plus(dataTypeName).plus(extension)\r
71         return getModelType(fileName, DataType::class.java)\r
72     }\r
73 \r
74     override fun getNodeType(nodeTypeName: String): Mono<NodeType>? {\r
75         val fileName = nodeTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(nodeTypeName).plus(extension)\r
76         return getModelType(fileName, NodeType::class.java)\r
77     }\r
78 \r
79     override fun getArtifactType(artifactTypeName: String): Mono<ArtifactType>? {\r
80         val fileName = artifactTypePath.plus(BluePrintConstants.PATH_DIVIDER)\r
81                 .plus(artifactTypeName).plus(extension)\r
82         return getModelType(fileName, ArtifactType::class.java)\r
83     }\r
84 \r
85     override fun getRelationshipType(relationshipTypeName: String): Mono<RelationshipType>? {\r
86         val fileName = relationshipTypePath.plus(BluePrintConstants.PATH_DIVIDER)\r
87                 .plus(relationshipTypeName).plus(extension)\r
88         return getModelType(fileName, RelationshipType::class.java)\r
89     }\r
90 \r
91     override fun getCapabilityDefinition(capabilityDefinitionName: String): Mono<CapabilityDefinition>? {\r
92         val fileName = capabilityTypePath.plus(BluePrintConstants.PATH_DIVIDER)\r
93                 .plus(capabilityDefinitionName).plus(extension)\r
94         return getModelType(fileName, CapabilityDefinition::class.java)\r
95     }\r
96 \r
97     private fun <T> getModelType(fileName: String, valueType: Class<T>): Mono<T> {\r
98         return JacksonReactorUtils.readValueFromFile(fileName, valueType)\r
99     }\r
100 }