2018-05-03 14:07:02 +03:00
|
|
|
import com.devsoap.dbt.DBTModule
|
2018-02-25 07:43:48 +02:00
|
|
|
import com.devsoap.dbt.app.DatabaseService
|
|
|
|
|
import com.devsoap.dbt.config.DBTConfig
|
|
|
|
|
import com.devsoap.dbt.handlers.ExecutorHandler
|
2018-05-03 14:07:02 +03:00
|
|
|
|
|
|
|
|
import com.devsoap.dbt.services.TransactionManagerService
|
2018-02-25 07:43:48 +02:00
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper
|
|
|
|
|
import org.h2.jdbcx.JdbcDataSource
|
2018-05-03 14:07:02 +03:00
|
|
|
import ratpack.config.ConfigData
|
|
|
|
|
import ratpack.session.SessionModule
|
2018-02-25 07:43:48 +02:00
|
|
|
|
|
|
|
|
import javax.sql.DataSource
|
|
|
|
|
|
|
|
|
|
import static ratpack.groovy.Groovy.ratpack
|
|
|
|
|
|
|
|
|
|
ratpack {
|
|
|
|
|
|
|
|
|
|
serverConfig {
|
2018-05-03 14:07:02 +03:00
|
|
|
sysProps()
|
|
|
|
|
require('/dbt', DBTConfig)
|
2018-02-25 07:43:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bindings {
|
|
|
|
|
|
2018-05-03 14:07:02 +03:00
|
|
|
module SessionModule
|
|
|
|
|
module (DBTModule) {
|
|
|
|
|
it.ledger.remoteUrl = 'http://localhost:5050/ledger'
|
|
|
|
|
it.executor.remoteUrl = 'http://localhost:5050/executor'
|
|
|
|
|
}
|
2018-02-25 07:43:48 +02:00
|
|
|
|
2018-05-03 14:07:02 +03:00
|
|
|
bindInstance(DataSource, new JdbcDataSource(url: 'jdbc:h2:mem:dbtdb;DB_CLOSE_DELAY=-1', user: ''))
|
|
|
|
|
bind DatabaseService
|
2018-02-25 07:43:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handlers {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Consumer services
|
|
|
|
|
*/
|
|
|
|
|
get('frontend') {
|
2018-05-03 14:07:02 +03:00
|
|
|
get(TransactionManagerService).execute { transaction ->
|
2018-02-25 07:43:48 +02:00
|
|
|
transaction.query("INSERT INTO LOGS(LOG_ID,LOG_VALUE) VALUES (${new Random().nextInt()}, 'HELLO')")
|
|
|
|
|
}.then {
|
|
|
|
|
redirect("/gateway/${it['id'].textValue()}")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get('gateway/:transactionId?') {
|
2018-05-03 14:07:02 +03:00
|
|
|
get(TransactionManagerService).execute(pathTokens.transactionId, { transaction ->
|
2018-02-25 07:43:48 +02:00
|
|
|
transaction.query("INSERT INTO LOGS(LOG_ID,LOG_VALUE) VALUES (${new Random().nextInt()}, 'WORLD')")
|
|
|
|
|
}).then {
|
|
|
|
|
redirect("/gateway2/${it['id'].textValue()}")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get('gateway2/:transactionId?') {
|
2018-05-03 14:07:02 +03:00
|
|
|
get(TransactionManagerService).execute(pathTokens.transactionId, { transaction ->
|
2018-02-25 07:43:48 +02:00
|
|
|
transaction.query("SELECT * FROM LOGS")
|
|
|
|
|
transaction.complete()
|
|
|
|
|
}).then {
|
|
|
|
|
render it.toString()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|