summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-04-04 14:39:36 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-04 14:39:36 +0000
commit4002c9b2afb3f6c71ad97c5031e98c72940e256f (patch)
tree6e8b8957b74932c4f2c6acf54c47a8606de8a537 /ms/controllerblueprints
parent835c347f632c32d67ad5051b8dd93b059e1eadaf (diff)
parent0007063cc856483e36dd49718dea5dda80ed6809 (diff)
Merge "Improve step data access."
Diffstat (limited to 'ms/controllerblueprints')
-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
-rw-r--r--ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintNodeTypeValidatorImpl.kt6
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt11
6 files changed, 46 insertions, 32 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)
diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintNodeTypeValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintNodeTypeValidatorImpl.kt
index 10804e48d..3d3122c61 100644
--- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintNodeTypeValidatorImpl.kt
+++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintNodeTypeValidatorImpl.kt
@@ -20,7 +20,7 @@ package org.onap.ccsdk.cds.controllerblueprints.validation
import org.slf4j.LoggerFactory
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
-import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmptyOrThrow
+import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
import org.onap.ccsdk.cds.controllerblueprints.core.data.*
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintNodeTypeValidator
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
@@ -35,7 +35,7 @@ import org.springframework.stereotype.Service
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
open class BluePrintNodeTypeValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintNodeTypeValidator {
- private val log= LoggerFactory.getLogger(BluePrintServiceTemplateValidatorImpl::class.toString())
+ private val log = LoggerFactory.getLogger(BluePrintServiceTemplateValidatorImpl::class.toString())
lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
lateinit var bluePrintContext: BluePrintContext
@@ -161,7 +161,7 @@ open class BluePrintNodeTypeValidatorImpl(private val bluePrintTypeValidatorServ
}
open fun validateImplementation(implementation: Implementation) {
- checkNotEmptyOrThrow(implementation.primary)
+ checkNotEmpty(implementation.primary) { "couldn't get implementation" }
}
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt
index df8cffdba..e339bcd68 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt
@@ -21,7 +21,7 @@ import com.google.common.base.Preconditions
import org.apache.commons.collections.CollectionUtils
import org.apache.commons.lang3.StringUtils
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
-import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmptyOrThrow
+import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory
import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary
@@ -137,12 +137,11 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour
}
private fun validateResourceDictionary(resourceDictionary: ResourceDictionary): Boolean {
- checkNotEmptyOrThrow(resourceDictionary.name, "DataDictionary Definition name is missing.")
+ checkNotEmpty(resourceDictionary.name){ "DataDictionary Definition name is missing."}
checkNotNull(resourceDictionary.definition) { "DataDictionary Definition Information is missing." }
- checkNotEmptyOrThrow(resourceDictionary.description, "DataDictionary Definition Information is missing.")
- checkNotEmptyOrThrow(resourceDictionary.tags, "DataDictionary Definition tags is missing.")
- checkNotEmptyOrThrow(resourceDictionary.updatedBy, "DataDictionary Definition updatedBy is missing.")
+ checkNotEmpty(resourceDictionary.description){ "DataDictionary Definition Information is missing."}
+ checkNotEmpty(resourceDictionary.tags){ "DataDictionary Definition tags is missing."}
+ checkNotEmpty(resourceDictionary.updatedBy){ "DataDictionary Definition updatedBy is missing."}
return true
-
}
} \ No newline at end of file