2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
3 * Modifications Copyright © 2018 IBM.
\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
9 * http://www.apache.org/licenses/LICENSE-2.0
\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
18 package org.onap.ccsdk.apps.controllerblueprints.core.service
\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.Serializable
\r
30 * BluePrintRepoFileService
\r
31 * @author Brinda Santh
\r
35 interface BluePrintRepoService : Serializable {
\r
37 @Throws(BluePrintException::class)
\r
38 fun getNodeType(nodeTypeName: String): Mono<NodeType>
\r
40 @Throws(BluePrintException::class)
\r
41 fun getDataType(dataTypeName: String): Mono<DataType>
\r
43 @Throws(BluePrintException::class)
\r
44 fun getArtifactType(artifactTypeName: String): Mono<ArtifactType>
\r
46 @Throws(BluePrintException::class)
\r
47 fun getRelationshipType(relationshipTypeName: String): Mono<RelationshipType>
\r
49 @Throws(BluePrintException::class)
\r
50 fun getCapabilityDefinition(capabilityDefinitionName: String): Mono<CapabilityDefinition>
\r
55 open class BluePrintRepoFileService(modelTypePath: String) : BluePrintRepoService {
\r
57 private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintRepoFileService::class.toString())
\r
59 private val dataTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
\r
60 private val nodeTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE)
\r
61 private val artifactTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE)
\r
62 private val capabilityTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE)
\r
63 private val relationshipTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE)
\r
64 private val extension = ".json"
\r
66 override fun getDataType(dataTypeName: String): Mono<DataType> {
\r
67 val fileName = dataTypePath.plus(BluePrintConstants.PATH_DIVIDER)
\r
68 .plus(dataTypeName).plus(extension)
\r
69 return getModelType(fileName, DataType::class.java)
\r
72 override fun getNodeType(nodeTypeName: String): Mono<NodeType> {
\r
73 val fileName = nodeTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(nodeTypeName).plus(extension)
\r
74 return getModelType(fileName, NodeType::class.java)
\r
77 override fun getArtifactType(artifactTypeName: String): Mono<ArtifactType> {
\r
78 val fileName = artifactTypePath.plus(BluePrintConstants.PATH_DIVIDER)
\r
79 .plus(artifactTypeName).plus(extension)
\r
80 return getModelType(fileName, ArtifactType::class.java)
\r
83 override fun getRelationshipType(relationshipTypeName: String): Mono<RelationshipType> {
\r
84 val fileName = relationshipTypePath.plus(BluePrintConstants.PATH_DIVIDER)
\r
85 .plus(relationshipTypeName).plus(extension)
\r
86 return getModelType(fileName, RelationshipType::class.java)
\r
89 override fun getCapabilityDefinition(capabilityDefinitionName: String): Mono<CapabilityDefinition> {
\r
90 val fileName = capabilityTypePath.plus(BluePrintConstants.PATH_DIVIDER)
\r
91 .plus(capabilityDefinitionName).plus(extension)
\r
92 return getModelType(fileName, CapabilityDefinition::class.java)
\r
95 private fun <T> getModelType(fileName: String, valueType: Class<T>): Mono<T> {
\r
96 return JacksonReactorUtils.readValueFromFile(fileName, valueType)
\r