Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing global mapping bug from 1.8.3 #269

Merged
merged 1 commit into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ trait PipelineStepMapper {
* @param pipelineContext The pipelineContext
* @return A map with substituted values
*/
private def mapEmbeddedVariables(classMap: Map[String, Any], pipelineContext: PipelineContext): Map[String, Any] = {
private[pipeline] def mapEmbeddedVariables(classMap: Map[String, Any], pipelineContext: PipelineContext): Map[String, Any] = {
implicit val formats: Formats = pipelineContext.getJson4sFormats
classMap.foldLeft(classMap)((map, entry) => {
entry._2 match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,8 @@ object ApplicationUtils {
defaultGlobals: Option[Map[String, Any]],
pipelineContext: PipelineContext,
merge: Boolean = false)(implicit formats: Formats): Option[Map[String, Any]] = {
globals.map { baseGlobals =>
val result = rootGlobals ++ baseGlobals.map{
case (key, m: Map[String, Any]) if m.contains("className") =>
key -> Parameter(Some("object"), Some(key), value = m.get("object"), className = m.get("className").map(_.toString))
case (key, l: List[Any]) => key -> Parameter(Some("list"), Some(key), value = Some(l))
case (key, value) => key -> Parameter(Some("text"), Some(key), value = Some(value))
}.map{
case ("GlobalLinks", p) => "GlobalLinks" -> p.value.get // skip global links
case (key, p) => key -> pipelineContext.parameterMapper.mapParameter(p, pipelineContext)
}
// val result = baseGlobals.foldLeft(rootGlobals)((rootMap, entry) => parseValue(rootMap, entry._1, entry._2))
globals.map{ baseGlobals =>
val result = baseGlobals.foldLeft(rootGlobals)((rootMap, entry) => parseValue(rootMap, entry._1, entry._2, Some(pipelineContext)))
if (merge) {
defaultGlobals.getOrElse(Map[String, Any]()) ++ result
} else {
Expand All @@ -299,21 +290,33 @@ object ApplicationUtils {
.foldLeft(Map[String, Any]("credentialProvider" -> credentialProvider))((rootMap, entry) => parseValue(rootMap, entry._1, entry._2))
}

private def parseValue(rootMap: Map[String, Any], key: String, value: Any)(implicit formats: Formats) = {
private def parseValue(rootMap: Map[String, Any], key: String, value: Any, ctx: Option[PipelineContext] = None)(implicit formats: Formats) = {
value match {
case map: Map[String, Any] if map.contains("className") =>
val obj = DriverUtils.parseJson(Serialization.write(map("object").asInstanceOf[Map[String, Any]]), map("className").asInstanceOf[String])
val mapEmbedded = map.get("mapEmbeddedVariables").exists(_.toString.toBoolean) && ctx.isDefined
val finalMap = if (mapEmbedded) {
ctx.get.parameterMapper.mapEmbeddedVariables(map("object").asInstanceOf[Map[String, Any]], ctx.get)
} else {
map("object").asInstanceOf[Map[String, Any]]
}
val obj = DriverUtils.parseJson(Serialization.write(finalMap), map("className").asInstanceOf[String])
rootMap + (key -> obj)
case listMap: List[Any] =>
val obj = listMap.map {
case m: Map[String, Any] =>
if (m.contains("className")) {
val mapEmbedded = m.get("mapEmbeddedVariables").exists(_.toString.toBoolean) && ctx.isDefined
val map = if (m.contains("parameters")) {
m("parameters").asInstanceOf[Map[String, Any]]
} else {
m("object").asInstanceOf[Map[String, Any]]
}
DriverUtils.parseJson(Serialization.write(map), m("className").asInstanceOf[String])
val finalMap = if (mapEmbedded) {
ctx.get.parameterMapper.mapEmbeddedVariables(map, ctx.get)
} else {
map
}
DriverUtils.parseJson(Serialization.write(finalMap), m("className").asInstanceOf[String])
} else {
m
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class ApplicationTests extends FunSpec with BeforeAndAfterAll with Suite {
assert(globals.contains("rootLogLevel"))
assert(globals.contains("rootLogLevel"))
assert(globals.contains("number"))
assert(globals("number").asInstanceOf[Int] == 5)
assert(globals("number").asInstanceOf[BigInt] == 5)
assert(globals.contains("float"))
assert(globals("float").asInstanceOf[Double] == 1.5)
assert(globals.contains("string"))
Expand Down Expand Up @@ -452,7 +452,7 @@ class ApplicationTests extends FunSpec with BeforeAndAfterAll with Suite {
assert(globals.contains("rootLogLevel"))
assert(globals.contains("rootLogLevel"))
assert(globals.contains("number"))
assert(globals("number").asInstanceOf[Int] == 2)
assert(globals("number").asInstanceOf[BigInt] == 2)
assert(globals.contains("float"))
assert(globals("float").asInstanceOf[Double] == 3.5)
assert(globals.contains("string"))
Expand Down Expand Up @@ -492,7 +492,7 @@ class ApplicationTests extends FunSpec with BeforeAndAfterAll with Suite {
assert(globals1.contains("rootLogLevel"))
assert(globals1.contains("rootLogLevel"))
assert(globals1.contains("number"))
assert(globals1("number").asInstanceOf[Int] == 1)
assert(globals1("number").asInstanceOf[BigInt] == 1)
assert(globals1.contains("float"))
assert(globals1("float").asInstanceOf[Double] == 1.5)
assert(globals1.contains("string"))
Expand Down Expand Up @@ -565,7 +565,7 @@ class ApplicationTests extends FunSpec with BeforeAndAfterAll with Suite {
assert(globals.contains("rootLogLevel"))
assert(globals.contains("rootLogLevel"))
assert(globals.contains("number"))
assert(globals("number").asInstanceOf[Int] == 2)
assert(globals("number").asInstanceOf[BigInt] == 2)
assert(globals.contains("float"))
assert(globals("float").asInstanceOf[Double] == 3.5)
assert(globals.contains("string"))
Expand Down