Allow the blank to schedule field
This commit is contained in:
parent
7d34239c7f
commit
1a4fb3ab0d
7 changed files with 34 additions and 5 deletions
|
@ -36,6 +36,7 @@ import jp.sf.fess.util.FessBeans;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.codelibs.core.util.StringUtil;
|
||||
import org.codelibs.sastruts.core.exception.SSCActionMessagesException;
|
||||
import org.seasar.struts.annotation.Execute;
|
||||
import org.seasar.struts.exception.ActionMessagesException;
|
||||
|
@ -69,6 +70,8 @@ public class ScheduledJobAction extends BsScheduledJobAction {
|
|||
FessBeans.copy(scheduledJob, scheduledJobForm)
|
||||
.commonColumnDateConverter()
|
||||
.excludes("searchParams", "mode", "jobLogging").execute();
|
||||
scheduledJobForm.cronEnabled = StringUtil.isNotBlank(scheduledJob
|
||||
.getCronExpression()) ? Constants.ON : null;
|
||||
scheduledJobForm.jobLogging = scheduledJob.isLoggingEnabled() ? Constants.ON
|
||||
: null;
|
||||
scheduledJobForm.crawler = scheduledJob.isCrawlerJob() ? Constants.ON
|
||||
|
@ -100,6 +103,9 @@ public class ScheduledJobAction extends BsScheduledJobAction {
|
|||
scheduledJob.setUpdatedTime(timestamp);
|
||||
FessBeans.copy(scheduledJobForm, scheduledJob).excludesCommonColumns()
|
||||
.execute();
|
||||
scheduledJob.setCronExpression(Constants.ON
|
||||
.equals(scheduledJobForm.cronEnabled) ? null
|
||||
: scheduledJobForm.cronExpression);
|
||||
scheduledJob.setJobLogging(Constants.ON
|
||||
.equals(scheduledJobForm.jobLogging) ? Constants.T
|
||||
: Constants.F);
|
||||
|
|
|
@ -52,7 +52,7 @@ public abstract class BsLabelTypeForm {
|
|||
public String name;
|
||||
|
||||
@Required(target = "confirmfromcreate,create,confirmfromupdate,update,delete")
|
||||
@Maxbytelength(maxbytelength = 20)
|
||||
@Maxbytelength(maxbytelength = 40)
|
||||
@Mask(mask = "^[a-zA-Z0-9_-]+$", msg = @Msg(key = "errors.alphaDigitOnly"))
|
||||
public String value;
|
||||
|
||||
|
|
|
@ -54,11 +54,13 @@ public abstract class BsScheduledJobForm {
|
|||
@Maxbytelength(maxbytelength = 100)
|
||||
public String target;
|
||||
|
||||
@Required(target = "confirmfromcreate,create,confirmfromupdate,update,delete")
|
||||
@Maxbytelength(maxbytelength = 100)
|
||||
@CronExpression
|
||||
public String cronExpression;
|
||||
|
||||
// ignore
|
||||
public String cronEnabled;
|
||||
|
||||
@Required(target = "confirmfromcreate,create,confirmfromupdate,update,delete")
|
||||
@Maxbytelength(maxbytelength = 100)
|
||||
public String scriptType;
|
||||
|
@ -107,6 +109,7 @@ public abstract class BsScheduledJobForm {
|
|||
name = null;
|
||||
target = null;
|
||||
cronExpression = null;
|
||||
cronEnabled = null;
|
||||
scriptType = null;
|
||||
scriptData = null;
|
||||
crawler = null;
|
||||
|
|
|
@ -34,6 +34,7 @@ public class ScheduledJobForm extends BsScheduledJobForm implements
|
|||
super.initialize();
|
||||
target = Constants.DEFAULT_JOB_TARGET;
|
||||
cronExpression = Constants.DEFAULT_CRON_EXPRESSION;
|
||||
cronEnabled = Constants.ON;
|
||||
scriptType = Constants.DEFAULT_JOB_SCRIPT_TYPE;
|
||||
sortOrder = "0";
|
||||
// Temporary data
|
||||
|
|
|
@ -97,6 +97,10 @@ public class JobScheduler {
|
|||
}
|
||||
|
||||
public void register(final ScheduledJob scheduledJob) {
|
||||
final String cronExpression = scheduledJob.getCronExpression();
|
||||
if (StringUtil.isBlank(cronExpression)) {
|
||||
return;
|
||||
}
|
||||
if (scheduledJob == null) {
|
||||
throw new ScheduledJobException("No job.");
|
||||
}
|
||||
|
@ -136,7 +140,7 @@ public class JobScheduler {
|
|||
.usingJobData(jobDataMap).build();
|
||||
|
||||
final Trigger trigger = newTrigger().withIdentity(triggerId)
|
||||
.withSchedule(cronSchedule(scheduledJob.getCronExpression()))
|
||||
.withSchedule(cronSchedule(cronExpression))
|
||||
.startNow().build();
|
||||
|
||||
try {
|
||||
|
|
|
@ -22,6 +22,8 @@ import java.util.Map;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.codelibs.core.util.StringUtil;
|
||||
|
||||
import jp.sf.fess.Constants;
|
||||
import jp.sf.fess.crud.service.BsScheduledJobService;
|
||||
import jp.sf.fess.db.cbean.ScheduledJobCB;
|
||||
|
@ -89,11 +91,12 @@ public class ScheduledJobService extends BsScheduledJobService implements
|
|||
public void store(final ScheduledJob scheduledJob) {
|
||||
final boolean isNew = scheduledJob.getId() == null;
|
||||
final boolean isDelete = scheduledJob.getDeletedBy() != null;
|
||||
final boolean isEnabled = StringUtil.isNotBlank(scheduledJob.getCronExpression());
|
||||
super.store(scheduledJob);
|
||||
if (!isNew) {
|
||||
jobScheduler.unregister(scheduledJob);
|
||||
}
|
||||
if (!isDelete) {
|
||||
if (!isDelete && isEnabled) {
|
||||
jobScheduler.register(scheduledJob);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,18 @@
|
|||
<tiles:put name="menuType" value="scheduledJob" />
|
||||
<tiles:put name="headerScript" type="string"></tiles:put>
|
||||
<tiles:put name="body" type="string">
|
||||
<script>
|
||||
$(function(){
|
||||
if (!($("#cronEnabled").prop('checked'))) {
|
||||
$("#cronExpression").prop('disabled',true);
|
||||
}
|
||||
$('#cronEnabled').on('change', function(){
|
||||
var chk = $(this).prop('checked'),
|
||||
obj = $('#cronExpression');
|
||||
(chk) ? obj.prop('disabled',false) : obj.prop('disabled',true);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<h3>
|
||||
<bean:message key="labels.scheduledjob_title_details" />
|
||||
|
@ -69,7 +81,7 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<th><bean:message key="labels.scheduledjob_cronExpression" /></th>
|
||||
<td><html:text property="cronExpression" styleClass="xlarge" /></td>
|
||||
<td><html:text property="cronExpression" styleId="cronExpression" styleClass="xlarge" /> <html:checkbox property="cronEnabled" styleId="cronEnabled"/><bean:message key="labels.enabled"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><bean:message key="labels.scheduledjob_scriptType" /></th>
|
||||
|
|
Loading…
Add table
Reference in a new issue