Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ insert_final_newline = true
trim_trailing_whitespace = true

[*.{kt,kts}]
ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^
ktlint_standard_annotation = disabled
ktlint_standard_annotation-spacing = disabled
ktlint_standard_blank-line-before-declaration = disabled
Expand All @@ -19,4 +20,4 @@ ktlint_standard_function-expression-body = disabled
ktlint_standard_function-signature = disabled
ktlint_standard_modifier-list-spacing = disabled
ktlint_standard_multiline-expression-wrapping = disabled
ktlint_standard_parameter-list-wrapping = disabled
ktlint_standard_parameter-list-wrapping = disabled
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ archived project [jactor-rises](https://github.com/jactor-rises/jactor-rises))

### Set up

* a spring-boot 3 application
* a spring-boot 4 application
* build with [gradle](https://gradle.org).
* is using [h2](http://h2database.com) (in-memory database)
* run it with spring-boot
Expand Down Expand Up @@ -50,7 +50,7 @@ java -jar build/lib/jactor-persistence-<version>-SNAPSHOT.jar

#### Implementation

* [spring-boot 3.5.x](https://spring.io/projects/spring-boot)
* [spring-boot 4.x](https://spring.io/projects/spring-boot)
* [jetbrains-exposed](https://www.jetbrains.com/exposed/)
* [h2](http://h2database.com)
* [kotlin 2.x](https://kotlinlang.org)
Expand Down
36 changes: 25 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,34 @@ repositories {
}

tasks.register("printVersion") {
doLast {
println(project.version)
}
doLast { println(project.version) }
}

tasks.test {
useJUnitPlatform()
tasks {
val ktlintFormatAndCheck by registering {
dependsOn("ktlintFormat")
doLast {
ProcessBuilder("${project.rootDir}/gradlew", "ktlintCheck")
.directory(project.rootDir).inheritIO()
.start().waitFor() // venter på at prosessen skal fullføre før vi går videre til testene
}
}

matching { it.name.startsWith("runKtlintCheck") }.configureEach {
mustRunAfter(project.tasks.matching { it.name.startsWith("runKtlintFormat") })
}

test {
useJUnitPlatform()

jvmArgs("--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED")
exclude("**/RunCucumberTest*")
jvmArgs("--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED")
exclude("**/RunCucumberTest*")
dependsOn(ktlintFormatAndCheck)

testLogging {
events("passed", "skipped", "failed")
showStandardStreams = true
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
testLogging {
events("passed", "skipped", "failed")
showStandardStreams = true
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jvm = "25"
kotlin = "2.3.20"
kotlin-logging = "8.0.01"
ktlint = "14.0.1"
spring-boot = "4.0.4"
spring-boot = "4.0.5"
springdoc-openapi = "1.8.0"
springmockk = "5.0.1"
versions-plugin = "0.53.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ fun Throwable.exceptionMessageMedCause(): String {
return "$exceptionMessage$causeMessage".take(10000)
}

private fun Throwable.exceptionMessage() =
when (this is HttpClientErrorException) {
true -> "Internal client, $statusCode: ${simpleExceptionMessage()}"
false -> simpleExceptionMessage()
}
private fun Throwable.exceptionMessage() = when (this is HttpClientErrorException) {
true -> "Internal client, $statusCode: ${simpleExceptionMessage()}"
false -> simpleExceptionMessage()
}

private fun Throwable?.findRootCauseMessage(): String? {
var rootCause: Throwable? = this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ class JactorPersistence {
}
}

private fun list(args: Array<String>) =
when (args.isEmpty()) {
true -> "without arguments!"
false -> "with arguments: ${args.joinToString { " " }}!"
}
private fun list(args: Array<String>) = when (args.isEmpty()) {
true -> "without arguments!"
false -> "with arguments: ${args.joinToString { " " }}!"
}

fun main(args: Array<String>) {
runApplication<JactorPersistence>(*args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ class PersistenceHandler {
suspend fun <T : PersistentDao<*>> modifyAndSave(
dao: T,
modifier: suspend (T) -> T,
): T =
run {
dao.isPersisted.whenTrue { dao.modifiedBy(modifier = "todo") }
modifier(dao)
}
): T = run {
dao.isPersisted.whenTrue { dao.modifiedBy(modifier = "todo") }
modifier(dao)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ data class Persistent(
val timeOfCreation: LocalDateTime = LocalDateTime.now(),
val timeOfModification: LocalDateTime = LocalDateTime.now(),
) {
fun toPersistentDto() =
PersistentDto(
id = id,
createdBy = createdBy,
modifiedBy = modifiedBy,
timeOfCreation = timeOfCreation,
timeOfModification = timeOfModification,
)
fun toPersistentDto() = PersistentDto(
id = id,
createdBy = createdBy,
modifiedBy = modifiedBy,
timeOfCreation = timeOfCreation,
timeOfModification = timeOfModification,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ interface PersistentDao<T> {

fun modifiedBy(modifier: String): T

fun toPersistent() =
Persistent(
id = id,
createdBy = createdBy,
modifiedBy = modifiedBy,
timeOfCreation = timeOfCreation,
timeOfModification = timeOfModification,
)
fun toPersistent() = Persistent(
id = id,
createdBy = createdBy,
modifiedBy = modifiedBy,
timeOfCreation = timeOfCreation,
timeOfModification = timeOfModification,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,17 @@ data class Address(
zipCode = dao.zipCode,
)

fun toAddressDao() =
AddressDao(
id = null,
createdBy = persistent.createdBy,
timeOfCreation = persistent.timeOfCreation,
modifiedBy = persistent.modifiedBy,
timeOfModification = persistent.timeOfModification,
addressLine1 = addressLine1,
addressLine2 = addressLine2,
addressLine3 = addressLine3,
city = city,
country = country,
zipCode = zipCode,
)
fun toAddressDao() = AddressDao(
id = null,
createdBy = persistent.createdBy,
timeOfCreation = persistent.timeOfCreation,
modifiedBy = persistent.modifiedBy,
timeOfModification = persistent.timeOfModification,
addressLine1 = addressLine1,
addressLine2 = addressLine2,
addressLine3 = addressLine3,
city = city,
country = country,
zipCode = zipCode,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ data class AddressDao(
return this
}

fun toAddress() =
Address(
persistent = toPersistent(),
addressLine1 = addressLine1,
addressLine2 = addressLine2,
addressLine3 = addressLine3,
city = city,
country = country,
zipCode = zipCode,
)
fun toAddress() = Address(
persistent = toPersistent(),
addressLine1 = addressLine1,
addressLine2 = addressLine2,
addressLine3 = addressLine3,
city = city,
country = country,
zipCode = zipCode,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import org.jetbrains.exposed.v1.jdbc.selectAll
import java.util.UUID

object AddressRepositoryObject : AddressRepository {
override fun findById(id: UUID): AddressDao? =
Addresses
.selectAll()
.andWhere { Addresses.id eq id }
.singleOrNull()
?.toAddressDao()
override fun findById(id: UUID): AddressDao? = Addresses
.selectAll()
.andWhere { Addresses.id eq id }
.singleOrNull()
?.toAddressDao()
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import org.jetbrains.exposed.v1.javatime.datetime
import java.util.UUID

object Addresses : IdTable<UUID>(name = "T_ADDRESS") {
override val id: Column<EntityID<UUID>> =
javaUUID("ID")
.clientDefault { UUIDv7.generate() }
.entityId()
override val id: Column<EntityID<UUID>> = javaUUID("ID")
.clientDefault { UUIDv7.generate() }
.entityId()

val createdBy = text("CREATED_BY")
val modifiedBy = text("UPDATED_BY")
Expand Down
32 changes: 15 additions & 17 deletions src/main/kotlin/com/github/jactor/rises/persistence/blog/Blog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,20 @@ data class Blog(
) {
val id: UUID? get() = persistent.id

fun toBlogDao() =
BlogDao(
id = persistent.id,
created = created ?: persistent.timeOfCreation.toLocalDate(),
createdBy = persistent.createdBy,
modifiedBy = persistent.modifiedBy,
timeOfCreation = persistent.timeOfCreation,
timeOfModification = persistent.timeOfModification,
title = title,
userId = userId,
)
fun toBlogDao() = BlogDao(
id = persistent.id,
created = created ?: persistent.timeOfCreation.toLocalDate(),
createdBy = persistent.createdBy,
modifiedBy = persistent.modifiedBy,
timeOfCreation = persistent.timeOfCreation,
timeOfModification = persistent.timeOfModification,
title = title,
userId = userId,
)

fun toBlogDto() =
BlogDto(
persistentDto = persistent.toPersistentDto(),
title = title,
userId = userId,
)
fun toBlogDto() = BlogDto(
persistentDto = persistent.toPersistentDto(),
title = title,
userId = userId,
)
}
Loading
Loading