mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-4346 - Start on the scheduled persisted actions service implementation
Tests are only stubbed out for now git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21813 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -22,6 +22,9 @@ import java.util.Date;
|
||||
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.quartz.SimpleTrigger;
|
||||
import org.quartz.Trigger;
|
||||
|
||||
/**
|
||||
* The scheduling wrapper around a persisted
|
||||
@@ -33,17 +36,26 @@ import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction;
|
||||
*/
|
||||
public class ScheduledPersistedActionImpl implements ScheduledPersistedAction
|
||||
{
|
||||
private NodeRef persistedAtNodeRef;
|
||||
private Action action;
|
||||
private Date scheduleStart;
|
||||
private Integer intervalCount;
|
||||
private IntervalPeriod intervalPeriod;
|
||||
|
||||
public ScheduledPersistedActionImpl(Action action)
|
||||
protected ScheduledPersistedActionImpl(Action action)
|
||||
{
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the persisted nodeRef for this schedule
|
||||
*/
|
||||
protected NodeRef getPersistedAtNodeRef()
|
||||
{
|
||||
return persistedAtNodeRef;
|
||||
}
|
||||
|
||||
/** Get the action which the schedule applies to */
|
||||
public Action getAction()
|
||||
{
|
||||
@@ -123,4 +135,72 @@ public class ScheduledPersistedActionImpl implements ScheduledPersistedAction
|
||||
}
|
||||
return intervalCount.toString() + intervalPeriod.getLetter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Quartz trigger definition based on the current
|
||||
* scheduling details.
|
||||
* May only be called once this object has been persisted
|
||||
*/
|
||||
public Trigger asTrigger()
|
||||
{
|
||||
if(persistedAtNodeRef == null)
|
||||
throw new IllegalStateException("Must be persisted first");
|
||||
|
||||
// Use our nodeRef as the unique title
|
||||
String triggerName = persistedAtNodeRef.toString();
|
||||
|
||||
// Monthly is a special case, since the period
|
||||
// will vary
|
||||
// TODO - Make more things use DateIntervalTrigger
|
||||
if(intervalPeriod == IntervalPeriod.Month)
|
||||
{
|
||||
// TODO
|
||||
// DateIntervalTrigger trigger = new DateIntervalTrigger(
|
||||
// triggerName, null,
|
||||
// scheduleStart, null,
|
||||
// DateIntervalTrigger.IntervalUnit.MONTH,
|
||||
// intervalCount
|
||||
// );
|
||||
// trigger.setMisfireInstruction( DateIntervalTrigger.MISFIRE_INSTRUCTION_FIRE_NOW );
|
||||
}
|
||||
|
||||
SimpleTrigger trigger = null;
|
||||
|
||||
// Is it Start Date + Repeat Interval?
|
||||
if(scheduleStart != null && getScheduleInterval() != null)
|
||||
{
|
||||
trigger = new SimpleTrigger(
|
||||
triggerName, null,
|
||||
scheduleStart, null,
|
||||
SimpleTrigger.REPEAT_INDEFINITELY,
|
||||
intervalCount * intervalPeriod.getInterval()
|
||||
);
|
||||
}
|
||||
|
||||
// Is it a single Start Date?
|
||||
if(scheduleStart != null && getScheduleInterval() == null)
|
||||
{
|
||||
trigger = new SimpleTrigger(
|
||||
triggerName, null,
|
||||
scheduleStart
|
||||
);
|
||||
}
|
||||
|
||||
// Is it start now, run with Repeat Interval?
|
||||
if(getScheduleInterval() != null)
|
||||
{
|
||||
trigger = new SimpleTrigger(
|
||||
triggerName, null,
|
||||
SimpleTrigger.REPEAT_INDEFINITELY,
|
||||
intervalCount * intervalPeriod.getInterval()
|
||||
);
|
||||
}
|
||||
|
||||
if(trigger != null)
|
||||
{
|
||||
// If we miss running, run as soon after as we can
|
||||
trigger.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW);
|
||||
}
|
||||
return trigger;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user