Skip to content

Commit ff268fc

Browse files
author
Derek Smart
committed
environments have actions
Signed-off-by: Derek Smart <derek.smart@delphix.com>
1 parent d423199 commit ff268fc

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
package com.delphix.yamlparser
22

3+
import com.fasterxml.jackson.databind.JsonNode;
4+
35
data class Action (
4-
val condition: String,
5-
val then: String
6-
)
6+
val event: String,
7+
val action: String
8+
){
9+
companion object {
10+
@JvmStatic
11+
fun mapFromNode(node: JsonNode): Action {
12+
val name = Mapper().getNodeName(node)
13+
val action = Action(
14+
"$name",
15+
node["$name"].asText()
16+
)
17+
return action
18+
}
19+
}
20+
}

src/main/kotlin/com/delphix/yamlparser/Connector.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ data class Connector(
1313
companion object {
1414
@JvmStatic
1515
fun mapFromNode(node: JsonNode): Connector {
16-
val it: Iterator<String> = node.fieldNames()
17-
var name: String = ""
18-
while (it.hasNext()) {
19-
name = it.next()
20-
}
16+
val name = Mapper().getNodeName(node)
2117
val connector = Connector(
2218
"$name",
2319
node["$name"]["host"].asText(),

src/main/kotlin/com/delphix/yamlparser/DataSource.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ data class DataSource(
1313
companion object {
1414
@JvmStatic
1515
fun mapFromNode(node: JsonNode): DataSource {
16-
val it: Iterator<String> = node.fieldNames()
17-
var name: String = ""
18-
while (it.hasNext()) {
19-
name = it.next()
20-
}
16+
val name = Mapper().getNodeName(node)
2117
val dataSource = DataSource(
2218
"$name",
2319
node["$name"]["notes"].asText(),

src/main/kotlin/com/delphix/yamlparser/Environment.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,17 @@ data class Environment(
66
val name: String,
77
val branch: String,
88
val datapod: String,
9-
val ami: String?= null
9+
val actions: List<Action>
1010
) {
1111
companion object {
1212
@JvmStatic
13-
fun mapFromNode(node: JsonNode): Environment {
14-
val it: Iterator<String> = node.fieldNames()
15-
var name: String = ""
16-
while (it.hasNext()) {
17-
name = it.next()
18-
}
13+
fun mapFromNode(node: JsonNode, actionList: MutableList<Action>): Environment {
14+
val name = Mapper().getNodeName(node)
1915
val environment = Environment(
2016
"$name",
2117
node["$name"]["branch"]?.asText() ?: "",
2218
node["$name"]["datapod"]?.asText() ?: "",
23-
node["$name"]["ami"]?.asText()
19+
actionList
2420
)
2521
return environment
2622
}

src/main/kotlin/com/delphix/yamlparser/Mapper.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ class Mapper {
1515
fun mapEnvironments(environments: JsonNode): MutableList<Environment> {
1616
var environmentsList = mutableListOf<Environment>()
1717
for (environment in environments) {
18-
environmentsList.add(Environment.mapFromNode(environment))
18+
var actionsList = mutableListOf<Action>()
19+
val name = Mapper().getNodeName(environment)
20+
for(action in environment["$name"]["when"]) {
21+
actionsList.add(Action.mapFromNode(action))
22+
}
23+
environmentsList.add(Environment.mapFromNode(environment, actionsList))
1924
}
2025
return environmentsList
2126
}

0 commit comments

Comments
 (0)