From 208cb6ae94922c0198648aea817085793ce8bc47 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Mon, 27 Aug 2018 17:29:51 +0000 Subject: Controller Blueprints Microservice Optimise model type repository search for DB and file in blueprint repo service. Change-Id: If5458e218b723d3fff451789a73a667dd75bc91c Issue-ID: CCSDK-487 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- ms/controllerblueprints/modules/core/pom.xml | 4 + .../core/service/BluePrintEnhancerService.kt | 6 +- .../core/service/BluePrintRepoService.kt | 71 ++++++++++------ .../core/service/BluePrintRepoFileServiceTest.kt | 8 ++ .../resource/dict/data/ResourceSource.java | 2 +- .../service/ResourceDictionaryValidationService.kt | 3 +- .../load/resource_dictionary/input-source.json | 2 +- .../load/resource_dictionary/v4-ip-type.json | 2 +- .../service/BluePrintRepoDBService.java | 63 +++++++------- .../service/ResourceDictionaryService.java | 96 ++++++++++------------ .../resourcedictionary/default_definition.json | 4 +- 11 files changed, 140 insertions(+), 121 deletions(-) (limited to 'ms/controllerblueprints/modules') diff --git a/ms/controllerblueprints/modules/core/pom.xml b/ms/controllerblueprints/modules/core/pom.xml index 51b3af35..ba38de63 100644 --- a/ms/controllerblueprints/modules/core/pom.xml +++ b/ms/controllerblueprints/modules/core/pom.xml @@ -43,6 +43,10 @@ com.fasterxml.jackson.module jackson-module-jsonSchema + + io.projectreactor + reactor-core + org.yaml snakeyaml diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt index 64fc57fc..8bc0e6e0 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt @@ -217,21 +217,21 @@ open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRe } open fun populateNodeType(nodeTypeName: String): NodeType { - val nodeType = bluePrintRepoService.getNodeType(nodeTypeName) + val nodeType = bluePrintRepoService.getNodeType(nodeTypeName)?.block() ?: throw BluePrintException(format("Couldn't get NodeType({}) from repo.", nodeTypeName)) serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType) return nodeType } open fun populateArtifactType(artifactTypeName: String): ArtifactType { - val artifactType = bluePrintRepoService.getArtifactType(artifactTypeName) + val artifactType = bluePrintRepoService.getArtifactType(artifactTypeName)?.block() ?: throw BluePrintException(format("Couldn't get ArtifactType({}) from repo.", artifactTypeName)) serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType) return artifactType } open fun populateDataTypes(dataTypeName: String): DataType { - val dataType = bluePrintRepoService.getDataType(dataTypeName) + val dataType = bluePrintRepoService.getDataType(dataTypeName)?.block() ?: throw BluePrintException(format("Couldn't get DataType({}) from repo.", dataTypeName)) serviceTemplate.dataTypes?.put(dataTypeName, dataType) return dataType diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt index a529a85f..8c444618 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt @@ -17,11 +17,16 @@ package org.onap.ccsdk.apps.controllerblueprints.core.service +import com.google.common.base.Preconditions import org.apache.commons.io.FileUtils +import org.apache.commons.lang3.StringUtils import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.data.* import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import reactor.core.publisher.Mono import java.io.File import java.io.Serializable import java.nio.charset.Charset @@ -35,25 +40,27 @@ import java.nio.charset.Charset interface BluePrintRepoService : Serializable { @Throws(BluePrintException::class) - fun getNodeType(nodeTypeName: String): NodeType? + fun getNodeType(nodeTypeName: String): Mono? @Throws(BluePrintException::class) - fun getDataType(dataTypeName: String): DataType? + fun getDataType(dataTypeName: String): Mono? @Throws(BluePrintException::class) - fun getArtifactType(artifactTypeName: String): ArtifactType? + fun getArtifactType(artifactTypeName: String): Mono? @Throws(BluePrintException::class) - fun getRelationshipType(relationshipTypeName: String): RelationshipType? + fun getRelationshipType(relationshipTypeName: String): Mono? @Throws(BluePrintException::class) - fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition? + fun getCapabilityDefinition(capabilityDefinitionName: String): Mono? } class BluePrintRepoFileService(val basePath: String) : BluePrintRepoService { + private val log: Logger = LoggerFactory.getLogger(BluePrintRepoFileService::class.java) + val dataTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) val nodeTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE) val artifactTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) @@ -61,33 +68,47 @@ class BluePrintRepoFileService(val basePath: String) : BluePrintRepoService { val relationshipTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) val extension = ".json" - override fun getDataType(dataTypeName: String): DataType? { - val content = FileUtils.readFileToString(File(dataTypePath.plus(BluePrintConstants.PATH_DIVIDER) - .plus(dataTypeName).plus(extension)), Charset.defaultCharset()) - return JacksonUtils.readValue(content) + override fun getDataType(dataTypeName: String): Mono? { + val fileName = dataTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(dataTypeName).plus(extension) + return getModelType(fileName, DataType::class.java) + } + + override fun getNodeType(nodeTypeName: String): Mono? { + val fileName = nodeTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(nodeTypeName).plus(extension) + return getModelType(fileName, NodeType::class.java) } - override fun getNodeType(nodeTypeName: String): NodeType? { - val content = FileUtils.readFileToString(File(nodeTypePath.plus(BluePrintConstants.PATH_DIVIDER) - .plus(nodeTypeName).plus(extension)), Charset.defaultCharset()) - return JacksonUtils.readValue(content) + override fun getArtifactType(artifactTypeName: String): Mono? { + val fileName = artifactTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(artifactTypeName).plus(extension) + return getModelType(fileName, ArtifactType::class.java) } - override fun getArtifactType(artifactTypeName: String): ArtifactType? { - val content = FileUtils.readFileToString(File(artifactTypePath.plus(BluePrintConstants.PATH_DIVIDER) - .plus(artifactTypeName).plus(extension)), Charset.defaultCharset()) - return JacksonUtils.readValue(content) + override fun getRelationshipType(relationshipTypeName: String): Mono? { + val fileName = relationshipTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(relationshipTypeName).plus(extension) + return getModelType(fileName, RelationshipType::class.java) } - override fun getRelationshipType(relationshipTypeName: String): RelationshipType? { - val content = FileUtils.readFileToString(File(relationshipTypePath.plus(BluePrintConstants.PATH_DIVIDER) - .plus(relationshipTypeName).plus(extension)), Charset.defaultCharset()) - return JacksonUtils.readValue(content) + override fun getCapabilityDefinition(capabilityDefinitionName: String): Mono? { + val fileName = capabilityTypePath.plus(BluePrintConstants.PATH_DIVIDER) + .plus(capabilityDefinitionName).plus(extension) + return getModelType(fileName, CapabilityDefinition::class.java) + } + + private fun getModelType(fileName: String, valueType: Class): Mono { + return getFileContent(fileName).map { content -> + Preconditions.checkArgument(StringUtils.isNotBlank(content), + String.format("Failed to get model content for file (%s)", fileName)) + + JacksonUtils.readValue(content, valueType) + ?: throw BluePrintException(String.format("Failed to get model file from content for file (%s)", fileName)) + + } } - override fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition? { - val content = FileUtils.readFileToString(File(capabilityTypePath.plus(BluePrintConstants.PATH_DIVIDER) - .plus(capabilityDefinitionName).plus(extension)), Charset.defaultCharset()) - return JacksonUtils.readValue(content) + private fun getFileContent(fileName: String): Mono { + return Mono.just(FileUtils.readFileToString(File(fileName), Charset.defaultCharset())) } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt index 574eae6d..4731935e 100644 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt +++ b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.core.service import org.junit.Test +import java.io.FileNotFoundException import kotlin.test.assertNotNull /** @@ -49,4 +50,11 @@ class BluePrintRepoFileServiceTest { val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity") assertNotNull(nodeType, "Failed to get ArtifactType from repo") } + + @Test(expected = FileNotFoundException::class) + fun testModelNotFound() { + val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) + val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-not-found") + assertNotNull(dataType, "Failed to get DataType from repo") + } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java index 735832cb..1ef69fa9 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java @@ -17,6 +17,6 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data; import java.io.Serializable; - +@Deprecated public interface ResourceSource extends Serializable { } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt index cef1f158..5a1e3812 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt @@ -1,5 +1,6 @@ /* * Copyright © 2018 IBM. + * Modifications Copyright © 2017-2018 AT&T Intellectual Property. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +47,7 @@ open class ResourceDictionaryDefaultValidationService(val bluePrintRepoService: resourceDefinition.sources.forEach { (name, nodeTemplate) -> val sourceType = nodeTemplate.type - val sourceNodeType = bluePrintRepoService.getNodeType(sourceType) + val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)?.block() ?: throw BluePrintException(format("Failed to get node type definition for source({})", sourceType)) // Validate Property Name, expression, values and Data Type diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json index c34c252b..610e8fc0 100644 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json @@ -7,7 +7,7 @@ "resource-path": "action-name", "resource-type": "ONAP", "updated-by": "brindasanth@onap.com", - "tags": null, + "tags": "action-name, brindasanth", "sources": { "input": { "type": "source-input", diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json index 349183bd..e7e06000 100644 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json @@ -7,7 +7,7 @@ "resource-path": "vnf/v4-ip-type", "resource-type": "ONAP", "updated-by": "brindasanth@onap.com", - "tags": null, + "tags": "v4-ip-type, source-input, brindasanth", "sources": { "input": { "type": "source-input", diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java index 4a26119c..4c11d8c6 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java @@ -26,6 +26,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository; import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; import java.util.Optional; @@ -43,59 +44,51 @@ public class BluePrintRepoDBService implements BluePrintRepoService { this.modelTypeRepository = modelTypeRepository; } - @Override - public NodeType getNodeType(String nodeTypeName) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(nodeTypeName), "NodeType name is missing"); - String content = getModelDefinitions(nodeTypeName); - Preconditions.checkArgument(StringUtils.isNotBlank(content), "NodeType content is missing"); - return JacksonUtils.readValue(content, NodeType.class); + public Mono getNodeType(String nodeTypeName) throws BluePrintException { + return getModelType(nodeTypeName, NodeType.class); } - @Override - public DataType getDataType(String dataTypeName) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(dataTypeName), "DataType name is missing"); - String content = getModelDefinitions(dataTypeName); - Preconditions.checkArgument(StringUtils.isNotBlank(content), "DataType content is missing"); - return JacksonUtils.readValue(content, DataType.class); + public Mono getDataType(String dataTypeName) throws BluePrintException { + return getModelType(dataTypeName, DataType.class); } - @Override - public ArtifactType getArtifactType(String artifactTypeName) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(artifactTypeName), "ArtifactType name is missing"); - String content = getModelDefinitions(artifactTypeName); - Preconditions.checkArgument(StringUtils.isNotBlank(content), "ArtifactType content is missing"); - return JacksonUtils.readValue(content, ArtifactType.class); + public Mono getArtifactType(String artifactTypeName) throws BluePrintException { + return getModelType(artifactTypeName, ArtifactType.class); } - @Override - public RelationshipType getRelationshipType(String relationshipTypeName) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(relationshipTypeName), "RelationshipType name is missing"); - String content = getModelDefinitions(relationshipTypeName); - Preconditions.checkArgument(StringUtils.isNotBlank(content), "RelationshipType content is missing"); - return JacksonUtils.readValue(content, RelationshipType.class); + public Mono getRelationshipType(String relationshipTypeName) throws BluePrintException { + return getModelType(relationshipTypeName, RelationshipType.class); } - @Override - public CapabilityDefinition getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(capabilityDefinitionName), "CapabilityDefinition name is missing"); - String content = getModelDefinitions(capabilityDefinitionName); - Preconditions.checkArgument(StringUtils.isNotBlank(content), "CapabilityDefinition content is missing"); - return JacksonUtils.readValue(content, CapabilityDefinition.class); + public Mono getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException { + return getModelType(capabilityDefinitionName, CapabilityDefinition.class); } - private String getModelDefinitions(String modelName) throws BluePrintException { + private Mono getModelType(String modelName, Class valueClass) throws BluePrintException { + Preconditions.checkArgument(StringUtils.isNotBlank(modelName), + "Failed to get model from repo, model name is missing"); + + return getModelDefinitions(modelName).map(content -> { + Preconditions.checkArgument(StringUtils.isNotBlank(content), + String.format("Failed to get model content for model name (%s)", modelName)); + return JacksonUtils.readValue(content, valueClass); + } + ); + } + + private Mono getModelDefinitions(String modelName) throws BluePrintException { String modelDefinition = null; - Optional modelTypedb = modelTypeRepository.findByModelName(modelName); - if (modelTypedb.isPresent()) { - modelDefinition = modelTypedb.get().getDefinition(); + Optional modelTypeDb = modelTypeRepository.findByModelName(modelName); + if (modelTypeDb.isPresent()) { + modelDefinition = modelTypeDb.get().getDefinition(); } else { throw new BluePrintException(String.format("failed to get model definition (%s) from repo", modelName)); } - return modelDefinition; + return Mono.just(modelDefinition); } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java index 5420dd39..629b94c0 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java @@ -17,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.google.common.base.Preconditions; import org.apache.commons.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.data.EntrySchema; @@ -112,60 +113,51 @@ public class ResourceDictionaryService { */ public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) throws BluePrintException { - if (resourceDictionary != null) { - ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary); - - ResourceDefinition resourceDefinition = - JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); - // Check the Source already Present - resourceDictionaryValidationService.validate(resourceDefinition); - - if (resourceDefinition == null) { - throw new BluePrintException( - "Resource dictionary definition is not valid content " + resourceDictionary.getDefinition()); - } - - resourceDefinition.setName(resourceDictionary.getName()); - resourceDefinition.setResourcePath(resourceDictionary.getResourcePath()); - resourceDefinition.setResourceType(resourceDictionary.getResourceType()); - - PropertyDefinition propertyDefinition = new PropertyDefinition(); - propertyDefinition.setType(resourceDictionary.getDataType()); - propertyDefinition.setDescription(resourceDictionary.getDescription()); - if (StringUtils.isNotBlank(resourceDictionary.getEntrySchema())) { - EntrySchema entrySchema = new EntrySchema(); - entrySchema.setType(resourceDictionary.getEntrySchema()); - propertyDefinition.setEntrySchema(entrySchema); - } else { - propertyDefinition.setEntrySchema(null); - } - resourceDefinition.setTags(resourceDictionary.getTags()); - resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy()); - - String definitionContent = JacksonUtils.getJson(resourceDefinition, true); - resourceDictionary.setDefinition(definitionContent); - - Optional dbResourceDictionaryData = - resourceDictionaryRepository.findByName(resourceDictionary.getName()); - if (dbResourceDictionaryData.isPresent()) { - ResourceDictionary dbResourceDictionary = dbResourceDictionaryData.get(); - - dbResourceDictionary.setName(resourceDictionary.getName()); - dbResourceDictionary.setDefinition(resourceDictionary.getDefinition()); - dbResourceDictionary.setDescription(resourceDictionary.getDescription()); - dbResourceDictionary.setResourceType(resourceDictionary.getResourceType()); - dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath()); - dbResourceDictionary.setDataType(resourceDictionary.getDataType()); - dbResourceDictionary.setEntrySchema(resourceDictionary.getEntrySchema()); - dbResourceDictionary.setTags(resourceDictionary.getTags()); - dbResourceDictionary.setValidValues(resourceDictionary.getValidValues()); - resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary); - } else { - resourceDictionary = resourceDictionaryRepository.save(resourceDictionary); - } + Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing"); + Preconditions.checkArgument(StringUtils.isNotBlank(resourceDictionary.getDefinition()), + "Resource Dictionary definition information is missing"); + + ResourceDefinition resourceDefinition = + JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); + // Validate the Resource Definitions + resourceDictionaryValidationService.validate(resourceDefinition); + + resourceDictionary.setResourceType(resourceDefinition.getResourceType()); + resourceDictionary.setResourcePath(resourceDefinition.getResourcePath()); + resourceDictionary.setTags(resourceDefinition.getTags()); + resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy()); + // Set the Property Definitions + PropertyDefinition propertyDefinition = resourceDefinition.getProperty(); + resourceDictionary.setDescription(propertyDefinition.getDescription()); + resourceDictionary.setDataType(propertyDefinition.getType()); + if(propertyDefinition.getEntrySchema() != null){ + resourceDictionary.setEntrySchema(propertyDefinition.getEntrySchema().getType()); + } + + String definitionContent = JacksonUtils.getJson(resourceDefinition, true); + resourceDictionary.setDefinition(definitionContent); + + ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary); + + Optional dbResourceDictionaryData = + resourceDictionaryRepository.findByName(resourceDictionary.getName()); + if (dbResourceDictionaryData.isPresent()) { + ResourceDictionary dbResourceDictionary = dbResourceDictionaryData.get(); + + dbResourceDictionary.setName(resourceDictionary.getName()); + dbResourceDictionary.setDefinition(resourceDictionary.getDefinition()); + dbResourceDictionary.setDescription(resourceDictionary.getDescription()); + dbResourceDictionary.setResourceType(resourceDictionary.getResourceType()); + dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath()); + dbResourceDictionary.setTags(resourceDictionary.getTags()); + dbResourceDictionary.setUpdatedBy(resourceDictionary.getUpdatedBy()); + dbResourceDictionary.setDataType(resourceDictionary.getDataType()); + dbResourceDictionary.setEntrySchema(resourceDictionary.getEntrySchema()); + resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary); } else { - throw new BluePrintException("Resource Dictionary information is missing"); + resourceDictionary = resourceDictionaryRepository.save(resourceDictionary); } + return resourceDictionary; } diff --git a/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json index 986ba706..198823bb 100644 --- a/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json +++ b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json @@ -1,5 +1,5 @@ { - "name": "v4-aggregat-list", + "name": "ipaddress", "property": { "description": "name of the ", "type": "list", @@ -10,7 +10,7 @@ "updated-by": "Brinda Santh (bs2796)", "resource-type": "ONAP", "resource-path": "/v4-aggregat-list", - "tags": null, + "tags": "ipaddress", "sources": { "input": { "type": "source-input" -- cgit 1.2.3-korg