package applets.etsmtl.ca;


import applets.etsmtl.ca.news.jobs.EventsJob;
import applets.etsmtl.ca.news.jobs.SourcesJob;
import com.sun.jersey.api.model.AbstractResourceModelContext;
import com.sun.jersey.api.model.AbstractResourceModelListener;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import javax.ws.rs.ext.Provider;

/**
 * Created by gnut3ll4 on 24/01/16.
 */
@Provider
public class StartupListener implements AbstractResourceModelListener {

    @Override
    public void onLoaded(AbstractResourceModelContext modelContext) {
        System.out.println("STARTUP");

        JobDetail sources_job = JobBuilder.newJob(SourcesJob.class)
                .withIdentity("sourcesjob", "group1").build();

        JobDetail events_job = JobBuilder.newJob(EventsJob.class)
                .withIdentity("eventsjob", "group2").build();

        Trigger trigger_sources = TriggerBuilder
                .newTrigger()
                .withIdentity("triggersources", "group1")
                .withSchedule(
                        SimpleScheduleBuilder.simpleSchedule()
                                .withIntervalInSeconds(25).repeatForever())
                .build();

        Trigger trigger_events = TriggerBuilder
                .newTrigger()
                .withIdentity("triggerevents", "group2")
                .withSchedule(
                        SimpleScheduleBuilder.simpleSchedule()
                                .withIntervalInSeconds(450).repeatForever())
                .build();


        /*
        //For a more cron-like syntax
        Trigger trigger = TriggerBuilder
                .newTrigger()
                .withIdentity("dummyTriggerName", "group1")
                .withSchedule(
                        CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
                .build();
        */

        try {
            // schedule it
            Scheduler scheduler = new StdSchedulerFactory().getScheduler();
            scheduler.start();
            //scheduler.scheduleJob(sources_job, trigger_sources);
            scheduler.scheduleJob(events_job, trigger_events);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }


    }
}
@@ -64,24 +64,68 @@
 .EventsJob;%0A
+import applets.etsmtl.ca.news.jobs.NewsJob;%0A
 import apple
@@ -155,24 +155,24 @@
 SourcesJob;%0A
-
 import com.s
@@ -888,32 +888,155 @@
 up2%22).build();%0A%0A
+        JobDetail news_job = JobBuilder.newJob(NewsJob.class)%0A                .withIdentity(%22newsjob%22, %22group3%22).build();%0A%0A
         Trigger 
@@ -1309,10 +1309,12 @@
 nds(
-2
 5
+000
 ).re
@@ -1643,10 +1643,341 @@
 nds(
-45
+2500).repeatForever())%0A                .build();%0A%0A        Trigger trigger_news = TriggerBuilder%0A                .newTrigger()%0A                .withIdentity(%22triggernews%22, %22group3%22)%0A                .withSchedule(%0A                        SimpleScheduleBuilder.simpleSchedule()%0A                                .withIntervalInSeconds(250
 0).r
@@ -2504,18 +2504,16 @@
         
-//
 schedule
@@ -2616,24 +2616,83 @@
 er_events);%0A
+            scheduler.scheduleJob(news_job, trigger_news);%0A
         %7D ca

Enable start for event, source, news job