SchedulerResourceUtil { public static IJobTrigger convertScheduleRequestToJobTrigger( JobScheduleRequest scheduleRequest, IScheduler scheduler ) throws SchedulerException, UnifiedRepositoryException { boolean runInBackground = scheduleRequest.getSimpleJobTrigger() == null && scheduleRequest.getComplexJobTrigger() == null && scheduleRequest.getCronJobTrigger() == null; 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(); 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; }  static IJobTrigger convertScheduleRequestToJobTrigger( JobScheduleRequest scheduleRequest,
                                                                IScheduler scheduler ); static void updateStartDateForTimeZone( JobScheduleRequest request ); static Date convertDateToServerTimeZone( Date dateTime, String timeZone ); static HashMap<String, Serializable> handlePDIScheduling( RepositoryFile file,
                                                                   HashMap<String, Serializable> parameterMap, Map<String, String> pdiParameters ); static boolean isPdiFile( RepositoryFile file ); static boolean isTransformation( RepositoryFile file ); static boolean isJob( RepositoryFile file ); static String resolveActionId( final String inputFile ); static String getExtension( final String filename ); static final String RESERVEDMAPKEY_LINEAGE_ID; static final String RESERVED_BACKGROUND_EXECUTION_ACTION_ID; }
@Test public void testConvertScheduleRequestToJobTrigger_SimpleJobTrigger() throws Exception { IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger( scheduleRequest, scheduler ); assertNotNull( trigger ); assertTrue( trigger instanceof SimpleJobTrigger ); assertTrue( trigger.getStartTime().getTime() > System.currentTimeMillis() ); }
@Test public void testConvertScheduleRequestToJobTrigger_SimpleJobTrigger_basedOnExisting() throws Exception { when( scheduleRequest.getSimpleJobTrigger() ).thenReturn( simple ); IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger( scheduleRequest, scheduler ); assertNotNull( trigger ); assertEquals( simple, trigger ); verify( simple ).setStartTime( any( Date.class ) ); }
@Test public void testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_daysOfMonth() throws Exception { complex.setDaysOfMonth( new int[] { 1, 25 } ); when( scheduleRequest.getComplexJobTrigger() ).thenReturn( complex ); IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger( scheduleRequest, scheduler ); assertNotNull( trigger ); assertTrue( trigger instanceof ComplexJobTrigger ); ComplexJobTrigger trig = (ComplexJobTrigger) trigger; List<ITimeRecurrence> recurrences = trig.getDayOfMonthRecurrences().getRecurrences(); assertEquals( 2, recurrences.size() ); RecurrenceList rec = (RecurrenceList) recurrences.get( 0 ); assertEquals( 1, rec.getValues().get( 0 ).intValue() ); rec = (RecurrenceList) recurrences.get( 1 ); assertEquals( 25, rec.getValues().get( 0 ).intValue() ); }
@Test public void testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_monthsOfYear() throws Exception { complex.setMonthsOfYear( new int[] { 1, 8 } ); when( scheduleRequest.getComplexJobTrigger() ).thenReturn( complex ); IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger( scheduleRequest, scheduler ); assertNotNull( trigger ); assertTrue( trigger instanceof ComplexJobTrigger ); ComplexJobTrigger trig = (ComplexJobTrigger) trigger; List<ITimeRecurrence> recurrences = trig.getMonthlyRecurrences().getRecurrences(); assertEquals( 2, recurrences.size() ); RecurrenceList rec = (RecurrenceList) recurrences.get( 0 ); assertEquals( 2, rec.getValues().get( 0 ).intValue() ); rec = (RecurrenceList) recurrences.get( 1 ); assertEquals( 9, rec.getValues().get( 0 ).intValue() ); }
@Test public void testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_years() throws Exception { complex.setYears( new int[] { 2016, 2020 } ); when( scheduleRequest.getComplexJobTrigger() ).thenReturn( complex ); IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger( scheduleRequest, scheduler ); assertNotNull( trigger ); assertTrue( trigger instanceof ComplexJobTrigger ); ComplexJobTrigger trig = (ComplexJobTrigger) trigger; List<ITimeRecurrence> recurrences = trig.getYearlyRecurrences().getRecurrences(); assertEquals( 2, recurrences.size() ); RecurrenceList rec = (RecurrenceList) recurrences.get( 0 ); assertEquals( 2016, rec.getValues().get( 0 ).intValue() ); rec = (RecurrenceList) recurrences.get( 1 ); assertEquals( 2020, rec.getValues().get( 0 ).intValue() ); }
@Test public void testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_daysOfWeek() throws Exception { complex.setDaysOfWeek( new int[] { 1, 5 } ); when( scheduleRequest.getComplexJobTrigger() ).thenReturn( complex ); IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger( scheduleRequest, scheduler ); assertNotNull( trigger ); assertTrue( trigger instanceof ComplexJobTrigger ); ComplexJobTrigger trig = (ComplexJobTrigger) trigger; List<ITimeRecurrence> recurrences = trig.getDayOfWeekRecurrences().getRecurrences(); assertEquals( 2, recurrences.size() ); RecurrenceList rec = (RecurrenceList) recurrences.get( 0 ); assertEquals( 2, rec.getValues().get( 0 ).intValue() ); rec = (RecurrenceList) recurrences.get( 1 ); assertEquals( 6, rec.getValues().get( 0 ).intValue() ); }
@Test public void testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_weeksOfMonth() throws Exception { complex.setDaysOfWeek( new int[] { 1, 5 } ); complex.setWeeksOfMonth( new int[] { 3, 4 } ); when( scheduleRequest.getComplexJobTrigger() ).thenReturn( complex ); IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger( scheduleRequest, scheduler ); assertNotNull( trigger ); assertTrue( trigger instanceof ComplexJobTrigger ); ComplexJobTrigger trig = (ComplexJobTrigger) trigger; List<ITimeRecurrence> recurrences = trig.getDayOfWeekRecurrences().getRecurrences(); assertEquals( 4, recurrences.size() ); QualifiedDayOfWeek rec = (QualifiedDayOfWeek) recurrences.get( 0 ); assertEquals( "MON", rec.getDayOfWeek().toString() ); assertEquals( "FOURTH", rec.getQualifier().toString() ); rec = (QualifiedDayOfWeek) recurrences.get( 1 ); assertEquals( "MON", rec.getDayOfWeek().toString() ); assertEquals( "LAST", rec.getQualifier().toString() ); rec = (QualifiedDayOfWeek) recurrences.get( 2 ); assertEquals( "FRI", rec.getDayOfWeek().toString() ); assertEquals( "FOURTH", rec.getQualifier().toString() ); rec = (QualifiedDayOfWeek) recurrences.get( 3 ); assertEquals( "FRI", rec.getDayOfWeek().toString() ); assertEquals( "LAST", rec.getQualifier().toString() ); }
@Test public void testConvertScheduleRequestToJobTrigger_CronString() throws Exception { cron = new CronJobTrigger(); cron.setCronString( "0 45 16 ? * 2#4,2L,6#4,6L *" ); cron.setDuration( 200000 ); cron.setStartTime( now ); cron.setUiPassParam( "param" ); cron.setEndTime( now ); when( scheduleRequest.getCronJobTrigger() ).thenReturn( cron ); IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger( scheduleRequest, scheduler ); assertTrue( trigger instanceof ComplexJobTrigger ); ComplexJobTrigger trig = (ComplexJobTrigger) trigger; assertEquals( now, trig.getStartTime() ); assertEquals( now, trig.getEndTime() ); assertEquals( 200000, trig.getDuration() ); assertEquals( "param", trig.getUiPassParam() ); List<ITimeRecurrence> recurrences = trig.getDayOfWeekRecurrences().getRecurrences(); assertEquals( 4, recurrences.size() ); QualifiedDayOfWeek rec = (QualifiedDayOfWeek) recurrences.get( 0 ); assertEquals( "MON", rec.getDayOfWeek().toString() ); assertEquals( "FOURTH", rec.getQualifier().toString() ); rec = (QualifiedDayOfWeek) recurrences.get( 1 ); assertEquals( "MON", rec.getDayOfWeek().toString() ); assertEquals( "LAST", rec.getQualifier().toString() ); rec = (QualifiedDayOfWeek) recurrences.get( 2 ); assertEquals( "FRI", rec.getDayOfWeek().toString() ); assertEquals( "FOURTH", rec.getQualifier().toString() ); rec = (QualifiedDayOfWeek) recurrences.get( 3 ); assertEquals( "FRI", rec.getDayOfWeek().toString() ); assertEquals( "LAST", rec.getQualifier().toString() ); }