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:
@@ -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;
|
||||
|
||||
@@ -88,6 +91,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)
|
||||
@@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user