Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	api-client/build.gradle.kts
#	build.gradle.kts
  • Loading branch information
Joseph5610 committed Jun 15, 2024
2 parents 41ed870 + cc10089 commit 530aef8
Show file tree
Hide file tree
Showing 36 changed files with 265 additions and 216 deletions.
14 changes: 9 additions & 5 deletions api-client/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
version = "0.10"
version = "0.11"

val retrofitVersion = "2.11.0"
val jacksonVersion = "2.17.0"

dependencies {
api(platform("com.squareup.okhttp3:okhttp-bom:4.12.0"))
api("com.google.code.gson:gson:2.11.0") // patch for CVE-2022-25647
api("com.squareup.okhttp3:logging-interceptor")
api("com.squareup.okhttp3:okhttp-dnsoverhttps")
api("com.squareup.retrofit2:retrofit:2.11.0")
api("com.squareup.retrofit2:adapter-rxjava3:2.11.0")
api("com.squareup.retrofit2:converter-gson:2.11.0")
api("com.squareup.retrofit2:retrofit:$retrofitVersion")
api("com.squareup.retrofit2:adapter-rxjava3:$retrofitVersion")
api("com.squareup.retrofit2:converter-jackson:$retrofitVersion")
api("com.fasterxml.jackson.core:jackson-core:$jacksonVersion")
api("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

package online.hudacek.fxradio.apiclient

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import online.hudacek.fxradio.apiclient.http.provider.AbstractClientProvider
import online.hudacek.fxradio.apiclient.http.provider.CachingClientProvider
import retrofit2.Retrofit
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.jackson.JacksonConverterFactory

/**
* Provides Retrofit instance for [baseUrl]
Expand All @@ -38,7 +39,7 @@ class ServiceProvider(
val retrofit: Retrofit
get() = Retrofit.Builder()
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(JacksonConverterFactory.create(jacksonObjectMapper))
.baseUrl(baseUrl)
.client(clientProvider.client)
.build()
Expand All @@ -49,4 +50,12 @@ class ServiceProvider(
inline fun <reified T : ApiDefinition> create(): T = retrofit.create(T::class.java)

fun close() = clientProvider.close()

companion object {

/**
* instance of kotlin jackson object mapper
*/
private val jacksonObjectMapper = jacksonObjectMapper()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package online.hudacek.fxradio.apiclient.musicbrainz.model

import com.fasterxml.jackson.annotation.JsonIgnoreProperties

@JsonIgnoreProperties(ignoreUnknown = true)
data class Artist(
val id: String,
val name: String,
val disambiguation: String
val disambiguation: String?
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package online.hudacek.fxradio.apiclient.musicbrainz.model

import com.fasterxml.jackson.annotation.JsonIgnoreProperties

@JsonIgnoreProperties(ignoreUnknown = true)
data class ArtistCredit(
val name: String,
val artist: Artist
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package online.hudacek.fxradio.apiclient.musicbrainz.model

import com.google.gson.annotations.SerializedName
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty

@JsonIgnoreProperties(ignoreUnknown = true)
data class Release(
val id: String,
val score: Int,
val title: String,
val status: String,
@SerializedName("artist-credit") val artistCredit: List<ArtistCredit>
val status: String?,
@JsonProperty("artist-credit") val artistCredit: List<ArtistCredit>
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package online.hudacek.fxradio.apiclient.musicbrainz.model

import com.fasterxml.jackson.annotation.JsonIgnoreProperties

@JsonIgnoreProperties(ignoreUnknown = true)
data class SearchResult(
val created: String,
val count: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

package online.hudacek.fxradio.apiclient.radiobrowser.model

import com.google.gson.annotations.SerializedName
import com.fasterxml.jackson.annotation.JsonProperty

data class AddStationRequest(
val name: String = "",
val url: String = "",
val homepage: String = "",
val favicon: String = "",
@SerializedName("countrycode") val countryCode: String = "",
@JsonProperty("countrycode") val countryCode: String = "",
val country: String = "",
val language: String = "",
val tags: String = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@

package online.hudacek.fxradio.apiclient.radiobrowser.model

import com.google.gson.annotations.SerializedName
import com.fasterxml.jackson.annotation.JsonProperty

data class AdvancedSearchRequest(
val name: String? = null,
val tag: String? = null,
val tagExact: Boolean? = null,
val order: String? = null,
val limit: Int? = null,
@SerializedName("hidebroken") val hideBroken: Boolean = true,
@JsonProperty("hidebroken") val hideBroken: Boolean = true,
val reverse: Boolean? = null,
@SerializedName("has_extended_info") val hasExtendedInfo: Boolean? = null,
@JsonProperty("has_extended_info") val hasExtendedInfo: Boolean? = null,
)

Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

package online.hudacek.fxradio.apiclient.radiobrowser.model

import com.google.gson.annotations.SerializedName
import com.fasterxml.jackson.annotation.JsonProperty
import online.hudacek.fxradio.apiclient.ApiUtils.COUNTRY_IGNORE_LIST

data class Country(
val name: String,
@SerializedName("iso_3166_1") val iso3166: String,
@SerializedName("stationcount") val stationCount: Int
@JsonProperty("iso_3166_1") val iso3166: String,
@JsonProperty("stationcount") val stationCount: Int
) {

// Don't use stationCount when comparing this data class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

package online.hudacek.fxradio.apiclient.radiobrowser.model

import com.google.gson.annotations.SerializedName
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import online.hudacek.fxradio.apiclient.ApiUtils.COUNTRY_IGNORE_LIST
import java.io.Serializable

Expand All @@ -29,26 +30,27 @@ private const val INVALID_UUID = "0"
/**
* Station data class
*/
@JsonIgnoreProperties(ignoreUnknown = true)
data class Station(
@SerializedName("stationuuid") val uuid: String,
@JsonProperty("stationuuid") val uuid: String,
val name: String,
@SerializedName("url_resolved") val urlResolved: String,
@JsonProperty("url_resolved") val urlResolved: String,
val homepage: String,
val favicon: String?,
val tags: String = "",
val country: String = "",
@SerializedName("countrycode") val countryCode: String = "",
@JsonProperty("countrycode") val countryCode: String = "",
val state: String = "",
val language: String = "",
val codec: String = "",
val bitrate: Int = 0,
val votes: Int = 0,
@SerializedName("geo_lat") val geoLat: Double = 0.0,
@SerializedName("geo_long") val geoLong: Double = 0.0,
@SerializedName("clicktrend") val clickTrend: Int = 0,
@SerializedName("clickcount") val clickCount: Int = 0,
@SerializedName("languagecodes") val languageCodes: String = "",
@SerializedName("has_extended_info") val hasExtendedInfo: Boolean = false
@JsonProperty("geo_lat") val geoLat: Double = 0.0,
@JsonProperty("geo_long") val geoLong: Double = 0.0,
@JsonProperty("clicktrend") val clickTrend: Int = 0,
@JsonProperty("clickcount") val clickCount: Int = 0,
@JsonProperty("languagecodes") val languageCodes: String = "",
@JsonProperty("has_extended_info") val hasExtendedInfo: Boolean = false
) : Serializable {

fun isValid() = uuid != INVALID_UUID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@

package online.hudacek.fxradio.apiclient.radiobrowser.model

import com.google.gson.annotations.SerializedName
import com.fasterxml.jackson.annotation.JsonProperty

data class StatsResponse(
@SerializedName("supported_version") val supportedVersion: String = "",
@SerializedName("software_version") val softwareVersion: String = "",
@JsonProperty("supported_version") val supportedVersion: String = "",
@JsonProperty("software_version") val softwareVersion: String = "",
val status: String = "",
val stations: String = "",
@SerializedName("stations_broken") val stationsBroken: String = "",
@JsonProperty("stations_broken") val stationsBroken: String = "",
val tags: String = "",
@SerializedName("clicks_last_hour") val clicksLastHour: Int = 0,
@SerializedName("clicks_last_day") val clicksLastDay: Int = 0,
@JsonProperty("clicks_last_hour") val clicksLastHour: Int = 0,
@JsonProperty("clicks_last_day") val clicksLastDay: Int = 0,
val languages: Int = 0,
val countries: Int = 0
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package online.hudacek.fxradio.apiclient.radiobrowser.model

import com.google.gson.annotations.SerializedName
import com.fasterxml.jackson.annotation.JsonProperty

data class Tag(val name: String, @SerializedName("stationcount") val stationCount: Int)
data class Tag(val name: String, @JsonProperty("stationcount") val stationCount: Int)
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ val junitVersion = "5.10.2"
val vlcjVersion = "4.8.2"
val humbleVersion = "0.3.0"
val flywayVersion = "10.14.0"
val controlsFxVersion = "11.2.0"
val controlsFxVersion = "11.2.1"

val defaultAppJvmArgs = listOf(
// Tornadofx
Expand Down Expand Up @@ -97,7 +97,7 @@ dependencies {
implementation("no.tornado:tornadofx-controlsfx:0.1.1")

implementation("org.pdfsam.rxjava3:rxjavafx:3.0.3")
implementation("org.xerial:sqlite-jdbc:3.45.1.0")
implementation("org.xerial:sqlite-jdbc:3.46.0.0")
implementation("de.jangassen:nsmenufx:3.1.0")
implementation("org.flywaydb:flyway-core:$flywayVersion")
implementation("com.github.davidmoten:rxjava3-jdbc:0.1.4") {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/online/hudacek/fxradio/FxRadio.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ open class FxRadio(
RadioBrowserApiProvider.close()
MusicBrainzApiProvider.close()
HttpClient.close()
Database.close()
Database.shutdown()
LogManager.shutdown()
}
super.stop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,19 @@ package online.hudacek.fxradio.persistence.database

import io.reactivex.rxjava3.core.Flowable
import online.hudacek.fxradio.apiclient.radiobrowser.model.Station
import org.davidmoten.rxjava3.jdbc.SelectBuilder
import online.hudacek.fxradio.persistence.database.entity.StationEntity

/**
* Common operations on database of stations with different tables (e.g. History, Favourites ..)
* Common operations on database of stations with different tables (e.g. History, Favourites ...)
*/
abstract class StationTable(override val tableName: String) : Table<Station>, Database(tableName) {
abstract class BaseStationDao : Dao<Station, StationEntity> {

override fun selectAll() = selectAllQuery().asStationFlowable()
override fun selectAll(): Flowable<StationEntity> = selectAllQuery().autoMap(StationEntity::class.java)

override fun removeAll(): Flowable<Int> = removeAllQuery().counts()

override fun remove(element: Station): Flowable<Int> =
database.update("DELETE FROM $tableName WHERE stationuuid = ?")
.parameter(element.uuid)
.counts()

/**
* Map ResultSet to [Station] Flowable
*/
fun SelectBuilder.asStationFlowable(): Flowable<Station> = get {
Station(
it.getString("stationuuid"),
it.getString("name"),
it.getString("url_resolved"),
it.getString("homepage"),
it.getString("favicon"),
it.getString("tags"),
it.getString("country"),
it.getString("countrycode"),
it.getString("state"),
it.getString("language"),
it.getString("codec"),
it.getInt("bitrate"),
hasExtendedInfo = it.getBoolean("has_extended_info")
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package online.hudacek.fxradio.persistence.database

import io.reactivex.rxjava3.schedulers.Schedulers
import online.hudacek.fxradio.Config
import org.davidmoten.rxjava3.jdbc.Database
import org.davidmoten.rxjava3.jdbc.pool.Pools
import org.flywaydb.core.Flyway
import java.util.concurrent.Executors

private const val DB_POOLS = 5

class ConnectionManager(private val dbUrl: String) {

// Workaround for https://github.com/davidmoten/rxjava2-jdbc/issues/51
private val executor = Executors.newFixedThreadPool(DB_POOLS)

private val pools = Pools.nonBlocking()
.url(dbUrl)
.maxPoolSize(DB_POOLS)
.scheduler(Schedulers.from(executor))
.build()

/**
* Establishes connection to SQLite db with [dbUrl]
* Performs flyway migrations for the given database
*/
val database: Database by lazy {
Database.from(pools).also {
Flyway.configure().dataSource(dbUrl, null, null).load().also {
it.migrate()
}
}
}

/**
* Closes connection to DB
*/
fun close() {
database.close()
executor.shutdownNow()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,33 @@
package online.hudacek.fxradio.persistence.database

import io.reactivex.rxjava3.core.Flowable
import org.davidmoten.rxjava3.jdbc.Database
import org.davidmoten.rxjava3.jdbc.SelectBuilder
import org.davidmoten.rxjava3.jdbc.UpdateBuilder

/**
* Basic interface for common table operations
*/
interface Table<T : Any> {
interface Dao<In : Any, Out: Any> {

val database: Database

/**
* Name of the table in SQLite DB
*/
val tableName: String

fun selectAll(): Flowable<T>
fun selectAll(): Flowable<Out>

fun removeAll(): Flowable<Int>
fun insert(element: T): Flowable<Int>
fun remove(element: T): Flowable<Int>

fun insert(element: In): Flowable<Int>

fun remove(element: In): Flowable<Int>

fun selectAllQuery(): SelectBuilder = database.select("SELECT * FROM $tableName")

fun removeAllQuery(): UpdateBuilder = database.update("DELETE FROM $tableName")
}


Expand Down
Loading

0 comments on commit 530aef8

Please sign in to comment.