mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Replication Service tweaks
In preparation for writing the webscripts, add a rename service method, and change the user facing type of the name from QName to string git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21440 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -304,7 +304,7 @@ public class ReplicationActionExecutor extends ActionExecuterAbstractBase {
|
||||
try {
|
||||
// Quick try
|
||||
lockToken = jobLockService.getLock(
|
||||
replicationDef.getReplicationName(),
|
||||
replicationDef.getReplicationQName(),
|
||||
replicationActionLockDuration,
|
||||
5 * 1000, // Every 5 seconds
|
||||
6 // 6 times = wait up to 30 seconds
|
||||
@@ -312,7 +312,7 @@ public class ReplicationActionExecutor extends ActionExecuterAbstractBase {
|
||||
} catch(LockAcquisitionException e) {
|
||||
// Long try - every 30 seconds
|
||||
lockToken = jobLockService.getLock(
|
||||
replicationDef.getReplicationName(),
|
||||
replicationDef.getReplicationQName(),
|
||||
replicationActionLockDuration,
|
||||
retryTime,
|
||||
retries
|
||||
@@ -323,7 +323,7 @@ public class ReplicationActionExecutor extends ActionExecuterAbstractBase {
|
||||
{
|
||||
jobLockService.refreshLock(
|
||||
lockToken,
|
||||
replicationDef.getReplicationName(),
|
||||
replicationDef.getReplicationQName(),
|
||||
replicationActionLockDuration
|
||||
);
|
||||
}
|
||||
@@ -331,7 +331,7 @@ public class ReplicationActionExecutor extends ActionExecuterAbstractBase {
|
||||
{
|
||||
jobLockService.releaseLock(
|
||||
lockToken,
|
||||
replicationDef.getReplicationName()
|
||||
replicationDef.getReplicationQName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication
|
||||
* @param replicationName
|
||||
* a unique name for the replication action.
|
||||
*/
|
||||
public ReplicationDefinitionImpl(String id, QName replicationName)
|
||||
public ReplicationDefinitionImpl(String id, String replicationName)
|
||||
{
|
||||
this(id, replicationName, null);
|
||||
}
|
||||
@@ -65,10 +65,10 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication
|
||||
* @param description
|
||||
* a description of the replication
|
||||
*/
|
||||
public ReplicationDefinitionImpl(String id, QName replicationName, String description)
|
||||
public ReplicationDefinitionImpl(String id, String replicationName, String description)
|
||||
{
|
||||
super(null, id, "replicationActionExecutor");
|
||||
setParameterValue(REPLICATION_DEFINITION_NAME, replicationName);
|
||||
setReplicationQName(QName.createQName(null, replicationName));
|
||||
setDescription(description);
|
||||
}
|
||||
|
||||
@@ -80,10 +80,27 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication
|
||||
/*
|
||||
* @see org.alfresco.service.cmr.replication.ReplicationDefinition#getReplicationName()
|
||||
*/
|
||||
public QName getReplicationName()
|
||||
public String getReplicationName()
|
||||
{
|
||||
return getReplicationQName().getLocalName();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.alfresco.service.cmr.replication.ReplicationDefinition#getReplicationQName()
|
||||
*/
|
||||
public QName getReplicationQName()
|
||||
{
|
||||
Serializable parameterValue = getParameterValue(REPLICATION_DEFINITION_NAME);
|
||||
return (QName) parameterValue;
|
||||
return (QName)parameterValue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets or changes the replication name, which should match
|
||||
* the association name in the data dictionary
|
||||
*/
|
||||
protected void setReplicationQName(QName replicationName)
|
||||
{
|
||||
setParameterValue(REPLICATION_DEFINITION_NAME, replicationName);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -22,7 +22,6 @@ package org.alfresco.repo.replication;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.cmr.replication.ReplicationDefinition;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* This class provides the implementation of ReplicationDefinition persistence.
|
||||
@@ -52,17 +51,30 @@ public interface ReplicationDefinitionPersister
|
||||
*/
|
||||
void deleteReplicationDefinition(ReplicationDefinition replicationDefinition);
|
||||
|
||||
/**
|
||||
* This method renames a {@link ReplicationDefinition} that has been stored
|
||||
* in the repository using the <code>save()</code> method.
|
||||
* If no {@link ReplicationDefinition} exists in the repository with the specified
|
||||
* replication name, then nothing happens.
|
||||
*
|
||||
* @param oldReplicationName The unique identifier used to specify the
|
||||
* {@link ReplicationDefinition} to rename.
|
||||
* @param newReplicationName The unique identifier used to specify the
|
||||
* new {@link ReplicationDefinition} name.
|
||||
*/
|
||||
void renameReplicationDefinition(String oldReplicationName, String newReplicationName);
|
||||
|
||||
/**
|
||||
* This method retrieves a {@link ReplicationDefinition} that has been stored
|
||||
* in the repository using the <code>save()</code> method. If no
|
||||
* {@link ReplicationDefinition} exists in the repository with the specified
|
||||
* rendition name then this method returns null.
|
||||
* replication name then this method returns null.
|
||||
*
|
||||
* @param replicationName The unique identifier used to specify the
|
||||
* {@link ReplicationDefinition} to retrieve.
|
||||
* @return The specified {@link ReplicationDefinition} or null.
|
||||
*/
|
||||
ReplicationDefinition loadReplicationDefinition(QName replicationName);
|
||||
ReplicationDefinition loadReplicationDefinition(String replicationName);
|
||||
|
||||
/**
|
||||
* This method retrieves the {@link ReplicationDefinition}s that have been
|
||||
|
@@ -118,6 +118,10 @@ public class ReplicationDefinitionPersisterImpl implements ReplicationDefinition
|
||||
}
|
||||
|
||||
|
||||
public ReplicationDefinition loadReplicationDefinition(String replicationDefinitionName)
|
||||
{
|
||||
return loadReplicationDefinition( buildReplicationQName(replicationDefinitionName) );
|
||||
}
|
||||
public ReplicationDefinition loadReplicationDefinition(QName replicationDefinitionName)
|
||||
{
|
||||
NodeRef actionNode = findActionNode(replicationDefinitionName);
|
||||
@@ -130,6 +134,47 @@ public class ReplicationDefinitionPersisterImpl implements ReplicationDefinition
|
||||
return null;
|
||||
}
|
||||
|
||||
public void renameReplicationDefinition(String oldReplicationName, String newReplicationName)
|
||||
{
|
||||
renameReplicationDefinition(
|
||||
buildReplicationQName(oldReplicationName),
|
||||
buildReplicationQName(newReplicationName)
|
||||
);
|
||||
}
|
||||
public void renameReplicationDefinition(QName oldReplicationName, QName newReplicationName)
|
||||
{
|
||||
NodeRef actionNode = findActionNode(oldReplicationName);
|
||||
if(actionNode == null)
|
||||
{
|
||||
// No current definition with this name
|
||||
// So, nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure the destination name is free
|
||||
if(findActionNode(newReplicationName) != null)
|
||||
{
|
||||
throw new ReplicationServiceException("Can't rename to '" + newReplicationName +
|
||||
"' as a definition with that name already exists");
|
||||
}
|
||||
|
||||
// Rename the node
|
||||
nodeService.moveNode(
|
||||
actionNode, REPLICATION_ACTION_ROOT_NODE_REF,
|
||||
ContentModel.ASSOC_CONTAINS, newReplicationName
|
||||
);
|
||||
|
||||
// Update the definition properties
|
||||
ReplicationDefinition rd = loadReplicationDefinition(newReplicationName);
|
||||
rd.setParameterValue(
|
||||
ReplicationDefinitionImpl.REPLICATION_DEFINITION_NAME,
|
||||
newReplicationName
|
||||
);
|
||||
saveReplicationDefinition(rd);
|
||||
|
||||
// All done
|
||||
}
|
||||
|
||||
public void saveReplicationDefinition(ReplicationDefinition replicationAction)
|
||||
{
|
||||
NodeRef actionNodeRef = findOrCreateActionNode(replicationAction);
|
||||
@@ -143,7 +188,7 @@ public class ReplicationDefinitionPersisterImpl implements ReplicationDefinition
|
||||
|
||||
public void deleteReplicationDefinition(ReplicationDefinition replicationAction)
|
||||
{
|
||||
QName actionName = replicationAction.getReplicationName();
|
||||
QName actionName = replicationAction.getReplicationQName();
|
||||
NodeRef actionNode = findActionNode(actionName);
|
||||
if(actionNode != null) {
|
||||
nodeService.deleteNode(actionNode);
|
||||
@@ -174,7 +219,7 @@ public class ReplicationDefinitionPersisterImpl implements ReplicationDefinition
|
||||
|
||||
private NodeRef findOrCreateActionNode(ReplicationDefinition replicationAction)
|
||||
{
|
||||
QName actionName = replicationAction.getReplicationName();
|
||||
QName actionName = replicationAction.getReplicationQName();
|
||||
NodeRef actionNode = findActionNode(actionName);
|
||||
if (actionNode == null)
|
||||
{
|
||||
@@ -200,4 +245,9 @@ public class ReplicationDefinitionPersisterImpl implements ReplicationDefinition
|
||||
throw new ReplicationServiceException("Unable to find replication action root node.");
|
||||
}
|
||||
}
|
||||
|
||||
private static QName buildReplicationQName(String name)
|
||||
{
|
||||
return QName.createQName(null, name);
|
||||
}
|
||||
}
|
||||
|
@@ -26,7 +26,6 @@ import org.alfresco.service.cmr.replication.ReplicationDefinition;
|
||||
import org.alfresco.service.cmr.replication.ReplicationService;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.transfer.TransferService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -97,7 +96,7 @@ public class ReplicationServiceImpl implements ReplicationService, ReplicationDe
|
||||
* (org.alfresco.service.namespace.QName, java.lang.String)
|
||||
*/
|
||||
public ReplicationDefinition createReplicationDefinition(
|
||||
QName replicationDefinitionName, String description) {
|
||||
String replicationDefinitionName, String description) {
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
StringBuilder msg = new StringBuilder();
|
||||
@@ -114,7 +113,7 @@ public class ReplicationServiceImpl implements ReplicationService, ReplicationDe
|
||||
* org.alfresco.service.cmr.replication.ReplicationService#loadReplicationDefinition
|
||||
* (org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public ReplicationDefinition loadReplicationDefinition(QName replicationDefinitionName) {
|
||||
public ReplicationDefinition loadReplicationDefinition(String replicationDefinitionName) {
|
||||
return replicationDefinitionPersister.loadReplicationDefinition(replicationDefinitionName);
|
||||
}
|
||||
|
||||
@@ -136,6 +135,17 @@ public class ReplicationServiceImpl implements ReplicationService, ReplicationDe
|
||||
public List<ReplicationDefinition> loadReplicationDefinitions(String target) {
|
||||
return replicationDefinitionPersister.loadReplicationDefinitions(target); // TODO is this right
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see
|
||||
* org.alfresco.service.cmr.replication.ReplicationService#renameReplicationDefinition
|
||||
* (String,String)
|
||||
*/
|
||||
public void renameReplicationDefinition(String oldReplicationName, String newReplicationName)
|
||||
{
|
||||
replicationDefinitionPersister.renameReplicationDefinition(oldReplicationName, newReplicationName);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
@@ -25,8 +25,6 @@ import junit.framework.TestCase;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.replication.ReplicationDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* @author Nick Burch
|
||||
@@ -39,8 +37,8 @@ public class ReplicationServiceImplTest extends TestCase
|
||||
private final ReplicationDefinitionPersisterImpl replicationDefinitionPersister = mock(ReplicationDefinitionPersisterImpl.class);
|
||||
private ReplicationServiceImpl replicationService;
|
||||
|
||||
private final QName ACTION_NAME = QName.createQName(NamespaceService.ALFRESCO_URI, "testName");
|
||||
private final QName ACTION_NAME2 = QName.createQName(NamespaceService.ALFRESCO_URI, "testName2");
|
||||
private final String ACTION_NAME = "testName";
|
||||
private final String ACTION_NAME2 = "testName2";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
|
@@ -100,8 +100,10 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
||||
private NodeRef thumbnail2a_2; // Thumbnail extends content
|
||||
private NodeRef zone2a_3; // Zone doesn't
|
||||
|
||||
private final QName ACTION_NAME = QName.createQName(NamespaceService.ALFRESCO_URI, "testName");
|
||||
private final QName ACTION_NAME2 = QName.createQName(NamespaceService.ALFRESCO_URI, "testName2");
|
||||
private final String ACTION_NAME = "testName";
|
||||
private final String ACTION_NAME2 = "testName2";
|
||||
private final QName ACTION_QNAME = QName.createQName(null, ACTION_NAME);
|
||||
private final QName ACTION_QNAME2 = QName.createQName(null, ACTION_NAME2);
|
||||
|
||||
private final String TRANSFER_TARGET = "TestTransferTarget";
|
||||
|
||||
@@ -192,6 +194,7 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
||||
assertNotNull(replicationAction);
|
||||
assertEquals("Test Definition", replicationAction.getDescription());
|
||||
assertEquals(ACTION_NAME, replicationAction.getReplicationName());
|
||||
assertEquals(ACTION_QNAME, replicationAction.getReplicationQName());
|
||||
|
||||
String id = replicationAction.getId();
|
||||
assertNotNull(id);
|
||||
@@ -224,6 +227,7 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
||||
assertNotNull(retrieved);
|
||||
assertEquals(initialId, retrieved.getId());
|
||||
assertEquals(ACTION_NAME, retrieved.getReplicationName());
|
||||
assertEquals(ACTION_QNAME, retrieved.getReplicationQName());
|
||||
assertEquals("Test Definition", retrieved.getDescription());
|
||||
assertEquals(2, retrieved.getPayload().size());
|
||||
|
||||
@@ -233,6 +237,7 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
||||
assertNotNull(second);
|
||||
assertEquals(initialId, second.getId());
|
||||
assertEquals(ACTION_NAME, second.getReplicationName());
|
||||
assertEquals(ACTION_QNAME, second.getReplicationQName());
|
||||
assertEquals("Test Definition", second.getDescription());
|
||||
assertEquals(2, second.getPayload().size());
|
||||
}
|
||||
@@ -393,6 +398,54 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
||||
assertEquals(1, rdTT.getPayload().size());
|
||||
assertEquals(content1_1, rdTT.getPayload().get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that we can rename definitions
|
||||
*/
|
||||
public void testRenaming() throws Exception
|
||||
{
|
||||
// Create one instance
|
||||
ReplicationDefinition rdTT = replicationService.createReplicationDefinition(ACTION_NAME, "Test");
|
||||
rdTT.setTargetName("TestTarget");
|
||||
replicationService.saveReplicationDefinition(rdTT);
|
||||
assertEquals(1, replicationService.loadReplicationDefinitions().size());
|
||||
|
||||
|
||||
// Rename it
|
||||
replicationService.renameReplicationDefinition(ACTION_NAME, ACTION_NAME2);
|
||||
|
||||
assertEquals(1, replicationService.loadReplicationDefinitions().size());
|
||||
assertEquals(null, replicationService.loadReplicationDefinition(ACTION_NAME));
|
||||
|
||||
rdTT = replicationService.loadReplicationDefinition(ACTION_NAME2);
|
||||
assertNotNull(rdTT);
|
||||
assertEquals(ACTION_NAME2, rdTT.getReplicationName());
|
||||
assertEquals(ACTION_QNAME2, rdTT.getReplicationQName());
|
||||
|
||||
|
||||
// If the source name doesn't exist, does nothing
|
||||
replicationService.renameReplicationDefinition(ACTION_NAME, ACTION_NAME2);
|
||||
|
||||
assertEquals(1, replicationService.loadReplicationDefinitions().size());
|
||||
assertEquals(null, replicationService.loadReplicationDefinition(ACTION_NAME));
|
||||
|
||||
rdTT = replicationService.loadReplicationDefinition(ACTION_NAME2);
|
||||
assertNotNull(rdTT);
|
||||
assertEquals(ACTION_NAME2, rdTT.getReplicationName());
|
||||
assertEquals(ACTION_QNAME2, rdTT.getReplicationQName());
|
||||
|
||||
|
||||
// Renaming to a duplicate name breaks
|
||||
rdTT = replicationService.createReplicationDefinition(ACTION_NAME, "Test");
|
||||
rdTT.setTargetName("TestTarget");
|
||||
replicationService.saveReplicationDefinition(rdTT);
|
||||
assertEquals(2, replicationService.loadReplicationDefinitions().size());
|
||||
|
||||
try {
|
||||
replicationService.renameReplicationDefinition(ACTION_NAME, ACTION_NAME2);
|
||||
fail("Shouldn't be able to rename onto a duplicate name");
|
||||
} catch(ReplicationServiceException e) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the action service can find the executor
|
||||
@@ -503,7 +556,7 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
||||
// Get the lock, and run
|
||||
long start = System.currentTimeMillis();
|
||||
String token = jobLockService.getLock(
|
||||
rd.getReplicationName(),
|
||||
rd.getReplicationQName(),
|
||||
10 * 1000,
|
||||
1,
|
||||
1
|
||||
@@ -540,7 +593,7 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
||||
|
||||
// Get the lock for 2 seconds
|
||||
String token = jobLockService.getLock(
|
||||
rd.getReplicationName(),
|
||||
rd.getReplicationQName(),
|
||||
2 * 1000,
|
||||
1,
|
||||
1
|
||||
@@ -564,7 +617,7 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
||||
|
||||
// Release our lock, should allow the replication task
|
||||
// to get going and spot the cancel
|
||||
jobLockService.releaseLock(token, rd.getReplicationName());
|
||||
jobLockService.releaseLock(token, rd.getReplicationQName());
|
||||
|
||||
// Let the main replication task run to cancelled/completed
|
||||
// This can take quite some time though...
|
||||
|
Reference in New Issue
Block a user