package com.blossomproject.autoconfigure.core;

import com.blossomproject.core.scheduler.history.TriggerHistoryDao;
import com.blossomproject.core.scheduler.history.TriggerHistoryDaoImpl;
import com.blossomproject.core.scheduler.job.ScheduledJobService;
import com.blossomproject.core.scheduler.job.ScheduledJobServiceImpl;
import com.blossomproject.core.scheduler.listener.GlobalTriggerListener;
import org.quartz.Scheduler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * Created by Maël Gargadennnec on 04/05/2017.
 */
@Configuration
public class SchedulerAutoConfiguration {

  @Bean
  public TriggerHistoryDao triggerHistoryDao(JdbcTemplate jdbcTemplate) {
    return new TriggerHistoryDaoImpl(jdbcTemplate, 10);
  }

  @Bean
  public GlobalTriggerListener globalTriggerListener(TriggerHistoryDao triggerHistoryDao) {
    return new GlobalTriggerListener(triggerHistoryDao);
  }

  @Bean
  public ScheduledJobService scheduledJobService(Scheduler scheduler,
    TriggerHistoryDao triggerHistoryDao) {
    return new ScheduledJobServiceImpl(scheduler, triggerHistoryDao);
  }

}

@@ -415,24 +415,320 @@
 .Scheduler;%0A
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;%0Aimport org.springframework.boot.autoconfigure.AutoConfigureBefore;%0Aimport org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration;%0Aimport org.springframework.boot.autoconfigure.quartz.SchedulerFactoryBeanCustomizer;%0A
 import org.s
@@ -878,16 +878,83 @@
 emplate;
+%0Aimport org.springframework.scheduling.quartz.SchedulerFactoryBean;
 %0A%0A/**%0A *
@@ -1061,19 +1061,157 @@
 ion 
+ 
 %7B%0A%0A  @
-Bean%0A
+Configuration%0A  @AutoConfigureBefore(QuartzAutoConfiguration.class)%0A  public static class GlobalListenerQuartzAutoConfiguration %7B%0A    @Bean%0A  
   pu
@@ -1276,32 +1276,34 @@
 Template) %7B%0A    
+  
 return new Trigg
@@ -1338,21 +1338,25 @@
 e, 10);%0A
+  
   %7D%0A%0A
+  
   @Bean%0A
@@ -1353,24 +1353,26 @@
     @Bean%0A  
+ 
+ 
 public Globa
@@ -1445,32 +1445,34 @@
 storyDao) %7B%0A    
+  
 return new Globa
@@ -1514,19 +1514,736 @@
 ;%0A  
-%7D%0A%0A  @Bean%0A
+  %7D%0A%0A  %7D%0A%0A  @Configuration%0A  @AutoConfigureAfter(GlobalListenerQuartzAutoConfiguration.class)%0A  public static class CustomizerQuartzAutoConfiguration implements SchedulerFactoryBeanCustomizer%7B%0A    private final GlobalTriggerListener globalTriggerListener;%0A%0A    public CustomizerQuartzAutoConfiguration(GlobalTriggerListener globalTriggerListener) %7B%0A      this.globalTriggerListener = globalTriggerListener;%0A    %7D%0A%0A    @Override%0A    public void customize(SchedulerFactoryBean schedulerFactoryBean) %7B%0A      schedulerFactoryBean.setGlobalTriggerListeners(globalTriggerListener);%0A    %7D%0A  %7D%0A%0A%0A  @Configuration%0A  @AutoConfigureAfter(QuartzAutoConfiguration.class)%0A  public static class JobServiceQuartzAutoConfiguration %7B%0A    @Bean%0A  
   pu
@@ -2307,20 +2307,16 @@
 heduler,
-%0A   
  Trigger
@@ -2343,24 +2343,26 @@
 storyDao) %7B%0A
+  
     return n
@@ -2419,15 +2419,21 @@
 ryDao);%0A
+    %7D%0A
   %7D%0A%0A%7D%0A

Customize SchedulerFactoryBean to add custom TriggerListener