diff --git a/config/alfresco/model/publishingModel.xml b/config/alfresco/model/publishingModel.xml index 61630cfdbd..28e9e83aed 100644 --- a/config/alfresco/model/publishingModel.xml +++ b/config/alfresco/model/publishingModel.xml @@ -34,6 +34,17 @@ + + + false + false + + + pub:DeliveryChannel + false + false + + false diff --git a/config/alfresco/slideshare-publishing-context.xml b/config/alfresco/slideshare-publishing-context.xml index af80052544..7963c03c67 100644 --- a/config/alfresco/slideshare-publishing-context.xml +++ b/config/alfresco/slideshare-publishing-context.xml @@ -12,6 +12,12 @@ + + + + + + diff --git a/config/test/alfresco/TestPresentation.pptx b/config/test/alfresco/TestPresentation.pptx new file mode 100644 index 0000000000..6751ae084d Binary files /dev/null and b/config/test/alfresco/TestPresentation.pptx differ diff --git a/source/java/org/alfresco/repo/publishing/AbstractChannelType.java b/source/java/org/alfresco/repo/publishing/AbstractChannelType.java index 7cc8c97f1a..77fd534518 100644 --- a/source/java/org/alfresco/repo/publishing/AbstractChannelType.java +++ b/source/java/org/alfresco/repo/publishing/AbstractChannelType.java @@ -19,9 +19,11 @@ package org.alfresco.repo.publishing; +import java.io.Serializable; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.Map; import org.alfresco.repo.transfer.CompositeNodeFilter; @@ -31,10 +33,9 @@ import org.alfresco.service.ServiceRegistry; 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.service.cmr.repository.NodeService; import org.alfresco.service.cmr.transfer.NodeFilter; import org.alfresco.service.cmr.transfer.NodeFinder; +import org.alfresco.service.namespace.QName; import org.alfresco.util.ParameterCheck; import org.springframework.beans.factory.InitializingBean; @@ -48,12 +49,19 @@ public abstract class AbstractChannelType implements ChannelType, InitializingBe private ServiceRegistry serviceRegistry; protected NodeFinder nodeFinder; protected NodeFilter nodeFilter; + private ChannelService channelService; public void setChannelService(ChannelService channelService) { + this.channelService = channelService; channelService.register(this); } + protected ChannelService getChannelService() + { + return channelService; + } + /** * @param serviceRegistry * the serviceRegistry to set @@ -154,15 +162,14 @@ public abstract class AbstractChannelType implements ChannelType, InitializingBe + "; Received " + channel.getChannelType().getId()); } - NodeRef channelNodeRef = channel.getNodeRef(); - NodeService nodeService = serviceRegistry.getNodeService(); - String[] username = callbackParams.get("username"); String[] password = callbackParams.get("password"); if (username != null && password != null) { - nodeService.setProperty(channelNodeRef, PublishingModel.PROP_CHANNEL_USERNAME, username[0]); - nodeService.setProperty(channelNodeRef, PublishingModel.PROP_CHANNEL_PASSWORD, password[0]); + Map props = new HashMap(); + props.put(PublishingModel.PROP_CHANNEL_USERNAME, username[0]); + props.put(PublishingModel.PROP_CHANNEL_PASSWORD, password[0]); + channelService.updateChannel(channel, props); //TODO: BJR: 20110707: Should test the connection here result = true; } diff --git a/source/java/org/alfresco/repo/publishing/ChannelHelper.java b/source/java/org/alfresco/repo/publishing/ChannelHelper.java index 3b6a1b2286..941d6fa777 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelHelper.java +++ b/source/java/org/alfresco/repo/publishing/ChannelHelper.java @@ -109,7 +109,9 @@ public class ChannelHelper { ChannelType channelType = channel.getChannelType(); String channelName = channel.getName(); - return createChannelNode(environment, channelType, channelName, properties); + NodeRef envChannel = createChannelNode(environment, channelType, channelName, properties); + nodeService.createAssociation(envChannel, channel.getNodeRef(), PublishingModel.ASSOC_EDITORIAL_CHANNEL); + return envChannel; } public Channel getChannel(NodeRef environment, String channelName, ChannelService channelService) diff --git a/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java b/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java index ff9a0ba830..4d68e8b26d 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java +++ b/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java @@ -39,6 +39,7 @@ import org.alfresco.service.cmr.dictionary.DictionaryService; 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.AssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.site.SiteInfo; @@ -379,15 +380,20 @@ public class ChannelServiceImpl implements ChannelService * (java.lang.String, java.lang.String, java.util.Map) */ @Override - public void updateChannel(String siteId, String channelName, Map properties) + public void updateChannel(Channel channel, Map properties) { - Set containers = getAllChannelContainers(siteId); - for (NodeRef channelContainer : containers) + List allChannelNodes = new ArrayList(); + NodeRef editorialNode = channel.getNodeRef(); + allChannelNodes.add(editorialNode); + for (AssociationRef assoc : nodeService.getSourceAssocs(editorialNode, PublishingModel.ASSOC_EDITORIAL_CHANNEL)) { - NodeRef channel = nodeService.getChildByName(channelContainer, ContentModel.ASSOC_CONTAINS, channelName); - if (channel != null) + allChannelNodes.add(assoc.getSourceRef()); + } + for (NodeRef channelNode : allChannelNodes) + { + for (Map.Entry entry : properties.entrySet()) { - nodeService.setProperties(channel, properties); + nodeService.setProperty(channelNode, entry.getKey(), entry.getValue()); } } } diff --git a/source/java/org/alfresco/repo/publishing/ChannelServiceImplIntegratedTest.java b/source/java/org/alfresco/repo/publishing/ChannelServiceImplIntegratedTest.java index be595a7e17..743815db54 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelServiceImplIntegratedTest.java +++ b/source/java/org/alfresco/repo/publishing/ChannelServiceImplIntegratedTest.java @@ -139,7 +139,7 @@ public class ChannelServiceImplIntegratedTest extends AbstractPublishingIntegrat assertNull(props.get(ContentModel.PROP_TITLE)); props.put(ContentModel.PROP_TITLE, newTitle); - channelService.updateChannel(siteId, channelName, props); + channelService.updateChannel(channel, props); channels = channelService.getChannels(siteId); assertEquals(1, channels.size()); diff --git a/source/java/org/alfresco/repo/publishing/PublishingModel.java b/source/java/org/alfresco/repo/publishing/PublishingModel.java index 88c8d6739b..e263ec8900 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingModel.java +++ b/source/java/org/alfresco/repo/publishing/PublishingModel.java @@ -87,6 +87,7 @@ public interface PublishingModel public static final QName ASSOC_PUBLISHING_EVENT = QName.createQName(NAMESPACE, "publishingEventAssoc"); public static final QName ASSOC_SOURCE = QName.createQName(NAMESPACE, "source"); public static final QName ASSOC_LAST_PUBLISHING_EVENT= QName.createQName(NAMESPACE, "lastPublishingEvent"); + public static final QName ASSOC_EDITORIAL_CHANNEL= QName.createQName(NAMESPACE, "editorialChannel"); // Workflow Properties public static final QName PROP_WF_PUBLISHING_EVENT= QName.createQName(WF_NAMESPACE, "publishingEvent"); diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareApiImpl.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareApiImpl.java new file mode 100644 index 0000000000..264c8a8404 --- /dev/null +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareApiImpl.java @@ -0,0 +1,303 @@ +/* + * Copyright (C) 2005-2011 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.slideshare; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.benfante.jslideshare.DocumentParser; +import com.benfante.jslideshare.DocumentParserResult; +import com.benfante.jslideshare.SlideShareAPI; +import com.benfante.jslideshare.SlideShareConnector; +import com.benfante.jslideshare.SlideShareErrorException; +import com.benfante.jslideshare.SlideShareException; +import com.benfante.jslideshare.messages.Group; +import com.benfante.jslideshare.messages.Slideshow; +import com.benfante.jslideshare.messages.SlideshowInfo; +import com.benfante.jslideshare.messages.Tag; +import com.benfante.jslideshare.messages.User; + +public class SlideShareApiImpl implements SlideShareAPI +{ + private static final Log logger = LogFactory.getLog(SlideShareApiImpl.class); + + public static final String URL_GET_SLIDESHOW = "URL_GET_SLIDESHOW"; + public static final String URL_GET_SLIDESHOW_INFO = "URL_GET_SLIDESHOW_INFO"; + public static final String URL_GET_SLIDESHOW_BY_USER = "URL_GET_SLIDESHOW_BY_USER"; + public static final String URL_GET_SLIDESHOW_BY_TAG = "URL_GET_SLIDESHOW_BY_TAG"; + public static final String URL_GET_SLIDESHOW_BY_GROUP = "URL_GET_SLIDESHOW_BY_GROUP"; + public static final String URL_UPLOAD_SLIDESHOW = "URL_UPLOAD_SLIDESHOW"; + public static final String URL_DELETE_SLIDESHOW = "URL_DELETE_SLIDESHOW"; + + private static Map DEFAULT_API_URLS = new TreeMap(); + + static + { + DEFAULT_API_URLS.put(URL_GET_SLIDESHOW, "http://www.slideshare.net/api/2/get_slideshow"); + DEFAULT_API_URLS.put(URL_GET_SLIDESHOW_INFO, "https://www.slideshare.net/api/2/get_slideshow_info"); + DEFAULT_API_URLS.put(URL_GET_SLIDESHOW_BY_USER, "https://www.slideshare.net/api/2/get_slideshow_by_user"); + DEFAULT_API_URLS.put(URL_GET_SLIDESHOW_BY_TAG, "https://www.slideshare.net/api/2/get_slideshow_by_tag"); + DEFAULT_API_URLS.put(URL_GET_SLIDESHOW_BY_GROUP, "https://www.slideshare.net/api/2/get_slideshow_from_group"); + DEFAULT_API_URLS.put(URL_UPLOAD_SLIDESHOW, "http://www.slideshare.net/api/2/upload_slideshow"); + DEFAULT_API_URLS.put(URL_DELETE_SLIDESHOW, "https://www.slideshare.net/api/2/delete_slideshow"); + } + + private Map apiUrls = new TreeMap(DEFAULT_API_URLS); + + protected SlideShareConnector connector; + + private String username; + + private String password; + + public SlideShareApiImpl() + { + } + + public SlideShareApiImpl(SlideShareConnector connector) + { + this.connector = connector; + } + + public SlideShareConnector getConnector() + { + return connector; + } + + public void setConnector(SlideShareConnector connector) + { + this.connector = connector; + } + + public void setApiUrls(Map urls) + { + if (urls == null || !urls.keySet().containsAll(DEFAULT_API_URLS.keySet())) + { + throw new IllegalArgumentException("Specified URL set is missing one or more values. Expected " + + DEFAULT_API_URLS.keySet() + "; Received " + (urls == null ? urls : urls.keySet())); + } + } + + public Slideshow getSlideshow(String id) throws SlideShareException, SlideShareErrorException + { + logger.info("Called getSlideshow with id=" + id); + Map parameters = new HashMap(); + addParameter(parameters, "slideshow_id", id); + return sendMessage(URL_GET_SLIDESHOW, parameters).getSlideShow(); + } + + public SlideshowInfo getSlideshowInfo(String id, String url) throws SlideShareException, SlideShareErrorException + { + logger.info("Called getSlideshowInfo with id=" + id + ", url=" + url); + Map parameters = new HashMap(); + addParameter(parameters, "slideshow_id", id); + addParameter(parameters, "slideshow_url", url); + return sendGetMessage(URL_GET_SLIDESHOW_INFO, parameters).getSlideShowInfo(); + } + + public User getSlideshowByUser(String username) throws SlideShareException, SlideShareErrorException + { + logger.info("Called getSlideshowByUser with username=" + username); + return getSlideshowByUser(username, -1, -1); + } + + public User getSlideshowByUser(String username, int offset, int limit) throws SlideShareException, + SlideShareErrorException + { + logger.info("Called getSlideshowByUser with username=" + username + ", offset=" + offset + ", limit=" + limit); + Map parameters = new HashMap(); + addParameter(parameters, "username_for", username); + addLimits(parameters, offset, limit); + return sendMessage(URL_GET_SLIDESHOW_BY_USER, parameters).getUser(); + } + + public Tag getSlideshowByTag(String tag) throws SlideShareException, SlideShareErrorException + { + logger.info("Called getSlideshowByTag with tag=" + tag); + return getSlideshowByTag(tag, -1, -1); + } + + public Tag getSlideshowByTag(String tag, int offset, int limit) throws SlideShareException, + SlideShareErrorException + { + logger.info("Called getSlideshowByTag with tag=" + tag + ", offset=" + offset + ", limit=" + limit); + Map parameters = new HashMap(); + addParameter(parameters, "tag", tag); + addLimits(parameters, offset, limit); + return sendMessage(URL_GET_SLIDESHOW_BY_TAG, parameters).getTag(); + } + + public Group getSlideshowByGroup(String groupName) throws SlideShareException, SlideShareErrorException + { + logger.info("Called getSlideshowByGroup with groupName=" + groupName); + return getSlideshowByGroup(groupName, -1, -1); + } + + public Group getSlideshowByGroup(String groupName, int offset, int limit) throws SlideShareException, + SlideShareErrorException + { + logger + .info("Called getSlideshowByGrop with groupName=" + groupName + ", offset=" + offset + ", limit=" + + limit); + Map parameters = new HashMap(); + addParameter(parameters, "group_name", groupName); + addLimits(parameters, offset, limit); + return sendMessage(URL_GET_SLIDESHOW_BY_GROUP, parameters).getGroup(); + } + + public String uploadSlideshow(String username, String password, String title, File src, String description, + String tags, boolean makeSrcPublic, boolean makeSlideshowPrivate, boolean generateSecretUrl, + boolean allowEmbeds, boolean shareWithContacts) throws SlideShareException, SlideShareErrorException + { + logger.info("Called uploadSlideshow with username=" + username + ", password=XXX, title=" + title + + ", description=" + description + ", tags=" + tags + ", makeSrcPublic=" + makeSrcPublic + + ", makeSlideshowPrivate=" + makeSlideshowPrivate + ", generateSecretUrl=" + generateSecretUrl + + ", allowEmbeds=" + allowEmbeds + ", shareWithContacts=" + shareWithContacts); + Map parameters = new HashMap(); + addParameter(parameters, "username", username); + addParameter(parameters, "password", password); + addParameter(parameters, "slideshow_title", title); + addParameter(parameters, "slideshow_description", description); + addParameter(parameters, "slideshow_tags", tags); + addParameter(parameters, "make_src_public", makeSrcPublic); + addParameter(parameters, "make_slideshow_private", makeSlideshowPrivate); + addParameter(parameters, "generate_secret_url", generateSecretUrl); + addParameter(parameters, "allow_embeds", allowEmbeds); + addParameter(parameters, "share_with_contacts", shareWithContacts); + Map files = new HashMap(); + files.put("slideshow_srcfile", src); + return sendMessage(URL_UPLOAD_SLIDESHOW, parameters, files).getSlideShowId(); + } + + public String deleteSlideshow(String username, String password, String id) throws SlideShareException, + SlideShareErrorException + { + logger.info("Called deleteSlideshow with username=" + username + ", password=XXX, id=" + id); + Map parameters = new HashMap(); + addParameter(parameters, "username", username); + addParameter(parameters, "password", password); + addParameter(parameters, "slideshow_id", id); + return sendGetMessage(URL_DELETE_SLIDESHOW, parameters).getSlideShowId(); + } + + private Map addParameter(Map parameters, String name, String value) + { + if (value != null) + { + parameters.put(name, value); + } + return parameters; + } + + private Map addParameter(Map parameters, String name, boolean value) + { + parameters.put(name, value ? "Y" : "N"); + return parameters; + } + + private Map addLimits(Map parameters, int offset, int limit) + { + if (offset >= 0) + { + parameters.put("offset", Integer.toString(offset)); + } + if (limit >= 0) + { + parameters.put("limit", Integer.toString(limit)); + } + return parameters; + } + + private DocumentParserResult sendMessage(String url, Map parameters) + throws SlideShareErrorException + { + addCredentials(parameters); + DocumentParserResult result; + try + { + InputStream response = connector.sendMessage(apiUrls.get(url), parameters); + result = DocumentParser.parse(response); + } + catch (IOException iOException) + { + throw new SlideShareErrorException(-1, "Error sending a message to the url " + apiUrls.get(url), iOException); + } + return result; + } + + private DocumentParserResult sendGetMessage(String url, Map parameters) + throws SlideShareErrorException + { + addCredentials(parameters); + DocumentParserResult result; + try + { + InputStream response = connector.sendGetMessage(apiUrls.get(url), parameters); + result = DocumentParser.parse(response); + } + catch (IOException iOException) + { + throw new SlideShareErrorException(-1, "Error sending a message to the url " + apiUrls.get(url), iOException); + } + return result; + } + + private DocumentParserResult sendMessage(String url, Map parameters, Map files) + throws SlideShareErrorException + { + addCredentials(parameters); + DocumentParserResult result; + try + { + InputStream response = connector.sendMultiPartMessage(apiUrls.get(url), parameters, files); + result = DocumentParser.parse(response); + } + catch (IOException iOException) + { + throw new SlideShareErrorException(-1, "Error sending a multipart message to the url " + apiUrls.get(url), iOException); + } + return result; + } + + private void addCredentials(Map parameters) + { + if (username != null && password != null) + { + addParameter(parameters, "username", username); + addParameter(parameters, "password", password); + } + } + + public void setUsername(String username) + { + this.username = username; + } + + public void setPassword(String password) + { + this.password = password; + } +} diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareChannelType.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareChannelType.java index 4f6f32dbea..db2d8ffa0f 100644 --- a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareChannelType.java +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareChannelType.java @@ -144,7 +144,7 @@ public class SlideShareChannelType extends AbstractChannelType String url = null; if (node != null && nodeService.exists(node) && nodeService.hasAspect(node, SlideSharePublishingModel.ASPECT_ASSET)) { - url = (String)nodeService.getProperty(node, SlideSharePublishingModel.PROP_PLAYER_URL); + url = (String)nodeService.getProperty(node, SlideSharePublishingModel.PROP_ASSET_URL); } return url; } diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishAction.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishAction.java index e93fe2a6b9..a8020d03e0 100644 --- a/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishAction.java +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishAction.java @@ -73,12 +73,12 @@ public class SlideSharePublishAction extends ActionExecuterAbstractBase @Override protected void executeImpl(Action action, NodeRef nodeRef) { - SlideShareAPI api = slideShareHelper.getSlideShareApi(); Pair usernamePassword = slideShareHelper.getSlideShareCredentialsForNode(nodeRef); - if (api == null || usernamePassword == null) + if (usernamePassword == null) { - throw new AlfrescoRuntimeException("publish.failed.unable_to_connect_to_service_provider"); + throw new AlfrescoRuntimeException("publish.failed.no_credentials_found"); } + SlideShareAPI api = slideShareHelper.getSlideShareApi(usernamePassword.getFirst(), usernamePassword.getSecond()); ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); if (reader.exists()) @@ -121,7 +121,14 @@ public class SlideSharePublishAction extends ActionExecuterAbstractBase String assetId = api.uploadSlideshow(usernamePassword.getFirst(), usernamePassword.getSecond(), title, contentFile, description, tags.toString(), false, false, false, false, false); +// String url = api.getSlideshow(assetId).getPermalink(); + String url = null; + if (log.isInfoEnabled()) + { + log.info("File " + name + " has been published to SlideShare with id " + assetId + " at URL " + url); + } nodeService.setProperty(nodeRef, SlideSharePublishingModel.PROP_ASSET_ID, assetId); + nodeService.setProperty(nodeRef, SlideSharePublishingModel.PROP_ASSET_URL, url); if (deleteContentFileOnCompletion) { diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishingHelper.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishingHelper.java index 1b33f5ea9e..ad1c1e6aa8 100644 --- a/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishingHelper.java +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishingHelper.java @@ -24,23 +24,32 @@ import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.util.Pair; import com.benfante.jslideshare.SlideShareAPI; -import com.benfante.jslideshare.SlideShareAPIFactory; +import com.benfante.jslideshare.SlideShareConnector; public class SlideSharePublishingHelper { private NodeService nodeService; + private SlideShareConnector slideshareConnector; public void setNodeService(NodeService nodeService) { this.nodeService = nodeService; } - + + public void setSlideshareConnector(SlideShareConnector slideshareConnector) + { + this.slideshareConnector = slideshareConnector; + } public SlideShareAPI getSlideShareApi() { - return SlideShareAPIFactory.getSlideShareAPI("hhjh", "oijkl"); + return createApiObject(); } + private SlideShareApiImpl createApiObject() + { + return new SlideShareApiImpl(slideshareConnector); + } public Pair getSlideShareCredentialsForNode(NodeRef publishNode) { @@ -61,4 +70,12 @@ public class SlideSharePublishingHelper return result; } + public SlideShareAPI getSlideShareApi(String username, String password) + { + SlideShareApiImpl api = createApiObject(); + api.setUsername(username); + api.setPassword(password); + return api; + } + } diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishingModel.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishingModel.java index 90b76625da..3705493ef7 100644 --- a/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishingModel.java +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideSharePublishingModel.java @@ -27,8 +27,8 @@ import org.alfresco.service.namespace.QName; */ public interface SlideSharePublishingModel { - public static final String NAMESPACE = "http://www.alfresco.org/model/publishing/youtube/1.0"; - public static final String PREFIX = "youtube"; + public static final String NAMESPACE = "http://www.alfresco.org/model/publishing/slideshare/1.0"; + public static final String PREFIX = "slideshare"; public static final QName TYPE_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannel"); @@ -36,5 +36,5 @@ public interface SlideSharePublishingModel public static final QName ASPECT_ASSET = QName.createQName(NAMESPACE, "AssetAspect"); public static final QName PROP_ASSET_ID = QName.createQName(NAMESPACE, "assetId"); - public static final QName PROP_PLAYER_URL = QName.createQName(NAMESPACE, "assetUrl"); + public static final QName PROP_ASSET_URL = QName.createQName(NAMESPACE, "assetUrl"); } diff --git a/source/java/org/alfresco/repo/publishing/slideshare/SlideShareTest.java b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareTest.java new file mode 100644 index 0000000000..de0e86b7f9 --- /dev/null +++ b/source/java/org/alfresco/repo/publishing/slideshare/SlideShareTest.java @@ -0,0 +1,163 @@ +/* + * 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.slideshare; + +import java.io.Serializable; +import java.util.HashMap; +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.PublishingModel; +import org.alfresco.repo.publishing.PublishingQueueImpl; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.transaction.RetryingTransactionHelper; +import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.model.FileFolderService; +import org.alfresco.service.cmr.publishing.channels.Channel; +import org.alfresco.service.cmr.publishing.channels.ChannelService; +import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.ContentWriter; +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.cmr.site.SiteVisibility; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.BaseSpringTest; +import org.alfresco.util.GUID; +import org.junit.Assert; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; + +/** + * @author Brian + * + */ +public class SlideShareTest extends BaseSpringTest +{ + protected ServiceRegistry serviceRegistry; + protected SiteService siteService; + protected FileFolderService fileFolderService; + protected NodeService nodeService; + protected String siteId; + protected PublishingQueueImpl queue; + protected EnvironmentImpl environment; + protected NodeRef docLib; + + private ChannelService channelService; + + private RetryingTransactionHelper transactionHelper; + + public void onSetUp() throws Exception + { + serviceRegistry = (ServiceRegistry) getApplicationContext().getBean("ServiceRegistry"); + channelService = (ChannelService) getApplicationContext().getBean("channelService"); + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); + siteService = serviceRegistry.getSiteService(); + fileFolderService = serviceRegistry.getFileFolderService(); + nodeService = serviceRegistry.getNodeService(); + transactionHelper = serviceRegistry.getRetryingTransactionHelper(); + + siteId = GUID.generate(); + siteService.createSite("test", siteId, "Site created by publishing test", "Site created by publishing test", + SiteVisibility.PUBLIC); + docLib = siteService.createContainer(siteId, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null); + } + + public void onTearDown() + { + siteService.deleteSite(siteId); + } + + public void testBlank() + { + + } + + //Note that this test isn't normally run, as it requires valid YouTube credentials. + //To run it, remove the initial 'x' from the method name and set the appropriate YouTube credentials where the + //text "YOUR_USER_NAME" and "YOUR_PASSWORD" appear. + public void xtestSlideSharePublishAndUnpublishActions() throws Exception + { + final NodeRef node = transactionHelper.doInTransaction(new RetryingTransactionCallback() + { + public NodeRef execute() throws Throwable + { + 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); + + NodeRef channelNode = channel.getNodeRef(); + Resource file = new ClassPathResource("test/alfresco/TestPresentation.pptx"); + Map vidProps = new HashMap(); + vidProps.put(ContentModel.PROP_NAME, "Test Presentation"); + NodeRef node = nodeService.createNode(channelNode, ContentModel.ASSOC_CONTAINS, + QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "testPresentation"), + ContentModel.TYPE_CONTENT, vidProps).getChildRef(); + ContentService contentService = serviceRegistry.getContentService(); + ContentWriter writer = contentService.getWriter(node, ContentModel.PROP_CONTENT, true); + writer.setMimetype(MimetypeMap.MIMETYPE_OPENXML_PRESENTATION); + writer.putContent(file.getFile()); + return node; + } + }); + + transactionHelper.doInTransaction(new RetryingTransactionCallback() + { + public NodeRef execute() throws Throwable + { + ActionService actionService = serviceRegistry.getActionService(); + Action publishAction = actionService.createAction(SlideSharePublishAction.NAME); + actionService.executeAction(publishAction, node); + Map props = nodeService.getProperties(node); + Assert.assertTrue(nodeService.hasAspect(node, SlideSharePublishingModel.ASPECT_ASSET)); + Assert.assertNotNull(props.get(SlideSharePublishingModel.PROP_ASSET_ID)); +// Assert.assertNotNull(props.get(SlideSharePublishingModel.PROP_ASSET_URL)); + + System.out.println("SlideShare id: " + props.get(SlideSharePublishingModel.PROP_ASSET_ID)); + +// Action unpublishAction = actionService.createAction(SlideShareUnpublishAction.NAME); +// actionService.executeAction(unpublishAction, node); +// props = nodeService.getProperties(node); +// Assert.assertFalse(nodeService.hasAspect(node, SlideSharePublishingModel.ASPECT_ASSET)); +// Assert.assertNull(props.get(SlideSharePublishingModel.PROP_ASSET_ID)); +// Assert.assertNull(props.get(SlideSharePublishingModel.PROP_ASSET_URL)); + return null; + } + }); + + transactionHelper.doInTransaction(new RetryingTransactionCallback() + { + public NodeRef execute() throws Throwable + { + nodeService.deleteNode(node); + return null; + } + }); + + } + +} diff --git a/source/java/org/alfresco/repo/publishing/twitter/TwitterChannelType.java b/source/java/org/alfresco/repo/publishing/twitter/TwitterChannelType.java index 6060f1414c..c24f4448b2 100644 --- a/source/java/org/alfresco/repo/publishing/twitter/TwitterChannelType.java +++ b/source/java/org/alfresco/repo/publishing/twitter/TwitterChannelType.java @@ -20,6 +20,7 @@ package org.alfresco.repo.publishing.twitter; import java.io.Serializable; import java.util.Collections; +import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -154,14 +155,16 @@ public class TwitterChannelType extends AbstractChannelType OAuth1Operations oauthOperations = publishingHelper.getConnectionFactory().getOAuthOperations(); NodeRef channelNodeRef = channel.getNodeRef(); - Map props = nodeService.getProperties(channelNodeRef); - String tokenValue = (String) props.get(PublishingModel.PROP_OAUTH1_TOKEN_VALUE); - String tokenSecret = (String) props.get(PublishingModel.PROP_OAUTH1_TOKEN_SECRET); + Map currentProps = nodeService.getProperties(channelNodeRef); + String tokenValue = (String) currentProps.get(PublishingModel.PROP_OAUTH1_TOKEN_VALUE); + String tokenSecret = (String) currentProps.get(PublishingModel.PROP_OAUTH1_TOKEN_SECRET); OAuthToken token = new OAuthToken(tokenValue, tokenSecret); OAuthToken accessToken = oauthOperations.exchangeForAccessToken(new AuthorizedRequestToken(token, verifier[0]), null); - nodeService.setProperty(channelNodeRef, PublishingModel.PROP_OAUTH1_TOKEN_VALUE, accessToken.getValue()); - nodeService.setProperty(channelNodeRef, PublishingModel.PROP_OAUTH1_TOKEN_SECRET, accessToken.getSecret()); + Map newProps = new HashMap(); + newProps.put(PublishingModel.PROP_OAUTH1_TOKEN_VALUE, accessToken.getValue()); + newProps.put(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, accessToken.getSecret()); + getChannelService().updateChannel(channel, newProps); authorised = true; } return authorised; diff --git a/source/java/org/alfresco/repo/publishing/youtube/YouTubeTest.java b/source/java/org/alfresco/repo/publishing/youtube/YouTubeTest.java index 1f8c9e1fd5..c4d370660a 100644 --- a/source/java/org/alfresco/repo/publishing/youtube/YouTubeTest.java +++ b/source/java/org/alfresco/repo/publishing/youtube/YouTubeTest.java @@ -105,8 +105,8 @@ public class YouTubeTest extends BaseSpringTest public NodeRef execute() throws Throwable { Map props = new HashMap(); - props.put(PublishingModel.PROP_CHANNEL_USERNAME, "demochilledpenguin"); - props.put(PublishingModel.PROP_CHANNEL_PASSWORD, "D3moChilledPenguin"); + 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); NodeRef channelNode = channel.getNodeRef(); 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 e829a7213b..8015ef1dce 100644 --- a/source/java/org/alfresco/service/cmr/publishing/channels/ChannelService.java +++ b/source/java/org/alfresco/service/cmr/publishing/channels/ChannelService.java @@ -80,11 +80,11 @@ public interface ChannelService /** * Update the properties of the specified channel. - * @param siteId The identifier of the Share site that contains the channel that is to be updated. - * @param channelName The name of the channel that is to be updated. - * @param properties The complete set of properties to set on the channel. + * @param channel The channel that is to be updated. + * @param properties The properties to set on the channel. These are blended with the current properties + * on the channel. Any that aren't currently set will be added, others will be updated. */ - void updateChannel(String siteId, String channelName, Map properties); + void updateChannel(Channel channel, Map properties); /** * Retrieve all the channels contained by the specified Share site. @@ -130,7 +130,7 @@ public interface ChannelService List getStatusUpdateChannels(String siteId); /** - * Returns all {@link Channel}s cpaable of performing a status update for the Share Site in which the specified nodeToPublish exists. + * Returns all {@link Channel}s capable of performing a status update for the Share Site in which the specified nodeToPublish exists. * @param siteId * @return */