mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Refactored AbstractOAuth1ChannelType. Partially implemented LinkedInChannelType.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29425 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -27,20 +27,50 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.springframework.social.connect.Connection;
|
||||
import org.springframework.social.connect.support.OAuth1ConnectionFactory;
|
||||
import org.springframework.social.oauth1.AuthorizedRequestToken;
|
||||
import org.springframework.social.oauth1.OAuth1Operations;
|
||||
import org.springframework.social.oauth1.OAuth1Parameters;
|
||||
import org.springframework.social.oauth1.OAuthToken;
|
||||
|
||||
public abstract class AbstractOAuth1ChannelType extends AbstractChannelType
|
||||
/**
|
||||
* @author Brian
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*
|
||||
* @param <A> The API type, e.g. Twitter, Flickr, LinkedIn, etc.
|
||||
*/
|
||||
public abstract class AbstractOAuth1ChannelType<A> extends AbstractChannelType
|
||||
{
|
||||
private NodeService nodeService;
|
||||
private OAuth1ConnectionFactory<A> connectionFactory;
|
||||
|
||||
public final void setNodeService(NodeService nodeService)
|
||||
public Connection<A> getConnectionForPublishNode(NodeRef publishNode)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
NodeRef channelNode = nodeService.getPrimaryParent(publishNode).getParentRef();
|
||||
return getConnectionForChannel(channelNode);
|
||||
}
|
||||
|
||||
|
||||
public Connection<A> getConnectionForChannel(NodeRef channelNode)
|
||||
{
|
||||
Connection<A> connection = null;
|
||||
if (nodeService.exists(channelNode)
|
||||
&& nodeService.hasAspect(channelNode, PublishingModel.ASPECT_OAUTH1_DELIVERY_CHANNEL))
|
||||
{
|
||||
String tokenValue = (String) nodeService.getProperty(channelNode, PublishingModel.PROP_OAUTH1_TOKEN_VALUE);
|
||||
String tokenSecret = (String) nodeService.getProperty(channelNode, PublishingModel.PROP_OAUTH1_TOKEN_SECRET);
|
||||
Boolean danceComplete = (Boolean) nodeService.getProperty(channelNode, PublishingModel.PROP_AUTHORISATION_COMPLETE);
|
||||
|
||||
if (danceComplete)
|
||||
{
|
||||
OAuthToken token = new OAuthToken(tokenValue, tokenSecret);
|
||||
connection = connectionFactory.createConnection(token);
|
||||
}
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
protected NodeService getNodeService()
|
||||
{
|
||||
return nodeService;
|
||||
@@ -92,8 +122,6 @@ public abstract class AbstractOAuth1ChannelType extends AbstractChannelType
|
||||
return authorised;
|
||||
}
|
||||
|
||||
protected abstract OAuth1Operations getOAuth1Operations();
|
||||
|
||||
/**
|
||||
* Override this method to add additonal parameters onto the URL that the user is redirected to
|
||||
* to authorise access to their account. By default, no parameters are added, but this may be useful to
|
||||
@@ -110,4 +138,25 @@ public abstract class AbstractOAuth1ChannelType extends AbstractChannelType
|
||||
{
|
||||
return "oauth_verifier";
|
||||
}
|
||||
}
|
||||
|
||||
private OAuth1Operations getOAuth1Operations()
|
||||
{
|
||||
return connectionFactory.getOAuthOperations();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param connectionFactory the connectionFactory to set
|
||||
*/
|
||||
public void setConnectionFactory(OAuth1ConnectionFactory<A> connectionFactory)
|
||||
{
|
||||
this.connectionFactory = connectionFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeService the nodeService to set
|
||||
*/
|
||||
public final void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
}
|
@@ -27,38 +27,29 @@ import java.util.TreeSet;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.publishing.AbstractOAuth1ChannelType;
|
||||
import org.alfresco.repo.publishing.PublishingModel;
|
||||
import org.alfresco.repo.publishing.flickr.springsocial.api.Flickr;
|
||||
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.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.springframework.social.oauth1.OAuth1Operations;
|
||||
import org.alfresco.util.collections.CollectionUtils;
|
||||
import org.springframework.social.oauth1.OAuth1Parameters;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
public class FlickrChannelType extends AbstractOAuth1ChannelType
|
||||
public class FlickrChannelType extends AbstractOAuth1ChannelType<Flickr>
|
||||
{
|
||||
public final static String ID = "flickr";
|
||||
private final static Set<String> DEFAULT_SUPPORTED_MIME_TYPES = new TreeSet<String>();
|
||||
private final static Set<String> DEFAULT_SUPPORTED_MIME_TYPES = CollectionUtils.unmodifiableSet(
|
||||
MimetypeMap.MIMETYPE_IMAGE_GIF,
|
||||
MimetypeMap.MIMETYPE_IMAGE_JPEG,
|
||||
MimetypeMap.MIMETYPE_IMAGE_PNG);
|
||||
|
||||
static
|
||||
{
|
||||
DEFAULT_SUPPORTED_MIME_TYPES.add(MimetypeMap.MIMETYPE_IMAGE_GIF);
|
||||
DEFAULT_SUPPORTED_MIME_TYPES.add(MimetypeMap.MIMETYPE_IMAGE_JPEG);
|
||||
DEFAULT_SUPPORTED_MIME_TYPES.add(MimetypeMap.MIMETYPE_IMAGE_PNG);
|
||||
}
|
||||
|
||||
private FlickrPublishingHelper publishingHelper;
|
||||
private ActionService actionService;
|
||||
private Set<String> supportedMimeTypes = Collections.unmodifiableSet(DEFAULT_SUPPORTED_MIME_TYPES);
|
||||
private Set<String> supportedMimeTypes = DEFAULT_SUPPORTED_MIME_TYPES;
|
||||
|
||||
public void setPublishingHelper(FlickrPublishingHelper flickrPublishingHelper)
|
||||
{
|
||||
this.publishingHelper = flickrPublishingHelper;
|
||||
}
|
||||
|
||||
public void setActionService(ActionService actionService)
|
||||
{
|
||||
this.actionService = actionService;
|
||||
@@ -114,6 +105,10 @@ public class FlickrChannelType extends AbstractOAuth1ChannelType
|
||||
@Override
|
||||
public void publish(NodeRef nodeToPublish, Map<QName, Serializable> properties)
|
||||
{
|
||||
// TODO Nick S: Not sure it is very useful to use an Action hee.
|
||||
// The Action assumes the nodeToPublish is under a properly configured DeliveryChannel.
|
||||
// Ie. the action assumes the node was generated via the Publishing Service.
|
||||
// The Action only really has value if it can be called independant of the Publishing Service IMO.
|
||||
Action publishAction = actionService.createAction(FlickrPublishAction.NAME);
|
||||
actionService.executeAction(publishAction, nodeToPublish);
|
||||
}
|
||||
@@ -121,6 +116,7 @@ public class FlickrChannelType extends AbstractOAuth1ChannelType
|
||||
@Override
|
||||
public void unpublish(NodeRef nodeToUnpublish, Map<QName, Serializable> properties)
|
||||
{
|
||||
//NOOP
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,7 +136,7 @@ public class FlickrChannelType extends AbstractOAuth1ChannelType
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected OAuth1Parameters getOAuth1Parameters(String callbackUrl)
|
||||
{
|
||||
@@ -149,10 +145,4 @@ public class FlickrChannelType extends AbstractOAuth1ChannelType
|
||||
return new OAuth1Parameters(callbackUrl, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OAuth1Operations getOAuth1Operations()
|
||||
{
|
||||
return publishingHelper.getConnectionFactory().getOAuthOperations();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* 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.linkedin;
|
||||
|
||||
import static org.alfresco.repo.publishing.linkedin.LinkedInPublishingModel.TYPE_DELIVERY_CHANNEL;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.publishing.AbstractOAuth1ChannelType;
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.springframework.social.connect.Connection;
|
||||
import org.springframework.social.linkedin.api.LinkedIn;
|
||||
import org.springframework.social.oauth1.OAuth1Parameters;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public class LinkedInChannelType extends AbstractOAuth1ChannelType<LinkedIn>
|
||||
{
|
||||
public final static String ID = "linkedIn";
|
||||
|
||||
@Override
|
||||
public boolean canPublish()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPublishStatusUpdates()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUnpublish()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QName getChannelNodeType()
|
||||
{
|
||||
return TYPE_DELIVERY_CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<QName> getSupportedContentTypes()
|
||||
{
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedMimeTypes()
|
||||
{
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish(NodeRef nodeToPublish, Map<QName, Serializable> properties)
|
||||
{
|
||||
//NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unpublish(NodeRef nodeToUnpublish, Map<QName, Serializable> properties)
|
||||
{
|
||||
//NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStatus(Channel channel, String status, Map<QName, Serializable> properties)
|
||||
{
|
||||
NodeRef channelNode = new NodeRef(channel.getId());
|
||||
Connection<LinkedIn> connection = getConnectionForChannel(channelNode);
|
||||
// TODO update status
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNodeUrl(NodeRef node)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OAuth1Parameters getOAuth1Parameters(String callbackUrl)
|
||||
{
|
||||
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
|
||||
params.add("perms", "delete");
|
||||
return new OAuth1Parameters(callbackUrl, params);
|
||||
}
|
||||
|
||||
}
|
@@ -16,7 +16,7 @@
|
||||
* 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.twitter;
|
||||
package org.alfresco.repo.publishing.linkedin;
|
||||
|
||||
import org.alfresco.repo.publishing.PublishingModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
@@ -26,7 +26,7 @@ import org.springframework.social.oauth1.OAuthToken;
|
||||
import org.springframework.social.twitter.api.Twitter;
|
||||
import org.springframework.social.twitter.connect.TwitterConnectionFactory;
|
||||
|
||||
public class TwitterPublishingHelper
|
||||
public class LinkedInPublishingHelper
|
||||
{
|
||||
private NodeService nodeService;
|
||||
private TwitterConnectionFactory connectionFactory;
|
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.linkedin;
|
||||
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface LinkedInPublishingModel
|
||||
{
|
||||
public static final String NAMESPACE = "http://www.alfresco.org/model/publishing/linkedin/1.0";
|
||||
public static final String PREFIX = "linkedin";
|
||||
|
||||
public static final QName TYPE_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannel");
|
||||
|
||||
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_ASSET_URL = QName.createQName(NAMESPACE, "assetUrl");
|
||||
}
|
@@ -28,18 +28,11 @@ import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.springframework.social.connect.Connection;
|
||||
import org.springframework.social.oauth1.OAuth1Operations;
|
||||
import org.springframework.social.twitter.api.Twitter;
|
||||
|
||||
public class TwitterChannelType extends AbstractOAuth1ChannelType
|
||||
public class TwitterChannelType extends AbstractOAuth1ChannelType<Twitter>
|
||||
{
|
||||
public final static String ID = "twitter";
|
||||
private TwitterPublishingHelper publishingHelper;
|
||||
|
||||
public void setPublishingHelper(TwitterPublishingHelper twitterPublishingHelper)
|
||||
{
|
||||
this.publishingHelper = twitterPublishingHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPublish()
|
||||
@@ -98,7 +91,7 @@ public class TwitterChannelType extends AbstractOAuth1ChannelType
|
||||
@Override
|
||||
public void updateStatus(Channel channel, String status, Map<QName, Serializable> properties)
|
||||
{
|
||||
Connection<Twitter> connection = publishingHelper.getTwitterConnectionForChannel(channel.getNodeRef());
|
||||
Connection<Twitter> connection = getConnectionForChannel(channel.getNodeRef());
|
||||
connection.getApi().timelineOperations().updateStatus(status);
|
||||
}
|
||||
|
||||
@@ -108,9 +101,4 @@ public class TwitterChannelType extends AbstractOAuth1ChannelType
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OAuth1Operations getOAuth1Operations()
|
||||
{
|
||||
return publishingHelper.getConnectionFactory().getOAuthOperations();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user