Modularized Scala/Spring example

This commit is contained in:
Chris Richardson
2015-01-03 14:54:06 -08:00
parent a0e2b52ba3
commit 1084dbe3a8
56 changed files with 477 additions and 198 deletions

32
scala-spring/README.md Normal file
View File

@@ -0,0 +1,32 @@
This is the Scala/Spring version of the Event Sourcing/CQRS money transfer example application.
This application consists of three microservices:
* Account Service - the command side business logic for Accounts
* Money Transfer Service - the command side business logic for Money Transfers
* Query service - query side implementation of a MongoDB-based, denormalized view of Accounts and MoneyTransfers
The Account Service consists of the following modules:
* commandside-backend-accounts - the Account aggregate
* commandside-web-accounts - a REST API for creating and retrieving Accounts
The Money Transfer Service consists of the following modules:
* commandside-backend-transactions - the MoneyTransfer aggregate
* commandside-web-transactions - a REST API for creating and retrieving Money Transfers
The Query Service consists the following modules:
* queryside-backend - MongoDB-based, denormalized view of Accounts and MoneyTransfers
* queryside-web - a REST API for querying the denormalized view
In order to be used with the embedded Event Store, the three services are currently packaged as a single monolithic web application:
* monolithic-web - all-in-one, monolithic packaging of the application
As well as the above modules there are also:
* common-backend - code that is shared between the command side and the query side, primarily events and value objects
* backend-integration-tests - integrations tests for the backend

View File

@@ -0,0 +1,17 @@
apply plugin: 'scala'
dependencies {
compile "org.scala-lang:scala-library:2.10.2"
compile project(":commandside-backend-transactions")
compile project(":commandside-backend-accounts")
compile project(":queryside-backend")
testCompile scalaTestDependency
testCompile "junit:junit:4.11"
testCompile "net.chrisrichardson.eventstore.client:eventstore-jdbc:$eventStoreClientVersion"
}

View File

@@ -1,10 +1,12 @@
package net.chrisrichardson.eventstore.examples.bank
import net.chrisrichardson.eventstore.EventStore
import net.chrisrichardson.eventstore.examples.bank.accounts.{AccountService, AccountDebitedEvent, Account}
import net.chrisrichardson.eventstore.examples.bank.accounts.{AccountService, Account}
import net.chrisrichardson.eventstore.examples.bank.backend.common.accounts.AccountDebitedEvent
import net.chrisrichardson.eventstore.examples.bank.config.BankingTestConfiguration
import net.chrisrichardson.eventstore.examples.bank.queryside.AccountInfoQueryService
import net.chrisrichardson.eventstore.examples.bank.transactions.{TransferDetails, MoneyTransferService, MoneyTransfer, TransferStates}
import net.chrisrichardson.eventstore.examples.bank.backend.common.transactions.TransferDetails
import net.chrisrichardson.eventstore.examples.bank.transactions.{MoneyTransferService, TransferStates, MoneyTransfer}
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration
import org.junit.runner.RunWith
import org.scalatest.FlatSpec

View File

@@ -0,0 +1,5 @@
dependencies {
compile "org.scala-lang:scala-library:2.10.2"
compile project(":common-backend")
compile "net.chrisrichardson.eventstore.client:eventstore-client-event-handling:$eventStoreClientVersion"
}

View File

