Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#29] Feature/aggregate with immutable identifier #54

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,19 @@ If you want to build the extension locally, you need to check it out from GiHub

Please execute the following command line if you are interested in producing KDoc and Source archives:
zambrovski marked this conversation as resolved.
Show resolved Hide resolved

./mvnw clean install -Pjavadoc-and-sources
./mvnw clean install -Pdocs-and-sources

### Collecting code coverage data

If you are interested in test code coverage, please run the following command:

./mvnw clean install -Pcoverage

### Building example project

The project includes an example module demonstrating usage of the extension. If you want to skip the example
build, please run the following command line:

./mvnw clean install -DskipExamples

---
55 changes: 55 additions & 0 deletions kotlin-example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2020. Axon Framework
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<name>Axon Framework - Kotlin Extension Example</name>
<description>Module for the Kotlin Extension Example of Axon Framework</description>

<parent>
<groupId>org.axonframework.extensions.kotlin</groupId>
<artifactId>axon-kotlin-parent</artifactId>
<version>0.3.0-SNAPSHOT</version>
</parent>

<artifactId>axon-kotlin-example</artifactId>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.axonframework.extensions.kotlin</groupId>
<artifactId>axon-kotlin-springboot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.axonframework</groupId>
<artifactId>axon-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>io.github.microutils</groupId>
<artifactId>kotlin-logging-jvm</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2020. Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.axonframework.extension.kotlin.example

import mu.KLogging
import org.axonframework.config.Configurer
import org.axonframework.eventhandling.EventBus
import org.axonframework.eventhandling.EventMessage
import org.axonframework.eventhandling.interceptors.EventLoggingInterceptor
import org.axonframework.eventhandling.tokenstore.TokenStore
import org.axonframework.eventhandling.tokenstore.inmemory.InMemoryTokenStore
import org.axonframework.eventsourcing.eventstore.EmbeddedEventStore
import org.axonframework.eventsourcing.eventstore.EventStore
import org.axonframework.eventsourcing.eventstore.inmemory.InMemoryEventStorageEngine
import org.axonframework.extension.kotlin.spring.EnableAggregateWithImmutableIdentifierScan
import org.axonframework.messaging.interceptors.LoggingInterceptor
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.context.annotation.Bean

/**
* Starting point.
* @param args CLI parameters.
*/
fun main(args: Array<String>) {
SpringApplication.run(AxonKotlinExampleApplication::class.java, *args)
}

/**
* Main example application class.
*/
@SpringBootApplication
@EnableAggregateWithImmutableIdentifierScan
class AxonKotlinExampleApplication {

companion object : KLogging()

/**
* Configures to use in-memory embedded event store.
*/
@Bean
fun eventStore(): EventStore = EmbeddedEventStore.builder().storageEngine(InMemoryEventStorageEngine()).build()

/**
* Configure logging interceptor.
*/
@Autowired
fun configureEventHandlingInterceptors(eventBus: EventBus) {
eventBus.registerDispatchInterceptor(EventLoggingInterceptor())
}

/**
* Configures to use in-memory token store.
*/
@Bean
fun tokenStore(): TokenStore = InMemoryTokenStore()

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2020. Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.axonframework.extension.kotlin.example.api

import org.axonframework.extension.kotlin.example.core.BankAccountIdentifier
import org.axonframework.modelling.command.TargetAggregateIdentifier
import javax.validation.constraints.Min

/**
* Create account.
*/
data class CreateBankAccountCommand(
@TargetAggregateIdentifier
val bankAccountId: String,
@Min(value = 0, message = "Overdraft limit must not be less than zero")
val overdraftLimit: Long
)

/**
* Create advanced account.
*/
data class CreateAdvancedBankAccountCommand(
@TargetAggregateIdentifier
val bankAccountId: BankAccountIdentifier,
@Min(value = 0, message = "Overdraft limit must not be less than zero")
val overdraftLimit: Long
)


/**
* Deposit money.
*/
data class DepositMoneyCommand(
@TargetAggregateIdentifier
val bankAccountId: String,
val amountOfMoney: Long
)

/**
* Withdraw money.
*/
data class WithdrawMoneyCommand(
@TargetAggregateIdentifier
val bankAccountId: String,
val amountOfMoney: Long
)

/**
* Return money if transfer is not possible.
*/
data class ReturnMoneyOfFailedBankTransferCommand(
@TargetAggregateIdentifier
val bankAccountId: String,
val amount: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2020. Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.axonframework.extension.kotlin.example.api

import org.axonframework.extension.kotlin.example.core.BankAccountIdentifier

/**
* Account created.
*/
data class BankAccountCreatedEvent(
val id: String,
val overdraftLimit: Long
)

/**
* Advanced account created.
*/
data class AdvancedBankAccountCreatedEvent(
val id: BankAccountIdentifier,
val overdraftLimit: Long
)

/**
* Collecting event for increasing amount.
*/
sealed class MoneyAddedEvent(
open val bankAccountId: String,
open val amount: Long
)

/**
* Money deposited.
*/
data class MoneyDepositedEvent(override val bankAccountId: String, override val amount: Long) : MoneyAddedEvent(bankAccountId, amount)

/**
* Money returned.
*/
data class MoneyOfFailedBankTransferReturnedEvent(override val bankAccountId: String, override val amount: Long) : MoneyAddedEvent(bankAccountId, amount)

/**
* Money received via transfer.
*/
data class DestinationBankAccountCreditedEvent(override val bankAccountId: String, override val amount: Long, val bankTransferId: String) : MoneyAddedEvent(bankAccountId, amount)

/**
* Collecting event for decreasing amount.
*/
sealed class MoneySubtractedEvent(
open val bankAccountId: String,
open val amount: Long
)

/**
* Money withdrawn.
*/
data class MoneyWithdrawnEvent(override val bankAccountId: String, override val amount: Long) : MoneySubtractedEvent(bankAccountId, amount)

/**
* Money transferred.
*/
data class SourceBankAccountDebitedEvent(override val bankAccountId: String, override val amount: Long, val bankTransferId: String) : MoneySubtractedEvent(bankAccountId, amount)

/**
* Money transfer rejected.
*/
data class SourceBankAccountDebitRejectedEvent(val bankTransferId: String)
Loading