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 com.att.eelf.configuration.EELFLogger
\r
21 import com.att.eelf.configuration.EELFManager
\r
22 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
\r
23 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
\r
24 import org.onap.ccsdk.apps.controllerblueprints.core.data.*
\r
25 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
\r
26 import java.io.Serializable
\r
29 * BluePrintRepoFileService
\r
30 * @author Brinda Santh
\r
34 interface BluePrintRepoService : Serializable {
\r
36 @Throws(BluePrintException::class)
\r
37 fun getNodeType(nodeTypeName: String): NodeType
\r
39 @Throws(BluePrintException::class)
\r
40 fun getDataType(dataTypeName: String): DataType
\r
42 @Throws(BluePrintException::class)
\r
43 fun getArtifactType(artifactTypeName: String): ArtifactType
\r
45 @Throws(BluePrintException::class)
\r
46 fun getRelationshipType(relationshipTypeName: String): RelationshipType
\r
48 @Throws(BluePrintException::class)
\r
49 fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition
\r
54 open class BluePrintRepoFileService(modelTypePath: String) : BluePrintRepoService {
\r
56 private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintRepoFileService::class.toString())
\r
58 private val dataTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
\r
59 private val nodeTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE)
\r
60 private val artifactTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE)
\r
61 private val capabilityTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE)
\r
62 private val relationshipTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE)
\r
63 private val extension = ".json"
\r
65 override fun getDataType(dataTypeName: String): DataType {
\r
66 val fileName = dataTypePath.plus(BluePrintConstants.PATH_DIVIDER)
\r
67 .plus(dataTypeName).plus(extension)
\r
68 return getModelType(fileName, DataType::class.java)
\r
71 override fun getNodeType(nodeTypeName: String): NodeType {
\r
72 val fileName = nodeTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(nodeTypeName).plus(extension)
\r
73 return getModelType(fileName, NodeType::class.java)
\r
76 override fun getArtifactType(artifactTypeName: String): ArtifactType {
\r
77 val fileName = artifactTypePath.plus(BluePrintConstants.PATH_DIVIDER)
\r
78 .plus(artifactTypeName).plus(extension)
\r
79 return getModelType(fileName, ArtifactType::class.java)
\r
82 override fun getRelationshipType(relationshipTypeName: String): RelationshipType {
\r
83 val fileName = relationshipTypePath.plus(BluePrintConstants.PATH_DIVIDER)
\r
84 .plus(relationshipTypeName).plus(extension)
\r
85 return getModelType(fileName, RelationshipType::class.java)
\r
88 override fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition {
\r
89 val fileName = capabilityTypePath.plus(BluePrintConstants.PATH_DIVIDER)
\r
90 .plus(capabilityDefinitionName).plus(extension)
\r
91 return getModelType(fileName, CapabilityDefinition::class.java)
\r
94 private fun <T> getModelType(fileName: String, valueType: Class<T>): T {
\r
95 return JacksonUtils.readValueFromFile(fileName, valueType)
\r
96 ?: throw BluePrintException("couldn't get file($fileName) for type(${valueType.name}")
\r