mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-4346 & ALF-4348 - More work on schedulable actions, and start to expose this through to the replication service
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22019 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -45,6 +45,7 @@
|
||||
<property name="actionService" ref="ActionService"/>
|
||||
<property name="dictionaryService" ref="dictionaryService" />
|
||||
<property name="transferService" ref="TransferService" />
|
||||
<property name="scheduledPersistedActionService" ref="scheduledPersistedActionService" />
|
||||
<property name="replicationDefinitionPersister" ref="replicationDefinitionPersister" />
|
||||
</bean>
|
||||
|
||||
|
@@ -35,16 +35,15 @@ import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.action.scheduled.SchedulableAction.IntervalPeriod;
|
||||
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction;
|
||||
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedActionService;
|
||||
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction.IntervalPeriod;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -142,7 +141,11 @@ public class ScheduledPersistedActionServiceImpl implements ScheduledPersistedAc
|
||||
List<ScheduledPersistedAction> actions = listSchedules(startupNodeService);
|
||||
for (ScheduledPersistedAction action : actions)
|
||||
{
|
||||
addToScheduler((ScheduledPersistedActionImpl) action);
|
||||
// Only schedule if the action still exists
|
||||
if(action.getActionNodeRef() != null)
|
||||
{
|
||||
addToScheduler((ScheduledPersistedActionImpl) action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -32,9 +32,9 @@ import org.alfresco.repo.action.ActionServiceImplTest.SleepActionExecuter;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.action.scheduled.SchedulableAction.IntervalPeriod;
|
||||
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction;
|
||||
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedActionService;
|
||||
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction.IntervalPeriod;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
@@ -94,11 +94,11 @@ public class ScheduledPersistedActionServiceTest extends TestCase
|
||||
SleepActionExecuter.registerIfNeeded(ctx);
|
||||
|
||||
// Zap all test schedules
|
||||
// List<ScheduledPersistedAction> schedules = service.listSchedules();
|
||||
// for (ScheduledPersistedAction schedule : schedules)
|
||||
// {
|
||||
// service.deleteSchedule(schedule);
|
||||
// }
|
||||
List<ScheduledPersistedAction> schedules = service.listSchedules();
|
||||
for (ScheduledPersistedAction schedule : schedules)
|
||||
{
|
||||
service.deleteSchedule(schedule);
|
||||
}
|
||||
|
||||
// Persist an action that uses the test executor
|
||||
testAction = new TestAction(actionService.createAction(SleepActionExecuter.NAME));
|
||||
@@ -145,6 +145,10 @@ public class ScheduledPersistedActionServiceTest extends TestCase
|
||||
/**
|
||||
* Tests that the to-trigger stuff works properly
|
||||
*/
|
||||
public void testActionToTrigger() throws Exception
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that we can create, save, edit, delete etc the scheduled persisted
|
||||
@@ -180,7 +184,10 @@ public class ScheduledPersistedActionServiceTest extends TestCase
|
||||
schedule.setScheduleStart(now);
|
||||
schedule.setScheduleIntervalCount(2);
|
||||
schedule.setScheduleIntervalPeriod(ScheduledPersistedAction.IntervalPeriod.Day);
|
||||
|
||||
assertNull( ((ScheduledPersistedActionImpl)schedule).getPersistedAtNodeRef() );
|
||||
service.saveSchedule(schedule);
|
||||
assertNotNull( ((ScheduledPersistedActionImpl)schedule).getPersistedAtNodeRef() );
|
||||
|
||||
// Load it again, should have the same details still
|
||||
ScheduledPersistedAction retrieved = serviceImpl.loadPersistentSchedule(((ScheduledPersistedActionImpl)schedule).getPersistedAtNodeRef());
|
||||
@@ -189,6 +196,7 @@ public class ScheduledPersistedActionServiceTest extends TestCase
|
||||
assertEquals(now, retrieved.getScheduleStart());
|
||||
assertEquals(new Integer(2), retrieved.getScheduleIntervalCount());
|
||||
assertEquals(ScheduledPersistedAction.IntervalPeriod.Day, retrieved.getScheduleIntervalPeriod());
|
||||
assertNotNull( ((ScheduledPersistedActionImpl)schedule).getPersistedAtNodeRef() );
|
||||
|
||||
// Load a 2nd copy, won't be any changes
|
||||
ScheduledPersistedAction second = serviceImpl.loadPersistentSchedule(((ScheduledPersistedActionImpl)schedule).getPersistedAtNodeRef());
|
||||
@@ -197,6 +205,28 @@ public class ScheduledPersistedActionServiceTest extends TestCase
|
||||
assertEquals(now, second.getScheduleStart());
|
||||
assertEquals(new Integer(2), second.getScheduleIntervalCount());
|
||||
assertEquals(ScheduledPersistedAction.IntervalPeriod.Day, second.getScheduleIntervalPeriod());
|
||||
|
||||
|
||||
// Now ensure we can create for an action that didn't have a noderef
|
||||
// when we started
|
||||
Action testAction3 = new TestAction(actionService.createAction(SleepActionExecuter.NAME));
|
||||
schedule = service.createSchedule(testAction3);
|
||||
|
||||
assertNull(schedule.getActionNodeRef());
|
||||
assertNull( ((ScheduledPersistedActionImpl)schedule).getPersistedAtNodeRef() );
|
||||
|
||||
runtimeActionService.createActionNodeRef(
|
||||
//
|
||||
testAction3, ScheduledPersistedActionServiceImpl.SCHEDULED_ACTION_ROOT_NODE_REF,
|
||||
ContentModel.ASSOC_CONTAINS, QName.createQName("TestAction3"));
|
||||
|
||||
assertNotNull(schedule.getActionNodeRef());
|
||||
assertNull( ((ScheduledPersistedActionImpl)schedule).getPersistedAtNodeRef() );
|
||||
|
||||
service.saveSchedule(schedule);
|
||||
|
||||
assertNotNull(schedule.getActionNodeRef());
|
||||
assertNotNull( ((ScheduledPersistedActionImpl)schedule).getPersistedAtNodeRef() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,6 +320,7 @@ public class ScheduledPersistedActionServiceTest extends TestCase
|
||||
ScheduledPersistedAction retrieved = service.getSchedule(testAction2);
|
||||
assertNull(retrieved);
|
||||
|
||||
// and from one which does
|
||||
retrieved = service.getSchedule(testAction);
|
||||
assertNotNull(retrieved);
|
||||
assertEquals(testAction.getNodeRef(), retrieved.getActionNodeRef());
|
||||
@@ -437,8 +468,13 @@ public class ScheduledPersistedActionServiceTest extends TestCase
|
||||
|
||||
Thread.sleep(4000);
|
||||
|
||||
// Ensure it did properly run twice times
|
||||
assertEquals(2, sleepActionExec.getTimesExecuted());
|
||||
// Ensure it did properly run two times
|
||||
// (Depending on timing of tests, might actually slip in 3 runs)
|
||||
if(sleepActionExec.getTimesExecuted() == 3) {
|
||||
assertEquals(3, sleepActionExec.getTimesExecuted());
|
||||
} else {
|
||||
assertEquals(2, sleepActionExec.getTimesExecuted());
|
||||
}
|
||||
|
||||
// Zap it
|
||||
service.deleteSchedule(schedule);
|
||||
|
@@ -21,10 +21,12 @@ package org.alfresco.repo.replication;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.action.ActionImpl;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction;
|
||||
import org.alfresco.service.cmr.replication.ReplicationDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -48,6 +50,8 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication
|
||||
public static final String REPLICATION_DEFINITION_LOCAL_TRANSFER_REPORT = "replicationTransferLocalReport";
|
||||
public static final String REPLICATION_DEFINITION_REMOTE_TRANSFER_REPORT = "replicationTransferRemoteReport";
|
||||
|
||||
private ScheduledPersistedAction schedule;
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* the action id
|
||||
@@ -209,4 +213,54 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication
|
||||
public void setRemoteTransferReport(NodeRef report) {
|
||||
setParameterValue(REPLICATION_DEFINITION_REMOTE_TRANSFER_REPORT, report);
|
||||
}
|
||||
|
||||
public ScheduledPersistedAction getSchedule()
|
||||
{
|
||||
return schedule;
|
||||
}
|
||||
|
||||
public void setSchedule(ScheduledPersistedAction schedule)
|
||||
{
|
||||
this.schedule = schedule;
|
||||
}
|
||||
|
||||
public Integer getScheduleIntervalCount() {
|
||||
if(schedule == null)
|
||||
return null;
|
||||
return schedule.getScheduleIntervalCount();
|
||||
}
|
||||
|
||||
public IntervalPeriod getScheduleIntervalPeriod() {
|
||||
if(schedule == null)
|
||||
return null;
|
||||
return schedule.getScheduleIntervalPeriod();
|
||||
}
|
||||
|
||||
public Date getScheduleStart() {
|
||||
if(schedule == null)
|
||||
return null;
|
||||
return schedule.getScheduleStart();
|
||||
}
|
||||
|
||||
public void setScheduleIntervalCount(Integer count) {
|
||||
if(schedule == null)
|
||||
throw new IllegalStateException("Scheduling not enabled");
|
||||
schedule.setScheduleIntervalCount(count);
|
||||
}
|
||||
|
||||
public void setScheduleIntervalPeriod(IntervalPeriod period) {
|
||||
if(schedule == null)
|
||||
throw new IllegalStateException("Scheduling not enabled");
|
||||
schedule.setScheduleIntervalPeriod(period);
|
||||
}
|
||||
|
||||
public void setScheduleStart(Date startDate) {
|
||||
if(schedule == null)
|
||||
throw new IllegalStateException("Scheduling not enabled");
|
||||
schedule.setScheduleStart(startDate);
|
||||
}
|
||||
|
||||
public boolean isSchedulingEnabled() {
|
||||
return (schedule != null);
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,8 @@ package org.alfresco.repo.replication;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction;
|
||||
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedActionService;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.replication.ReplicationDefinition;
|
||||
import org.alfresco.service.cmr.replication.ReplicationService;
|
||||
@@ -41,6 +43,7 @@ public class ReplicationServiceImpl implements ReplicationService, ReplicationDe
|
||||
private DictionaryService dictionaryService;
|
||||
private TransferService transferService;
|
||||
private NodeService nodeService;
|
||||
private ScheduledPersistedActionService scheduledPersistedActionService;
|
||||
|
||||
private ReplicationDefinitionPersisterImpl replicationDefinitionPersister;
|
||||
|
||||
@@ -89,6 +92,15 @@ public class ReplicationServiceImpl implements ReplicationService, ReplicationDe
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Injects the Scheduled Persisted Action Service bean
|
||||
* @param scheduledPersistedActionService
|
||||
*/
|
||||
public void setScheduledPersistedActionService(ScheduledPersistedActionService scheduledPersistedActionService)
|
||||
{
|
||||
this.scheduledPersistedActionService = scheduledPersistedActionService;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see
|
||||
@@ -114,7 +126,26 @@ public class ReplicationServiceImpl implements ReplicationService, ReplicationDe
|
||||
* (org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public ReplicationDefinition loadReplicationDefinition(String replicationDefinitionName) {
|
||||
return replicationDefinitionPersister.loadReplicationDefinition(replicationDefinitionName);
|
||||
ReplicationDefinitionImpl rd = (ReplicationDefinitionImpl)
|
||||
replicationDefinitionPersister.loadReplicationDefinition(replicationDefinitionName);
|
||||
if(rd != null) {
|
||||
rd.setSchedule(
|
||||
scheduledPersistedActionService.getSchedule(rd)
|
||||
);
|
||||
}
|
||||
return rd;
|
||||
}
|
||||
|
||||
private List<ReplicationDefinition> attachSchedules(List<ReplicationDefinition> definitions) {
|
||||
for(ReplicationDefinition rd : definitions) {
|
||||
if(rd != null) {
|
||||
ReplicationDefinitionImpl rdi = (ReplicationDefinitionImpl)rd;
|
||||
rdi.setSchedule(
|
||||
scheduledPersistedActionService.getSchedule(rdi)
|
||||
);
|
||||
}
|
||||
}
|
||||
return definitions;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -123,7 +154,7 @@ public class ReplicationServiceImpl implements ReplicationService, ReplicationDe
|
||||
* org.alfresco.service.cmr.replication.ReplicationService#loadReplicationDefinitions()
|
||||
*/
|
||||
public List<ReplicationDefinition> loadReplicationDefinitions() {
|
||||
return replicationDefinitionPersister.loadReplicationDefinitions();
|
||||
return attachSchedules( replicationDefinitionPersister.loadReplicationDefinitions() );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -133,7 +164,7 @@ public class ReplicationServiceImpl implements ReplicationService, ReplicationDe
|
||||
* (String)
|
||||
*/
|
||||
public List<ReplicationDefinition> loadReplicationDefinitions(String target) {
|
||||
return replicationDefinitionPersister.loadReplicationDefinitions(target); // TODO is this right
|
||||
return attachSchedules( replicationDefinitionPersister.loadReplicationDefinitions(target) );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -155,7 +186,16 @@ public class ReplicationServiceImpl implements ReplicationService, ReplicationDe
|
||||
*/
|
||||
public void saveReplicationDefinition(
|
||||
ReplicationDefinition replicationDefinition) {
|
||||
// Save the replication definition
|
||||
replicationDefinitionPersister.saveReplicationDefinition(replicationDefinition);
|
||||
|
||||
// If required, now also save the schedule for it
|
||||
if(replicationDefinition.isSchedulingEnabled())
|
||||
{
|
||||
scheduledPersistedActionService.saveSchedule(
|
||||
((ReplicationDefinitionImpl)replicationDefinition).getSchedule()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -166,6 +206,12 @@ public class ReplicationServiceImpl implements ReplicationService, ReplicationDe
|
||||
*/
|
||||
public void deleteReplicationDefinition(
|
||||
ReplicationDefinition replicationDefinition) {
|
||||
if(replicationDefinition.isSchedulingEnabled())
|
||||
{
|
||||
scheduledPersistedActionService.deleteSchedule(
|
||||
((ReplicationDefinitionImpl)replicationDefinition).getSchedule()
|
||||
);
|
||||
}
|
||||
replicationDefinitionPersister.deleteReplicationDefinition(replicationDefinition);
|
||||
}
|
||||
|
||||
@@ -181,4 +227,24 @@ public class ReplicationServiceImpl implements ReplicationService, ReplicationDe
|
||||
ReplicationDefinitionPersisterImpl.REPLICATION_ACTION_ROOT_NODE_REF
|
||||
);
|
||||
}
|
||||
|
||||
public void disableScheduling(ReplicationDefinition replicationDefinition) {
|
||||
ReplicationDefinitionImpl definition = (ReplicationDefinitionImpl)replicationDefinition;
|
||||
if(replicationDefinition.isSchedulingEnabled())
|
||||
{
|
||||
scheduledPersistedActionService.deleteSchedule(
|
||||
definition.getSchedule()
|
||||
);
|
||||
}
|
||||
definition.setSchedule(null);
|
||||
}
|
||||
|
||||
public void enableScheduling(ReplicationDefinition replicationDefinition) {
|
||||
if(!replicationDefinition.isSchedulingEnabled())
|
||||
{
|
||||
ScheduledPersistedAction schedule =
|
||||
scheduledPersistedActionService.createSchedule(replicationDefinition);
|
||||
((ReplicationDefinitionImpl)replicationDefinition).setSchedule(schedule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@
|
||||
package org.alfresco.repo.replication;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -31,6 +32,7 @@ import javax.transaction.UserTransaction;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.scheduled.ScheduledPersistedActionImpl;
|
||||
import org.alfresco.repo.lock.JobLockService;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
@@ -42,6 +44,8 @@ import org.alfresco.repo.transfer.manifest.TransferManifestNodeFactory;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.action.ActionStatus;
|
||||
import org.alfresco.service.cmr.action.ActionTrackingService;
|
||||
import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedActionService;
|
||||
import org.alfresco.service.cmr.action.scheduled.SchedulableAction.IntervalPeriod;
|
||||
import org.alfresco.service.cmr.lock.LockService;
|
||||
import org.alfresco.service.cmr.lock.UnableToReleaseLockException;
|
||||
import org.alfresco.service.cmr.replication.ReplicationDefinition;
|
||||
@@ -88,6 +92,7 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
||||
private LockService lockService;
|
||||
private Repository repositoryHelper;
|
||||
private ActionTrackingService actionTrackingService;
|
||||
private ScheduledPersistedActionService scheduledPersistedActionService;
|
||||
|
||||
private NodeRef replicationRoot;
|
||||
|
||||
@@ -125,6 +130,7 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
||||
lockService = (LockService) ctx.getBean("lockService");
|
||||
repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
|
||||
actionTrackingService = (ActionTrackingService) ctx.getBean("actionTrackingService");
|
||||
scheduledPersistedActionService = (ScheduledPersistedActionService) ctx.getBean("scheduledPersistedActionService");
|
||||
|
||||
// Set the current security context as admin
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||
@@ -856,6 +862,150 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
||||
assertEquals(true, td.getNodes().contains(content1_1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the schedule related parts work properly
|
||||
*/
|
||||
public void testScheduling() throws Exception
|
||||
{
|
||||
UserTransaction txn = transactionService.getUserTransaction();
|
||||
|
||||
// A new definition doesn't have scheduling
|
||||
ReplicationDefinition rd = replicationService.createReplicationDefinition(ACTION_NAME, "Test");
|
||||
rd.setTargetName("Target");
|
||||
assertFalse(rd.isSchedulingEnabled());
|
||||
|
||||
|
||||
// Disable does nothing
|
||||
replicationService.disableScheduling(rd);
|
||||
assertFalse(rd.isSchedulingEnabled());
|
||||
|
||||
|
||||
// Enable it
|
||||
txn.begin();
|
||||
replicationService.saveReplicationDefinition(rd);
|
||||
replicationService.enableScheduling(rd);
|
||||
txn.commit();
|
||||
assertTrue(rd.isSchedulingEnabled());
|
||||
|
||||
|
||||
// Double enabling does nothing
|
||||
replicationService.enableScheduling(rd);
|
||||
assertTrue(rd.isSchedulingEnabled());
|
||||
|
||||
|
||||
// Change it
|
||||
assertNull(rd.getScheduleStart());
|
||||
assertNull(rd.getScheduleIntervalCount());
|
||||
assertNull(rd.getScheduleIntervalPeriod());
|
||||
|
||||
rd.setScheduleStart(new Date(1));
|
||||
|
||||
assertEquals(1, rd.getScheduleStart().getTime());
|
||||
assertEquals(null, rd.getScheduleIntervalCount());
|
||||
assertEquals(null, rd.getScheduleIntervalPeriod());
|
||||
|
||||
|
||||
// Won't show up until saved
|
||||
ReplicationDefinition rd2 = replicationService.loadReplicationDefinition(ACTION_NAME);
|
||||
assertEquals(false, rd2.isSchedulingEnabled());
|
||||
assertEquals(null, rd2.getScheduleStart());
|
||||
assertEquals(null, rd2.getScheduleIntervalCount());
|
||||
assertEquals(null, rd2.getScheduleIntervalPeriod());
|
||||
|
||||
|
||||
// Save and check
|
||||
assertEquals(true, rd.isSchedulingEnabled());
|
||||
|
||||
txn = transactionService.getUserTransaction();
|
||||
txn.begin();
|
||||
replicationService.saveReplicationDefinition(rd);
|
||||
txn.commit();
|
||||
|
||||
assertEquals(true, rd.isSchedulingEnabled());
|
||||
assertEquals(1, rd.getScheduleStart().getTime());
|
||||
assertEquals(null, rd.getScheduleIntervalCount());
|
||||
assertEquals(null, rd.getScheduleIntervalPeriod());
|
||||
|
||||
rd = replicationService.loadReplicationDefinition(ACTION_NAME);
|
||||
assertEquals(true, rd.isSchedulingEnabled());
|
||||
assertEquals(1, rd.getScheduleStart().getTime());
|
||||
assertEquals(null, rd.getScheduleIntervalCount());
|
||||
assertEquals(null, rd.getScheduleIntervalPeriod());
|
||||
|
||||
|
||||
// Change, save, check
|
||||
rd.setScheduleIntervalCount(2);
|
||||
rd.setScheduleIntervalPeriod(IntervalPeriod.Hour);
|
||||
|
||||
assertEquals(true, rd.isSchedulingEnabled());
|
||||
assertEquals(1, rd.getScheduleStart().getTime());
|
||||
assertEquals(2, rd.getScheduleIntervalCount().intValue());
|
||||
assertEquals(IntervalPeriod.Hour, rd.getScheduleIntervalPeriod());
|
||||
|
||||
txn = transactionService.getUserTransaction();
|
||||
txn.begin();
|
||||
replicationService.saveReplicationDefinition(rd);
|
||||
rd = replicationService.loadReplicationDefinition(ACTION_NAME);
|
||||
txn.commit();
|
||||
|
||||
assertEquals(true, rd.isSchedulingEnabled());
|
||||
assertEquals(1, rd.getScheduleStart().getTime());
|
||||
assertEquals(2, rd.getScheduleIntervalCount().intValue());
|
||||
assertEquals(IntervalPeriod.Hour, rd.getScheduleIntervalPeriod());
|
||||
|
||||
|
||||
// Re-load and enable is fine
|
||||
rd2 = replicationService.loadReplicationDefinition(ACTION_NAME);
|
||||
replicationService.enableScheduling(rd2);
|
||||
|
||||
|
||||
// Check on the listing methods
|
||||
assertEquals(1, replicationService.loadReplicationDefinitions().size());
|
||||
rd = replicationService.loadReplicationDefinitions().get(0);
|
||||
assertEquals(true, rd.isSchedulingEnabled());
|
||||
assertEquals(1, rd.getScheduleStart().getTime());
|
||||
assertEquals(2, rd.getScheduleIntervalCount().intValue());
|
||||
assertEquals(IntervalPeriod.Hour, rd.getScheduleIntervalPeriod());
|
||||
|
||||
assertEquals(1, replicationService.loadReplicationDefinitions("Target").size());
|
||||
rd = replicationService.loadReplicationDefinitions("Target").get(0);
|
||||
assertEquals(true, rd.isSchedulingEnabled());
|
||||
assertEquals(1, rd.getScheduleStart().getTime());
|
||||
assertEquals(2, rd.getScheduleIntervalCount().intValue());
|
||||
assertEquals(IntervalPeriod.Hour, rd.getScheduleIntervalPeriod());
|
||||
|
||||
|
||||
// Disable it
|
||||
replicationService.disableScheduling(rd);
|
||||
assertEquals(false, rd.isSchedulingEnabled());
|
||||
|
||||
|
||||
// Check listings again
|
||||
rd = replicationService.loadReplicationDefinitions().get(0);
|
||||
assertEquals(false, rd.isSchedulingEnabled());
|
||||
|
||||
rd = replicationService.loadReplicationDefinitions("Target").get(0);
|
||||
assertEquals(false, rd.isSchedulingEnabled());
|
||||
|
||||
|
||||
// Enable it, and check the scheduled service
|
||||
txn = transactionService.getUserTransaction();
|
||||
txn.begin();
|
||||
int count = scheduledPersistedActionService.listSchedules().size();
|
||||
replicationService.enableScheduling(rd);
|
||||
replicationService.saveReplicationDefinition(rd);
|
||||
assertEquals(count+1, scheduledPersistedActionService.listSchedules().size());
|
||||
txn.commit();
|
||||
|
||||
|
||||
// Delete is, and check the scheduled service
|
||||
txn = transactionService.getUserTransaction();
|
||||
txn.begin();
|
||||
replicationService.deleteReplicationDefinition(rd);
|
||||
assertEquals(count, scheduledPersistedActionService.listSchedules().size());
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
|
||||
private NodeRef makeNode(NodeRef parent, QName nodeType)
|
||||
{
|
||||
|
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.service.cmr.action.scheduled;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* The scheduling details for an action, normally used
|
||||
* via {@link ScheduledPersistedAction}
|
||||
*
|
||||
* @author Nick Burch
|
||||
* @since 3.4
|
||||
*/
|
||||
public interface SchedulableAction
|
||||
{
|
||||
/**
|
||||
* Get the first date that the action should be run
|
||||
* on or after, or null if it should start shortly
|
||||
* after each startup.
|
||||
*/
|
||||
public Date getScheduleStart();
|
||||
|
||||
/**
|
||||
* Sets the first date that the action should be
|
||||
* run on or after. Set to null if the action
|
||||
* should be run shortly after each startup.
|
||||
*/
|
||||
public void setScheduleStart(Date startDate);
|
||||
|
||||
|
||||
/**
|
||||
* How many {@link #getScheduleIntervalPeriod()} periods
|
||||
* should we wait between executions?
|
||||
* Will be null if the action isn't scheduled to
|
||||
* be repeated.
|
||||
*/
|
||||
public Integer getScheduleIntervalCount();
|
||||
|
||||
/**
|
||||
* Sets how many periods should be waited between
|
||||
* each execution, or null if it shouldn't be
|
||||
* repeated.
|
||||
*/
|
||||
public void setScheduleIntervalCount(Integer count);
|
||||
|
||||
|
||||
/**
|
||||
* How long are {@link #getScheduleIntervalCount()} counts
|
||||
* measured in?
|
||||
*/
|
||||
public IntervalPeriod getScheduleIntervalPeriod();
|
||||
|
||||
/**
|
||||
* Sets the interval period
|
||||
*/
|
||||
public void setScheduleIntervalPeriod(IntervalPeriod period);
|
||||
|
||||
|
||||
public static enum IntervalPeriod {
|
||||
Month,
|
||||
Week,
|
||||
Day,
|
||||
Hour,
|
||||
Minute,
|
||||
Second;
|
||||
}
|
||||
}
|
@@ -18,8 +18,6 @@
|
||||
*/
|
||||
package org.alfresco.service.cmr.action.scheduled;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
@@ -31,7 +29,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
* @author Nick Burch
|
||||
* @since 3.4
|
||||
*/
|
||||
public interface ScheduledPersistedAction
|
||||
public interface ScheduledPersistedAction extends SchedulableAction
|
||||
{
|
||||
/** Get the action which the schedule applies to */
|
||||
public Action getAction();
|
||||
@@ -39,62 +37,10 @@ public interface ScheduledPersistedAction
|
||||
/** Get the persisted {@link NodeRef} of the action this applies to */
|
||||
public NodeRef getActionNodeRef();
|
||||
|
||||
/**
|
||||
* Get the first date that the action should be run
|
||||
* on or after, or null if it should start shortly
|
||||
* after each startup.
|
||||
*/
|
||||
public Date getScheduleStart();
|
||||
|
||||
/**
|
||||
* Sets the first date that the action should be
|
||||
* run on or after. Set to null if the action
|
||||
* should be run shortly after each startup.
|
||||
*/
|
||||
public void setScheduleStart(Date startDate);
|
||||
|
||||
|
||||
/**
|
||||
* How many {@link #getScheduleIntervalPeriod()} periods
|
||||
* should we wait between executions?
|
||||
* Will be null if the action isn't scheduled to
|
||||
* be repeated.
|
||||
*/
|
||||
public Integer getScheduleIntervalCount();
|
||||
|
||||
/**
|
||||
* Sets how many periods should be waited between
|
||||
* each execution, or null if it shouldn't be
|
||||
* repeated.
|
||||
*/
|
||||
public void setScheduleIntervalCount(Integer count);
|
||||
|
||||
|
||||
/**
|
||||
* How long are {@link #getScheduleIntervalCount()} counts
|
||||
* measured in?
|
||||
*/
|
||||
public IntervalPeriod getScheduleIntervalPeriod();
|
||||
|
||||
/**
|
||||
* Sets the interval period
|
||||
*/
|
||||
public void setScheduleIntervalPeriod(IntervalPeriod period);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the interval in a form like 1Day (1 day)
|
||||
* or 2Hour (2 hours)
|
||||
*/
|
||||
public String getScheduleInterval();
|
||||
|
||||
|
||||
public static enum IntervalPeriod {
|
||||
Month,
|
||||
Week,
|
||||
Day,
|
||||
Hour,
|
||||
Minute,
|
||||
Second;
|
||||
}
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.cmr.action.CancellableAction;
|
||||
import org.alfresco.service.cmr.action.scheduled.SchedulableAction;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
@@ -35,7 +36,7 @@ import org.alfresco.service.namespace.QName;
|
||||
*
|
||||
* @author Nick Burch
|
||||
*/
|
||||
public interface ReplicationDefinition extends CancellableAction, Serializable {
|
||||
public interface ReplicationDefinition extends CancellableAction, SchedulableAction, Serializable {
|
||||
/**
|
||||
* @return the name which uniquely identifies this replication definition.
|
||||
*/
|
||||
@@ -114,5 +115,12 @@ public interface ReplicationDefinition extends CancellableAction, Serializable {
|
||||
*/
|
||||
void setRemoteTransferReport(NodeRef report);
|
||||
|
||||
/**
|
||||
* Is scheduling currently enabled?
|
||||
* See {@link ReplicationService#enableScheduling(ReplicationDefinition)} and
|
||||
* {@link ReplicationService#disableScheduling(ReplicationDefinition)}
|
||||
*/
|
||||
boolean isSchedulingEnabled();
|
||||
|
||||
// TODO Replication options, such as permissions and rules
|
||||
}
|
||||
|
@@ -45,4 +45,17 @@ public interface ReplicationService extends ReplicationDefinitionPersister {
|
||||
*/
|
||||
@NotAuditable
|
||||
void replicate(ReplicationDefinition replicationDefinition);
|
||||
|
||||
/**
|
||||
* Turns on scheduling for the specified replication. You can
|
||||
* then set the scheduling details on the definition.
|
||||
*/
|
||||
@NotAuditable
|
||||
void enableScheduling(ReplicationDefinition replicationDefinition);
|
||||
|
||||
/**
|
||||
* Turns off scheduling for the specified replication
|
||||
*/
|
||||
@NotAuditable
|
||||
void disableScheduling(ReplicationDefinition replicationDefinition);
|
||||
}
|
||||
|
Reference in New Issue
Block a user