diff --git a/config/alfresco/web-publishing-context.xml b/config/alfresco/web-publishing-context.xml
index bee44bf1aa..86f5ad4271 100644
--- a/config/alfresco/web-publishing-context.xml
+++ b/config/alfresco/web-publishing-context.xml
@@ -103,7 +103,7 @@
-
+
diff --git a/source/java/org/alfresco/repo/publishing/NodeSnapshotTransferImpl.java b/source/java/org/alfresco/repo/publishing/NodeSnapshotTransferImpl.java
index 644f8af238..d41a33d765 100644
--- a/source/java/org/alfresco/repo/publishing/NodeSnapshotTransferImpl.java
+++ b/source/java/org/alfresco/repo/publishing/NodeSnapshotTransferImpl.java
@@ -20,6 +20,7 @@
package org.alfresco.repo.publishing;
import java.io.Serializable;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -42,7 +43,6 @@ import org.alfresco.service.namespace.QName;
public class NodeSnapshotTransferImpl implements NodeSnapshot
{
private final TransferManifestNormalNode transferNode;
- private final String version;
/**
* @param transferNode
@@ -50,88 +50,107 @@ public class NodeSnapshotTransferImpl implements NodeSnapshot
public NodeSnapshotTransferImpl(TransferManifestNormalNode transferNode)
{
this.transferNode = transferNode;
- Map props = transferNode.getProperties();
- this.version = (String) props.get(ContentModel.PROP_VERSION_LABEL);
}
- /* (non-Javadoc)
- * @see org.alfresco.service.cmr.publishing.NodeSnapshot#getAllParentAssocs()
- */
public List getAllParentAssocs()
{
+ if(transferNode==null)
+ {
+ return Collections.emptyList();
+ }
return transferNode.getParentAssocs();
}
- /* (non-Javadoc)
- * @see org.alfresco.service.cmr.publishing.NodeSnapshot#getAspects()
+ /**
+ * {@inheritDoc}
*/
-
public Set getAspects()
{
+ if(transferNode==null)
+ {
+ return Collections.emptySet();
+ }
return transferNode.getAspects();
}
- /* (non-Javadoc)
- * @see org.alfresco.service.cmr.publishing.NodeSnapshot#getNodeRef()
- */
-
+ /**
+ * {@inheritDoc}
+ */
public NodeRef getNodeRef()
{
+ if(transferNode==null)
+ {
+ return null;
+ }
return transferNode.getNodeRef();
}
- /* (non-Javadoc)
- * @see org.alfresco.service.cmr.publishing.NodeSnapshot#getOutboundPeerAssociations()
+ /**
+ * @return
*/
-
public List getOutboundPeerAssociations()
{
+ if(transferNode==null)
+ {
+ return Collections.emptyList();
+ }
return transferNode.getTargetAssocs();
}
- /* (non-Javadoc)
- * @see org.alfresco.service.cmr.publishing.NodeSnapshot#getPrimaryParentAssoc()
+ /**
+ * @return
*/
-
public ChildAssociationRef getPrimaryParentAssoc()
{
+ if(transferNode==null)
+ {
+ return null;
+ }
return transferNode.getPrimaryParentAssoc();
}
- /* (non-Javadoc)
- * @see org.alfresco.service.cmr.publishing.NodeSnapshot#getPrimaryPath()
+ /**
+ * @return
*/
-
public Path getPrimaryPath()
{
+ if(transferNode==null)
+ {
+ return null;
+ }
return transferNode.getParentPath();
}
- /* (non-Javadoc)
- * @see org.alfresco.service.cmr.publishing.NodeSnapshot#getProperties()
+ /**
+ * {@inheritDoc}
*/
-
public Map getProperties()
{
+ if(transferNode==null)
+ {
+ return Collections.emptyMap();
+ }
return transferNode.getProperties();
}
- /* (non-Javadoc)
- * @see org.alfresco.service.cmr.publishing.NodeSnapshot#getType()
+ /**
+ * {@inheritDoc}
*/
-
public QName getType()
{
+ if(transferNode==null)
+ {
+ return null;
+ }
return transferNode.getType();
}
/**
* {@inheritDoc}
*/
-
public String getVersion()
{
- return version;
+ return (String) getProperties().get(ContentModel.PROP_VERSION_LABEL);
}
/**
diff --git a/source/java/org/alfresco/repo/publishing/PublishEventActionTest.java b/source/java/org/alfresco/repo/publishing/PublishEventActionTest.java
index f35053d203..0b04758ded 100644
--- a/source/java/org/alfresco/repo/publishing/PublishEventActionTest.java
+++ b/source/java/org/alfresco/repo/publishing/PublishEventActionTest.java
@@ -46,7 +46,12 @@ import javax.annotation.Resource;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
+import org.alfresco.repo.transaction.RetryingTransactionHelper;
+import org.alfresco.service.cmr.publishing.NodeSnapshot;
import org.alfresco.service.cmr.publishing.PublishingDetails;
+import org.alfresco.service.cmr.publishing.PublishingEvent;
+import org.alfresco.service.cmr.publishing.PublishingPackage;
+import org.alfresco.service.cmr.publishing.PublishingPackageEntry;
import org.alfresco.service.cmr.publishing.PublishingService;
import org.alfresco.service.cmr.publishing.Status;
import org.alfresco.service.cmr.publishing.channels.Channel;
@@ -215,12 +220,30 @@ public class PublishEventActionTest extends AbstractPublishingIntegrationTest
assertTrue(nodeService.exists(publishedNode));
// Unpublish source node.
- publishNode(source, null, false);
+ NodeRef eventNode = publishNode(source, null, false);
// Check the published node no longer exists.
assertFalse(nodeService.exists(publishedNode));
publishedNode = channelHelper.mapSourceToEnvironment(source, channelNode);
assertNull(publishedNode);
+
+ // Check can generate a valid snapshot for the unpublish entry.
+ PublishingEvent event = publishingService.getPublishingEvent(eventNode.toString());
+ PublishingPackage packg = event.getPackage();
+
+ Set toUnpublish = packg.getNodesToUnpublish();
+ assertEquals(1, toUnpublish.size());
+ assertTrue(toUnpublish.contains(source));
+
+ PublishingPackageEntry entry = packg.getEntryMap().get(source);
+ assertEquals(false, entry.isPublish());
+
+ NodeSnapshot snapshot = entry.getSnapshot();
+ assertEquals(source, snapshot.getNodeRef());
+ assertEquals(ContentModel.TYPE_CONTENT, snapshot.getType());
+ Serializable name = nodeService.getProperty(source, ContentModel.PROP_NAME);
+ assertEquals(name, snapshot.getProperties().get(ContentModel.PROP_NAME));
+
}
@SuppressWarnings("unchecked")
diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java b/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java
index 719806f7a5..d2f8db0534 100644
--- a/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java
+++ b/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java
@@ -42,7 +42,6 @@ import static org.alfresco.util.collections.CollectionUtils.isEmpty;
import static org.alfresco.util.collections.CollectionUtils.toListOfStrings;
import static org.alfresco.util.collections.CollectionUtils.transform;
import static org.alfresco.util.collections.CollectionUtils.transformFlat;
-import static org.alfresco.util.collections.CollectionUtils.transformToMap;
import java.io.InputStream;
import java.io.OutputStream;
@@ -90,7 +89,6 @@ import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.GUID;
-import org.alfresco.util.collections.CollectionUtils;
import org.alfresco.util.collections.Filter;
import org.alfresco.util.collections.Function;
import org.apache.commons.logging.Log;
@@ -506,7 +504,9 @@ public class PublishingEventHelper
{
try
{
+ NodeRef channelNode = new NodeRef(details.getPublishChannelId());
List snapshots = createPublishSnapshots(details.getNodesToPublish());
+ snapshots.addAll(createUnpublishSnapshots(details.getNodesToUnpublish(), channelNode));
ContentWriter contentWriter = contentService.getWriter(eventNode,
PROP_PUBLISHING_EVENT_PAYLOAD, true);
contentWriter.setEncoding("UTF-8");
@@ -522,31 +522,24 @@ public class PublishingEventHelper
}
}
- private PublishingPackage getPublishingPackage(NodeRef eventNode, String channelId) throws AlfrescoRuntimeException
+ private List createUnpublishSnapshots(Set nodes, final NodeRef channelNode)
{
- Map publishEntires = getPublishEntries(eventNode);
- Map allEntries = getUnpublishEntries(eventNode, channelId);
- allEntries.putAll(publishEntires);
- return new PublishingPackageImpl(allEntries);
- }
-
- public Map createPublishEntries(Collection nodesToAdd)
- {
- return transformToMap(nodesToAdd, new Function()
+ return transform(nodes, new Function()
{
- public PublishingPackageEntry apply(NodeRef node)
+ public NodeSnapshot apply(NodeRef node)
{
- return createPublishEntry(node);
+ return createUnpublishSnapshot(node, channelNode);
}
});
}
- private PublishingPackageEntry createPublishEntry(NodeRef node)
+ private PublishingPackage getPublishingPackage(NodeRef eventNode, String channelId) throws AlfrescoRuntimeException
{
- NodeSnapshotTransferImpl snapshot = createPublishSnapshot(node);
- return new PublishingPackageEntryImpl(true, node, snapshot);
+ Map entries = getPublishingPackageEntries(eventNode);
+ return new PublishingPackageImpl(entries);
}
+
private List createPublishSnapshots(final Collection nodes)
{
return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork>()
@@ -572,8 +565,11 @@ public class PublishingEventHelper
return snapshot;
}
- private Map getPublishEntries(NodeRef eventNode)
+ @SuppressWarnings("unchecked")
+ private Map getPublishingPackageEntries(NodeRef eventNode)
{
+ List idsToUnpublish = (List) nodeService.getProperty(eventNode, PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH);
+ List nodesToUnpublish = NodeUtils.toNodeRefs(idsToUnpublish);
ContentReader contentReader = contentService.getReader(eventNode, PROP_PUBLISHING_EVENT_PAYLOAD);
InputStream input = contentReader.getContentInputStream();
try
@@ -583,7 +579,8 @@ public class PublishingEventHelper
for (NodeSnapshot snapshot : snapshots)
{
NodeRef node = snapshot.getNodeRef();
- PublishingPackageEntryImpl entry = new PublishingPackageEntryImpl(true, node, snapshot);
+ boolean isPublish = false == nodesToUnpublish.contains(node);
+ PublishingPackageEntryImpl entry = new PublishingPackageEntryImpl(isPublish, node, snapshot);
entries.put(node, entry);
}
return entries;
@@ -595,40 +592,18 @@ public class PublishingEventHelper
}
}
- public Map getUnpublishEntries(NodeRef eventNode, String channelId)
- {
- @SuppressWarnings("unchecked")
- List entries= (List) nodeService.getProperty(eventNode, PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH);
- if(CollectionUtils.isEmpty(entries))
- {
- return new HashMap();
- }
- final NodeRef channelNode = new NodeRef(channelId);
- List nodes = NodeUtils.toNodeRefs(entries);
- return transformToMap(nodes, new Function()
- {
- public PublishingPackageEntry apply(NodeRef node)
- {
- if(NodeUtils.exists(node, nodeService))
- {
- return makeUnpublishEntry(node, channelNode);
- }
- return null;
- }
- });
- }
- private PublishingPackageEntry makeUnpublishEntry(NodeRef source, NodeRef channelNode)
+ private NodeSnapshot createUnpublishSnapshot(NodeRef source, NodeRef channelNode)
{
NodeRef lastEvent = getLastPublishEvent(source, channelNode);
- NodeSnapshot snapshot = null;
- if(lastEvent!=null)
+ if(lastEvent==null)
{
- Map entries = getPublishEntries(lastEvent);
- PublishingPackageEntry entry = entries.get(source);
- snapshot = entry.getSnapshot();
+ String msg = "Cannot create unpublish snapshot as last publishing event does not exist! Source node: "+ source + " channelId: "+channelNode;
+ throw new AlfrescoRuntimeException(msg);
}
- return new PublishingPackageEntryImpl(false, source, snapshot);
+ Map entries = getPublishingPackageEntries(lastEvent);
+ PublishingPackageEntry entry = entries.get(source);
+ return entry.getSnapshot();
}
public NodeRef getLastPublishEvent(NodeRef source, NodeRef channelNode)
@@ -684,55 +659,8 @@ public class PublishingEventHelper
return nodeService.createAssociation(publishedNode, eventNode, ASSOC_LAST_PUBLISHING_EVENT);
}
- public PublishingDetails createPublishingPackageBuilder()
+ public PublishingDetails createPublishingDetails()
{
return new PublishingDetailsImpl();
}
-
-// public NodePublishStatus checkNodeStatus(NodeRef node, String channelId, NodeRef queue)
-// {
-// PublishingEvent queuedEvent = getQueuedPublishingEvent(node, channelId, queue);
-// PublishingEvent lastEvent= getLastPublishingEvent(node, channelId, queue);
-// if(queuedEvent != null)
-// {
-// if(lastEvent != null)
-// {
-// return new NodePublishStatusPublishedAndOnQueue(node, channelId, queuedEvent, lastEvent);
-// }
-// else
-// {
-// return new NodePublishStatusOnQueue(node, channelId, queuedEvent);
-// }
-// }
-// else
-// {
-// if(lastEvent != null)
-// {
-// return new NodePublishStatusPublished(node, channelId, lastEvent);
-// }
-// else
-// {
-// return new NodePublishStatusNotPublished(node, channelId);
-// }
-// }
-// }
-//
-// private PublishingEvent getLastPublishingEvent(NodeRef node, String channelId, NodeRef queue)
-// {
-// getEventNodesForPublishedNode(queue, node);
-// return null;
-// }
-//
-// private PublishingEvent getQueuedPublishingEvent(NodeRef node, String channelId)
-// {
-// return publishingEventHelper.getPublishingEvent(nextEventNode);
-// }
-//
-// private boolean isActiveEvent(NodeRef eventNode)
-// {
-// String statusStr = (String) nodeService.getProperty( eventNode, PROP_PUBLISHING_EVENT_STATUS);
-// Status status = Status.valueOf(statusStr);
-// return status == Status.IN_PROGRESS || status == Status.SCHEDULED;
-// }
-
}
diff --git a/source/java/org/alfresco/repo/publishing/PublishingPackageSerializerTest.java b/source/java/org/alfresco/repo/publishing/PublishingPackageSerializerTest.java
index db9e271ea9..ed9e40b5ca 100644
--- a/source/java/org/alfresco/repo/publishing/PublishingPackageSerializerTest.java
+++ b/source/java/org/alfresco/repo/publishing/PublishingPackageSerializerTest.java
@@ -55,7 +55,7 @@ import org.junit.Test;
public class PublishingPackageSerializerTest extends AbstractPublishingIntegrationTest
{
@Resource(name="publishingPackageSerializer")
- private StandardPublishingPackageSerializer serializer;
+ private StandardNodeSnapshotSerializer serializer;
private TransferManifestNormalNode normalNode1;
@@ -67,7 +67,7 @@ public class PublishingPackageSerializerTest extends AbstractPublishingIntegrati
public void onSetUp() throws Exception
{
super.onSetUp();
- serializer = (StandardPublishingPackageSerializer) getApplicationContext().getBean("publishingPackageSerializer");
+ serializer = (StandardNodeSnapshotSerializer) getApplicationContext().getBean("publishingPackageSerializer");
normalNode1 = new TransferManifestNormalNode();
normalNode1.setAccessControl(null);
diff --git a/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java b/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java
index d979fad430..7841619ac3 100644
--- a/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java
+++ b/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java
@@ -53,7 +53,7 @@ public class PublishingQueueImpl implements PublishingQueue
*/
public PublishingDetails createPublishingDetails()
{
- return publishingEventHelper.createPublishingPackageBuilder();
+ return publishingEventHelper.createPublishingDetails();
}
/**
diff --git a/source/java/org/alfresco/repo/publishing/PublishingQueueImplTest.java b/source/java/org/alfresco/repo/publishing/PublishingQueueImplTest.java
index 3073f1eb5d..f60367620e 100644
--- a/source/java/org/alfresco/repo/publishing/PublishingQueueImplTest.java
+++ b/source/java/org/alfresco/repo/publishing/PublishingQueueImplTest.java
@@ -33,7 +33,10 @@ import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
+import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
+import org.alfresco.repo.transaction.RetryingTransactionHelper;
+import org.alfresco.service.cmr.publishing.NodeSnapshot;
import org.alfresco.service.cmr.publishing.PublishingDetails;
import org.alfresco.service.cmr.publishing.PublishingEvent;
import org.alfresco.service.cmr.publishing.PublishingPackage;
@@ -69,7 +72,6 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest
{
NodeRef firstNode = createContent("First");
NodeRef secondNode = createContent("second");
- NodeRef thirdNode = createContent("third");
assertNull(nodeService.getProperty(firstNode, PROP_VERSION_LABEL));
assertNull(nodeService.getProperty(firstNode, PROP_VERSION_LABEL));
@@ -79,7 +81,6 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest
PublishingDetails details = publishingService.getPublishingQueue().createPublishingDetails()
.addNodesToPublish(firstNode, secondNode)
- .addNodesToUnpublish(thirdNode)
.setPublishChannel(channelId)
.setSchedule(schedule)
.setComment(comment);
@@ -119,8 +120,7 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest
assertTrue(toPublish.contains(firstNode));
assertTrue(toPublish.contains(secondNode));
- assertEquals(1, toUnpublish.size());
- assertTrue(toUnpublish.contains(thirdNode));
+ assertEquals(0, toUnpublish.size());
// Check the correct version is recorded in the entry.
PublishingPackageEntry entry = pckg.getEntryMap().get(firstNode);
diff --git a/source/java/org/alfresco/repo/publishing/PublishingTestHelper.java b/source/java/org/alfresco/repo/publishing/PublishingTestHelper.java
index de8c72fc31..1f2aa1a71a 100644
--- a/source/java/org/alfresco/repo/publishing/PublishingTestHelper.java
+++ b/source/java/org/alfresco/repo/publishing/PublishingTestHelper.java
@@ -38,10 +38,14 @@ import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
+import org.alfresco.repo.transaction.RetryingTransactionHelper;
+import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.publishing.PublishingDetails;
+import org.alfresco.service.cmr.publishing.PublishingEvent;
import org.alfresco.service.cmr.publishing.PublishingQueue;
import org.alfresco.service.cmr.publishing.PublishingService;
+import org.alfresco.service.cmr.publishing.Status;
import org.alfresco.service.cmr.publishing.channels.Channel;
import org.alfresco.service.cmr.publishing.channels.ChannelService;
import org.alfresco.service.cmr.publishing.channels.ChannelType;
@@ -272,4 +276,31 @@ public class PublishingTestHelper
writer.putContent(theContent);
}
+
+ public PublishingEvent publishAndWait(final PublishingDetails details, RetryingTransactionHelper transactionHelper) throws InterruptedException
+ {
+ RetryingTransactionCallback startWorkflowCallback = new RetryingTransactionCallback()
+ {
+ public String execute() throws Throwable
+ {
+ return scheduleEvent(details);
+ }
+ };
+ String eventId = transactionHelper.doInTransaction(startWorkflowCallback);
+
+ int i = 0;
+ while(i<100)
+ {
+ Thread.sleep(200);
+ PublishingEvent event = publishingService.getPublishingEvent(eventId);
+ Status status = event.getStatus();
+ if(Status.IN_PROGRESS!=status && Status.SCHEDULED!=status)
+ {
+ return event;
+ }
+ i++;
+ }
+ throw new IllegalStateException("The publishing event did not complete after 20s!");
+ }
+
}
diff --git a/source/java/org/alfresco/repo/publishing/StandardPublishingPackageSerializer.java b/source/java/org/alfresco/repo/publishing/StandardNodeSnapshotSerializer.java
similarity index 89%
rename from source/java/org/alfresco/repo/publishing/StandardPublishingPackageSerializer.java
rename to source/java/org/alfresco/repo/publishing/StandardNodeSnapshotSerializer.java
index 1c6449b81e..3ea585bcce 100644
--- a/source/java/org/alfresco/repo/publishing/StandardPublishingPackageSerializer.java
+++ b/source/java/org/alfresco/repo/publishing/StandardNodeSnapshotSerializer.java
@@ -22,7 +22,6 @@ package org.alfresco.repo.publishing;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
@@ -32,6 +31,7 @@ import java.util.List;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
+import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.transfer.manifest.TransferManifestDeletedNode;
import org.alfresco.repo.transfer.manifest.TransferManifestHeader;
import org.alfresco.repo.transfer.manifest.TransferManifestNormalNode;
@@ -39,13 +39,12 @@ import org.alfresco.repo.transfer.manifest.TransferManifestProcessor;
import org.alfresco.repo.transfer.manifest.XMLTransferManifestReader;
import org.alfresco.repo.transfer.manifest.XMLTransferManifestWriter;
import org.alfresco.service.cmr.publishing.NodeSnapshot;
-import org.xml.sax.SAXException;
/**
* @author Brian
* @author Nick Smith
*/
-public class StandardPublishingPackageSerializer implements NodeSnapshotSerializer
+public class StandardNodeSnapshotSerializer implements NodeSnapshotSerializer
{
/**
* {@inheritDoc}
@@ -94,14 +93,9 @@ public class StandardPublishingPackageSerializer implements NodeSnapshotSerializ
transferManifestWriter.endTransferManifest();
writer.flush();
}
- catch (SAXException e)
+ catch (Exception e)
{
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- catch (UnsupportedEncodingException e)
- {
- //UTF-8 must be supported, so this is not going to happen
+ throw new AlfrescoRuntimeException("Failed to serialize node snapshots.", e);
}
}