2016-09-20 8 views
-1

enthält, möchte ich die Liste von E-Mail-IDs erhalten, basierend auf zur Verfügung gestellt und filetype companyLesen Wiedergabe Anwendungskonfigurationsdatei verschachtelten Objekten

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

meine obige Funktion mir einige komplexe Liste der Konfiguration ist zu geben, die nicht leicht überfahrbar ist.

Ich möchte grundsätzlich List[String], die nichts anderes als eine Liste von E-Mail-IDs ist.

Zum Beispiel gegebenen Argumente:

  • filetype = test_2
  • company = company2

Ich möchte String erhalten "[email protected], [email protected]" , die List[String] von .split(",").toList umgewandelt werden können

Kann das vereinfacht werden?

finden meine application.conf Datei in scala Play Anwendung

email_list = [ 
    { 
    file0 : "[email protected],[email protected]" 
    }, 
    { 
    file1 : [ 
     {"company1" : "[email protected]"}, 
     {"company2" : "[email protected]"}, 
     {"company3" : "[email protected]m"} 
    ] 
    }, 
    { 
    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

Wenn Sie es von 'application.conf' lesen, warum strukturieren Sie es nicht auf eine einfachere Art und Weise, um gelesen/transversiert zu werden ?? – Salem

+0

@Selem für bessere Lesbarkeit habe ich es basierend auf file_types modularisiert. – prasshant

Antwort

0

ich einige Versuche auf HOCON Syntax getan haben und folgenden Code + Config gefunden zu arbeiten

Code

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) 
    } 

anwendung 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]" 
    } 
} 
Verwandte Themen