2016-09-20 60 views
-1

我要根據所提供的fileType和公司名稱讀取播放應用程序配置文件

def getEmailAddresses(fileType: String, companyName: String): List[String] = { 
    val xz = Play.application.configuration.getConfigList("email_list") 
    println(xz) 
} 

我上面的功能是給我配置的一些複雜的列表是不容易穿越獲取電子郵件ID列表。

我基本上想List[String]這只是電子郵件ID列表。

例如,給定的參數:

  • 的fileType = test_2
  • 的companyName = Company2的

欲獲得字符串"[email protected], [email protected]" 可以由.split(",").toList

被轉換爲List[String]這可以簡化嗎?

以下是Scala播放應用

email_list = [ 
    { 
    file0 : "[email protected],[email protected]" 
    }, 
    { 
    file1 : [ 
     {"company1" : "[email protected]"}, 
     {"company2" : "[email protected]"}, 
     {"company3" : "[email protected]"} 
    ] 
    }, 
    { 
    top2 = [ 
     {"company1": "[email protected],[email protected]"}, 
     {"company2": "[email protected],[email protected]"}, 
     {"company3": "[email protected],[email protected]"} 
    ] 
    }, 
    { 
    test_2 = [ 
     {"company1": "[email protected],[email protected]"}, 
     {"company2": "[email protected],[email protected]"}, 
     {"company3": "[email protected],[email protected]"} 
    ] 
    }, 
    { 
    xyz_7 = [ 
     {"company1": "[email protected],[email protected]"}, 
     {"company2": "[email protected],[email protected]"}, 
     {"company3": "[email protected],[email protected]"} 
    ] 
    }, 
    { 
    abc_def = [ 
     {"company1": "[email protected],[email protected]"}, 
     {"company2": "[email protected],[email protected]"}, 
     {"company3": "[email protected],[email protected]"} 
    ] 
    } 
] 
+0

如果你正在從'application.conf'中讀取它,爲什麼你不以一種更簡單的方式構造它來讀/橫? – Salem

+0

@Salem更好的可讀性我已經基於file_types模塊化它。 – prasshant

回答

0

我已經做HOCON語法一些試驗,發現下面的代碼+配置是工作我application.conf文件

代碼

def getEmailAddresses(fileType: String, companyName: String): List[String] = { 
     // fileType = "file1" 
     // companyName = "company1" 

     val file0 = Play.application.configuration.getString("email_list.file0") 
     println(file0) 

     val file1_company1 = Play.application.configuration.getString(s"email_list.${fileType}.${companyName}") 
     println(file1_company1) 
    } 

application conf

email_list { 

    file0 = "[email protected],[email protected]" 

    file1 { 
     company1 = "[email protected]" 
     company2 = "[email protected]" 
     company3 = "[email protected]" 
    } 

    top2 { 
     company1 = "[email protected],[email protected]" 
     company2 = "[email protected],[email protected]" 
     company3 = "[email protected],[email protected]" 
    } 

    test_2 { 
     company1 = "[email protected],[email protected]" 
     company2 = "[email protected],[email protected]" 
     company3 = "[email protected],[email protected]" 
    } 

    xyz_7 { 
     company1 = "[email protected],[email protected]" 
     company2 = "[email protected],[email protected]" 
     company3 = "[email protected],[email protected]" 
    } 

    abc_def { 
     company1 = "[email protected],[email protected]" 
     company2 = "[email protected],[email protected]" 
     company3 = "[email protected],[email protected]" 
    } 
} 
相關問題