Skip to content

Commit

Permalink
Updated dependencies and fixed few minor issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
ppanopticon committed Mar 8, 2022
1 parent 982a75a commit 7d7d215
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 53 deletions.
54 changes: 25 additions & 29 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 {
Expand Down
15 changes: 14 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
kotlin.code.style=official
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
13 changes: 5 additions & 8 deletions src/main/kotlin/ch/pontius/swissqr/api/cli/Cli.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {

Expand All @@ -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()}
Expand All @@ -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) {
Expand All @@ -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
}
Expand All @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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) {
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!")
}
Expand All @@ -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
}
Expand Down

0 comments on commit 7d7d215

Please sign in to comment.