aboutsummaryrefslogtreecommitdiffstats
path: root/components/core
diff options
context:
space:
mode:
Diffstat (limited to 'components/core')
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt14
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt2
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt31
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BlueprintErrorCode.kt97
-rwxr-xr-xcomponents/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintCatalogService.kt41
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt2
-rwxr-xr-xcomponents/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt65
-rwxr-xr-xcomponents/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtils.kt24
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt70
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTypeValidatorImpl.kt4
-rw-r--r--components/core/src/test/resources/dictionary/dictionary_schema.json4
11 files changed, 252 insertions, 102 deletions
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
index 102e2ebd..4ef0e82b 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
@@ -27,16 +27,18 @@ object BluePrintConstants {
const val RESPONSE_HEADER_TRANSACTION_ID: String = "X-ONAP-RequestID"
const val RESPONSE_HEADER_MINOR_VERSION: String = "X-MinorVersion"
const val RESPONSE_HEADER_PATCH_VERSION: String = "X-PatchVersion"
- const val RESPONSE_HEADER_LATEST_VERSION: String = "X-LatestVersion"
-
- const val STATUS_SUCCESS: String = "success"
- const val STATUS_FAILURE: String = "failure"
-
- const val TYPE_DEFAULT: String = "default"
+ const val RESPONSE_HEADER_LATEST_VERSION: String = "X-LatestVersion"
+
+ const val STATUS_SUCCESS: String = "success"
+ const val STATUS_PROCESSING: String = "processing"
+ const val STATUS_FAILURE: String = "failure"
+
+ const val TYPE_DEFAULT: String = "default"
const val DATA_TYPE_STRING: String = "string"
const val DATA_TYPE_INTEGER: String = "integer"
const val DATA_TYPE_FLOAT: String = "float"
+ const val DATA_TYPE_DOUBLE: String = "double"
const val DATA_TYPE_BOOLEAN: String = "boolean"
const val DATA_TYPE_TIMESTAMP: String = "timestamp"
const val DATA_TYPE_NULL: String = "null"
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt
index 64797ed4..4c35b53a 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt
@@ -103,6 +103,7 @@ object BluePrintTypes {
validTypes.add(BluePrintConstants.DATA_TYPE_STRING)
validTypes.add(BluePrintConstants.DATA_TYPE_INTEGER)
validTypes.add(BluePrintConstants.DATA_TYPE_FLOAT)
+ validTypes.add(BluePrintConstants.DATA_TYPE_DOUBLE)
validTypes.add(BluePrintConstants.DATA_TYPE_BOOLEAN)
validTypes.add(BluePrintConstants.DATA_TYPE_TIMESTAMP)
validTypes.add(BluePrintConstants.DATA_TYPE_NULL)
@@ -117,6 +118,7 @@ object BluePrintTypes {
validTypes.add(BluePrintConstants.DATA_TYPE_STRING)
validTypes.add(BluePrintConstants.DATA_TYPE_INTEGER)
validTypes.add(BluePrintConstants.DATA_TYPE_FLOAT)
+ validTypes.add(BluePrintConstants.DATA_TYPE_DOUBLE)
validTypes.add(BluePrintConstants.DATA_TYPE_BOOLEAN)
validTypes.add(BluePrintConstants.DATA_TYPE_TIMESTAMP)
validTypes.add(BluePrintConstants.DATA_TYPE_NULL)
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt
index 4d1d9b65..11f709c9 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt
@@ -112,25 +112,40 @@ fun MutableMap<String, JsonNode>.getAsDouble(key: String): Double {
// Checks
fun checkNotEmpty(value: String?): Boolean {
- return value != null && value.isNotEmpty()
+ return value != null && value.isNotBlank()
}
-fun checkNotEmptyNThrow(value: String?, message: String? = value.plus(" is null/empty ")): Boolean {
- val notEmpty = value != null && value.isNotEmpty()
+fun checkNotEmptyOrThrow(value: String?, message: String? = value.plus(" is null/empty ")): Boolean {
+ val notEmpty = checkNotEmpty(value)
if (!notEmpty) {
throw BluePrintException(message!!)
}
return notEmpty
}
+fun checkEqualsOrThrow(value1: String?, value2: String?, lazyMessage: () -> Any): Boolean {
+ if (value1.equals(value2, ignoreCase = true)) {
+ return true
+ } else {
+ throw BluePrintException(lazyMessage().toString())
+ }
+}
+
+fun nullToEmpty(value: String?): String {
+ return if (checkNotEmpty(value)) value!! else ""
+}
+
+fun returnNotEmptyOrThrow(value: String?, lazyMessage: () -> Any): String {
+ if (checkNotEmpty(value)) {
+ return value!!
+ } else {
+ throw IllegalStateException(lazyMessage().toString())
+ }
+}
+
fun InputStream.toFile(path: String): File {
val file = File(path)
file.outputStream().use { this.copyTo(it) }
return file
}
-
-
-
-
-
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BlueprintErrorCode.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BlueprintErrorCode.kt
new file mode 100644
index 00000000..bef174b9
--- /dev/null
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BlueprintErrorCode.kt
@@ -0,0 +1,97 @@
+/*
+ * Copyright © 2018-2019 Bell Canada Intellectual Property.
+ *
+ * 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.apps.controllerblueprints.core.data
+
+import java.util.HashMap
+
+/**
+ * ErrorCode.java Purpose: Maintain a list of HTTP status codes
+ *
+ * @author Steve Siani
+ * @version 1.0
+ */
+enum class ErrorCode (val value: Int, val httpCode: Int) {
+
+ /// TODO: Add more attribute for each needed application protocol
+ // TODO: Example: INVALID_FILE_EXTENSION(2, 415, 25)
+ GENERIC_FAILURE(1, 500) {
+ override fun message(detailMsg: String): String {
+ return "Generic failure. Details : {$detailMsg}"
+ }
+ },
+ INVALID_FILE_EXTENSION(2, 415) {
+ override fun message(detailMsg: String): String {
+ return "Unexpected file extension. Details : {$detailMsg}"
+ }
+ },
+ BLUEPRINT_PATH_MISSING(3, 503) {
+ override fun message(detailMsg: String): String {
+ return "Blueprint path missing or wrong. Details : {$detailMsg}"
+ }
+ },
+ BLUEPRINT_WRITING_FAIL(4, 503) {
+ override fun message(detailMsg: String): String {
+ return "Fail to write blueprint files. Details : {$detailMsg}"
+ }
+ },
+ IO_FILE_INTERRUPT(5, 503) {
+ override fun message(detailMsg: String): String {
+ return "IO file system interruption. Details : {$detailMsg}"
+ }
+ },
+ INVALID_REQUEST_FORMAT(6, 400) {
+ override fun message(detailMsg: String): String {
+ return "Bad request. Details : {$detailMsg}"
+ }
+ },
+ UNAUTHORIZED_REQUEST(7, 401) {
+ override fun message(detailMsg: String): String {
+ return "The request requires user authentication. Details : {$detailMsg}"
+ }
+ },
+ REQUEST_NOT_FOUND(8, 404) {
+ override fun message(detailMsg: String): String {
+ return "Request mapping doesn't exist. Details : {$detailMsg}"
+ }
+ },
+ RESOURCE_NOT_FOUND(9, 404) {
+ override fun message(detailMsg: String): String {
+ return "No response was found for this request in the server. Details : {$detailMsg}"
+ }
+ },
+ CONFLICT_ADDING_RESOURCE(10, 409) {
+ override fun message(detailMsg: String): String {
+ return "Duplicated entry while saving Blueprint. Details : {$detailMsg}"
+ }
+ };
+
+ abstract fun message(detailMsg: String): String
+
+ companion object {
+
+ private val map = HashMap<Int, ErrorCode>()
+
+ init {
+ for (errorCode in ErrorCode.values()) {
+ map[errorCode.value] = errorCode
+ }
+ }
+
+ fun valueOf(value: Int): ErrorCode? {
+ return if (map.containsKey(value)) map[value] else map[1]
+ }
+ }
+} \ No newline at end of file
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintCatalogService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintCatalogService.kt
index 9186635e..c99cdf74 100755
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintCatalogService.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintCatalogService.kt
@@ -16,25 +16,44 @@
package org.onap.ccsdk.apps.controllerblueprints.core.interfaces
-interface BluePrintCatalogService {
+import org.jetbrains.annotations.NotNull
+import org.jetbrains.annotations.Nullable
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import java.io.File
+import java.nio.file.Path
- /**
- * Upload the CBA Zip fle to data base and return the Database identifier
- */
- fun uploadToDataBase(file: String, validate : Boolean): String
+interface BluePrintCatalogService {
/**
- * Download the CBA zip file from the data base and place it in a path and return the CBA zip absolute path
+ * Save the CBA to database.
+ * @param blueprintFile Either a directory, or an archive
+ * @param validate whether to validate blueprint content. Default true.
+ * @return The unique blueprint identifier
+ * @throws BluePrintException if process failed
*/
- fun downloadFromDataBase(name: String, version: String, path: String): String
+ @NotNull
+ @Throws(BluePrintException::class)
+ fun saveToDatabase(@NotNull blueprintFile: File, @Nullable validate: Boolean = true): String
/**
- * Get the Blueprint from Data Base and Download it under working directory and return the path path
+ * Retrieve the CBA from database either archived or extracted.
+ * @param name Name of the blueprint
+ * @param version Version of the blueprint
+ * @param extract true to extract the content, false for archived content. Default to true
+ * @return Path where CBA is located
+ * @throws BluePrintException if process failed
*/
- fun prepareBluePrint(name: String, version: String): String
+ @NotNull
+ @Throws(BluePrintException::class)
+ fun getFromDatabase(@NotNull name: String, @NotNull version: String, @Nullable extract: Boolean = true): Path
/**
- * Get blueprint archive with zip file from Data Base
+ * Delete the CBA from database.
+ * @param name Name of the blueprint
+ * @param version Version of the blueprint
+ * @throws BluePrintException if process failed
*/
- fun downloadFromDataBase(uuid: String, path: String): String
+ @NotNull
+ @Throws(BluePrintException::class)
+ fun deleteFromDatabase(@NotNull name: String, @NotNull version: String)
} \ No newline at end of file
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt
index 17837370..b33cc3f0 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt
@@ -523,7 +523,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
@Throws(BluePrintException::class)
open fun validateImplementation(implementation: Implementation) {
- checkNotEmptyNThrow(implementation.primary)
+ checkNotEmptyOrThrow(implementation.primary)
}
@Throws(BluePrintException::class)
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt
index ab5175de..fe7929e8 100755
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt
@@ -24,13 +24,18 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
import org.apache.commons.io.IOUtils
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
-import java.io.*
+import org.slf4j.LoggerFactory
+import java.io.BufferedInputStream
+import java.io.File
+import java.io.FileInputStream
+import java.io.IOException
import java.nio.charset.Charset
import java.util.zip.ZipFile
class BluePrintArchiveUtils {
companion object {
+ private val log = LoggerFactory.getLogger(BluePrintArchiveUtils::class.java)
fun getFileContent(fileName: String): String = runBlocking {
async {
@@ -51,50 +56,20 @@ class BluePrintArchiveUtils {
/**
* Create a new Zip from a root directory
*
- * @param directory the base directory
- * @param filename the output filename
+ * @param source the base directory
+ * @param destination the output filename
* @param absolute store absolute filepath (from directory) or only filename
* @return True if OK
*/
fun compress(source: File, destination: File, absolute: Boolean): Boolean {
- // recursive call
- val zaos: ZipArchiveOutputStream
try {
- zaos = ZipArchiveOutputStream(FileOutputStream(destination))
- } catch (e: FileNotFoundException) {
- return false
- }
-
- try {
- recurseFiles(source, source, zaos, absolute)
- } catch (e2: IOException) {
- try {
- zaos.close()
- } catch (e: IOException) {
- // ignore
+ ZipArchiveOutputStream(destination).use {
+ recurseFiles(source, source, it, absolute)
}
-
+ } catch (e: Exception) {
+ log.error("Fail to compress folder(:$source) to path(${destination.path}", e)
return false
}
-
- try {
- zaos.finish()
- } catch (e1: IOException) {
- // ignore
- }
-
- try {
- zaos.flush()
- } catch (e: IOException) {
- // ignore
- }
-
- try {
- zaos.close()
- } catch (e: IOException) {
- // ignore
- }
-
return true
}
@@ -113,21 +88,19 @@ class BluePrintArchiveUtils {
if (file.isDirectory) {
// recursive call
val files = file.listFiles()
- for (file2 in files!!) {
- recurseFiles(root, file2, zaos, absolute)
+ for (fileChild in files!!) {
+ recurseFiles(root, fileChild, zaos, absolute)
}
} else if (!file.name.endsWith(".zip") && !file.name.endsWith(".ZIP")) {
- var filename: String? = null
- if (absolute) {
- filename = file.absolutePath.substring(root.absolutePath.length)
+ val filename = if (absolute) {
+ file.absolutePath.substring(root.absolutePath.length)
} else {
- filename = file.name
+ file.name
}
val zae = ZipArchiveEntry(filename)
- zae.setSize(file.length())
+ zae.size = file.length()
zaos.putArchiveEntry(zae)
- val fis = FileInputStream(file)
- IOUtils.copy(fis, zaos)
+ FileInputStream(file).use { IOUtils.copy(it, zaos) }
zaos.closeArchiveEntry()
}
}
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtils.kt
index 5a10e43f..9746bf57 100755
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtils.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintFileUtils.kt
@@ -24,6 +24,7 @@ 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.ErrorCode
import org.onap.ccsdk.apps.controllerblueprints.core.data.ImportDefinition
import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
@@ -105,7 +106,8 @@ class BluePrintFileUtils {
val definitionDir = File(definitionPath)
check(definitionDir.exists()) {
- throw BluePrintException("couldn't get definition file under path(${definitionDir.absolutePath})")
+ throw BluePrintException(ErrorCode.BLUEPRINT_PATH_MISSING.value, "couldn't get definition file under " +
+ "path(${definitionDir.absolutePath})")
}
blueprintContext.serviceTemplate.dataTypes?.let {
@@ -192,7 +194,8 @@ class BluePrintFileUtils {
Files.write(definitionFile.toPath(), content.toByteArray(), StandardOpenOption.CREATE_NEW)
check(definitionFile.exists()) {
- throw BluePrintException("couldn't write definition file under path(${definitionFile.absolutePath})")
+ throw BluePrintException(ErrorCode.BLUEPRINT_WRITING_FAIL.value, "couldn't write definition file under " +
+ "path(${definitionFile.absolutePath})")
}
}
@@ -201,7 +204,8 @@ class BluePrintFileUtils {
Files.write(typeFile.toPath(), content.toByteArray(), StandardOpenOption.CREATE_NEW)
check(typeFile.exists()) {
- throw BluePrintException("couldn't write $type.json file under path(${typeFile.absolutePath})")
+ throw BluePrintException(ErrorCode.BLUEPRINT_WRITING_FAIL.value, "couldn't write $type.json file under " +
+ "path(${typeFile.absolutePath})")
}
}
@@ -213,9 +217,21 @@ class BluePrintFileUtils {
"\nTemplate-Tags: <TAGS>"
}
+
+ fun getBluePrintFile(fileName: String, targetPath: Path) : File {
+ val filePath = targetPath.resolve(fileName).toString()
+ val file = File(filePath)
+ check(file.exists()) {
+ throw BluePrintException(ErrorCode.BLUEPRINT_PATH_MISSING.value, "couldn't get definition file under " +
+ "path(${file.absolutePath})")
+ }
+ return file
+ }
+
fun getCbaStorageDirectory(path: String): Path {
check(StringUtils.isNotBlank(path)) {
- throw BluePrintException("CBA Path is missing.")
+ throw BluePrintException(ErrorCode.BLUEPRINT_PATH_MISSING.value, "couldn't get " +
+ "Blueprint folder under path($path)")
}
val fileStorageLocation = Paths.get(path).toAbsolutePath().normalize()
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt
index 6321a838..2e5a040c 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt
@@ -33,9 +33,11 @@ import kotlinx.coroutines.withContext
import org.apache.commons.io.IOUtils
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
import java.io.File
import java.nio.charset.Charset
+import kotlin.reflect.jvm.internal.impl.load.kotlin.JvmType
/**
*
@@ -174,8 +176,13 @@ class JacksonUtils {
return getMapFromJson(content, valueType)
}
+ fun <T> getInstanceFromMap(properties: MutableMap<String, JsonNode>, classType: Class<T>): T {
+ return readValue(getJson(properties), classType)
+ ?: throw BluePrintProcessorException("failed to transform content ($properties) to type ($classType)")
+ }
+
fun checkJsonNodeValueOfType(type: String, jsonNode: JsonNode): Boolean {
- if (BluePrintTypes.validPrimitiveTypes().contains(type)) {
+ if (BluePrintTypes.validPrimitiveTypes().contains(type.toLowerCase())) {
return checkJsonNodeValueOfPrimitiveType(type, jsonNode)
} else if (BluePrintTypes.validCollectionTypes().contains(type)) {
return checkJsonNodeValueOfCollectionType(type, jsonNode)
@@ -183,59 +190,76 @@ class JacksonUtils {
return false
}
+ fun checkIfPrimitiveType(primitiveType: String): Boolean {
+ return when (primitiveType.toLowerCase()) {
+ BluePrintConstants.DATA_TYPE_STRING -> true
+ BluePrintConstants.DATA_TYPE_BOOLEAN -> true
+ BluePrintConstants.DATA_TYPE_INTEGER -> true
+ BluePrintConstants.DATA_TYPE_FLOAT -> true
+ BluePrintConstants.DATA_TYPE_DOUBLE -> true
+ BluePrintConstants.DATA_TYPE_TIMESTAMP -> true
+ else -> false
+ }
+ }
+
fun checkJsonNodeValueOfPrimitiveType(primitiveType: String, jsonNode: JsonNode): Boolean {
- when (primitiveType) {
- BluePrintConstants.DATA_TYPE_STRING -> return jsonNode.isTextual
- BluePrintConstants.DATA_TYPE_BOOLEAN -> return jsonNode.isBoolean
- BluePrintConstants.DATA_TYPE_INTEGER -> return jsonNode.isInt
- BluePrintConstants.DATA_TYPE_FLOAT -> return jsonNode.isDouble
- BluePrintConstants.DATA_TYPE_TIMESTAMP -> return jsonNode.isTextual
- else -> return false
+ return when (primitiveType.toLowerCase()) {
+ BluePrintConstants.DATA_TYPE_STRING -> jsonNode.isTextual
+ BluePrintConstants.DATA_TYPE_BOOLEAN -> jsonNode.isBoolean
+ BluePrintConstants.DATA_TYPE_INTEGER -> jsonNode.isInt
+ BluePrintConstants.DATA_TYPE_FLOAT -> jsonNode.isDouble
+ BluePrintConstants.DATA_TYPE_DOUBLE -> jsonNode.isDouble
+ BluePrintConstants.DATA_TYPE_TIMESTAMP -> jsonNode.isTextual
+ else -> false
}
}
fun checkJsonNodeValueOfCollectionType(type: String, jsonNode: JsonNode): Boolean {
- when (type) {
- BluePrintConstants.DATA_TYPE_LIST -> return jsonNode.isArray
- BluePrintConstants.DATA_TYPE_MAP -> return jsonNode.isContainerNode
- else -> return false
+ return when (type.toLowerCase()) {
+ BluePrintConstants.DATA_TYPE_LIST -> jsonNode.isArray
+ BluePrintConstants.DATA_TYPE_MAP -> jsonNode.isContainerNode
+ else -> false
}
}
fun populatePrimitiveValues(key: String, value: Any, primitiveType: String, objectNode: ObjectNode) {
- when (primitiveType) {
+ when (primitiveType.toLowerCase()) {
BluePrintConstants.DATA_TYPE_BOOLEAN -> objectNode.put(key, value as Boolean)
BluePrintConstants.DATA_TYPE_INTEGER -> objectNode.put(key, value as Int)
BluePrintConstants.DATA_TYPE_FLOAT -> objectNode.put(key, value as Float)
+ BluePrintConstants.DATA_TYPE_DOUBLE -> objectNode.put(key, value as Double)
BluePrintConstants.DATA_TYPE_TIMESTAMP -> objectNode.put(key, value as String)
else -> objectNode.put(key, value as String)
}
}
fun populatePrimitiveValues(value: Any, primitiveType: String, arrayNode: ArrayNode) {
- when (primitiveType) {
+ when (primitiveType.toLowerCase()) {
BluePrintConstants.DATA_TYPE_BOOLEAN -> arrayNode.add(value as Boolean)
BluePrintConstants.DATA_TYPE_INTEGER -> arrayNode.add(value as Int)
BluePrintConstants.DATA_TYPE_FLOAT -> arrayNode.add(value as Float)
+ BluePrintConstants.DATA_TYPE_DOUBLE -> arrayNode.add(value as Double)
BluePrintConstants.DATA_TYPE_TIMESTAMP -> arrayNode.add(value as String)
else -> arrayNode.add(value as String)
}
}
fun populatePrimitiveDefaultValues(key: String, primitiveType: String, objectNode: ObjectNode) {
- when (primitiveType) {
+ when (primitiveType.toLowerCase()) {
BluePrintConstants.DATA_TYPE_BOOLEAN -> objectNode.put(key, false)
BluePrintConstants.DATA_TYPE_INTEGER -> objectNode.put(key, 0)
BluePrintConstants.DATA_TYPE_FLOAT -> objectNode.put(key, 0.0)
+ BluePrintConstants.DATA_TYPE_DOUBLE -> objectNode.put(key, 0.0)
else -> objectNode.put(key, "")
}
}
fun populatePrimitiveDefaultValuesForArrayNode(primitiveType: String, arrayNode: ArrayNode) {
- when (primitiveType) {
+ when (primitiveType.toLowerCase()) {
BluePrintConstants.DATA_TYPE_BOOLEAN -> arrayNode.add(false)
BluePrintConstants.DATA_TYPE_INTEGER -> arrayNode.add(0)
BluePrintConstants.DATA_TYPE_FLOAT -> arrayNode.add(0.0)
+ BluePrintConstants.DATA_TYPE_DOUBLE -> arrayNode.add(0.0)
else -> arrayNode.add("")
}
}
@@ -250,13 +274,15 @@ class JacksonUtils {
}
}
- fun convertPrimitiveResourceValue(type: String, value: String): JsonNode? {
- when (type) {
- BluePrintConstants.DATA_TYPE_BOOLEAN -> return JacksonUtils.getJsonNode(value as Boolean)
- BluePrintConstants.DATA_TYPE_INTEGER -> return JacksonUtils.getJsonNode(value as Int)
- BluePrintConstants.DATA_TYPE_FLOAT -> return JacksonUtils.getJsonNode(value as Float)
- else -> return JacksonUtils.getJsonNode(value)
+ fun convertPrimitiveResourceValue(type: String, value: String): JsonNode {
+ return when (type.toLowerCase()) {
+ BluePrintConstants.DATA_TYPE_BOOLEAN -> jsonNodeFromObject(java.lang.Boolean.valueOf(value))
+ BluePrintConstants.DATA_TYPE_INTEGER -> jsonNodeFromObject(Integer.valueOf(value))
+ BluePrintConstants.DATA_TYPE_FLOAT -> jsonNodeFromObject(java.lang.Float.valueOf(value))
+ BluePrintConstants.DATA_TYPE_DOUBLE -> jsonNodeFromObject(java.lang.Double.valueOf(value))
+ else -> getJsonNode(value)
}
}
+
}
} \ No newline at end of file
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTypeValidatorImpl.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTypeValidatorImpl.kt
index 2e4a733a..1077f347 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTypeValidatorImpl.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTypeValidatorImpl.kt
@@ -20,7 +20,7 @@ import com.att.eelf.configuration.EELFLogger
import com.att.eelf.configuration.EELFManager
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
-import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyNThrow
+import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow
import org.onap.ccsdk.apps.controllerblueprints.core.data.*
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTypeValidator
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
@@ -149,7 +149,7 @@ open class BluePrintNodeTypeValidatorImpl(private val bluePrintTypeValidatorServ
}
open fun validateImplementation(implementation: Implementation) {
- checkNotEmptyNThrow(implementation.primary)
+ checkNotEmptyOrThrow(implementation.primary)
}
} \ No newline at end of file
diff --git a/components/core/src/test/resources/dictionary/dictionary_schema.json b/components/core/src/test/resources/dictionary/dictionary_schema.json
index d0317005..f9ef9eee 100644
--- a/components/core/src/test/resources/dictionary/dictionary_schema.json
+++ b/components/core/src/test/resources/dictionary/dictionary_schema.json
@@ -104,7 +104,7 @@
}
}
},
- "db": {
+ "primary-db": {
"type": "object",
"properties": {
"query": {
@@ -210,7 +210,7 @@
}
}
},
- "db": {
+ "primary-db": {
"type": "object",
"properties": {
"names": {