package top.quantic.sentry.config;

import org.quartz.spi.JobFactory;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import top.quantic.sentry.config.scheduler.AutowiringSpringBeanJobFactory;

import java.io.IOException;
import java.util.Properties;

@Configuration
@AutoConfigureAfter(DatabaseConfiguration.class)
public class SchedulerConfiguration {

    @Bean
    public JobFactory jobFactory(ApplicationContext applicationContext)    {
        AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
        jobFactory.setApplicationContext(applicationContext);
        return jobFactory;
    }

    @Bean
    public SchedulerFactoryBean schedulerFactory(JobFactory jobFactory) throws IOException {
        SchedulerFactoryBean factory = new SchedulerFactoryBean();
        factory.setSchedulerName("Sentry");
        factory.setJobFactory(jobFactory);
        factory.setQuartzProperties(quartzProperties());
        // this allows to update triggers in DB when updating settings in config file:
        factory.setOverwriteExistingJobs(true);
        return factory;
    }

    @Bean
    public Properties quartzProperties() throws IOException {
        PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
        propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
        propertiesFactoryBean.afterPropertiesSet();
        return propertiesFactoryBean.getObject();
    }
}

@@ -403,25 +403,26 @@
 core.io.
-ClassPath
+FileSystem
 Resource
@@ -1680,22 +1680,24 @@
 tion
+s
 (new 
-ClassPath
+FileSystem
 Reso
@@ -1702,17 +1702,16 @@
 source(%22
-/
 quartz.p

Use quartz.properties from filesystem