From 2c3c17229b220234c1adc5254f7443157d8cd5d4 Mon Sep 17 00:00:00 2001 From: N Smith Date: Thu, 21 Jul 2011 16:10:17 +0000 Subject: [PATCH] Removed the siteId from all PublishingService and ChannelService methods. These services are no longer tied to a Share site. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29255 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../bootstrap/publishingRootFolder.xml | 16 + config/alfresco/import-export-context.xml | 9 + .../messages/bootstrap-spaces.properties | 3 + .../alfresco/patch/patch-services-context.xml | 26 ++ config/alfresco/repository.properties | 4 +- config/alfresco/version.properties | 2 +- config/alfresco/web-publishing-context.xml | 23 +- .../alfresco/test-web-publishing-context.xml | 17 +- .../org/alfresco/repo/node/NodeUtils.java | 20 ++ .../AbstractPublishingIntegrationTest.java | 20 +- .../repo/publishing/ChannelHelper.java | 13 +- .../repo/publishing/ChannelServiceImpl.java | 126 +++----- .../ChannelServiceImplIntegratedTest.java | 73 ++--- .../alfresco/repo/publishing/Environment.java | 63 ++++ .../repo/publishing/EnvironmentFactory.java | 30 -- .../repo/publishing/EnvironmentHelper.java | 289 ++++-------------- .../publishing/EnvironmentHelperTest.java | 64 ---- .../repo/publishing/EnvironmentImpl.java | 114 ------- .../repo/publishing/EnvironmentImplTest.java | 133 ++++---- .../publishing/PublishEventActionTest.java | 4 +- .../repo/publishing/PublishServiceImpl.java | 87 ++---- .../publishing/PublishingEventProcessor.java | 4 +- .../publishing/PublishingIntegratedTest.java | 4 +- .../publishing/PublishingObjectFactory.java | 117 ------- .../repo/publishing/PublishingQueueImpl.java | 50 +-- .../publishing/PublishingQueueImplTest.java | 3 +- .../repo/publishing/PublishingRootObject.java | 254 +++++++++++++++ .../publishing/PublishingRootObjectTest.java | 81 +++++ .../publishing/WebPublishingTestSuite.java | 4 +- .../repo/publishing/flickr/FlickrTest.java | 8 +- .../publishing/slideshare/SlideShareTest.java | 6 +- .../repo/publishing/test/SiteType.java | 6 +- .../repo/publishing/youtube/YouTubeTest.java | 6 +- .../cmr/publishing/PublishingService.java | 6 +- .../publishing/channels/ChannelService.java | 27 +- 35 files changed, 778 insertions(+), 934 deletions(-) create mode 100644 config/alfresco/bootstrap/publishingRootFolder.xml create mode 100644 source/java/org/alfresco/repo/publishing/Environment.java delete mode 100644 source/java/org/alfresco/repo/publishing/EnvironmentFactory.java delete mode 100644 source/java/org/alfresco/repo/publishing/EnvironmentHelperTest.java delete mode 100644 source/java/org/alfresco/repo/publishing/EnvironmentImpl.java delete mode 100644 source/java/org/alfresco/repo/publishing/PublishingObjectFactory.java create mode 100644 source/java/org/alfresco/repo/publishing/PublishingRootObject.java create mode 100644 source/java/org/alfresco/repo/publishing/PublishingRootObjectTest.java diff --git a/config/alfresco/bootstrap/publishingRootFolder.xml b/config/alfresco/bootstrap/publishingRootFolder.xml new file mode 100644 index 0000000000..3bed60601a --- /dev/null +++ b/config/alfresco/bootstrap/publishingRootFolder.xml @@ -0,0 +1,16 @@ + + + + + + workspace + SpacesStore + publishing_root_space + ${spaces.publishing.root.name} + ${spaces.publishing.root.name} + ${spaces.publishing.root.description} + + + diff --git a/config/alfresco/import-export-context.xml b/config/alfresco/import-export-context.xml index befb9626de..40f5799696 100644 --- a/config/alfresco/import-export-context.xml +++ b/config/alfresco/import-export-context.xml @@ -397,6 +397,7 @@ ${spaces.rendition.rendering_actions.childname} ${spaces.replication.replication_actions.childname} ${spaces.wcm_deployed.childname} + ${spaces.publishing.root.childname} @@ -664,6 +665,14 @@ alfresco/messages/bootstrap-spaces + + + ${publishing.root.path} + alfresco/bootstrap/publishingRootFolder.xml + alfresco/messages/bootstrap-spaces + + diff --git a/config/alfresco/messages/bootstrap-spaces.properties b/config/alfresco/messages/bootstrap-spaces.properties index a6af51e5a5..dfc950091e 100644 --- a/config/alfresco/messages/bootstrap-spaces.properties +++ b/config/alfresco/messages/bootstrap-spaces.properties @@ -42,6 +42,9 @@ spaces.templates.rss.description=RSS templates spaces.actions.scheduled_actions.name=Scheduled Actions spaces.actions.scheduled_actions.description=Schedule of when persistent actions are executed +spaces.publishing.root.name=Publishing Root +spaces.publishing.root.description=Root folder for the PublishingService. + spaces.rendition.rendering_actions.name=Rendering Actions Space spaces.rendition.rendering_actions.description=A space used by the system to persist rendering actions. diff --git a/config/alfresco/patch/patch-services-context.xml b/config/alfresco/patch/patch-services-context.xml index 08ee6171ef..76a80080bd 100644 --- a/config/alfresco/patch/patch-services-context.xml +++ b/config/alfresco/patch/patch-services-context.xml @@ -2421,6 +2421,32 @@ + + patch.publishing.root + patch.publishing.root.description + 0 + 5013 + 5014 + + + + + + + + + + ${publishing.root} + + + + ${publishing.root.path} + alfresco/bootstrap/publishingRootFolder.xml + alfresco/messages/bootstrap-spaces + + + + patch.updateMimetypes2 patch.updateMimetypes2.description diff --git a/config/alfresco/repository.properties b/config/alfresco/repository.properties index 7eb93d9d30..30daf7346d 100644 --- a/config/alfresco/repository.properties +++ b/config/alfresco/repository.properties @@ -407,6 +407,7 @@ spaces.webscripts.childname=cm:webscripts spaces.extension_webscripts.childname=cm:extensionwebscripts spaces.models.childname=app:models spaces.workflow.definitions.childname=app:workflow_defs +spaces.publishing.root.childname=app:publishing_root # ADM VersionStore Configuration version.store.deprecated.lightWeightVersionStore=workspace://lightWeightVersionStore @@ -681,7 +682,8 @@ solr.secureComms.enabled=true # # Web Publishing Properties # -publishing.default.environment=live +publishing.root.path=/app:company_home/app:dictionary +publishing.root=${publishing.root.path}/${spaces.publishing.root.childname} # # URL Shortening Properties diff --git a/config/alfresco/version.properties b/config/alfresco/version.properties index deaacd344a..2b49cf88a5 100644 --- a/config/alfresco/version.properties +++ b/config/alfresco/version.properties @@ -19,4 +19,4 @@ version.build=@build-number@ # Schema number -version.schema=5013 +version.schema=5014 diff --git a/config/alfresco/web-publishing-context.xml b/config/alfresco/web-publishing-context.xml index c6e80b8b31..71a4d0e90f 100644 --- a/config/alfresco/web-publishing-context.xml +++ b/config/alfresco/web-publishing-context.xml @@ -39,10 +39,9 @@ + - - @@ -58,11 +57,16 @@ - + - + + + - + + + + @@ -89,17 +93,10 @@ - - - - - - - - + diff --git a/config/test/alfresco/test-web-publishing-context.xml b/config/test/alfresco/test-web-publishing-context.xml index d674116bd5..2d74757cb3 100644 --- a/config/test/alfresco/test-web-publishing-context.xml +++ b/config/test/alfresco/test-web-publishing-context.xml @@ -75,11 +75,26 @@ - + + + + + + + + + + + + + + + + diff --git a/source/java/org/alfresco/repo/node/NodeUtils.java b/source/java/org/alfresco/repo/node/NodeUtils.java index 287c1f7336..a7b930f44b 100644 --- a/source/java/org/alfresco/repo/node/NodeUtils.java +++ b/source/java/org/alfresco/repo/node/NodeUtils.java @@ -22,6 +22,7 @@ package org.alfresco.repo.node; import java.util.Collection; import java.util.List; +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.NodeService; @@ -110,4 +111,23 @@ public abstract class NodeUtils }; } + public static NodeRef getSingleChildAssocNode(Collection assocs, boolean getChild) + { + if(assocs != null && assocs.size()==1 ) + { + ChildAssociationRef association = assocs.iterator().next(); + return getChild ? association.getChildRef() : association.getParentRef(); + } + return null; + } + + public static NodeRef getSingleAssocNode(Collection assocs, boolean getTarget) + { + if(assocs != null && assocs.size()==1 ) + { + AssociationRef association = assocs.iterator().next(); + return getTarget ? association.getTargetRef() : association.getSourceRef(); + } + return null; + } } diff --git a/source/java/org/alfresco/repo/publishing/AbstractPublishingIntegrationTest.java b/source/java/org/alfresco/repo/publishing/AbstractPublishingIntegrationTest.java index bf87a071cc..7daaf08b37 100644 --- a/source/java/org/alfresco/repo/publishing/AbstractPublishingIntegrationTest.java +++ b/source/java/org/alfresco/repo/publishing/AbstractPublishingIntegrationTest.java @@ -23,11 +23,7 @@ import static org.alfresco.repo.publishing.PublishingModel.TYPE_DELIVERY_CHANNEL import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import javax.transaction.HeuristicMixedException; -import javax.transaction.HeuristicRollbackException; -import javax.transaction.RollbackException; import javax.transaction.Status; -import javax.transaction.SystemException; import javax.transaction.UserTransaction; import org.alfresco.model.ContentModel; @@ -43,7 +39,6 @@ import org.alfresco.util.BaseSpringTest; import org.alfresco.util.GUID; import org.junit.After; import org.junit.Before; -import org.mockito.Mockito; /** * @author Nick Smith @@ -54,7 +49,7 @@ public abstract class AbstractPublishingIntegrationTest extends BaseSpringTest { protected static final String channelTypeId = "MockChannelType"; - protected PublishingObjectFactory factory; + protected PublishingRootObject rootObject; protected ServiceRegistry serviceRegistry; @@ -64,15 +59,17 @@ public abstract class AbstractPublishingIntegrationTest extends BaseSpringTest protected String siteId; protected PublishingQueueImpl queue; - protected EnvironmentImpl environment; + protected Environment environment; protected NodeRef docLib; protected UserTransaction transaction; + @Override @Before public void onSetUp() throws Exception { - factory = (PublishingObjectFactory) getApplicationContext().getBean("publishingObjectFactory"); + super.onSetUp(); + this.rootObject = (PublishingRootObject) getApplicationContext().getBean("publishingRootObject"); serviceRegistry = (ServiceRegistry) getApplicationContext().getBean("ServiceRegistry"); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); this.siteService = serviceRegistry.getSiteService(); @@ -90,12 +87,12 @@ public abstract class AbstractPublishingIntegrationTest extends BaseSpringTest SiteVisibility.PUBLIC); this.docLib = siteService.createContainer(siteId, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null); - this.environment = (EnvironmentImpl) factory.createEnvironmentObject(siteId); - this.queue = (PublishingQueueImpl) environment.getPublishingQueue(); + this.environment = rootObject.getEnvironment(); + this.queue = rootObject.getPublishingQueue(); } @After - public void onTearDown() + public void onTearDown() throws Exception { siteService.deleteSite(siteId); try @@ -114,6 +111,7 @@ public abstract class AbstractPublishingIntegrationTest extends BaseSpringTest e.printStackTrace(); throw new RuntimeException(e); } + super.onTearDown(); } protected ChannelType mockChannelType() diff --git a/source/java/org/alfresco/repo/publishing/ChannelHelper.java b/source/java/org/alfresco/repo/publishing/ChannelHelper.java index 30ac71b6e4..143fc86434 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelHelper.java +++ b/source/java/org/alfresco/repo/publishing/ChannelHelper.java @@ -36,6 +36,7 @@ import java.util.Map; import java.util.Set; import org.alfresco.model.ContentModel; +import org.alfresco.repo.node.NodeUtils; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.PropertyDefinition; import org.alfresco.service.cmr.dictionary.TypeDefinition; @@ -143,7 +144,7 @@ public class ChannelHelper public NodeRef mapEnvironmentToSource(NodeRef publishedNode) { List assocs = nodeService.getTargetAssocs(publishedNode, ASSOC_SOURCE); - return getSingleValue(assocs, true); + return NodeUtils.getSingleAssocNode(assocs, true); } /** @@ -326,16 +327,6 @@ public class ChannelHelper return null; } - private NodeRef getSingleValue(List assocs, boolean getChild) - { - if(assocs != null && assocs.size()==1 ) - { - AssociationRef association = assocs.get(0); - return getChild ? association.getTargetRef() : association.getSourceRef(); - } - return null; - } - private Function getChannelTransformer(final ChannelService channelService) { return new Function() diff --git a/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java b/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java index 5e90e11364..e5426ba590 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java +++ b/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java @@ -26,15 +26,11 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.TreeMap; 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.dictionary.DictionaryService; import org.alfresco.service.cmr.publishing.channels.Channel; import org.alfresco.service.cmr.publishing.channels.ChannelService; @@ -60,27 +56,15 @@ import org.alfresco.util.collections.Function; */ public class ChannelServiceImpl implements ChannelService { - - private static final String CHANNEL_CONTAINER_NAME = "channels"; - public static final String NAME = "channelService"; private final Map channelTypes = new TreeMap(); private SiteService siteService; private NodeService nodeService; private DictionaryService dictionaryService; - private EnvironmentHelper environmentHelper; private ChannelHelper channelHelper; + private PublishingRootObject rootObject; - /** - * @param siteService - * the siteService to set - */ - public void setSiteService(SiteService siteService) - { - this.siteService = siteService; - } - /** * @param nodeService * the nodeService to set @@ -100,14 +84,13 @@ public class ChannelServiceImpl implements ChannelService } /** - * @param environmentHelper - * the environmentHelper to set + * @param rootObject the rootObject to set */ - public void setEnvironmentHelper(EnvironmentHelper environmentHelper) + public void setPublishingRootObject(PublishingRootObject rootObject) { - this.environmentHelper = environmentHelper; + this.rootObject = rootObject; } - + /** * @param channelHelper the channelHelper to set */ @@ -141,13 +124,9 @@ public class ChannelServiceImpl implements ChannelService /** * {@inheritDoc} */ - public Channel createChannel(String siteId, String channelTypeId, String name, Map properties) + public Channel createChannel(String channelTypeId, String name, Map properties) { - NodeRef channelContainer = getChannelContainer(siteId); - if(channelContainer==null) - { - channelContainer = createChannelContainer(siteId); - } + NodeRef channelContainer = getChannelContainer(); ChannelType channelType = channelTypes.get(channelTypeId); if(channelType == null) { @@ -177,22 +156,27 @@ public class ChannelServiceImpl implements ChannelService /** * {@inheritDoc} */ - public List getChannels(String siteId) + public List getChannels() { - ParameterCheck.mandatory("siteId", siteId); - NodeRef channelContainer = getChannelContainer(siteId); + NodeRef channelContainer = getChannelContainer(); return channelHelper.getChannels(channelContainer, this); } /** * {@inheritDoc} */ - public Channel getChannel(String siteId, String channelName) + @Override + public Channel getChannelByName(String channelName) + { + NodeRef node = getChannelNodeByName(channelName); + return channelHelper.buildChannelObject(node, this); + } + + private NodeRef getChannelNodeByName(String channelName) { - ParameterCheck.mandatory("siteId", siteId); ParameterCheck.mandatory("channelName", channelName); - NodeRef channelContainer = getChannelContainer(siteId); + NodeRef channelContainer = getChannelContainer(); if(channelContainer == null) { return null; @@ -204,7 +188,7 @@ public class ChannelServiceImpl implements ChannelService QName type = nodeService.getType(child); if(dictionaryService.isSubClass(type, TYPE_DELIVERY_CHANNEL)) { - return channelHelper.buildChannelObject(child, this); + return child; } } return null; @@ -215,25 +199,17 @@ public class ChannelServiceImpl implements ChannelService */ public List getRelevantPublishingChannels(NodeRef nodeToPublish) { - SiteInfo siteInfo = siteService.getSite(nodeToPublish); - if(siteInfo != null) - { - final NodeRef containerNode = getChannelContainer(siteInfo.getShortName()); - if(containerNode != null) - { - List types = channelHelper.getReleventChannelTypes(nodeToPublish, channelTypes.values()); - return getChannelsForTypes(containerNode, types); - } - } - return Collections.emptyList(); + NodeRef containerNode = getChannelContainer(); + List types = channelHelper.getReleventChannelTypes(nodeToPublish, channelTypes.values()); + return getChannelsForTypes(containerNode, types); } /** * {@inheritDoc} */ - public List getPublishingChannels(String siteId) + public List getPublishingChannels() { - final NodeRef containerNode = getChannelContainer(siteId); + final NodeRef containerNode = getChannelContainer(); if(containerNode != null) { List types = CollectionUtils.filter(channelTypes.values(), new Filter() @@ -251,9 +227,9 @@ public class ChannelServiceImpl implements ChannelService /** * {@inheritDoc} */ - public List getStatusUpdateChannels(String siteId) + public List getStatusUpdateChannels() { - final NodeRef containerNode = getChannelContainer(siteId); + final NodeRef containerNode = getChannelContainer(); if (containerNode != null) { List types = channelHelper.getStatusUpdateChannelTypes(channelTypes.values()); @@ -270,7 +246,7 @@ public class ChannelServiceImpl implements ChannelService SiteInfo site = siteService.getSite(nodeToPublish); if(site!=null) { - return getStatusUpdateChannels(site.getShortName()); + return getStatusUpdateChannels(); } return Collections.emptyList(); } @@ -286,34 +262,9 @@ public class ChannelServiceImpl implements ChannelService }); } - private NodeRef getChannelContainer(final String siteId) + private NodeRef getChannelContainer() { - return siteService.getContainer(siteId, CHANNEL_CONTAINER_NAME); - } - - private Set getAllChannelContainers(String siteId) - { - Set containers = new HashSet(); - NodeRef environment = environmentHelper.getEnvironment(siteId); - containers.add(environment); - NodeRef editorialContainer = getChannelContainer(siteId); - if(editorialContainer!=null) - { - containers.add(editorialContainer); - } - return containers; - } - - private NodeRef createChannelContainer(final String siteId) - { - return AuthenticationUtil.runAs(new RunAsWork() - { - public NodeRef doWork() throws Exception - { - return siteService.createContainer(siteId, CHANNEL_CONTAINER_NAME, - PublishingModel.TYPE_CHANNEL_CONTAINER, null); - } - }, AuthenticationUtil.getSystemUserName()); + return rootObject.getChannelContainer(); } /** @@ -343,18 +294,15 @@ public class ChannelServiceImpl implements ChannelService /** * {@inheritDoc} */ - public void renameChannel(String siteId, String oldName, String newName) + public void renameChannel(String oldName, String newName) { - Set containers = getAllChannelContainers(siteId); - for (NodeRef channelContainer : containers) + NodeRef channelContainer = getChannelContainer(); + NodeRef channel = nodeService.getChildByName(channelContainer, ContentModel.ASSOC_CONTAINS, oldName); + if (channel != null) { - NodeRef channel = nodeService.getChildByName(channelContainer, ContentModel.ASSOC_CONTAINS, oldName); - if (channel != null) - { - nodeService.setProperty(channel, ContentModel.PROP_NAME, newName); - nodeService.moveNode(channel, channelContainer, ContentModel.ASSOC_CONTAINS, QName.createQName( - NamespaceService.APP_MODEL_1_0_URI, newName)); - } + nodeService.setProperty(channel, ContentModel.PROP_NAME, newName); + nodeService.moveNode(channel, channelContainer, ContentModel.ASSOC_CONTAINS, + QName.createQName(NamespaceService.APP_MODEL_1_0_URI, newName)); } } @@ -378,7 +326,7 @@ public class ChannelServiceImpl implements ChannelService * {@inheritDoc} */ @Override - public Channel getChannel(String id) + public Channel getChannelById(String id) { if(id!=null&& id.isEmpty()==false && NodeRef.isNodeRef(id)) diff --git a/source/java/org/alfresco/repo/publishing/ChannelServiceImplIntegratedTest.java b/source/java/org/alfresco/repo/publishing/ChannelServiceImplIntegratedTest.java index 24de16845a..3eb8dbfa07 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelServiceImplIntegratedTest.java +++ b/source/java/org/alfresco/repo/publishing/ChannelServiceImplIntegratedTest.java @@ -31,7 +31,6 @@ import java.util.Set; import javax.annotation.Resource; import org.alfresco.model.ContentModel; -import org.alfresco.repo.site.SiteServiceException; import org.alfresco.service.cmr.publishing.channels.Channel; import org.alfresco.service.cmr.publishing.channels.ChannelType; import org.alfresco.service.namespace.QName; @@ -74,9 +73,6 @@ public class ChannelServiceImplIntegratedTest extends AbstractPublishingIntegrat @Test public void testCreateChannel() throws Exception { - List channels = channelService.getChannels(siteId); - assertTrue(channels.isEmpty()); - Channel channel = createChannel(); assertEquals(channelTypeName, channel.getChannelType().getId()); assertEquals(channelName, channel.getName()); @@ -89,44 +85,36 @@ public class ChannelServiceImplIntegratedTest extends AbstractPublishingIntegrat Channel channel = createChannel(); channelService.deleteChannel(channel); - List channels = channelService.getChannels(siteId); - assertTrue(channels.isEmpty()); + assertNull("The channel should have been deleed! Id: "+channel.getId(), channelService.getChannelById(channel.getId())); + assertNull("The channel should have been deleed! Name: "+channelName, channelService.getChannelByName(channelName)); } @Test public void testRenameChannel() throws Exception { String newChannelName = "New Channel Name"; - testCreateChannel(); - List channels = channelService.getChannels(siteId); - assertEquals(1, channels.size()); - channelService.renameChannel(siteId, channelName, newChannelName); + Channel channel = createChannel(); + channelService.renameChannel(channelName, newChannelName); - channels = channelService.getChannels(siteId); - assertEquals(1, channels.size()); - Channel channel = channels.get(0); - assertEquals(newChannelName, channel.getName()); + Channel renamedChannel = channelService.getChannelById(channel.getId()); + assertNotNull(renamedChannel); + assertEquals(newChannelName, renamedChannel.getName()); } @Test public void testUpdateChannel() throws Exception { String newTitle = "This is my title"; - testCreateChannel(); - List channels = channelService.getChannels(siteId); - assertEquals(1, channels.size()); - - Channel channel = channels.get(0); + Channel channel = createChannel(); + Map props = channel.getProperties(); assertNull(props.get(ContentModel.PROP_TITLE)); props.put(ContentModel.PROP_TITLE, newTitle); channelService.updateChannel(channel, props); - channels = channelService.getChannels(siteId); - assertEquals(1, channels.size()); - channel = channels.get(0); - Serializable title = channel.getProperties().get(ContentModel.PROP_TITLE); + Channel updatedChannel = channelService.getChannelById(channel.getId()); + Serializable title = updatedChannel.getProperties().get(ContentModel.PROP_TITLE); assertNotNull(title); assertEquals(newTitle, title); } @@ -134,23 +122,22 @@ public class ChannelServiceImplIntegratedTest extends AbstractPublishingIntegrat @Test public void testGetChannels() throws Exception { - List channels = channelService.getChannels(siteId); - assertTrue(channels.isEmpty()); - + int startingSize = channelService.getChannels().size(); + int channelCount = 7; Set channelNames = new HashSet(); for (int i = 0; i < channelCount; ++i) { String name = GUID.generate(); channelNames.add(name); - channelService.createChannel(siteId, channelTypeName, name, null); + channelService.createChannel(channelTypeName, name, null); - channels = channelService.getChannels(siteId); - assertEquals(i + 1, channels.size()); + List channels = channelService.getChannels(); + assertEquals(i + 1 + startingSize, channels.size()); Set names = new HashSet(channelNames); for (Channel channel : channels) { - assertTrue(names.remove(channel.getName())); + names.remove(channel.getName()); } assertTrue(names.isEmpty()); } @@ -161,36 +148,18 @@ public class ChannelServiceImplIntegratedTest extends AbstractPublishingIntegrat { try { - channelService.getChannel(null, channelName); - fail("Should throw an Exception if siteId is null!"); - } - catch (IllegalArgumentException e) { - // NOOP - } - try - { - channelService.getChannel(siteId, null); + channelService.getChannelByName(null); fail("Should throw an Exception if channelName is null!"); } catch (IllegalArgumentException e) { // NOOP } - Channel channel = channelService.getChannel(siteId, channelName); + Channel channel = channelService.getChannelByName(channelName); assertNull("Should return null if unknown channelName", channel); Channel createdChannel = createChannel(); - try - { - channel = channelService.getChannel("No Site", channelName); - fail("Should throw exception if site does not exist!"); - } - catch (SiteServiceException e) - { - // NOOP - } - - channel = channelService.getChannel(siteId, channelName); + channel = channelService.getChannelByName(channelName); assertNotNull("Should return created channel!", channel); assertEquals(channelName, channel.getName()); assertEquals(createdChannel.getChannelType().getId(), channel.getChannelType().getId()); @@ -202,6 +171,6 @@ public class ChannelServiceImplIntegratedTest extends AbstractPublishingIntegrat */ private Channel createChannel() { - return channelService.createChannel(siteId, channelTypeName, channelName, null); + return channelService.createChannel(channelTypeName, channelName, null); } } diff --git a/source/java/org/alfresco/repo/publishing/Environment.java b/source/java/org/alfresco/repo/publishing/Environment.java new file mode 100644 index 0000000000..178d028bac --- /dev/null +++ b/source/java/org/alfresco/repo/publishing/Environment.java @@ -0,0 +1,63 @@ +/* + * 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 org.alfresco.service.cmr.repository.NodeRef; + +/** + * @author Brian + * @author Nick Smith + * + */ +public class Environment +{ + private final NodeRef nodeRef; + private final PublishingQueueImpl queue; + private final NodeRef channelsContainer; + + public Environment(NodeRef nodeRef, PublishingQueueImpl queue, NodeRef channelsContainer) + { + this.nodeRef = nodeRef; + this.queue = queue; + this.channelsContainer = channelsContainer; + } + + /** + * {@inheritDoc} + */ + public PublishingQueueImpl getPublishingQueue() + { + return queue; + } + + /** + * @return the channelsContainer + */ + public NodeRef getChannelsContainer() + { + return channelsContainer; + } + + public NodeRef getNodeRef() + { + return nodeRef; + } + +} diff --git a/source/java/org/alfresco/repo/publishing/EnvironmentFactory.java b/source/java/org/alfresco/repo/publishing/EnvironmentFactory.java deleted file mode 100644 index 76f4f3e666..0000000000 --- a/source/java/org/alfresco/repo/publishing/EnvironmentFactory.java +++ /dev/null @@ -1,30 +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; - - -/** - * @author Brian - * - */ -public interface EnvironmentFactory -{ - EnvironmentImpl createEnvironmentObject(String siteId); -} diff --git a/source/java/org/alfresco/repo/publishing/EnvironmentHelper.java b/source/java/org/alfresco/repo/publishing/EnvironmentHelper.java index 7d13dc5730..fff0d01a37 100644 --- a/source/java/org/alfresco/repo/publishing/EnvironmentHelper.java +++ b/source/java/org/alfresco/repo/publishing/EnvironmentHelper.java @@ -19,33 +19,7 @@ package org.alfresco.repo.publishing; -import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_STATUS; - -import java.io.Serializable; -import java.util.Calendar; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -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.publishing.NodePublishStatus; -import org.alfresco.service.cmr.publishing.NodePublishStatusNotPublished; -import org.alfresco.service.cmr.publishing.NodePublishStatusOnQueue; -import org.alfresco.service.cmr.publishing.NodePublishStatusPublished; -import org.alfresco.service.cmr.publishing.NodePublishStatusPublishedAndOnQueue; -import org.alfresco.service.cmr.publishing.PublishingEvent; -import org.alfresco.service.cmr.publishing.PublishingEvent.Status; -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.site.SiteService; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.ParameterCheck; /** * A utility class to help out with environment-related operations that are used @@ -57,210 +31,77 @@ import org.alfresco.util.ParameterCheck; */ public class EnvironmentHelper { - /** - * The name of the live environment. This environment is always available. - */ - private static final String LIVE_ENVIRONMENT_NAME = "live"; - - private static final String ENVIRONMENT_CONTAINER_NAME = "environments"; - private static final Set PUBLISHING_QUEUE_TYPE = new HashSet(); - private Set environmentNodeTypes; + private PublishingRootObject rootObject; - private SiteService siteService; - private NodeService nodeService; - private PublishingEventHelper publishingEventHelper; - - static + public NodeRef getChannelContainer() { - PUBLISHING_QUEUE_TYPE.add(PublishingModel.TYPE_PUBLISHING_QUEUE); - } - - public EnvironmentHelper() - { - environmentNodeTypes = new HashSet(); - environmentNodeTypes.add(PublishingModel.TYPE_ENVIRONMENT); - } - - /** - * @param environmentNodeTypes - * the environmentNodeTypes to set - */ - public void setEnvironmentNodeTypes(Set environmentNodeTypes) - { - this.environmentNodeTypes = environmentNodeTypes; - } - - /** - * @param siteService - * the siteService to set - */ - public void setSiteService(SiteService siteService) - { - this.siteService = siteService; - } - - /** - * @param nodeService - * the nodeService to set - */ - public void setNodeService(NodeService nodeService) - { - this.nodeService = nodeService; - } - - /** - * @param publishingEventHelper the publishingEventHelper to set - */ - public void setPublishingEventHelper(PublishingEventHelper publishingEventHelper) - { - this.publishingEventHelper = publishingEventHelper; + return rootObject.getChannelContainer(); } - /** - * @param channelHelper the channelHelper to set - */ - public void setChannelHelper(ChannelHelper channelHelper) + public PublishingQueueImpl getPublishingQueue() { - //NOOP + return rootObject.getPublishingQueue(); } - public NodeRef getEnvironment(String siteId) - { - ParameterCheck.mandatory("siteId", siteId); - NodeRef environmentContainer = getEnvironmentContainer(siteId); - return nodeService.getChildByName(environmentContainer, ContentModel.ASSOC_CONTAINS, LIVE_ENVIRONMENT_NAME); - } - - public NodeRef getPublishingQueue(NodeRef environment) - { - ParameterCheck.mandatory("environment", environment); - - ChildAssociationRef queueAssoc = null; - List childAssocs = nodeService.getChildAssocs(environment, PUBLISHING_QUEUE_TYPE); - for (ChildAssociationRef childAssoc : childAssocs) - { - if (childAssoc.getTypeQName().equals(PublishingModel.ASSOC_PUBLISHING_QUEUE)) - { - queueAssoc = childAssoc; - break; - } - } - - if (queueAssoc == null) - { - // No publishing queue - queueAssoc = nodeService.createNode(environment, - PublishingModel.ASSOC_PUBLISHING_QUEUE, - QName.createQName(PublishingModel.NAMESPACE, "publishingQueue"), - PublishingModel.TYPE_PUBLISHING_QUEUE); - } - return queueAssoc.getChildRef(); - } - - /** - * @return - */ - protected Set getEnvironmentNodeTypes() - { - return environmentNodeTypes; - } - - /** - * @param siteId - * @return - */ - private NodeRef getEnvironmentContainer(final String siteId) - { - return AuthenticationUtil.runAs(new RunAsWork() - { - public NodeRef doWork() throws Exception - { - NodeRef environmentContainer = siteService.getContainer(siteId, ENVIRONMENT_CONTAINER_NAME); - if (environmentContainer == null) - { - // No environment container exists for this site yet. Create - // it. - environmentContainer = siteService.createContainer(siteId, ENVIRONMENT_CONTAINER_NAME, - PublishingModel.TYPE_CHANNEL_CONTAINER, null); - - // Also create the default live environment - Map props = new HashMap(); - props.put(ContentModel.PROP_NAME, LIVE_ENVIRONMENT_NAME); - nodeService.createNode(environmentContainer, ContentModel.ASSOC_CONTAINS, QName.createQName( - NamespaceService.CONTENT_MODEL_1_0_URI, LIVE_ENVIRONMENT_NAME), - PublishingModel.TYPE_ENVIRONMENT, props); - } - return environmentContainer; - } - }, AuthenticationUtil.getSystemUserName()); - - } - - public NodePublishStatus checkNodeStatus(NodeRef node, EnvironmentImpl environment, String channelName) - { - PublishingEvent queuedEvent = getQueuedPublishingEvent(node, environment, channelName); - PublishingEvent lastEvent= getLastPublishingEvent(node, environment, channelName); - if(queuedEvent != null) - { - if(lastEvent != null) - { - return new NodePublishStatusPublishedAndOnQueue(node, channelName, queuedEvent, lastEvent); - } - else - { - return new NodePublishStatusOnQueue(node, channelName, queuedEvent); - } - } - else - { - if(lastEvent != null) - { - return new NodePublishStatusPublished(node, channelName, lastEvent); - } - else - { - return new NodePublishStatusNotPublished(node, channelName); - } - } - } - - private PublishingEvent getQueuedPublishingEvent(NodeRef node, EnvironmentImpl environment, String channelName) - { - NodeRef queue = getPublishingQueue(environment.getNodeRef()); - Calendar nextPublishTime = null; - NodeRef nextEventNode = null; - List eventNodes = publishingEventHelper.getEventNodesForPublishedNodes(queue, node); - for (NodeRef eventNode: eventNodes) - { - if (isActiveEvent(eventNode)) - { - Map props = nodeService.getProperties(eventNode); - Serializable eventChannel = props.get(PublishingModel.PROP_PUBLISHING_EVENT_CHANNEL); - if(channelName.equals(eventChannel)) - { - Calendar schedule = publishingEventHelper.getScheduledTime(props); - if (nextPublishTime == null || schedule.before(nextPublishTime)) - { - nextPublishTime = schedule; - nextEventNode = eventNode; - } - } - } - } - return publishingEventHelper.getPublishingEvent(nextEventNode); - } - - private boolean isActiveEvent(NodeRef eventNode) - { - String statusStr = (String) nodeService.getProperty( eventNode, PROP_PUBLISHING_EVENT_STATUS); - Status status = Status.valueOf(statusStr); - return status == Status.IN_PROGRESS || status == Status.SCHEDULED; - } - - private PublishingEvent getLastPublishingEvent(NodeRef node, EnvironmentImpl environment, String channelName) - { - //TODO Find the publish event. - return null; - } +// public NodePublishStatus checkNodeStatus(NodeRef node, String channelId) +// { +// PublishingEvent queuedEvent = getQueuedPublishingEvent(node, channelId); +// PublishingEvent lastEvent= getLastPublishingEvent(node, environment, channelName); +// if(queuedEvent != null) +// { +// if(lastEvent != null) +// { +// return new NodePublishStatusPublishedAndOnQueue(node, channelName, queuedEvent, lastEvent); +// } +// else +// { +// return new NodePublishStatusOnQueue(node, channelName, queuedEvent); +// } +// } +// else +// { +// if(lastEvent != null) +// { +// return new NodePublishStatusPublished(node, channelName, lastEvent); +// } +// else +// { +// return new NodePublishStatusNotPublished(node, channelName); +// } +// } +// } +// +// private PublishingEvent getQueuedPublishingEvent(NodeRef node, String channelId) +// { +// NodeRef queue = getPublishingQueue().getNodeRef(); +// Calendar nextPublishTime = null; +// NodeRef nextEventNode = null; +// List eventNodes = publishingEventHelper.getEventNodesForPublishedNodes(queue, node); +// for (NodeRef eventNode: eventNodes) +// { +// if (isActiveEvent(eventNode)) +// { +// Map props = nodeService.getProperties(eventNode); +// Serializable eventChannel = props.get(PublishingModel.PROP_PUBLISHING_EVENT_CHANNEL); +// if(channelId.equals(eventChannel)) +// { +// Calendar schedule = publishingEventHelper.getScheduledTime(props); +// if (nextPublishTime == null || schedule.before(nextPublishTime)) +// { +// nextPublishTime = schedule; +// nextEventNode = eventNode; +// } +// } +// } +// } +// return publishingEventHelper.getPublishingEvent(nextEventNode); +// } +// +// private boolean isActiveEvent(NodeRef eventNode) +// { +// String statusStr = (String) nodeService.getProperty( eventNode, PROP_PUBLISHING_EVENT_STATUS); +// Status status = Status.valueOf(statusStr); +// return status == Status.IN_PROGRESS || status == Status.SCHEDULED; +// } } diff --git a/source/java/org/alfresco/repo/publishing/EnvironmentHelperTest.java b/source/java/org/alfresco/repo/publishing/EnvironmentHelperTest.java deleted file mode 100644 index a7ddb0ccbf..0000000000 --- a/source/java/org/alfresco/repo/publishing/EnvironmentHelperTest.java +++ /dev/null @@ -1,64 +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 javax.annotation.Resource; - -import org.alfresco.service.cmr.repository.NodeRef; -import org.junit.Test; - -/** - * @author Brian - * - */ -public class EnvironmentHelperTest extends AbstractPublishingIntegrationTest -{ - @Resource(name="environmentHelper") - private EnvironmentHelper environmentHelper; - - @Override - public void onSetUp() throws Exception - { - super.onSetUp(); - environmentHelper = (EnvironmentHelper) getApplicationContext().getBean("environmentHelper"); - } - - @Test - public void testGetEnvironmentByName() throws Exception - { - NodeRef liveEnvironment = environmentHelper.getEnvironment(siteId); - assertNotNull(liveEnvironment); - assertTrue(nodeService.exists(liveEnvironment)); - assertEquals(PublishingModel.TYPE_ENVIRONMENT, nodeService.getType(liveEnvironment)); - } - - @Test - public void testGetPublishingQueue() throws Exception - { - NodeRef liveEnvironment = environmentHelper.getEnvironment(siteId); - NodeRef publishingQueue = environmentHelper.getPublishingQueue(liveEnvironment); - assertNotNull(publishingQueue); - assertTrue(nodeService.exists(publishingQueue)); - assertEquals(PublishingModel.TYPE_PUBLISHING_QUEUE, nodeService.getType(publishingQueue)); - assertEquals(PublishingModel.ASSOC_PUBLISHING_QUEUE, nodeService.getPrimaryParent(publishingQueue) - .getTypeQName()); - } - -} diff --git a/source/java/org/alfresco/repo/publishing/EnvironmentImpl.java b/source/java/org/alfresco/repo/publishing/EnvironmentImpl.java deleted file mode 100644 index 0d7912a644..0000000000 --- a/source/java/org/alfresco/repo/publishing/EnvironmentImpl.java +++ /dev/null @@ -1,114 +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.Map; - -import org.alfresco.service.cmr.publishing.NodePublishStatus; -import org.alfresco.service.cmr.publishing.PublishingQueue; -import org.alfresco.service.cmr.repository.NodeRef; - -/** - * @author Brian - * @author Nick Smith - * - */ -public class EnvironmentImpl -{ - private PublishingQueueFactory publishingQueueFactory; - private NodeRef nodeRef; - private String id; - private EnvironmentHelper environmentHelper; - - /** - * {@inheritDoc} - */ - public Map checkPublishStatus(String channelName, Collection nodes) - { - - Map results = new HashMap(); - for (NodeRef node : nodes) - { - if(node!=null && results.containsKey(node)==false) - { - results.put(node, environmentHelper.checkNodeStatus(node, this, channelName)); - } - } - return results; - } - - /** - * {@inheritDoc} - */ - public Map checkPublishStatus(String channelName, NodeRef... nodes) - { - return checkPublishStatus(channelName, Arrays.asList(nodes)); - } - - /** - * {@inheritDoc} - */ - public String getId() - { - return id; - } - - /** - * {@inheritDoc} - */ - public PublishingQueue getPublishingQueue() - { - return publishingQueueFactory.createPublishingQueueObject(nodeRef); - } - - public NodeRef getNodeRef() - { - return nodeRef; - } - - /** - * @param node - */ - public void setNodeRef(NodeRef node) - { - this.nodeRef = node; - this.id = node.toString(); - } - - /** - * @param publishingObjectFactory - */ - public void setPublishingQueueFactory(PublishingQueueFactory publishingQueueFactory) - { - this.publishingQueueFactory = publishingQueueFactory; - } - - /** - * @param environmentHelper - */ - public void setEnvironmentHelper(EnvironmentHelper environmentHelper) - { - this.environmentHelper = environmentHelper; - } - -} diff --git a/source/java/org/alfresco/repo/publishing/EnvironmentImplTest.java b/source/java/org/alfresco/repo/publishing/EnvironmentImplTest.java index d080bc6930..5353c2a383 100644 --- a/source/java/org/alfresco/repo/publishing/EnvironmentImplTest.java +++ b/source/java/org/alfresco/repo/publishing/EnvironmentImplTest.java @@ -19,86 +19,71 @@ package org.alfresco.repo.publishing; -import java.util.Calendar; -import java.util.Map; - -import javax.annotation.Resource; - -import org.alfresco.model.ContentModel; -import org.alfresco.service.cmr.publishing.MutablePublishingPackage; -import org.alfresco.service.cmr.publishing.NodePublishStatus; -import org.alfresco.service.cmr.publishing.NodePublishStatus.Status; -import org.alfresco.service.cmr.publishing.channels.Channel; -import org.alfresco.service.cmr.publishing.channels.ChannelService; -import org.alfresco.service.cmr.publishing.channels.ChannelType; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.util.GUID; -import org.junit.Test; /** * @author Nick Smith * @since 4.0 * */ -public class EnvironmentImplTest extends AbstractPublishingIntegrationTest +public class EnvironmentImplTest //extends AbstractPublishingIntegrationTest { - private Channel channel1; - private Channel channel2; - - @Resource(name="channelService") - private ChannelService channelService; - - @Test - public void testCheckPublishStatus() - { - NodeRef first = fileFolderService.create(docLib, "first", ContentModel.TYPE_CONTENT).getNodeRef(); - NodeRef second = fileFolderService.create(docLib, "second", ContentModel.TYPE_CONTENT).getNodeRef(); - - Map results = environment.checkPublishStatus(channel1.getId(), first); - assertEquals(1, results.size()); - checkNodeStatus(first, Status.NOT_PUBLISHED, results); - - // Schedule first Node for publishing. - Calendar schedule = Calendar.getInstance(); - schedule.add(Calendar.YEAR, 1); - MutablePublishingPackage pckg =queue.createPublishingPackage(); - pckg.addNodesToPublish(first); - queue.scheduleNewEvent(pckg, channel1.getId(), schedule, null, null); - - results = environment.checkPublishStatus(channel1.getId(), first, second); - assertEquals(2, results.size()); - checkNodeStatus(first, Status.ON_QUEUE, results); - checkNodeStatus(second, Status.NOT_PUBLISHED, results); - - results = environment.checkPublishStatus(channel2.getId(), first, second); - assertEquals(2, results.size()); - checkNodeStatus(first, Status.NOT_PUBLISHED, results); - checkNodeStatus(second, Status.NOT_PUBLISHED, results); - } - - private void checkNodeStatus(NodeRef node, Status expStatus, Map results) - { - NodePublishStatus nodeStatus = results.get(node); - assertEquals(node, nodeStatus.getNodeRef()); - assertEquals(expStatus, nodeStatus.getStatus()); - } - - /** - * {@inheritDoc} - */ - @Override - public void onSetUp() throws Exception - { - super.onSetUp(); - channelService = (ChannelServiceImpl) getApplicationContext().getBean("channelService"); - - ChannelType channelType = mockChannelType(); - if (channelService.getChannelType(channelType.getId()) == null) - { - channelService.register(channelType); - } - this.channel1 = channelService.createChannel(siteId, channelTypeId, GUID.generate(), null); - this.channel2 = channelService.createChannel(siteId, channelTypeId, GUID.generate(), null); - } +// private Channel channel1; +// private Channel channel2; +// +// @Resource(name="channelService") +// private ChannelService channelService; +// +// @Test +// public void testCheckPublishStatus() +// { +// NodeRef first = fileFolderService.create(docLib, "first", ContentModel.TYPE_CONTENT).getNodeRef(); +// NodeRef second = fileFolderService.create(docLib, "second", ContentModel.TYPE_CONTENT).getNodeRef(); +// +// Map results = environment.checkPublishStatus(channel1.getId(), first); +// assertEquals(1, results.size()); +// checkNodeStatus(first, Status.NOT_PUBLISHED, results); +// +// // Schedule first Node for publishing. +// Calendar schedule = Calendar.getInstance(); +// schedule.add(Calendar.YEAR, 1); +// MutablePublishingPackage pckg =queue.createPublishingPackage(); +// pckg.addNodesToPublish(first); +// queue.scheduleNewEvent(pckg, channel1.getId(), schedule, null, null); +// +// results = environment.checkPublishStatus(channel1.getId(), first, second); +// assertEquals(2, results.size()); +// checkNodeStatus(first, Status.ON_QUEUE, results); +// checkNodeStatus(second, Status.NOT_PUBLISHED, results); +// +// results = environment.checkPublishStatus(channel2.getId(), first, second); +// assertEquals(2, results.size()); +// checkNodeStatus(first, Status.NOT_PUBLISHED, results); +// checkNodeStatus(second, Status.NOT_PUBLISHED, results); +// } +// +// private void checkNodeStatus(NodeRef node, Status expStatus, Map results) +// { +// NodePublishStatus nodeStatus = results.get(node); +// assertEquals(node, nodeStatus.getNodeRef()); +// assertEquals(expStatus, nodeStatus.getStatus()); +// } +// +// /** +// * {@inheritDoc} +// */ +// @Override +// public void onSetUp() throws Exception +// { +// super.onSetUp(); +// channelService = (ChannelServiceImpl) getApplicationContext().getBean("channelService"); +// +// ChannelType channelType = mockChannelType(); +// if (channelService.getChannelType(channelType.getId()) == null) +// { +// channelService.register(channelType); +// } +// this.channel1 = channelService.createChannel(channelTypeId, GUID.generate(), null); +// this.channel2 = channelService.createChannel(channelTypeId, GUID.generate(), null); +// } } diff --git a/source/java/org/alfresco/repo/publishing/PublishEventActionTest.java b/source/java/org/alfresco/repo/publishing/PublishEventActionTest.java index 93d7622737..16669acb13 100644 --- a/source/java/org/alfresco/repo/publishing/PublishEventActionTest.java +++ b/source/java/org/alfresco/repo/publishing/PublishEventActionTest.java @@ -425,12 +425,12 @@ public class PublishEventActionTest extends AbstractPublishingIntegrationTest Mockito.reset(channelType); mockChannelTypeBehaviour(channelType); } - this.channel = channelService.createChannel(siteId, channelTypeId, GUID.generate(), null); + this.channel = channelService.createChannel(channelTypeId, GUID.generate(), null); this.channelNode = channel.getNodeRef(); } @Override - public void onTearDown() + public void onTearDown() throws Exception { if(eventId !=null) { diff --git a/source/java/org/alfresco/repo/publishing/PublishServiceImpl.java b/source/java/org/alfresco/repo/publishing/PublishServiceImpl.java index 2446c3d919..f414a1a663 100644 --- a/source/java/org/alfresco/repo/publishing/PublishServiceImpl.java +++ b/source/java/org/alfresco/repo/publishing/PublishServiceImpl.java @@ -20,9 +20,7 @@ package org.alfresco.repo.publishing; import java.util.Collection; -import java.util.Collections; import java.util.Map; -import java.util.Set; import org.alfresco.service.cmr.publishing.NodePublishStatus; import org.alfresco.service.cmr.publishing.PublishingEvent; @@ -40,17 +38,17 @@ public class PublishServiceImpl implements PublishingService { public static final String NAME = "publishingService"; - private EnvironmentFactory environmentFactory; private PublishingEventHelper publishingEventHelper; + private PublishingRootObject rootObject; /** - * @param environmentFactory the environmentFactory to set + * @param rootObject the rootObject to set */ - public void setEnvironmentFactory(EnvironmentFactory environmentFactory) + public void setPublishingRootObject(PublishingRootObject rootObject) { - this.environmentFactory = environmentFactory; + this.rootObject = rootObject; } - + /** * @param publishingEventHelper the publishingEventHelper to set */ @@ -59,16 +57,6 @@ public class PublishServiceImpl implements PublishingService this.publishingEventHelper = publishingEventHelper; } - /** - * - * {@inheritDoc} - */ - public Set getPublishingDependencies(NodeRef node) - { - // TODO Auto-generated method stub - return null; - } - /** * {@inheritDoc} */ @@ -91,44 +79,35 @@ public class PublishServiceImpl implements PublishingService */ public PublishingQueue getPublishingQueue(String siteId) { - EnvironmentImpl environment = getEnvironment(siteId); - if(environment!=null) - { - return environment.getPublishingQueue(); - } + return rootObject.getPublishingQueue(); + } + + /** + * {@inheritDoc} + */ + public Map checkPublishStatus(String channelId, Collection nodes) + { +// Map results = new HashMap(); +// for (NodeRef node : nodes) +// { +// if(node!=null && results.containsKey(node)==false) +// { +// results.put(node, environmentHelper.checkNodeStatus(node, channelId)); +// } +// } +// return results; + //TODO + return null; + } + + /** + * {@inheritDoc} + */ + public Map checkPublishStatus(String channelId, NodeRef... nodes) + { +// return checkPublishStatus(channelId, Arrays.asList(nodes)); + //TODO return null; } - /** - * {@inheritDoc} - */ - public Map checkPublishStatus(String siteId, String channelName, - Collection nodes) - { - EnvironmentImpl environment = getEnvironment(siteId); - if(environment !=null ) - { - return environment.checkPublishStatus(channelName, nodes); - } - return Collections.emptyMap(); - } - - /** - * {@inheritDoc} - */ - public Map checkPublishStatus(String siteId, String channelName, NodeRef... nodes) - { - EnvironmentImpl environment = getEnvironment(siteId); - if(environment !=null ) - { - return environment.checkPublishStatus(channelName, nodes); - } - return Collections.emptyMap(); - } - - private EnvironmentImpl getEnvironment(String siteId) - { - return environmentFactory.createEnvironmentObject(siteId); - } - } \ No newline at end of file diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java b/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java index fe2b04c1ac..a7d0b5cf6f 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java +++ b/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java @@ -76,7 +76,7 @@ public class PublishingEventProcessor PublishingEvent event = eventHelper.getPublishingEvent(eventNode); NodeRef environment = eventHelper.getEnvironmentNodeForPublishingEvent(eventNode); String channelName = event.getChannelId(); - Channel channel = channelService.getChannel(channelName); + Channel channel = channelService.getChannelById(channelName); if (channel == null) { fail(eventNode, "No channel found"); @@ -118,7 +118,7 @@ public class PublishingEventProcessor Set channels = update.getChannelIds(); for (String channelId : channels) { - Channel channel = channelService.getChannel(channelId); + Channel channel = channelService.getChannelById(channelId); if(channel != null && channel.getChannelType().canPublishStatusUpdates()) { channel.updateStatus(message); diff --git a/source/java/org/alfresco/repo/publishing/PublishingIntegratedTest.java b/source/java/org/alfresco/repo/publishing/PublishingIntegratedTest.java index f803e322f5..55276b57a1 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingIntegratedTest.java +++ b/source/java/org/alfresco/repo/publishing/PublishingIntegratedTest.java @@ -75,7 +75,7 @@ public class PublishingIntegratedTest extends BaseSpringTest @Test public void testScheduleNewEvent() throws Exception { - Channel channel = channelService.createChannel(siteId, channelTypeName, GUID.generate(), null); + Channel channel = channelService.createChannel(channelTypeName, GUID.generate(), null); Set nodes = new HashSet(); for (int i = 0; i < 4; ++i) @@ -109,7 +109,7 @@ public class PublishingIntegratedTest extends BaseSpringTest @Test public void testCancelScheduledEvent() { - Channel channel = channelService.createChannel(siteId, channelTypeName, GUID.generate(), null); + Channel channel = channelService.createChannel(channelTypeName, GUID.generate(), null); Set nodes = new HashSet(); for (int i = 0; i < 4; ++i) diff --git a/source/java/org/alfresco/repo/publishing/PublishingObjectFactory.java b/source/java/org/alfresco/repo/publishing/PublishingObjectFactory.java deleted file mode 100644 index f5688630c6..0000000000 --- a/source/java/org/alfresco/repo/publishing/PublishingObjectFactory.java +++ /dev/null @@ -1,117 +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 org.alfresco.repo.transfer.manifest.TransferManifestNodeFactory; -import org.alfresco.service.cmr.publishing.PublishingQueue; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.version.VersionService; - -/** - * @author Brian - * - */ -public class PublishingObjectFactory implements EnvironmentFactory, PublishingQueueFactory -{ - public static final String NAME = "publishingObjectFactory"; - - private EnvironmentHelper environmentHelper; - private TransferManifestNodeFactory transferManifestNodeFactory; - private PublishingEventHelper publishingEventHelper; - private VersionService versionService; - - /** - * @param environmentHelper the environmentHelper to set - */ - public void setEnvironmentHelper(EnvironmentHelper environmentHelper) - { - this.environmentHelper = environmentHelper; - } - - /** - * @param transferManifestNodeFactory the transferManifestNodeFactory to set - */ - public void setTransferManifestNodeFactory(TransferManifestNodeFactory transferManifestNodeFactory) - { - this.transferManifestNodeFactory = transferManifestNodeFactory; - } - - /** - * @param publishingEventHelper the publishingEventHelper to set - */ - public void setPublishingEventHelper(PublishingEventHelper publishingEventHelper) - { - this.publishingEventHelper = publishingEventHelper; - } - - /** - * @param versionService the versionService to set - */ - public void setVersionService(VersionService versionService) - { - this.versionService = versionService; - } - - /* (non-Javadoc) - * @see org.alfresco.repo.publishing.EnvironmentFactory#createEnvironmentObject(java.lang.String, java.lang.String) - */ - public EnvironmentImpl createEnvironmentObject(String siteId) - { - NodeRef node = environmentHelper.getEnvironment(siteId); - return createEnvironmentFromNode(node); - } - - /** - * @param node - * @return - */ - private EnvironmentImpl createEnvironmentFromNode(NodeRef node) - { - EnvironmentImpl environment = new EnvironmentImpl(); - environment.setNodeRef(node); - environment.setPublishingQueueFactory(this); - environment.setEnvironmentHelper(environmentHelper); - return environment; - } - - /* (non-Javadoc) - * @see org.alfresco.repo.publishing.PublishingQueueFactory#createPublishingQueueObject(java.lang.String, java.lang.String) - */ - public PublishingQueue createPublishingQueueObject(String siteId) - { - NodeRef environmentNode = environmentHelper.getEnvironment(siteId); - return createPublishingQueueObject(environmentNode); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.publishing.PublishingQueueFactory#createPublishingQueueObject(org.alfresco.service.cmr.repository.NodeRef) - */ - public PublishingQueue createPublishingQueueObject(NodeRef environmentNodeRef) - { - NodeRef queueNode = environmentHelper.getPublishingQueue(environmentNodeRef); - PublishingQueueImpl publishingQueue = new PublishingQueueImpl(); - publishingQueue.setNodeRef(queueNode); - publishingQueue.setTransferManifestNodeFactory(transferManifestNodeFactory); - publishingQueue.setPublishingEventHelper(publishingEventHelper); - publishingQueue.setVersionService(versionService); - return publishingQueue; - } - -} diff --git a/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java b/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java index 0c0ae4b6ce..83d51d813b 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java +++ b/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java @@ -43,11 +43,20 @@ import org.alfresco.service.cmr.version.VersionService; public class PublishingQueueImpl implements PublishingQueue { private final static String MSG_FAILED_TO_CREATE_PUBLISHING_EVENT = "publishing-create-event-failed"; - private NodeRef nodeRef; - private TransferManifestNodeFactory transferManifestNodeFactory; - private VersionService versionService; - private PublishingEventHelper publishingEventHelper; + 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) + { + this.nodeRef = nodeRef; + this.publishingEventHelper = publishingEventHelper; + this.versionService = versionService; + this.transferManifestNodeFactory = transferManifestNodeFactory; + } + /** * {@inheritDoc} */ @@ -106,38 +115,11 @@ public class PublishingQueueImpl implements PublishingQueue } /** - * @param queueNode + * @return the nodeRef */ - public void setNodeRef(NodeRef queueNode) + public NodeRef getNodeRef() { - this.nodeRef = queueNode; + return nodeRef; } - /** - * @param transferManifestNodeFactory - * the transferManifestNodeFactory to set - */ - public void setTransferManifestNodeFactory(TransferManifestNodeFactory transferManifestNodeFactory) - { - this.transferManifestNodeFactory = transferManifestNodeFactory; - } - - /** - * @param publishingEventHelper - * the publishingEventHelper to set - */ - public void setPublishingEventHelper(PublishingEventHelper publishingEventHelper) - { - this.publishingEventHelper = publishingEventHelper; - } - - /** - * @param versionService the versionService to set - */ - public void setVersionService(VersionService versionService) - { - this.versionService = versionService; - } - - } diff --git a/source/java/org/alfresco/repo/publishing/PublishingQueueImplTest.java b/source/java/org/alfresco/repo/publishing/PublishingQueueImplTest.java index b82308c593..4e4368c59a 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingQueueImplTest.java +++ b/source/java/org/alfresco/repo/publishing/PublishingQueueImplTest.java @@ -180,9 +180,10 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest /** * {@inheritDoc} + * @throws Exception */ @Override - public void onTearDown() + public void onTearDown() throws Exception { if(eventId!=null) { diff --git a/source/java/org/alfresco/repo/publishing/PublishingRootObject.java b/source/java/org/alfresco/repo/publishing/PublishingRootObject.java new file mode 100644 index 0000000000..b5b7529d61 --- /dev/null +++ b/source/java/org/alfresco/repo/publishing/PublishingRootObject.java @@ -0,0 +1,254 @@ +/* + * 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 static org.alfresco.model.ContentModel.ASSOC_CONTAINS; +import static org.alfresco.model.ContentModel.TYPE_FOLDER; +import static org.alfresco.repo.publishing.PublishingModel.ASSOC_PUBLISHING_QUEUE; +import static org.alfresco.repo.publishing.PublishingModel.NAMESPACE; +import static org.alfresco.repo.publishing.PublishingModel.TYPE_PUBLISHING_QUEUE; + +import java.util.List; + +import org.alfresco.repo.node.NodeUtils; +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.version.VersionService; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.alfresco.service.namespace.RegexQNamePattern; +import org.springframework.beans.BeansException; + +/** + * Returns a properly configured Environment. The factory is multi-tenancy enabled, returning the correct Environment object for the current domain. + * @author Nick Smith + * @since 4.0 + * + */ +public class PublishingRootObject +{ + public static final String NAME = "publishingRootObject"; + protected static final QName CHANNELS_QNAME = QName.createQName(NAMESPACE, "channels"); + + private NodeService nodeService; + private PublishingEventHelper publishingEventHelper; + private NamespaceService namespaceService; + private SearchService searchService; + private VersionService versionService; + private TransferManifestNodeFactory transferManifestNodeFactory; + private RetryingTransactionHelper retryingTransactionHelper; +// private TenantAdminService tenantAdminService; + + private StoreRef publishingStore; + private String publishingRootPath; + +// private Map environments = new HashMap(); + + /** + * @return the approprieate {@link Environment} for the current domain. + * @throws BeansException + */ + public Environment getEnvironment() throws BeansException + { +// String tenantDomain = tenantAdminService.getCurrentUserDomain(); +// Environment environment = environments.get(tenantDomain); +// if(environment != null) +// { +// return environment; +// } +// environment = createEnvironment(); +// environments.put(tenantDomain, environment); +// return environment; + return createEnvironment(); + } + + public NodeRef getChannelContainer() + { + return getEnvironment().getChannelsContainer(); + } + + public PublishingQueueImpl getPublishingQueue() + { + return getEnvironment().getPublishingQueue(); + } + + private Environment createEnvironment() + { + return AuthenticationUtil.runAs(new RunAsWork() + { + public Environment doWork() throws Exception + { + NodeRef environmentNode = getEnvironmentNode(); + PublishingQueueImpl queue = createPublishingQueue(environmentNode); + NodeRef channelsContainer = getChannelsContainer(environmentNode); + return new Environment(environmentNode, queue, channelsContainer); + } + + }, AuthenticationUtil.getSystemUserName()); + } + + private NodeRef getChannelsContainer(NodeRef environmentNode) + { + List childAssocs = + nodeService.getChildAssocs(environmentNode,ASSOC_CONTAINS, CHANNELS_QNAME); + NodeRef channels = NodeUtils.getSingleChildAssocNode(childAssocs, true); + if (channels == null) + { + // No channels container. + channels = nodeService.createNode(environmentNode, + ASSOC_CONTAINS, + CHANNELS_QNAME, + TYPE_FOLDER).getChildRef(); + } + return channels; + } + + private PublishingQueueImpl createPublishingQueue(NodeRef environmentNode) + { + NodeRef queueNode = getPublishingQueueNode(environmentNode); + return new PublishingQueueImpl(queueNode, publishingEventHelper, versionService, transferManifestNodeFactory); + } + + private NodeRef getPublishingQueueNode(NodeRef environmentNode) + { + List childAssocs = nodeService.getChildAssocs(environmentNode, ASSOC_PUBLISHING_QUEUE, RegexQNamePattern.MATCH_ALL); + NodeRef queueNode = NodeUtils.getSingleChildAssocNode(childAssocs, true); + if (queueNode == null) + { + // No publishing queue + queueNode = nodeService.createNode(environmentNode, + ASSOC_PUBLISHING_QUEUE, + QName.createQName(NAMESPACE, "publishingQueue"), + TYPE_PUBLISHING_QUEUE).getChildRef(); + } + return queueNode; + } + + private NodeRef getEnvironmentNode() + { + return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() + { + public NodeRef execute() throws Exception + { + return findEnvrionmentNode(); + } + }, true); + } + + private NodeRef findEnvrionmentNode() + { + NodeRef rootNode = nodeService.getRootNode(publishingStore); + List refs = searchService.selectNodes(rootNode, publishingRootPath, null, namespaceService, false); + if (refs.size() != 1) + { + String msg = "Invalid publishing root path: " + publishingRootPath + " - found: " + refs.size(); + throw new IllegalStateException(msg); + } + return refs.get(0); + } + + /** + * @param publishingStore the publishingStore to set + */ + public void setPublishingStore(String publishingStore) + { + this.publishingStore = new StoreRef(publishingStore); + } + + /** + * @param publishingRootPath the publishingRootPath to set + */ + public void setPublishingRootPath(String publishingRootPath) + { + this.publishingRootPath = publishingRootPath; + } + + /** + * @param retryingTransactionHelper the retryingTransactionHelper to set + */ + public void setRetryingTransactionHelper(RetryingTransactionHelper retryingTransactionHelper) + { + this.retryingTransactionHelper = retryingTransactionHelper; + } + + /** + * @param namespaceService the namespaceService to set + */ + public void setNamespaceService(NamespaceService namespaceService) + { + this.namespaceService = namespaceService; + } + + /** + * @param nodeService the nodeService to set + */ + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + /** + * @param publishingEventHelper the publishingEventHelper to set + */ + public void setPublishingEventHelper(PublishingEventHelper publishingEventHelper) + { + this.publishingEventHelper = publishingEventHelper; + } + + /** + * @param searchService the searchService to set + */ + public void setSearchService(SearchService searchService) + { + this.searchService = searchService; + } + +// /** +// * @param tenantAdminService the tenantAdminService to set +// */ +// public void setTenantAdminService(TenantAdminService tenantAdminService) +// { +// this.tenantAdminService = tenantAdminService; +// } + + /** + * @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; + } +} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/publishing/PublishingRootObjectTest.java b/source/java/org/alfresco/repo/publishing/PublishingRootObjectTest.java new file mode 100644 index 0000000000..9a59a32a8d --- /dev/null +++ b/source/java/org/alfresco/repo/publishing/PublishingRootObjectTest.java @@ -0,0 +1,81 @@ +/* + * 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 javax.annotation.Resource; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.junit.Test; + +/** + * @author Brian + * + */ +public class PublishingRootObjectTest extends AbstractPublishingIntegrationTest +{ + @Resource(name="publishingRootObject") + private PublishingRootObject rootObject; + + @Override + public void onSetUp() throws Exception + { + super.onSetUp(); + this.rootObject = (PublishingRootObject) getApplicationContext().getBean(PublishingRootObject.NAME); + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); + } + + @Test + public void testGetEnvironment() throws Exception + { + Environment theEnvironment = rootObject.getEnvironment(); + assertNotNull(theEnvironment); + assertTrue(nodeService.exists(theEnvironment.getNodeRef())); + assertEquals(PublishingModel.TYPE_ENVIRONMENT, nodeService.getType(theEnvironment.getNodeRef())); + } + + @Test + public void testGetPublishingQueue() throws Exception + { + PublishingQueueImpl theQueue = rootObject.getPublishingQueue(); + assertNotNull(theQueue); + NodeRef queueNode = theQueue.getNodeRef(); + assertTrue(nodeService.exists(queueNode)); + assertEquals(PublishingModel.TYPE_PUBLISHING_QUEUE, nodeService.getType(queueNode)); + ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(queueNode); + assertEquals(PublishingModel.ASSOC_PUBLISHING_QUEUE, parentAssoc.getTypeQName()); + assertEquals(rootObject.getEnvironment().getNodeRef(), parentAssoc.getParentRef()); + } + + @Test + public void testGetChannelContainer() throws Exception + { + NodeRef channels = rootObject.getChannelContainer(); + assertNotNull(channels); + assertTrue(nodeService.exists(channels)); + assertEquals(ContentModel.TYPE_FOLDER, nodeService.getType(channels)); + ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(channels); + assertEquals(PublishingRootObject.CHANNELS_QNAME, parentAssoc.getQName()); + assertEquals(rootObject.getEnvironment().getNodeRef(), parentAssoc.getParentRef()); + } + +} diff --git a/source/java/org/alfresco/repo/publishing/WebPublishingTestSuite.java b/source/java/org/alfresco/repo/publishing/WebPublishingTestSuite.java index 3989919882..65a04ab109 100644 --- a/source/java/org/alfresco/repo/publishing/WebPublishingTestSuite.java +++ b/source/java/org/alfresco/repo/publishing/WebPublishingTestSuite.java @@ -31,8 +31,8 @@ import org.junit.runners.Suite; @Suite.SuiteClasses( { ChannelServiceImplTest.class, PublishingEventHelperTest.class, ChannelServiceImplIntegratedTest.class, - EnvironmentHelperTest.class, - EnvironmentImplTest.class, + PublishingRootObjectTest.class, +// EnvironmentImplTest.class, PublishingQueueImplTest.class, PublishingPackageSerializerTest.class, PublishingIntegratedTest.class, diff --git a/source/java/org/alfresco/repo/publishing/flickr/FlickrTest.java b/source/java/org/alfresco/repo/publishing/flickr/FlickrTest.java index 5d0d8a090d..76b1a4a267 100644 --- a/source/java/org/alfresco/repo/publishing/flickr/FlickrTest.java +++ b/source/java/org/alfresco/repo/publishing/flickr/FlickrTest.java @@ -25,7 +25,7 @@ import java.util.Map; import org.alfresco.model.ContentModel; import org.alfresco.repo.content.MimetypeMap; -import org.alfresco.repo.publishing.EnvironmentImpl; +import org.alfresco.repo.publishing.Environment; import org.alfresco.repo.publishing.PublishingModel; import org.alfresco.repo.publishing.PublishingQueueImpl; import org.alfresco.repo.security.authentication.AuthenticationUtil; @@ -63,7 +63,7 @@ public class FlickrTest extends BaseSpringTest protected NodeService nodeService; protected String siteId; protected PublishingQueueImpl queue; - protected EnvironmentImpl environment; + protected Environment environment; protected NodeRef docLib; private ChannelService channelService; @@ -109,7 +109,7 @@ public class FlickrTest extends BaseSpringTest props.put(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, "YOUR_OAUTH_TOKEN_SECRET"); props.put(PublishingModel.PROP_AUTHORISATION_COMPLETE, Boolean.TRUE); - Channel channel = channelService.createChannel(siteId, FlickrChannelType.ID, "FlickrTestChannel", props); + Channel channel = channelService.createChannel(FlickrChannelType.ID, "FlickrTestChannel", props); //This looks a little odd, but a new channel always has its "authorisation complete" flag //forced off initially. This will force it on for this channel... channelService.updateChannel(channel, props); @@ -153,5 +153,7 @@ public class FlickrTest extends BaseSpringTest return null; } }); + } + } diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareTest.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareTest.java index e878a2bccb..10ebdfbcbc 100644 --- a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareTest.java +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareTest.java @@ -25,7 +25,7 @@ import java.util.Map; import org.alfresco.model.ContentModel; import org.alfresco.repo.content.MimetypeMap; -import org.alfresco.repo.publishing.EnvironmentImpl; +import org.alfresco.repo.publishing.Environment; import org.alfresco.repo.publishing.PublishingModel; import org.alfresco.repo.publishing.PublishingQueueImpl; import org.alfresco.repo.security.authentication.AuthenticationUtil; @@ -63,7 +63,7 @@ public class SlideShareTest extends BaseSpringTest protected NodeService nodeService; protected String siteId; protected PublishingQueueImpl queue; - protected EnvironmentImpl environment; + protected Environment environment; protected NodeRef docLib; private ChannelService channelService; @@ -108,7 +108,7 @@ public class SlideShareTest extends BaseSpringTest Map props = new HashMap(); props.put(PublishingModel.PROP_CHANNEL_USERNAME, "YOUR_USER_NAME"); props.put(PublishingModel.PROP_CHANNEL_PASSWORD, "YOUR_PASSWORD"); - Channel channel = channelService.createChannel(siteId, SlideShareChannelType.ID, "SlideShareChannel", props); + Channel channel = channelService.createChannel(SlideShareChannelType.ID, "SlideShareChannel", props); NodeRef channelNode = channel.getNodeRef(); Resource file = new ClassPathResource("test/alfresco/TestPresentation.pptx"); diff --git a/source/java/org/alfresco/repo/publishing/test/SiteType.java b/source/java/org/alfresco/repo/publishing/test/SiteType.java index 9fac4809eb..4aa54ada58 100644 --- a/source/java/org/alfresco/repo/publishing/test/SiteType.java +++ b/source/java/org/alfresco/repo/publishing/test/SiteType.java @@ -82,9 +82,9 @@ public class SiteType log.debug("onCreateNode " + childAssocRef); } String siteId = childAssocRef.getQName().getLocalName(); - channelService.createChannel(siteId, "TestChannelType1", "Test Channel One", null); - channelService.createChannel(siteId, "TestChannelType2", "Test Channel Two", null); - channelService.createChannel(siteId, "TestChannelType3", "Test Channel Three", null); + channelService.createChannel("TestChannelType1", "Test Channel One", null); + channelService.createChannel("TestChannelType2", "Test Channel Two", null); + channelService.createChannel("TestChannelType3", "Test Channel Three", null); } } diff --git a/source/java/org/alfresco/repo/publishing/youtube/YouTubeTest.java b/source/java/org/alfresco/repo/publishing/youtube/YouTubeTest.java index 597e9c1f17..9de852dc51 100644 --- a/source/java/org/alfresco/repo/publishing/youtube/YouTubeTest.java +++ b/source/java/org/alfresco/repo/publishing/youtube/YouTubeTest.java @@ -24,7 +24,7 @@ import java.util.HashMap; import java.util.Map; import org.alfresco.model.ContentModel; -import org.alfresco.repo.publishing.EnvironmentImpl; +import org.alfresco.repo.publishing.Environment; import org.alfresco.repo.publishing.PublishingModel; import org.alfresco.repo.publishing.PublishingQueueImpl; import org.alfresco.repo.security.authentication.AuthenticationUtil; @@ -62,7 +62,7 @@ public class YouTubeTest extends BaseSpringTest protected NodeService nodeService; protected String siteId; protected PublishingQueueImpl queue; - protected EnvironmentImpl environment; + protected Environment environment; protected NodeRef docLib; private ChannelService channelService; @@ -107,7 +107,7 @@ public class YouTubeTest extends BaseSpringTest Map props = new HashMap(); props.put(PublishingModel.PROP_CHANNEL_USERNAME, "YOUR_USER_NAME"); props.put(PublishingModel.PROP_CHANNEL_PASSWORD, "YOUR_PASSWORD"); - Channel channel = channelService.createChannel(siteId, YouTubeChannelType.ID, "YouTubeChannel", props); + Channel channel = channelService.createChannel(YouTubeChannelType.ID, "YouTubeChannel", props); NodeRef channelNode = channel.getNodeRef(); Resource videoFile = new ClassPathResource("test/alfresco/TestVideoFile.MP4"); diff --git a/source/java/org/alfresco/service/cmr/publishing/PublishingService.java b/source/java/org/alfresco/service/cmr/publishing/PublishingService.java index 684c8e40bc..e867b58ea0 100644 --- a/source/java/org/alfresco/service/cmr/publishing/PublishingService.java +++ b/source/java/org/alfresco/service/cmr/publishing/PublishingService.java @@ -55,11 +55,11 @@ public interface PublishingService /** * Discover the publishing status of each of the specified nodes - * @param channelName TODO + * @param channelId TODO * @param nodes The identifiers of the nodes whose publishing status is being sought * @return A map associating a NodePublishStatus object with each of the supplied NodeRef objects */ - Map checkPublishStatus(String siteId, String channelName, Collection nodes); + Map checkPublishStatus(String channelId, Collection nodes); - Map checkPublishStatus(String siteId, String channelName, NodeRef... nodes); + Map checkPublishStatus(String channelId, NodeRef... nodes); } diff --git a/source/java/org/alfresco/service/cmr/publishing/channels/ChannelService.java b/source/java/org/alfresco/service/cmr/publishing/channels/ChannelService.java index ef7b72cc46..a46d074441 100644 --- a/source/java/org/alfresco/service/cmr/publishing/channels/ChannelService.java +++ b/source/java/org/alfresco/service/cmr/publishing/channels/ChannelService.java @@ -54,14 +54,13 @@ public interface ChannelService /** * Create a new channel of the specified channel type on the specified Share site with the specified name and properties. - * @param siteId The identifier of the Share site on which this channel is to be created. * @param channelTypeId The identifier of the channel type that is to be used for the new channel. This must identify a channel type that * has been registered with the channel service. * @param name The name of the new channel. This must be unique within the specified Share site. * @param properties Any additional properties that are to be saved as part of the new channel. * @return A Channel object corresponding to the newly created channel. */ - Channel createChannel(String siteId, String channelTypeId, String name, Map properties); + Channel createChannel(String channelTypeId, String name, Map properties); /** * Remove the specified channel. @@ -71,11 +70,10 @@ public interface ChannelService /** * Rename the specified channel - * @param siteId The identifier of the Share site that contains the channel to be renamed. * @param oldName The current name of the channel that is to be renamed. * @param newName The new name of the channel */ - void renameChannel(String siteId, String oldName, String newName); + void renameChannel(String oldName, String newName); /** * Update the properties of the specified channel. @@ -87,25 +85,23 @@ public interface ChannelService /** * Retrieve all the channels contained by the specified Share site. - * @param siteId The identifier of the Share site * @return A list of Channel objects, each one representing a channel that exists within the specified Share site. */ - List getChannels(String siteId); + List getChannels(); /** * Retrieve the channel with the given channel name contained by the specified Share site. - * @param siteId The identifier of the Share site * @param channelName The name of the channel * @return The specified Channel objects or null if the specified channel does not exist. */ - Channel getChannel(String siteId, String channelName); + Channel getChannelByName(String channelName); /** * Retrieve the channel with the given id. * @param id The string value of the channel {@link NodeRef}. * @return The specified Channel objects or null if the specified channel does not exist. */ - Channel getChannel(String id); + Channel getChannelById(String id); /** * Returns a list of all the channels that are capable of publishing the specified NodeRef. @@ -116,23 +112,14 @@ public interface ChannelService /** * Returns a list of all the channels that are capable of publishing in the specified Share site. - * @param siteId * @return */ - List getPublishingChannels(String siteId); + List getPublishingChannels(); /** * Returns all {@link Channel}s cpaable of performing a status update for the given Share Site. - * @param siteId * @return */ - List getStatusUpdateChannels(String siteId); - - /** - * Returns all {@link Channel}s capable of performing a status update for the Share Site in which the specified nodeToPublish exists. - * @param siteId - * @return - */ - List getStatusUpdateChannels(NodeRef nodeToPublish); + List getStatusUpdateChannels(); }