Search in sources :

Example 26 with SimpleJobTrigger

use of org.pentaho.platform.api.scheduler2.SimpleJobTrigger in project pentaho-platform by pentaho.

the class SimpleTriggerTest method defaultValidTest.

@Test
public void defaultValidTest() {
    SimpleJobTrigger trigger = new SimpleJobTrigger();
    Assert.assertNull(trigger.getStartTime());
    Assert.assertNull(trigger.getEndTime());
    Assert.assertFalse(trigger.getRepeatCount() != 0 && trigger.getRepeatInterval() < 1);
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Test(org.junit.Test)

Example 27 with SimpleJobTrigger

use of org.pentaho.platform.api.scheduler2.SimpleJobTrigger in project pentaho-platform by pentaho.

the class ComplianceJaxBTest method testSimpleTrigger.

@Test
public void testSimpleTrigger() throws JAXBException {
    SimpleJobTrigger orig = new SimpleJobTrigger();
    Date STARTTIME = new Date();
    orig.setStartTime(STARTTIME);
    SimpleJobTrigger unmarshalled = JaxBUtil.outin(orig, SimpleJobTrigger.class);
    Assert.assertEquals(orig.getStartTime(), unmarshalled.getStartTime());
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Date(java.util.Date) Test(org.junit.Test)

Example 28 with SimpleJobTrigger

use of org.pentaho.platform.api.scheduler2.SimpleJobTrigger in project pentaho-platform by pentaho.

the class EmbeddedVersionCheckSystemListener method scheduleJob.

protected void scheduleJob(final int versionRequestFlags, final int repeatSeconds) throws Exception {
    // $NON-NLS-1$
    IScheduler scheduler = PentahoSystem.get(IScheduler.class, "IScheduler2", null);
    deleteJobIfNecessary();
    Map<String, Serializable> parms = new HashMap<String, Serializable>();
    parms.put(VersionCheckerAction.VERSION_REQUEST_FLAGS, new Integer(versionRequestFlags));
    JobTrigger trigger = new SimpleJobTrigger(new Date(), null, -1, repeatSeconds);
    scheduler.createJob(EmbeddedVersionCheckSystemListener.VERSION_CHECK_JOBNAME, VersionCheckerAction.class, parms, trigger);
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Serializable(java.io.Serializable) HashMap(java.util.HashMap) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) JobTrigger(org.pentaho.platform.api.scheduler2.JobTrigger) Date(java.util.Date)

Example 29 with SimpleJobTrigger

use of org.pentaho.platform.api.scheduler2.SimpleJobTrigger in project pentaho-platform by pentaho.

the class SchedulerResourceUtil method convertScheduleRequestToJobTrigger.

public static IJobTrigger convertScheduleRequestToJobTrigger(JobScheduleRequest scheduleRequest, IScheduler scheduler) throws SchedulerException, UnifiedRepositoryException {
    // Used to determine if created by a RunInBackgroundCommand
    boolean runInBackground = scheduleRequest.getSimpleJobTrigger() == null && scheduleRequest.getComplexJobTrigger() == null && scheduleRequest.getCronJobTrigger() == null;
    // add 10 seconds to the RIB to ensure execution (see PPP-3264)
    IJobTrigger jobTrigger = runInBackground ? new SimpleJobTrigger(new Date(System.currentTimeMillis() + 10000), null, 0, 0) : scheduleRequest.getSimpleJobTrigger();
    if (scheduleRequest.getSimpleJobTrigger() != null) {
        SimpleJobTrigger simpleJobTrigger = scheduleRequest.getSimpleJobTrigger();
        if (simpleJobTrigger.getStartTime() == null) {
            simpleJobTrigger.setStartTime(new Date());
        }
        jobTrigger = simpleJobTrigger;
    } else if (scheduleRequest.getComplexJobTrigger() != null) {
        ComplexJobTriggerProxy proxyTrigger = scheduleRequest.getComplexJobTrigger();
        ComplexJobTrigger complexJobTrigger = new ComplexJobTrigger();
        complexJobTrigger.setStartTime(proxyTrigger.getStartTime());
        complexJobTrigger.setEndTime(proxyTrigger.getEndTime());
        complexJobTrigger.setDuration(scheduleRequest.getDuration());
        if (proxyTrigger.getDaysOfWeek().length > 0) {
            if (proxyTrigger.getWeeksOfMonth().length > 0) {
                for (int dayOfWeek : proxyTrigger.getDaysOfWeek()) {
                    for (int weekOfMonth : proxyTrigger.getWeeksOfMonth()) {
                        QualifiedDayOfWeek qualifiedDayOfWeek = new QualifiedDayOfWeek();
                        qualifiedDayOfWeek.setDayOfWeek(DayOfWeek.values()[dayOfWeek]);
                        if (weekOfMonth == JobScheduleRequest.LAST_WEEK_OF_MONTH) {
                            qualifiedDayOfWeek.setQualifier(DayOfWeekQualifier.LAST);
                        } else {
                            qualifiedDayOfWeek.setQualifier(DayOfWeekQualifier.values()[weekOfMonth]);
                        }
                        complexJobTrigger.addDayOfWeekRecurrence(qualifiedDayOfWeek);
                    }
                }
            } else {
                for (int dayOfWeek : proxyTrigger.getDaysOfWeek()) {
                    complexJobTrigger.addDayOfWeekRecurrence(dayOfWeek + 1);
                }
            }
        } else if (proxyTrigger.getDaysOfMonth().length > 0) {
            for (int dayOfMonth : proxyTrigger.getDaysOfMonth()) {
                complexJobTrigger.addDayOfMonthRecurrence(dayOfMonth);
            }
        }
        for (int month : proxyTrigger.getMonthsOfYear()) {
            complexJobTrigger.addMonthlyRecurrence(month + 1);
        }
        for (int year : proxyTrigger.getYears()) {
            complexJobTrigger.addYearlyRecurrence(year);
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(complexJobTrigger.getStartTime());
        complexJobTrigger.setHourlyRecurrence(calendar.get(Calendar.HOUR_OF_DAY));
        complexJobTrigger.setMinuteRecurrence(calendar.get(Calendar.MINUTE));
        complexJobTrigger.setUiPassParam(scheduleRequest.getComplexJobTrigger().getUiPassParam());
        jobTrigger = complexJobTrigger;
    } else if (scheduleRequest.getCronJobTrigger() != null) {
        if (scheduler instanceof QuartzScheduler) {
            String cronString = scheduleRequest.getCronJobTrigger().getCronString();
            // $NON-NLS-1$
            String delims = "[ ]+";
            String[] tokens = cronString.split(delims);
            if (tokens.length < 7) {
                cronString += " *";
            }
            ComplexJobTrigger complexJobTrigger = QuartzScheduler.createComplexTrigger(cronString);
            complexJobTrigger.setStartTime(scheduleRequest.getCronJobTrigger().getStartTime());
            complexJobTrigger.setEndTime(scheduleRequest.getCronJobTrigger().getEndTime());
            complexJobTrigger.setDuration(scheduleRequest.getCronJobTrigger().getDuration());
            complexJobTrigger.setUiPassParam(scheduleRequest.getCronJobTrigger().getUiPassParam());
            jobTrigger = complexJobTrigger;
        } else {
            throw new IllegalArgumentException();
        }
    }
    return jobTrigger;
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) QuartzScheduler(org.pentaho.platform.scheduler2.quartz.QuartzScheduler) Date(java.util.Date) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) QualifiedDayOfWeek(org.pentaho.platform.scheduler2.recur.QualifiedDayOfWeek) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger)

Aggregations

SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)29 Test (org.junit.Test)23 Date (java.util.Date)14 Job (org.pentaho.platform.api.scheduler2.Job)14 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)12 Serializable (java.io.Serializable)10 Calendar (java.util.Calendar)7 HashMap (java.util.HashMap)7 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)7 JobScheduleRequest (org.pentaho.platform.web.http.api.resources.JobScheduleRequest)6 GregorianCalendar (java.util.GregorianCalendar)4 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)3 IBackgroundExecutionStreamProvider (org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider)3 IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)3 JobScheduleParam (org.pentaho.platform.web.http.api.resources.JobScheduleParam)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Matchers.anyString (org.mockito.Matchers.anyString)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)2