-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ability to open data from file and save to file (#24)
add ability to open data from url Signed-off-by: John Burns <[email protected]>
- Loading branch information
1 parent
bef01cb
commit 04cdf70
Showing
11 changed files
with
157 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...wakingrufus/eloleague/data/DataHandler.kt → .../wakingrufus/eloleague/dao/DataHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...ngrufus/eloleague/data/FileDataHandler.kt → ...s/eloleague/dao/JacksonFileDataHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/com/github/wakingrufus/eloleague/dao/JacksonUrlDataHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.github.wakingrufus.eloleague.dao | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.KotlinModule | ||
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule | ||
import com.github.wakingrufus.eloleague.data.ConfigData | ||
import mu.KLogging | ||
import java.io.IOException | ||
import java.net.URL | ||
|
||
class JacksonUrlDataHandler(val url: URL) : DataHandler { | ||
companion object : KLogging() { | ||
val objectMapper = ObjectMapper() | ||
.registerModule(ParameterNamesModule()) | ||
.registerModule(KotlinModule()) | ||
} | ||
|
||
override fun readFileConfig(): ConfigData { | ||
return try { | ||
objectMapper.readValue(url, ConfigData::class.java) | ||
} catch (e: IOException) { | ||
logger.error("Error reading data file: " + e.localizedMessage, e) | ||
ConfigData() | ||
} | ||
} | ||
|
||
override fun saveConfig(configData: ConfigData) { | ||
System.out.println("save url not implemented") | ||
} | ||
|
||
} |
24 changes: 1 addition & 23 deletions
24
src/main/kotlin/com/github/wakingrufus/eloleague/league/LeagueListController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 52 additions & 2 deletions
54
src/main/kotlin/com/github/wakingrufus/eloleague/ui/MainView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/kotlin/com/github/wakingrufus/eloleague/ui/UrlDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.github.wakingrufus.eloleague.ui | ||
|
||
import javafx.beans.property.SimpleStringProperty | ||
import tornadofx.* | ||
import java.net.URI | ||
import java.net.URL | ||
|
||
|
||
class UrlPickerItem(url: String) { | ||
val urlProperty = SimpleStringProperty(this, "", url) | ||
var url by urlProperty | ||
} | ||
|
||
class UrlPickerModel : ItemViewModel<UrlPickerItem>() { | ||
var url = bind(UrlPickerItem::urlProperty) | ||
} | ||
|
||
class UrlDialog : Fragment() { | ||
var url: URL? = null | ||
private val urlProperty = UrlPickerModel() | ||
override val root = borderpane { | ||
center { | ||
form { | ||
fieldset { | ||
field { | ||
label("URL") | ||
textfield(urlProperty.url).validator { | ||
if (URI.create(it.toString()) != null) null else error("error") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
bottom { | ||
buttonbar { | ||
button("OK") { | ||
enableWhen(urlProperty.dirty) | ||
action { | ||
url = URI.create(urlProperty.url.value).toURL() | ||
close() | ||
} | ||
} | ||
button("Cancel") { | ||
action { | ||
url = null | ||
close() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/test/kotlin/com/github/wakingrufus/eloleague/IntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/test/kotlin/com/github/wakingrufus/eloleague/dao/JacksonUrlDataHandlerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.github.wakingrufus.eloleague.dao | ||
|
||
import org.junit.Test | ||
import kotlin.test.assertEquals | ||
|
||
class JacksonUrlDataHandlerTest { | ||
@Test | ||
fun test() { | ||
val actual = JacksonUrlDataHandler(javaClass.classLoader.getResource("elo-test.json")).readFileConfig() | ||
assertEquals(expected = 1, actual = actual.leagues.size) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"leagues":[{"id":"8ee58b3b-183b-455b-8d54-db9972c26f33","name":"Test League","players":[{"id":"0ef83839-474e-4204-8c27-877acfb6f1a8","name":"Dave"},{"id":"56c5d390-f15c-45c5-a2f8-11076bada6be","name":"Alice"},{"id":"c143defc-27b6-4682-bfd4-b718c6774d26","name":"Bob"},{"id":"f4ed42ec-45e2-43c4-b976-0c79e9a0aa20","name":"Harold"},{"id":"f7110f75-fbb2-4291-a5db-cbfff784f296","name":"Frank"},{"id":"7fbf8032-5fed-4d11-8030-8099fdb6fc7f","name":"Gary"},{"id":"ba6778db-ead2-4265-8940-d7d14b5fe03b","name":"Carol"},{"id":"6c84336a-6caa-4369-8224-89611c7e003b","name":"Erin"},{"id":"59be1e67-1993-47dc-9727-0964b71f034c","name":"Ian"}],"games":[{"id":"331299ee-6ea1-4b4a-a970-f01c77174fbb","team1Score":1,"team2Score":0,"timestamp":1516922304148,"team1PlayerIds":["56c5d390-f15c-45c5-a2f8-11076bada6be","c143defc-27b6-4682-bfd4-b718c6774d26"],"team2PlayerIds":["0ef83839-474e-4204-8c27-877acfb6f1a8","ba6778db-ead2-4265-8940-d7d14b5fe03b"]},{"id":"f9c1b4b5-c52b-44bd-9b9a-287da1eed88e","team1Score":4,"team2Score":0,"timestamp":1516922316670,"team1PlayerIds":["c143defc-27b6-4682-bfd4-b718c6774d26","ba6778db-ead2-4265-8940-d7d14b5fe03b"],"team2PlayerIds":["56c5d390-f15c-45c5-a2f8-11076bada6be","0ef83839-474e-4204-8c27-877acfb6f1a8"]},{"id":"454902e3-5f62-4a1b-9429-271196de3489","team1Score":0,"team2Score":9,"timestamp":1516975661716,"team1PlayerIds":["c143defc-27b6-4682-bfd4-b718c6774d26","56c5d390-f15c-45c5-a2f8-11076bada6be"],"team2PlayerIds":["ba6778db-ead2-4265-8940-d7d14b5fe03b","0ef83839-474e-4204-8c27-877acfb6f1a8"]},{"id":"a807b30b-43d3-421f-bea0-2f338ee979aa","team1Score":10,"team2Score":0,"timestamp":1516975894382,"team1PlayerIds":["c143defc-27b6-4682-bfd4-b718c6774d26","56c5d390-f15c-45c5-a2f8-11076bada6be"],"team2PlayerIds":["ba6778db-ead2-4265-8940-d7d14b5fe03b","0ef83839-474e-4204-8c27-877acfb6f1a8"]},{"id":"dca1ef21-27e5-4a8a-a9ae-78aa639b7cae","team1Score":5,"team2Score":0,"timestamp":1517319555925,"team1PlayerIds":["f4ed42ec-45e2-43c4-b976-0c79e9a0aa20","7fbf8032-5fed-4d11-8030-8099fdb6fc7f"],"team2PlayerIds":["6c84336a-6caa-4369-8224-89611c7e003b","f7110f75-fbb2-4291-a5db-cbfff784f296"]},{"id":"d8553781-2eb1-4bd8-aad3-808044b976d5","team1Score":0,"team2Score":8,"timestamp":1517319572836,"team1PlayerIds":["7fbf8032-5fed-4d11-8030-8099fdb6fc7f","f4ed42ec-45e2-43c4-b976-0c79e9a0aa20"],"team2PlayerIds":["56c5d390-f15c-45c5-a2f8-11076bada6be","c143defc-27b6-4682-bfd4-b718c6774d26"]},{"id":"02e4e605-0c1e-4db9-a47a-c998e8664c56","team1Score":2,"team2Score":3,"timestamp":1517319590081,"team1PlayerIds":["f4ed42ec-45e2-43c4-b976-0c79e9a0aa20","7fbf8032-5fed-4d11-8030-8099fdb6fc7f"],"team2PlayerIds":["ba6778db-ead2-4265-8940-d7d14b5fe03b","0ef83839-474e-4204-8c27-877acfb6f1a8"]},{"id":"a8f2fe9b-c0df-457a-b3fd-dfd997515df1","team1Score":0,"team2Score":2,"timestamp":1517319609428,"team1PlayerIds":["6c84336a-6caa-4369-8224-89611c7e003b","f7110f75-fbb2-4291-a5db-cbfff784f296"],"team2PlayerIds":["56c5d390-f15c-45c5-a2f8-11076bada6be","c143defc-27b6-4682-bfd4-b718c6774d26"]},{"id":"a7097e4d-5ea8-4f62-ba1e-ac9fe786229d","team1Score":3,"team2Score":6,"timestamp":1517319621723,"team1PlayerIds":["6c84336a-6caa-4369-8224-89611c7e003b","f7110f75-fbb2-4291-a5db-cbfff784f296"],"team2PlayerIds":["ba6778db-ead2-4265-8940-d7d14b5fe03b","0ef83839-474e-4204-8c27-877acfb6f1a8"]},{"id":"d5a29f13-fde9-4458-bd9a-26a52a128623","team1Score":1,"team2Score":3,"timestamp":1518217771143,"team1PlayerIds":["0ef83839-474e-4204-8c27-877acfb6f1a8"],"team2PlayerIds":["c143defc-27b6-4682-bfd4-b718c6774d26"]},{"id":"c9bd9644-bd99-4687-b546-490ef13a332c","team1Score":2,"team2Score":0,"timestamp":1518217787941,"team1PlayerIds":["0ef83839-474e-4204-8c27-877acfb6f1a8"],"team2PlayerIds":["c143defc-27b6-4682-bfd4-b718c6774d26"]}],"startingRating":1500,"xi":1000,"trialPeriod":10,"trialKFactorMultiplier":2,"tournamentData":[{"id":"fd172f6d-9294-4295-b35c-01d127ec961d","startTime":1516752150053,"name":"Tournament 1","teams":[{"id":"bbd8b1ab-4f4c-4374-8a46-9102b89b1d81","name":"Team 2","playerIds":["0ef83839-474e-4204-8c27-877acfb6f1a8","ba6778db-ead2-4265-8940-d7d14b5fe03b"]},{"id":"7c01d205-8f11-43ca-9175-b52c484705a1","name":"Team 1","playerIds":["56c5d390-f15c-45c5-a2f8-11076bada6be","c143defc-27b6-4682-bfd4-b718c6774d26"]}],"rounds":[{"roundNumber":1,"pairings":[{"id":"4a917b01-1468-42a1-b31d-36301952442a","teamIds":["bbd8b1ab-4f4c-4374-8a46-9102b89b1d81","7c01d205-8f11-43ca-9175-b52c484705a1"],"games":[{"id":"989a5474-1d5f-425b-ab23-617b13449ae0","gameId":"331299ee-6ea1-4b4a-a970-f01c77174fbb","winningTeamId":"7c01d205-8f11-43ca-9175-b52c484705a1"},{"id":"6b14fd59-b43f-478e-9b5e-0380dc1552c2","gameId":"a807b30b-43d3-421f-bea0-2f338ee979aa","winningTeamId":"7c01d205-8f11-43ca-9175-b52c484705a1"},{"id":"f5e1fbd0-91a9-4886-b94a-a55fb3745842","gameId":"454902e3-5f62-4a1b-9429-271196de3489","winningTeamId":"bbd8b1ab-4f4c-4374-8a46-9102b89b1d81"}],"drops":[]}]}]},{"id":"54f93ead-ad7a-4cbb-b035-2c33c9e0c773","startTime":1516752284200,"name":"tournament2","teams":[{"id":"68eda989-77e5-488c-b467-0ec52ac3b3da","name":"team 4","playerIds":["f4ed42ec-45e2-43c4-b976-0c79e9a0aa20","7fbf8032-5fed-4d11-8030-8099fdb6fc7f"]},{"id":"5f193445-3f27-44f5-90f7-c1a728580976","name":"team 3","playerIds":["6c84336a-6caa-4369-8224-89611c7e003b","f7110f75-fbb2-4291-a5db-cbfff784f296"]},{"id":"8b01dc11-4544-4319-a71e-6ba2e65f3960","name":"team 2","playerIds":["0ef83839-474e-4204-8c27-877acfb6f1a8","ba6778db-ead2-4265-8940-d7d14b5fe03b"]},{"id":"18d316fe-cf8a-4bf2-814d-5ea8872522f2","name":"team 1","playerIds":["56c5d390-f15c-45c5-a2f8-11076bada6be","c143defc-27b6-4682-bfd4-b718c6774d26"]}],"rounds":[{"roundNumber":1,"pairings":[{"id":"3f4788fa-6d01-4ec6-8cd3-0b359ac80e96","teamIds":["68eda989-77e5-488c-b467-0ec52ac3b3da","8b01dc11-4544-4319-a71e-6ba2e65f3960"],"games":[{"id":"95b17c8b-6357-4e0a-b062-0dfdd24c5bed","gameId":"02e4e605-0c1e-4db9-a47a-c998e8664c56","winningTeamId":"8b01dc11-4544-4319-a71e-6ba2e65f3960"}],"drops":[]},{"id":"6150ef4d-0232-450c-b458-47dc9a0a9d99","teamIds":["5f193445-3f27-44f5-90f7-c1a728580976","18d316fe-cf8a-4bf2-814d-5ea8872522f2"],"games":[{"id":"02fcba8a-f75f-4a9e-85d2-c6c2f9c8f4ba","gameId":"a8f2fe9b-c0df-457a-b3fd-dfd997515df1","winningTeamId":"18d316fe-cf8a-4bf2-814d-5ea8872522f2"}],"drops":[]}]}]}],"kfactorBase":32}]} |