From e931e43bb97c63d5c68f2c5626f4432ca25b3456 Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Thu, 11 Mar 2021 21:24:22 +0530 Subject: [PATCH] Extract to case class Signed-off-by: Rahul Rudragoudar --- src/main/scala/lc/core/config.scala | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/scala/lc/core/config.scala b/src/main/scala/lc/core/config.scala index eabd373..2bf02be 100644 --- a/src/main/scala/lc/core/config.scala +++ b/src/main/scala/lc/core/config.scala @@ -1,9 +1,8 @@ package lc.core import scala.io.Source.fromFile -import org.json4s.{DefaultFormats, JValue, JObject, JField} +import org.json4s.{DefaultFormats, JValue, JObject, JField, JString} import org.json4s.jackson.JsonMethods.parse -import scala.collection.immutable.HashMap object Config { @@ -20,12 +19,15 @@ object Config { val seed: Int = (configJson \ "randomSeed").extract[Int] val captchaExpiryTimeLimit: Int = (configJson \ "captchaExpiryTimeLimit").extract[Int] val threadDelay: Int = (configJson \ "threadDelay").extract[Int] - private val captchaConfig = (configJson \ "captchas") - val captchaConfigMap: Map[String,HashMap[String,List[String]]] = captchaConfig.values.asInstanceOf[Map[String, HashMap[String, List[String]]]] - val supportedLevels: Set[String] = getAllValues(configJson, "supportedLevels") - val supportedMedia: Set[String] = getAllValues(configJson, "supportedMedia") - val supportedinputType: Set[String] = getAllValues(configJson, "supportedinputType") + private val captchaConfigJson = (configJson \ "captchas") + val captchaConfigTransform: JValue = captchaConfigJson transformField { + case JField("config", JObject(config)) => ("config", JString(config.toString)) + } + val captchaConfig: List[CaptchaConfig] = captchaConfigTransform.extract[List[CaptchaConfig]] + val allowedLevels: Set[String] = getAllValues(configJson, ParametersEnum.ALLOWEDLEVELS.toString) + val allowedMedia: Set[String] = getAllValues(configJson, ParametersEnum.ALLOWEDMEDIA.toString) + val allowedInputType: Set[String] = getAllValues(configJson, ParametersEnum.ALLOWEDINPUTTYPE.toString) private def getAllValues(config: JValue, param: String): Set[String] = { val configValues = (config \\ param)