diff options
Diffstat (limited to 'ms/controllerblueprints/modules/blueprint-core')
4 files changed, 38 insertions, 23 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt index d409b136a..0493deb5e 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt @@ -127,19 +127,7 @@ fun MutableMap<String, JsonNode>.getAsDouble(key: String): Double { // Checks -fun checkNotEmpty(value: String?): Boolean { - return value != null && value.isNotBlank() -} - -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 { +inline fun checkEquals(value1: String?, value2: String?, lazyMessage: () -> Any): Boolean { if (value1.equals(value2, ignoreCase = true)) { return true } else { @@ -147,15 +135,35 @@ fun checkEqualsOrThrow(value1: String?, value2: String?, lazyMessage: () -> Any) } } -fun nullToEmpty(value: String?): String { - return if (checkNotEmpty(value)) value!! else "" +inline fun checkNotEmpty(value: String?, lazyMessage: () -> Any): String { + if (value == null || value.isEmpty()) { + val message = lazyMessage() + throw IllegalStateException(message.toString()) + } else { + return value + } } -fun returnNotEmptyOrThrow(value: String?, lazyMessage: () -> Any): String { - if (checkNotEmpty(value)) { - return value!! +inline fun checkNotBlank(value: String?, lazyMessage: () -> Any): String { + if (value == null || value.isBlank()) { + val message = lazyMessage() + throw IllegalStateException(message.toString()) } else { - throw IllegalStateException(lazyMessage().toString()) + return value } } +fun isNotEmpty(value: String?): Boolean { + return value != null && value.isNotEmpty() +} + +fun isNotBlank(value: String?): Boolean { + return value != null && value.isNotBlank() +} + + +fun nullToEmpty(value: String?): String { + return if (isNotEmpty(value)) value!! else "" +} + + diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/FileExtensionFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/FileExtensionFunctions.kt index bda60ea73..5d84854e5 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/FileExtensionFunctions.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/FileExtensionFunctions.kt @@ -72,6 +72,13 @@ fun deleteDir(path: String, vararg more: String?) { normalizedFile(path, *more).deleteRecursively() } +fun checkFileExists(file: File, lazyMessage: () -> Any) { + if (!file.exists()) { + val message = lazyMessage() + throw IllegalStateException(message.toString()) + } +} + fun normalizedFile(path: String, vararg more: String?): File { return Paths.get(path, *more).toFile().normalize() } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintValidatorService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintValidatorService.kt index e74a8e9cc..d3dd30224 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintValidatorService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintValidatorService.kt @@ -523,7 +523,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { @Throws(BluePrintException::class) open fun validateImplementation(implementation: Implementation) { - checkNotEmptyOrThrow(implementation.primary) + checkNotEmpty(implementation.primary) { "couldn't get implementation" } } @Throws(BluePrintException::class) diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/ResourceResolverUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/ResourceResolverUtils.kt index f26e7ae20..f06cc107d 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/ResourceResolverUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/ResourceResolverUtils.kt @@ -17,9 +17,9 @@ package org.onap.ccsdk.cds.controllerblueprints.core.utils -import org.slf4j.LoggerFactory import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty +import org.onap.ccsdk.cds.controllerblueprints.core.isNotEmpty +import org.slf4j.LoggerFactory import java.io.File import java.net.URL @@ -45,7 +45,7 @@ object ResourceResolverUtils { } } else { if (!filename.startsWith("/")) { - if (checkNotEmpty(basePath)) { + if (isNotEmpty(basePath)) { resolvedFileName = basePath.plus(File.separator).plus(filename) } else { resolvedFileName = javaClass.classLoader.getResource(".").path.plus(filename) |