diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/scheduler/OleNGBatchJobScheduler.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/scheduler/OleNGBatchJobScheduler.java index 2d81b44d50..0c30d6c760 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/scheduler/OleNGBatchJobScheduler.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/scheduler/OleNGBatchJobScheduler.java @@ -80,16 +80,6 @@ public void initializeAllJobs() { } } - private Date getNextValidTimeAfter(String cron) { - try { - CronExpression exp = new CronExpression(cron); - return exp.getNextValidTimeAfter(new Date()); - } catch (ParseException e) { - e.printStackTrace(); - } - return null; - } - public void scheduleOrRescheduleJob(long id, long profileId, String jobType, String cron) { try { String jobId = OleNGConstants.JOB_NAME_PFX + id; diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/scheduler/job/BatchSchedulerJob.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/scheduler/job/BatchSchedulerJob.java index 14e6d4175b..35b619ae05 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/scheduler/job/BatchSchedulerJob.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/scheduler/job/BatchSchedulerJob.java @@ -9,20 +9,18 @@ import org.kuali.ole.docstore.common.util.BusinessObjectServiceHelperUtil; import org.kuali.ole.oleng.batch.process.model.BatchJobDetails; import org.kuali.ole.oleng.batch.process.model.BatchProcessJob; +import org.kuali.ole.oleng.util.OleNGSchedulerHelperUtil; import org.kuali.ole.spring.batch.BatchUtil; import org.kuali.ole.spring.batch.processor.BatchFileProcessor; import org.kuali.rice.core.api.config.property.ConfigContext; import org.kuali.rice.krad.UserSession; import org.kuali.rice.krad.util.GlobalVariables; import org.quartz.*; -import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.io.IOException; import java.sql.Timestamp; import java.util.Date; -import java.util.Iterator; -import java.util.List; /** * Created by SheikS on 4/15/2016. @@ -32,6 +30,7 @@ public class BatchSchedulerJob extends BusinessObjectServiceHelperUtil implement private static final Logger LOG = Logger.getLogger(BatchSchedulerJob.class); private BatchUtil batchUtil; + private OleNGSchedulerHelperUtil oleNGSchedulerHelperUtil; public void execute(JobExecutionContext context) throws JobExecutionException { @@ -45,10 +44,7 @@ public void execute(JobExecutionContext context) GlobalVariables.setUserSession(new UserSession(principalName)); BatchProcessJob batchProcessJobById = getBatchUtil().getBatchProcessJobById(jobId); if(null != processor && batchProcessJobById != null) { - batchProcessJobById.setJobType(OleNGConstants.ADHOC); - batchProcessJobById.setNextRunTime(null); - batchProcessJobById.setCronExpression(null); - getBusinessObjectService().save(batchProcessJobById); + processNextExecutionTime(batchProcessJobById); String schedulerUploadLocation = ConfigContext.getCurrentContextConfig().getProperty("schedulerUploadLocation"); File schedulerFileUploadLocation = new File(schedulerUploadLocation, String.valueOf(jobId)); File file = getFileName(schedulerFileUploadLocation); @@ -77,6 +73,17 @@ public void execute(JobExecutionContext context) } } + private void processNextExecutionTime(BatchProcessJob batchProcessJobById) { + Date nextValidTimeAfter = getOleNGSchedulerHelperUtil().getNextValidTimeAfter(batchProcessJobById.getCronExpression()); + if(null == nextValidTimeAfter) { + batchProcessJobById.setJobType(OleNGConstants.ADHOC); + batchProcessJobById.setNextRunTime(null); + } else { + batchProcessJobById.setNextRunTime(new Timestamp(nextValidTimeAfter.getTime())); + } + getBusinessObjectService().save(batchProcessJobById); + } + private File getFileName(File uploadedFileDirecotry) { File[] files = uploadedFileDirecotry.listFiles(); if(files != null && files.length > 0) { @@ -124,4 +131,14 @@ public BatchUtil getBatchUtil() { return batchUtil; } + public OleNGSchedulerHelperUtil getOleNGSchedulerHelperUtil() { + if(null == oleNGSchedulerHelperUtil) { + oleNGSchedulerHelperUtil = new OleNGSchedulerHelperUtil(); + } + return oleNGSchedulerHelperUtil; + } + + public void setOleNGSchedulerHelperUtil(OleNGSchedulerHelperUtil oleNGSchedulerHelperUtil) { + this.oleNGSchedulerHelperUtil = oleNGSchedulerHelperUtil; + } } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGSchedulerHelperUtil.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGSchedulerHelperUtil.java index 0135901b52..10bc214520 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGSchedulerHelperUtil.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGSchedulerHelperUtil.java @@ -5,6 +5,7 @@ import org.kuali.ole.constants.OleNGConstants; import org.kuali.ole.docstore.common.util.BusinessObjectServiceHelperUtil; import org.kuali.ole.oleng.batch.process.model.BatchScheduleJob; +import org.quartz.CronExpression; import java.sql.Timestamp; import java.text.ParseException; @@ -143,4 +144,15 @@ public String createCronExpressionForMonthly(String day, String frequency, Strin } return cron; } + + + public Date getNextValidTimeAfter(String cron) { + try { + CronExpression exp = new CronExpression(cron); + return exp.getNextValidTimeAfter(new Date()); + } catch (ParseException e) { + e.printStackTrace(); + } + return null; + } }