Fix country import; fix layout; bump to 0.3
This commit is contained in:
@@ -124,7 +124,7 @@ object OpenGotha {
|
||||
shortName = genParams.shortName,
|
||||
startDate = genParams.beginDate.toLocalDate(),
|
||||
endDate = genParams.endDate.toLocalDate(),
|
||||
country = "FR", // no country in opengotha format
|
||||
country = "fr", // no country in opengotha format
|
||||
location = genParams.location,
|
||||
online = genParams.isBInternet ?: false,
|
||||
timeSystem = when (genParams.complementaryTimeSystem) {
|
||||
|
@@ -21,9 +21,10 @@ import kotlin.io.path.useDirectoryEntries
|
||||
private const val LEFT_PAD = 6 // left padding of IDs with '0' in filename
|
||||
private fun Tournament<*>.filename() = "${id.toString().padStart(LEFT_PAD, '0')}-${shortName}.tour"
|
||||
|
||||
class FileStore(pathStr: String): StoreImplementation {
|
||||
class FileStore(pathStr: String): IStore {
|
||||
companion object {
|
||||
private val filenameRegex = Regex("^(\\d+)-(.*)\\.tour$")
|
||||
private val displayFormat: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
|
||||
private val timestampFormat: DateFormat = SimpleDateFormat("yyyyMMddHHmmss")
|
||||
private val timestamp: String get() = timestampFormat.format(Date())
|
||||
}
|
||||
@@ -37,11 +38,17 @@ class FileStore(pathStr: String): StoreImplementation {
|
||||
_nextTournamentId.set(getTournaments().keys.maxOrNull() ?: 0.toID())
|
||||
}
|
||||
|
||||
override fun getTournaments(): Map<ID, String> {
|
||||
|
||||
private fun lastModified(path: Path) = displayFormat.format(Date(path.toFile().lastModified()))
|
||||
|
||||
override fun getTournaments(): Map<ID, Map<String, String>> {
|
||||
return path.useDirectoryEntries("*.tour") { entries ->
|
||||
entries.mapNotNull { entry ->
|
||||
val match = filenameRegex.matchEntire(entry.fileName.toString())
|
||||
match?.let { Pair(it.groupValues[1].toID(), it.groupValues[2]) }
|
||||
match?.let { Pair(it.groupValues[1].toID(), mapOf(
|
||||
"name" to it.groupValues[2],
|
||||
"lastModified" to lastModified(entry))
|
||||
) }
|
||||
}.sortedBy { it.first }.toMap()
|
||||
}
|
||||
}
|
||||
|
@@ -8,13 +8,13 @@ internal val _nextTournamentId = AtomicInteger()
|
||||
internal val _nextPlayerId = AtomicInteger()
|
||||
internal val _nextGameId = AtomicInteger()
|
||||
|
||||
interface StoreImplementation {
|
||||
interface IStore {
|
||||
|
||||
val nextTournamentId get() = _nextTournamentId.incrementAndGet()
|
||||
val nextPlayerId get() = _nextPlayerId.incrementAndGet()
|
||||
val nextGameId get() = _nextGameId.incrementAndGet()
|
||||
|
||||
fun getTournaments(): Map<ID, String>
|
||||
fun getTournaments(): Map<ID, Map<String, String>>
|
||||
fun addTournament(tournament: Tournament<*>)
|
||||
fun getTournament(id: ID): Tournament<*>?
|
||||
fun replaceTournament(tournament: Tournament<*>)
|
@@ -3,10 +3,12 @@ package org.jeudego.pairgoth.store
|
||||
import org.jeudego.pairgoth.model.ID
|
||||
import org.jeudego.pairgoth.model.Tournament
|
||||
|
||||
class MemoryStore: StoreImplementation {
|
||||
class MemoryStore: IStore {
|
||||
private val tournaments = mutableMapOf<ID, Tournament<*>>()
|
||||
|
||||
override fun getTournaments(): Map<ID, String> = tournaments.mapValues { it.value.shortName }
|
||||
override fun getTournaments(): Map<ID, Map<String, String>> = tournaments.mapValues {
|
||||
mapOf("name" to it.value.shortName)
|
||||
}
|
||||
|
||||
override fun addTournament(tournament: Tournament<*>) {
|
||||
if (tournaments.containsKey(tournament.id)) throw Error("tournament id #${tournament.id} already exists")
|
||||
|
@@ -1,11 +1,8 @@
|
||||
package org.jeudego.pairgoth.store
|
||||
|
||||
import org.jeudego.pairgoth.model.ID
|
||||
import org.jeudego.pairgoth.model.Tournament
|
||||
import org.jeudego.pairgoth.server.WebappManager
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
private fun createStoreImplementation(): StoreImplementation {
|
||||
private fun createStoreImplementation(): IStore {
|
||||
return when (val storeProperty = WebappManager.getProperty("store") ?: "memory") {
|
||||
"memory" -> MemoryStore()
|
||||
"file" -> {
|
||||
@@ -16,4 +13,4 @@ private fun createStoreImplementation(): StoreImplementation {
|
||||
}
|
||||
}
|
||||
|
||||
object Store: StoreImplementation by createStoreImplementation()
|
||||
object Store: IStore by createStoreImplementation()
|
||||
|
Reference in New Issue
Block a user