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

Feature/141 jmolecules #142

Open
wants to merge 2 commits into
base: develop
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
26 changes: 25 additions & 1 deletion _examples/axon-avro-holi-bank-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jmolecules</groupId>
<artifactId>jmolecules-bom</artifactId>
<version>2023.1.2</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -73,6 +80,21 @@
<artifactId>jakarta.annotation-api</artifactId>
</dependency>

<dependency>
<groupId>org.jmolecules</groupId>
<artifactId>kmolecules-ddd</artifactId>
</dependency>

<dependency>
<groupId>org.jmolecules</groupId>
<artifactId>jmolecules-cqrs-architecture</artifactId>
</dependency>

<dependency>
<groupId>org.jmolecules</groupId>
<artifactId>jmolecules-events</artifactId>
</dependency>

<!-- TEST -->
<dependency>
<groupId>org.mockito.kotlin</groupId>
Expand Down Expand Up @@ -110,7 +132,9 @@
<groupId>io.toolisticon.kotlin.avro.maven</groupId>
<artifactId>avro-kotlin-maven-plugin</artifactId>
<version>${avro-kotlin.version}</version>
<configuration />
<configuration>
<formatter>NONE</formatter>
</configuration>
<executions>
<execution>
<id>generate-schema</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import org.axonframework.queryhandling.QueryGateway
import org.axonframework.serialization.Serializer
import org.axonframework.serialization.json.JacksonSerializer
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.event.ApplicationStartedEvent
import org.springframework.boot.runApplication
import org.springframework.context.ApplicationContext
import org.springframework.context.ApplicationContextAware
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary
Expand Down Expand Up @@ -55,10 +58,12 @@ class AxonAvroExampleApplication {
class ExampleRunner(
val commandGateway: CommandGateway,
val queryGateway: QueryGateway
) {
) : ApplicationContextAware {

companion object : KLogging()

private lateinit var applicationContext: ApplicationContext

@EventListener
fun runExample(event: ApplicationStartedEvent) {
logger.info {
Expand Down Expand Up @@ -124,7 +129,7 @@ class AxonAvroExampleApplication {

Transactions for account $bankAccountId:

${transactions.items.joinToString( separator = "\n")}
${transactions.items.joinToString(separator = "\n")}

================================================================================
""".trimIndent()
Expand All @@ -138,6 +143,13 @@ ${transactions.items.joinToString( separator = "\n")}
===============================================================================
""".trimIndent()
}

SpringApplication.exit(applicationContext, { 0 })
}

override fun setApplicationContext(applicationContext: ApplicationContext) {
this.applicationContext = applicationContext
}

}
}
31 changes: 31 additions & 0 deletions axon-avro-generation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
<name>${project.artifactId}</name>
<description>Axon Avro Generation - strategies and processors for avro-kotlin-generator.</description>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jmolecules</groupId>
<artifactId>jmolecules-bom</artifactId>
<version>2023.1.2</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.toolisticon.kotlin.avro</groupId>
Expand Down Expand Up @@ -45,6 +57,25 @@
<artifactId>kotlin-code-generation-test</artifactId>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.jmolecules</groupId>
<artifactId>kmolecules-ddd</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jmolecules</groupId>
<artifactId>jmolecules-cqrs-architecture</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jmolecules</groupId>
<artifactId>jmolecules-events</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
19 changes: 18 additions & 1 deletion axon-avro-generation/src/main/kotlin/AxonAvroGeneration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,22 @@ package io.holixon.axon.avro.generation


object AxonAvroGeneration {
// empty marker

object jmolecules {

val ddd = try {
Class.forName("org.jmolecules.ddd.annotation.AggregateRoot")
true
} catch (e: ClassNotFoundException) {
false
}

val cqrs = try {
Class.forName("org.jmolecules.ddd.annotation.AggregateRoot")
true
} catch (e: ClassNotFoundException) {
false
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum class RecordMetaDataType {
Command,
Query,
QueryResult,
Undefined,
;

val decapitalizedName = name.replaceFirstChar { c -> c.lowercase(Locale.getDefault()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.holixon.axon.avro.generation.processor

import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi
import io.holixon.axon.avro.generation.meta.RecordMetaData.Companion.recordMetaData
import io.holixon.axon.avro.generation.support.RevisionAnnotation
import io.holixon.axon.avro.generation.support.AxonFrameworkAnnotations.RevisionAnnotation
import io.toolisticon.kotlin.avro.generator.processor.KotlinDataClassFromRecordTypeProcessorBase
import io.toolisticon.kotlin.avro.generator.spi.SchemaDeclarationContext
import io.toolisticon.kotlin.avro.model.RecordType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package io.holixon.axon.avro.generation.processor
import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi
import io.holixon.axon.avro.generation.meta.FieldMetaData.Companion.fieldMetaData
import io.holixon.axon.avro.generation.meta.FieldMetaDataType
import io.holixon.axon.avro.generation.support.TargetAggregateIdentifierAnnotation
import io.holixon.axon.avro.generation.support.AxonFrameworkAnnotations.TargetAggregateIdentifierAnnotation
import io.holixon.axon.avro.generation.support.JMoleculesAnnotationSupplier.AssociationAnnotation
import io.toolisticon.kotlin.avro.generator.processor.ConstructorPropertyFromRecordFieldProcessorBase
import io.toolisticon.kotlin.avro.generator.spi.SchemaDeclarationContext
import io.toolisticon.kotlin.avro.model.RecordField
Expand All @@ -13,14 +14,18 @@ import io.toolisticon.kotlin.generation.builder.KotlinConstructorPropertySpecBui
@OptIn(ExperimentalKotlinPoetApi::class)
class AxonTargetIdentifierAnnotationProcessor : ConstructorPropertyFromRecordFieldProcessorBase() {

override fun invoke(context: SchemaDeclarationContext, input: RecordField, builder: KotlinConstructorPropertySpecBuilder): KotlinConstructorPropertySpecBuilder = builder.apply {
requireNotNull(input)
override fun invoke(
context: SchemaDeclarationContext,
input: RecordField,
builder: KotlinConstructorPropertySpecBuilder
): KotlinConstructorPropertySpecBuilder = builder.apply {

AssociationAnnotation().addIfEnabled(this)

addAnnotation(TargetAggregateIdentifierAnnotation)
}

override fun test(ctx: SchemaDeclarationContext, input: Any): Boolean {
return super.test(ctx, input) && input is RecordField && input.fieldMetaData()?.type == FieldMetaDataType.Association
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.holixon.axon.avro.generation.processor

import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi
import io.holixon.axon.avro.generation.meta.RecordMetaData.Companion.recordMetaData
import io.holixon.axon.avro.generation.meta.RecordMetaDataType
import io.holixon.axon.avro.generation.meta.RecordMetaDataType.Command
import io.holixon.axon.avro.generation.meta.RecordMetaDataType.Event
import io.holixon.axon.avro.generation.meta.RecordMetaDataType.Query
import io.holixon.axon.avro.generation.meta.RecordMetaDataType.QueryResult
import io.holixon.axon.avro.generation.meta.RecordMetaDataType.Undefined
import io.holixon.axon.avro.generation.support.JMoleculesAnnotationSupplier.CommandAnnotation
import io.holixon.axon.avro.generation.support.JMoleculesAnnotationSupplier.DomainEventAnnotation
import io.toolisticon.kotlin.avro.generator.processor.KotlinDataClassFromRecordTypeProcessorBase
import io.toolisticon.kotlin.avro.generator.spi.SchemaDeclarationContext
import io.toolisticon.kotlin.avro.model.RecordType
import io.toolisticon.kotlin.generation.builder.KotlinDataClassSpecBuilder

@OptIn(ExperimentalKotlinPoetApi::class)
class JMoleculesAnnotationRecordTypeProcessor : KotlinDataClassFromRecordTypeProcessorBase() {

private fun recordMetaDataType(input: Any): RecordMetaDataType = if (input is RecordType) {
input.recordMetaData()?.type ?: Undefined
} else {
Undefined
}

override fun invoke(
context: SchemaDeclarationContext,
input: RecordType,
builder: KotlinDataClassSpecBuilder
): KotlinDataClassSpecBuilder = builder.apply {
when (recordMetaDataType(input)) {
Event -> DomainEventAnnotation(input.canonicalName).addIfEnabled(this)
Command -> CommandAnnotation(input.canonicalName).addIfEnabled(this)
Query, QueryResult, Undefined -> {
}
}
}

override fun test(ctx: SchemaDeclarationContext, input: Any): Boolean {
return super.test(ctx, input) && Undefined != recordMetaDataType(input)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ import org.axonframework.modelling.command.TargetAggregateIdentifier
import org.axonframework.serialization.Revision

@OptIn(ExperimentalKotlinPoetApi::class)
data class RevisionAnnotation(
val value: String,
) : KotlinAnnotationSpecSupplier {
override fun spec(): KotlinAnnotationSpec = buildAnnotation(Revision::class) {
addMember(FORMAT_STRING, value)
object AxonFrameworkAnnotations {

data class RevisionAnnotation(
val value: String,
) : KotlinAnnotationSpecSupplier {
override fun spec(): KotlinAnnotationSpec = buildAnnotation(Revision::class) {
addMember(FORMAT_STRING, value)
}
}
}

@OptIn(ExperimentalKotlinPoetApi::class)
data object TargetAggregateIdentifierAnnotation : KotlinAnnotationSpecSupplier {
override fun spec(): KotlinAnnotationSpec = buildAnnotation(TargetAggregateIdentifier::class)
data object TargetAggregateIdentifierAnnotation : KotlinAnnotationSpecSupplier {
override fun spec(): KotlinAnnotationSpec = buildAnnotation(TargetAggregateIdentifier::class)
}
}
Loading
Loading