我的任务是转换Flowable LDAP库的xml配置文件,并将其添加到已经存在的Java配置中,用于其他所有使用的文件。
我没有看到xml在转换为Java时如何适合现有的Java代码。我看过的所有示例似乎都是使用Spring LDAP进行的,这有点不同。
Flowable配置:
<bean id="processEngineConfiguration" class="...SomeProcessEngineConfigurationClass">
...
<property name="configurators">
<list>
<bean class="org.flowable.ldap.LDAPConfigurator">
<!-- Server connection params -->
<property name="server" value="ldap://localhost" />
<property name="port" value="33389" />
<property name="user" value="uid=admin, ou=users, o=flowable" />
<property name="password" value="pass" />
<!-- Query params -->
<property name="baseDn" value="o=flowable" />
<property name="queryUserByUserId" value="(&(objectClass=inetOrgPerson)(uid={0}))" />
<property name="queryUserByFullNameLike" value="(&(objectClass=inetOrgPerson)(|({0}=*{1}*)({2}=*{3}*)))" />
<property name="queryGroupsForUser" value="(&(objectClass=groupOfUniqueNames)(uniqueMember={0}))" />
<!-- Attribute config -->
<property name="userIdAttribute" value="uid" />
<property name="userFirstNameAttribute" value="cn" />
<property name="userLastNameAttribute" value="sn" />
<property name="userEmailAttribute" value="mail" />
<property name="groupIdAttribute" value="cn" />
<property name="groupNameAttribute" value="cn" />
</bean>
</list>
</property>
</bean>
Java Engine配置文件
@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = Array("com.name.product.engine.services"))
class FlowableEngineConfig {
@Bean
def processEngineConfiguration(env: Environment, dataSource: DataSource, transactionManager: PlatformTransactionManager, applicationContext: ApplicationContext): ProcessEngineConfiguration = {
val updateSchema = env.getProperty("conduct.engine.database.updateSchema", "true").trim.toLowerCase match {
case "update" | "true" =>
AbstractEngineConfiguration.DB_SCHEMA_UPDATE_TRUE
case "none" =>
null
case x =>
AbstractEngineConfiguration.DB_SCHEMA_UPDATE_FALSE
}
val engineConfig = new SpringProcessEngineConfiguration()
engineConfig.setDataSource(dataSource)
engineConfig.setTransactionManager(transactionManager)
engineConfig.setTransactionsExternallyManaged(true)
engineConfig.setDatabaseSchemaUpdate(updateSchema)
engineConfig.setAsyncExecutorActivate(true)
engineConfig.setAsyncExecutor(asyncExecutor())
engineConfig.setHistoryLevel(HistoryLevel.FULL)
// engineConfig.setCustomFormTypes(Seq[org.flowable.engine.form.AbstractFormType](
// ISODateFormType
// ).asJava)
engineConfig.setExpressionManager(new SpringExpressionManager(applicationContext, null))
engineConfig.setBeans(new SpringBeanFactoryProxyMap(applicationContext))
// Enable safe XML. See http://www.flowable.org/docs/userguide/index.html#advanced.safe.bpmn.xml
engineConfig.setEnableSafeBpmnXml(true)
engineConfig.setProcessDefinitionCacheLimit(128)
//engineConfig.setDisableIdmEngine(true)
engineConfig.addConfigurator(new SpringFormEngineConfigurator())
engineConfig.addConfigurator(new SpringDmnEngineConfigurator())
engineConfig
}
@Bean
def processEngine(engineConfig: ProcessEngineConfiguration): ProcessEngine = {
engineConfig.buildProcessEngine()
}
@Bean
def clock(engineConfig: ProcessEngineConfiguration): Clock = {
engineConfig.getClock
}
@Bean
def asyncExecutor(): AsyncExecutor = {
val asyncExecutor = new DefaultAsyncJobExecutor()
asyncExecutor.setDefaultAsyncJobAcquireWaitTimeInMillis(5000)
asyncExecutor.setDefaultTimerJobAcquireWaitTimeInMillis(5000)
asyncExecutor
}
@Bean
def dataSource(env: Environment): DataSource = {
val hconf = new HikariConfig()
env.getRequiredProperty("conductor.engine.database.platform").trim.toLowerCase() match {
case "postgresql" =>
hconf.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource")
hconf.addDataSourceProperty("serverName", env.getRequiredProperty("conduct.engine.database.hostname"))
hconf.addDataSourceProperty("portNumber", env.getRequiredProperty("conduct.engine.database.port", classOf[Int]))
hconf.addDataSourceProperty("databaseName", env.getRequiredProperty("conduct.engine.database.name"))
hconf.addDataSourceProperty("applicationName", "conduct")
case "h2" =>
hconf.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource")
val dbName = env.getRequiredProperty("conduct.engine.database.name")
hconf.addDataSourceProperty("URL", s"jdbc:h2:file:./$dbName")
case "h2mem" =>
hconf.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource")
val dbName = env.getRequiredProperty("conduct.engine.database.name")
hconf.addDataSourceProperty("URL", s"jdbc:h2:mem:$dbName")
case x =>
throw new RuntimeException(s"Unknown database platform $x")
}
hconf.setUsername(env.getRequiredProperty("conduct.engine.database.username"))
hconf.setPassword(env.getRequiredProperty("conduct.engine.database.password"))
hconf.setMinimumIdle(env.getRequiredProperty("conduct.engine.database.minConnections", classOf[Int]))
hconf.setMaximumPoolSize(env.getRequiredProperty("conduct.engine.database.maxConnections", classOf[Int]))
hconf.setInitializationFailFast(env.getRequiredProperty("conduct.engine.database.initializationFailFast", classOf[Boolean]))
hconf.setTransactionIsolation("TRANSACTION_READ_COMMITTED")
new HikariDataSource(hconf)
}