Merge branch 'cleanup' into 'master'

Cleanup

See merge request pheerai/rcdbquery!1
This commit is contained in:
Oliver Rümpelein 2021-03-06 20:26:25 +01:00
commit dfd6d5f405
57 changed files with 339 additions and 327 deletions

30
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,30 @@
# Based on https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Gradle.gitlab-ci.yml
image: gradle:jdk11
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
build:
stage: build
script: gradle --build-cache assemble
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths:
- build
- .gradle
artifact:
stage: deploy
script: gradle publish
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
cache:
key: "$CI_COMMIT_REF_NAME"
policy: pull-push
paths:
- build
- .gradle

View File

@ -1,5 +1,16 @@
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
extra.apply {
set("pheeraiBomVersion", "0.0.3-SNAPSHOT")
set("kotlinApiVersion", "1.4")
set("javaVersion", JavaVersion.VERSION_11)
}
}
inline fun <reified T> getFromExtra(prop: String) = project.extra[prop] as T
// TODO: Documentation
// TODO: Source Jar
// TODO: Doc Jar
@ -11,31 +22,42 @@ plugins {
repositories {
mavenCentral()
jcenter()
google()
maven {
url = uri("https://git.f3l.de/api/v4/projects/160/packages/maven")
mavenContent {
includeGroup("de.pheerai")
includeGroup("de.pheerai.eap")
}
}
}
project.version = "0.0.1"
project.version = "0.0.2"
project.group = "de.pheerai.rcdb"
java {
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = getFromExtra("javaVersion")
sourceCompatibility = getFromExtra("javaVersion")
}
kotlin {
explicitApi = ExplicitApiMode.Strict
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(enforcedPlatform("de.pheerai:kotlin-crawler-app-bom:${getFromExtra<String>("pheeraiBomVersion")}"))
testImplementation("io.kotest:kotest-runner-junit5-jvm:4.0.5")
testImplementation("io.kotest:kotest-assertions-core-jvm:4.0.5")
testImplementation("io.kotest", "kotest-runner-junit5-jvm")
testImplementation("io.kotest", "kotest-assertions-core-jvm")
}
tasks {
withType<KotlinCompile>().configureEach {
kotlinOptions {
freeCompilerArgs = listOf("-XXLanguage:+InlineClasses")
apiVersion = "1.3"
languageVersion = "1.3"
jvmTarget = JavaVersion.VERSION_11.toString()
apiVersion = getFromExtra("kotlinApiVersion")
languageVersion = getFromExtra("kotlinApiVersion")
jvmTarget = getFromExtra<JavaVersion>("javaVersion").toString()
}
}
@ -46,13 +68,21 @@ tasks {
publishing {
publications {
create<MavenPublication>("maven") {
groupId = project.group as String
artifactId = project.name as String
version = project.version as String
create<MavenPublication>("QueryBuilder") {
from(components["java"])
}
repositories {
maven {
url = uri("https://git.f3l.de/api/v4/projects/180/packages/maven")
name = "GitLab"
credentials(HttpHeaderCredentials::class.java) {
name = "Job-Token"
value = System.getenv("CI_JOB_TOKEN")
}
authentication {
create<HttpHeaderAuthentication>("header")
}
}
}
}
}

Binary file not shown.

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

2
gradlew vendored
View File

@ -82,6 +82,7 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath

1
gradlew.bat vendored
View File

@ -84,6 +84,7 @@ set CMD_LINE_ARGS=%*
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

View File

@ -1,6 +1,6 @@
pluginManagement {
plugins {
kotlin("jvm") version "1.3.72"
kotlin("jvm") version "1.4.30"
}
}

View File

@ -1,38 +1,38 @@
package de.pheerai.rcdbquery
import de.pheerai.rcdbquery.dataMappings.order.Order
import de.pheerai.rcdbquery.dataMappings.order.sortBy
import de.pheerai.rcdbquery.dataMappings.page.page
import de.pheerai.rcdbquery.dataMappings.searchTerm.searchTerm
import de.pheerai.rcdbquery.dataMappings.searchType.SearchType
import de.pheerai.rcdbquery.dataMappings.searchType.searchType
import de.pheerai.rcdbquery.dataMappings.vendor.Vendor
import de.pheerai.rcdbquery.dataMappings.vendor.Vendor.*
import de.pheerai.rcdbquery.dataMappings.vendor.vendors
import de.pheerai.rcdbquery.dsl.rcdbQuery
fun main() {
public fun main() {
println(generateNameQueryUrl())
println(generatePageQueryUrl())
}
fun generateNameQueryUrl() = rcdbQuery {
private fun generateNameQueryUrl() = rcdbQuery {
searchType(SearchType.COASTER)
searchTerm("Dragon")
vendors {
vekoma()
intamin()
mack()
of(Vendor.PRESTON_AND_BARBIERI)
VEKOMA()
INTAMIN()
MACK()
}
sortBy {
manufacturer()
inversions()
Order.MANUFACTURER()
Order.INVERSIONS()
}
}
fun generatePageQueryUrl() = rcdbQuery {
private fun generatePageQueryUrl() = rcdbQuery {
page(3)
searchType(SearchType.COASTER)
vendors {
intamin()
INTAMIN()
}
}

View File

@ -3,7 +3,7 @@ package de.pheerai.rcdbquery.dataMappings.category
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
enum class Category(
public enum class Category(
override val prettyName: String,
override val fullName: String,
override val paramValue: Long
@ -38,7 +38,7 @@ enum class Category(
constructor(name: String, paramValue: Long) : this(name, name, paramValue)
companion object : StringGeneratable<Category> {
internal companion object : StringGeneratable<Category> {
override val paramKey = "ca"
override fun of(input: String): Category? = when (input) {
"4th Dimension" -> FOURTH_DIMENSION

View File

@ -2,36 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.category
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
class CategoryBuilder: MultiParamBuilder<Long, Category>() {
public class CategoryBuilder : MultiParamBuilder<Long, Category>() {
override fun add(param: Category): CategoryBuilder {
super.add(param)
return this
}
fun fourthDimension() = this.add(Category.FOURTH_DIMENSION)
fun brakeman() = this.add(Category.BRAKEMAN)
fun builtInhouse() = this.add(Category.BUILT_INHOUSE)
fun darkride() = this.add(Category.DARK_RIDE)
fun dualStation() = this.add(Category.DUAL_STATION)
fun enclosed() = this.add(Category.ENCLOSED)
fun floorless() = this.add(Category.FLOORLESS)
fun hybrid() = this.add(Category.HYBRID)
fun indoor() = this.add(Category.INDOOR)
fun mirror() = this.add(Category.MIRROR)
fun moebius() = this.add(Category.MOEBIUS)
fun onboardSound() = this.add(Category.ONBOARD_SOUND)
fun pendulum() = this.add(Category.PENDULUM)
fun quasiMoebius() = this.add(Category.QUASI_MOEBIUS)
fun rockingCars() = this.add(Category.ROCKING_CARS)
fun scenicRailway() = this.add(Category.SCENIC_RAILWAY)
fun shuttle() = this.add(Category.SHUTTLE)
fun sideFriction() = this.add(Category.SIDE_FRICTION)
fun singleRail() = this.add(Category.SINGLE_RAIL)
fun slidingStation() = this.add(Category.SLIDING_STATION)
fun spinningCars() = this.add(Category.SPINNING_CARS)
fun stackedStorage() = this.add(Category.STACKED_STORAGE)
fun turntableStation() = this.add(Category.TURNTABLE_STATION)
fun twin() = this.add(Category.TWIN)
fun virtualReality() = this.add(Category.VIRTUAL_REALITY)
fun waterCoaster() = this.add(Category.WATER_COASTER)
override fun Category.invoke(): CategoryBuilder = add(this)
}

View File

@ -1,8 +1,8 @@
package de.pheerai.rcdbquery.dataMappings.category
import de.pheerai.rcdbquery.dsl.ParamsCollector
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
fun ParamsCollector.category(body: CategoryBuilder.() -> CategoryBuilder): ParamsCollector {
public fun ParamsCollector.category(body: CategoryBuilder.() -> CategoryBuilder): ParamsCollector {
val builder = CategoryBuilder()
builder.body()
this[Category.paramKey] = builder.build()

View File

@ -3,7 +3,7 @@ package de.pheerai.rcdbquery.dataMappings.classification
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
enum class Classification(
public enum class Classification(
override val prettyName: String,
override val fullName: String,
override val paramValue: Long
@ -15,8 +15,8 @@ enum class Classification(
constructor(name: String, paramValue: Long) : this(name, name, paramValue)
companion object: StringGeneratable<Classification> {
override fun of(input: String) = values().find { it.fullName == input }
override val paramKey = "cs"
public companion object: StringGeneratable<Classification> {
override fun of(input: String): Classification? = values().find { it.fullName == input }
override val paramKey: String = "cs"
}
}

View File

@ -2,13 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.classification
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
class ClassificationBuilder : MultiParamBuilder<Long, Classification>() {
public class ClassificationBuilder : MultiParamBuilder<Long, Classification>() {
override fun add(param: Classification): ClassificationBuilder {
super.add(param)
return this
}
fun rollerCoaster() = this.add(Classification.ROLLER_COASTER)
fun poweredCoaster() = this.add(Classification.POWERED_COASTER)
fun mountainCoaster() = this.add(Classification.MOUNTAIN_COASTER)
override fun Classification.invoke(): ClassificationBuilder = add(this)
}

View File

@ -1,8 +1,8 @@
package de.pheerai.rcdbquery.dataMappings.classification
import de.pheerai.rcdbquery.dsl.ParamsCollector
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
fun ParamsCollector.classification(body: ClassificationBuilder.() -> ClassificationBuilder): ParamsCollector {
public fun ParamsCollector.classification(body: ClassificationBuilder.() -> ClassificationBuilder): ParamsCollector {
val builder = ClassificationBuilder()
builder.body()
this[Classification.paramKey] = builder.build()

View File

@ -3,7 +3,7 @@ package de.pheerai.rcdbquery.dataMappings.design
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
enum class Design(
public enum class Design(
override val prettyName: String,
override val fullName: String,
override val paramValue: Long
@ -20,8 +20,8 @@ enum class Design(
constructor(name: String, paramValue: Long) : this(name, name, paramValue)
companion object : StringGeneratable<Design> {
override val paramKey = "de"
public companion object : StringGeneratable<Design> {
override val paramKey: String = "de"
override fun of(input: String): Design? = when (input) {
"Sit Down" -> SIT_DOWN
"Inverted" -> INVERTED

View File

@ -2,18 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.design
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
class DesignBuilder : MultiParamBuilder<Long, Design>() {
public class DesignBuilder : MultiParamBuilder<Long, Design>() {
override fun add(param: Design): DesignBuilder {
super.add(param)
return this
}
fun sitDown() = Design.SIT_DOWN
fun inverted() = Design.INVERTED
fun suspended() = Design.SUSPENDED
fun wing() = Design.WING
fun flying() = Design.FLYING
fun standUp() = Design.STAND_UP
fun bobsled() = Design.BOBSLED
fun pipeline() = Design.PIPELINE
override fun Design.invoke(): DesignBuilder = add(this)
}

View File

@ -1,8 +1,8 @@
package de.pheerai.rcdbquery.dataMappings.design
import de.pheerai.rcdbquery.dsl.ParamsCollector
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
fun ParamsCollector.design(body: DesignBuilder.() -> DesignBuilder): ParamsCollector {
public fun ParamsCollector.design(body: DesignBuilder.() -> DesignBuilder): ParamsCollector {
val builder = DesignBuilder()
builder.body()
this[Design.paramKey] = builder.build()

View File

@ -1,9 +1,9 @@
package de.pheerai.rcdbquery.dataMappings.internal
open class MultiParamBuilder<out U : Any, T : RcdbParamOption<U>> {
public abstract class MultiParamBuilder<out U : Any, T : RcdbParamOption<U>> {
private val paramList: MutableList<T> = mutableListOf()
open fun add(param: T): MultiParamBuilder<U, T> {
public open fun add(param: T): MultiParamBuilder<U, T> {
paramList.add(param)
return this
}
@ -18,6 +18,7 @@ open class MultiParamBuilder<out U : Any, T : RcdbParamOption<U>> {
return this
}
fun build() = paramList.toList()
}
public fun build(): List<T> = paramList.toList()
public abstract operator fun T.invoke(): MultiParamBuilder<U, T>
}

View File

@ -1,5 +1,5 @@
package de.pheerai.rcdbquery.dataMappings.internal
interface ParamKey {
internal interface ParamKey {
val paramKey: String
}

View File

@ -1,6 +1,6 @@
package de.pheerai.rcdbquery.dataMappings.internal
interface RcdbItem {
internal interface RcdbItem {
val url: String
get() ="https://www.rcdb.com/${id}.htm"
val id: Long

View File

@ -1,7 +1,7 @@
package de.pheerai.rcdbquery.dataMappings.internal
interface RcdbParamOption<out T> {
val prettyName: String
val fullName: String
val paramValue: T
public interface RcdbParamOption<out T> {
public val prettyName: String
public val fullName: String
public val paramValue: T
}

View File

@ -1,5 +1,5 @@
package de.pheerai.rcdbquery.dataMappings.internal
interface RelevantForAll {
internal interface RelevantForAll {
val relevantForAll: Boolean
}

View File

@ -1,5 +1,5 @@
package de.pheerai.rcdbquery.dataMappings.internal
interface StringGeneratable<T>: ParamKey {
internal interface StringGeneratable<T>: ParamKey {
fun of(input: String): T?
}

View File

@ -3,7 +3,7 @@ package de.pheerai.rcdbquery.dataMappings.layout
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
enum class Layout(
public enum class Layout(
override val prettyName: String,
override val fullName: String,
override val paramValue: Long
@ -37,8 +37,8 @@ enum class Layout(
constructor(name: String, paramValue: Long) : this(name, name, paramValue)
companion object : StringGeneratable<Layout> {
override val paramKey = "lo"
public companion object : StringGeneratable<Layout> {
override val paramKey: String = "lo"
override fun of(input: String): Layout? = values().find { input == it.fullName }
}

View File

@ -2,38 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.layout
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
class LayoutBuilder : MultiParamBuilder<Long, Layout>() {
public class LayoutBuilder : MultiParamBuilder<Long, Layout>() {
override fun add(param: Layout): LayoutBuilder {
super.add(param)
return this
}
fun bigApple() = this.add(Layout.BIG_APPLE)
fun wackyWorm() = this.add(Layout.BIG_APPLE)
fun circleDip() = this.add(Layout.CIRCLE_DIP)
fun circularGravityRailway() = this.add(Layout.CIRCULAR_GRAVIY_RAILWAY)
fun cyclone() = this.add(Layout.CYCLONE)
fun doubleFigureEight() = this.add(Layout.DOUBLE_FIGURE_EIGHT)
fun doubleOutAndBack() = this.add(Layout.DOUBLE_OUT_AND_BACK)
fun figureEight() = this.add(Layout.FIGURE_EIGHT)
fun jungleMouse() = this.add(Layout.JUNGLE_MOUSE)
fun lShapedOutAndBack() = this.add(Layout.L_SHAPED_OUT_AND_BACK)
fun miteMouse() = this.add(Layout.MITE_MOUSE)
fun outAndBack() = this.add(Layout.OUT_AND_BACK)
fun oval() = this.add(Layout.OVAL)
fun shuttleLoop() = this.add(Layout.SHUTTLE_LOOP)
fun singleHelixCenter() = this.add(Layout.SINGLE_HELIX_CENTER)
fun singleHelixLeft() = this.add(Layout.SINGLE_HELIX_LEFT)
fun singleHelixRear() = this.add(Layout.SINGLE_HELIX_REAR)
fun singleHelixRight() = this.add(Layout.SINGLE_HELIX_RIGHT)
fun terrain() = this.add(Layout.TERRAIN)
fun triangle() = this.add(Layout.TRIANGLE)
fun tripleOutAndBack() = this.add(Layout.TRIPLE_OUT_AND_BACK)
fun twinHelix() = this.add(Layout.TWIN_HELIX)
fun twister() = this.add(Layout.TWISTER)
fun uShuttle() = this.add(Layout.U_SHUTTLE)
fun wildMouse() = this.add(Layout.WILD_MOUSE)
fun zyklon() = this.add(Layout.ZYKLON)
fun galaxy() = this.add(Layout.ZYKLON)
override operator fun Layout.invoke(): LayoutBuilder = add(this)
}

View File

@ -1,10 +1,12 @@
package de.pheerai.rcdbquery.dataMappings.layout
import de.pheerai.rcdbquery.dsl.ParamsCollector
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
fun ParamsCollector.layout(body: LayoutBuilder.() -> LayoutBuilder): ParamsCollector {
public fun ParamsCollector.layout(body: LayoutBuilder.() -> LayoutBuilder): ParamsCollector {
val builder = LayoutBuilder()
builder.body()
with(Layout) {
builder.body()
}
this[Layout.paramKey] = builder.build()
return this
}

View File

@ -3,14 +3,13 @@ package de.pheerai.rcdbquery.dataMappings.order
import de.pheerai.rcdbquery.dataMappings.internal.ParamKey
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
import de.pheerai.rcdbquery.dataMappings.internal.RelevantForAll
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
@Suppress("unused")
enum class Order(
public enum class Order(
override val prettyName: String,
override val fullName: String,
override val paramValue: Long,
override val relevantForAll: Boolean = true
override val relevantForAll: Boolean = true,
) : RcdbParamOption<Long>,
RelevantForAll {
IMAGES("Images", "Amount of Images", 0),
@ -50,7 +49,7 @@ enum class Order(
constructor(name: String, paramId: Long) : this(name, name, paramId)
companion object: ParamKey {
override val paramKey = "order"
public companion object : ParamKey {
override val paramKey: String = "order"
}
}

View File

@ -2,7 +2,7 @@ package de.pheerai.rcdbquery.dataMappings.order
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
class OrderBuilder : MultiParamBuilder<Long, Order>() {
public class OrderBuilder : MultiParamBuilder<Long, Order>() {
override fun add(param: Order): OrderBuilder {
super.add(param)
return this
@ -18,30 +18,6 @@ class OrderBuilder : MultiParamBuilder<Long, Order>() {
return this
}
fun of(order: Order) = this.add(order)
fun manufacturer() = this.add(Order.MANUFACTURER)
fun inversions() = this.add(Order.INVERSIONS)
fun name() = this.add(Order.NAME)
fun location() = this.add(Order.LOCATION)
fun park() = this.add(Order.PARK)
fun opened() = this.add(Order.OPENED)
fun closed() = this.add(Order.CLOSED)
fun entered() = this.add(Order.ENTERED)
fun type() = this.add(Order.TYPE)
fun design() = this.add(Order.DESIGN)
fun classification() = this.add(Order.CLASSIFICATION)
fun layout() = this.add(Order.LAYOUT)
fun model() = this.add(Order.MODEL)
fun modelLine() = this.add(Order.MODEL_LINE)
fun speed() = this.add(Order.SPEED)
fun height() = this.add(Order.HEIGHT)
fun drop() = this.add(Order.DROP)
fun length() = this.add(Order.LENGTH)
fun angle() = this.add(Order.ANGLE)
fun serialNo() = this.add(Order.SERIAL_NO)
fun scale() = this.add(Order.SCALE)
fun rideTime() = this.add(Order.RIDE_TIME)
fun state() = this.add(Order.STATUS)
fun closing() = this.add(Order.CLOSING)
fun allRelevant() = this.addAll(Order.values().filter { it.relevantForAll })
override operator fun Order.invoke(): OrderBuilder = add(this)
public fun allRelevant(): OrderBuilder = this.addAll(Order.values().filter { it.relevantForAll })
}

View File

@ -1,8 +1,8 @@
package de.pheerai.rcdbquery.dataMappings.order
import de.pheerai.rcdbquery.dsl.ParamsCollector
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
fun ParamsCollector.sortBy(body: OrderBuilder.() -> OrderBuilder): ParamsCollector {
public fun ParamsCollector.sortBy(body: OrderBuilder.() -> OrderBuilder): ParamsCollector {
val builder = OrderBuilder()
builder.body()
this[Order.paramKey] = builder.build()

View File

@ -3,7 +3,7 @@ package de.pheerai.rcdbquery.dataMappings.page
import de.pheerai.rcdbquery.dataMappings.internal.ParamKey
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
class Page(override val paramValue: Long) :
internal class Page(override val paramValue: Long) :
RcdbParamOption<Long> {
override val fullName = "The page to show"
override val prettyName = "Page"

View File

@ -1,8 +1,8 @@
package de.pheerai.rcdbquery.dataMappings.page
import de.pheerai.rcdbquery.dsl.ParamsCollector
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
fun ParamsCollector.page(page: Long) = also {
public fun ParamsCollector.page(page: Long): ParamsCollector = also {
this[Page.paramKey] =
Page(page)
}

View File

@ -3,7 +3,7 @@ package de.pheerai.rcdbquery.dataMappings.searchTerm
import de.pheerai.rcdbquery.dataMappings.internal.ParamKey
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
class SearchTerm(override val paramValue: String) :
internal class SearchTerm(override val paramValue: String) :
RcdbParamOption<String> {
override val prettyName = "Search Term"
override val fullName = "Search for elements whose name contain this term"

View File

@ -1,8 +1,8 @@
package de.pheerai.rcdbquery.dataMappings.searchTerm
import de.pheerai.rcdbquery.dsl.ParamsCollector
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
fun ParamsCollector.searchTerm(term: String) = also {
public fun ParamsCollector.searchTerm(term: String): ParamsCollector = also {
it[SearchTerm.paramKey] = listOf(
SearchTerm(term)
)

View File

@ -4,7 +4,7 @@ import de.pheerai.rcdbquery.dataMappings.internal.ParamKey
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
@Suppress("unused")
enum class SearchType(
public enum class SearchType(
override val prettyName: String,
override val fullName: String,
override val paramValue: Long
@ -15,7 +15,7 @@ enum class SearchType(
PERSON("Person", "Search for a person (designer, engineer,...)", 13)
;
companion object: ParamKey {
override val paramKey = "ot"
public companion object: ParamKey {
override val paramKey: String = "ot"
}
}

View File

@ -1,7 +1,7 @@
package de.pheerai.rcdbquery.dataMappings.searchType
import de.pheerai.rcdbquery.dsl.ParamsCollector
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
fun ParamsCollector.searchType(searchType: SearchType) = also {
public fun ParamsCollector.searchType(searchType: SearchType): ParamsCollector = also {
it[SearchType.paramKey] = searchType
}

View File

@ -5,7 +5,7 @@ package de.pheerai.rcdbquery.dataMappings.startsWith
import de.pheerai.rcdbquery.dataMappings.internal.ParamKey
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
class StartsWith(override val paramValue: String) :
internal class StartsWith(override val paramValue: String) :
RcdbParamOption<String> {
override val prettyName = "Starts with"
override val fullName = "Name starting with term"

View File

@ -1,8 +1,8 @@
package de.pheerai.rcdbquery.dataMappings.startsWith
import de.pheerai.rcdbquery.dsl.ParamsCollector
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
fun ParamsCollector.startsWith(term: String) = also {
public fun ParamsCollector.startsWith(term: String): ParamsCollector = also {
this[StartsWith.paramKey] =
StartsWith(term)
}

View File

@ -4,7 +4,7 @@ import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
@Suppress("unused")
enum class Status(
public enum class Status(
override val prettyName: String,
override val fullName: String,
override val paramValue: Long
@ -18,10 +18,10 @@ enum class Status(
constructor(name: String, paramId: Long) : this(name, name, paramId)
companion object: StringGeneratable<Status> {
override val paramKey = "st"
public companion object: StringGeneratable<Status> {
override val paramKey: String = "st"
override fun of(input: String) = when (input) {
override fun of(input: String): Status? = when (input) {
"SBNO" -> SBNO
"Operating" -> OPERATING
"Under Construction" -> UNDER_CONSTRUCTION

View File

@ -2,14 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.status
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
class StatusBuilder : MultiParamBuilder<Long, Status>() {
public class StatusBuilder : MultiParamBuilder<Long, Status>() {
override fun add(param: Status): StatusBuilder {
super.add(param)
return this
}
fun sbno() = this.add(Status.SBNO)
fun operating() = this.add(Status.OPERATING)
fun underConstruction() = this.add(Status.UNDER_CONSTRUCTION)
fun stored() = this.add(Status.STORED)
override fun Status.invoke(): StatusBuilder = add(this)
}

View File

@ -1,8 +1,8 @@
package de.pheerai.rcdbquery.dataMappings.status
import de.pheerai.rcdbquery.dsl.ParamsCollector
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
fun ParamsCollector.status(body: StatusBuilder.() -> StatusBuilder): ParamsCollector {
public fun ParamsCollector.status(body: StatusBuilder.() -> StatusBuilder): ParamsCollector {
val builder = StatusBuilder()
builder.body()
this[Status.paramKey] = builder.build()

View File

@ -3,7 +3,7 @@ package de.pheerai.rcdbquery.dataMappings.thrill
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
enum class Thrill(
public enum class Thrill(
override val prettyName: String,
override val fullName: String,
override val paramValue: Long
@ -16,8 +16,8 @@ enum class Thrill(
constructor(name: String, paramValue: Long) : this(name, name, paramValue)
companion object : StringGeneratable<Thrill> {
override val paramKey = "sc"
public companion object : StringGeneratable<Thrill> {
override val paramKey: String = "sc"
override fun of(input: String): Thrill? = when (input) {
"Kiddie" -> KIDDIE

View File

@ -2,14 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.thrill
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
class ThrillBuilder : MultiParamBuilder<Long, Thrill>() {
public class ThrillBuilder : MultiParamBuilder<Long, Thrill>() {
override fun add(param: Thrill): ThrillBuilder {
super.add(param)
return this
}
fun kiddie() = this.add(Thrill.KIDDIE)
fun family() = this.add(Thrill.FAMILY)
fun thrill() = this.add(Thrill.THRILL)
fun extreme() = this.add(Thrill.EXTREME)
override fun Thrill.invoke(): ThrillBuilder = add(this)
}

View File

@ -1,8 +1,8 @@
package de.pheerai.rcdbquery.dataMappings.thrill
import de.pheerai.rcdbquery.dsl.ParamsCollector
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
fun ParamsCollector.type(body: ThrillBuilder.() -> ThrillBuilder): ParamsCollector {
public fun ParamsCollector.thrill(body: ThrillBuilder.() -> ThrillBuilder): ParamsCollector {
val builder = ThrillBuilder()
builder.body()
this[Thrill.paramKey] = builder.build()

View File

@ -3,7 +3,7 @@ package de.pheerai.rcdbquery.dataMappings.type
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
enum class Type(
public enum class Type(
override val prettyName: String,
override val fullName: String,
override val paramValue: Long
@ -14,10 +14,10 @@ enum class Type(
constructor(name: String, paramValue: Long): this(name, name, paramValue)
companion object: StringGeneratable<Type> {
override val paramKey = "ty"
public companion object: StringGeneratable<Type> {
override val paramKey: String = "ty"
override fun of(input: String) = when(input) {
override fun of(input: String): Type? = when(input) {
"Steel" -> STEEL
"Wood" -> WOOD
else -> null

View File

@ -2,12 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.type
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
class TypeBuilder : MultiParamBuilder<Long, Type>() {
public class TypeBuilder : MultiParamBuilder<Long, Type>() {
override fun add(param: Type): TypeBuilder {
super.add(param)
return this
}
fun steel() = this.add(Type.STEEL)
fun wood() = this.add(Type.WOOD)
override fun Type.invoke(): TypeBuilder = add(this)
}

View File

@ -1,12 +1,10 @@
package de.pheerai.rcdbquery.dataMappings.type
import de.pheerai.rcdbquery.dataMappings.thrill.Thrill
import de.pheerai.rcdbquery.dataMappings.thrill.ThrillBuilder
import de.pheerai.rcdbquery.dsl.ParamsCollector
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
fun ParamsCollector.thrill(body: ThrillBuilder.() -> ThrillBuilder): ParamsCollector {
val builder = ThrillBuilder()
public fun ParamsCollector.type(body: TypeBuilder.() -> TypeBuilder): ParamsCollector {
val builder = TypeBuilder()
builder.body()
this[Thrill.paramKey] = builder.build()
this[Type.paramKey] = builder.build()
return this
}

View File

@ -1,20 +1,23 @@
package de.pheerai.rcdbquery.dataMappings
import de.pheerai.rcdbquery.dataMappings.order.Order
import de.pheerai.rcdbquery.dsl.ParamsCollector
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
public const val EXTRA_COLUMNS_ERROR_MESSAGE: String =
"The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)"
@Suppress("unused")
@Deprecated(
"The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)",
EXTRA_COLUMNS_ERROR_MESSAGE,
ReplaceWith("sortBy"), DeprecationLevel.ERROR
)
fun ParamsCollector.extraColumns(orders: List<Order>): Nothing =
error("The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)")
public fun ParamsCollector.extraColumns(orders: List<Order>): Nothing =
error(EXTRA_COLUMNS_ERROR_MESSAGE)
@Suppress("unused")
@Deprecated(
"The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)",
EXTRA_COLUMNS_ERROR_MESSAGE,
ReplaceWith("sortBy"), DeprecationLevel.ERROR
)
fun ParamsCollector.extraColumns(vararg orders: Order): Nothing =
error("The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)")
public fun ParamsCollector.extraColumns(vararg orders: Order): Nothing =
error(EXTRA_COLUMNS_ERROR_MESSAGE)

View File

@ -5,10 +5,10 @@ import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
@Suppress("unused")
enum class Vendor(
public enum class Vendor(
override val prettyName: String,
override val fullName: String,
override val paramValue: Long
override val paramValue: Long,
) : RcdbParamOption<Long>, RcdbItem {
YAQIAO_MACHINE("Yaqiao", "Yaqiao Machine", 6471),
CREDIBLE("Credible", 6584),
@ -118,7 +118,7 @@ enum class Vendor(
TAKAHASHI_KIKAI_SANGYO("Takahashi Kikai Sangyo", 7472),
DYNAMIC("Dynamic Attractions", 7489),
GOLDEN_HORSE("Golden Horse", 7492),
WIEGAND("Wiegand", "Josef Wiegand GmbH & Co. KG", 7514),
WIEGAND("Wiegand", 7514),
ASCOT("Ascot Design", 7530),
DAL_AMUSEMENT_RIDES("DAL Amusement Rides Company", 7536),
CHILDRESS_COASTER("Childress Coaster", 7550),
@ -249,15 +249,18 @@ enum class Vendor(
constructor(name: String, paramId: Long) : this(name, name, paramId)
companion object : StringGeneratable<Vendor> {
override val paramKey = "mk"
override fun of(input: String) = values().find { input == it.fullName }
public companion object : StringGeneratable<Vendor> {
override val paramKey: String = "mk"
override fun of(input: String): Vendor? = values().find { input == it.fullName }
fun searchByName(name: String): List<Vendor> {
public fun searchByName(name: String): List<Vendor> {
val searchName = name.toLowerCase()
return values().filter {
it.fullName.toLowerCase().contains(searchName)
}.toList()
return values()
.filter {
it.fullName
.toLowerCase()
.contains(searchName)
}.toList()
}
}
}

View File

@ -2,16 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.vendor
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
class VendorBuilder : MultiParamBuilder<Long, Vendor>() {
public class VendorBuilder : MultiParamBuilder<Long, Vendor>() {
override fun add(param: Vendor): VendorBuilder {
super.add(param)
return this
}
fun of(vendor: Vendor) = this.add(vendor)
fun vekoma() = this.add(Vendor.VEKOMA)
fun intamin() = this.add(Vendor.INTAMIN)
fun mack() = this.add(Vendor.MACK)
fun bandm() = this.add(Vendor.B_AND_M)
fun gerstlauer() = this.add(Vendor.GERSTLAUER)
override operator fun Vendor.invoke(): VendorBuilder = add(this)
}

View File

@ -1,9 +1,9 @@
package de.pheerai.rcdbquery.dataMappings.vendor
import de.pheerai.rcdbquery.dsl.ParamsCollector
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
// TODO: Try to generify. This is currently lacking some sort of "This interface requires a companion implementing that interface"
fun ParamsCollector.vendors(body: VendorBuilder.() -> VendorBuilder): ParamsCollector {
public fun ParamsCollector.vendors(body: VendorBuilder.() -> VendorBuilder): ParamsCollector {
val builder = VendorBuilder()
builder.body()
this[Vendor.paramKey] = builder.build()

View File

@ -0,0 +1,48 @@
package de.pheerai.rcdbquery.dsl.params
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
import de.pheerai.rcdbquery.dataMappings.searchType.SearchType
import de.pheerai.rcdbquery.dsl.RcdbParams
public class ParamsCollector {
private val multiParams: MutableMap<String, List<RcdbParamOption<Any>>> = mutableMapOf()
private val singleParams: MutableMap<String, RcdbParamOption<Any>> = mutableMapOf()
public fun build(): RcdbParams = RcdbParams(buildMulti(), buildSingle())
/**
* Creates the Query Params from this builder.
* If no Search type has been set, this will default to "Coaster"
*/
private fun buildMulti() = multiParams.apply {
// Defaults go here, if any
}
.filter { it.value.isNotEmpty() }
.mapValues { e -> e.value.map { o -> o.paramValue.toString() } }
.let { MultiParams(it) }
private fun buildSingle() = singleParams.apply {
putIfAbsent(SearchType.paramKey, SearchType.COASTER)
}
.mapValues { e -> e.value.paramValue.toString() }
.let { SingleParams(it) }
public operator fun set(paramName: String, options: List<RcdbParamOption<Any>>) {
this.multiParams[paramName] = options
}
public operator fun set(paramName: String, option: RcdbParamOption<Any>) {
if (paramName !in singleParams && paramName !in multiParams) {
this.singleParams[paramName] = option
} else {
throw ParamAlreadySetException("Parameter $paramName already set.")
}
}
public fun getSingle(paramName: String): Any? = this.multiParams[paramName] ?: this.singleParams[paramName]
public fun getMulti(paramName: String): List<RcdbParamOption<Any>>? = this.multiParams[paramName]
public fun keys(): Set<String> = this.multiKeys().plus(singleKeys())
private fun multiKeys() = this.multiParams.keys.toSet()
private fun singleKeys() = this.singleParams.keys.toSet()
}

View File

@ -0,0 +1,8 @@
package de.pheerai.rcdbquery.dsl.params
public sealed class BaseParams<T> {
public abstract val params: Map<String, T>
}
public class MultiParams(override val params: Map<String, List<String>>) : BaseParams<List<String>>()
public class SingleParams(override val params: Map<String, String>) : BaseParams<String>()

View File

@ -0,0 +1,3 @@
package de.pheerai.rcdbquery.dsl.params
internal class ParamAlreadySetException(message: String) : IllegalArgumentException(message)

View File

@ -1,19 +1,19 @@
package de.pheerai.rcdbquery.dsl
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
import de.pheerai.rcdbquery.dataMappings.searchType.SearchType
import de.pheerai.rcdbquery.dsl.params.MultiParams
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
import de.pheerai.rcdbquery.dsl.params.SingleParams
// TODO: Restructure
data class RcdbParams(
val multiParams: MultiParams,
val singleParams: SingleParams
public data class RcdbParams(
private val multiParams: MultiParams,
private val singleParams: SingleParams,
) {
fun toStrings(): List<String> {
public fun toStrings(): List<String> {
val multiParamSequence: Sequence<Pair<String, String>> = this.multiParams
.params
.mapValues { it.value.joinToString(separator = ",") }
.map { it.toPair() }
.asSequence()
.map { e -> e.key to e.value.joinToString(separator = ",") }
val singleParamSequence: Sequence<Pair<String, String>> = this.singleParams
.params
.asSequence()
@ -24,62 +24,10 @@ data class RcdbParams(
}
}
sealed class Params<T> {
abstract val params: Map<String, T>
}
class ParamAlreadySetException(message: String) : IllegalArgumentException(message)
class MultiParams(override val params: Map<String, List<String>>) : Params<List<String>>()
class SingleParams(override val params: Map<String, String>) : Params<String>()
class ParamsCollector {
private val multiParams: MutableMap<String, List<RcdbParamOption<Any>>> = mutableMapOf()
private val singleParams: MutableMap<String, RcdbParamOption<Any>> = mutableMapOf()
fun build() = RcdbParams(buildMulti(), buildSingle())
/**
* Creates the Query Params from this builder.
* If no Search type has been set, this will default to "Coaster"
*/
private fun buildMulti() = multiParams.apply {
// Defaults go here, if any
}
.filter { it.value.isNotEmpty() }
.mapValues { e -> e.value.map { o -> o.paramValue.toString() } }
.let { MultiParams(it) }
private fun buildSingle() = singleParams.apply {
putIfAbsent(SearchType.paramKey, SearchType.COASTER)
}
.mapValues { e -> e.value.paramValue.toString() }
.let { SingleParams(it) }
operator fun set(paramName: String, options: List<RcdbParamOption<Any>>) {
this.multiParams[paramName] = options
}
operator fun set(paramName: String, option: RcdbParamOption<Any>) {
if (paramName !in singleParams && paramName !in multiParams) {
this.singleParams[paramName] = option
} else {
throw ParamAlreadySetException("Parameter $paramName already set.")
}
}
fun getSingle(paramName: String) = this.multiParams[paramName] ?: this.singleParams[paramName]
fun getMulti(paramName: String) = this.multiParams[paramName]
fun keys() = this.multiKeys().plus(singleKeys())
private fun multiKeys() = this.multiParams.keys.toSet()
private fun singleKeys() = this.singleParams.keys.toSet()
}
fun rcdbQuery(body: ParamsCollector.() -> ParamsCollector) =
public fun rcdbQuery(body: ParamsCollector.() -> ParamsCollector): String =
RcdbUrlQuery("https://www.rcdb.com/r.htm?", rcdbQueryParams(body)).toString()
data class RcdbUrlQuery(val baseUrl: String, val params: RcdbParams) {
private data class RcdbUrlQuery(val baseUrl: String, val params: RcdbParams) {
override fun toString(): String {
return params.toStrings()
.joinToString(prefix = baseUrl, separator = "&")
@ -87,9 +35,9 @@ data class RcdbUrlQuery(val baseUrl: String, val params: RcdbParams) {
}
/**
* Builder for the parameters only (mainly because it might be possilbe in the future to have an API with a POST search object?
* Builder for the parameters only (mainly because it might be possible in the future to have an API with a POST search object?
*/
fun rcdbQueryParams(body: ParamsCollector.() -> ParamsCollector): RcdbParams {
private fun rcdbQueryParams(body: ParamsCollector.() -> ParamsCollector): RcdbParams {
val builder = ParamsCollector()
builder.body()
return builder.build()

View File

@ -1,6 +1,7 @@
module rcdbquery.main {
exports de.pheerai.rcdbquery.dataMappings.category;
exports de.pheerai.rcdbquery.dataMappings.classification;
exports de.pheerai.rcdbquery.dataMappings;
exports de.pheerai.rcdbquery.dataMappings.design;
exports de.pheerai.rcdbquery.dataMappings.layout;
exports de.pheerai.rcdbquery.dataMappings.order;
@ -13,6 +14,8 @@ module rcdbquery.main {
exports de.pheerai.rcdbquery.dataMappings.type;
exports de.pheerai.rcdbquery.dataMappings.vendor;
exports de.pheerai.rcdbquery.dsl;
exports de.pheerai.rcdbquery.dsl.params;
requires kotlin.stdlib;
requires java.base;
}

View File

@ -0,0 +1,10 @@
package de.pheerai.rcdbquery
import io.kotest.core.config.AbstractProjectConfig
class TestConfig : AbstractProjectConfig() {
override val globalAssertSoftly = true
}
// Just for IJ to stop whining about unused classes
annotation class Spec()

View File

@ -1,38 +1,58 @@
package de.pheerai.rcdbquery.dsl
import de.pheerai.rcdbquery.dataMappings.vendor.Vendor
import de.pheerai.rcdbquery.Spec
import de.pheerai.rcdbquery.dataMappings.order.Order
import de.pheerai.rcdbquery.dataMappings.order.sortBy
import de.pheerai.rcdbquery.dataMappings.searchType.SearchType
import de.pheerai.rcdbquery.dataMappings.searchType.searchType
import de.pheerai.rcdbquery.dataMappings.type.Type
import de.pheerai.rcdbquery.dataMappings.type.type
import de.pheerai.rcdbquery.dataMappings.vendor.Vendor
import de.pheerai.rcdbquery.dataMappings.vendor.vendors
import de.pheerai.rcdbquery.dsl.params.ParamAlreadySetException
import io.kotest.assertions.asClue
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldHaveLength
@Spec
class RcdbQueryDslTest : StringSpec({
"should generate a proper URL" {
val actual = rcdbQuery {
rcdbQuery {
vendors {
vekoma()
mack()
of(Vendor.MAURER)
Vendor.VEKOMA()
Vendor.MACK()
Vendor.MAURER()
}
sortBy {
inversions()
manufacturer()
Order.INVERSIONS()
Order.MANUFACTURER()
}
}.asClue {
it shouldHaveLength 61
it shouldContain "https://www.rcdb.com/r.htm?"
it shouldContain "mk="
it shouldContain "6836"
it shouldContain "6856"
it shouldContain "6905"
it shouldContain "order="
it shouldContain "24"
it shouldContain "30"
it shouldContain "ot=2"
it.filter { c -> c == '&' } shouldHaveLength 2
}
}
"Should throw if unique value is reset" {
shouldThrow<ParamAlreadySetException> {
rcdbQuery {
searchType(SearchType.COASTER)
type {
Type.WOOD()
}
searchType(SearchType.AMUSEMENT_PARK)
}
}
actual.length shouldBe 61
actual.shouldContain("https://www.rcdb.com/r.htm?")
actual.shouldContain("mk=")
actual.shouldContain("6836")
actual.shouldContain("6856")
actual.shouldContain("6905")
actual.shouldContain("order=")
actual.shouldContain("24")
actual.shouldContain("30")
actual.shouldContain("ot=2")
actual.filter { it == '&' }.length shouldBe 2
}
})