Skip to content

Commit

Permalink
Merge branch 'release/3.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
zambrovski committed Nov 15, 2022
2 parents 2018113 + 5093c39 commit dfb1076
Show file tree
Hide file tree
Showing 102 changed files with 3,048 additions and 576 deletions.
2 changes: 1 addition & 1 deletion bom/datapool-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holunda.polyflow</groupId>
<artifactId>polyflow-parent</artifactId>
<version>3.3.3</version>
<version>3.4.0</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand Down
6 changes: 3 additions & 3 deletions bom/parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holunda.polyflow</groupId>
<artifactId>polyflow-root</artifactId>
<version>3.3.3</version>
<version>3.4.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand All @@ -21,10 +21,10 @@
<springboot.version>2.7.5</springboot.version>
<camunda-commons-typed-values.version>7.18.0</camunda-commons-typed-values.version>

<axon-bom.version>4.6.1</axon-bom.version>
<axon-bom.version>4.6.2</axon-bom.version>

<axon-kotlin.version>4.6.0</axon-kotlin.version>
<axon-gateway-extension.version>0.1.1</axon-gateway-extension.version>
<axon-gateway-extension.version>1.0.0</axon-gateway-extension.version>

<awaitability.version>4.2.0</awaitability.version>
<mockito-kotlin.version>4.0.0</mockito-kotlin.version>
Expand Down
2 changes: 1 addition & 1 deletion bom/taskpool-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holunda.polyflow</groupId>
<artifactId>polyflow-parent</artifactId>
<version>3.3.3</version>
<version>3.4.0</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion core/bus-jackson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holunda.polyflow</groupId>
<artifactId>polyflow-parent</artifactId>
<version>3.3.3</version>
<version>3.4.0</version>
<relativePath>../../bom/parent/pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion core/datapool/datapool-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.holunda.polyflow</groupId>
<artifactId>polyflow-datapool-parent</artifactId>
<version>3.3.3</version>
<version>3.4.0</version>
</parent>

<artifactId>polyflow-datapool-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,30 @@ data class UpdateDataEntryCommand(
@TargetAggregateIdentifier
val dataIdentity: String = dataIdentityString(entryType = dataEntryChange.entryType, entryId = dataEntryChange.entryId)
)

