From 1e6a73aae3921071cab8c2ca63ae48d0fe219c74 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 21 Apr 2024 22:27:55 -0700 Subject: [PATCH] chore(deps): update plugin org.jlleitschuh.gradle.ktlint to v12 --- build.gradle.kts | 2 +- .../rahulsom/grooves/EventApplyOutcome.kt | 3 +- .../com/github/rahulsom/grooves/EventType.kt | 5 +- .../github/rahulsom/grooves/GroovesQuery.kt | 19 ++- .../rahulsom/grooves/functions/Deprecator.kt | 5 +- .../grooves/functions/EventHandler.kt | 5 +- .../grooves/functions/EventsProvider.kt | 2 +- .../grooves/functions/ExceptionHandler.kt | 6 +- .../grooves/functions/SnapshotProvider.kt | 5 +- .../grooves/functions/SnapshotVersioner.kt | 5 +- .../rahulsom/grooves/impl/GroovesQueryImpl.kt | 58 +++++--- .../grooves/logging/IndentedLogging.kt | 8 +- .../rahulsom/grooves/asciidoctor/Aggregate.kt | 43 +++--- .../rahulsom/grooves/asciidoctor/Constants.kt | 12 +- .../rahulsom/grooves/asciidoctor/Event.kt | 49 +++---- .../rahulsom/grooves/asciidoctor/EventType.kt | 7 +- .../grooves/asciidoctor/EventsBlock.kt | 18 ++- .../grooves/asciidoctor/SvgBuilder.kt | 39 +++--- .../grooves/example/push/Application.kt | 88 ++++++------ .../kotlin/grooves/example/push/Balance.kt | 25 ++-- .../grooves/example/push/BankingModule.kt | 4 +- .../example/push/ContextAwareScheduler.kt | 8 +- .../grooves/example/push/ContextManager.kt | 2 +- .../kotlin/grooves/example/push/Database.kt | 23 ++-- .../grooves/example/push/EventService.kt | 26 ++-- .../grooves/example/push/Transaction.kt | 10 +- .../grooves/example/pushstyle/PushTest.kt | 1 - .../kotlin/grooves/boot/kotlin/BootStrap.kt | 80 ++++++----- .../kotlin/controllers/PatientController.kt | 73 +++++----- .../grooves/boot/kotlin/domain/Patient.kt | 1 + .../boot/kotlin/domain/PatientAccount.kt | 9 +- .../boot/kotlin/domain/PatientEvent.kt | 8 +- .../boot/kotlin/domain/PatientHealth.kt | 17 +-- .../kotlin/queries/PatientAccountQuery.kt | 127 +++++++++++------- .../boot/kotlin/queries/PatientHealthQuery.kt | 89 +++++++----- .../kotlin/repositories/PatientRepository.kt | 18 ++- .../rahulsom/grooves/api/EventApplyOutcome.kt | 2 +- .../rahulsom/grooves/api/events/BaseEvent.kt | 1 - .../grooves/api/events/DeprecatedBy.kt | 1 - .../rahulsom/grooves/api/events/Deprecates.kt | 1 - .../grooves/api/events/DisjoinEvent.kt | 1 - .../rahulsom/grooves/api/events/JoinEvent.kt | 4 +- .../grooves/api/events/RevertEvent.kt | 1 - .../rahulsom/grooves/api/snapshots/Join.kt | 3 +- .../grooves/api/snapshots/Snapshot.kt | 3 +- .../grooves/api/snapshots/TemporalJoin.kt | 3 +- .../grooves/api/snapshots/TemporalSnapshot.kt | 4 +- .../grooves/api/snapshots/VersionedJoin.kt | 3 +- .../api/snapshots/VersionedSnapshot.kt | 4 +- .../api/snapshots/internal/BaseJoin.kt | 5 +- .../api/snapshots/internal/BaseSnapshot.kt | 4 +- 51 files changed, 534 insertions(+), 406 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 380319dc5..ed2a56c1a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ plugins { id("com.github.rahulsom.waena.root").version("0.6.1") id("org.jetbrains.kotlin.jvm").version("1.8.22").apply(false) id("org.jetbrains.kotlin.plugin.allopen").version("1.8.22").apply(false) - id("org.jlleitschuh.gradle.ktlint").version("11.6.1").apply(false) + id("org.jlleitschuh.gradle.ktlint").version("12.1.0").apply(false) id("org.springframework.boot").version("3.0.4").apply(false) id("io.spring.dependency-management").version("1.1.4").apply(false) id("org.sonarqube").version("4.4.1.3373") diff --git a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/EventApplyOutcome.kt b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/EventApplyOutcome.kt index 578b49f28..67e0f69d1 100644 --- a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/EventApplyOutcome.kt +++ b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/EventApplyOutcome.kt @@ -4,5 +4,6 @@ package com.github.rahulsom.grooves * The outcome of applying an event to a snapshot. */ enum class EventApplyOutcome { - RETURN, CONTINUE + RETURN, + CONTINUE, } \ No newline at end of file diff --git a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/EventType.kt b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/EventType.kt index 15dba31e2..c8f461418 100644 --- a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/EventType.kt +++ b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/EventType.kt @@ -1,5 +1,8 @@ package com.github.rahulsom.grooves enum class EventType { - Normal, Revert, Deprecates, DeprecatedBy + Normal, + Revert, + Deprecates, + DeprecatedBy, } \ No newline at end of file diff --git a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/GroovesQuery.kt b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/GroovesQuery.kt index 5314f1354..b69fd53a4 100644 --- a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/GroovesQuery.kt +++ b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/GroovesQuery.kt @@ -1,12 +1,17 @@ package com.github.rahulsom.grooves interface GroovesQuery { - fun computeSnapshot(aggregate: Aggregate, at: VersionOrTimestamp?, redirect: Boolean): - GroovesResult + fun computeSnapshot( + aggregate: Aggregate, + at: VersionOrTimestamp?, + redirect: Boolean, + ): GroovesResult - fun computeSnapshot(aggregate: Aggregate, at: VersionOrTimestamp?) = - ( - computeSnapshot(aggregate, at, true) - as GroovesResult.Success - ).snapshot + fun computeSnapshot( + aggregate: Aggregate, + at: VersionOrTimestamp?, + ) = ( + computeSnapshot(aggregate, at, true) + as GroovesResult.Success + ).snapshot } \ No newline at end of file diff --git a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/Deprecator.kt b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/Deprecator.kt index 99c2aeecb..df20a7c6b 100644 --- a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/Deprecator.kt +++ b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/Deprecator.kt @@ -7,5 +7,8 @@ import com.github.rahulsom.grooves.logging.Trace */ interface Deprecator { @Trace - fun invoke(snapshot: Snapshot, deprecatingAggregate: Aggregate) + fun invoke( + snapshot: Snapshot, + deprecatingAggregate: Aggregate, + ) } \ No newline at end of file diff --git a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/EventHandler.kt b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/EventHandler.kt index b412b7654..f243d69b7 100644 --- a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/EventHandler.kt +++ b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/EventHandler.kt @@ -8,5 +8,8 @@ import com.github.rahulsom.grooves.logging.Trace */ interface EventHandler { @Trace - fun invoke(event: Event, snapshot: Snapshot): EventApplyOutcome + fun invoke( + event: Event, + snapshot: Snapshot, + ): EventApplyOutcome } \ No newline at end of file diff --git a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/EventsProvider.kt b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/EventsProvider.kt index 52a43e872..f92b014c2 100644 --- a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/EventsProvider.kt +++ b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/EventsProvider.kt @@ -12,6 +12,6 @@ interface EventsProvider { fun invoke( aggregates: List, versionOrTimestamp: VersionOrTimestamp?, - lastSnapshot: Snapshot + lastSnapshot: Snapshot, ): Stream } \ No newline at end of file diff --git a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/ExceptionHandler.kt b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/ExceptionHandler.kt index e61d0563e..797191fbd 100644 --- a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/ExceptionHandler.kt +++ b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/ExceptionHandler.kt @@ -8,5 +8,9 @@ import com.github.rahulsom.grooves.logging.Trace */ interface ExceptionHandler { @Trace - fun invoke(exception: Exception, snapshot: Snapshot, event: Event): EventApplyOutcome + fun invoke( + exception: Exception, + snapshot: Snapshot, + event: Event, + ): EventApplyOutcome } \ No newline at end of file diff --git a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/SnapshotProvider.kt b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/SnapshotProvider.kt index b4d7393c5..2ee903e0d 100644 --- a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/SnapshotProvider.kt +++ b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/SnapshotProvider.kt @@ -7,5 +7,8 @@ import com.github.rahulsom.grooves.logging.Trace */ interface SnapshotProvider { @Trace - fun invoke(aggregate: Aggregate, versionOrTimestamp: VersionOrTimestamp?): Snapshot? + fun invoke( + aggregate: Aggregate, + versionOrTimestamp: VersionOrTimestamp?, + ): Snapshot? } \ No newline at end of file diff --git a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/SnapshotVersioner.kt b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/SnapshotVersioner.kt index 5bdb94677..0373e3fcd 100644 --- a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/SnapshotVersioner.kt +++ b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/functions/SnapshotVersioner.kt @@ -7,5 +7,8 @@ import com.github.rahulsom.grooves.logging.Trace */ interface SnapshotVersioner { @Trace - fun invoke(snapshot: Snapshot, versionOrTimestamp: VersionOrTimestamp) + fun invoke( + snapshot: Snapshot, + versionOrTimestamp: VersionOrTimestamp, + ) } \ No newline at end of file diff --git a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/impl/GroovesQueryImpl.kt b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/impl/GroovesQueryImpl.kt index d24a30ee3..b3478a9b0 100644 --- a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/impl/GroovesQueryImpl.kt +++ b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/impl/GroovesQueryImpl.kt @@ -39,13 +39,16 @@ class GroovesQueryImpl( private val snapshotVersioner: SnapshotVersioner, private val deprecatedByProvider: DeprecatedByProvider, private val revertedEventProvider: RevertedEventProvider, - private val eventIdProvider: EventIdProvider + private val eventIdProvider: EventIdProvider, ) : GroovesQuery { - private val log = LoggerFactory.getLogger(javaClass) @Trace - override fun computeSnapshot(aggregate: Aggregate, at: VersionOrTimestamp?, redirect: Boolean): GroovesResult { + override fun computeSnapshot( + aggregate: Aggregate, + at: VersionOrTimestamp?, + redirect: Boolean, + ): GroovesResult { val providedSnapshot = snapshotProvider.invoke(aggregate, at) val snapshot = providedSnapshot ?: emptySnapshotProvider.invoke(aggregate) val events = eventsProvider.invoke(listOf(aggregate), at, snapshot).collect(Collectors.toList()) @@ -67,18 +70,20 @@ class GroovesQueryImpl( aggregates: List, at: VersionOrTimestamp?, redirect: Boolean, - beforeReturn: (CallIdentifier, Snapshot?) -> Unit + beforeReturn: (CallIdentifier, Snapshot?) -> Unit, ): GroovesResult { val indent = IndentedLogging.indent() - val callIdentifier = CallIdentifier( - "${indent}computeSnapshotImpl(<... ${events.size} items>, $snapshot, $aggregates, $at)" - ) + val callIdentifier = + CallIdentifier( + "${indent}computeSnapshotImpl(<... ${events.size} items>, $snapshot, $aggregates, $at)", + ) log.trace(callIdentifier.data) IndentedLogging.stepIn() - val (revertEvents, forwardEvents) = events - .partition { eventClassifier.invoke(it) == Revert } - .let { it.first.toMutableList() to it.second.toMutableList() } + val (revertEvents, forwardEvents) = + events + .partition { eventClassifier.invoke(it) == Revert } + .let { it.first.toMutableList() to it.second.toMutableList() } if (revertsExistOutsideEvents(revertEvents, indent, forwardEvents)) { val snapshot1 = emptySnapshotProvider.invoke(aggregates[0]) @@ -110,14 +115,16 @@ class GroovesQueryImpl( DeprecatedBy -> { val ret = deprecatedByProvider.invoke(event) log.debug("$indent ...The aggregate was deprecated by ${ret.aggregate}. Recursing to compute snapshot for it...") - val refEvent = eventsProvider.invoke(listOf(ret.aggregate), null, emptySnapshotProvider.invoke(ret.aggregate)) - .collect(Collectors.toList()) - .find { eventIdProvider.invoke(it) == ret.eventId } + val refEvent = + eventsProvider.invoke(listOf(ret.aggregate), null, emptySnapshotProvider.invoke(ret.aggregate)) + .collect(Collectors.toList()) + .find { eventIdProvider.invoke(it) == ret.eventId } val redirectVersion = eventVersioner.invoke(refEvent!!) val otherSnapshot = snapshotProvider.invoke(ret.aggregate, redirectVersion) ?: emptySnapshotProvider.invoke(ret.aggregate) - val newEvents = eventsProvider.invoke(listOf(ret.aggregate) + aggregates, redirectVersion, otherSnapshot) - .collect(Collectors.toList()) + val newEvents = + eventsProvider.invoke(listOf(ret.aggregate) + aggregates, redirectVersion, otherSnapshot) + .collect(Collectors.toList()) @Suppress("LiftReturnOrAssignment") if (redirect) { return computeSnapshotImpl(newEvents, otherSnapshot, aggregates + listOf(ret.aggregate), at, redirect) { c, s -> @@ -152,7 +159,11 @@ class GroovesQueryImpl( return GroovesResult.Success(snapshot) } - private fun revertsExistOutsideEvents(revertEvents: MutableList, indent: String, forwardEvents: MutableList): Boolean { + private fun revertsExistOutsideEvents( + revertEvents: MutableList, + indent: String, + forwardEvents: MutableList, + ): Boolean { while (revertEvents.isNotEmpty()) { val mostRecentRevert = revertEvents.removeLast() val revertedEvent = revertedEventProvider.invoke(mostRecentRevert) @@ -172,10 +183,13 @@ class GroovesQueryImpl( return false } - private inline fun tryRunning(snapshot: Snapshot, it: Event, code: () -> EventApplyOutcome) = - try { - code() - } catch (e: Exception) { - exceptionHandler.invoke(e, snapshot, it) - } + private inline fun tryRunning( + snapshot: Snapshot, + it: Event, + code: () -> EventApplyOutcome, + ) = try { + code() + } catch (e: Exception) { + exceptionHandler.invoke(e, snapshot, it) + } } \ No newline at end of file diff --git a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/logging/IndentedLogging.kt b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/logging/IndentedLogging.kt index a51472178..1dc7c16ff 100644 --- a/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/logging/IndentedLogging.kt +++ b/grooves-core/src/main/kotlin/com/github/rahulsom/grooves/logging/IndentedLogging.kt @@ -11,18 +11,24 @@ class IndentedLogging { companion object { private val indentLevel = ThreadLocal() private const val INITIAL_INDENT = 1 + fun stepIn() = indentLevel.set(indentLevel.getOrSet { INITIAL_INDENT } + 1) + fun stepOut() = indentLevel.set(indentLevel.getOrSet { INITIAL_INDENT } - 1) @JvmStatic fun indent() = "".padStart(indentLevel.getOrSet { INITIAL_INDENT } * 2) + private fun eventsToString(it: List<*>): Any = "<... ${it.size} item(s)>" } @Suppress("unused", "UNUSED_PARAMETER") @Around(value = "@annotation(trace)", argNames = "trace") @ExperimentalStdlibApi - fun around(joinPoint: ProceedingJoinPoint, trace: Trace): Any? { + fun around( + joinPoint: ProceedingJoinPoint, + trace: Trace, + ): Any? { val signature = joinPoint.signature val classWithFunction = joinPoint.target.javaClass val loggerName = classWithFunction.name.replace(Regex("\\\$\\\$Lambda.*$"), "") diff --git a/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/Aggregate.kt b/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/Aggregate.kt index af6037e6b..4098576e2 100644 --- a/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/Aggregate.kt +++ b/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/Aggregate.kt @@ -1,11 +1,11 @@ package com.github.rahulsom.grooves.asciidoctor -import com.github.rahulsom.grooves.asciidoctor.Constants.aggregateHeight -import com.github.rahulsom.grooves.asciidoctor.Constants.aggregateWidth -import com.github.rahulsom.grooves.asciidoctor.Constants.eventLineHeight -import com.github.rahulsom.grooves.asciidoctor.Constants.eventSpace -import com.github.rahulsom.grooves.asciidoctor.Constants.offset -import com.github.rahulsom.grooves.asciidoctor.Constants.textLineHeight +import com.github.rahulsom.grooves.asciidoctor.Constants.AGGREGATE_HEIGHT +import com.github.rahulsom.grooves.asciidoctor.Constants.AGGREGATE_WIDTH +import com.github.rahulsom.grooves.asciidoctor.Constants.EVENT_LINE_HEIGHT +import com.github.rahulsom.grooves.asciidoctor.Constants.EVENT_SPACE +import com.github.rahulsom.grooves.asciidoctor.Constants.OFFSET +import com.github.rahulsom.grooves.asciidoctor.Constants.TEXT_LINE_HEIGHT import com.github.rahulsom.svg.G import com.github.rahulsom.svg.ObjectFactory import java.util.Date @@ -25,39 +25,40 @@ class Aggregate(private val counter: Int, var type: String, var id: String, var } fun buildSvg(dates: Map): G { - val y = index * eventLineHeight + offset - val yMid = index * eventLineHeight + offset + aggregateHeight / 2 + val y = index * EVENT_LINE_HEIGHT + OFFSET + val yMid = index * EVENT_LINE_HEIGHT + OFFSET + AGGREGATE_HEIGHT / 2 val objectFactory = ObjectFactory() - val g = objectFactory.createG() - .withId("aggregate_$counter") - .withClazz("aggregate") + val g = + objectFactory.createG() + .withId("aggregate_$counter") + .withClazz("aggregate") return g.withSVGDescriptionClassOrSVGAnimationClassOrSVGStructureClass( objectFactory.createRect( objectFactory.createRect().withX("10").withY(y.toString()) - .withWidth("$aggregateWidth").withHeight("$aggregateHeight") + .withWidth("$AGGREGATE_WIDTH").withHeight("$AGGREGATE_HEIGHT"), ), objectFactory.createText( - objectFactory.createText().withX("15").withY("${y + textLineHeight}") + objectFactory.createText().withX("15").withY("${y + TEXT_LINE_HEIGHT}") .withClazz("type") - .withContent(type) + .withContent(type), ), objectFactory.createText( - objectFactory.createText().withX("15").withY("${y + textLineHeight * 2}") + objectFactory.createText().withX("15").withY("${y + TEXT_LINE_HEIGHT * 2}") .withClazz("id") - .withContent(id) + .withContent(id), ), objectFactory.createText( objectFactory.createText().withX("10").withY("${y - 5}") .withClazz("description") - .withContent(description) + .withContent(description), ), objectFactory.createLine( - objectFactory.createLine().withX1("${10 + aggregateWidth}").withY1("$yMid") - .withX2("${dates.values.maxOrNull()!! * eventSpace + 3 * aggregateWidth}") + objectFactory.createLine().withX1("${10 + AGGREGATE_WIDTH}").withY1("$yMid") + .withX2("${dates.values.maxOrNull()!! * EVENT_SPACE + 3 * AGGREGATE_WIDTH}") .withY2("$yMid") - .withClazz("eventLine").withMarkerEnd("url(#triangle)") - ) + .withClazz("eventLine").withMarkerEnd("url(#triangle)"), + ), ) } } \ No newline at end of file diff --git a/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/Constants.kt b/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/Constants.kt index 4ce6a4a87..d8fbab701 100644 --- a/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/Constants.kt +++ b/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/Constants.kt @@ -6,12 +6,12 @@ package com.github.rahulsom.grooves.asciidoctor * @author Rahul Somasunderam */ object Constants { - const val eventLineHeight: Int = 100 - const val aggregateHeight: Int = 40 - const val aggregateWidth: Int = 100 - const val eventSpace: Int = 50 - const val offset: Int = 45 - const val textLineHeight: Int = 18 + const val EVENT_LINE_HEIGHT: Int = 100 + const val AGGREGATE_HEIGHT: Int = 40 + const val AGGREGATE_WIDTH: Int = 100 + const val EVENT_SPACE: Int = 50 + const val OFFSET: Int = 45 + const val TEXT_LINE_HEIGHT: Int = 18 val CSS: String by lazy { Constants::class.java.getResourceAsStream("/esdiag.css").reader().readText() diff --git a/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/Event.kt b/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/Event.kt index 84faa912e..c9fa664d3 100644 --- a/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/Event.kt +++ b/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/Event.kt @@ -1,10 +1,10 @@ package com.github.rahulsom.grooves.asciidoctor -import com.github.rahulsom.grooves.asciidoctor.Constants.aggregateHeight -import com.github.rahulsom.grooves.asciidoctor.Constants.aggregateWidth -import com.github.rahulsom.grooves.asciidoctor.Constants.eventLineHeight -import com.github.rahulsom.grooves.asciidoctor.Constants.eventSpace -import com.github.rahulsom.grooves.asciidoctor.Constants.offset +import com.github.rahulsom.grooves.asciidoctor.Constants.AGGREGATE_HEIGHT +import com.github.rahulsom.grooves.asciidoctor.Constants.AGGREGATE_WIDTH +import com.github.rahulsom.grooves.asciidoctor.Constants.EVENT_LINE_HEIGHT +import com.github.rahulsom.grooves.asciidoctor.Constants.EVENT_SPACE +import com.github.rahulsom.grooves.asciidoctor.Constants.OFFSET import com.github.rahulsom.svg.Circle import com.github.rahulsom.svg.G import com.github.rahulsom.svg.ObjectFactory @@ -19,7 +19,6 @@ import kotlin.math.sqrt * @author Rahul Somasunderam */ class Event(private val counter: Int, var id: String, var date: Date, var description: String, var type: EventType) { - override fun toString(): String { val sdf = SimpleDateFormat("yyyy-MM-dd") return " - $id ${sdf.format(date)} $description ($type)" @@ -29,7 +28,10 @@ class Event(private val counter: Int, var id: String, var date: Date, var descri var x: Int = 0 var y: Int = 0 - fun buildSvg(index: Int, svgBuilder: SvgBuilder): G { + fun buildSvg( + index: Int, + svgBuilder: SvgBuilder, + ): G { if (description == ".") { return G() } @@ -37,11 +39,12 @@ class Event(private val counter: Int, var id: String, var date: Date, var descri val xOffset = svgBuilder.dates[date]!! // builder.mkp.comment(toString()) val revertedClass = if (this.reverted) "reverted" else "" - val g = G().withId("event_$counter") - .withClazz("event ${this.type.name} $revertedClass") + val g = + G().withId("event_$counter") + .withClazz("event ${this.type.name} $revertedClass") - var x = (10 + aggregateWidth * 2 + xOffset * eventSpace).toInt() - var y = index * eventLineHeight + offset + aggregateHeight / 2 + var x = (10 + AGGREGATE_WIDTH * 2 + xOffset * EVENT_SPACE).toInt() + var y = index * EVENT_LINE_HEIGHT + OFFSET + AGGREGATE_HEIGHT / 2 while (svgBuilder.allEvents.find { it.x == x && it.y == y } != null) { y -= (20 * sqrt(3.0) / 2).toInt() @@ -58,8 +61,8 @@ class Event(private val counter: Int, var id: String, var date: Date, var descri val y1 = y - ((this.x - reverted.x) / 3) g.withSVGDescriptionClassOrSVGAnimationClassOrSVGStructureClass( ObjectFactory().createPath( - ObjectFactory().createPath().withD("M$x $y Q $x1 $y1, ${reverted.x + 15} ${reverted.y - 15}") - ) + ObjectFactory().createPath().withD("M$x $y Q $x1 $y1, ${reverted.x + 15} ${reverted.y - 15}"), + ), ) } @@ -68,7 +71,7 @@ class Event(private val counter: Int, var id: String, var date: Date, var descri val other = svgBuilder.allEvents.find { it.id == otherId }!! if (other.x > 0 && other.y > 0) { - val x1 = (if (type == EventType.Disjoin) -30 else 30) * abs(other.y - y) / eventLineHeight + val x1 = (if (type == EventType.Disjoin) -30 else 30) * abs(other.y - y) / EVENT_LINE_HEIGHT val xContactOffset = if (type == EventType.Disjoin) -10 else 10 val y1 = (y + other.y) / 2 @@ -80,9 +83,9 @@ class Event(private val counter: Int, var id: String, var date: Date, var descri g.withSVGDescriptionClassOrSVGAnimationClassOrSVGStructureClass( ObjectFactory().createPath( ObjectFactory().createPath().withD( - "M${this.x} $y Q ${x1 + this.x} $y1, ${other.x + xContactOffset} ${other.y + yOffset}" - ) - ) + "M${this.x} $y Q ${x1 + this.x} $y1, ${other.x + xContactOffset} ${other.y + yOffset}", + ), + ), ) } } @@ -92,8 +95,8 @@ class Event(private val counter: Int, var id: String, var date: Date, var descri ObjectFactory().createCircle( Circle().withCx("${this.x}").withCy("$y").withR("14") .withStrokeDasharray("2, 5") - .withClazz("eventCreated ${this.type.name}") - ) + .withClazz("eventCreated ${this.type.name}"), + ), ) } @@ -101,14 +104,14 @@ class Event(private val counter: Int, var id: String, var date: Date, var descri ObjectFactory().createCircle( ObjectFactory().createCircle().withCx("${this.x}").withCy("${this.y}") .withR("10") - .withClazz("event ${this.type.name} $revertedClass") - ) + .withClazz("event ${this.type.name} $revertedClass"), + ), ) g.withSVGDescriptionClassOrSVGAnimationClassOrSVGStructureClass( ObjectFactory().createText( ObjectFactory().createText().withX("${this.x}").withY("${this.y}") - .withClazz("eventId").withContent(this.id) - ) + .withClazz("eventId").withContent(this.id), + ), ) return g } diff --git a/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/EventType.kt b/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/EventType.kt index 009e0c4e0..cf67fa903 100644 --- a/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/EventType.kt +++ b/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/EventType.kt @@ -6,5 +6,10 @@ package com.github.rahulsom.grooves.asciidoctor * @author Rahul Somasunderam */ enum class EventType { - Normal, Revert, Deprecates, DeprecatedBy, Join, Disjoin + Normal, + Revert, + Deprecates, + DeprecatedBy, + Join, + Disjoin, } \ No newline at end of file diff --git a/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/EventsBlock.kt b/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/EventsBlock.kt index 75273a73c..0d4967533 100644 --- a/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/EventsBlock.kt +++ b/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/EventsBlock.kt @@ -14,8 +14,11 @@ import java.security.MessageDigest */ class EventsBlock(name: String) : BlockProcessor(name, mapOf("contexts" to listOf(":literal"), "content_model" to ":simple")) { - - override fun process(parent: StructuralNode, reader: Reader, attributes: MutableMap?): Any { + override fun process( + parent: StructuralNode, + reader: Reader, + attributes: MutableMap?, + ): Any { val projectDirAttr = parent.document.attributes["gradle-projectdir"] as String val outDir = File(projectDirAttr, "build/docs/asciidoc") @@ -26,11 +29,12 @@ class EventsBlock(name: String) : SvgBuilder(input).write(File(outDir, filename)) - val newAttributes = mapOf( - "type" to ":image", - "target" to filename, - "format" to "svg" - ) + val newAttributes = + mapOf( + "type" to ":image", + "target" to filename, + "format" to "svg", + ) return createBlock(parent, "image", input, newAttributes, attributes?.mapKeys { it }) } diff --git a/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/SvgBuilder.kt b/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/SvgBuilder.kt index 0d0f61b59..58bd22b90 100644 --- a/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/SvgBuilder.kt +++ b/grooves-diagrams/src/main/kotlin/com/github/rahulsom/grooves/asciidoctor/SvgBuilder.kt @@ -1,9 +1,9 @@ package com.github.rahulsom.grooves.asciidoctor +import com.github.rahulsom.grooves.asciidoctor.Constants.AGGREGATE_WIDTH import com.github.rahulsom.grooves.asciidoctor.Constants.CSS -import com.github.rahulsom.grooves.asciidoctor.Constants.aggregateWidth -import com.github.rahulsom.grooves.asciidoctor.Constants.eventLineHeight -import com.github.rahulsom.grooves.asciidoctor.Constants.eventSpace +import com.github.rahulsom.grooves.asciidoctor.Constants.EVENT_LINE_HEIGHT +import com.github.rahulsom.grooves.asciidoctor.Constants.EVENT_SPACE import com.github.rahulsom.svg.ObjectFactory import com.github.rahulsom.svg.Path import com.github.rahulsom.svg.Rect @@ -96,20 +96,21 @@ class SvgBuilder(private val input: String) { fun write(file: File) { init() - val svg = Svg().withHeight("${aggregates.size * eventLineHeight}") - .withWidth("${dates.values.maxOrNull()!! * eventSpace + 4 * aggregateWidth}") + val svg = + Svg().withHeight("${aggregates.size * EVENT_LINE_HEIGHT}") + .withWidth("${dates.values.maxOrNull()!! * EVENT_SPACE + 4 * AGGREGATE_WIDTH}") svg.withSVGDescriptionClassOrSVGAnimationClassOrSVGStructureClass( ObjectFactory().createStyle( - SVGStyleClass().withContent("/* */") - ) + SVGStyleClass().withContent("/* */"), + ), ) svg.withSVGDescriptionClassOrSVGAnimationClassOrSVGStructureClass( ObjectFactory().createRect( - Rect().withX("0").withY("0").withHeight("${aggregates.size * eventLineHeight}").withWidth( - "${dates.values.maxOrNull()!! * eventSpace + 4 * aggregateWidth}" - ).withClazz("background") + Rect().withX("0").withY("0").withHeight("${aggregates.size * EVENT_LINE_HEIGHT}").withWidth( + "${dates.values.maxOrNull()!! * EVENT_SPACE + 4 * AGGREGATE_WIDTH}", + ).withClazz("background"), ), ObjectFactory().createDefs( ObjectFactory().createDefs().withSVGDescriptionClassOrSVGAnimationClassOrSVGStructureClass( @@ -119,24 +120,24 @@ class SvgBuilder(private val input: String) { .withMarkerWidth("10").withMarkerHeight("10") .withOrient("auto").withMarkerUnits("userSpaceOnUse") .withSVGDescriptionClassOrSVGAnimationClassOrSVGStructureClass( - ObjectFactory().createPath(Path().withD("M 0 0 L 10 5 L 0 10 z")) - ) - ) - ) - ) + ObjectFactory().createPath(Path().withD("M 0 0 L 10 5 L 0 10 z")), + ), + ), + ), + ), ) aggregates.forEach { aggregate -> svg.withSVGDescriptionClassOrSVGAnimationClassOrSVGStructureClass( ObjectFactory().createG( aggregate.buildSvg( - dates - ) - ) + dates, + ), + ), ) aggregate.events.forEach { event -> svg.withSVGDescriptionClassOrSVGAnimationClassOrSVGStructureClass( - ObjectFactory().createG(event.buildSvg(aggregate.index, this)) + ObjectFactory().createG(event.buildSvg(aggregate.index, this)), ) } } diff --git a/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/Application.kt b/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/Application.kt index 0dd67a57f..daf5e3bfd 100644 --- a/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/Application.kt +++ b/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/Application.kt @@ -10,62 +10,70 @@ import org.slf4j.LoggerFactory.getLogger import java.util.Date import java.util.UUID -class Application @Inject constructor( - private val eventBus: EventBus, - private val eventService: EventService, - private val database: Database, - private val dslContext: DSLContext -) : AbstractService() { +class Application + @Inject + constructor( + private val eventBus: EventBus, + private val eventService: EventService, + private val database: Database, + private val dslContext: DSLContext, + ) : AbstractService() { + public override fun doStop() { + dslContext.dropTable(BALANCE) + eventBus.unregister(eventService) + log.error("======== Shutting down ========") + } - public override fun doStop() { - dslContext.dropTable(BALANCE) - eventBus.unregister(eventService) - log.error("======== Shutting down ========") - } + public override fun doStart() { + log.error("") + log.error("") + log.error("") + log.error("========= Starting up =========") + dslContext.createSchemaIfNotExists(Public.PUBLIC).execute() + dslContext.createTableIfNotExists(BALANCE) + .column(BALANCE.B_ID) + .column(BALANCE.B_VERSION) + .column(BALANCE.B_TIME) + .column(BALANCE.B_ACCOUNT) + .column(BALANCE.BALANCE_) + .execute() + eventBus.register(eventService) + log.error("doStart complete") + } - public override fun doStart() { - log.error("") - log.error("") - log.error("") - log.error("========= Starting up =========") - dslContext.createSchemaIfNotExists(Public.PUBLIC).execute() - dslContext.createTableIfNotExists(BALANCE) - .column(BALANCE.B_ID) - .column(BALANCE.B_VERSION) - .column(BALANCE.B_TIME) - .column(BALANCE.B_ACCOUNT) - .column(BALANCE.BALANCE_) - .execute() - eventBus.register(eventService) - log.error("doStart complete") - } + private val log = getLogger(this.javaClass) - private val log = getLogger(this.javaClass) - - fun deposit(accountId: String, position: Long, atmId: String, amount: Long) = - eventBus.post( + fun deposit( + accountId: String, + position: Long, + atmId: String, + amount: Long, + ) = eventBus.post( Transaction.Deposit( UUID.randomUUID().toString(), Account(accountId), Date(), position, atmId, - amount - ) + amount, + ), ) - fun withdraw(accountId: String, position: Long, atmId: String, amount: Long) = - eventBus.post( + fun withdraw( + accountId: String, + position: Long, + atmId: String, + amount: Long, + ) = eventBus.post( Transaction.Withdraw( UUID.randomUUID().toString(), Account(accountId), Date(), position, atmId, - amount - ) + amount, + ), ) - fun getBalance(accountId: String) = - database.getBalance(Account(accountId), null)?.balance -} \ No newline at end of file + fun getBalance(accountId: String) = database.getBalance(Account(accountId), null)?.balance + } \ No newline at end of file diff --git a/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/Balance.kt b/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/Balance.kt index aa0495bc2..2adeaf0e9 100644 --- a/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/Balance.kt +++ b/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/Balance.kt @@ -7,7 +7,8 @@ import org.reactivestreams.Publisher import java.text.SimpleDateFormat import java.time.OffsetDateTime import java.time.ZoneId -import java.util.* +import java.util.Date +import java.util.UUID class Balance() : Snapshot { override var id: String? = UUID.randomUUID().toString() @@ -24,7 +25,7 @@ class Balance() : Snapshot { aggregate: Account?, balance: Long, lastEventPosition: Long, - lastEventTimestamp: Date + lastEventTimestamp: Date, ) : this() { this.id = id this.aggregate = aggregate @@ -39,7 +40,7 @@ class Balance() : Snapshot { Account(balance.bAccount), balance.balance, balance.bVersion, - Date.from(balance.bTime.toInstant()) + Date.from(balance.bTime.toInstant()), ) fun toBalanceRecord(): BalanceRecord { @@ -48,18 +49,15 @@ class Balance() : Snapshot { lastEventPosition, OffsetDateTime.ofInstant(lastEventTimestamp?.toInstant(), ZoneId.systemDefault()), aggregate?.id, - balance + balance, ) } - override fun getAggregateObservable(): Publisher = - Flowable.fromIterable(listOfNotNull(aggregate)) + override fun getAggregateObservable(): Publisher = Flowable.fromIterable(listOfNotNull(aggregate)) - override fun getDeprecatesObservable() = - Flowable.fromIterable(deprecates) + override fun getDeprecatesObservable() = Flowable.fromIterable(deprecates) - override fun getDeprecatedByObservable(): Publisher = - Flowable.fromIterable(listOfNotNull(deprecatedBy)) + override fun getDeprecatedByObservable(): Publisher = Flowable.fromIterable(listOfNotNull(deprecatedBy)) override fun setAggregate(aggregate: Account) { this.aggregate = aggregate @@ -72,9 +70,10 @@ class Balance() : Snapshot { override fun toString(): String { val idPart = id?.substring(24) val aggPart = aggregate?.id - val ts = lastEventTimestamp.let { - SimpleDateFormat("HH:mm:ss,SSS").format(it) - } + val ts = + lastEventTimestamp.let { + SimpleDateFormat("HH:mm:ss,SSS").format(it) + } return "Balance(id=$idPart, aggregate=$aggPart, lastEventTimestamp=$ts, " + "version=$lastEventPosition, balance=$balance)" } diff --git a/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/BankingModule.kt b/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/BankingModule.kt index 5b3a798fa..142ac896c 100644 --- a/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/BankingModule.kt +++ b/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/BankingModule.kt @@ -8,7 +8,6 @@ import org.jooq.impl.DSL import java.sql.DriverManager.getConnection object BankingModule : AbstractModule() { - override fun configure() { bind(Application::class.java) bind(EventBus::class.java) @@ -17,6 +16,5 @@ object BankingModule : AbstractModule() { } @Provides - fun dslContext() = - DSL.using(getConnection("jdbc:h2:mem:app", "sa", ""), H2) + fun dslContext() = DSL.using(getConnection("jdbc:h2:mem:app", "sa", ""), H2) } \ No newline at end of file diff --git a/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/ContextAwareScheduler.kt b/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/ContextAwareScheduler.kt index a875f9e9c..71f3c17c8 100644 --- a/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/ContextAwareScheduler.kt +++ b/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/ContextAwareScheduler.kt @@ -16,16 +16,18 @@ import java.util.concurrent.TimeUnit * that works for RxJava even though RxJava manages threads differently. */ object ContextAwareScheduler : Scheduler() { - private val worker = NewThreadWorker(RxThreadFactory("ContextAwareScheduler")) override fun createWorker(): Worker = ContextAwareWorker(worker) internal class ContextAwareWorker(private val worker: NewThreadWorker) : Worker() { - private val tracking = CompositeDisposable() - override fun schedule(runnable: Runnable, delay: Long, unit: TimeUnit): Disposable { + override fun schedule( + runnable: Runnable, + delay: Long, + unit: TimeUnit, + ): Disposable { if (isDisposed) { return Disposables.disposed() } diff --git a/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/ContextManager.kt b/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/ContextManager.kt index edba7832c..2dc528d75 100644 --- a/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/ContextManager.kt +++ b/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/ContextManager.kt @@ -7,9 +7,9 @@ package grooves.example.push * */ object ContextManager { - private val ctx = ThreadLocal>() fun get() = ctx.get() + fun set(context: Map) = ctx.set(context) } \ No newline at end of file diff --git a/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/Database.kt b/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/Database.kt index 6cebc5cac..1bea00e23 100644 --- a/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/Database.kt +++ b/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/Database.kt @@ -7,22 +7,25 @@ import org.jooq.DSLContext import org.slf4j.LoggerFactory class Database { - private val log = LoggerFactory.getLogger(this.javaClass) @Inject lateinit var dslContext: DSLContext - fun getBalance(account: Account, version: Long?): BalanceRecord? { + fun getBalance( + account: Account, + version: Long?, + ): BalanceRecord? { log.info("getBalance($account, $version)") - val balanceRecord = dslContext - .select() - .from(Tables.BALANCE) - .where(Tables.BALANCE.B_ACCOUNT.eq(account.id)) - .and(Tables.BALANCE.B_VERSION.le(version ?: Long.MAX_VALUE)) - .orderBy(Tables.BALANCE.B_VERSION.desc()) - .limit(1) - .fetchAny() as BalanceRecord? + val balanceRecord = + dslContext + .select() + .from(Tables.BALANCE) + .where(Tables.BALANCE.B_ACCOUNT.eq(account.id)) + .and(Tables.BALANCE.B_VERSION.le(version ?: Long.MAX_VALUE)) + .orderBy(Tables.BALANCE.B_VERSION.desc()) + .limit(1) + .fetchAny() as BalanceRecord? log.info("<-- \n$balanceRecord") return balanceRecord } diff --git a/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/EventService.kt b/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/EventService.kt index d9a7f7b6b..b5d5f86e9 100644 --- a/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/EventService.kt +++ b/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/EventService.kt @@ -12,7 +12,6 @@ import org.jooq.DSLContext import org.slf4j.LoggerFactory class EventService { - @Inject lateinit var database: Database @@ -45,7 +44,8 @@ class EventService { } } .withApplyEvents { balance -> true } // <5> - .withDeprecator { balance, deprecatingAccount -> /* No op */ } // <6> + .withDeprecator { balance, deprecatingAccount -> // <6> + } .withExceptionHandler { exception, balance, transaction -> // <7> log.warn("$exception occurred") @@ -54,17 +54,19 @@ class EventService { .withEventHandler(this::updateBalance) // <8> .build() // <9> - private fun updateBalance(transaction: Transaction, balance: Balance) = - when (transaction) { - is Transaction.Deposit -> { - balance.balance += transaction.amount - just(CONTINUE) - } - is Transaction.Withdraw -> { - balance.balance -= transaction.amount - just(CONTINUE) - } + private fun updateBalance( + transaction: Transaction, + balance: Balance, + ) = when (transaction) { + is Transaction.Deposit -> { + balance.balance += transaction.amount + just(CONTINUE) } + is Transaction.Withdraw -> { + balance.balance -= transaction.amount + just(CONTINUE) + } + } // end::documented[] @Suppress("unused") diff --git a/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/Transaction.kt b/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/Transaction.kt index 6959a6445..23726551f 100644 --- a/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/Transaction.kt +++ b/grooves-example-pushstyle/src/main/kotlin/grooves/example/push/Transaction.kt @@ -11,11 +11,9 @@ sealed class Transaction( override var aggregate: Account?, override var timestamp: Date, override var position: Long, - override var revertedBy: RevertEvent? = null + override var revertedBy: RevertEvent? = null, ) : BaseEvent { - - override fun getAggregateObservable(): Publisher = - Flowable.fromIterable(listOfNotNull(aggregate)) + override fun getAggregateObservable(): Publisher = Flowable.fromIterable(listOfNotNull(aggregate)) data class Deposit( override val id: String, @@ -23,7 +21,7 @@ sealed class Transaction( override var timestamp: Date, override var position: Long, val atmId: String, - val amount: Long + val amount: Long, ) : Transaction(id, aggregate, timestamp, position) data class Withdraw( @@ -32,6 +30,6 @@ sealed class Transaction( override var timestamp: Date, override var position: Long, val atmId: String, - val amount: Long + val amount: Long, ) : Transaction(id, aggregate, timestamp, position) } \ No newline at end of file diff --git a/grooves-example-pushstyle/src/test/kotlin/grooves/example/pushstyle/PushTest.kt b/grooves-example-pushstyle/src/test/kotlin/grooves/example/pushstyle/PushTest.kt index 8397f0db3..6a9e662f5 100644 --- a/grooves-example-pushstyle/src/test/kotlin/grooves/example/pushstyle/PushTest.kt +++ b/grooves-example-pushstyle/src/test/kotlin/grooves/example/pushstyle/PushTest.kt @@ -11,7 +11,6 @@ import org.junit.jupiter.api.Test import java.util.concurrent.TimeUnit.SECONDS class PushTest { - private val injector = Guice.createInjector(BankingModule) private val application = injector.getInstance(Application::class.java) diff --git a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/BootStrap.kt b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/BootStrap.kt index fb43aeb52..a8ab8bfa5 100644 --- a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/BootStrap.kt +++ b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/BootStrap.kt @@ -30,9 +30,8 @@ class BootStrap constructor( @Autowired val patientAccountQuery: PatientAccountQuery, @Autowired val patientHealthQuery: PatientHealthQuery, @Autowired val patientAccountRepository: PatientAccountRepository, - @Autowired val patientHealthRepository: PatientHealthRepository + @Autowired val patientHealthRepository: PatientHealthRepository, ) { - @PostConstruct fun init() { setupJohnLennon() @@ -162,12 +161,19 @@ class BootStrap constructor( } @Suppress("UNUSED_PARAMETER") - private fun , - QueryT : QuerySupport> snapshotWith( - it: OnSpec>, + private fun < + SnapshotT : Snapshot, + QueryT : QuerySupport, + > snapshotWith( + it: OnSpec< + Patient, + String, + PatientEvent, + String, + out Snapshot, + >, query: QueryT, - repository: ReactiveCrudRepository + repository: ReactiveCrudRepository, ) = null // query.computeSnapshot(it.aggregate, Long.MAX_VALUE) // .flatMap { repository.save(it).toObservable() } @@ -180,22 +186,27 @@ class BootStrap constructor( * @param into The aggregate to survive * @return */ - private fun merge(self: Patient, into: Patient): PatientEvent.PatientDeprecatedBy { - val e2 = patientEventRepository.save( - PatientEvent.PatientDeprecates(self).also { - it.aggregate = into - it.timestamp = currDate.time - it.position = countEvents(into) - } - ) + private fun merge( + self: Patient, + into: Patient, + ): PatientEvent.PatientDeprecatedBy { + val e2 = + patientEventRepository.save( + PatientEvent.PatientDeprecates(self).also { + it.aggregate = into + it.timestamp = currDate.time + it.position = countEvents(into) + }, + ) - val e1 = patientEventRepository.save( - PatientEvent.PatientDeprecatedBy(into, e2.id!!).also { - it.aggregate = self - it.timestamp = currDate.time - it.position = countEvents(self) - } - ) + val e1 = + patientEventRepository.save( + PatientEvent.PatientDeprecatedBy(into, e2.id!!).also { + it.aggregate = self + it.timestamp = currDate.time + it.position = countEvents(self) + }, + ) e2.converseId = e1.id @@ -204,17 +215,19 @@ class BootStrap constructor( return e1 } - val currDate = Calendar.getInstance(TimeZone.getTimeZone("UTC")) - .also { - it.time = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX") - .parse("2016-01-01T00:00:00.000Z") - } + val currDate = + Calendar.getInstance(TimeZone.getTimeZone("UTC")) + .also { + it.time = + SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX") + .parse("2016-01-01T00:00:00.000Z") + } fun on( patient: Patient, closure: ( - OnSpec> - ) -> Unit + OnSpec>, + ) -> Unit, ): Patient { val eventSaver: (Any) -> Unit = { when (it) { @@ -232,11 +245,12 @@ class BootStrap constructor( eventSaver, positionSupplier, timestampSupplier, - closure + closure, ) } - private fun countEvents(patient: Patient) = patientEventRepository - .findAllByAggregateIdIn(listOf(patient.id!!)) - .count() + 1L + private fun countEvents(patient: Patient) = + patientEventRepository + .findAllByAggregateIdIn(listOf(patient.id!!)) + .count() + 1L } \ No newline at end of file diff --git a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/controllers/PatientController.kt b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/controllers/PatientController.kt index 7f8038d9f..00e679c85 100644 --- a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/controllers/PatientController.kt +++ b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/controllers/PatientController.kt @@ -20,24 +20,23 @@ class PatientController constructor( @Autowired val patientRepository: PatientRepository, @Autowired val patientAccountQuery: PatientAccountQuery, @Autowired val patientHealthQuery: PatientHealthQuery, - @Autowired val patientEventRepository: PatientEventRepository + @Autowired val patientEventRepository: PatientEventRepository, ) { - @GetMapping("/patient") - fun list() = - patientRepository.findAllByOrderByUniqueIdAsc() + fun list() = patientRepository.findAllByOrderByUniqueIdAsc() @GetMapping("/patientEvent") - fun events() = - patientEventRepository.findAll() + fun events() = patientEventRepository.findAll() @GetMapping("/patient/show/{id}") - fun show(@PathVariable id: String) = - patientRepository.findById(id) + fun show( + @PathVariable id: String, + ) = patientRepository.findById(id) @GetMapping("/patient/event/{id}") - fun patientEvents(@PathVariable id: String) = - patientEventRepository.findAllByAggregateIdIn(listOf(id)) + fun patientEvents( + @PathVariable id: String, + ) = patientEventRepository.findAllByAggregateIdIn(listOf(id)) @GetMapping("/patient/account/{id}") fun account( @@ -45,20 +44,19 @@ class PatientController constructor( @RequestParam(required = false) version: Long?, @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX") @RequestParam(required = false) - date: Instant? - ) = - patientRepository.findById(id) - .flatMap { patient -> - Mono.from( - version?.let { patientAccountQuery.computeSnapshot(patient, it) } - ?: date?.let { - patientAccountQuery.computeSnapshot( - patient, - extractDate(it) - ) - } ?: patientAccountQuery.computeSnapshot(patient, Long.MAX_VALUE) - ) - } + date: Instant?, + ) = patientRepository.findById(id) + .flatMap { patient -> + Mono.from( + version?.let { patientAccountQuery.computeSnapshot(patient, it) } + ?: date?.let { + patientAccountQuery.computeSnapshot( + patient, + extractDate(it), + ) + } ?: patientAccountQuery.computeSnapshot(patient, Long.MAX_VALUE), + ) + } private fun extractDate(instant: Instant) = Calendar.getInstance().let { @@ -78,18 +76,17 @@ class PatientController constructor( @RequestParam(required = false) version: Long?, @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX") @RequestParam(required = false) - date: Instant? - ) = - patientRepository.findById(id) - .flatMap { patient -> - Mono.from( - version?.let { patientHealthQuery.computeSnapshot(patient, version) } - ?: date?.let { - patientHealthQuery.computeSnapshot( - patient, - extractDate(it) - ) - } ?: patientHealthQuery.computeSnapshot(patient, Long.MAX_VALUE) - ) - } + date: Instant?, + ) = patientRepository.findById(id) + .flatMap { patient -> + Mono.from( + version?.let { patientHealthQuery.computeSnapshot(patient, version) } + ?: date?.let { + patientHealthQuery.computeSnapshot( + patient, + extractDate(it), + ) + } ?: patientHealthQuery.computeSnapshot(patient, Long.MAX_VALUE), + ) + } } \ No newline at end of file diff --git a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/domain/Patient.kt b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/domain/Patient.kt index 38fe5fb0f..1f1d86790 100644 --- a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/domain/Patient.kt +++ b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/domain/Patient.kt @@ -4,6 +4,7 @@ package grooves.boot.kotlin.domain class Patient(var uniqueId: String? = null) { // <1> var id: String? = null + override fun toString() = "Patient(uniqueId=$uniqueId, id=$id)" } // end::documented[] \ No newline at end of file diff --git a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/domain/PatientAccount.kt b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/domain/PatientAccount.kt index 6d98952f1..c9e40eedd 100644 --- a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/domain/PatientAccount.kt +++ b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/domain/PatientAccount.kt @@ -32,7 +32,8 @@ class PatientAccount : Snapshot { // <1> fun getDeprecatedBy() = deprecator @JsonIgnore - override fun getAggregateObservable() = // <4> + override fun getAggregateObservable() = + // <4> aggregateId?.let { patientRepository!!.findAllById(just(it)) } ?: empty() override fun setAggregate(aggregate: Patient) { @@ -44,7 +45,8 @@ class PatientAccount : Snapshot { // <1> var patientRepository: PatientRepository? = null @JsonIgnore - override fun getDeprecatedByObservable() = // <5> + override fun getDeprecatedByObservable() = + // <5> deprecator?.let { just(it) } ?: Mono.empty() override fun setDeprecatedBy(deprecatingAggregate: Patient) { @@ -52,7 +54,8 @@ class PatientAccount : Snapshot { // <1> } @JsonIgnore - override fun getDeprecatesObservable() = // <6> + override fun getDeprecatesObservable() = + // <6> if (deprecatesIds.size > 0) { patientRepository!!.findAllById(deprecatesIds) } else { diff --git a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/domain/PatientEvent.kt b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/domain/PatientEvent.kt index d39f4e68b..6161d4c1a 100644 --- a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/domain/PatientEvent.kt +++ b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/domain/PatientEvent.kt @@ -37,7 +37,8 @@ sealed class PatientEvent : BaseEvent { // <1><2> fun getType(): String = this.javaClass.simpleName @JsonIgnore - override fun getAggregateObservable(): Publisher = // <6> + override fun getAggregateObservable(): Publisher = + // <6> aggregateId?.let { BeansHolder.context?.getBean(PatientRepository::class.java)?.findById(it) } ?: empty() @@ -83,13 +84,13 @@ sealed class PatientEvent : BaseEvent { // <1><2> override fun getDeprecatedObservable(): Publisher = just(deprecated) fun getAudit(): String = "$id - Deprecates $deprecated" + override fun toString() = "[${getTs()}] #$position: ${getAudit()}" } data class PatientDeprecatedBy(val deprecator: Patient, val converseId: String) : PatientEvent(), DeprecatedBy { - @JsonIgnore override fun getConverseObservable(): Publisher { val patientEventRepository = @@ -103,6 +104,7 @@ sealed class PatientEvent : BaseEvent { // <1><2> override fun getDeprecatorObservable(): Publisher = just(deprecator) fun getAudit(): String = "$id - Deprecated by $deprecator" + override fun toString() = "[${getTs()}] #$position: ${getAudit()}" } @@ -119,11 +121,13 @@ sealed class PatientEvent : BaseEvent { // <1><2> data class ProcedurePerformed(val code: String, val cost: BigDecimal) : Applicable() { fun getAudit(): String = "$id - Performed '$code' for $cost" + override fun toString() = "[${getTs()}] #$position: ${getAudit()}" } data class PaymentMade(val amount: BigDecimal) : Applicable() { fun getAudit(): String = "$id - Paid $amount" + override fun toString() = "[${getTs()}] #$position: ${getAudit()}" } // tag::created[] diff --git a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/domain/PatientHealth.kt b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/domain/PatientHealth.kt index 97d15289b..0864875cb 100644 --- a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/domain/PatientHealth.kt +++ b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/domain/PatientHealth.kt @@ -13,7 +13,6 @@ import java.util.Date @Configurable class PatientHealth : Snapshot { - override var id: String? = null override var lastEventPosition: Long = 0 @@ -29,8 +28,7 @@ class PatientHealth : Snapshot { fun getDeprecatedBy() = deprecator @JsonIgnore - override fun getAggregateObservable() = - aggregateId?.let { patientRepository.findAllById(just(it)) } ?: Flux.empty() + override fun getAggregateObservable() = aggregateId?.let { patientRepository.findAllById(just(it)) } ?: Flux.empty() override fun setAggregate(aggregate: Patient) { this.aggregateId = aggregate.id @@ -41,23 +39,22 @@ class PatientHealth : Snapshot { lateinit var patientRepository: PatientRepository @JsonIgnore - override fun getDeprecatedByObservable() = - deprecator?.let { just(it) } ?: Mono.empty() + override fun getDeprecatedByObservable() = deprecator?.let { just(it) } ?: Mono.empty() override fun setDeprecatedBy(deprecatingAggregate: Patient) { deprecator = deprecatingAggregate } @JsonIgnore - override fun getDeprecatesObservable() = - patientRepository.findAllById(deprecatesIds) + override fun getDeprecatesObservable() = patientRepository.findAllById(deprecatesIds) - override fun toString() = "PatientAccount(id=$id, aggregate=$aggregateId, " + - "lastEventPosition=$lastEventPosition, lastEventTimestamp=$lastEventTimestamp)" + override fun toString() = + "PatientAccount(id=$id, aggregate=$aggregateId, " + + "lastEventPosition=$lastEventPosition, lastEventTimestamp=$lastEventTimestamp)" } class Procedure( var code: String? = null, @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ") - var date: Date? = null + var date: Date? = null, ) \ No newline at end of file diff --git a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/queries/PatientAccountQuery.kt b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/queries/PatientAccountQuery.kt index fc8bb4151..b1dbf5e09 100644 --- a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/queries/PatientAccountQuery.kt +++ b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/queries/PatientAccountQuery.kt @@ -19,68 +19,97 @@ import java.util.Date @Component class PatientAccountQuery constructor( @Autowired val patientEventRepository: PatientEventRepository, - @Autowired val patientAccountRepository: PatientAccountRepository + @Autowired val patientAccountRepository: PatientAccountRepository, ) : QuerySupport, - // <1> - SimpleQuery { // <2> + // <1> + SimpleQuery< + Patient, + String, + PatientEvent, + PatientEvent.Applicable, + String, + PatientAccount, + > { // <2> - override fun getExecutor() = SimpleExecutor() // <3> + override fun getExecutor() = + SimpleExecutor< + Patient, + String, + PatientEvent, + PatientEvent.Applicable, + String, + PatientAccount, + PatientAccountQuery, + >() // <3> - override fun createEmptySnapshot() = PatientAccount() // <4> + override fun createEmptySnapshot() = PatientAccount() // <4> - override fun getSnapshot(maxPosition: Long, aggregate: Patient) = // <5> - patientAccountRepository.findByAggregateIdAndLastEventPositionLessThan( - aggregate.id!!, - maxPosition - ) + override fun getSnapshot( + maxPosition: Long, + aggregate: Patient, + ) = // <5> + patientAccountRepository.findByAggregateIdAndLastEventPositionLessThan( + aggregate.id!!, + maxPosition, + ) - override fun getSnapshot(maxTimestamp: Date?, aggregate: Patient) = // <6> - patientAccountRepository.findByAggregateIdAndLastEventTimestampLessThan( - aggregate.id!!, - maxTimestamp!! - ) + override fun getSnapshot( + maxTimestamp: Date?, + aggregate: Patient, + ) = // <6> + patientAccountRepository.findByAggregateIdAndLastEventTimestampLessThan( + aggregate.id!!, + maxTimestamp!!, + ) - override fun shouldEventsBeApplied(snapshot: PatientAccount) = true // <7> + override fun shouldEventsBeApplied(snapshot: PatientAccount) = true // <7> - override fun addToDeprecates(snapshot: PatientAccount, deprecatedAggregate: Patient) { - snapshot.deprecatesIds.add(deprecatedAggregate.id!!) - } + override fun addToDeprecates( + snapshot: PatientAccount, + deprecatedAggregate: Patient, + ) { + snapshot.deprecatesIds.add(deprecatedAggregate.id!!) + } - override fun onException(e: Exception, snapshot: PatientAccount, event: PatientEvent) = // <8> - just(CONTINUE) + override fun onException( + e: Exception, + snapshot: PatientAccount, + event: PatientEvent, + ) = // <8> + just(CONTINUE) - override fun getUncomputedEvents( - aggregate: Patient, - lastSnapshot: PatientAccount?, - version: Long - ) = // <9> - patientEventRepository.findAllByPositionRange( - aggregate.id!!, - lastSnapshot?.lastEventPosition ?: 0, - version - ) + override fun getUncomputedEvents( + aggregate: Patient, + lastSnapshot: PatientAccount?, + version: Long, + ) = // <9> + patientEventRepository.findAllByPositionRange( + aggregate.id!!, + lastSnapshot?.lastEventPosition ?: 0, + version, + ) - override fun getUncomputedEvents( - aggregate: Patient, - lastSnapshot: PatientAccount?, - snapshotTime: Date - ) = // <10> - lastSnapshot?.lastEventTimestamp?.let { - patientEventRepository.findAllByTimestampRange( + override fun getUncomputedEvents( + aggregate: Patient, + lastSnapshot: PatientAccount?, + snapshotTime: Date, + ) = // <10> + lastSnapshot?.lastEventTimestamp?.let { + patientEventRepository.findAllByTimestampRange( + aggregate.id!!, + it, + snapshotTime, + ) + } ?: patientEventRepository.findAllByAggregateIdAndTimestampLessThan( aggregate.id!!, - it, - snapshotTime + snapshotTime, ) - } ?: patientEventRepository.findAllByAggregateIdAndTimestampLessThan( - aggregate.id!!, - snapshotTime - ) - override fun applyEvent(event: PatientEvent.Applicable, snapshot: PatientAccount) = - when (event) { // <11> + override fun applyEvent( + event: PatientEvent.Applicable, + snapshot: PatientAccount, + ) = when (event) { // <11> is PatientEvent.Applicable.Created -> { if (event.aggregateId == snapshot.aggregateId) { snapshot.name = event.name @@ -97,5 +126,5 @@ class PatientAccountQuery constructor( just(CONTINUE) } } -} + } // end::documented[] \ No newline at end of file diff --git a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/queries/PatientHealthQuery.kt b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/queries/PatientHealthQuery.kt index f9d840df7..0148b7d8a 100644 --- a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/queries/PatientHealthQuery.kt +++ b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/queries/PatientHealthQuery.kt @@ -19,66 +19,83 @@ import java.util.Date @Component class PatientHealthQuery constructor( @Autowired val patientEventRepository: PatientEventRepository, - @Autowired val patientHealthRepository: PatientHealthRepository + @Autowired val patientHealthRepository: PatientHealthRepository, ) : QuerySupport, - SimpleQuery { + SimpleQuery { + override fun getExecutor() = + SimpleExecutor< + Patient, + String, + PatientEvent, + PatientEvent.Applicable, + String, + PatientHealth, + PatientHealthQuery, + >() - override fun getExecutor() = SimpleExecutor() + override fun createEmptySnapshot() = PatientHealth() - override fun createEmptySnapshot() = PatientHealth() - - override fun getSnapshot(maxPosition: Long, aggregate: Patient) = - patientHealthRepository.findByAggregateIdAndLastEventPositionLessThan( + override fun getSnapshot( + maxPosition: Long, + aggregate: Patient, + ) = patientHealthRepository.findByAggregateIdAndLastEventPositionLessThan( aggregate.id!!, - maxPosition + maxPosition, ) - override fun getSnapshot(maxTimestamp: Date?, aggregate: Patient) = - patientHealthRepository.findByAggregateIdAndLastEventTimestampLessThan( + override fun getSnapshot( + maxTimestamp: Date?, + aggregate: Patient, + ) = patientHealthRepository.findByAggregateIdAndLastEventTimestampLessThan( aggregate.id!!, - maxTimestamp!! + maxTimestamp!!, ) - override fun shouldEventsBeApplied(snapshot: PatientHealth) = true + override fun shouldEventsBeApplied(snapshot: PatientHealth) = true - override fun addToDeprecates(snapshot: PatientHealth, deprecatedAggregate: Patient) { - snapshot.deprecatesIds.add(deprecatedAggregate.id!!) - } + override fun addToDeprecates( + snapshot: PatientHealth, + deprecatedAggregate: Patient, + ) { + snapshot.deprecatesIds.add(deprecatedAggregate.id!!) + } - override fun onException(e: Exception, snapshot: PatientHealth, event: PatientEvent) = - just(CONTINUE) + override fun onException( + e: Exception, + snapshot: PatientHealth, + event: PatientEvent, + ) = just(CONTINUE) - override fun getUncomputedEvents( - aggregate: Patient, - lastSnapshot: PatientHealth?, - version: Long - ) = - patientEventRepository.findAllByPositionRange( + override fun getUncomputedEvents( + aggregate: Patient, + lastSnapshot: PatientHealth?, + version: Long, + ) = patientEventRepository.findAllByPositionRange( aggregate.id!!, lastSnapshot?.lastEventPosition ?: 0, - version + version, ) - override fun getUncomputedEvents( - aggregate: Patient, - lastSnapshot: PatientHealth?, - snapshotTime: Date - ) = - lastSnapshot?.lastEventTimestamp?.let { + override fun getUncomputedEvents( + aggregate: Patient, + lastSnapshot: PatientHealth?, + snapshotTime: Date, + ) = lastSnapshot?.lastEventTimestamp?.let { patientEventRepository.findAllByTimestampRange( aggregate.id!!, it, - snapshotTime + snapshotTime, ) } ?: patientEventRepository.findAllByAggregateIdAndTimestampLessThan( aggregate.id!!, - snapshotTime + snapshotTime, ) - override fun applyEvent(event: PatientEvent.Applicable, snapshot: PatientHealth) = - when (event) { + override fun applyEvent( + event: PatientEvent.Applicable, + snapshot: PatientHealth, + ) = when (event) { is PatientEvent.Applicable.Created -> { if (event.aggregateId == snapshot.aggregateId) { snapshot.name = event.name @@ -93,4 +110,4 @@ class PatientHealthQuery constructor( just(CONTINUE) } } -} \ No newline at end of file + } \ No newline at end of file diff --git a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/repositories/PatientRepository.kt b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/repositories/PatientRepository.kt index a820bc188..5ee735981 100644 --- a/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/repositories/PatientRepository.kt +++ b/grooves-example-springboot-kotlin/src/main/kotlin/grooves/boot/kotlin/repositories/PatientRepository.kt @@ -12,6 +12,7 @@ import reactor.core.publisher.Mono import java.util.Date interface PatientBlockingRepository : CrudRepository + interface PatientEventBlockingRepository : CrudRepository { fun findAllByAggregateIdIn(aggregateIds: List): List } @@ -21,51 +22,48 @@ interface PatientRepository : ReactiveCrudRepository { } interface PatientEventRepository : ReactiveCrudRepository { - fun findAllByAggregateIdIn(aggregateIds: List): Flux @Query("{'aggregateId':?0, 'position':{'\$gt':?1, '\$lte':?2}}") fun findAllByPositionRange( aggregateId: String, lowerBoundExclusive: Long, - upperBoundInclusive: Long + upperBoundInclusive: Long, ): Flux @Query("{'aggregateId':?0, 'timestamp':{'\$gt':?1, '\$lte':?2}}") fun findAllByTimestampRange( aggregateId: String, lowerBoundExclusive: Date, - upperBoundInclusive: Date + upperBoundInclusive: Date, ): Flux fun findAllByAggregateIdAndTimestampLessThan( aggregateId: String, - snapshotTime: Date + snapshotTime: Date, ): Flux } interface PatientAccountRepository : ReactiveCrudRepository { - fun findByAggregateIdAndLastEventPositionLessThan( aggregateId: String, - maxPosition: Long + maxPosition: Long, ): Mono fun findByAggregateIdAndLastEventTimestampLessThan( aggregateId: String, - maxTimestamp: Date + maxTimestamp: Date, ): Mono } interface PatientHealthRepository : ReactiveCrudRepository { - fun findByAggregateIdAndLastEventPositionLessThan( aggregateId: String, - maxPosition: Long + maxPosition: Long, ): Mono fun findByAggregateIdAndLastEventTimestampLessThan( aggregateId: String, - maxTimestamp: Date + maxTimestamp: Date, ): Mono } \ No newline at end of file diff --git a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/EventApplyOutcome.kt b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/EventApplyOutcome.kt index 377e25f15..53fab8e2a 100644 --- a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/EventApplyOutcome.kt +++ b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/EventApplyOutcome.kt @@ -17,5 +17,5 @@ enum class EventApplyOutcome { * Normal processing can continue and the current value of snapshot can be passed to the * remainder of the computation. */ - CONTINUE + CONTINUE, } \ No newline at end of file diff --git a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/BaseEvent.kt b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/BaseEvent.kt index a6cf7ea3d..1de06cf47 100644 --- a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/BaseEvent.kt +++ b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/BaseEvent.kt @@ -14,7 +14,6 @@ import java.util.Date * @author Rahul Somasunderam */ interface BaseEvent { - /** * Returns the aggregate as an Observable. * This can be used in a reactive way to obtain the aggregate. diff --git a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/DeprecatedBy.kt b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/DeprecatedBy.kt index b28717160..851bdc6b4 100644 --- a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/DeprecatedBy.kt +++ b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/DeprecatedBy.kt @@ -17,7 +17,6 @@ import org.reactivestreams.Publisher */ interface DeprecatedBy : BaseEvent { - /** * An Observable of the converse of this event. * The converse of a [DeprecatedBy] is a [Deprecates] event that does the exact opposite of this event. diff --git a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/Deprecates.kt b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/Deprecates.kt index 23ddb3502..42ec54b8f 100644 --- a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/Deprecates.kt +++ b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/Deprecates.kt @@ -17,7 +17,6 @@ import org.reactivestreams.Publisher */ interface Deprecates : BaseEvent { - /** * An Observable of the converse of this event. * The converse of a [Deprecates] is a [DeprecatedBy] event that does the exact opposite of this event. diff --git a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/DisjoinEvent.kt b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/DisjoinEvent.kt index be586d437..40ec8f41e 100644 --- a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/DisjoinEvent.kt +++ b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/DisjoinEvent.kt @@ -14,7 +14,6 @@ import org.reactivestreams.Publisher */ interface DisjoinEvent : BaseEvent { - /** * An observable that points to the aggregate to which a join is being performed. * diff --git a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/JoinEvent.kt b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/JoinEvent.kt index 17240b4a7..9569f4686 100644 --- a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/JoinEvent.kt +++ b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/JoinEvent.kt @@ -16,9 +16,9 @@ interface JoinEvent< AggregateT, EventIdT, EventT, - JoinedAggregateT> : + JoinedAggregateT, + > : BaseEvent { - /** * An observable that points to the aggregate to which a join is being performed. * diff --git a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/RevertEvent.kt b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/RevertEvent.kt index 5e39987a4..cd8acb4a5 100644 --- a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/RevertEvent.kt +++ b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/events/RevertEvent.kt @@ -11,7 +11,6 @@ package com.github.rahulsom.grooves.api.events */ interface RevertEvent : BaseEvent { - /** * [BaseEvent.id] from the event that should be reverted. */ diff --git a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/Join.kt b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/Join.kt index acf2c7960..a6be794de 100644 --- a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/Join.kt +++ b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/Join.kt @@ -19,7 +19,8 @@ interface Join< JoinIdT, in JoinedAggregateT, EventIdT, - in EventT : BaseEvent> : + in EventT : BaseEvent, + > : TemporalJoin, VersionedJoin, Snapshot \ No newline at end of file diff --git a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/Snapshot.kt b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/Snapshot.kt index 24aac3db1..e96435747 100644 --- a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/Snapshot.kt +++ b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/Snapshot.kt @@ -17,6 +17,7 @@ interface Snapshot< AggregateT, SnapshotIdT, EventIdT, - in EventT : BaseEvent> : + in EventT : BaseEvent, + > : VersionedSnapshot, TemporalSnapshot \ No newline at end of file diff --git a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/TemporalJoin.kt b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/TemporalJoin.kt index 4e0c55515..54001ea47 100644 --- a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/TemporalJoin.kt +++ b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/TemporalJoin.kt @@ -18,6 +18,7 @@ interface TemporalJoin< JoinIdT, in JoinedAggregateT, EventIdT, - in EventT : BaseEvent> : + in EventT : BaseEvent, + > : TemporalSnapshot, BaseJoin \ No newline at end of file diff --git a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/TemporalSnapshot.kt b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/TemporalSnapshot.kt index bb121f859..1d2c980b6 100644 --- a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/TemporalSnapshot.kt +++ b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/TemporalSnapshot.kt @@ -18,9 +18,9 @@ interface TemporalSnapshot< AggregateT, SnapshotIdT, EventIdT, - in EventT : BaseEvent> : + in EventT : BaseEvent, + > : BaseSnapshot { - /** * The timestamp of the last event that this snapshot represents. * diff --git a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/VersionedJoin.kt b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/VersionedJoin.kt index 08045b88d..3cc28e438 100644 --- a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/VersionedJoin.kt +++ b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/VersionedJoin.kt @@ -18,6 +18,7 @@ interface VersionedJoin< JoinIdT, in JoinedAggregateT, EventIdT, - in EventT : BaseEvent> : + in EventT : BaseEvent, + > : VersionedSnapshot, BaseJoin \ No newline at end of file diff --git a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/VersionedSnapshot.kt b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/VersionedSnapshot.kt index d7a3dc3cb..167613779 100644 --- a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/VersionedSnapshot.kt +++ b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/VersionedSnapshot.kt @@ -17,9 +17,9 @@ interface VersionedSnapshot< AggregateT, SnapshotIdT, EventIdT, - in EventT : BaseEvent> : + in EventT : BaseEvent, + > : BaseSnapshot { - /** * The position of the last event that this snapshot represents. * diff --git a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/internal/BaseJoin.kt b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/internal/BaseJoin.kt index 2c3a10446..54e582fe5 100644 --- a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/internal/BaseJoin.kt +++ b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/internal/BaseJoin.kt @@ -17,9 +17,10 @@ interface BaseJoin< JoinIdT, in JoinedAggregateT, EventIdT, - in EventT : BaseEvent> : + in EventT : BaseEvent, + > : BaseSnapshot { - fun addJoinedAggregate(joinedAggregateT: JoinedAggregateT) + fun removeJoinedAggregate(joinedAggregateT: JoinedAggregateT) } \ No newline at end of file diff --git a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/internal/BaseSnapshot.kt b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/internal/BaseSnapshot.kt index 59d449fde..1bef9fbf0 100644 --- a/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/internal/BaseSnapshot.kt +++ b/grooves-types/src/main/kotlin/com/github/rahulsom/grooves/api/snapshots/internal/BaseSnapshot.kt @@ -17,8 +17,8 @@ interface BaseSnapshot< AggregateT, SnapshotIdT, EventIdT, - in EventT : BaseEvent> { - + in EventT : BaseEvent, + > { /** * A unique identifier for the Snapshot. * This typically maps to the primary key in a persistence mechanism.