ALF-5068 - rework of content equality test.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22880 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2010-10-05 11:23:46 +00:00
parent e08fd4e940
commit 5ef4758194
6 changed files with 531 additions and 462 deletions

View File

@@ -210,6 +210,13 @@
<type>d:text</type> <type>d:text</type>
<mandatory enforced="true">true</mandatory> <mandatory enforced="true">true</mandatory>
</property> </property>
<property name="trx:fromContent">
<title>ContentProperties</title>
<description>The content URLs transferred with this node</description>
<type>d:text</type>
<mandatory enforced="false">false</mandatory>
<multiple>true</multiple>
</property>
</properties> </properties>
</aspect> </aspect>

View File

@@ -524,16 +524,9 @@ public class RepoPrimaryManifestProcessorImpl extends AbstractManifestProcessorB
Map<QName, Serializable> props = new HashMap<QName, Serializable>(node.getProperties()); Map<QName, Serializable> props = new HashMap<QName, Serializable>(node.getProperties());
Map<QName, Serializable> existingProps = nodeService.getProperties(nodeToUpdate); Map<QName, Serializable> existingProps = nodeService.getProperties(nodeToUpdate);
// inject transferred property here // inject transferred properties/aspect here
injectTransferred(props); injectTransferred(props);
// if(!props.containsKey(TransferModel.PROP_REPOSITORY_ID))
// {
// log.debug("injecting repositoryId property");
// props.put(TransferModel.PROP_REPOSITORY_ID, header.getRepositoryId());
// }
// props.put(TransferModel.PROP_FROM_REPOSITORY_ID, header.getRepositoryId());
// Remove the invadedBy property since that is used by the transfer service // Remove the invadedBy property since that is used by the transfer service
// and is local to this repository. // and is local to this repository.
props.remove(TransferModel.PROP_INVADED_BY); props.remove(TransferModel.PROP_INVADED_BY);
@@ -944,6 +937,26 @@ public class RepoPrimaryManifestProcessorImpl extends AbstractManifestProcessorB
props.put(TransferModel.PROP_REPOSITORY_ID, header.getRepositoryId()); props.put(TransferModel.PROP_REPOSITORY_ID, header.getRepositoryId());
} }
props.put(TransferModel.PROP_FROM_REPOSITORY_ID, header.getRepositoryId()); props.put(TransferModel.PROP_FROM_REPOSITORY_ID, header.getRepositoryId());
/**
* For each property
*/
List<String> contentProps = new ArrayList();
for (Serializable value : props.values())
{
if ((value != null) && ContentData.class.isAssignableFrom(value.getClass()))
{
ContentData srcContent = (ContentData)value;
if(srcContent.getContentUrl() != null && !srcContent.getContentUrl().isEmpty())
{
log.debug("adding part name to from content field");
contentProps.add(TransferCommons.URLToPartName(srcContent.getContentUrl()));
}
}
}
props.put(TransferModel.PROP_FROM_CONTENT, (Serializable)contentProps);
} }
public void setAlienProcessor(AlienProcessor alienProcessor) public void setAlienProcessor(AlienProcessor alienProcessor)

View File

