This repository has been archived by the owner on Sep 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ibrahim AlTamimi <ibm.iloom@gmail.com>
- Loading branch information
Showing
33 changed files
with
232 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
ktx-radix-development/ktx-radix-development-operation/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
<parent> | ||
<artifactId>ktx-radix-development</artifactId> | ||
<groupId>io.quee.ktx.radix</groupId> | ||
<version>v1.2.0-RELEASE</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>ktx-radix-development-operation</artifactId> | ||
|
||
</project> |
77 changes: 77 additions & 0 deletions
77
...pment-operation/src/main/java/io/quee/ktx/radix/develop/operation/operation-definition.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package io.quee.ktx.radix.develop.operation | ||
|
||
/** | ||
* Created By [*Ibrahim Al-Tamimi *](https://www.linkedin.com/in/iloom/) | ||
* Created At 21, **Sun February, 2021** | ||
* Project *ktx-radix* [Quee.IO] | ||
*/ | ||
interface Operation<RQ, RS> { | ||
fun RQ.operate(): RS | ||
} | ||
|
||
interface OperationRole<RQ, RS> { | ||
fun RQ.operateRole(): RS | ||
} | ||
|
||
interface Operator<RQ, RS> { | ||
fun RQ.operate(response: RS) | ||
} | ||
|
||
infix fun <RQ, RS> Operation<RQ, RS>.operationBuilder( | ||
builder: OperationBuilder<RQ, RS>.() -> Unit, | ||
): Operation<RQ, RS> = | ||
OperationBuilder(this) | ||
.apply { | ||
builder() | ||
} | ||
|
||
class OperationBuilder<RQ, RS>( | ||
private val mainOperation: Operation<RQ, RS>, | ||
) : Operation<RQ, RS> { | ||
private val roles: MutableList<OperationRole<RQ, Unit>> = mutableListOf() | ||
private val afterOperators: MutableList<Operator<RQ, RS>> = mutableListOf() | ||
|
||
private fun RQ.before() = | ||
roles.forEach { it.run { operateRole() } } | ||
|
||
private fun RQ.process() = | ||
mainOperation.run { operate() } | ||
|
||
private fun RQ.after(response: RS) = | ||
afterOperators.forEach { | ||
it.run { operate(response) } | ||
} | ||
|
||
infix fun after(operator: Operator<RQ, RS>) { | ||
this.afterOperators.add(operator) | ||
} | ||
|
||
infix fun after(operator: RQ.(RS) -> Unit) { | ||
this.afterOperators.add(object : Operator<RQ, RS> { | ||
override fun RQ.operate(response: RS) { | ||
operator(response) | ||
} | ||
}) | ||
} | ||
|
||
infix fun install(role: OperationRole<RQ, Unit>) { | ||
roles.add(role) | ||
} | ||
|
||
infix fun install(role: RQ.() -> Unit) { | ||
roles.add(object : OperationRole<RQ, Unit> { | ||
override fun RQ.operateRole() { | ||
role() | ||
} | ||
}) | ||
} | ||
|
||
override fun RQ.operate(): RS { | ||
before() | ||
return process().apply { | ||
after(this) | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...tx-radix-development-usecase-ext/src/main/java/io/quee/ktx/radix/develop/usecase/roles.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.quee.ktx.radix.develop.usecase | ||
|
||
import io.quee.ktx.radix.develop.usecase.model.UseCaseRequest | ||
import io.quee.ktx.radix.develop.usecase.validation.func.DefaultUseCaseValidator | ||
import io.quee.ktx.radix.develop.usecase.validation.validate | ||
|
||
/** | ||
* Created By [*Ibrahim Al-Tamimi *](https://www.linkedin.com/in/iloom/) | ||
* Created At 26, **Fri February, 2021** | ||
* Project *ktx-radix* [Quee.IO] | ||
*/ | ||
object JavaXValidator : (UseCaseRequest) -> Unit { | ||
private val useCaseValidator = DefaultUseCaseValidator.create() | ||
override fun invoke(p1: UseCaseRequest) = | ||
useCaseValidator.run { | ||
validate(p1) | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...velopment-usecase-ext/src/main/java/io/quee/ktx/radix/develop/usecase/usecases-builder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package io.quee.ktx.radix.develop.usecase | ||
|
||
import io.quee.ktx.radix.develop.usecase.actionable.ActionableCommandUseCase | ||
import io.quee.ktx.radix.develop.usecase.actionable.ActionableFunctionalUseCase | ||
import io.quee.ktx.radix.develop.usecase.factory.UseCaseFactory | ||
import io.quee.ktx.radix.develop.usecase.model.UseCaseRequest | ||
import io.quee.ktx.radix.develop.usecase.model.UseCaseResponse | ||
|
||
/** | ||
* Created By [*Ibrahim AlTamimi *](https://www.linkedin.com/in/iloom/) | ||
* Created At 28, **Sat November, 2020** | ||
* Project *ktx-radix* [Quee.IO] | ||
*/ | ||
|
||
typealias UseCaseRole<RQ, RS> = RQ.() -> RS | ||
typealias UseCaseOperator<RQ, RS> = RQ.() -> RS | ||
|
||
fun <F : UseCaseFactory, RQ : UseCaseRequest> F.commandUseCaseBuilder( | ||
command: UseCaseOperator<RQ, Unit>, | ||
builder: BuilderCommandUseCase<RQ>.(F) -> Unit, | ||
): CommandUseCase<RQ> = | ||
BuilderCommandUseCase(command).apply { | ||
builder(this@commandUseCaseBuilder) | ||
} | ||
|
||
infix fun <RQ : UseCaseRequest> UseCaseOperator<RQ, Unit>.commandUseCaseBuilder( | ||
builder: BuilderCommandUseCase<RQ>.() -> Unit, | ||
): CommandUseCase<RQ> = | ||
BuilderCommandUseCase(this).apply { | ||
builder() | ||
} | ||
|
||
fun <F : UseCaseFactory, RQ : UseCaseRequest, RS : UseCaseResponse> F.functionalUseCaseBuilder( | ||
function: UseCaseOperator<RQ, RS>, | ||
builder: BuilderFunctionalUseCase<RQ, RS>.(F) -> Unit, | ||
): FunctionalUseCase<RQ, RS> = | ||
BuilderFunctionalUseCase(function).apply { | ||
builder(this@functionalUseCaseBuilder) | ||
} | ||
|
||
infix fun <RQ : UseCaseRequest, RS : UseCaseResponse> UseCaseOperator<RQ, RS>.functionalUseCaseBuilder( | ||
builder: BuilderFunctionalUseCase<RQ, RS>.() -> Unit, | ||
): FunctionalUseCase<RQ, RS> = | ||
BuilderFunctionalUseCase(this).apply { | ||
builder() | ||
} | ||
|
||
class BuilderCommandUseCase<RQ : UseCaseRequest>( | ||
private val command: UseCaseOperator<RQ, Unit>, | ||
) : ActionableCommandUseCase<RQ>() { | ||
private val afterOperators: MutableList<UseCaseOperator<RQ, Unit>> = mutableListOf() | ||
private val roles: MutableList<UseCaseRole<RQ, Unit>> = mutableListOf() | ||
override fun RQ.before() = | ||
roles.forEach { | ||
it() | ||
} | ||
|
||
override fun RQ.doExecute() = command() | ||
override fun RQ.after(response: Unit) = afterOperators.forEach { it() } | ||
|
||
infix fun afterCommand(operator: UseCaseOperator<RQ, Unit>) { | ||
this.afterOperators.add(operator) | ||
} | ||
|
||
infix fun install(role: UseCaseRole<RQ, Unit>) { | ||
roles.add(role) | ||
} | ||
} | ||
|
||
class BuilderFunctionalUseCase<RQ : UseCaseRequest, RS : UseCaseResponse>( | ||
private val function: UseCaseOperator<RQ, RS>, | ||
) : ActionableFunctionalUseCase<RQ, RS>() { | ||
private val roles: MutableList<UseCaseRole<RQ, Unit>> = mutableListOf() | ||
private val afterOperators: MutableList<UseCaseOperator<RQ, RS>> = mutableListOf() | ||
|
||
override fun RQ.before() = roles.forEach { it() } | ||
|
||
override fun RQ.doProcess() = function() | ||
|
||
override fun RQ.after(response: RS) = afterOperators.forEach { it() } | ||
|
||
infix fun afterFunction(operator: UseCaseOperator<RQ, RS>) { | ||
this.afterOperators.add(operator) | ||
} | ||
|
||
infix fun install(role: UseCaseRole<RQ, Unit>) { | ||
roles.add(role) | ||
} | ||
} |
Oops, something went wrong.