summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/blueprint-core
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-04-03 21:36:57 -0400
committerMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-04-04 08:09:16 -0400
commit0007063cc856483e36dd49718dea5dda80ed6809 (patch)
treef97d43008e4f0d816a8041b02e5d986cc5f3557e /ms/controllerblueprints/modules/blueprint-core
parenta2a21cd7a80c3ff3b754d7a4e47fc48f45ff2312 (diff)
Improve step data access.
Change-Id: I3917905b1e38cebcb26e4422784a5553e2dbac9f Issue-ID: CCSDK-1127 Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/blueprint-core')
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt46
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/FileExtensionFunctions.kt7
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintValidatorService.kt2
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/ResourceResolverUtils.kt6
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)