package org.camunda.bpm.spring.boot.starter;

import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.camunda.bpm.engine.impl.interceptor.CommandExecutor;
import org.camunda.bpm.engine.spring.ProcessEngineFactoryBean;
import org.camunda.bpm.engine.spring.SpringProcessEngineServicesConfiguration;
import org.camunda.bpm.spring.boot.starter.event.ProcessApplicationEventPublisher;
import org.camunda.bpm.spring.boot.starter.property.CamundaBpmProperties;
import org.camunda.bpm.spring.boot.starter.property.ManagementProperties;
import org.camunda.bpm.spring.boot.starter.util.CamundaBpmVersion;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;

@EnableConfigurationProperties({
  CamundaBpmProperties.class,
  ManagementProperties.class
})
@Import({
  CamundaBpmConfiguration.class,
  CamundaBpmActuatorConfiguration.class,
  CamundaBpmPluginConfiguration.class,
  SpringProcessEngineServicesConfiguration.class
})
@AutoConfigureAfter(HibernateJpaAutoConfiguration.class)
public class CamundaBpmAutoConfiguration {

  @Bean
  public ProcessEngineFactoryBean processEngineFactoryBean(final ProcessEngineConfigurationImpl processEngineConfigurationImpl) {
    final ProcessEngineFactoryBean factoryBean = new ProcessEngineFactoryBean();
    factoryBean.setProcessEngineConfiguration(processEngineConfigurationImpl);

    return factoryBean;
  }

  @Bean
  public CamundaBpmVersion camundaBpmVersion() {
    return new CamundaBpmVersion();
  }

  @Bean
  @Primary
  public CommandExecutor commandExecutorTxRequired(final ProcessEngineConfigurationImpl processEngineConfiguration) {
    return processEngineConfiguration.getCommandExecutorTxRequired();
  }

  @Bean
  public CommandExecutor commandExecutorTxRequiresNew(final ProcessEngineConfigurationImpl processEngineConfiguration) {
    return processEngineConfiguration.getCommandExecutorTxRequiresNew();
  }

  @Bean
  public CommandExecutor commandExecutorSchemaOperations(final ProcessEngineConfigurationImpl processEngineConfiguration) {
    return processEngineConfiguration.getCommandExecutorSchemaOperations();
  }

  @Bean
  public ProcessApplicationEventPublisher processApplicationEventPublisher(ApplicationEventPublisher publisher) {
    return new ProcessApplicationEventPublisher(publisher);
  }

}

@@ -610,24 +610,87 @@
 BpmVersion;%0A
+import org.springframework.beans.factory.annotation.Autowired;%0A
 import org.s
@@ -1020,24 +1020,85 @@
 ation.Bean;%0A
+import org.springframework.context.annotation.Configuration;%0A
 import org.s
@@ -1228,16 +1228,18 @@
 rties(%7B%0A
+  
   Camund
@@ -1260,16 +1260,18 @@
 .class,%0A
+  
   Manage
@@ -1306,16 +1306,18 @@
 ort(%7B%0A  
+  
 CamundaB
@@ -1331,32 +1331,34 @@
 guration.class,%0A
+  
   CamundaBpmActu
@@ -1382,16 +1382,18 @@
 .class,%0A
+  
   Camund
@@ -1423,16 +1423,18 @@
 .class,%0A
+  
   Spring
@@ -1585,79 +1585,147 @@
 %0A  @
-Bean%0A  public ProcessEngineFactoryBean processEngineFactoryBean(final P
+Configuration%0A  class ProcessEngineConfigurationImplDependingConfiguration %7B%0A%0A    @Autowired%0A    protected ProcessEngineConfigurationImpl p
 roce
@@ -1753,43 +1753,88 @@
 Impl
- processEngineConfigurationImpl
+;%0A%0A    @Bean%0A    public ProcessEngineFactoryBean processEngineFactoryBean(
 ) %7B%0A
+  
     
@@ -1914,16 +1914,18 @@
 ();%0A    
+  
 factoryB
@@ -1992,24 +1992,26 @@
 Impl);%0A%0A    
+  
 return facto
@@ -2024,117 +2024,23 @@
 ;%0A  
-%7D%0A%0A  @Bean%0A  public CamundaBpmVersion camundaBpmVersion() %7B%0A    return new CamundaBpmVersion();%0A
   %7D%0A%0A
+  
   @Bean%0A
   @P
@@ -2035,16 +2035,18 @@
   @Bean%0A
+  
   @Prima
@@ -2048,16 +2048,18 @@
 Primary%0A
+  
   public
@@ -2105,75 +2105,14 @@
 red(
-final ProcessEngineConfigurationImpl processEngineConfiguration
 ) %7B%0A
+  
     
@@ -2136,32 +2136,36 @@
 ineConfiguration
+Impl
 .getCommandExecu
@@ -2177,37 +2177,43 @@
 Required();%0A
+  
   %7D%0A%0A  
+  
 @Bean%0A
+  
   public Com
@@ -2258,75 +2258,14 @@
 New(
-final ProcessEngineConfigurationImpl processEngineConfiguration
 ) %7B%0A
+  
     
@@ -2289,32 +2289,36 @@
 ineConfiguration
+Impl
 .getCommandExecu
@@ -2333,37 +2333,41 @@
 uiresNew();%0A
+  
   %7D%0A%0A
+  
   @Bean%0A
   public Com
@@ -2346,32 +2346,34 @@
    %7D%0A%0A    @Bean%0A
+  
   public Command
@@ -2413,23 +2413,34 @@
 rations(
-final P
+) %7B%0A      return p
 rocessEn
@@ -2464,111 +2464,147 @@
 Impl
- processEngineConfiguration) %7B%0A    return processEngineConfiguration.getCommandExecutorSchemaOperat
+.getCommandExecutorSchemaOperations();%0A    %7D%0A  %7D%0A%0A  @Bean%0A  public CamundaBpmVersion camundaBpmVersion() %7B%0A    return new CamundaBpmVers
 ion
-s
 ();%0A

resolve possible cycles