Commit 8a392cb4 authored by Peter van 't Hof's avatar Peter van 't Hof

Moved fileToConfigMap to utils

parent a5e6b563
......@@ -3,8 +3,6 @@ package nl.lumc.sasc.biopet.core.config
import java.io.File
import nl.lumc.sasc.biopet.core.Logging
import nl.lumc.sasc.biopet.utils.ConfigUtils._
import argonaut._, Argonaut._
import scalaz._, Scalaz._
class Config(var map: Map[String, Any]) extends Logging {
logger.debug("Init phase of config")
......@@ -30,18 +28,10 @@ class Config(var map: Map[String, Any]) extends Logging {
}
def loadConfigFile(configFile: File) {
logger.debug("Jsonfile: " + configFile)
val jsonText = scala.io.Source.fromFile(configFile).mkString
val json = Parse.parseOption(jsonText)
if (json == None) {
throw new IllegalStateException("The config JSON file is either not properly formatted or not a JSON file, file: " + configFile)
}
logger.debug(json)
val configJson = jsonToMap(json.get)
logger.debug("Contain: " + configJson)
val configMap = fileToConfigMap(configFile)
if (map.isEmpty) map = configJson
else map = mergeMaps(configJson, map)
if (map.isEmpty) map = configMap
else map = mergeMaps(configMap, map)
logger.debug("New config: " + map)
}
......
......@@ -27,6 +27,19 @@ object ConfigUtils extends Logging {
return newMap
}
def fileToConfigMap(configFile: File): Map[String, Any] = {
logger.debug("Jsonfile: " + configFile)
val jsonText = scala.io.Source.fromFile(configFile).mkString
val json = Parse.parseOption(jsonText)
if (json == None) {
throw new IllegalStateException("The config JSON file is either not properly formatted or not a JSON file, file: " + configFile)
}
logger.debug(json)
val configJson = jsonToMap(json.get)
logger.debug("Contain: " + configJson)
return configJson
}
def jsonToMap(json: Json): Map[String, Any] = {
var output: Map[String, Any] = Map()
if (json.isObject) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment