aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin
diff options
context:
space:
mode:
authorJozsef Csongvai <jozsef.csongvai@bell.ca>2020-01-07 13:30:24 -0500
committerJozsef Csongvai <jozsef.csongvai@bell.ca>2020-01-08 14:22:24 -0500
commitcc969006532a1e1994ab6609b2c4ddcb0dc49d87 (patch)
treeccd23eab4814af59a746a3ce580a34af61be247a /ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin
parent5e5718c9191f125ad65bd9ab15334147bedd79cc (diff)
Add new endpoint for posting data-dictinary as ResourceDefinition
Starter-dictionaries and examples in the documentation have the type ResourceDefinition. The existing endpoint accepts ResourceDictionary which is the wrapping entity of ResourceDefinition. Issue-ID: CCSDK-1725 Change-Id: I07f925ba4f607a6eaecf5907ac6e08691578c3b5 Signed-off-by: Jozsef Csongvai <jozsef.csongvai@bell.ca>
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin')
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryController.kt8
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandler.kt29
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ResourceDictionaryLoadService.kt26
3 files changed, 38 insertions, 25 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryController.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryController.kt
index 390207995..75403d479 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryController.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryController.kt
@@ -20,6 +20,7 @@ import kotlinx.coroutines.runBlocking
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ResourceDictionaryHandler
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.DeleteMapping
@@ -49,6 +50,13 @@ open class ResourceDictionaryController(private val resourceDictionaryHandler: R
resourceDictionaryHandler.saveResourceDictionary(dataDictionary)
}
+ @PostMapping(path = ["/definition"], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE])
+ @ResponseBody
+ @Throws(BluePrintException::class)
+ fun saveResourceDictionary(@RequestBody resourceDefinition: ResourceDefinition): ResourceDefinition = runBlocking {
+ resourceDictionaryHandler.saveResourceDefinition(resourceDefinition)
+ }
+
@DeleteMapping(path = ["/{name}"])
fun deleteResourceDictionaryByName(@PathVariable(value = "name") name: String) = runBlocking {
resourceDictionaryHandler.deleteResourceDictionary(name)
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandler.kt
index d7563e821..0f0bfef6d 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandler.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandler.kt
@@ -24,6 +24,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictio
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.repository.ResourceDictionaryRepository
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory
import org.springframework.stereotype.Service
@@ -121,6 +122,34 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour
}
/**
+ * This is a saveDataDictionary service
+ *
+ * @param resourceDefinition ResourceDefinition
+ * @return ResourceDefinition
+ */
+ @Throws(BluePrintException::class)
+ suspend fun saveResourceDefinition(resourceDefinition: ResourceDefinition): ResourceDefinition {
+ val resourceDictionary = ResourceDictionary()
+ resourceDictionary.name = resourceDefinition.name
+ resourceDictionary.updatedBy = resourceDefinition.updatedBy
+ resourceDictionary.resourceDictionaryGroup = resourceDefinition.group
+ resourceDictionary.entrySchema = resourceDefinition.property.entrySchema?.type
+ if (StringUtils.isBlank(resourceDefinition.tags)) {
+ resourceDictionary.tags = (resourceDefinition.name + ", " + resourceDefinition.updatedBy +
+ ", " + resourceDefinition.updatedBy)
+ } else {
+ resourceDictionary.tags = resourceDefinition.tags!!
+ }
+ resourceDictionary.description = resourceDefinition.property.description!!
+ resourceDictionary.dataType = resourceDefinition.property.type
+ resourceDictionary.definition = resourceDefinition
+
+ validateResourceDictionary(resourceDictionary)
+
+ return resourceDictionaryRepository.save(resourceDictionary).definition
+ }
+
+ /**
* This is a deleteResourceDictionary service
*
* @param name name
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ResourceDictionaryLoadService.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ResourceDictionaryLoadService.kt
index 432ef0f38..15cf3dcb0 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ResourceDictionaryLoadService.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ResourceDictionaryLoadService.kt
@@ -20,9 +20,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.load
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
-import org.apache.commons.lang3.StringUtils
import org.apache.commons.lang3.text.StrBuilder
-import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ResourceDictionaryHandler
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
@@ -74,29 +72,7 @@ open class ResourceDictionaryLoadService(private val resourceDictionaryHandler:
val definitionContent = file.readNBText()
val resourceDefinition = JacksonUtils.readValue(definitionContent, ResourceDefinition::class.java)
if (resourceDefinition != null) {
-
- checkNotNull(resourceDefinition.property) { "Failed to get Property Definition" }
- val resourceDictionary = ResourceDictionary()
- resourceDictionary.name = resourceDefinition.name
- resourceDictionary.definition = resourceDefinition
-
- checkNotNull(resourceDefinition.property) { "Property field is missing" }
- resourceDictionary.description = resourceDefinition.property.description!!
- resourceDictionary.dataType = resourceDefinition.property.type
-
- if (resourceDefinition.property.entrySchema != null) {
- resourceDictionary.entrySchema = resourceDefinition.property.entrySchema!!.type
- }
- resourceDictionary.updatedBy = resourceDefinition.updatedBy
-
- if (StringUtils.isBlank(resourceDefinition.tags)) {
- resourceDictionary.tags = (resourceDefinition.name + ", " + resourceDefinition.updatedBy +
- ", " + resourceDefinition.updatedBy)
- } else {
- resourceDictionary.tags = resourceDefinition.tags!!
- }
- resourceDictionaryHandler.saveResourceDictionary(resourceDictionary)
-
+ resourceDictionaryHandler.saveResourceDefinition(resourceDefinition)
log.trace("Resource dictionary(${file.name}) loaded successfully ")
} else {
throw BluePrintException("couldn't get dictionary from content information")