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);
@@ -937,13 +930,33 @@ public class RepoPrimaryManifestProcessorImpl extends AbstractManifestProcessorB
* inject transferred * inject transferred
*/ */
private void injectTransferred(Map<QName, Serializable> props) private void injectTransferred(Map<QName, Serializable> props)
{ {
if(!props.containsKey(TransferModel.PROP_REPOSITORY_ID)) if(!props.containsKey(TransferModel.PROP_REPOSITORY_ID))
{ {
log.debug("injecting repositoryId property"); log.debug("injecting repositoryId property");
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()); /**
if(destSer != null && ContentData.class.isAssignableFrom(destSer.getClass())) * Source Content is not empty
*/
String partName = TransferCommons.URLToPartName(srcContent.getContentUrl());
Serializable destSer = destinationProps.get(propName);
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())
{
SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
log.debug ("srcModified :" + srcModified + "destModified :" + destModified);
if(srcModified instanceof Date)
{
log.debug("srcModified: " + SDF.format(srcModified));
}
if(destModified instanceof Date)
{
log.debug("destModified: " + SDF.format(destModified));
}
}
if(srcModified != null && Serializable destFromContents = destinationProps.get(TransferModel.PROP_FROM_CONTENT);
destModified != null &&
srcModified instanceof Date && if(destFromContents != null && Collection.class.isAssignableFrom(destFromContents.getClass()))
destModified instanceof Date &&
((Date)srcModified).getTime() <= ((Date)destModified).getTime())
{ {
if(log.isDebugEnabled()) Collection<String> contents = (Collection<String>)destFromContents;
/**
* Content property not empty and content property already exists on destination
*/
if(contents.contains(partName))
{ {
log.debug("the modified date is the same or before - no need send content:" + node.getNodeRef()); if(log.isDebugEnabled())
{
log.debug("part already transferred, no need to send it again, partName:" + partName + ", nodeRef:" + node.getNodeRef());
}
}
else
{
if(log.isDebugEnabled())
{
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()));
} }
} }
else else
{ {
// dest from contents is null
if(log.isDebugEnabled()) if(log.isDebugEnabled())
{ {
log.debug("time different, require content for node : " + node.getNodeRef()); 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())); out.missingContent(node.getNodeRef(), propEntry.getKey(), TransferCommons.URLToPartName(srcContent.getContentUrl()));
} }
} }
else else
{ {
/**
* Content property not empty and does not exist on destination
*/
if(log.isDebugEnabled()) if(log.isDebugEnabled())
{ {
log.debug("no content on destination, content is required" + propEntry.getKey() + srcContent.getContentUrl()); 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 }
} // value is content data } // src content url not null
} } // 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,8 +1113,23 @@ 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);
alienProcessor.beforeDeleteAlien(newChildAssocRef.getChildRef(), oldChildAssocRef);
alienProcessor.afterMoveAlien(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.afterMoveAlien(newChildAssocRef);
}
} }
/** /**
@@ -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

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