s2.spring.automate.ssm.S2SsmConfigurerAdapter.kt Maven / Gradle / Ivy
package s2.spring.automate.ssm
import com.fasterxml.jackson.databind.ObjectMapper
import f2.dsl.fnc.invoke
import kotlinx.coroutines.runBlocking
import org.springframework.beans.factory.annotation.Autowired
import s2.automate.core.persist.AutomatePersister
import s2.dsl.automate.Evt
import s2.dsl.automate.S2Automate
import s2.dsl.automate.S2State
import s2.dsl.automate.model.WithS2Id
import s2.dsl.automate.model.WithS2State
import s2.dsl.automate.ssm.toSsm
import s2.spring.automate.S2ConfigurerAdapter
import s2.spring.automate.executor.S2AutomateExecutorSpring
import s2.spring.automate.ssm.persister.SsmAutomatePersister
import ssm.chaincode.dsl.model.Agent
import ssm.chaincode.dsl.model.uri.ChaincodeUri
import ssm.data.dsl.features.query.DataSsmSessionGetQueryFunction
import ssm.tx.dsl.features.ssm.SsmInitCommand
import ssm.tx.dsl.features.ssm.SsmTxInitFunction
import ssm.tx.dsl.features.ssm.SsmTxSessionPerformActionFunction
import ssm.tx.dsl.features.ssm.SsmTxSessionStartFunction
abstract class S2SsmConfigurerAdapter :
S2ConfigurerAdapter() where
STATE : S2State,
ENTITY : WithS2State,
ENTITY : WithS2Id,
AGGREGATE : S2AutomateExecutorSpring {
@Autowired
lateinit var ssmTxInitFunction: SsmTxInitFunction
@Autowired
lateinit var ssmSessionStartFunction: SsmTxSessionStartFunction
@Autowired
lateinit var ssmSessionPerformActionFunction: SsmTxSessionPerformActionFunction
@Autowired
lateinit var dataSsmSessionGetQueryFunction: DataSsmSessionGetQueryFunction
@Autowired
lateinit var objectMapper: ObjectMapper
// @Bean
override fun aggregateRepository(): AutomatePersister = runBlocking {
val automate = automate()
val signer = signerAgent()
val chaincodeUri = chaincodeUri()
SsmAutomatePersister().also {
it.ssmSessionStartFunction = ssmSessionStartFunction
it.ssmSessionPerformActionFunction = ssmSessionPerformActionFunction
it.objectMapper = objectMapper
it.dataSsmSessionGetQueryFunction = dataSsmSessionGetQueryFunction
it.entityType = entityType()
it.chaincodeUri = chaincodeUri
it.agentSigner = signer
it.permisive = permisive
}.also {
ssmTxInitFunction.invoke(
SsmInitCommand(
signerName = signer.name,
ssm = automate.toSsm(permisive),
agent = signer,
chaincodeUri = chaincodeUri
)
)
}
}
abstract fun entityType(): Class
abstract fun chaincodeUri(): ChaincodeUri
abstract fun signerAgent(): Agent
open var permisive = false
}