@@ -1,15 +1,14 @@
package net.chrisrichardson.eventstore.examples.bank.accounts
import net.chrisrichardson.eventstore.{PatternMatchingCommandProcessingAggregate, CommandProcessingAggregate}
import net.chrisrichardson.eventstore.examples.bank.accounts.AccountCommands.AccountCommand
import net.chrisrichardson.eventstore.PatternMatchingCommandProcessingAggregate
import net.chrisrichardson.eventstore.examples.bank.accounts.AccountCommands.{DebitAccountCommand, AccountCommand, CreditAccountCommand, OpenAccountCommand}
import net.chrisrichardson.eventstore.examples.bank.backend.common.accounts.{AccountCreditedEvent, AccountDebitFailedDueToInsufficientFundsEvent, AccountDebitedEvent, AccountOpenedEvent}
case class Account(balance : BigDecimal)
extends PatternMatchingCommandProcessingAggregate[Account, AccountCommand] {
def this() = this(null)
import net.chrisrichardson.eventstore.examples.bank.accounts.AccountCommands._
def processCommand = {
case OpenAccountCommand(initialBalance) =>

View File

@@ -1,11 +1,7 @@
package net.chrisrichardson.eventstore.examples.bank.accounts
import net.chrisrichardson.eventstore.EntityId
import net.chrisrichardson.eventstore.Command
import net.chrisrichardson.eventstore.{Command, EntityId}
/**
* Created by cer on 7/16/14.
*/
object AccountCommands {
sealed trait AccountCommand extends Command

View File

@@ -2,8 +2,8 @@ package net.chrisrichardson.eventstore.examples.bank.accounts
import net.chrisrichardson.eventstore.EventStore
import net.chrisrichardson.eventstore.examples.bank.accounts.AccountCommands.{CreditAccountCommand, DebitAccountCommand}
import net.chrisrichardson.eventstore.examples.bank.transactions.{DebitRecordedEvent, MoneyTransferCreatedEvent}
import net.chrisrichardson.eventstore.subscriptions.{EventSubscriber, CompoundEventHandler, EventHandlerMethod}
import net.chrisrichardson.eventstore.examples.bank.backend.common.transactions.{DebitRecordedEvent, MoneyTransferCreatedEvent}
import net.chrisrichardson.eventstore.subscriptions.{EventHandlerMethod, CompoundEventHandler, EventSubscriber}
import net.chrisrichardson.eventstore.util.EventHandlingUtil._
@EventSubscriber(id = "accountEventHandlers")

View File

@@ -0,0 +1,5 @@
dependencies {
compile "org.scala-lang:scala-library:2.10.2"
compile project(":common-backend")
compile "net.chrisrichardson.eventstore.client:eventstore-client-event-handling:$eventStoreClientVersion"
}

View File

@@ -1,7 +1,8 @@
package net.chrisrichardson.eventstore.examples.bank.transactions
import net.chrisrichardson.eventstore.{PatternMatchingCommandProcessingAggregate, EntityId, CommandProcessingAggregate}
import net.chrisrichardson.eventstore.examples.bank.transactions.MoneyTransferCommands.MoneyTransferCommand
import net.chrisrichardson.eventstore.PatternMatchingCommandProcessingAggregate
import net.chrisrichardson.eventstore.examples.bank.backend.common.transactions._
import net.chrisrichardson.eventstore.examples.bank.transactions.MoneyTransferCommands._
object TransferStates {
sealed trait State
@@ -19,8 +20,6 @@ case class MoneyTransfer(state : TransferStates.State, details : TransferDetails
def this() = this(TransferStates.NEW, null)
import net.chrisrichardson.eventstore.examples.bank.transactions.MoneyTransferCommands._
def processCommand = {
case CreateMoneyTransferCommand(withDetails) if state == TransferStates.NEW =>
Seq(MoneyTransferCreatedEvent(withDetails))

View File

@@ -1,7 +1,7 @@
package net.chrisrichardson.eventstore.examples.bank.transactions
import net.chrisrichardson.eventstore.EntityId
import net.chrisrichardson.eventstore.Command
import net.chrisrichardson.eventstore.{Command, EntityId}
import net.chrisrichardson.eventstore.examples.bank.backend.common.transactions.TransferDetails
object MoneyTransferCommands {

View File

@@ -1,9 +1,9 @@
package net.chrisrichardson.eventstore.examples.bank.transactions
import net.chrisrichardson.eventstore.EventStore
import net.chrisrichardson.eventstore.examples.bank.accounts._
import net.chrisrichardson.eventstore.examples.bank.transactions.MoneyTransferCommands.{RecordCreditCommand, RecordDebitCommand, RecordDebitFailedDueToInsufficientFundsCommand}
import net.chrisrichardson.eventstore.subscriptions.{EventSubscriber, CompoundEventHandler, DispatchedEvent, EventHandlerMethod}
import net.chrisrichardson.eventstore.examples.bank.backend.common.accounts._
import net.chrisrichardson.eventstore.examples.bank.transactions.MoneyTransferCommands.{RecordDebitFailedDueToInsufficientFundsCommand, RecordCreditCommand, RecordDebitCommand}
import net.chrisrichardson.eventstore.subscriptions.{CompoundEventHandler, EventSubscriber}
import net.chrisrichardson.eventstore.util.EventHandlingUtil._
@EventSubscriber (id = "transactionEventHandlers")

View File

@@ -1,6 +1,7 @@
package net.chrisrichardson.eventstore.examples.bank.transactions
import net.chrisrichardson.eventstore.EventStore
import net.chrisrichardson.eventstore.examples.bank.backend.common.transactions.TransferDetails
import net.chrisrichardson.eventstore.examples.bank.transactions.MoneyTransferCommands.CreateMoneyTransferCommand
import net.chrisrichardson.eventstore.util.ServiceUtil._

View File

@@ -0,0 +1,10 @@
apply plugin: 'scala'
dependencies {
compile "org.scala-lang:scala-library:2.10.2"
compile project(":commandside-backend-accounts")
compile project(":web-common")
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
testCompile scalaTestDependency
}

View File

@@ -0,0 +1,11 @@
package net.chrisrichardson.eventstore.examples.bank.web.accounts
import net.chrisrichardson.eventstore.examples.bank.accounts.AccountConfiguration
import org.springframework.context.annotation.{ComponentScan, Configuration, Import}
@Configuration
@Import(Array(classOf[AccountConfiguration]))
@ComponentScan
class CommandSideWebAccountsConfiguration {
}

View File

@@ -1,8 +1,8 @@
package net.chrisrichardson.eventstore.examples.bank.web.accounts.controllers
import net.chrisrichardson.eventstore.EntityId
import net.chrisrichardson.eventstore.EventStore
import net.chrisrichardson.eventstore.examples.bank.accounts.{Account, AccountService}
import net.chrisrichardson.eventstore.examples.bank.accounts.AccountService
import net.chrisrichardson.eventstore.examples.bank.web.util.WebUtil
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation._
import scala.concurrent.ExecutionContext.Implicits.global

View File

@@ -1,6 +1,3 @@
package net.chrisrichardson.eventstore.examples.bank.web.accounts.controllers
/**
* Created by cer on 7/16/14.
*/
case class CreateAccountRequest(initialBalance : BigDecimal)

View File

@@ -0,0 +1,10 @@
apply plugin: 'scala'
dependencies {
compile "org.scala-lang:scala-library:2.10.2"
compile project(":commandside-backend-transactions")
compile project(":web-common")
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
testCompile scalaTestDependency
}

View File

@@ -0,0 +1,11 @@
package net.chrisrichardson.eventstore.examples.bank.web.transactions
import net.chrisrichardson.eventstore.examples.bank.transactions.TransactionConfiguration
import org.springframework.context.annotation.{ComponentScan, Configuration, Import}
@Configuration
@Import(Array(classOf[TransactionConfiguration]))
@ComponentScan
class CommandSideWebTransactionsConfiguration {
}

View File

@@ -2,9 +2,9 @@ package net.chrisrichardson.eventstore.examples.bank.web.transactions.controller
import net.chrisrichardson.eventstore.EntityId
import net.chrisrichardson.eventstore.EventStore
import net.chrisrichardson.eventstore.examples.bank.accounts.Account
import net.chrisrichardson.eventstore.examples.bank.transactions.{TransferDetails, MoneyTransfer, MoneyTransferService}
import net.chrisrichardson.eventstore.examples.bank.web.accounts.controllers.{GetAccountResponse, WebUtil}
import net.chrisrichardson.eventstore.examples.bank.backend.common.transactions.TransferDetails
import net.chrisrichardson.eventstore.examples.bank.transactions.{MoneyTransferService, MoneyTransfer}
import net.chrisrichardson.eventstore.examples.bank.web.util.WebUtil
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation._

View File

@@ -0,0 +1,12 @@
apply plugin: 'scala'
dependencies {
compile "org.scala-lang:scala-library:2.10.2"
compile "net.chrisrichardson.eventstore.common:eventstore-common:$eventStoreCommonVersion"
testCompile scalaTestDependency
testCompile "junit:junit:4.11"
}

View File

@@ -1,7 +1,6 @@
package net.chrisrichardson.eventstore.examples.bank.accounts
package net.chrisrichardson.eventstore.examples.bank.backend.common.accounts
import net.chrisrichardson.eventstore.EntityId
import net.chrisrichardson.eventstore.Event
import net.chrisrichardson.eventstore.{EntityId, Event}
trait AccountChangedEvent extends Event {
val amount : BigDecimal

View File

@@ -1,2 +1,2 @@
@net.chrisrichardson.eventstore.EventEntity(entity="net.chrisrichardson.eventstore.examples.bank.accounts.Account")
package net.chrisrichardson.eventstore.examples.bank.accounts;
package net.chrisrichardson.eventstore.examples.bank.backend.common.accounts;

View File

@@ -1,6 +1,5 @@
package net.chrisrichardson.eventstore.examples.bank.transactions
package net.chrisrichardson.eventstore.examples.bank.backend.common.transactions
import net.chrisrichardson.eventstore.EntityId
import net.chrisrichardson.eventstore.Event
case class MoneyTransferCreatedEvent(details : TransferDetails) extends Event

View File

@@ -1,5 +1,6 @@
package net.chrisrichardson.eventstore.examples.bank.transactions
package net.chrisrichardson.eventstore.examples.bank.backend.common.transactions
import net.chrisrichardson.eventstore.EntityId
case class TransferDetails(fromAccountId : EntityId, toAccountId : EntityId, amount : BigDecimal)

View File

@@ -1,2 +1,2 @@
@net.chrisrichardson.eventstore.EventEntity(entity="net.chrisrichardson.eventstore.examples.bank.transactions.MoneyTransfer")
package net.chrisrichardson.eventstore.examples.bank.transactions;
package net.chrisrichardson.eventstore.examples.bank.backend.common.transactions;

View File

@@ -1,35 +0,0 @@
package net.chrisrichardson.eventstore.examples.customersandorders.customers
import net.chrisrichardson.eventstore.{PatternMatchingCommandProcessingAggregate, Command, CommandProcessingAggregate, Event}
import CustomerCommands._
case class Customer(customerId: String, creditLimit: BigDecimal)
extends PatternMatchingCommandProcessingAggregate[Customer, CustomerCommand] {
def this() = this(null, null)
override def processCommand = {
case CreateCustomer(customerId, creditLimit) => Seq(CustomerCreatedEvent(customerId, creditLimit))
case UpdateCreditLimit(newLimit) if newLimit >= 0 => Seq(CustomerCreditLimitUpdatedEvent(newLimit))
}
override def applyEvent = {
case CustomerCreatedEvent(customerId, creditLimit) => copy(customerId=customerId, creditLimit=creditLimit)
case CustomerCreditLimitUpdatedEvent(newLimit) => copy(creditLimit=newLimit)
}
}
object CustomerCommands {
trait CustomerCommand extends Command
case class CreateCustomer(customerId : String, creditLimit : BigDecimal) extends CustomerCommand
case class UpdateCreditLimit(newLimit: BigDecimal) extends CustomerCommand
}
case class CustomerCreatedEvent(customerId : String, creditLimit : BigDecimal) extends Event
case class CustomerCreditLimitUpdatedEvent(newLimit: BigDecimal) extends Event

View File

@@ -1,41 +0,0 @@
package net.chrisrichardson.eventstore.examples.customersandorders.orders
import net.chrisrichardson.eventstore.examples.customersandorders.orders.OrderCommands.OrderCommand
import net.chrisrichardson.eventstore.{PatternMatchingCommandProcessingAggregate, Command, CommandProcessingAggregate, Event}
case class Order(orderId: String, orderTotal: BigDecimal, state : OrderState)
extends PatternMatchingCommandProcessingAggregate[Order, OrderCommand] {
import OrderCommands._
def this() = this(null, null, null)
override def processCommand = {
case CreateOrder(orderId, orderTotal) => Seq(OrderCreatedEvent(orderId, orderTotal))
case PayForOrder(orderId) => Seq(OrderPaidEvent(orderId))
}
override def applyEvent = {
case OrderCreatedEvent(orderId, orderTotal) => copy(orderId=orderId, orderTotal=orderTotal, state=OPEN)
case OrderPaidEvent(orderId) => copy(orderId=orderId, orderTotal=orderTotal, state=PAID)
}
}
trait OrderState
object OPEN extends OrderState
object PAID extends OrderState
object OrderCommands {
trait OrderCommand extends Command
case class CreateOrder(orderId : String, orderTotal : BigDecimal) extends OrderCommand
case class PayForOrder(orderId : String) extends OrderCommand
}
case class OrderCreatedEvent(orderId : String, creditLimit : BigDecimal) extends Event
case class OrderPaidEvent(orderId : String) extends Event

View File

@@ -1,62 +0,0 @@
package net.chrisrichardson.eventstore.examples.customersandorders.orders
import net.chrisrichardson.eventstore.examples.customersandorders.orders.OrderCustomerCommands.OrderCustomerCommand
import net.chrisrichardson.eventstore.{PatternMatchingCommandProcessingAggregate, Command, CommandProcessingAggregate, Event}
case class OrderCustomer(customerId: String, creditLimit: BigDecimal,
openOrderTotal : BigDecimal,
openOrders : Set[String] = Set(),
paidOrders : Set[String] = Set())
extends PatternMatchingCommandProcessingAggregate[OrderCustomer, OrderCustomerCommand] {
import OrderCustomerCommands._
def this() = this(null, null, null)
override def processCommand = {
case CreateOrderCustomer(customerId, creditLimit) => Seq(OrderCustomerCreatedEvent(customerId, creditLimit))
case UpdateCreditLimit(newLimit) => Seq(OrderCustomerCreditLimitUpdatedEvent(newLimit))
case RecordNewOrder(orderId, orderTotal) if !openOrders.contains(orderId) && !paidOrders.contains(orderId) =>
Seq(NewOrderRecorded(orderId), OpenOrderTotalUpdated(openOrderTotal + orderTotal))
case _ : RecordNewOrder => Seq()
case RecordPaidOrder(orderId, orderTotal) if openOrders.contains(orderId) && !paidOrders.contains(orderId) =>
Seq(PaidOrderRecorded(orderId), OpenOrderTotalUpdated(openOrderTotal - orderTotal))
case _ : PaidOrderRecorded => Seq()
}
override def applyEvent = {
case OrderCustomerCreatedEvent(customerId, creditLimit) => copy(customerId=customerId, creditLimit=creditLimit, openOrderTotal=0)
case OrderCustomerCreditLimitUpdatedEvent(newLimit) => copy(creditLimit=newLimit)
case NewOrderRecorded(orderId) => copy(openOrders=openOrders + orderId)
case PaidOrderRecorded(orderId) => copy(paidOrders=paidOrders + orderId, openOrders=openOrders - orderId)
case OpenOrderTotalUpdated(orderTotal) => copy(openOrderTotal=orderTotal)
}
}
object OrderCustomerCommands {
trait OrderCustomerCommand extends Command
case class CreateOrderCustomer(customerId : String, creditLimit : BigDecimal) extends OrderCustomerCommand
case class UpdateCreditLimit(newLimit: BigDecimal) extends OrderCustomerCommand
case class RecordNewOrder(orderId : String, orderTotal : BigDecimal) extends OrderCustomerCommand
case class RecordPaidOrder(orderId : String, orderTotal : BigDecimal) extends OrderCustomerCommand
}
case class OrderCustomerCreatedEvent(customerId : String, creditLimit : BigDecimal) extends Event
case class OrderCustomerCreditLimitUpdatedEvent(newLimit: BigDecimal) extends Event
case class NewOrderRecorded(orderId : String) extends Event
case class PaidOrderRecorded(orderId : String) extends Event
case class OpenOrderTotalUpdated(orderTotal: BigDecimal) extends Event

Binary file not shown.

View File

@@ -0,0 +1,6 @@
#Sat Jan 03 13:06:18 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip

164
scala-spring/gradle/gradlew vendored Executable file
View File

@@ -0,0 +1,164 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

90
scala-spring/gradle/gradlew.bat vendored Normal file
View File

@@ -0,0 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@@ -1,6 +1,6 @@
#Wed Oct 29 07:09:05 PDT 2014
#Sat Jan 03 13:36:23 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.0-bin.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-2.0-all.zip

View File

@@ -1,13 +1,11 @@
apply plugin: 'scala'
apply plugin: 'spring-boot'
if (!hasProperty("eventstoreType")) {
ext.eventstoreType="jdbc"
}
dependencies {
compile "org.scala-lang:scala-library:2.10.2"
compile project(":eventstore-examples")
compile project(":commandside-web-accounts")
compile project(":commandside-web-transactions")
compile project(":queryside-web")
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-actuator"

View File

@@ -4,12 +4,16 @@ import net.chrisrichardson.eventstore.embedded.config.EmbeddedEventStoreConfigur
import net.chrisrichardson.eventstore.examples.bank.accounts.AccountConfiguration
import net.chrisrichardson.eventstore.examples.bank.queryside.QuerySideConfiguration
import net.chrisrichardson.eventstore.examples.bank.transactions.TransactionConfiguration
import net.chrisrichardson.eventstore.examples.bank.web.accounts.CommandSideWebAccountsConfiguration
import net.chrisrichardson.eventstore.examples.bank.web.queryside.QuerySideWebConfiguration
import net.chrisrichardson.eventstore.examples.bank.web.transactions.CommandSideWebTransactionsConfiguration
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.context.annotation._
@Configuration
@EnableAutoConfiguration
@Import(Array(classOf[AccountConfiguration], classOf[TransactionConfiguration], classOf[QuerySideConfiguration], classOf[EmbeddedEventStoreConfiguration]))
@Import(Array(classOf[CommandSideWebTransactionsConfiguration], classOf[CommandSideWebAccountsConfiguration], classOf[QuerySideWebConfiguration],
classOf[EmbeddedEventStoreConfiguration]))
@ComponentScan
class BankingWebAppConfiguration {

View File

@@ -1,6 +1,9 @@
apply plugin: 'scala'
dependencies {
compile project(":common-backend")
compile "org.scala-lang:scala-library:2.10.2"
compile "org.springframework.boot:spring-boot-starter-data-mongodb:$springBootVersion"

View File

@@ -3,10 +3,9 @@ package net.chrisrichardson.eventstore.examples.bank.queryside
import net.chrisrichardson.eventstore.EntityId
import net.chrisrichardson.eventstore.Event
import net.chrisrichardson.eventstore.Event.EventId
import net.chrisrichardson.eventstore.examples.bank.transactions.{MoneyTransferCreatedEvent, MoneyTransferCommands}
import MoneyTransferCommands.RecordCreditCommand
import net.chrisrichardson.eventstore.examples.bank.backend.common.transactions.MoneyTransferCreatedEvent
import net.chrisrichardson.eventstore.examples.bank._
import net.chrisrichardson.eventstore.examples.bank.accounts._
import net.chrisrichardson.eventstore.examples.bank.backend.common.accounts._
import net.chrisrichardson.eventstore.subscriptions.{EventSubscriber, DispatchedEvent, EventHandlerMethod, CompoundEventHandler}
import net.chrisrichardson.eventstore.util.ServiceUtil._
import net.chrisrichardson.utils.logging.Logging

View File

@@ -0,0 +1,16 @@
apply plugin: 'scala'
dependencies {
compile "org.scala-lang:scala-library:2.10.2"
compile project(":queryside-backend")
compile project(":web-common")
compile "org.springframework.boot:spring-boot-starter-actuator:$springBootVersion"
testCompile "org.springframework.boot:spring-boot-starter-test"
testCompile scalaTestDependency
}

View File

@@ -0,0 +1,11 @@
package net.chrisrichardson.eventstore.examples.bank.web.queryside
import net.chrisrichardson.eventstore.examples.bank.queryside.QuerySideConfiguration
import org.springframework.context.annotation._
@Configuration
@Import(Array(classOf[QuerySideConfiguration]))
@ComponentScan
class QuerySideWebConfiguration {
}

View File

@@ -1,12 +1,9 @@
package net.chrisrichardson.eventstore.examples.bank.web.queryside.controllers
import net.chrisrichardson.eventstore.EntityId
import net.chrisrichardson.eventstore.EventStore
import net.chrisrichardson.eventstore.examples.bank.accounts.{Account, AccountService}
import net.chrisrichardson.eventstore.examples.bank.queryside.AccountInfoQueryService
import net.chrisrichardson.eventstore.examples.bank.web.accounts.controllers.{GetAccountResponse, WebUtil}
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.{PathVariable, RequestMethod, RequestMapping, RestController}
import org.springframework.web.bind.annotation.{PathVariable, RequestMapping, RequestMethod, RestController}
@RestController
class AccountQuerySideController @Autowired() (accountInfoQueryService : AccountInfoQueryService) {

View File

@@ -1,2 +1,18 @@
include 'eventstore-examples'
include 'eventstore-examples-main'
include 'web-common'
include 'common-backend'
include 'commandside-backend-accounts'
include 'commandside-backend-transactions'
include 'commandside-web-accounts'
include 'commandside-web-transactions'
include 'queryside-backend'
include 'queryside-web'
include 'backend-integration-tests'
include 'monolithic-web'
rootProject.name = 'scala-spring-event-sourcing-example'

View File

@@ -0,0 +1,10 @@
apply plugin: 'scala'
dependencies {
compile "org.scala-lang:scala-library:2.10.2"
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
}

View File

@@ -1,13 +1,10 @@
package net.chrisrichardson.eventstore.examples.bank.web.accounts.controllers
package net.chrisrichardson.eventstore.examples.bank.web.util
import org.springframework.web.context.request.async.DeferredResult
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
/**
* Created by cer on 7/16/14.
*/
object WebUtil {
def toDeferredResult[T](future: Future[T]): DeferredResult[T] = {
val result = new DeferredResult[T]