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 argument = ArgumentCaptor.forClass(Map.class); @@ -208,7 +209,7 @@ public class PublishingEventHelperTest Map props = argument.getValue(); assertNotNull(props.get(ContentModel.PROP_NAME)); - assertEquals(channelName, props.get(PROP_PUBLISHING_EVENT_CHANNEL)); + assertEquals(channelId, props.get(PROP_PUBLISHING_EVENT_CHANNEL)); assertEquals(comment, props.get(PROP_PUBLISHING_EVENT_COMMENT)); assertEquals(schedule.getTime(), props.get(PROP_PUBLISHING_EVENT_TIME)); assertEquals(schedule.getTimeZone().getID(), props.get(PROP_PUBLISHING_EVENT_TIME_ZONE)); diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java b/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java index 0159b6fab6..135e089cf8 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java +++ b/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java @@ -150,7 +150,8 @@ public class PublishingEventProcessor public void unpublishEntry(Channel channel, PublishingPackageEntry entry) { - NodeRef publishedNode = channelHelper.mapSourceToEnvironment(entry.getNodeRef(), channel.getNodeRef()); + NodeRef channelNode = new NodeRef(channel.getId()); + NodeRef publishedNode = channelHelper.mapSourceToEnvironment(entry.getNodeRef(), channelNode); if(NodeUtils.exists(publishedNode, nodeService)) { channel.unPublish(publishedNode); diff --git a/source/java/org/alfresco/repo/publishing/PublishingIntegratedTest.java b/source/java/org/alfresco/repo/publishing/PublishingIntegratedTest.java index 538a343c6a..f8929d734f 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingIntegratedTest.java +++ b/source/java/org/alfresco/repo/publishing/PublishingIntegratedTest.java @@ -34,7 +34,7 @@ import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.model.FileFolderService; -import org.alfresco.service.cmr.publishing.MutablePublishingPackage; +import org.alfresco.service.cmr.publishing.PublishingDetails; import org.alfresco.service.cmr.publishing.PublishingEvent; import org.alfresco.service.cmr.publishing.PublishingPackageEntry; import org.alfresco.service.cmr.publishing.PublishingQueue; @@ -85,16 +85,20 @@ public class PublishingIntegratedTest extends BaseSpringTest } PublishingQueue liveQueue = publishingService.getPublishingQueue(); - MutablePublishingPackage publishingPackage = liveQueue.createPublishingPackageBuilder(); - publishingPackage.addNodesToPublish(nodes); - Calendar scheduleTime = Calendar.getInstance(); - scheduleTime.add(Calendar.HOUR, 1); - String eventId = liveQueue.scheduleNewEvent(publishingPackage, channel.getId(), scheduleTime, null, null); + Calendar schedule = Calendar.getInstance(); + schedule.add(Calendar.HOUR, 1); + + PublishingDetails details = liveQueue.createPublishingDetails() + .addNodesToPublish(nodes) + .setPublishChannel(channel.getId()) + .setSchedule(schedule); + + String eventId = liveQueue.scheduleNewEvent(details); PublishingEvent event = publishingService.getPublishingEvent(eventId); - Assert.assertEquals(scheduleTime, event.getScheduledTime()); + Assert.assertEquals(schedule, event.getScheduledTime()); Assert.assertEquals(eventId, event.getId()); Collection entries = event.getPackage().getEntries(); Assert.assertEquals(4, entries.size()); @@ -118,12 +122,14 @@ public class PublishingIntegratedTest extends BaseSpringTest NamespaceService.CONTENT_MODEL_1_0_URI, Integer.toString(i)), ContentModel.TYPE_CONTENT).getChildRef()); } PublishingQueue liveQueue = publishingService.getPublishingQueue(); - MutablePublishingPackage publishingPackage = liveQueue.createPublishingPackageBuilder(); - publishingPackage.addNodesToPublish(nodes); + Calendar schedule = Calendar.getInstance(); + schedule.add(Calendar.HOUR, 1); - Calendar scheduleTime = Calendar.getInstance(); - scheduleTime.add(Calendar.HOUR, 1); - String eventId = liveQueue.scheduleNewEvent(publishingPackage, channel.getId(), scheduleTime, null, null); + PublishingDetails details = liveQueue.createPublishingDetails() + .addNodesToPublish(nodes) + .setPublishChannel(channel.getId()) + .setSchedule(schedule); + String eventId = liveQueue.scheduleNewEvent(details); PublishingEvent event = publishingService.getPublishingEvent(eventId); Assert.assertNotNull(event); publishingService.cancelPublishingEvent(eventId); diff --git a/source/java/org/alfresco/repo/publishing/PublishingPackageEntryImpl.java b/source/java/org/alfresco/repo/publishing/PublishingPackageEntryImpl.java index 17cb585b1b..54a259cf67 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingPackageEntryImpl.java +++ b/source/java/org/alfresco/repo/publishing/PublishingPackageEntryImpl.java @@ -19,8 +19,6 @@ package org.alfresco.repo.publishing; -import org.alfresco.repo.transfer.manifest.TransferManifestNode; -import org.alfresco.repo.transfer.manifest.TransferManifestNormalNode; import org.alfresco.service.cmr.publishing.NodeSnapshot; import org.alfresco.service.cmr.publishing.PublishingPackageEntry; import org.alfresco.service.cmr.repository.NodeRef; @@ -36,17 +34,13 @@ class PublishingPackageEntryImpl implements PublishingPackageEntry { private final boolean publish; private final NodeRef nodeRef; - private final TransferManifestNormalNode payload; - private final String version; + private final NodeSnapshot snapshot; - public PublishingPackageEntryImpl(boolean publish, - NodeRef nodeRef, TransferManifestNormalNode payload, - String version) + public PublishingPackageEntryImpl(boolean publish, NodeRef nodeRef, NodeSnapshot snapshot) { this.publish = publish; this.nodeRef = nodeRef; - this.payload = payload; - this.version = version; + this.snapshot= snapshot; } /** @@ -65,20 +59,11 @@ class PublishingPackageEntryImpl implements PublishingPackageEntry return publish; } - /** - * @return the payload - */ - public TransferManifestNode getPayload() - { - return payload; - } - /** * {@inheritDoc} */ public NodeSnapshot getSnapshot() { - //TODO Add versioning information. - return new NodeSnapshotTransferImpl(payload, version); + return snapshot; } } diff --git a/source/java/org/alfresco/repo/publishing/PublishingPackageSerializerTest.java b/source/java/org/alfresco/repo/publishing/PublishingPackageSerializerTest.java index a73debbe88..db9e271ea9 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingPackageSerializerTest.java +++ b/source/java/org/alfresco/repo/publishing/PublishingPackageSerializerTest.java @@ -19,14 +19,11 @@ package org.alfresco.repo.publishing; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.Serializable; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -36,33 +33,27 @@ import java.util.Set; import javax.annotation.Resource; import org.alfresco.model.ContentModel; -import org.alfresco.repo.transaction.RetryingTransactionHelper; -import org.alfresco.repo.transfer.manifest.TransferManifestNodeFactory; import org.alfresco.repo.transfer.manifest.TransferManifestNormalNode; -import org.alfresco.service.cmr.publishing.PublishingPackageEntry; +import org.alfresco.service.cmr.publishing.NodeSnapshot; import org.alfresco.service.cmr.repository.AssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.Path; import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.transfer.TransferDefinition; -import org.alfresco.service.cmr.version.VersionService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.util.GUID; import org.junit.Before; import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; /** * @author Brian + * @author Nick Smith + * @since 4.0 * */ public class PublishingPackageSerializerTest extends AbstractPublishingIntegrationTest { - @Autowired - protected RetryingTransactionHelper retryingTransactionHelper; - @Resource(name="publishingPackageSerializer") private StandardPublishingPackageSerializer serializer; @@ -126,28 +117,20 @@ public class PublishingPackageSerializerTest extends AbstractPublishingIntegrati @Test public void testSerializer() throws Exception { - TransferManifestNodeFactory mockTMNFactory = mock(TransferManifestNodeFactory.class); - VersionService mockVersionService = mock(VersionService.class); - MutablePublishingPackageImpl packageImpl = new MutablePublishingPackageImpl(mockTMNFactory, mockVersionService); - - when(mockTMNFactory.createTransferManifestNode(any(NodeRef.class), any(TransferDefinition.class))) - .thenReturn(normalNode1); - - packageImpl.addNodesToPublish(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,"Hello")); - + NodeSnapshotTransferImpl transferSnapshot = new NodeSnapshotTransferImpl(normalNode1); ByteArrayOutputStream os = new ByteArrayOutputStream(); - serializer.serialize(packageImpl, os); + serializer.serialize(Collections.singleton(transferSnapshot), os); os.close(); byte[] output = os.toByteArray(); ByteArrayInputStream is = new ByteArrayInputStream(output); - Map entryMap = serializer.deserialize(is); - assertEquals(1, entryMap.size()); - assertTrue(entryMap.containsKey(normalNode1.getNodeRef())); - PublishingPackageEntryImpl entry = (PublishingPackageEntryImpl) entryMap.get(normalNode1.getNodeRef()); - assertEquals(TransferManifestNormalNode.class, entry.getPayload().getClass()); - TransferManifestNormalNode deserializedNode = (TransferManifestNormalNode) entry.getPayload(); - assertEquals(normalNode1.getType(), deserializedNode.getType()); + List snapshots = serializer.deserialize(is); + assertEquals(1, snapshots.size()); + NodeSnapshot snapshot = snapshots.get(0); + assertEquals(normalNode1.getNodeRef(), snapshot.getNodeRef()); + assertEquals(normalNode1.getType(), snapshot.getType()); + assertEquals(normalNode1.getAspects(), snapshot.getAspects()); + assertEquals(normalNode1.getProperties(), snapshot.getProperties()); } } diff --git a/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java b/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java index 602e6bbf67..d979fad430 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java +++ b/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java @@ -20,20 +20,16 @@ package org.alfresco.repo.publishing; import java.util.Arrays; -import java.util.Calendar; import java.util.Collection; import java.util.List; import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.transfer.manifest.TransferManifestNodeFactory; -import org.alfresco.service.cmr.publishing.MutablePublishingPackage; +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; import org.alfresco.service.cmr.publishing.PublishingQueue; import org.alfresco.service.cmr.publishing.StatusUpdate; import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.version.VersionService; /** * @author Brian @@ -44,25 +40,20 @@ public class PublishingQueueImpl implements PublishingQueue { private final static String MSG_FAILED_TO_CREATE_PUBLISHING_EVENT = "publishing-create-event-failed"; private final NodeRef nodeRef; - private final TransferManifestNodeFactory transferManifestNodeFactory; - private final VersionService versionService; private final PublishingEventHelper publishingEventHelper; - public PublishingQueueImpl(NodeRef nodeRef, PublishingEventHelper publishingEventHelper, - VersionService versionService, TransferManifestNodeFactory transferManifestNodeFactory) + public PublishingQueueImpl(NodeRef nodeRef, PublishingEventHelper publishingEventHelper) { this.nodeRef = nodeRef; this.publishingEventHelper = publishingEventHelper; - this.versionService = versionService; - this.transferManifestNodeFactory = transferManifestNodeFactory; } /** * {@inheritDoc} */ - public MutablePublishingPackage createPublishingPackageBuilder() + public PublishingDetails createPublishingDetails() { - return new MutablePublishingPackageImpl(transferManifestNodeFactory, versionService); + return publishingEventHelper.createPublishingPackageBuilder(); } /** @@ -100,12 +91,12 @@ public class PublishingQueueImpl implements PublishingQueue /** * {@inheritDoc} */ - public String scheduleNewEvent(PublishingPackage publishingPackage, String channelId, Calendar schedule, String comment, StatusUpdate statusUpdate) + public String scheduleNewEvent(PublishingDetails publishingDetails) { try { - NodeRef eventNode = publishingEventHelper.createNode(nodeRef, publishingPackage, channelId, schedule, comment, statusUpdate); - publishingEventHelper.startPublishingWorkflow(eventNode, schedule); + NodeRef eventNode = publishingEventHelper.createNode(nodeRef, publishingDetails); + publishingEventHelper.startPublishingWorkflow(eventNode, publishingDetails.getSchedule()); return eventNode.toString(); } catch (Exception ex) diff --git a/source/java/org/alfresco/repo/publishing/PublishingQueueImplTest.java b/source/java/org/alfresco/repo/publishing/PublishingQueueImplTest.java index e453cef151..3073f1eb5d 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingQueueImplTest.java +++ b/source/java/org/alfresco/repo/publishing/PublishingQueueImplTest.java @@ -34,7 +34,7 @@ import java.util.Set; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.service.cmr.publishing.MutablePublishingPackage; +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; @@ -69,19 +69,22 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest { NodeRef firstNode = createContent("First"); NodeRef secondNode = createContent("second"); - - assertNull(nodeService.getProperty(firstNode, PROP_VERSION_LABEL)); - assertNull(nodeService.getProperty(firstNode, PROP_VERSION_LABEL)); - MutablePublishingPackage publishingPackage = publishingService.getPublishingQueue().createPublishingPackageBuilder(); - publishingPackage.addNodesToPublish(firstNode, secondNode); - NodeRef thirdNode = createContent("third"); - publishingPackage.addNodesToUnpublish(thirdNode); + assertNull(nodeService.getProperty(firstNode, PROP_VERSION_LABEL)); + assertNull(nodeService.getProperty(firstNode, PROP_VERSION_LABEL)); + Calendar schedule = Calendar.getInstance(); schedule.add(Calendar.HOUR, 2); - String eventId = publishingService.getPublishingQueue().scheduleNewEvent(publishingPackage, channelId, schedule, comment, null); + PublishingDetails details = publishingService.getPublishingQueue().createPublishingDetails() + .addNodesToPublish(firstNode, secondNode) + .addNodesToUnpublish(thirdNode) + .setPublishChannel(channelId) + .setSchedule(schedule) + .setComment(comment); + + String eventId = testHelper.scheduleEvent(details); //Check schedule triggered versioning. Serializable version = nodeService.getProperty(firstNode, PROP_VERSION_LABEL); @@ -120,7 +123,7 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest assertTrue(toUnpublish.contains(thirdNode)); // Check the correct version is recorded in the entry. - PublishingPackageEntry entry = publishingPackage.getEntryMap().get(firstNode); + PublishingPackageEntry entry = pckg.getEntryMap().get(firstNode); assertEquals(version, entry.getSnapshot().getVersion()); NodeRef eventNode = new NodeRef(eventId); @@ -141,16 +144,17 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest NodeRef firstNode = createContent("First"); NodeRef secondNode = createContent("Second"); - List channelNames = Arrays.asList("test://channel/Channel1", "test://channel/Channel2", "test://channel/Channel3" ); + List statusChannels = Arrays.asList("test://channel/Channel1", "test://channel/Channel2", "test://channel/Channel3" ); String message = "The message"; - StatusUpdate update = publishingService.getPublishingQueue().createStatusUpdate(message, secondNode, channelNames); + PublishingDetails details = publishingService.getPublishingQueue().createPublishingDetails() + .setPublishChannel(channelId) + .addNodesToPublish(firstNode, secondNode) + .setStatusMessage(message) + .setStatusNodeToLinkTo(secondNode) + .addStatusUpdateChannels(statusChannels); // Publish an event with the StatusUpdate - MutablePublishingPackage publishingPackage = publishingService.getPublishingQueue().createPublishingPackageBuilder(); - publishingPackage.addNodesToPublish(firstNode, secondNode); - Calendar schedule = Calendar.getInstance(); - schedule.add(Calendar.HOUR, 2); - String eventId = testHelper.scheduleEvent1Year(publishingPackage, channelId, comment, update); + String eventId = testHelper.scheduleEvent1Year(details); PublishingEvent event = publishingService.getPublishingEvent(eventId); StatusUpdate actualUpdate = event.getStatusUpdate(); @@ -158,7 +162,7 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest assertEquals(secondNode, actualUpdate.getNodeToLinkTo()); Set names = actualUpdate.getChannelIds(); assertEquals(3, names.size()); - assertTrue(names.containsAll(channelNames)); + assertTrue(names.containsAll(statusChannels)); } @Test @@ -180,11 +184,12 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest personManager.setUser(user1); // Publish an event - MutablePublishingPackage publishingPackage = publishingService.getPublishingQueue().createPublishingPackageBuilder(); - publishingPackage.addNodesToPublish(firstNode, secondNode); + PublishingDetails details = publishingService.getPublishingQueue().createPublishingDetails(); + details.addNodesToPublish(firstNode, secondNode); + details.setPublishChannel(publishChannel.getId()); try { - testHelper.scheduleEvent1Year(publishingPackage, publishChannel.getId(), null, null); + testHelper.scheduleEvent1Year(details); fail("shceduleNewEvent should have thrown an AccessDeniedException!"); } catch(AlfrescoRuntimeException e) @@ -196,14 +201,16 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest testHelper.allowChannelAccess(user1, publishChannel.getId()); // Check publish works now. - String eventId = testHelper.scheduleEvent1Year(publishingPackage, publishChannel.getId(), null, null); + String eventId = testHelper.scheduleEvent1Year(details); assertNotNull(eventId); String message = "The message"; - StatusUpdate update = publishingService.getPublishingQueue().createStatusUpdate(message, secondNode, statusChannel.getId()); + details.setStatusMessage(message) + .setStatusNodeToLinkTo(secondNode) + .addStatusUpdateChannels(statusChannel.getId()); try { - eventId = testHelper.scheduleEvent1Year(publishingPackage, publishChannel.getId(), null, update); + eventId = testHelper.scheduleEvent1Year(details); fail("shceduleNewEvent with status update should have thrown an AccessDeniedException!"); } catch(AlfrescoRuntimeException e) @@ -215,7 +222,7 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest testHelper.allowChannelAccess(user1, statusChannel.getId()); // Check publish works now. - eventId = testHelper.scheduleEvent1Year(publishingPackage, publishChannel.getId(), null, update); + eventId = testHelper.scheduleEvent1Year(details); assertNotNull(eventId); } diff --git a/source/java/org/alfresco/repo/publishing/PublishingRootObject.java b/source/java/org/alfresco/repo/publishing/PublishingRootObject.java index 92d6461bac..ce2d080566 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingRootObject.java +++ b/source/java/org/alfresco/repo/publishing/PublishingRootObject.java @@ -32,14 +32,12 @@ 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.repo.transfer.manifest.TransferManifestNodeFactory; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.cmr.version.VersionService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.RegexQNamePattern; @@ -60,8 +58,6 @@ public class PublishingRootObject private PublishingEventHelper publishingEventHelper; private NamespaceService namespaceService; private SearchService searchService; - private VersionService versionService; - private TransferManifestNodeFactory transferManifestNodeFactory; private RetryingTransactionHelper retryingTransactionHelper; private PermissionService permissionService; @@ -122,7 +118,7 @@ public class PublishingRootObject private PublishingQueueImpl createPublishingQueue(NodeRef environmentNode) { NodeRef queueNode = getPublishingQueueNode(environmentNode); - return new PublishingQueueImpl(queueNode, publishingEventHelper, versionService, transferManifestNodeFactory); + return new PublishingQueueImpl(queueNode, publishingEventHelper); } private NodeRef getPublishingQueueNode(NodeRef environmentNode) @@ -220,22 +216,6 @@ public class PublishingRootObject this.searchService = searchService; } - /** - * @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 permissionService the permissionService to set */ diff --git a/source/java/org/alfresco/repo/publishing/PublishingTestHelper.java b/source/java/org/alfresco/repo/publishing/PublishingTestHelper.java index b3dc009057..de8c72fc31 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingTestHelper.java +++ b/source/java/org/alfresco/repo/publishing/PublishingTestHelper.java @@ -20,8 +20,8 @@ package org.alfresco.repo.publishing; import static org.alfresco.model.ContentModel.TYPE_CONTENT; -import static org.alfresco.repo.publishing.PublishingModel.TYPE_DELIVERY_CHANNEL; import static org.alfresco.repo.publishing.PublishingModel.PROP_AUTHORISATION_COMPLETE; +import static org.alfresco.repo.publishing.PublishingModel.TYPE_DELIVERY_CHANNEL; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.when; @@ -39,10 +39,9 @@ import org.alfresco.model.ContentModel; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.service.cmr.model.FileFolderService; -import org.alfresco.service.cmr.publishing.PublishingPackage; +import org.alfresco.service.cmr.publishing.PublishingDetails; import org.alfresco.service.cmr.publishing.PublishingQueue; import org.alfresco.service.cmr.publishing.PublishingService; -import org.alfresco.service.cmr.publishing.StatusUpdate; import org.alfresco.service.cmr.publishing.channels.Channel; import org.alfresco.service.cmr.publishing.channels.ChannelService; import org.alfresco.service.cmr.publishing.channels.ChannelType; @@ -53,7 +52,6 @@ import org.alfresco.service.cmr.site.SiteService; import org.alfresco.service.cmr.site.SiteVisibility; import org.alfresco.service.namespace.QName; import org.alfresco.util.GUID; -import org.alfresco.util.collections.CollectionUtils; /** * @author Nick Smith @@ -213,17 +211,18 @@ public class PublishingTestHelper }, AuthenticationUtil.getSystemUserName()); } - public String scheduleEvent1Year(PublishingPackage pckg, String channelId, String comment, StatusUpdate statusUpdate) + public String scheduleEvent1Year(PublishingDetails details) { Calendar schedule = Calendar.getInstance(); schedule.add(Calendar.YEAR, 1); - return scheduleEvent(pckg, channelId, schedule, comment, statusUpdate); + details.setSchedule(schedule); + return scheduleEvent(details); } - public String scheduleEvent(PublishingPackage pckg, String channelId, Calendar schedule, String comment, StatusUpdate statusUpdate) + public String scheduleEvent(PublishingDetails details) { PublishingQueue queue = publishingService.getPublishingQueue(); - String eventId = queue.scheduleNewEvent(pckg, channelId, schedule, comment, statusUpdate); + String eventId = queue.scheduleNewEvent(details); events.add(eventId); return eventId; } diff --git a/source/java/org/alfresco/repo/publishing/StandardPublishingPackageSerializer.java b/source/java/org/alfresco/repo/publishing/StandardPublishingPackageSerializer.java index cdfad0f786..1c6449b81e 100644 --- a/source/java/org/alfresco/repo/publishing/StandardPublishingPackageSerializer.java +++ b/source/java/org/alfresco/repo/publishing/StandardPublishingPackageSerializer.java @@ -22,62 +22,57 @@ package org.alfresco.repo.publishing; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; -import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.io.Writer; +import java.util.ArrayList; +import java.util.Collection; import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import java.util.List; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; -import org.alfresco.model.ContentModel; import org.alfresco.repo.transfer.manifest.TransferManifestDeletedNode; import org.alfresco.repo.transfer.manifest.TransferManifestHeader; import org.alfresco.repo.transfer.manifest.TransferManifestNormalNode; 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.PublishingPackage; -import org.alfresco.service.cmr.publishing.PublishingPackageEntry; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.namespace.QName; +import org.alfresco.service.cmr.publishing.NodeSnapshot; import org.xml.sax.SAXException; /** * @author Brian * @author Nick Smith */ -public class StandardPublishingPackageSerializer implements PublishingPackageSerializer +public class StandardPublishingPackageSerializer implements NodeSnapshotSerializer { /** - * {@inheritDoc} - * @return - */ - public Map deserialize(InputStream input) throws Exception + * {@inheritDoc} + */ + @Override + public List deserialize(InputStream input) throws Exception { SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); SAXParser parser = saxParserFactory.newSAXParser(); - PublishingPackageDeserializer processor = new PublishingPackageDeserializer(); + NodeSnapshotDeserializer processor = new NodeSnapshotDeserializer(); XMLTransferManifestReader xmlReader = new XMLTransferManifestReader(processor); parser.parse(input, xmlReader); - return processor.getEntries(); + return processor.getSnapshots(); } /** * {@inheritDoc} - */ - public void serialize(PublishingPackage publishingPackage, OutputStream output) throws Exception - { + */ + public void serialize(Collection snapshots, OutputStream output) throws Exception + { try { - Set nodesToPublish = publishingPackage.getNodesToPublish(); + TransferManifestHeader header = new TransferManifestHeader(); header.setCreatedDate(new Date()); - header.setNodeCount(nodesToPublish.size()); + header.setNodeCount(snapshots.size()); header.setReadOnly(false); header.setSync(false); @@ -88,14 +83,12 @@ public class StandardPublishingPackageSerializer implements PublishingPackageSer transferManifestWriter.writeTransferManifestHeader(header); // Iterate over NodesToPublish and Serialize. - Map entryMap = publishingPackage.getEntryMap(); - for (NodeRef publishNode: nodesToPublish) + for (NodeSnapshot snapshot: snapshots) { - PublishingPackageEntry entry = entryMap.get(publishNode); - if (entry instanceof PublishingPackageEntryImpl) + if (snapshot instanceof NodeSnapshotTransferImpl) { - PublishingPackageEntryImpl entryImpl = (PublishingPackageEntryImpl)entry; - transferManifestWriter.writeTransferManifestNode(entryImpl.getPayload()); + NodeSnapshotTransferImpl snapshotImpl = (NodeSnapshotTransferImpl)snapshot; + transferManifestWriter.writeTransferManifestNode(snapshotImpl.getTransferNode()); } } transferManifestWriter.endTransferManifest(); @@ -117,18 +110,19 @@ public class StandardPublishingPackageSerializer implements PublishingPackageSer * @author Nick Smith * */ - public static class PublishingPackageDeserializer implements TransferManifestProcessor + public static class NodeSnapshotDeserializer implements TransferManifestProcessor { - Map entries = new HashMap(); + private List snapshots = new ArrayList(); - /** - * @return the entries - */ - public Map getEntries() - { - return entries; - } + /** + * @return the snapshots + */ + public List getSnapshots() + { + return snapshots; + } + /** * {@inheritDoc} */ @@ -142,9 +136,8 @@ public class StandardPublishingPackageSerializer implements PublishingPackageSer */ public void processTransferManifestNode(TransferManifestNormalNode node) { - Map props = node.getProperties(); - String version = (String) props.get(ContentModel.PROP_VERSION_LABEL); - entries.put(node.getNodeRef(), new PublishingPackageEntryImpl(true, node.getNodeRef(), node, version)); + NodeSnapshotTransferImpl snapshot = new NodeSnapshotTransferImpl(node); + snapshots.add(snapshot); } /** @@ -152,7 +145,7 @@ public class StandardPublishingPackageSerializer implements PublishingPackageSer */ public void processTransferManifestNode(TransferManifestDeletedNode node) { - entries.put(node.getNodeRef(), new PublishingPackageEntryImpl(false, node.getNodeRef(), null, null)); + //NOOP } /** diff --git a/source/java/org/alfresco/service/cmr/publishing/NodeSnapshot.java b/source/java/org/alfresco/service/cmr/publishing/NodeSnapshot.java index b33fa7d9d3..bd8a706721 100644 --- a/source/java/org/alfresco/service/cmr/publishing/NodeSnapshot.java +++ b/source/java/org/alfresco/service/cmr/publishing/NodeSnapshot.java @@ -20,18 +20,16 @@ package org.alfresco.service.cmr.publishing; import java.io.Serializable; -import java.util.List; import java.util.Map; import java.util.Set; -import org.alfresco.service.cmr.repository.AssociationRef; -import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.Path; import org.alfresco.service.namespace.QName; /** * @author Brian + * @author Nick Smith + * @since 4.0 * */ public interface NodeSnapshot @@ -42,37 +40,12 @@ public interface NodeSnapshot */ NodeRef getNodeRef(); - /** - * Retrieve the primary parent association of the node at the moment this snapshot was taken - * @return The ChildAssociationRef object that describes the primary parent association of the node - */ - ChildAssociationRef getPrimaryParentAssoc(); - - /** - * Retrieve the primary path to the node at the moment this snapshot was taken. Note that the elements in this path describe - * the associations between the nodes in the hierarchy - not the "display path" - * @return A Path object that describes the primary path to the node - */ - Path getPrimaryPath(); - /** * The property values assigned to the node at the moment the snapshot was taken. * @return A map that associates property names to property values for the node. */ Map getProperties(); - - /** - * Retrieve all the parent associations of the node at the moment the snapshot was taken - * @return A list of ChildAssociationRef objects, each describing one parent association of the node. - */ - List getAllParentAssocs(); - - /** - * Retrieve all the peer associations for which this node was the source at the moment the snapshot was taken - * @return A list of AssociationRef objects, each describing a peer association for which this node is the source - */ - List getOutboundPeerAssociations(); - + /** * Retrieve the type of the node at the moment the snapshot was taken. * @return The QName that identifies the type of the node diff --git a/source/java/org/alfresco/service/cmr/publishing/PublishingDetails.java b/source/java/org/alfresco/service/cmr/publishing/PublishingDetails.java new file mode 100644 index 0000000000..3b225c0b04 --- /dev/null +++ b/source/java/org/alfresco/service/cmr/publishing/PublishingDetails.java @@ -0,0 +1,95 @@ +/* + * 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.service.cmr.publishing; + +import java.util.Calendar; +import java.util.Collection; +import java.util.Set; + +import org.alfresco.service.cmr.repository.NodeRef; + +/** + * A simple DTO used to gather parameters for scheduling a Publishing Event. + * + * @author Brian + * @author Nick Smith + * + * @since 4.0 + */ +public interface PublishingDetails +{ + PublishingDetails addNodesToUnpublish(NodeRef... nodesToRemove); + + PublishingDetails addNodesToUnpublish(Collection nodesToRemove); + + PublishingDetails addNodesToPublish(NodeRef... nodesToPublish); + + PublishingDetails addNodesToPublish(Collection nodesToPublish); + + PublishingDetails setPublishChannel(String channelId); + + PublishingDetails setComment(String comment); + + PublishingDetails setSchedule(Calendar schedule); + + PublishingDetails setStatusMessage(String message); + + PublishingDetails setStatusNodeToLinkTo(NodeRef nodeToLinkTo); + + PublishingDetails addStatusUpdateChannels(Collection channelIds); + PublishingDetails addStatusUpdateChannels(String... channelIds); + + /** + * @return the comment + */ + String getComment(); + + /** + * @return the message + */ + String getStatusMessage(); + + /** + * @return the nodeToLinkTo + */ + NodeRef getNodeToLinkTo(); + + /** + * @return the publishChannelId + */ + String getPublishChannelId(); + + /** + * @return the schedule + */ + Calendar getSchedule(); + + Set getStatusUpdateChannels(); + + /** + * @return a {@link Set} of all the {@link NodeRef}s to be published. + */ + Set getNodesToPublish(); + + /** + * @return a {@link Set} of all the {@link NodeRef}s to be unpublished. + */ + Set getNodesToUnpublish(); + +} diff --git a/source/java/org/alfresco/service/cmr/publishing/PublishingQueue.java b/source/java/org/alfresco/service/cmr/publishing/PublishingQueue.java index 7f15a463ee..76b3df1b9f 100644 --- a/source/java/org/alfresco/service/cmr/publishing/PublishingQueue.java +++ b/source/java/org/alfresco/service/cmr/publishing/PublishingQueue.java @@ -19,31 +19,20 @@ package org.alfresco.service.cmr.publishing; -import java.util.Calendar; -import java.util.Collection; - -import org.alfresco.service.cmr.repository.NodeRef; public interface PublishingQueue { /** * A factory method to create an empty publishing package that can be populated before being passed into - * a call to the {@link PublishingQueue#scheduleNewEvent(PublishingPackage, String, Calendar, String, StatusUpdate)} operation. + * a call to the {@link PublishingQueue#scheduleNewEvent(PublishingDetails)} operation. * @return A publishing package that can be populated before being placed on the publishing queue. */ - MutablePublishingPackage createPublishingPackageBuilder(); + PublishingDetails createPublishingDetails(); - StatusUpdate createStatusUpdate(String message, NodeRef nodeToLinkTo, String... channelIds); - StatusUpdate createStatusUpdate(String message, NodeRef nodeToLinkTo, Collection channelIds); - /** * Adds the supplied publishing package onto the queue. - * @param publishingPackage The publishing package that is to be enqueued - * @param channelId The name of the channel that the package is to be published to - * @param schedule The time at which the new publishing event should be scheduled (optional - null indicates "as soon as possible") - * @param comment A comment to be stored with this new event (optional - may be null) - * @param statusUpdate defines the status update (if any). If null then no status update is sent. + * @param publishingDetails The publishing package that is to be enqueued * @return The identifier of the newly scheduled event */ - String scheduleNewEvent(PublishingPackage publishingPackage, String channelId, Calendar schedule, String comment, StatusUpdate statusUpdate); + String scheduleNewEvent(PublishingDetails publishingDetails); }