From 7d7d215972866abe88321f5491a382ad7feff7dd Mon Sep 17 00:00:00 2001 From: Ralph Gasser Date: Tue, 8 Mar 2022 17:13:39 +0100 Subject: [PATCH] Updated dependencies and fixed few minor issues. --- build.gradle | 54 +++++++++---------- gradle.properties | 15 +++++- .../kotlin/ch/pontius/swissqr/api/cli/Cli.kt | 13 ++--- .../api/handlers/qr/GenerateQRCodeHandler.kt | 16 +++--- .../qr/GenerateQRCodeSimpleHandler.kt | 12 ++--- 5 files changed, 57 insertions(+), 53 deletions(-) diff --git a/build.gradle b/build.gradle index 2d43458..ae2a20c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,11 @@ -group 'ch.pontius' -version '1.0-SNAPSHOT' - -buildscript { - ext.kotlinVersion = '1.4.21' - repositories { - jcenter() - } - dependencies { - classpath "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" - classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion" - } +plugins { + id 'org.jetbrains.kotlin.jvm' version "$version_kotlin" + id 'org.jetbrains.kotlin.plugin.serialization' version "$version_kotlin" } +group 'ch.pontius' +version '1.1-SNAPSHOT' + apply plugin: 'java' apply plugin: 'kotlin' apply plugin: 'kotlinx-serialization' @@ -23,42 +16,45 @@ mainClassName = 'ch.pontius.swissqr.api.SwissQRServiceKt' repositories { mavenCentral() + maven { + url "https://oss.sonatype.org/content/repositories/snapshots/" + } } dependencies { ////// JLine, Clikt and Picnic for CLI - compile group: 'org.jline', name: 'jline', version: '3.19.0' - compile group: 'com.github.ajalt', name: 'clikt', version: '2.8.0' - compile group: 'com.jakewharton.picnic', name: 'picnic', version: '0.5.0' + compile group: 'org.jline', name: 'jline', version: version_jline + compile group: 'com.jakewharton.picnic', name: 'picnic', version: version_picnic + compile group: 'com.github.ajalt.clikt', name: 'clikt', version: version_clikt ///// Javalin - compile group: 'io.javalin', name: 'javalin', version: '3.13.3' - compile group: 'io.javalin', name: 'javalin-openapi', version: '3.13.3' + compile group: 'io.javalin', name: 'javalin', version: version_javalin + compile group: 'io.javalin', name: 'javalin-openapi', version: version_javalin ///// BoofCV - compile group: 'org.boofcv', name: 'boofcv-all', version: '0.37' + compile group: 'org.boofcv', name: 'boofcv-all', version: version_boofcv ///// MapDB - compile group: 'org.mapdb', name: 'mapdb', version: '3.0.8' + compile group: 'org.mapdb', name: 'mapdb', version: version_mapdb ////// BCrypt - compile group: 'org.mindrot', name: 'jbcrypt', version: '0.4' + compile group: 'org.mindrot', name: 'jbcrypt', version: version_bcrypt ///// PDFBox - compile group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.21' - compile group: 'org.apache.pdfbox', name: 'fontbox', version: '2.0.21' + compile group: 'org.apache.pdfbox', name: 'pdfbox', version: version_pdfbox + compile group: 'org.apache.pdfbox', name: 'fontbox', version: version_pdfbox ////// Log4j2 & SLF4j - compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.14.0' - compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.14.0' - compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.14.0' + compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: version_log4j2 + compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: version_log4j2 + compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: version_log4j2 //// QR Bill - compile group: 'net.codecrete.qrbill', name: 'qrbill-generator', version: '2.4.3+' + compile group: 'net.codecrete.qrbill', name: 'qrbill-generator', version: version_qrbill ///// Kotlin - compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: kotlinVersion - compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-serialization-json', version: '1.0.1' + compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: version_kotlin + compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-serialization-json', version: version_kotlinx_json_jvm } compileKotlin { diff --git a/gradle.properties b/gradle.properties index 29e08e8..cc9a25c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,14 @@ -kotlin.code.style=official \ No newline at end of file +kotlin.code.style=official + +version_bcrypt=0.4 +version_boofcv=0.38 +version_clikt=3.4.0 +version_javalin=3.13.12 +version_jline=3.21.0 +version_kotlin=1.6.10 +version_kotlinx_json_jvm=1.3.2 +version_log4j2=2.17.2 +version_mapdb=3.0.8 +version_pdfbox=2.0.25 +version_picnic=0.5.0 +version_qrbill=3.0.2 \ No newline at end of file diff --git a/src/main/kotlin/ch/pontius/swissqr/api/cli/Cli.kt b/src/main/kotlin/ch/pontius/swissqr/api/cli/Cli.kt index 6d292e2..e8b6ebf 100644 --- a/src/main/kotlin/ch/pontius/swissqr/api/cli/Cli.kt +++ b/src/main/kotlin/ch/pontius/swissqr/api/cli/Cli.kt @@ -10,7 +10,6 @@ import com.github.ajalt.clikt.output.HelpFormatter import org.jline.reader.LineReaderBuilder import org.jline.terminal.Terminal import org.jline.terminal.TerminalBuilder -import org.slf4j.Logger import java.io.IOException import java.util.ArrayList import java.util.regex.Pattern @@ -20,7 +19,7 @@ import kotlin.system.exitProcess * The [Cli] class that provides basic CLI functionality. * * @author Ralph Gasser - * @version 1.0.0 + * @version 1.0.1 */ class Cli(val dataAccessLayer: DataAccessLayer, val config: Config) { @@ -29,7 +28,7 @@ class Cli(val dataAccessLayer: DataAccessLayer, val config: Config) { private const val PROMPT = "QR> " } - /** Base [NoOpCliktCommand] with list of all knonw subcommands. */ + /** Base [NoOpCliktCommand] with list of all known subcommands. */ private val clikt = object: NoOpCliktCommand(name = "qr"){ init { context { helpFormatter = CliHelpFormatter()} @@ -45,7 +44,7 @@ class Cli(val dataAccessLayer: DataAccessLayer, val config: Config) { * program will terminate. */ fun loop() { - var terminal: Terminal? = null + var terminal: Terminal? try { terminal = TerminalBuilder.terminal() //basic terminal } catch (e: IOException) { @@ -59,10 +58,10 @@ class Cli(val dataAccessLayer: DataAccessLayer, val config: Config) { while (true) { val line = lineReader.readLine(PROMPT).trim() - if (line.toLowerCase() == "exit" || line.toLowerCase() == "quit") { + if (line.lowercase() == "exit" || line.lowercase() == "quit") { break } - if (line.toLowerCase() == "help") { + if (line.lowercase() == "help") { println(clikt.getFormattedHelp()) //TODO overwrite with something more useful in a cli context continue } @@ -77,8 +76,6 @@ class Cli(val dataAccessLayer: DataAccessLayer, val config: Config) { when (e) { is com.github.ajalt.clikt.core.NoSuchSubcommand -> println("Please enter a valid command; type help for list of commands.") is com.github.ajalt.clikt.core.PrintHelpMessage -> println(e.command.getFormattedHelp()) - is com.github.ajalt.clikt.core.MissingParameter, - is com.github.ajalt.clikt.core.NoSuchOption -> println(e.localizedMessage) else -> println(e.localizedMessage) } } diff --git a/src/main/kotlin/ch/pontius/swissqr/api/handlers/qr/GenerateQRCodeHandler.kt b/src/main/kotlin/ch/pontius/swissqr/api/handlers/qr/GenerateQRCodeHandler.kt index 81d41ec..14a77e5 100644 --- a/src/main/kotlin/ch/pontius/swissqr/api/handlers/qr/GenerateQRCodeHandler.kt +++ b/src/main/kotlin/ch/pontius/swissqr/api/handlers/qr/GenerateQRCodeHandler.kt @@ -6,7 +6,6 @@ import ch.pontius.swissqr.api.model.service.status.ErrorStatusException import ch.pontius.swissqr.api.model.service.status.Status import ch.pontius.swissqr.api.model.service.bill.Bill import ch.pontius.swissqr.api.model.users.Permission -import io.javalin.core.util.Header import io.javalin.http.BadRequestResponse import io.javalin.http.Context import io.javalin.plugin.openapi.annotations.* @@ -67,29 +66,30 @@ class GenerateQRCodeHandler : PostRestHandler { /* Extract and validate format parameters. */ try { - bill.format.outputSize = OutputSize.valueOf(ctx.pathParamMap().getOrDefault("type", "QR_BILL_ONLY").toUpperCase()) + bill.format.outputSize = OutputSize.valueOf(ctx.pathParamMap().getOrDefault("type", "QR_BILL_ONLY").uppercase()) } catch (e: IllegalArgumentException) { throw ErrorStatusException(400, "Illegal value for parameter 'type'. Possible values are A4_PORTRAIT_SHEET, QR_BILL_ONLY, QR_BILL_WITH_HORIZONTAL_LINE or QR_CODE_ONLY!") } try { - bill.format.language = Language.valueOf(ctx.queryParam("language", "EN")!!.toUpperCase()) + bill.format.language = Language.valueOf(ctx.queryParam("language", "EN")!!.uppercase()) } catch (e: IllegalArgumentException) { throw ErrorStatusException(400, "Illegal value for parameter 'language'. Possible values are DE, FR, IT or EN!") } - val width = ctx.queryParam("width")?.toDoubleOrNull() ?: when(bill.format.outputSize) { + val width = ctx.queryParam("width")?.toDoubleOrNull() ?: when(bill.format.outputSize ?: throw ErrorStatusException(500, "Bill format not specified! This is a programmers error.")) { OutputSize.A4_PORTRAIT_SHEET -> 210.0 OutputSize.QR_BILL_ONLY -> 210.0 - OutputSize.QR_BILL_WITH_HORIZONTAL_LINE -> 210.0 + OutputSize.QR_BILL_EXTRA_SPACE -> 210.0 OutputSize.QR_CODE_ONLY -> 46.0 } - val height = ctx.queryParam("height")?.toDoubleOrNull() ?: when(bill.format.outputSize) { + val height = ctx.queryParam("height")?.toDoubleOrNull() ?: when(bill.format.outputSize ?: throw ErrorStatusException(500, "Bill format not specified! This is a programmers error.")) { OutputSize.A4_PORTRAIT_SHEET -> 297.0 - OutputSize.QR_BILL_WITH_HORIZONTAL_LINE -> 110.0 + OutputSize.QR_BILL_EXTRA_SPACE -> 110.0 OutputSize.QR_BILL_ONLY -> 105.0 OutputSize.QR_CODE_ONLY -> 46.0 } + val resolution = ctx.queryParam("resolution")?.toIntOrNull() ?: 150 if (width < 0.0 || height < 0.0) { @@ -106,7 +106,7 @@ class GenerateQRCodeHandler : PostRestHandler { } /* Generate QR code. */ - val data = when(GraphicsFormat.valueOf(ctx.queryParam("format", "PNG")!!.toUpperCase())) { + val data = when(GraphicsFormat.valueOf(ctx.queryParam("format", "PNG")!!.uppercase())) { GraphicsFormat.PNG -> { bill.format.graphicsFormat = GraphicsFormat.PNG val canvas = PNGCanvas(width, height, resolution, "Arial, Helvetica, sans-serif") diff --git a/src/main/kotlin/ch/pontius/swissqr/api/handlers/qr/GenerateQRCodeSimpleHandler.kt b/src/main/kotlin/ch/pontius/swissqr/api/handlers/qr/GenerateQRCodeSimpleHandler.kt index 23b25c1..1f8980b 100644 --- a/src/main/kotlin/ch/pontius/swissqr/api/handlers/qr/GenerateQRCodeSimpleHandler.kt +++ b/src/main/kotlin/ch/pontius/swissqr/api/handlers/qr/GenerateQRCodeSimpleHandler.kt @@ -7,11 +7,8 @@ import ch.pontius.swissqr.api.model.service.status.Status import ch.pontius.swissqr.api.model.service.bill.Address import ch.pontius.swissqr.api.model.service.bill.Bill import ch.pontius.swissqr.api.model.users.Permission -import io.javalin.core.util.Header - import io.javalin.http.Context import io.javalin.plugin.openapi.annotations.* - import net.codecrete.qrbill.canvas.PNGCanvas import net.codecrete.qrbill.generator.GraphicsFormat import net.codecrete.qrbill.generator.Language @@ -136,13 +133,13 @@ class GenerateQRCodeSimpleHandler : GetRestHandler { /* Extract and validate format parameters. */ try { - bill.format.outputSize = OutputSize.valueOf(ctx.pathParamMap().getOrDefault("type", "QR_BILL_ONLY").toUpperCase()) + bill.format.outputSize = OutputSize.valueOf(ctx.pathParamMap().getOrDefault("type", "QR_BILL_ONLY").uppercase()) } catch (e: IllegalArgumentException) { throw ErrorStatusException(400, "Illegal value for parameter 'type'. Possible values are A4_PORTRAIT_SHEET, QR_BILL_ONLY, QR_BILL_WITH_HORIZONTAL_LINE or QR_CODE_ONLY!") } try { - bill.format.language = Language.valueOf(ctx.queryParam("language", "EN")!!.toUpperCase()) + bill.format.language = Language.valueOf(ctx.queryParam("language", "EN")!!.uppercase()) } catch (e: IllegalArgumentException) { throw ErrorStatusException(400, "Illegal value for parameter 'language'. Possible values are DE, FR, IT or EN!") } @@ -151,12 +148,13 @@ class GenerateQRCodeSimpleHandler : GetRestHandler { val width = when(bill.format.outputSize ?: throw ErrorStatusException(500, "Bill format not specified! This is a programmers error.")) { OutputSize.A4_PORTRAIT_SHEET -> 210.0 OutputSize.QR_BILL_ONLY -> 210.0 - OutputSize.QR_BILL_WITH_HORIZONTAL_LINE -> 210.0 + OutputSize.QR_BILL_EXTRA_SPACE -> 210.0 OutputSize.QR_CODE_ONLY -> 46.0 + else -> throw ErrorStatusException(400, "Unsupported bill format ${bill.format.outputSize}.") } val height = when(bill.format.outputSize ?: throw ErrorStatusException(500, "Bill format not specified! This is a programmers error.")) { OutputSize.A4_PORTRAIT_SHEET -> 297.0 - OutputSize.QR_BILL_WITH_HORIZONTAL_LINE -> 110.0 + OutputSize.QR_BILL_EXTRA_SPACE -> 110.0 OutputSize.QR_BILL_ONLY -> 105.0 OutputSize.QR_CODE_ONLY -> 46.0 }