Fixed ALF-10333: Publishing: Multiple publishing events are processed sequentially rather than in parallel

Publishing: Remove some operations from the Channel and ChannelType interface that really shouldn't be exposed. Also removed the PublishingQueue interface - the two operations it had are now on the PublishingService.
WQS: Removed obsolete references to publishing channels.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30794 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Brian Remmington
2011-09-27 11:23:19 +00:00
parent 590f665d63
commit 2fd91d87c2
49 changed files with 1274 additions and 1525 deletions

View File

@@ -199,7 +199,7 @@ public class SlideShareApiImpl implements SlideShareApi
addParameter(parameters, "username", username);
addParameter(parameters, "password", password);
addParameter(parameters, "slideshow_id", id);
return sendMessage(URL_DELETE_SLIDESHOW, parameters).getSlideShowId();
return sendGetMessage(URL_DELETE_SLIDESHOW, parameters).getSlideShowId();
}
private Map<String, String> addParameter(Map<String, String> parameters, String name, String value)

View File

@@ -18,43 +18,70 @@
*/
package org.alfresco.repo.publishing.slideshare;
import java.io.File;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.publishing.AbstractChannelType;
import org.alfresco.repo.publishing.PublishingModel;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.publishing.channels.Channel;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.tagging.TaggingService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.alfresco.util.TempFileProvider;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.benfante.jslideshare.SlideShareAPI;
import com.benfante.jslideshare.messages.SlideshowInfo;
public class SlideShareChannelType extends AbstractChannelType
{
public final static String ID = "slideshare";
private NodeService nodeService;
private ActionService actionService;
private final static Log log = LogFactory.getLog(SlideShareChannelType.class);
private final static int STATUS_QUEUED = 0;
// private final static int STATUS_CONVERTING = 1;
private final static int STATUS_SUCCEEDED = 2;
private final static int STATUS_FAILED = 3;
private final static int STATUS_TIMED_OUT = 10;
private static final String ERROR_SLIDESHARE_CONVERSION_FAILED = "publish.slideshare.conversionFailed";
private static final String ERROR_SLIDESHARE_CONVERSION_TIMED_OUT = "publish.slideshare.conversionTimedOut";
private SlideSharePublishingHelper publishingHelper;
private ContentService contentService;
private TaggingService taggingService;
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setActionService(ActionService actionService)
{
this.actionService = actionService;
}
private long timeoutMilliseconds = 40L * 60L * 1000L; // 40 mins default
public void setPublishingHelper(SlideSharePublishingHelper publishingHelper)
{
this.publishingHelper = publishingHelper;
}
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
public void setTaggingService(TaggingService taggingService)
{
this.taggingService = taggingService;
}
public void setTimeoutMilliseconds(long timeoutMilliseconds)
{
this.timeoutMilliseconds = timeoutMilliseconds;
}
@Override
public boolean canPublish()
{
@@ -85,12 +112,6 @@ public class SlideShareChannelType extends AbstractChannelType
return ID;
}
@Override
public Set<QName> getSupportedContentTypes()
{
return Collections.emptySet();
}
@Override
public Set<String> getSupportedMimeTypes()
{
@@ -100,31 +121,152 @@ public class SlideShareChannelType extends AbstractChannelType
@Override
public void publish(NodeRef nodeToPublish, Map<QName, Serializable> properties)
{
Action publishAction = actionService.createAction(SlideSharePublishAction.NAME);
actionService.executeAction(publishAction, nodeToPublish);
NodeService nodeService = getNodeService();
Pair<String, String> usernamePassword = publishingHelper
.getSlideShareCredentialsFromChannelProperties(properties);
if (usernamePassword == null)
{
throw new AlfrescoRuntimeException("publish.failed.no_credentials_found");
}
SlideShareAPI api = publishingHelper
.getSlideShareApi(usernamePassword.getFirst(), usernamePassword.getSecond());
ContentReader reader = contentService.getReader(nodeToPublish, ContentModel.PROP_CONTENT);
if (reader.exists())
{
File contentFile;
String mime = reader.getMimetype();
String extension = publishingHelper.getAllowedMimeTypes().get(mime);
if (extension == null)
extension = "";
boolean deleteContentFileOnCompletion = false;
// SlideShare seems to work entirely off file extension, so we
// always copy onto the
// file system and upload from there.
File tempDir = TempFileProvider.getLongLifeTempDir("slideshare");
contentFile = TempFileProvider.createTempFile("slideshare", extension, tempDir);
reader.getContent(contentFile);
deleteContentFileOnCompletion = true;
try
{
String name = (String) nodeService.getProperty(nodeToPublish, ContentModel.PROP_NAME);
String title = (String) nodeService.getProperty(nodeToPublish, ContentModel.PROP_TITLE);
if (title == null || title.length() == 0)
{
title = name;
}
String description = (String) nodeService.getProperty(nodeToPublish, ContentModel.PROP_DESCRIPTION);
if (description == null || description.length() == 0)
{
description = title;
}
List<String> tagList = taggingService.getTags(nodeToPublish);
StringBuilder tags = new StringBuilder();
for (String tag : tagList)
{
tags.append(tag);
tags.append(' ');
}
String assetId = api.uploadSlideshow(usernamePassword.getFirst(), usernamePassword.getSecond(), title,
contentFile, description, tags.toString(), false, false, false, false, false);
String url = null;
int status = STATUS_QUEUED;
boolean finished = false;
long timeoutTime = System.currentTimeMillis() + timeoutMilliseconds;
// Fetch the slideshow info every 30 seconds until we timeout
while (!finished)
{
SlideshowInfo slideInfo = api.getSlideshowInfo(assetId, "");
if (slideInfo != null)
{
if (url == null)
{
url = slideInfo.getUrl();
if (log.isInfoEnabled())
{
log.info("SlideShare has provided a URL for asset " + assetId + ": " + url);
}
}
status = slideInfo.getStatus();
}
finished = (status == STATUS_FAILED || status == STATUS_SUCCEEDED);
if (!finished)
{
if (System.currentTimeMillis() < timeoutTime)
{
try
{
Thread.sleep(30000L);
}
catch (InterruptedException e)
{
}
}
else
{
status = STATUS_TIMED_OUT;
finished = true;
}
}
}
if (status == STATUS_SUCCEEDED)
{
if (log.isInfoEnabled())
{
log.info("File " + name + " has been published to SlideShare with id " + assetId + " at URL "
+ url);
}
nodeService.addAspect(nodeToPublish, SlideSharePublishingModel.ASPECT_ASSET, null);
nodeService.setProperty(nodeToPublish, PublishingModel.PROP_ASSET_ID, assetId);
nodeService.setProperty(nodeToPublish, PublishingModel.PROP_ASSET_URL, url);
}
else
{
throw new AlfrescoRuntimeException(status == STATUS_FAILED ? ERROR_SLIDESHARE_CONVERSION_FAILED
: ERROR_SLIDESHARE_CONVERSION_TIMED_OUT);
}
}
finally
{
if (deleteContentFileOnCompletion)
{
contentFile.delete();
}
}
}
}
@Override
public void unpublish(NodeRef nodeToUnpublish, Map<QName, Serializable> properties)
{
Action unpublishAction = actionService.createAction(SlideShareUnpublishAction.NAME);
actionService.executeAction(unpublishAction, nodeToUnpublish);
}
@Override
public void updateStatus(Channel channel, String status, Map<QName, Serializable> properties)
{
throw new UnsupportedOperationException();
}
@Override
public String getNodeUrl(NodeRef node)
{
String url = null;
if (node != null && nodeService.exists(node) && nodeService.hasAspect(node, SlideSharePublishingModel.ASPECT_ASSET))
NodeService nodeService = getNodeService();
if (nodeService.hasAspect(nodeToUnpublish, SlideSharePublishingModel.ASPECT_ASSET))
{
url = (String)nodeService.getProperty(node, PublishingModel.PROP_ASSET_URL);
String assetId = (String) nodeService.getProperty(nodeToUnpublish, PublishingModel.PROP_ASSET_ID);
if (assetId != null)
{
Pair<String, String> usernamePassword = publishingHelper
.getSlideShareCredentialsFromChannelProperties(properties);
if (usernamePassword == null)
{
throw new AlfrescoRuntimeException("publish.failed.no_credentials_found");
}
SlideShareApi api = publishingHelper.getSlideShareApi(usernamePassword.getFirst(), usernamePassword
.getSecond());
api.deleteSlideshow(usernamePassword.getFirst(), usernamePassword.getSecond(), assetId);
nodeService.removeAspect(nodeToUnpublish, SlideSharePublishingModel.ASPECT_ASSET);
nodeService.removeAspect(nodeToUnpublish, PublishingModel.ASPECT_ASSET);
}
}
return url;
}
}

View File

@@ -0,0 +1,222 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco, but is derived from a file
* Copyright 2008 The JSlideShare Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.alfresco.repo.publishing.slideshare;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.apache.log4j.Logger;
import com.benfante.jslideshare.SlideShareConnector;
import com.benfante.jslideshare.SlideShareErrorException;
public class SlideShareConnectorImpl implements SlideShareConnector
{
private static final Logger logger = Logger.getLogger(SlideShareConnectorImpl.class);
private String apiKey;
private String sharedSecret;
private HttpClient httpClient;
public SlideShareConnectorImpl()
{
httpClient = new HttpClient();
httpClient.setHttpConnectionManager(new MultiThreadedHttpConnectionManager());
}
public SlideShareConnectorImpl(String apiKey, String sharedSecret)
{
this();
this.apiKey = apiKey;
this.sharedSecret = sharedSecret;
}
public String getApiKey()
{
return apiKey;
}
public void setApiKey(String apiKey)
{
this.apiKey = apiKey;
}
public String getSharedSecret()
{
return sharedSecret;
}
public void setSharedSecret(String sharedSecret)
{
this.sharedSecret = sharedSecret;
}
public InputStream sendMessage(String url, Map<String, String> parameters) throws IOException,
SlideShareErrorException
{
PostMethod method = new PostMethod(url);
method.addParameter("api_key", this.apiKey);
Iterator<Map.Entry<String, String>> entryIt = parameters.entrySet().iterator();
while (entryIt.hasNext())
{
Map.Entry<String, String> entry = entryIt.next();
method.addParameter(entry.getKey(), entry.getValue());
}
Date now = new Date();
String ts = Long.toString(now.getTime() / 1000);
String hash = DigestUtils.shaHex(this.sharedSecret + ts).toLowerCase();
method.addParameter("ts", ts);
method.addParameter("hash", hash);
logger.debug("Sending POST message to " + method.getURI().getURI() + " with parameters "
+ Arrays.toString(method.getParameters()));
int statusCode = httpClient.executeMethod(method);
if (statusCode != HttpStatus.SC_OK)
{
logger.debug("Server replied with a " + statusCode + " HTTP status code ("
+ HttpStatus.getStatusText(statusCode) + ")");
throw new SlideShareErrorException(statusCode, HttpStatus.getStatusText(statusCode));
}
if (logger.isDebugEnabled())
{
logger.debug(method.getResponseBodyAsString());
}
InputStream result = new ByteArrayInputStream(method.getResponseBody());
method.releaseConnection();
return result;
}
public InputStream sendMultiPartMessage(String url, Map<String, String> parameters, Map<String, File> files)
throws IOException, SlideShareErrorException
{
PostMethod method = new PostMethod(url);
List<Part> partList = new ArrayList<Part>();
partList.add(createStringPart("api_key", this.apiKey));
Date now = new Date();
String ts = Long.toString(now.getTime() / 1000);
String hash = DigestUtils.shaHex(this.sharedSecret + ts).toLowerCase();
partList.add(createStringPart("ts", ts));
partList.add(createStringPart("hash", hash));
Iterator<Map.Entry<String, String>> entryIt = parameters.entrySet().iterator();
while (entryIt.hasNext())
{
Map.Entry<String, String> entry = entryIt.next();
partList.add(createStringPart(entry.getKey(), entry.getValue()));
}
Iterator<Map.Entry<String, File>> entryFileIt = files.entrySet().iterator();
while (entryFileIt.hasNext())
{
Map.Entry<String, File> entry = entryFileIt.next();
partList.add(createFilePart(entry.getKey(), entry.getValue()));
}
MultipartRequestEntity requestEntity = new MultipartRequestEntity(partList.toArray(new Part[partList.size()]),
method.getParams());
method.setRequestEntity(requestEntity);
logger.debug("Sending multipart POST message to " + method.getURI().getURI() + " with parts " + partList);
int statusCode = httpClient.executeMethod(method);
if (statusCode != HttpStatus.SC_OK)
{
logger.debug("Server replied with a " + statusCode + " HTTP status code ("
+ HttpStatus.getStatusText(statusCode) + ")");
throw new SlideShareErrorException(statusCode, HttpStatus.getStatusText(statusCode));
}
if (logger.isDebugEnabled())
{
logger.debug(method.getResponseBodyAsString());
}
InputStream result = new ByteArrayInputStream(method.getResponseBody());
method.releaseConnection();
return result;
}
public InputStream sendGetMessage(String url, Map<String, String> parameters) throws IOException,
SlideShareErrorException
{
GetMethod method = new GetMethod(url);
NameValuePair[] params = new NameValuePair[parameters.size() + 3];
int i = 0;
params[i++] = new NameValuePair("api_key", this.apiKey);
Iterator<Map.Entry<String, String>> entryIt = parameters.entrySet().iterator();
while (entryIt.hasNext())
{
Map.Entry<String, String> entry = entryIt.next();
params[i++] = new NameValuePair(entry.getKey(), entry.getValue());
}
Date now = new Date();
String ts = Long.toString(now.getTime() / 1000);
String hash = DigestUtils.shaHex(this.sharedSecret + ts).toLowerCase();
params[i++] = new NameValuePair("ts", ts);
params[i++] = new NameValuePair("hash", hash);
method.setQueryString(params);
logger.debug("Sending GET message to " + method.getURI().getURI() + " with parameters "
+ Arrays.toString(params));
int statusCode = httpClient.executeMethod(method);
if (statusCode != HttpStatus.SC_OK)
{
logger.debug("Server replied with a " + statusCode + " HTTP status code ("
+ HttpStatus.getStatusText(statusCode) + ")");
throw new SlideShareErrorException(statusCode, HttpStatus.getStatusText(statusCode));
}
if (logger.isDebugEnabled())
{
logger.debug(method.getResponseBodyAsString());
}
InputStream result = new ByteArrayInputStream(method.getResponseBody());
method.releaseConnection();
return result;
}
private StringPart createStringPart(String name, String value)
{
StringPart stringPart = new StringPart(name, value);
stringPart.setContentType(null);
stringPart.setTransferEncoding(null);
stringPart.setCharSet("UTF-8");
return stringPart;
}
private FilePart createFilePart(String name, File value) throws FileNotFoundException
{
FilePart filePart = new FilePart(name, value);
filePart.setTransferEncoding(null);
filePart.setCharSet(null);
return filePart;
}
}

View File

@@ -1,216 +0,0 @@
/*
* 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.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.repo.publishing.PublishingModel;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.tagging.TaggingService;
import org.alfresco.util.Pair;
import org.alfresco.util.TempFileProvider;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.benfante.jslideshare.SlideShareAPI;
import com.benfante.jslideshare.messages.SlideshowInfo;
public class SlideSharePublishAction extends ActionExecuterAbstractBase
{
private final static Log log = LogFactory.getLog(SlideSharePublishAction.class);
private final static int STATUS_QUEUED = 0;
// private final static int STATUS_CONVERTING = 1;
private final static int STATUS_SUCCEEDED = 2;
private final static int STATUS_FAILED = 3;
private final static int STATUS_TIMED_OUT = 10;
public static final String NAME = "publish_slideshare";
private static final String ERROR_SLIDESHARE_CONVERSION_FAILED = "publish.slideshare.conversionFailed";
private static final String ERROR_SLIDESHARE_CONVERSION_TIMED_OUT = "publish.slideshare.conversionTimedOut";
private NodeService nodeService;
private ContentService contentService;
private TaggingService taggingService;
private SlideSharePublishingHelper slideShareHelper;
private long timeoutMilliseconds = 40L * 60L * 1000L; // 40 mins default
public void setSlideShareHelper(SlideSharePublishingHelper slideShareHelper)
{
this.slideShareHelper = slideShareHelper;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
public void setTaggingService(TaggingService taggingService)
{
this.taggingService = taggingService;
}
public void setTimeoutMilliseconds(long timeoutMilliseconds)
{
this.timeoutMilliseconds = timeoutMilliseconds;
}
@Override
protected void executeImpl(Action action, NodeRef nodeRef)
{
Pair<String, String> usernamePassword = slideShareHelper.getSlideShareCredentialsForNode(nodeRef);
if (usernamePassword == null)
{
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())
{
File contentFile;
String mime = reader.getMimetype();
String extension = slideShareHelper.getAllowedMimeTypes().get(mime);
if (extension == null)
extension = "";
boolean deleteContentFileOnCompletion = false;
// SlideShare seems to work entirely off file extension, so we
// always copy onto the
// file system and upload from there.
File tempDir = TempFileProvider.getLongLifeTempDir("slideshare");
contentFile = TempFileProvider.createTempFile("slideshare", extension, tempDir);
reader.getContent(contentFile);
deleteContentFileOnCompletion = true;
try
{
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
String title = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
if (title == null || title.length() == 0)
{
title = name;
}
String description = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION);
if (description == null || description.length() == 0)
{
description = title;
}
List<String> tagList = taggingService.getTags(nodeRef);
StringBuilder tags = new StringBuilder();
for (String tag : tagList)
{
tags.append(tag);
tags.append(' ');
}
String assetId = api.uploadSlideshow(usernamePassword.getFirst(), usernamePassword.getSecond(), title,
contentFile, description, tags.toString(), false, false, false, false, false);
String url = null;
int status = STATUS_QUEUED;
boolean finished = false;
long timeoutTime = System.currentTimeMillis() + timeoutMilliseconds;
// Fetch the slideshow info every 5 seconds for 5 minutes...
while (!finished)
{
SlideshowInfo slideInfo = api.getSlideshowInfo(assetId, "");
if (slideInfo != null)
{
if (url == null)
{
url = slideInfo.getUrl();
if (log.isInfoEnabled())
{
log.info("SlideShare has provided a URL for asset " + assetId + ": " + url);
}
}
status = slideInfo.getStatus();
}
finished = (status == STATUS_FAILED || status == STATUS_SUCCEEDED);
if (!finished)
{
if (System.currentTimeMillis() < timeoutTime)
{
try
{
Thread.sleep(30000L);
}
catch (InterruptedException e)
{
}
}
else
{
status = STATUS_TIMED_OUT;
finished = true;
}
}
}
if (status == STATUS_SUCCEEDED)
{
if (log.isInfoEnabled())
{
log.info("File " + name + " has been published to SlideShare with id " + assetId + " at URL "
+ url);
}
nodeService.addAspect(nodeRef, SlideSharePublishingModel.ASPECT_ASSET, null);
nodeService.setProperty(nodeRef, PublishingModel.PROP_ASSET_ID, assetId);
nodeService.setProperty(nodeRef, PublishingModel.PROP_ASSET_URL, url);
}
else
{
throw new AlfrescoRuntimeException(status == STATUS_FAILED ? ERROR_SLIDESHARE_CONVERSION_FAILED
: ERROR_SLIDESHARE_CONVERSION_TIMED_OUT);
}
}
finally
{
if (deleteContentFileOnCompletion)
{
contentFile.delete();
}
}
}
}
@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
{
}
}

View File

@@ -18,6 +18,7 @@
*/
package org.alfresco.repo.publishing.slideshare;
import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
@@ -25,8 +26,7 @@ import java.util.TreeMap;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.node.encryption.MetadataEncryptor;
import org.alfresco.repo.publishing.PublishingModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import com.benfante.jslideshare.SlideShareAPI;
@@ -52,15 +52,9 @@ public class SlideSharePublishingHelper
}
private Map<String, String> allowedMimeTypes = Collections.unmodifiableMap(DEFAULT_MIME_TYPES);
private NodeService nodeService;
private SlideShareConnector slideshareConnector;
private MetadataEncryptor encryptor;
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setSlideshareConnector(SlideShareConnector slideshareConnector)
{
this.slideshareConnector = slideshareConnector;
@@ -91,23 +85,16 @@ public class SlideSharePublishingHelper
return new SlideShareApiImpl(slideshareConnector);
}
public Pair<String, String> getSlideShareCredentialsForNode(NodeRef publishNode)
public Pair<String, String> getSlideShareCredentialsFromChannelProperties(Map<QName, Serializable> channelProperties)
{
Pair<String, String> result = null;
if (nodeService.exists(publishNode))
String username = (String) encryptor.decrypt(PublishingModel.PROP_CHANNEL_USERNAME,
channelProperties.get(PublishingModel.PROP_CHANNEL_USERNAME));
String password = (String) encryptor.decrypt(PublishingModel.PROP_CHANNEL_PASSWORD,
channelProperties.get(PublishingModel.PROP_CHANNEL_PASSWORD));
if (username != null && password != null)
{
NodeRef parent = nodeService.getPrimaryParent(publishNode).getParentRef();
if (nodeService.hasAspect(parent, SlideSharePublishingModel.ASPECT_DELIVERY_CHANNEL))
{
String username = (String) encryptor.decrypt(PublishingModel.PROP_CHANNEL_USERNAME, nodeService
.getProperty(parent, PublishingModel.PROP_CHANNEL_USERNAME));
String password = (String) encryptor.decrypt(PublishingModel.PROP_CHANNEL_PASSWORD, nodeService
.getProperty(parent, PublishingModel.PROP_CHANNEL_PASSWORD));
if (username != null && password != null)
{
result = new Pair<String, String>(username, password);
}
}
result = new Pair<String, String>(username, password);
}
return result;
}

