diff --git a/config/alfresco/web-publishing-context.xml b/config/alfresco/web-publishing-context.xml
index 2a6b42b1c9..bee44bf1aa 100644
--- a/config/alfresco/web-publishing-context.xml
+++ b/config/alfresco/web-publishing-context.xml
@@ -62,10 +62,8 @@
-
-
@@ -77,6 +75,8 @@
+
+
diff --git a/source/java/org/alfresco/repo/publishing/ChannelHelper.java b/source/java/org/alfresco/repo/publishing/ChannelHelper.java
index 05601e3a08..3092c074c4 100644
--- a/source/java/org/alfresco/repo/publishing/ChannelHelper.java
+++ b/source/java/org/alfresco/repo/publishing/ChannelHelper.java
@@ -49,7 +49,6 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
-import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService;
@@ -87,8 +86,6 @@ public class ChannelHelper
public NodeRef createChannelNode(NodeRef parent, ChannelType channelType, String channelName,
Map props)
{
- Set permissions = permissionService.getPermissions(parent);
-
QName channelQName = getChannelQName(channelName);
QName channelNodeType = channelType.getChannelNodeType();
ChildAssociationRef channelAssoc =
@@ -120,6 +117,18 @@ public class ChannelHelper
* @return
*/
public NodeRef mapSourceToEnvironment(NodeRef source, final NodeRef channelNode)
+ {
+ return mapSourceToEnvironment(source, channelNode, nodeService);
+ }
+
+ /**
+ * Given a noderef from the editorial space (e.g. the doclib), this returns the corresponding noderef published to the specified channel.
+ * @param source
+ * @param channelNode
+ * @param nodeService
+ * @return
+ */
+ public static NodeRef mapSourceToEnvironment(NodeRef source, final NodeRef channelNode, final NodeService nodeService)
{
if(source == null || channelNode == null)
{
@@ -145,6 +154,16 @@ public class ChannelHelper
* @return
*/
public NodeRef mapEnvironmentToSource(NodeRef publishedNode)
+ {
+ return mapEnvironmentToSource(publishedNode, nodeService);
+ }
+
+ /**
+ * Given a published noderef, this returns the corresponding source noderef in the editorial space (doclib).
+ * @param publishedNode
+ * @return
+ */
+ public static NodeRef mapEnvironmentToSource(NodeRef publishedNode, NodeService nodeService)
{
List assocs = nodeService.getTargetAssocs(publishedNode, ASSOC_SOURCE);
return NodeUtils.getSingleAssocNode(assocs, true);
diff --git a/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java b/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java
index 2335ab5d36..901d786d65 100644
--- a/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java
+++ b/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java
@@ -296,7 +296,7 @@ public class ChannelServiceImpl implements ChannelService
{
HashMap actualProps = new HashMap(properties);
actualProps.remove(ContentModel.PROP_NODE_UUID);
- NodeRef editorialNode = channel.getNodeRef();
+ NodeRef editorialNode = new NodeRef(channel.getId());
for (Map.Entry entry : actualProps.entrySet())
{
nodeService.setProperty(editorialNode, entry.getKey(), entry.getValue());
diff --git a/source/java/org/alfresco/repo/publishing/MutablePublishingPackageImpl.java b/source/java/org/alfresco/repo/publishing/MutablePublishingPackageImpl.java
deleted file mode 100644
index dd079783f4..0000000000
--- a/source/java/org/alfresco/repo/publishing/MutablePublishingPackageImpl.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (C) 2005-2010 Alfresco Software Limited.
- *
- * This file is part of Alfresco
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- */
-
-package org.alfresco.repo.publishing;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.alfresco.repo.security.authentication.AuthenticationUtil;
-import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
-import org.alfresco.repo.transfer.manifest.TransferManifestNodeFactory;
-import org.alfresco.repo.transfer.manifest.TransferManifestNormalNode;
-import org.alfresco.service.cmr.publishing.PublishingPackage;
-import org.alfresco.service.cmr.publishing.MutablePublishingPackage;
-import org.alfresco.service.cmr.publishing.PublishingPackageEntry;
-import org.alfresco.service.cmr.repository.NodeRef;
-import org.alfresco.service.cmr.version.Version;
-import org.alfresco.service.cmr.version.VersionService;
-
-/**
- * @author Brian
- * @author Nick Smith
- *
- * @since 4.0
- */
-public class MutablePublishingPackageImpl implements MutablePublishingPackage
-{
- private final VersionService versionService;
- private final TransferManifestNodeFactory transferManifestNodeFactory;
- private final Map entryMap = new HashMap();
- private final Set nodesToPublish = new HashSet();
- private final Set nodesToUnpublish= new HashSet();
-
- /**
- * @param transferManifestNodeFactory
- */
- public MutablePublishingPackageImpl(TransferManifestNodeFactory transferManifestNodeFactory,
- VersionService versionService)
- {
- this.transferManifestNodeFactory = transferManifestNodeFactory;
- this.versionService = versionService;
- }
-
- /**
- * {@inheritDoc}
- */
- public MutablePublishingPackage addNodesToPublish(NodeRef... nodesToAdd)
- {
- return addNodesToPublish(Arrays.asList(nodesToAdd));
- }
-
- /**
- * {@inheritDoc}
- */
- public MutablePublishingPackage addNodesToPublish(final Collection nodesToAdd)
- {
- AuthenticationUtil.runAs(new RunAsWork()
- {
- public Void doWork() throws Exception
- {
- versionNodes(nodesToAdd);
- return null;
- }
- }, AuthenticationUtil.getSystemUserName());
- nodesToPublish.addAll(nodesToAdd);
- return this;
- }
-
- private void versionNodes(Collection nodesToAdd)
- {
- for (NodeRef nodeRef : nodesToAdd)
- {
- Version version = versionService.createVersion(nodeRef, null);
- String versionLabel = null;
- if(version != null)
- {
- versionLabel = version.getVersionLabel();
- }
- TransferManifestNormalNode payload = (TransferManifestNormalNode) transferManifestNodeFactory.createTransferManifestNode(nodeRef, null);
- if (TransferManifestNormalNode.class.isAssignableFrom(payload.getClass()))
- {
- PublishingPackageEntryImpl publishingPackage = new PublishingPackageEntryImpl(true, nodeRef, payload, versionLabel);
- entryMap.put(nodeRef, publishingPackage);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public MutablePublishingPackage addNodesToUnpublish(NodeRef... nodesToRemove)
- {
- return addNodesToUnpublish(Arrays.asList(nodesToRemove));
- }
-
- /**
- * {@inheritDoc}
- */
- public MutablePublishingPackage addNodesToUnpublish(Collection nodesToRemove)
- {
- for (NodeRef nodeRef : nodesToRemove)
- {
- entryMap.put(nodeRef, new PublishingPackageEntryImpl(false, nodeRef, null, null));
- }
- nodesToUnpublish.addAll(nodesToRemove);
- return this;
- }
-
- /**
- * {@inheritDoc}
- */
- public Collection getEntries()
- {
- return entryMap.values();
- }
-
- /**
- * {@inheritDoc}
- */
- public Set getNodesToPublish()
- {
- return nodesToPublish;
- }
-
- /**
- * {@inheritDoc}
- */
- public Set getNodesToUnpublish()
- {
- return nodesToUnpublish;
- }
-
- /**
- * {@inheritDoc}
- */
- public Map getEntryMap()
- {
- return entryMap;
- }
-
- /**
- * {@inheritDoc}
- */
- public PublishingPackage build()
- {
- return new PublishingPackageImpl(entryMap);
- }
-}
diff --git a/source/java/org/alfresco/service/cmr/publishing/MutablePublishingPackage.java b/source/java/org/alfresco/repo/publishing/NodeSnapshotFactory.java
similarity index 53%
rename from source/java/org/alfresco/service/cmr/publishing/MutablePublishingPackage.java
rename to source/java/org/alfresco/repo/publishing/NodeSnapshotFactory.java
index bfbf1ce467..b28e34c78c 100644
--- a/source/java/org/alfresco/service/cmr/publishing/MutablePublishingPackage.java
+++ b/source/java/org/alfresco/repo/publishing/NodeSnapshotFactory.java
@@ -16,28 +16,15 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see .
*/
-package org.alfresco.service.cmr.publishing;
-import java.util.Collection;
-
-import org.alfresco.service.cmr.repository.NodeRef;
+package org.alfresco.repo.publishing;
/**
- * An extendsion of the {@link PublishingPackage} interface which allows values to be modified.
- * @author Brian
* @author Nick Smith
- *
* @since 4.0
+ *
*/
-public interface MutablePublishingPackage extends PublishingPackage
+public class NodeSnapshotFactory
{
- MutablePublishingPackage addNodesToUnpublish(NodeRef... nodesToRemove);
- MutablePublishingPackage addNodesToUnpublish(Collection nodesToRemove);
-
- MutablePublishingPackage addNodesToPublish(NodeRef... nodesToPublish);
-
- MutablePublishingPackage addNodesToPublish(Collection nodesToPublish);
-
- PublishingPackage build();
}
diff --git a/source/java/org/alfresco/repo/publishing/PublishingPackageSerializer.java b/source/java/org/alfresco/repo/publishing/NodeSnapshotSerializer.java
similarity index 75%
rename from source/java/org/alfresco/repo/publishing/PublishingPackageSerializer.java
rename to source/java/org/alfresco/repo/publishing/NodeSnapshotSerializer.java
index b370e66db2..c4d3ada3fa 100644
--- a/source/java/org/alfresco/repo/publishing/PublishingPackageSerializer.java
+++ b/source/java/org/alfresco/repo/publishing/NodeSnapshotSerializer.java
@@ -21,8 +21,11 @@ package org.alfresco.repo.publishing;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.Collection;
+import java.util.List;
import java.util.Map;
+import org.alfresco.service.cmr.publishing.NodeSnapshot;
import org.alfresco.service.cmr.publishing.PublishingPackage;
import org.alfresco.service.cmr.publishing.PublishingPackageEntry;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -33,9 +36,9 @@ import org.alfresco.service.cmr.repository.NodeRef;
*
* @since 4.0
*/
-public interface PublishingPackageSerializer
+public interface NodeSnapshotSerializer
{
- void serialize(PublishingPackage publishingPackage, OutputStream output) throws Exception;
+ void serialize(Collection snapshots, OutputStream output) throws Exception;
- Map deserialize(InputStream input) throws Exception;
+ List deserialize(InputStream input) throws Exception;
}
diff --git a/source/java/org/alfresco/repo/publishing/NodeSnapshotTransferImpl.java b/source/java/org/alfresco/repo/publishing/NodeSnapshotTransferImpl.java
index 0459505a78..644f8af238 100644
--- a/source/java/org/alfresco/repo/publishing/NodeSnapshotTransferImpl.java
+++ b/source/java/org/alfresco/repo/publishing/NodeSnapshotTransferImpl.java
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.alfresco.model.ContentModel;
import org.alfresco.repo.transfer.manifest.TransferManifestNormalNode;
import org.alfresco.service.cmr.publishing.NodeSnapshot;
import org.alfresco.service.cmr.repository.AssociationRef;
@@ -34,6 +35,8 @@ import org.alfresco.service.namespace.QName;
/**
* @author Brian
+ * @author Nick Smith
+ * @since 4.0
*
*/
public class NodeSnapshotTransferImpl implements NodeSnapshot
@@ -44,16 +47,16 @@ public class NodeSnapshotTransferImpl implements NodeSnapshot
/**
* @param transferNode
*/
- public NodeSnapshotTransferImpl(TransferManifestNormalNode transferNode, String version)
+ public NodeSnapshotTransferImpl(TransferManifestNormalNode transferNode)
{
this.transferNode = transferNode;
- this.version = version;
+ Map props = transferNode.getProperties();
+ this.version = (String) props.get(ContentModel.PROP_VERSION_LABEL);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.publishing.NodeSnapshot#getAllParentAssocs()
*/
- @Override
public List getAllParentAssocs()
{
return transferNode.getParentAssocs();
@@ -62,7 +65,7 @@ public class NodeSnapshotTransferImpl implements NodeSnapshot
/* (non-Javadoc)
* @see org.alfresco.service.cmr.publishing.NodeSnapshot#getAspects()
*/
- @Override
+
public Set getAspects()
{
return transferNode.getAspects();
@@ -71,7 +74,7 @@ public class NodeSnapshotTransferImpl implements NodeSnapshot
/* (non-Javadoc)
* @see org.alfresco.service.cmr.publishing.NodeSnapshot#getNodeRef()
*/
- @Override
+
public NodeRef getNodeRef()
{
return transferNode.getNodeRef();
@@ -80,7 +83,7 @@ public class NodeSnapshotTransferImpl implements NodeSnapshot
/* (non-Javadoc)
* @see org.alfresco.service.cmr.publishing.NodeSnapshot#getOutboundPeerAssociations()
*/
- @Override
+
public List getOutboundPeerAssociations()
{
return transferNode.getTargetAssocs();
@@ -89,7 +92,7 @@ public class NodeSnapshotTransferImpl implements NodeSnapshot
/* (non-Javadoc)
* @see org.alfresco.service.cmr.publishing.NodeSnapshot#getPrimaryParentAssoc()
*/
- @Override
+
public ChildAssociationRef getPrimaryParentAssoc()
{
return transferNode.getPrimaryParentAssoc();
@@ -98,7 +101,7 @@ public class NodeSnapshotTransferImpl implements NodeSnapshot
/* (non-Javadoc)
* @see org.alfresco.service.cmr.publishing.NodeSnapshot#getPrimaryPath()
*/
- @Override
+
public Path getPrimaryPath()
{
return transferNode.getParentPath();
@@ -107,7 +110,7 @@ public class NodeSnapshotTransferImpl implements NodeSnapshot
/* (non-Javadoc)
* @see org.alfresco.service.cmr.publishing.NodeSnapshot#getProperties()
*/
- @Override
+
public Map getProperties()
{
return transferNode.getProperties();
@@ -116,7 +119,7 @@ public class NodeSnapshotTransferImpl implements NodeSnapshot
/* (non-Javadoc)
* @see org.alfresco.service.cmr.publishing.NodeSnapshot#getType()
*/
- @Override
+
public QName getType()
{
return transferNode.getType();
@@ -125,9 +128,17 @@ public class NodeSnapshotTransferImpl implements NodeSnapshot
/**
* {@inheritDoc}
*/
- @Override
+
public String getVersion()
{
return version;
}
+
+ /**
+ * @return the transferNode
+ */
+ public TransferManifestNormalNode getTransferNode()
+ {
+ return transferNode;
+ }
}
diff --git a/source/java/org/alfresco/repo/publishing/PublishEventActionTest.java b/source/java/org/alfresco/repo/publishing/PublishEventActionTest.java
index 9d7d82d10e..f35053d203 100644
--- a/source/java/org/alfresco/repo/publishing/PublishEventActionTest.java
+++ b/source/java/org/alfresco/repo/publishing/PublishEventActionTest.java
@@ -46,10 +46,9 @@ import javax.annotation.Resource;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
-import org.alfresco.service.cmr.publishing.MutablePublishingPackage;
+import org.alfresco.service.cmr.publishing.PublishingDetails;
import org.alfresco.service.cmr.publishing.PublishingService;
import org.alfresco.service.cmr.publishing.Status;
-import org.alfresco.service.cmr.publishing.StatusUpdate;
import org.alfresco.service.cmr.publishing.channels.Channel;
import org.alfresco.service.cmr.publishing.channels.ChannelType;
import org.alfresco.service.cmr.repository.AssociationRef;
@@ -362,13 +361,12 @@ public class PublishEventActionTest extends AbstractPublishingIntegrationTest
// Create Status Update
String message = "Here is the message ";
- StatusUpdate status = publishingService.getPublishingQueue().createStatusUpdate(message, source, channel.getId());
String url = "http://test/url";
when(channelType.getNodeUrl(any(NodeRef.class))).thenReturn(url);
when(channelType.canPublishStatusUpdates()).thenReturn(true);
- publishNode(source, status);
+ publishNode(source, message);
String expMessage = message + " " + url;
verify(channelType, times(1)).updateStatus(any(Channel.class), eq(expMessage), anyMap());
@@ -379,23 +377,30 @@ public class PublishEventActionTest extends AbstractPublishingIntegrationTest
return publishNode(source, null);
}
- private NodeRef publishNode(NodeRef source, StatusUpdate statusUpdate)
+ private NodeRef publishNode(NodeRef source, String message)
{
- return publishNode(source, statusUpdate, true);
+ return publishNode(source, message, true);
}
- private NodeRef publishNode(NodeRef source, StatusUpdate statusUpdate, boolean publish)
+ private NodeRef publishNode(NodeRef source, String message, boolean publish)
{
- MutablePublishingPackage pckg = publishingService.getPublishingQueue().createPublishingPackageBuilder();
+ PublishingDetails details = publishingService.getPublishingQueue().createPublishingDetails();
+ details.setPublishChannel(channel.getId());
if(publish)
{
- pckg.addNodesToPublish(source);
+ details.addNodesToPublish(source);
}
else
{
- pckg.addNodesToUnpublish(source);
+ details.addNodesToUnpublish(source);
}
- String eventId = testHelper.scheduleEvent1Year(pckg, channel.getId(), null, statusUpdate);
+ if(message!=null)
+ {
+ details.setStatusMessage(message)
+ .setStatusNodeToLinkTo(source)
+ .addStatusUpdateChannels(channel.getId());
+ }
+ String eventId = testHelper.scheduleEvent1Year(details);
assertNotNull(eventId);
NodeRef eventNode = new NodeRef(eventId);
diff --git a/source/java/org/alfresco/repo/publishing/PublishingDetailsImpl.java b/source/java/org/alfresco/repo/publishing/PublishingDetailsImpl.java
new file mode 100644
index 0000000000..6d594edc56
--- /dev/null
+++ b/source/java/org/alfresco/repo/publishing/PublishingDetailsImpl.java
@@ -0,0 +1,216 @@
+/*
+ * Copyright (C) 2005-2010 Alfresco Software Limited.
+ *
+ * This file is part of Alfresco
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ */
+
+package org.alfresco.repo.publishing;
+
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.alfresco.service.cmr.publishing.PublishingDetails;
+import org.alfresco.service.cmr.repository.NodeRef;
+
+/**
+ * @author Brian
+ * @author Nick Smith
+ *
+ * @since 4.0
+ */
+public class PublishingDetailsImpl implements PublishingDetails
+{
+ private final Set nodesToPublish = new HashSet();
+ private final Set nodesToUnpublish= new HashSet();
+ private final Set statusChannels = new HashSet();
+
+ private NodeRef nodeToLinkTo = null;
+ private String message = null;
+ private Calendar schedule = null;
+ private String comment = null;
+ private String publishChannelId = null;
+
+ /**
+ * {@inheritDoc}
+ */
+ public PublishingDetails addNodesToPublish(NodeRef... nodesToAdd)
+ {
+ return addNodesToPublish(Arrays.asList(nodesToAdd));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PublishingDetails addNodesToUnpublish(NodeRef... nodesToRemove)
+ {
+ return addNodesToUnpublish(Arrays.asList(nodesToRemove));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public PublishingDetails addNodesToUnpublish(Collection nodesToRemove)
+ {
+ this.nodesToUnpublish.addAll(nodesToRemove);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PublishingDetails addNodesToPublish(Collection nodesToAdd)
+ {
+ this.nodesToPublish.addAll(nodesToAdd);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PublishingDetails setPublishChannel(String publishChannelId)
+ {
+ this.publishChannelId = publishChannelId;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PublishingDetails setComment(String comment)
+ {
+ this.comment = comment;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PublishingDetails setSchedule(Calendar schedule)
+ {
+ this.schedule = schedule;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PublishingDetails setStatusMessage(String message)
+ {
+ this.message = message;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PublishingDetails setStatusNodeToLinkTo(NodeRef nodeToLinkTo)
+ {
+ this.nodeToLinkTo = nodeToLinkTo;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PublishingDetails addStatusUpdateChannels(Collection channelIds)
+ {
+ statusChannels.addAll(channelIds);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PublishingDetails addStatusUpdateChannels(String... channelIds)
+ {
+ return addStatusUpdateChannels(Arrays.asList(channelIds));
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set getNodesToPublish()
+ {
+ return nodesToPublish;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set getNodesToUnpublish()
+ {
+ return nodesToUnpublish;
+ }
+
+ /**
+ * @return the statusChannels
+ */
+ public Set getStatusChannels()
+ {
+ return statusChannels;
+ }
+
+ /**
+ * @return the comment
+ */
+ public String getComment()
+ {
+ return comment;
+ }
+
+ /**
+ * @return the message
+ */
+ public String getStatusMessage()
+ {
+ return message;
+ }
+
+ /**
+ * @return the nodeToLinkTo
+ */
+ public NodeRef getNodeToLinkTo()
+ {
+ return nodeToLinkTo;
+ }
+
+ /**
+ * @return the publishChannelId
+ */
+ public String getPublishChannelId()
+ {
+ return publishChannelId;
+ }
+
+ /**
+ * @return the schedule
+ */
+ public Calendar getSchedule()
+ {
+ return schedule;
+ }
+
+ public Set getStatusUpdateChannels()
+ {
+ return statusChannels;
+ }
+
+}
diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java b/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java
index 47b62f0a91..1ff1f3172b 100644
--- a/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java
+++ b/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java
@@ -60,8 +60,13 @@ import java.util.TimeZone;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.node.NodeUtils;
+import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.permissions.AccessDeniedException;
+import org.alfresco.repo.transfer.manifest.TransferManifestNodeFactory;
+import org.alfresco.repo.transfer.manifest.TransferManifestNormalNode;
import org.alfresco.repo.workflow.WorkflowModel;
+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.PublishingEventFilter;
import org.alfresco.service.cmr.publishing.PublishingPackage;
@@ -77,6 +82,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionService;
+import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
import org.alfresco.service.cmr.workflow.WorkflowPath;
import org.alfresco.service.cmr.workflow.WorkflowService;
@@ -93,6 +99,7 @@ import org.apache.commons.logging.LogFactory;
/**
* @author Brian
* @author Nick Smith
+ * @since 4.0
*
*/
public class PublishingEventHelper
@@ -102,10 +109,12 @@ public class PublishingEventHelper
private NodeService nodeService;
private ContentService contentService;
+ private VersionService versionService;
private WorkflowService workflowService;
- private PublishingPackageSerializer serializer;
+ private NodeSnapshotSerializer serializer;
private PermissionService permissionService;
-
+ private TransferManifestNodeFactory transferManifestNodeFactory;
+
private String workflowEngineId;
/**
@@ -126,6 +135,22 @@ public class PublishingEventHelper
this.contentService = contentService;
}
+ /**
+ * @param transferManifestNodeFactory the transferManifestNodeFactory to set
+ */
+ public void setTransferManifestNodeFactory(TransferManifestNodeFactory transferManifestNodeFactory)
+ {
+ this.transferManifestNodeFactory = transferManifestNodeFactory;
+ }
+
+ /**
+ * @param versionService the versionService to set
+ */
+ public void setVersionService(VersionService versionService)
+ {
+ this.versionService = versionService;
+ }
+
/**
* @param workflowService the workflowService to set
*/
@@ -145,7 +170,7 @@ public class PublishingEventHelper
/**
* @param serializer the serializer to set
*/
- public void setSerializer(PublishingPackageSerializer serializer)
+ public void setSerializer(NodeSnapshotSerializer serializer)
{
this.serializer = serializer;
}
@@ -168,15 +193,15 @@ public class PublishingEventHelper
Map props = nodeService.getProperties(eventNode);
String statusStr = (String) props.get(PROP_PUBLISHING_EVENT_STATUS);
Status status = Status.valueOf(statusStr);
- PublishingPackage publishingPackage = getPayLoad(eventNode);
+ String channel = (String) props.get(PROP_PUBLISHING_EVENT_CHANNEL);
Date createdTime = (Date) props.get(ContentModel.PROP_CREATED);
String creator = (String) props.get(ContentModel.PROP_CREATOR);
Date modifiedTime = (Date) props.get(ContentModel.PROP_MODIFIED);
String modifier = (String) props.get(ContentModel.PROP_MODIFIER);
String comment = (String) props.get(PROP_PUBLISHING_EVENT_COMMENT);
Calendar scheduledTime = getScheduledTime(props);
+ PublishingPackage publishingPackage = getPublishingPackage(eventNode, channel);
- String channel = (String) props.get(PROP_PUBLISHING_EVENT_CHANNEL);
StatusUpdate statusUpdate = buildStatusUpdate(props);
return new PublishingEventImpl(eventNode.toString(),
status, channel,
@@ -210,28 +235,23 @@ public class PublishingEventHelper
});
}
- public NodeRef createNode(NodeRef queueNode, PublishingPackage publishingPackage, String channelId, Calendar schedule, String comment, StatusUpdate statusUpdate)
- throws Exception
+ public NodeRef createNode(NodeRef queueNode, PublishingDetails details) throws Exception
{
- checkChannelAccess(channelId);
- if(statusUpdate != null && isEmpty(statusUpdate.getChannelIds())==false )
- for (String statusChannelId : statusUpdate.getChannelIds())
+ checkChannelAccess(details.getPublishChannelId());
+ Set statusChannelIds = details.getStatusUpdateChannels();
+ if(isEmpty(statusChannelIds)==false )
+ for (String statusChannelId : statusChannelIds)
{
checkChannelAccess(statusChannelId);
}
- if (schedule == null)
- {
- schedule = Calendar.getInstance();
- }
String name = GUID.generate();
- Map props =
- buildPublishingEventProperties(publishingPackage, channelId, schedule, comment, statusUpdate, name);
+ Map props = buildPublishingEventProperties(details, name);
ChildAssociationRef newAssoc = nodeService.createNode(queueNode,
ASSOC_PUBLISHING_EVENT,
QName.createQName(NAMESPACE, name),
TYPE_PUBLISHING_EVENT, props);
NodeRef eventNode = newAssoc.getChildRef();
- setPayload(eventNode, publishingPackage);
+ serializePublishNodes(eventNode, details);
return eventNode;
}
@@ -245,33 +265,40 @@ public class PublishingEventHelper
}
}
- private Map buildPublishingEventProperties(PublishingPackage publishingPackage,
- String channelId, Calendar schedule, String comment, StatusUpdate statusUpdate, String name)
+ private Map buildPublishingEventProperties(PublishingDetails details, String name)
{
+ Calendar schedule = details.getSchedule();
+ if (schedule == null)
+ {
+ schedule = Calendar.getInstance();
+ }
Map props = new HashMap();
props.put(ContentModel.PROP_NAME, name);
props.put(PROP_PUBLISHING_EVENT_STATUS, Status.IN_PROGRESS.name());
props.put(PROP_PUBLISHING_EVENT_TIME, schedule.getTime());
props.put(PublishingModel.PROP_PUBLISHING_EVENT_TIME_ZONE, schedule.getTimeZone().getID());
- props.put(PublishingModel.PROP_PUBLISHING_EVENT_CHANNEL, channelId);
+ props.put(PublishingModel.PROP_PUBLISHING_EVENT_CHANNEL, details.getPublishChannelId());
props.put(PublishingModel.PROP_PUBLISHING_EVENT_STATUS, PublishingModel.PROPVAL_PUBLISHING_EVENT_STATUS_SCHEDULED);
+ String comment = details.getComment();
if (comment != null)
{
props.put(PROP_PUBLISHING_EVENT_COMMENT, comment);
}
- Collection publshStrings = mapNodesToStrings(publishingPackage.getNodesToPublish());
+ Collection publshStrings = mapNodesToStrings(details.getNodesToPublish());
props.put(PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH, (Serializable) publshStrings);
- Collection unpublshStrings = mapNodesToStrings(publishingPackage.getNodesToUnpublish());
+ Collection unpublshStrings = mapNodesToStrings(details.getNodesToUnpublish());
props.put(PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH, (Serializable) unpublshStrings);
- if(statusUpdate != null)
+ String message = details.getStatusMessage();
+ Set statusChannels = details.getStatusUpdateChannels();
+ if(message != null && isEmpty(statusChannels)==false)
{
- props.put(PROP_STATUS_UPDATE_MESSAGE, statusUpdate.getMessage());
- NodeRef statusNode = statusUpdate.getNodeToLinkTo();
+ props.put(PROP_STATUS_UPDATE_MESSAGE, message);
+ NodeRef statusNode = details.getNodeToLinkTo();
if(statusNode != null)
{
props.put(PROP_STATUS_UPDATE_NODE_REF, statusNode.toString());
}
- props.put(PROP_STATUS_UPDATE_CHANNEL_NAMES, (Serializable) statusUpdate.getChannelIds());
+ props.put(PROP_STATUS_UPDATE_CHANNEL_NAMES, (Serializable) statusChannels);
}
return props;
}
@@ -476,15 +503,16 @@ public class PublishingEventHelper
return scheduledTime;
}
- private void setPayload(NodeRef eventNode, PublishingPackage publishingPackage) throws Exception
+ private void serializePublishNodes(NodeRef eventNode, PublishingDetails details) throws Exception
{
try
{
+ List snapshots = createPublishSnapshots(details.getNodesToPublish());
ContentWriter contentWriter = contentService.getWriter(eventNode,
PROP_PUBLISHING_EVENT_PAYLOAD, true);
contentWriter.setEncoding("UTF-8");
OutputStream os = contentWriter.getContentOutputStream();
- serializer.serialize(publishingPackage, os);
+ serializer.serialize(snapshots, os);
os.flush();
os.close();
}
@@ -495,16 +523,71 @@ public class PublishingEventHelper
}
}
- private PublishingPackage getPayLoad(NodeRef eventNode) throws AlfrescoRuntimeException
+ private PublishingPackage getPublishingPackage(NodeRef eventNode, String channelId) throws AlfrescoRuntimeException
+ {
+ 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()
+ {
+ public PublishingPackageEntry apply(NodeRef node)
+ {
+ return createPublishEntry(node);
+ }
+ });
+ }
+
+ private PublishingPackageEntry createPublishEntry(NodeRef node)
+ {
+ NodeSnapshotTransferImpl snapshot = createPublishSnapshot(node);
+ return new PublishingPackageEntryImpl(true, node, snapshot);
+ }
+
+ private List createPublishSnapshots(final Collection nodes)
+ {
+ return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork>()
+ {
+ public List doWork() throws Exception
+ {
+ return transform(nodes, new Function()
+ {
+ public NodeSnapshot apply(NodeRef node)
+ {
+ return createPublishSnapshot(node);
+ }
+ });
+ }
+ }, AuthenticationUtil.getSystemUserName());
+ }
+
+ private NodeSnapshotTransferImpl createPublishSnapshot(NodeRef node)
+ {
+ versionService.createVersion(node, null);
+ TransferManifestNormalNode payload = (TransferManifestNormalNode) transferManifestNodeFactory.createTransferManifestNode(node, null);
+ NodeSnapshotTransferImpl snapshot = new NodeSnapshotTransferImpl(payload);
+ return snapshot;
+ }
+
+ private Map getPublishEntries(NodeRef eventNode)
{
ContentReader contentReader = contentService.getReader(eventNode, PROP_PUBLISHING_EVENT_PAYLOAD);
InputStream input = contentReader.getContentInputStream();
try
{
- Map publishEntires = serializer.deserialize(input);
- Map allEntries = getUnpublishPackageEntries(eventNode);
- allEntries.putAll(publishEntires);
- return new PublishingPackageImpl(allEntries);
+ List snapshots = serializer.deserialize(input);
+ Map entries = new HashMap(snapshots.size());
+ for (NodeSnapshot snapshot : snapshots)
+ {
+ NodeRef node = snapshot.getNodeRef();
+ PublishingPackageEntryImpl entry = new PublishingPackageEntryImpl(true, node, snapshot);
+ entries.put(node, entry);
+ }
+ return entries;
}
catch (Exception ex)
{
@@ -513,7 +596,7 @@ public class PublishingEventHelper
}
}
- private Map getUnpublishPackageEntries(NodeRef eventNode)
+ public Map getUnpublishEntries(NodeRef eventNode, String channelId)
{
@SuppressWarnings("unchecked")
List entries= (List) nodeService.getProperty(eventNode, PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH);
@@ -521,6 +604,7 @@ public class PublishingEventHelper
{
return new HashMap();
}
+ final NodeRef channelNode = new NodeRef(channelId);
List nodes = NodeUtils.toNodeRefs(entries);
return transformToMap(nodes, new Function()
{
@@ -528,13 +612,37 @@ public class PublishingEventHelper
{
if(NodeUtils.exists(node, nodeService))
{
- return new PublishingPackageEntryImpl(false, node, null, null);
+ return makeUnpublishEntry(node, channelNode);
}
return null;
}
});
}
+ private PublishingPackageEntry makeUnpublishEntry(NodeRef source, NodeRef channelNode)
+ {
+ NodeRef lastEvent = getLastPublishEvent(source, channelNode);
+ NodeSnapshot snapshot = null;
+ if(lastEvent!=null)
+ {
+ Map entries = getPublishEntries(lastEvent);
+ PublishingPackageEntry entry = entries.get(source);
+ snapshot = entry.getSnapshot();
+ }
+ return new PublishingPackageEntryImpl(false, source, snapshot);
+ }
+
+ public NodeRef getLastPublishEvent(NodeRef source, NodeRef channelNode)
+ {
+ NodeRef publishedNode = ChannelHelper.mapSourceToEnvironment(source, channelNode, nodeService);
+ if(publishedNode == null)
+ {
+ return null;
+ }
+ List assocs = nodeService.getTargetAssocs(publishedNode, ASSOC_LAST_PUBLISHING_EVENT);
+ return NodeUtils.getSingleAssocNode(assocs, true);
+ }
+
public void cancelEvent(String id)
{
NodeRef eventNode = getPublishingEventNode(id);
@@ -576,6 +684,11 @@ public class PublishingEventHelper
}
return nodeService.createAssociation(publishedNode, eventNode, ASSOC_LAST_PUBLISHING_EVENT);
}
+
+ public PublishingDetails createPublishingPackageBuilder()
+ {
+ return new PublishingDetailsImpl();
+ }
// public NodePublishStatus checkNodeStatus(NodeRef node, String channelId, NodeRef queue)
// {
diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventHelperTest.java b/source/java/org/alfresco/repo/publishing/PublishingEventHelperTest.java
index fa20244e3f..76316de0f4 100644
--- a/source/java/org/alfresco/repo/publishing/PublishingEventHelperTest.java
+++ b/source/java/org/alfresco/repo/publishing/PublishingEventHelperTest.java
@@ -42,7 +42,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Calendar;
-import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -50,9 +49,8 @@ import java.util.Map;
import javax.annotation.Resource;
import org.alfresco.model.ContentModel;
+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.Status;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentReader;
@@ -128,7 +126,7 @@ public class PublishingEventHelperTest
when(reader.getContentInputStream()).thenReturn(inputStream);
when(contentService.getReader(any(NodeRef.class), any(QName.class)))
.thenReturn(reader);
- PublishingPackageSerializer serializer = mock(PublishingPackageSerializer.class);
+ NodeSnapshotSerializer serializer = mock(NodeSnapshotSerializer.class);
helper.setSerializer(serializer);
PublishingEvent result = helper.getPublishingEvent((NodeRef)null);
@@ -181,7 +179,7 @@ public class PublishingEventHelperTest
.thenReturn(writer);
OutputStream outputStream = mock(OutputStream.class);
when(writer.getContentOutputStream()).thenReturn(outputStream);
- PublishingPackageSerializer serializer = mock(PublishingPackageSerializer.class);
+ NodeSnapshotSerializer serializer = mock(NodeSnapshotSerializer.class);
helper.setSerializer(serializer);
NodeRef queue = new NodeRef("foo://bar/queue");
@@ -191,13 +189,16 @@ public class PublishingEventHelperTest
when(nodeService.createNode(any(NodeRef.class), any(QName.class), any(QName.class), any(QName.class), anyMap()))
.thenReturn(childAssoc);
- Map entires = Collections.emptyMap();
- PublishingPackage pckg = new PublishingPackageImpl(entires);
- String channelName = "test://channel/id";
+ String channelId = "test://channel/id";
Calendar schedule = Calendar.getInstance();
String comment = "The comment";
- NodeRef result = helper.createNode(queue, pckg, channelName, schedule, comment, null);
+ PublishingDetails details = new PublishingDetailsImpl()
+ .setSchedule(schedule)
+ .setPublishChannel(channelId)
+ .setComment(comment);
+
+ NodeRef result = helper.createNode(queue, details);
assertEquals(event, result);
ArgumentCaptor