Publishing:

- SlideShare channel now tested (the service seems pretty flaky, but the publishing works fine).
- A couple of tweaks to ensure that credentials are being stored correctly for each channel.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28966 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Brian Remmington
2011-07-13 08:21:05 +00:00
parent 23119a80b5
commit f12b5edafa
17 changed files with 563 additions and 37 deletions

View File

@@ -34,6 +34,17 @@
</property>
</properties>
<associations>
<association name="pub:editorialChannel">
<source>
<mandatory>false</mandatory>
<many>false</many>
</source>
<target>
<class>pub:DeliveryChannel</class>
<mandatory>false</mandatory>
<many>false</many>
</target>
</association>
<child-association name="pub:deliveryServers">
<source>
<mandatory>false</mandatory>

View File

@@ -12,6 +12,12 @@
<bean id="slidesharePublishingHelper" class="org.alfresco.repo.publishing.slideshare.SlideSharePublishingHelper">
<property name="nodeService" ref="NodeService" />
<property name="slideshareConnector" ref="slideshareApiConnector" />
</bean>
<bean id="slideshareApiConnector" class="com.benfante.jslideshare.SlideShareConnectorImpl">
<property name="apiKey" value="iXUZdaNl" />
<property name="sharedSecret" value="DLysO5tR" />
</bean>
<bean id="publish_slideshare" parent="action-executer" class="org.alfresco.repo.publishing.slideshare.SlideSharePublishAction">

Binary file not shown.

View File

@@ -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<QName, Serializable> props = new HashMap<QName, Serializable>();
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;
}

View File

@@ -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)

View File

@@ -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<QName, Serializable> properties)
public void updateChannel(Channel channel, Map<QName, Serializable> properties)
{
Set<NodeRef> containers = getAllChannelContainers(siteId);
for (NodeRef channelContainer : containers)
List<NodeRef> allChannelNodes = new ArrayList<NodeRef>();
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)
{
nodeService.setProperties(channel, properties);
for (Map.Entry<QName, Serializable> entry : properties.entrySet())
{
nodeService.setProperty(channelNode, entry.getKey(), entry.getValue());
}
}
}

View File

@@ -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());

View File

@@ -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");

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<String, String> DEFAULT_API_URLS = new TreeMap<String, String>();
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<String, String> apiUrls = new TreeMap<String, String>(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<String, String> 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<String, String> parameters = new HashMap<String, String>();
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<String, String> parameters = new HashMap<String, String>();
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<String, String> parameters = new HashMap<String, String>();
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<String, String> parameters = new HashMap<String, String>();
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<String, String> parameters = new HashMap<String, String>();
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<String, String> parameters = new HashMap<String, String>();
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<String, File> files = new HashMap<String, File>();
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<String, String> parameters = new HashMap<String, String>();
addParameter(parameters, "username", username);
addParameter(parameters, "password", password);
addParameter(parameters, "slideshow_id", id);
return sendGetMessage(URL_DELETE_SLIDESHOW, parameters).getSlideShowId();
}
private Map<String, String> addParameter(Map<String, String> parameters, String name, String value)
{
if (value != null)
{
parameters.put(name, value);
}
return parameters;
}
private Map<String, String> addParameter(Map<String, String> parameters, String name, boolean value)
{
parameters.put(name, value ? "Y" : "N");
return parameters;
}
private Map<String, String> addLimits(Map<String, String> 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<String, String> 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<String, String> 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<String, String> parameters, Map<String, File> 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<String, String> 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;
}
}

View File

@@ -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;
}

View File

@@ -73,12 +73,12 @@ public class SlideSharePublishAction extends ActionExecuterAbstractBase
@Override
protected void executeImpl(Action action, NodeRef nodeRef)
{
SlideShareAPI api = slideShareHelper.getSlideShareApi();
Pair<String,String> 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)
{

View File

@@ -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<String, String> 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;
}
}

View File

@@ -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");
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<NodeRef>()
{
public NodeRef execute() throws Throwable
{
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
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<QName, Serializable> vidProps = new HashMap<QName, Serializable>();
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<NodeRef>()
{
public NodeRef execute() throws Throwable
{
ActionService actionService = serviceRegistry.getActionService();
Action publishAction = actionService.createAction(SlideSharePublishAction.NAME);
actionService.executeAction(publishAction, node);
Map<QName, Serializable> 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<NodeRef>()
{
public NodeRef execute() throws Throwable
{
nodeService.deleteNode(node);
return null;
}
});
}
}

View File

@@ -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<QName, Serializable> 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<QName, Serializable> 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<QName, Serializable> newProps = new HashMap<QName, Serializable>();
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;

View File

@@ -105,8 +105,8 @@ public class YouTubeTest extends BaseSpringTest
public NodeRef execute() throws Throwable
{
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
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();

View File

@@ -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<QName,Serializable> properties);
void updateChannel(Channel channel, Map<QName,Serializable> properties);
/**
* Retrieve all the channels contained by the specified Share site.
@@ -130,7 +130,7 @@ public interface ChannelService
List<Channel> getStatusUpdateChannels(String siteId);
/**
* Returns all {@link Channel}s cpaable of performing a status update for the Share Site in which the specified <code>nodeToPublish</code> exists.
* Returns all {@link Channel}s capable of performing a status update for the Share Site in which the specified <code>nodeToPublish</code> exists.
* @param siteId
* @return
*/