@@ -21,6 +21,7 @@ package org.alfresco.repo.transfer;
import java.io.Serializable; import java.io.Serializable;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
@@ -94,92 +95,102 @@ public class RepoRequisiteManifestProcessorImpl extends AbstractManifestProcesso
{ {
/** /**
* there is a corresponding node so we need to check whether we already * there is a corresponding node so we need to check whether we already
* have the content item * have the part for each content item
*/ */
NodeRef destinationNode = resolvedNodes.resolvedChild; NodeRef destinationNode = resolvedNodes.resolvedChild;
Map<QName, Serializable> destinationProps = nodeService.getProperties(destinationNode); Map<QName, Serializable> destinationProps = nodeService.getProperties(destinationNode);
/**
* For each property on the source node
*/
for (Map.Entry<QName, Serializable> propEntry : node.getProperties().entrySet()) for (Map.Entry<QName, Serializable> propEntry : node.getProperties().entrySet())
{ {
Serializable value = propEntry.getValue(); Serializable value = propEntry.getValue();
QName propName = propEntry.getKey();
if (log.isDebugEnabled()) if (log.isDebugEnabled())
{ {
if (value == null) if (value == null)
{ {
log.debug("Received a null value for property " + propEntry.getKey()); log.debug("Received a null value for property " + propName);
} }
} }
if ((value != null) && ContentData.class.isAssignableFrom(value.getClass())) if ((value != null) && ContentData.class.isAssignableFrom(value.getClass()))
{ {
/**
* Got a content property from source node.
*/
ContentData srcContent = (ContentData)value; ContentData srcContent = (ContentData)value;
if(srcContent.getContentUrl() != null && !srcContent.getContentUrl().isEmpty() ) if(srcContent.getContentUrl() != null && !srcContent.getContentUrl().isEmpty() )
{ {
Serializable destSer = destinationProps.get(propEntry.getKey()); /**
* Source Content is not empty
*/
String partName = TransferCommons.URLToPartName(srcContent.getContentUrl());
Serializable destSer = destinationProps.get(propName);
if(destSer != null && ContentData.class.isAssignableFrom(destSer.getClass())) if(destSer != null && ContentData.class.isAssignableFrom(destSer.getClass()))
{ {
ContentData destContent = (ContentData)destinationProps.get(propEntry.getKey());
/** /**
* If the modification dates for the node are different * Content property not empty and content property already exists on destination
*/ */
Serializable srcModified = node.getProperties().get(ContentModel.PROP_MODIFIED); ContentData destContent = (ContentData)destSer;
Serializable destModified = destinationProps.get(ContentModel.PROP_MODIFIED);
if(log.isDebugEnabled()) Serializable destFromContents = destinationProps.get(TransferModel.PROP_FROM_CONTENT);
if(destFromContents != null && Collection.class.isAssignableFrom(destFromContents.getClass()))
{ {
SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); Collection<String> contents = (Collection<String>)destFromContents;
/**
log.debug ("srcModified :" + srcModified + "destModified :" + destModified); * Content property not empty and content property already exists on destination
*/
if(srcModified instanceof Date) if(contents.contains(partName))
{
log.debug("srcModified: " + SDF.format(srcModified));
}
if(destModified instanceof Date)
{
log.debug("destModified: " + SDF.format(destModified));
}
}
if(srcModified != null &&
destModified != null &&
srcModified instanceof Date &&
destModified instanceof Date &&
((Date)srcModified).getTime() <= ((Date)destModified).getTime())
{ {
if(log.isDebugEnabled()) if(log.isDebugEnabled())
{ {
log.debug("the modified date is the same or before - no need send content:" + node.getNodeRef()); log.debug("part already transferred, no need to send it again, partName:" + partName + ", nodeRef:" + node.getNodeRef());
} }
} }
else else
{ {
if(log.isDebugEnabled()) if(log.isDebugEnabled())
{ {
log.debug("time different, require content for node : " + node.getNodeRef()); log.debug("part name not transferred, requesting new content item partName:" + partName + ", nodeRef:" + node.getNodeRef());
} }
out.missingContent(node.getNodeRef(), propEntry.getKey(), TransferCommons.URLToPartName(srcContent.getContentUrl())); out.missingContent(node.getNodeRef(), propEntry.getKey(), TransferCommons.URLToPartName(srcContent.getContentUrl()));
} }
} }
else else
{ {
// dest from contents is null
if(log.isDebugEnabled()) if(log.isDebugEnabled())
{ {
log.debug("no content on destination, content is required" + propEntry.getKey() + srcContent.getContentUrl()); log.debug("from contents is null, requesting new content item partName:" + partName + ", nodeRef:" + node.getNodeRef());
}
out.missingContent(node.getNodeRef(), propEntry.getKey(), TransferCommons.URLToPartName(srcContent.getContentUrl()));
}
}
else
{
/**
* Content property not empty and does not exist on destination
*/
if(log.isDebugEnabled())
{
log.debug("no content on destination, all content is required" + propEntry.getKey() + srcContent.getContentUrl());
} }
// We don't have the property on the destination node // We don't have the property on the destination node
out.missingContent(node.getNodeRef(), propEntry.getKey(), TransferCommons.URLToPartName(srcContent.getContentUrl())); out.missingContent(node.getNodeRef(), propEntry.getKey(), TransferCommons.URLToPartName(srcContent.getContentUrl()));
} }
}
} // src content url not null } // src content url not null
} // value is content data } // value is content data
} }
}
else else
{ {
log.debug("Node does not exist on destination nodeRef:" + node.getNodeRef()); log.debug("Node does not exist on destination nodeRef:" + node.getNodeRef());
/** /**
* there is no corresponding node so all content properties are "missing." * there is no corresponding node so all content properties are "missing."
*/ */

View File

@@ -40,6 +40,7 @@ import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParserFactory;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.ContentServicePolicies;
import org.alfresco.repo.copy.CopyBehaviourCallback; import org.alfresco.repo.copy.CopyBehaviourCallback;
import org.alfresco.repo.copy.CopyDetails; import org.alfresco.repo.copy.CopyDetails;
import org.alfresco.repo.copy.CopyServicePolicies; import org.alfresco.repo.copy.CopyServicePolicies;
@@ -96,7 +97,8 @@ public class RepoTransferReceiverImpl implements TransferReceiver,
NodeServicePolicies.OnCreateChildAssociationPolicy, NodeServicePolicies.OnCreateChildAssociationPolicy,
NodeServicePolicies.BeforeDeleteNodePolicy, NodeServicePolicies.BeforeDeleteNodePolicy,
NodeServicePolicies.OnRestoreNodePolicy, NodeServicePolicies.OnRestoreNodePolicy,
NodeServicePolicies.OnMoveNodePolicy NodeServicePolicies.OnMoveNodePolicy,
ContentServicePolicies.OnContentUpdatePolicy
{ {
/** /**
@@ -213,6 +215,14 @@ public class RepoTransferReceiverImpl implements TransferReceiver,
TransferModel.ASPECT_TRANSFERRED, TransferModel.ASPECT_TRANSFERRED,
new JavaBehaviour(this, "onCreateChildAssociation", NotificationFrequency.EVERY_EVENT)); new JavaBehaviour(this, "onCreateChildAssociation", NotificationFrequency.EVERY_EVENT));
/**
* For every update of a transferred node
*/
this.getPolicyComponent().bindClassBehaviour(
ContentServicePolicies.OnContentUpdatePolicy.QNAME,
TransferModel.ASPECT_TRANSFERRED,
new JavaBehaviour(this, "onContentUpdate", NotificationFrequency.EVERY_EVENT));
/** /**
* For every copy of a transferred node run onCopyTransferred * For every copy of a transferred node run onCopyTransferred
*/ */
@@ -1103,9 +1113,24 @@ public class RepoTransferReceiverImpl implements TransferReceiver,
log.debug("onMoveNode"); log.debug("onMoveNode");
log.debug("oldChildAssocRef:" + oldChildAssocRef); log.debug("oldChildAssocRef:" + oldChildAssocRef);
log.debug("newChildAssocRef:" + newChildAssocRef); log.debug("newChildAssocRef:" + newChildAssocRef);
NodeRef oldParentRef = oldChildAssocRef.getParentRef();
NodeRef newParentRef = newChildAssocRef.getParentRef();
if(newParentRef.equals(oldParentRef))
{
log.debug("old parent and new parent are the same - this is a rename, do nothing");
}
else
{
if(log.isDebugEnabled())
{
log.debug("moving node from oldParentRef:" + oldParentRef +" to:" + newParentRef);
}
alienProcessor.beforeDeleteAlien(newChildAssocRef.getChildRef(), oldChildAssocRef); alienProcessor.beforeDeleteAlien(newChildAssocRef.getChildRef(), oldChildAssocRef);
alienProcessor.afterMoveAlien(newChildAssocRef); alienProcessor.afterMoveAlien(newChildAssocRef);
} }
}
/** /**
* When a transferred node is copied, don't copy the transferred aspect. * When a transferred node is copied, don't copy the transferred aspect.
@@ -1223,4 +1248,18 @@ public class RepoTransferReceiverImpl implements TransferReceiver,
{ {
return alienProcessor; return alienProcessor;
} }
@Override
public void onContentUpdate(NodeRef nodeRef, boolean newContent)
{
/**
* On update of a transferred node remove the from content from property.
*/
log.debug("on content update called:" + nodeRef);
if(newContent)
{
log.debug("new content remove PROP_FROM_CONTENT from node:" + nodeRef);
nodeService.setProperty(nodeRef, TransferModel.PROP_FROM_CONTENT, null);
}
}
} }

