File tree Expand file tree Collapse file tree 5 files changed +29
-22
lines changed
src/main/kotlin/com/delphix/yamlparser Expand file tree Collapse file tree 5 files changed +29
-22
lines changed Original file line number Diff line number Diff line change 11package com.delphix.yamlparser
22
3+ import com.fasterxml.jackson.databind.JsonNode;
4+
35data 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+ }
Original file line number Diff line number Diff 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(),
Original file line number Diff line number Diff 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(),
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments