summaryrefslogtreecommitdiffstats
path: root/ms
diff options
context:
space:
mode:
authorBrinda Santh Muthuramalingam <brindasanth@in.ibm.com>2020-01-08 20:13:47 +0000
committerGerrit Code Review <gerrit@onap.org>2020-01-08 20:13:47 +0000
commitb12b08a3666d7765405445c4c0041577b951f321 (patch)
tree15c28fcb5e7d0c2c83074f6c3a1a20c2884dbb93 /ms
parentd04a854edfb6bdafbdc4bebc036763bd7fb9b77b (diff)
parentcc969006532a1e1994ab6609b2c4ddcb0dc49d87 (diff)
Merge "Add new endpoint for posting data-dictinary as ResourceDefinition"
Diffstat (limited to 'ms')
-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
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandlerTest.kt71
4 files changed, 109 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")
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandlerTest.kt
new file mode 100644
index 000000000..db25b6c35
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandlerTest.kt
@@ -0,0 +1,71 @@
+/*
+ * Copyright © 2019 Bell Canada.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler
+
+import kotlinx.coroutines.runBlocking
+import org.hamcrest.Matchers.samePropertyValuesAs
+import org.junit.Assert
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.ArgumentCaptor
+import org.mockito.ArgumentMatchers.any
+import org.mockito.Mockito
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.repository.ResourceDictionaryRepository
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
+import org.springframework.test.context.junit4.SpringRunner
+
+@RunWith(SpringRunner::class)
+class ResourceDictionaryHandlerTest {
+
+ private val mockRepository = Mockito.mock(ResourceDictionaryRepository::class.java)
+ private val resourceDictionaryHandler = ResourceDictionaryHandler(mockRepository)
+
+ @Test
+ fun testSaveResourceDictionary() {
+ val resourceDefinition: ResourceDefinition = JacksonUtils
+ .readValueFromFile(
+ "./../../../../../components/model-catalog/resource-dictionary/starter-dictionary/sample-db-source.json",
+ ResourceDefinition::class.java
+ )!!
+
+ val expectedResourceDictionary = ResourceDictionary()
+ expectedResourceDictionary.name = resourceDefinition.name
+ expectedResourceDictionary.updatedBy = resourceDefinition.updatedBy
+ expectedResourceDictionary.resourceDictionaryGroup = resourceDefinition.group
+ expectedResourceDictionary.tags = resourceDefinition.tags!!
+ expectedResourceDictionary.description = resourceDefinition.property.description!!
+ expectedResourceDictionary.dataType = resourceDefinition.property.type
+ expectedResourceDictionary.definition = resourceDefinition
+
+ // Mock save success
+ val mockReturnValue = ResourceDictionary()
+ mockReturnValue.definition = ResourceDefinition()
+ Mockito.`when`(mockRepository.save(any(ResourceDictionary::class.java)))
+ .thenReturn(mockReturnValue)
+
+ runBlocking {
+ resourceDictionaryHandler.saveResourceDefinition(resourceDefinition)
+ }
+
+ val argumentCaptor = ArgumentCaptor.forClass(ResourceDictionary::class.java)
+ Mockito.verify(mockRepository).save(argumentCaptor.capture())
+
+ Assert.assertThat(argumentCaptor.value, samePropertyValuesAs(expectedResourceDictionary))
+ }
+}