View File

@@ -36,8 +36,6 @@ 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;
@@ -115,6 +113,8 @@ public class SlideShareTest extends BaseSpringTest
// text "YOUR_USER_NAME" and "YOUR_PASSWORD" appear.
public void xtestSlideSharePublishAndUnpublishActions() throws Exception
{
final SlideShareChannelType channelType = (SlideShareChannelType)channelService.getChannelType(SlideShareChannelType.ID);
final String channelName = GUID.generate();
final List<NodeRef> nodes = transactionHelper.doInTransaction(new RetryingTransactionCallback<List<NodeRef>>()
{
public List<NodeRef> execute() throws Throwable
@@ -127,7 +127,7 @@ public class SlideShareTest extends BaseSpringTest
// "YOUR_PASSWORD");
props.put(PublishingModel.PROP_CHANNEL_USERNAME, "YOUR_USER_NAME");
props.put(PublishingModel.PROP_CHANNEL_PASSWORD, "YOUR_PASSWORD");
Channel channel = channelService.createChannel(SlideShareChannelType.ID, GUID.generate(), props);
Channel channel = channelService.createChannel(SlideShareChannelType.ID, channelName, props);
NodeRef channelNode = channel.getNodeRef();
@@ -162,29 +162,31 @@ public class SlideShareTest extends BaseSpringTest
{
public NodeRef execute() throws Throwable
{
Map<QName, Serializable> channelProperties = channelService.getChannelByName(channelName).getProperties();
for (NodeRef node : nodes)
{
ActionService actionService = serviceRegistry.getActionService();
Action publishAction = actionService.createAction(SlideSharePublishAction.NAME);
actionService.executeAction(publishAction, node);
channelType.publish(node, channelProperties);
Map<QName, Serializable> props = nodeService.getProperties(node);
Assert.assertTrue(nodeService.hasAspect(node, SlideSharePublishingModel.ASPECT_ASSET));
Assert.assertNotNull(props.get(PublishingModel.PROP_ASSET_ID));
Assert.assertNotNull(props.get(PublishingModel.PROP_ASSET_URL));
System.out.println("Test file: " + testNodeMap.get(node));
System.out.println("Published test file: " + testNodeMap.get(node));
System.out.println("SlideShare id: " + props.get(PublishingModel.PROP_ASSET_ID));
System.out.println("SlideShare URL: " + props.get(PublishingModel.PROP_ASSET_URL));
}
// 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));
for (NodeRef node : nodes)
{
Map<QName, Serializable> props = nodeService.getProperties(node);
channelType.unpublish(node, channelProperties);
props = nodeService.getProperties(node);
Assert.assertFalse(nodeService.hasAspect(node, SlideSharePublishingModel.ASPECT_ASSET));
Assert.assertNull(props.get(PublishingModel.PROP_ASSET_ID));
Assert.assertNull(props.get(PublishingModel.PROP_ASSET_URL));
System.out.println("Unpublished test file: " + testNodeMap.get(node));
}
return null;
}
});

View File

@@ -1,76 +0,0 @@
/*
* 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.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.repo.publishing.PublishingModel;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.util.Pair;
public class SlideShareUnpublishAction extends ActionExecuterAbstractBase
{
public static final String NAME = "unpublish_slideshare";
private NodeService nodeService;
private SlideSharePublishingHelper slideShareHelper;
public void setSlideShareHelper(SlideSharePublishingHelper slideShareHelper)
{
this.slideShareHelper = slideShareHelper;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
@Override
protected void executeImpl(Action action, NodeRef nodeRef)
{
if (nodeService.hasAspect(nodeRef, SlideSharePublishingModel.ASPECT_ASSET))
{
String assetId = (String) nodeService.getProperty(nodeRef, PublishingModel.PROP_ASSET_ID);
if (assetId != null)
{
Pair<String, String> usernamePassword = slideShareHelper.getSlideShareCredentialsForNode(nodeRef);
if (usernamePassword == null)
{
throw new AlfrescoRuntimeException("publish.failed.no_credentials_found");
}
SlideShareApi api = slideShareHelper.getSlideShareApi(
usernamePassword.getFirst(), usernamePassword.getSecond());
api.deleteSlideshow(usernamePassword.getFirst(), usernamePassword.getSecond(), assetId);
nodeService.removeAspect(nodeRef, SlideSharePublishingModel.ASPECT_ASSET);
nodeService.removeAspect(nodeRef, PublishingModel.ASPECT_ASSET);
}
}
}
@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
{
}
}