Skip to content

Commit

Permalink
Merge pull request #893 from sheiksalahudeen/release-2.1
Browse files Browse the repository at this point in the history
OLE-8994 : Fixed the issue with scheduled imports do not run after system restart
  • Loading branch information
sheiksalahudeen authored Sep 27, 2016
2 parents d7fc40c + 08d5255 commit 28d0d7f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 28d0d7f

Please sign in to comment.