aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/blueprints/blueprint-core
diff options
context:
space:
mode:
Diffstat (limited to 'ms/blueprintsprocessor/modules/blueprints/blueprint-core')
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintError.kt18
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintContext.kt10
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintErrorTest.kt12
3 files changed, 26 insertions, 14 deletions
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintError.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintError.kt
index b4d95ca3b..2ecdce770 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintError.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintError.kt
@@ -18,13 +18,21 @@ package org.onap.ccsdk.cds.controllerblueprints.core
class BlueprintError {
- var errors: MutableList<String> = arrayListOf()
+ private val errors: MutableMap<String, MutableList<String>> = mutableMapOf()
- fun addError(type: String, name: String, error: String) {
- this.errors.add("$type : $name : $error")
+ fun addError(type: String, name: String, error: String, stepName: String) {
+ addError("$type : $name : $error", stepName)
}
- fun addError(error: String) {
- this.errors.add(error)
+ fun addError(error: String, stepName: String) {
+ errors.getOrPut(stepName, { mutableListOf() }).add(error)
}
+
+ fun addErrors(stepName: String, errorList: List<String>) {
+ errors.getOrPut(stepName, { mutableListOf() }).addAll(errorList)
+ }
+
+ fun allErrors(): List<String> = errors.values.flatten()
+
+ fun stepErrors(stepName: String): MutableList<String>? = errors[stepName]
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintContext.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintContext.kt
index b79b86747..62026be88 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintContext.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintContext.kt
@@ -103,8 +103,11 @@ class BlueprintContext(val serviceTemplate: ServiceTemplate) {
fun workflowInputs(workFlowName: String) = workflowByName(workFlowName).inputs
+ fun workflowSteps(workFlowName: String) =
+ workflowByName(workFlowName).steps ?: throw BlueprintException("could't get steps for workflow($workFlowName)")
+
fun workflowStepByName(workFlowName: String, stepName: String): Step {
- return workflowByName(workFlowName).steps?.get(stepName)
+ return workflowSteps(workFlowName)[stepName]
?: throw BlueprintException("could't get step($stepName) for workflow($workFlowName)")
}
@@ -114,8 +117,9 @@ class BlueprintContext(val serviceTemplate: ServiceTemplate) {
}
fun workflowFirstStepNodeTemplate(workFlowName: String): String {
- val firstStepName = workflowByName(workFlowName).steps?.keys?.first()
- ?: throw BlueprintException("could't get first step for workflow($workFlowName)")
+ val firstStepName = workflowSteps(workFlowName).keys.ifEmpty {
+ throw BlueprintException("could't get first step for workflow($workFlowName)")
+ }.first()
return workflowStepNodeTemplate(workFlowName, firstStepName)
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintErrorTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintErrorTest.kt
index 482d21abd..94ba98603 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintErrorTest.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintErrorTest.kt
@@ -10,24 +10,24 @@ class BlueprintErrorTest {
fun testBlueprintErrorIsCreatedWithemptyList() {
val bluePrintError = BlueprintError()
- assertTrue(bluePrintError.errors.isEmpty())
+ assertTrue(bluePrintError.allErrors().isEmpty())
}
@Test
fun testAddErrorWith3Params() {
val bluePrintError = BlueprintError()
- bluePrintError.addError("type", "name", "error")
+ bluePrintError.addError("type", "name", "error", "step")
- assertEquals("type : name : error", bluePrintError.errors[0])
+ assertEquals("type : name : error", bluePrintError.stepErrors("step")!![0])
}
@Test
- fun testAddErrorWith1Params() {
+ fun testAddErrorWith2Params() {
val bluePrintError = BlueprintError()
- bluePrintError.addError("error")
+ bluePrintError.addError("error", "step")
- assertEquals("error", bluePrintError.errors[0])
+ assertEquals("error", bluePrintError.stepErrors("step")!![0])
}
}