/**
* Command to delete the aggregate.
*/
data class DeleteDataEntryCommand(
/**
* Entry id.
*/
val entryId: EntryId,
/**
* Entry type.
*/
val entryType: EntryType,
/**
* Modification information to mark the deletion state.
*/
val modification: Modification = Modification.NONE,
/**
* Final state.
*/
val state: DataEntryState= ProcessingType.UNDEFINED.of(""),
/**
* Addressing information.
*/
@TargetAggregateIdentifier
val dataIdentity: String = dataIdentityString(entryType = entryType, entryId = entryId),
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ enum class ProcessingType {
/**
* Undefined status.
*/
UNDEFINED;
UNDEFINED,
/**
* Data entry is deleted.
*/
DELETED;

/**
* Factory method.
Expand Down
2 changes: 1 addition & 1 deletion core/datapool/datapool-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.holunda.polyflow</groupId>
<artifactId>polyflow-datapool-parent</artifactId>
<version>3.3.3</version>
<version>3.4.0</version>
</parent>

<artifactId>polyflow-datapool-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class DataPoolCoreConfiguration {
@Bean(DATA_ENTRY_REPOSITORY)
fun firstEventDataEntryAggregateRepository(eventStore: EventStore): EventSourcingRepository<DataEntryAggregate> {
return FirstEventOnlyEventSourcingRepository.builder(DataEntryAggregate::class.java).eventStore(eventStore).build()

}

/**
Expand Down Expand Up @@ -75,5 +74,30 @@ class DataPoolCoreConfiguration {
@Bean(DATA_ENTRY_CACHE)
fun dataEntryCache(): Cache = WeakReferenceCache()

/**
* Deletion strategy for lax handling of updates after deletion (default).
*/
@ConditionalOnProperty(
name = ["polyflow.core.data-entry.deletion-strategy"],
havingValue = "lax",
matchIfMissing = true
)
@Bean
fun laxDeletionStrategy(): DeletionStrategy = object : DeletionStrategy {
override fun strictMode(): Boolean = false
}

/**
* Deletion strategy for strict handling of updates after deletion.
*/
@ConditionalOnProperty(
name = ["polyflow.core.data-entry.deletion-strategy"],
havingValue = "strict",
matchIfMissing = false
)
@Bean
fun strictDeletionStrategy(): DeletionStrategy = object : DeletionStrategy {
override fun strictMode(): Boolean = false
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.holunda.polyflow.datapool.core

/**
* Describes how deleted data entries should be handled.
*/
interface DeletionStrategy {
/**
* If set to true, the update event sent to the aggregate will result in AggregateDeletedException.
* If set to false, the update of deleted data entry will undelete it and update the properties.
*/
fun strictMode(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.holunda.polyflow.datapool.core.business
import io.holunda.camunda.taskpool.api.business.CreateDataEntryCommand
import io.holunda.camunda.taskpool.api.business.CreateOrUpdateDataEntryCommand
import io.holunda.camunda.taskpool.api.business.UpdateDataEntryCommand
import io.holunda.polyflow.datapool.core.DeletionStrategy
import io.holunda.polyflow.datapool.ifPresentOrElse
import mu.KLogging
import org.axonframework.commandhandling.CommandHandler
Expand All @@ -18,7 +19,8 @@ import java.util.*
*/
@Component
class CreateOrUpdateCommandHandler(
private val eventSourcingRepository: EventSourcingRepository<DataEntryAggregate>
private val eventSourcingRepository: EventSourcingRepository<DataEntryAggregate>,
private val deletionStrategy: DeletionStrategy
) {

companion object: KLogging()
Expand All @@ -38,7 +40,8 @@ class CreateOrUpdateCommandHandler(
logger.trace { "Aggregate found. Updating it passing command $updateCommand" }
aggregate.invoke {
it.handle(
command = updateCommand
command = updateCommand,
deletionStrategy = deletionStrategy
)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package io.holunda.polyflow.datapool.core.business

import io.holunda.camunda.taskpool.api.business.*
import io.holunda.polyflow.datapool.core.DataPoolCoreConfiguration
import io.holunda.polyflow.datapool.core.DeletionStrategy
import mu.KLogging
import org.axonframework.commandhandling.CommandHandler
import org.axonframework.eventsourcing.AggregateDeletedException
import org.axonframework.eventsourcing.EventSourcingHandler
import org.axonframework.modelling.command.AggregateIdentifier
import org.axonframework.modelling.command.AggregateLifecycle
Expand All @@ -21,10 +23,11 @@ import org.axonframework.spring.stereotype.Aggregate
)
class DataEntryAggregate() {

companion object: KLogging()
companion object : KLogging()

@AggregateIdentifier
private lateinit var dataIdentity: String
private var deleted: Boolean = false

/**
* Handle creation of data entry aggregate.
Expand All @@ -37,40 +40,80 @@ class DataEntryAggregate() {
}

/**
* Handle update command.
* Handle update.
*/
@CommandHandler
fun handle(command: UpdateDataEntryCommand) {
fun handle(command: UpdateDataEntryCommand, deletionStrategy: DeletionStrategy) {
if (deletionStrategy.strictMode()) {
if (deleted) {
throw AggregateDeletedException(this.dataIdentity, "The data entry has already been deleted")
}
}
AggregateLifecycle.apply(
command.updatedEvent()
)
}

/**
* React on create event.
* Handle delete.
*/
@CommandHandler
fun handle(command: DeleteDataEntryCommand, deletionStrategy: DeletionStrategy) {
if (deletionStrategy.strictMode()) {
if (deleted) {
throw AggregateDeletedException(this.dataIdentity, "The data entry has already been deleted")
}
}
AggregateLifecycle.apply(
command.deletedEvent()
)
}

/**
* React on created event.
*/
@EventSourcingHandler
fun on(event: DataEntryCreatedEvent) {
val identity = dataIdentityString(entryType = event.entryType, entryId = event.entryId)
this.dataIdentity = dataIdentityString(entryType = event.entryType, entryId = event.entryId)
if (this.deleted) {
this.deleted = false
}
if (logger.isDebugEnabled) {
logger.debug { "Created $identity." }
logger.debug { "Created $dataIdentity." }
}
if (logger.isTraceEnabled) {
logger.trace { "Created $identity with: $event" }
logger.trace { "Created $dataIdentity with: $event" }
}
this.dataIdentity = identity
}

/**
* React on update event.
* React on updated event.
*/
@EventSourcingHandler
fun on(event: DataEntryUpdatedEvent) {
if (this.deleted) {
this.deleted = false
}
if (logger.isDebugEnabled) {
logger.debug { "Updated $dataIdentity." }
}
if (logger.isTraceEnabled) {
logger.trace { "Updated $dataIdentity with: $event" }
}
}

/**
* React on deleted event.
*/
@EventSourcingHandler
fun on(event: DataEntryDeletedEvent) {
if (logger.isDebugEnabled) {
logger.debug { "Deleted $dataIdentity." }
}
if (logger.isTraceEnabled) {
logger.trace { "Deleted $dataIdentity with: $event" }
}
// Don't use AggregateLifecycle.markDeleted() because then the combination of entryType / entryId is then really deleted forever
this.deleted = true
}
}
Loading

0 comments on commit dfb1076

Please sign in to comment.