View File

@@ -39,13 +39,13 @@ public interface TransferModel
static final QName ASPECT_TRANSFERRED = QName.createQName(TRANSFER_MODEL_1_0_URI, "transferred"); static final QName ASPECT_TRANSFERRED = QName.createQName(TRANSFER_MODEL_1_0_URI, "transferred");
static final QName PROP_REPOSITORY_ID = QName.createQName(TRANSFER_MODEL_1_0_URI, "repositoryId"); static final QName PROP_REPOSITORY_ID = QName.createQName(TRANSFER_MODEL_1_0_URI, "repositoryId");
static final QName PROP_FROM_REPOSITORY_ID = QName.createQName(TRANSFER_MODEL_1_0_URI, "fromRepositoryId"); static final QName PROP_FROM_REPOSITORY_ID = QName.createQName(TRANSFER_MODEL_1_0_URI, "fromRepositoryId");
static final QName PROP_FROM_CONTENT = QName.createQName(TRANSFER_MODEL_1_0_URI, "fromContent");
/** /**
* Aspect : alien * Aspect : alien
*/ */
static final QName ASPECT_ALIEN = QName.createQName(TRANSFER_MODEL_1_0_URI, "alien"); static final QName ASPECT_ALIEN = QName.createQName(TRANSFER_MODEL_1_0_URI, "alien");
static final QName PROP_INVADED_BY = QName.createQName(TRANSFER_MODEL_1_0_URI, "invadedBy"); static final QName PROP_INVADED_BY = QName.createQName(TRANSFER_MODEL_1_0_URI, "invadedBy");
// static final QName PROP_ALIEN = QName.createQName(TRANSFER_MODEL_1_0_URI, "alien");
/* /*
* Type : Transfer Group * Type : Transfer Group

View File

@@ -6976,413 +6976,412 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest
} // copy node } // copy node
// TODO - temp comment out of unit tests - will be tested on branch rather than head. /**
// /** * Test the transfer method with regard to an empty content property. ALF-4865
// * Test the transfer method with regard to an empty content property. ALF-4865 *
// * * Step 1: create a node with an empty content property
// * Step 1: create a node with an empty content property * transfer
// * transfer *
// * * Step 2: add non empty content property
// * Step 2: add non empty content property * transfer
// * transfer *
// * * Step 3: update from non empty content to empty content property
// * Step 3: update from non empty content to empty content property * transfer
// * transfer *
// * * This is a unit test so it does some shenanigans to send to the same instance of alfresco.
// * This is a unit test so it does some shenanigans to send to the same instance of alfresco. */
// */ public void testEmptyContent() throws Exception
// public void testEmptyContent() throws Exception {
// { setDefaultRollback(false);
// setDefaultRollback(false);
// String CONTENT_TITLE = "ContentTitle";
// String CONTENT_TITLE = "ContentTitle"; String CONTENT_TITLE_UPDATED = "ContentTitleUpdated";
// String CONTENT_TITLE_UPDATED = "ContentTitleUpdated"; Locale CONTENT_LOCALE = Locale.ENGLISH;
// Locale CONTENT_LOCALE = Locale.ENGLISH; String CONTENT_ENCODING = "UTF-8";
// String CONTENT_ENCODING = "UTF-8"; String CONTENT_STRING = "The quick brown fox jumps over the lazy dog.";
// String CONTENT_STRING = "The quick brown fox jumps over the lazy dog.";
// /**
// /** * For unit test
// * For unit test * - replace the HTTP transport with the in-process transport
// * - replace the HTTP transport with the in-process transport * - replace the node factory with one that will map node refs, paths etc.
// * - replace the node factory with one that will map node refs, paths etc. *
// * * Fake Repository Id
// * Fake Repository Id */
// */ TransferTransmitter transmitter = new UnitTestInProcessTransmitterImpl(receiver, contentService, transactionService);
// TransferTransmitter transmitter = new UnitTestInProcessTransmitterImpl(receiver, contentService, transactionService); transferServiceImpl.setTransmitter(transmitter);
// transferServiceImpl.setTransmitter(transmitter); UnitTestTransferManifestNodeFactory testNodeFactory = new UnitTestTransferManifestNodeFactory(this.transferManifestNodeFactory);
// UnitTestTransferManifestNodeFactory testNodeFactory = new UnitTestTransferManifestNodeFactory(this.transferManifestNodeFactory); transferServiceImpl.setTransferManifestNodeFactory(testNodeFactory);
// transferServiceImpl.setTransferManifestNodeFactory(testNodeFactory); List<Pair<Path, Path>> pathMap = testNodeFactory.getPathMap();
// List<Pair<Path, Path>> pathMap = testNodeFactory.getPathMap(); // Map company_home/guest_home to company_home so tranferred nodes and moved "up" one level.
// // Map company_home/guest_home to company_home so tranferred nodes and moved "up" one level. pathMap.add(new Pair<Path, Path>(PathHelper.stringToPath(GUEST_HOME_XPATH_QUERY), PathHelper.stringToPath(COMPANY_HOME_XPATH_QUERY)));
// pathMap.add(new Pair<Path, Path>(PathHelper.stringToPath(GUEST_HOME_XPATH_QUERY), PathHelper.stringToPath(COMPANY_HOME_XPATH_QUERY)));
// DescriptorService mockedDescriptorService = getMockDescriptorService(REPO_ID_A);
// DescriptorService mockedDescriptorService = getMockDescriptorService(REPO_ID_A); transferServiceImpl.setDescriptorService(mockedDescriptorService);
// transferServiceImpl.setDescriptorService(mockedDescriptorService);
// /**
// /** * Now go ahead and create our first transfer target
// * Now go ahead and create our first transfer target */
// */ String targetName = "testTransferEmptyContent";
// String targetName = "testTransferEmptyContent"; TransferTarget transferMe;
// TransferTarget transferMe; NodeRef contentNodeRef;
// NodeRef contentNodeRef; NodeRef savedDestinationNodeRef;
// NodeRef savedDestinationNodeRef;
// startNewTransaction();
// startNewTransaction(); try
// try {
// { /**
// /** * Get guest home
// * Get guest home */
// */ String guestHomeQuery = "/app:company_home/app:guest_home";
// String guestHomeQuery = "/app:company_home/app:guest_home"; ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery);
// ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); assertEquals("", 1, guestHomeResult.length());
// assertEquals("", 1, guestHomeResult.length()); NodeRef guestHome = guestHomeResult.getNodeRef(0);
// NodeRef guestHome = guestHomeResult.getNodeRef(0);
// /**
// /** * Create a test node with an empty content that we will read and write
// * Create a test node with an empty content that we will read and write */
// */ String name = GUID.generate();
// String name = GUID.generate(); ChildAssociationRef child = nodeService.createNode(guestHome, ContentModel.ASSOC_CONTAINS, QName.createQName(name), ContentModel.TYPE_CONTENT);
// ChildAssociationRef child = nodeService.createNode(guestHome, ContentModel.ASSOC_CONTAINS, QName.createQName(name), ContentModel.TYPE_CONTENT); contentNodeRef = child.getChildRef();
// contentNodeRef = child.getChildRef(); nodeService.setProperty(contentNodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE);
// nodeService.setProperty(contentNodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE); nodeService.setProperty(contentNodeRef, ContentModel.PROP_NAME, name);
// nodeService.setProperty(contentNodeRef, ContentModel.PROP_NAME, name); ContentData cd = new ContentData(null, null, 0, null);
// ContentData cd = new ContentData(null, null, 0, null); nodeService.setProperty(contentNodeRef, ContentModel.PROP_CONTENT, cd);
// nodeService.setProperty(contentNodeRef, ContentModel.PROP_CONTENT, cd);
// if(!transferService.targetExists(targetName))
// if(!transferService.targetExists(targetName)) {
// { transferMe = createTransferTarget(targetName);
// transferMe = createTransferTarget(targetName); }
// } else
// else {
// { transferMe = transferService.getTransferTarget(targetName);
// transferMe = transferService.getTransferTarget(targetName); }
// } transferService.enableTransferTarget(targetName, true);
// transferService.enableTransferTarget(targetName, true); }
// } finally
// finally {
// { endTransaction();
// endTransaction(); }
// }
// SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
// SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
//
//
//
// /**
// /** * Step 1: Transfer our node which has empty content
// * Step 1: Transfer our node which has empty content */
// */ logger.debug("testEmptyContent : First transfer - create new node (empty content)");
// logger.debug("testEmptyContent : First transfer - create new node (empty content)"); startNewTransaction();
// startNewTransaction(); try
// try {
// { ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT);
// ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT); assertNull("test setup content reader not null", reader);
// assertNull("test setup content reader not null", reader); Map<QName, Serializable> props = nodeService.getProperties(contentNodeRef);
// Map<QName, Serializable> props = nodeService.getProperties(contentNodeRef); assertTrue(props.containsKey(ContentModel.PROP_CONTENT));
// assertTrue(props.containsKey(ContentModel.PROP_CONTENT));
// TransferDefinition definition = new TransferDefinition();
// TransferDefinition definition = new TransferDefinition(); Set<NodeRef>nodes = new HashSet<NodeRef>();
// Set<NodeRef>nodes = new HashSet<NodeRef>(); nodes.add(contentNodeRef);
// nodes.add(contentNodeRef); definition.setNodes(nodes);
// definition.setNodes(nodes); transferService.transfer(targetName, definition);
// transferService.transfer(targetName, definition);
// }
// } finally
// finally {
// { endTransaction();
// endTransaction(); }
// }
// startNewTransaction();
// startNewTransaction(); try
// try {
// { Serializable modifiedDate = nodeService.getProperty(contentNodeRef, ContentModel.PROP_MODIFIED);
// Serializable modifiedDate = nodeService.getProperty(contentNodeRef, ContentModel.PROP_MODIFIED); if(modifiedDate instanceof Date)
// if(modifiedDate instanceof Date) {
// { logger.debug("srcModified: " + SDF.format(modifiedDate));
// logger.debug("srcModified: " + SDF.format(modifiedDate)); }
// }
// NodeRef destinationNodeRef = testNodeFactory.getMappedNodeRef(contentNodeRef);
// NodeRef destinationNodeRef = testNodeFactory.getMappedNodeRef(contentNodeRef); savedDestinationNodeRef = destinationNodeRef;
// savedDestinationNodeRef = destinationNodeRef; assertTrue("content node (dest) does not exist", nodeService.exists(destinationNodeRef));
// assertTrue("content node (dest) does not exist", nodeService.exists(destinationNodeRef));
// ContentReader reader = contentService.getReader(destinationNodeRef, ContentModel.PROP_CONTENT);
// ContentReader reader = contentService.getReader(destinationNodeRef, ContentModel.PROP_CONTENT); assertNull("content reader not null", reader);
// assertNull("content reader not null", reader); Map<QName, Serializable> props = nodeService.getProperties(destinationNodeRef);
// Map<QName, Serializable> props = nodeService.getProperties(destinationNodeRef); assertTrue(props.containsKey(ContentModel.PROP_CONTENT));
// assertTrue(props.containsKey(ContentModel.PROP_CONTENT));
// }
// } finally
// finally {
// { endTransaction();
// endTransaction(); }
// }
// /**
// /** * Step 2: replace empty content with new content
// * Step 2: replace empty content with new content */
// */ logger.debug("testEmptyContent : Second transfer - replace empty content with some content");
// logger.debug("testEmptyContent : Second transfer - replace empty content with some content");
// startNewTransaction();
// startNewTransaction(); try
// try {
// { Serializable modifiedDate = nodeService.getProperty(contentNodeRef, ContentModel.PROP_MODIFIED);
// Serializable modifiedDate = nodeService.getProperty(contentNodeRef, ContentModel.PROP_MODIFIED); if(modifiedDate instanceof Date)
// if(modifiedDate instanceof Date) {
// { logger.debug("srcModified: " + SDF.format(modifiedDate));
// logger.debug("srcModified: " + SDF.format(modifiedDate)); }
// }
// ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
// ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); writer.setLocale(CONTENT_LOCALE);
// writer.setLocale(CONTENT_LOCALE); writer.setEncoding(CONTENT_ENCODING);
// writer.setEncoding(CONTENT_ENCODING); writer.putContent(CONTENT_STRING);
// writer.putContent(CONTENT_STRING); }
// } finally
// finally {
// { endTransaction();
// endTransaction(); }
// }
// startNewTransaction();
// startNewTransaction(); try
// try {
// { ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT);
// ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT); assertNotNull("test setup content reader not null", reader);
// assertNotNull("test setup content reader not null", reader); Map<QName, Serializable> props = nodeService.getProperties(contentNodeRef);
// Map<QName, Serializable> props = nodeService.getProperties(contentNodeRef); assertTrue(props.containsKey(ContentModel.PROP_CONTENT));
// assertTrue(props.containsKey(ContentModel.PROP_CONTENT));
// /**
// /** * Step 2: replace empty content with new content
// * Step 2: replace empty content with new content */
// */ TransferDefinition definition = new TransferDefinition();
// TransferDefinition definition = new TransferDefinition(); Set<NodeRef>nodes = new HashSet<NodeRef>();
// Set<NodeRef>nodes = new HashSet<NodeRef>(); nodes.add(contentNodeRef);
// nodes.add(contentNodeRef); definition.setNodes(nodes);
// definition.setNodes(nodes); transferService.transfer(targetName, definition);
// transferService.transfer(targetName, definition);
// }
// } finally
// finally {
// { endTransaction();
// endTransaction(); }
// }
// startNewTransaction();
// startNewTransaction(); try
// try {
// { NodeRef destinationNodeRef = testNodeFactory.getMappedNodeRef(contentNodeRef);
// NodeRef destinationNodeRef = testNodeFactory.getMappedNodeRef(contentNodeRef);
// assertEquals("test error destinationNodeRef not correct", savedDestinationNodeRef, destinationNodeRef);
// assertEquals("test error destinationNodeRef not correct", savedDestinationNodeRef, destinationNodeRef); ContentReader reader = contentService.getReader(destinationNodeRef, ContentModel.PROP_CONTENT);
// ContentReader reader = contentService.getReader(destinationNodeRef, ContentModel.PROP_CONTENT); assertNotNull("content reader is null", reader);
// assertNotNull("content reader is null", reader); assertEquals("content encoding is wrong", reader.getEncoding(), CONTENT_ENCODING);
// assertEquals("content encoding is wrong", reader.getEncoding(), CONTENT_ENCODING); assertEquals("content locale is wrong", reader.getLocale(), CONTENT_LOCALE);
// assertEquals("content locale is wrong", reader.getLocale(), CONTENT_LOCALE); assertTrue("content does not exist", reader.exists());
// assertTrue("content does not exist", reader.exists()); String contentStr = reader.getContentString();
// String contentStr = reader.getContentString(); assertEquals("Content is wrong", contentStr, CONTENT_STRING);
// assertEquals("Content is wrong", contentStr, CONTENT_STRING); }
// } finally
// finally {
// { endTransaction();
// endTransaction(); }
// }
// /**
// /** * Step 3 - transition from a content property having content to one that is empty
// * Step 3 - transition from a content property having content to one that is empty */
// */ logger.debug("testEmptyContent : Third transfer - remove existing content");
// logger.debug("testEmptyContent : Third transfer - remove existing content");
// startNewTransaction();
// startNewTransaction(); try
// try {
// { ContentData cd = new ContentData(null, null, 0, null);
// ContentData cd = new ContentData(null, null, 0, null); nodeService.setProperty(contentNodeRef, ContentModel.PROP_CONTENT, cd);
// nodeService.setProperty(contentNodeRef, ContentModel.PROP_CONTENT, cd); }
// } finally
// finally {
// { endTransaction();
// endTransaction(); }
// }
// startNewTransaction();
// startNewTransaction(); try
// try {
// { ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT);
// ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT); assertNull("test setup content reader not null", reader);
// assertNull("test setup content reader not null", reader); Map<QName, Serializable> props = nodeService.getProperties(contentNodeRef);
// Map<QName, Serializable> props = nodeService.getProperties(contentNodeRef); assertTrue(props.containsKey(ContentModel.PROP_CONTENT));
// assertTrue(props.containsKey(ContentModel.PROP_CONTENT));
// /**
// /** * Step 3: Transfer our node which has empty content to over-write existing
// * Step 3: Transfer our node which has empty content to over-write existing * content
// * content */
// */ TransferDefinition definition = new TransferDefinition();
// TransferDefinition definition = new TransferDefinition(); Set<NodeRef>nodes = new HashSet<NodeRef>();
// Set<NodeRef>nodes = new HashSet<NodeRef>(); nodes.add(contentNodeRef);
// nodes.add(contentNodeRef); definition.setNodes(nodes);
// definition.setNodes(nodes); transferService.transfer(targetName, definition);
// transferService.transfer(targetName, definition); }
// } finally
// finally {
// { endTransaction();
// endTransaction(); }
// }
// startNewTransaction();
// startNewTransaction(); try
// try {
// { NodeRef destinationNodeRef = testNodeFactory.getMappedNodeRef(contentNodeRef);
// NodeRef destinationNodeRef = testNodeFactory.getMappedNodeRef(contentNodeRef); assertTrue("content node (dest) does not exist", nodeService.exists(destinationNodeRef));
// assertTrue("content node (dest) does not exist", nodeService.exists(destinationNodeRef));
// ContentReader reader = contentService.getReader(destinationNodeRef, ContentModel.PROP_CONTENT);
// ContentReader reader = contentService.getReader(destinationNodeRef, ContentModel.PROP_CONTENT); assertNull("content reader not null", reader);
// assertNull("content reader not null", reader); Map<QName, Serializable> props = nodeService.getProperties(destinationNodeRef);
// Map<QName, Serializable> props = nodeService.getProperties(destinationNodeRef); assertTrue(props.containsKey(ContentModel.PROP_CONTENT));
// assertTrue(props.containsKey(ContentModel.PROP_CONTENT));
// }
// } finally
// finally {
// { endTransaction();
// endTransaction(); }
// }
// } // end of testEmptyContent
// } // end of testEmptyContent
//
// /**
// /** * Test the transfer method with regard to a repeated update of content.by sending one node (CRUD).
// * Test the transfer method with regard to a repeated update of content.by sending one node (CRUD). *
// * * This is a unit test so it does some shenanigans to send to the same instance of alfresco.
// * This is a unit test so it does some shenanigans to send to the same instance of alfresco. */
// */ public void testRepeatUpdateOfContent() throws Exception
// public void testRepeatUpdateOfContent() throws Exception {
// { final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
// final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper(); final String CONTENT_TITLE = "ContentTitle";
// final String CONTENT_TITLE = "ContentTitle"; final Locale CONTENT_LOCALE = Locale.GERMAN;
// final Locale CONTENT_LOCALE = Locale.GERMAN; final String CONTENT_ENCODING = "UTF-8";
// final String CONTENT_ENCODING = "UTF-8";
// /**
// /** * For unit test
// * For unit test * - replace the HTTP transport with the in-process transport
// * - replace the HTTP transport with the in-process transport * - replace the node factory with one that will map node refs, paths etc.
// * - replace the node factory with one that will map node refs, paths etc. *
// * * Fake Repository Id
// * Fake Repository Id */
// */ final TransferTransmitter transmitter = new UnitTestInProcessTransmitterImpl(receiver, contentService, transactionService);
// final TransferTransmitter transmitter = new UnitTestInProcessTransmitterImpl(receiver, contentService, transactionService); transferServiceImpl.setTransmitter(transmitter);
// transferServiceImpl.setTransmitter(transmitter); final UnitTestTransferManifestNodeFactory testNodeFactory = new UnitTestTransferManifestNodeFactory(this.transferManifestNodeFactory);
// final UnitTestTransferManifestNodeFactory testNodeFactory = new UnitTestTransferManifestNodeFactory(this.transferManifestNodeFactory); transferServiceImpl.setTransferManifestNodeFactory(testNodeFactory);
// transferServiceImpl.setTransferManifestNodeFactory(testNodeFactory); final List<Pair<Path, Path>> pathMap = testNodeFactory.getPathMap();
// final List<Pair<Path, Path>> pathMap = testNodeFactory.getPathMap(); // Map company_home/guest_home to company_home so tranferred nodes and moved "up" one level.
// // Map company_home/guest_home to company_home so tranferred nodes and moved "up" one level. pathMap.add(new Pair<Path, Path>(PathHelper.stringToPath(GUEST_HOME_XPATH_QUERY), PathHelper.stringToPath(COMPANY_HOME_XPATH_QUERY)));
// pathMap.add(new Pair<Path, Path>(PathHelper.stringToPath(GUEST_HOME_XPATH_QUERY), PathHelper.stringToPath(COMPANY_HOME_XPATH_QUERY)));
// DescriptorService mockedDescriptorService = getMockDescriptorService(REPO_ID_A);
// DescriptorService mockedDescriptorService = getMockDescriptorService(REPO_ID_A); transferServiceImpl.setDescriptorService(mockedDescriptorService);
// transferServiceImpl.setDescriptorService(mockedDescriptorService);
// final String targetName = "testRepeatUpdateOfContent";
// final String targetName = "testRepeatUpdateOfContent";
// class TestContext
// class TestContext {
// { TransferTarget transferMe;
// TransferTarget transferMe; NodeRef contentNodeRef;
// NodeRef contentNodeRef; NodeRef destNodeRef;
// NodeRef destNodeRef; String contentString;
// String contentString; };
// };
// RetryingTransactionCallback<TestContext> setupCB = new RetryingTransactionCallback<TestContext>()
// RetryingTransactionCallback<TestContext> setupCB = new RetryingTransactionCallback<TestContext>() {
// { @Override
// @Override public TestContext execute() throws Throwable
// public TestContext execute() throws Throwable {
// { TestContext testContext = new TestContext();
// TestContext testContext = new TestContext();
// /**
// /** * Get guest home
// * Get guest home */
// */ String guestHomeQuery = "/app:company_home/app:guest_home";
// String guestHomeQuery = "/app:company_home/app:guest_home"; ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery);
// ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); assertEquals("", 1, guestHomeResult.length());
// assertEquals("", 1, guestHomeResult.length()); NodeRef guestHome = guestHomeResult.getNodeRef(0);
// NodeRef guestHome = guestHomeResult.getNodeRef(0);
// /**
// /** * Create a test node that we will read and write
// * Create a test node that we will read and write */
// */ String name = GUID.generate();
// String name = GUID.generate(); ChildAssociationRef child = nodeService.createNode(guestHome, ContentModel.ASSOC_CONTAINS, QName.createQName(name), ContentModel.TYPE_CONTENT);
// ChildAssociationRef child = nodeService.createNode(guestHome, ContentModel.ASSOC_CONTAINS, QName.createQName(name), ContentModel.TYPE_CONTENT); testContext.contentNodeRef = child.getChildRef();
// testContext.contentNodeRef = child.getChildRef(); nodeService.setProperty(testContext.contentNodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE);
// nodeService.setProperty(testContext.contentNodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE); nodeService.setProperty(testContext.contentNodeRef, ContentModel.PROP_NAME, name);
// nodeService.setProperty(testContext.contentNodeRef, ContentModel.PROP_NAME, name);
// /**
// /** * Make sure the transfer target exists and is enabled.
// * Make sure the transfer target exists and is enabled. */
// */ if(!transferService.targetExists(targetName))
// if(!transferService.targetExists(targetName)) {
// { testContext.transferMe = createTransferTarget(targetName);
// testContext.transferMe = createTransferTarget(targetName); }
// } else
// else {
// { testContext.transferMe = transferService.getTransferTarget(targetName);
// testContext.transferMe = transferService.getTransferTarget(targetName); }
// } transferService.enableTransferTarget(targetName, true);
// transferService.enableTransferTarget(targetName, true); return testContext;
// return testContext; }
// } };
// };
// final TestContext testContext = tran.doInTransaction(setupCB);
// final TestContext testContext = tran.doInTransaction(setupCB);
// RetryingTransactionCallback<Void> updateContentCB = new RetryingTransactionCallback<Void>() {
// RetryingTransactionCallback<Void> updateContentCB = new RetryingTransactionCallback<Void>() {
// @Override
// @Override public Void execute() throws Throwable
// public Void execute() throws Throwable {
// { ContentWriter writer = contentService.getWriter(testContext.contentNodeRef, ContentModel.PROP_CONTENT, true);
// ContentWriter writer = contentService.getWriter(testContext.contentNodeRef, ContentModel.PROP_CONTENT, true); writer.setLocale(CONTENT_LOCALE);
// writer.setLocale(CONTENT_LOCALE); writer.setEncoding(CONTENT_ENCODING);
// writer.setEncoding(CONTENT_ENCODING); writer.putContent(testContext.contentString);
// writer.putContent(testContext.contentString); return null;
// return null; }
// } };
// };
// RetryingTransactionCallback<Void> transferCB = new RetryingTransactionCallback<Void>() {
// RetryingTransactionCallback<Void> transferCB = new RetryingTransactionCallback<Void>() {
// @Override
// @Override public Void execute() throws Throwable
// public Void execute() throws Throwable {
// { TransferDefinition definition = new TransferDefinition();
// TransferDefinition definition = new TransferDefinition(); Set<NodeRef>nodes = new HashSet<NodeRef>();
// Set<NodeRef>nodes = new HashSet<NodeRef>(); nodes.add(testContext.contentNodeRef);
// nodes.add(testContext.contentNodeRef); definition.setNodes(nodes);
// definition.setNodes(nodes); transferService.transfer(targetName, definition);
// transferService.transfer(targetName, definition); return null;
// return null; }
// } };
// };
// RetryingTransactionCallback<Void> checkTransferCB = new RetryingTransactionCallback<Void>() {
// RetryingTransactionCallback<Void> checkTransferCB = new RetryingTransactionCallback<Void>() {
// @Override
// @Override public Void execute() throws Throwable
// public Void execute() throws Throwable {
// { // Now validate that the target node exists and has similar properties to the source
// // Now validate that the target node exists and has similar properties to the source NodeRef destNodeRef = testNodeFactory.getMappedNodeRef(testContext.contentNodeRef);
// NodeRef destNodeRef = testNodeFactory.getMappedNodeRef(testContext.contentNodeRef);
// ContentReader reader = contentService.getReader(destNodeRef, ContentModel.PROP_CONTENT);
// ContentReader reader = contentService.getReader(destNodeRef, ContentModel.PROP_CONTENT); assertNotNull("content reader is null", reader);
// assertNotNull("content reader is null", reader); assertEquals("content encoding is wrong", reader.getEncoding(), CONTENT_ENCODING);
// assertEquals("content encoding is wrong", reader.getEncoding(), CONTENT_ENCODING); assertEquals("content locale is wrong", reader.getLocale(), CONTENT_LOCALE);
// assertEquals("content locale is wrong", reader.getLocale(), CONTENT_LOCALE); assertTrue("content does not exist", reader.exists());
// assertTrue("content does not exist", reader.exists()); String contentStr = reader.getContentString();
// String contentStr = reader.getContentString(); assertEquals("Content is wrong", contentStr, testContext.contentString);
// assertEquals("Content is wrong", contentStr, testContext.contentString);
// return null;
// return null; }
// } };
// };
// /**
// /** * This is the test
// * This is the test */
// */ for(int i = 0; i < 6 ; i++)
// for(int i = 0; i < 6 ; i++) {
// { logger.debug("testRepeatUpdateContent - iteration:" + i);
// logger.debug("testRepeatUpdateContent - iteration:" + i); testContext.contentString = String.valueOf(i);
// testContext.contentString = String.valueOf(i); tran.doInTransaction(updateContentCB);
// tran.doInTransaction(updateContentCB); tran.doInTransaction(transferCB);
// tran.doInTransaction(transferCB); tran.doInTransaction(checkTransferCB);
// tran.doInTransaction(checkTransferCB); }
// } } // test repeat update content
// } // test repeat update content
private void createUser(String userName, String password) private void createUser(String userName, String password)