diff --git a/source/java/org/alfresco/repo/publishing/AbstractChannelType.java b/source/java/org/alfresco/repo/publishing/AbstractChannelType.java index 77957274d9..525545aef5 100644 --- a/source/java/org/alfresco/repo/publishing/AbstractChannelType.java +++ b/source/java/org/alfresco/repo/publishing/AbstractChannelType.java @@ -145,16 +145,15 @@ public abstract class AbstractChannelType implements ChannelType, InitializingBe @Override public String getAuthorisationUrl(Channel channel, String callbackUrl) { - //Returning a null here to indicate that we should use our own credential-gathering mechanism. + // Returning a null here to indicate that we should use our own + // credential-gathering mechanism. return null; } @Override - public boolean acceptAuthorisationCallback(Channel channel, Map callbackHeaders, + public final AuthStatus acceptAuthorisationCallback(Channel channel, Map callbackHeaders, Map callbackParams) { - boolean result = false; - ParameterCheck.mandatory("channel", channel); ParameterCheck.mandatory("callbackHeaders", callbackHeaders); ParameterCheck.mandatory("callbackParams", callbackParams); @@ -164,6 +163,18 @@ public abstract class AbstractChannelType implements ChannelType, InitializingBe + "; Received " + channel.getChannelType().getId()); } + AuthStatus result = internalAcceptAuthorisation(channel, callbackHeaders, callbackParams); + + Map props = new HashMap(); + props.put(PublishingModel.PROP_AUTHORISATION_COMPLETE, Boolean.valueOf(AuthStatus.AUTHORISED.equals(result))); + channelService.updateChannel(channel, props); + return result; + } + + protected AuthStatus internalAcceptAuthorisation(Channel channel, Map callbackHeaders, + Map callbackParams) + { + AuthStatus result = AuthStatus.UNAUTHORISED; String[] username = callbackParams.get("username"); String[] password = callbackParams.get("password"); if (username != null && password != null) @@ -172,23 +183,13 @@ public abstract class AbstractChannelType implements ChannelType, InitializingBe 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; + // TODO: BJR: 20110707: Should test the connection here + result = AuthStatus.AUTHORISED; } return result; } - - public Resource getIcon16() - { - return getIcon("16"); - } - - public Resource getIcon32() - { - return getIcon("32"); - } - - protected Resource getIcon(String sizeSuffix) + + public Resource getIcon(String sizeSuffix) { String className = this.getClass().getCanonicalName(); className = className.replaceAll("\\.", "\\/"); @@ -197,7 +198,7 @@ public abstract class AbstractChannelType implements ChannelType, InitializingBe Resource resource = new ClassPathResource(iconPath.toString()); return resource.exists() ? resource : null; } - + public String getIconFileExtension() { return "png"; diff --git a/source/java/org/alfresco/repo/publishing/ChannelHelper.java b/source/java/org/alfresco/repo/publishing/ChannelHelper.java index 143fc86434..8a3f97c827 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelHelper.java +++ b/source/java/org/alfresco/repo/publishing/ChannelHelper.java @@ -363,5 +363,13 @@ public class ChannelHelper this.fileFolderService = fileFolderService; } - + public boolean isChannelAuthorised(NodeRef channelNode) + { + Boolean isAuthorised = Boolean.FALSE; + if (nodeService.exists(channelNode)) + { + isAuthorised = (Boolean)nodeService.getProperty(channelNode, PublishingModel.PROP_AUTHORISATION_COMPLETE); + } + return isAuthorised; + } } diff --git a/source/java/org/alfresco/repo/publishing/ChannelImpl.java b/source/java/org/alfresco/repo/publishing/ChannelImpl.java index 738cfb8ac0..e6768bf9f6 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelImpl.java +++ b/source/java/org/alfresco/repo/publishing/ChannelImpl.java @@ -133,4 +133,10 @@ public class ChannelImpl implements Channel NodeRef mappedNode = channelHelper.mapSourceToEnvironment(publishedNode, nodeRef); return channelType.getNodeUrl(mappedNode); } + + @Override + public boolean isAuthorised() + { + return channelHelper.isChannelAuthorised(getNodeRef()); + } } diff --git a/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java b/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java index e5426ba590..c472b7bec1 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java +++ b/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java @@ -319,7 +319,10 @@ public class ChannelServiceImpl implements ChannelService HashMap actualProps = new HashMap(properties); actualProps.remove(ContentModel.PROP_NODE_UUID); NodeRef editorialNode = channel.getNodeRef(); - nodeService.setProperties(editorialNode, actualProps); + for (Map.Entry entry : actualProps.entrySet()) + { + nodeService.setProperty(editorialNode, entry.getKey(), entry.getValue()); + } } /** diff --git a/source/java/org/alfresco/repo/publishing/facebook/FacebookChannelType.java b/source/java/org/alfresco/repo/publishing/facebook/FacebookChannelType.java index 673c2f2575..8c671d4b89 100644 --- a/source/java/org/alfresco/repo/publishing/facebook/FacebookChannelType.java +++ b/source/java/org/alfresco/repo/publishing/facebook/FacebookChannelType.java @@ -139,10 +139,10 @@ public class FacebookChannelType extends AbstractChannelType } @Override - public boolean acceptAuthorisationCallback(Channel channel, Map callbackHeaders, + protected AuthStatus internalAcceptAuthorisation(Channel channel, Map callbackHeaders, Map callbackParams) { - boolean authorised = false; + AuthStatus authorised = AuthStatus.UNAUTHORISED; String accessToken = null; if (callbackParams.containsKey("access_token")) @@ -162,7 +162,7 @@ public class FacebookChannelType extends AbstractChannelType Map channelProps = new HashMap(); channelProps.put(PublishingModel.PROP_OAUTH2_TOKEN, accessToken); getChannelService().updateChannel(channel, channelProps); - authorised = true; + authorised = AuthStatus.AUTHORISED; } return authorised; } diff --git a/source/java/org/alfresco/repo/publishing/flickr/FlickrChannelType.java b/source/java/org/alfresco/repo/publishing/flickr/FlickrChannelType.java index fe33a5de2e..1102019f3d 100644 --- a/source/java/org/alfresco/repo/publishing/flickr/FlickrChannelType.java +++ b/source/java/org/alfresco/repo/publishing/flickr/FlickrChannelType.java @@ -173,10 +173,10 @@ public class FlickrChannelType extends AbstractChannelType } @Override - public boolean acceptAuthorisationCallback(Channel channel, Map callbackHeaders, + protected AuthStatus internalAcceptAuthorisation(Channel channel, Map callbackHeaders, Map callbackParams) { - boolean authorised = false; + AuthStatus authorised = AuthStatus.UNAUTHORISED; String[] verifier = callbackParams.get("oauth_verifier"); if (verifier != null) { @@ -193,7 +193,7 @@ public class FlickrChannelType extends AbstractChannelType newProps.put(PublishingModel.PROP_OAUTH1_TOKEN_VALUE, accessToken.getValue()); newProps.put(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, accessToken.getSecret()); getChannelService().updateChannel(channel, newProps); - authorised = true; + authorised = AuthStatus.AUTHORISED; } return authorised; } diff --git a/source/java/org/alfresco/repo/publishing/twitter/TwitterChannelType.java b/source/java/org/alfresco/repo/publishing/twitter/TwitterChannelType.java index 2ce38fbdb1..583bb203d3 100644 --- a/source/java/org/alfresco/repo/publishing/twitter/TwitterChannelType.java +++ b/source/java/org/alfresco/repo/publishing/twitter/TwitterChannelType.java @@ -145,10 +145,10 @@ public class TwitterChannelType extends AbstractChannelType } @Override - public boolean acceptAuthorisationCallback(Channel channel, Map callbackHeaders, + protected AuthStatus internalAcceptAuthorisation(Channel channel, Map callbackHeaders, Map callbackParams) { - boolean authorised = false; + AuthStatus authorised = AuthStatus.UNAUTHORISED; String[] verifier = callbackParams.get("oauth_verifier"); if (verifier != null) { @@ -165,7 +165,7 @@ public class TwitterChannelType extends AbstractChannelType newProps.put(PublishingModel.PROP_OAUTH1_TOKEN_VALUE, accessToken.getValue()); newProps.put(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, accessToken.getSecret()); getChannelService().updateChannel(channel, newProps); - authorised = true; + authorised = AuthStatus.AUTHORISED; } return authorised; } diff --git a/source/java/org/alfresco/service/cmr/publishing/channels/Channel.java b/source/java/org/alfresco/service/cmr/publishing/channels/Channel.java index 8d35e94597..7aa2559076 100644 --- a/source/java/org/alfresco/service/cmr/publishing/channels/Channel.java +++ b/source/java/org/alfresco/service/cmr/publishing/channels/Channel.java @@ -58,4 +58,15 @@ public interface Channel * @return a URL for the published content. */ String getUrl(NodeRef publishedNode); + + /** + * Has this channel been authorised yet? + * Typically, when a channel is created in Alfresco the user is sent to the service provider to authorise + * Alfresco to access their account on their behalf. Once Alfresco has been told that the user has done that then + * this operation will return true. Until then, this operation will return false. + * + * A channel that is not authorised cannot be used to publish content or status updates to. + * @return true if this channel has been authorised and is ready for use. + */ + boolean isAuthorised(); } \ No newline at end of file diff --git a/source/java/org/alfresco/service/cmr/publishing/channels/ChannelType.java b/source/java/org/alfresco/service/cmr/publishing/channels/ChannelType.java index d9bc79e8a3..19b3c22c7c 100644 --- a/source/java/org/alfresco/service/cmr/publishing/channels/ChannelType.java +++ b/source/java/org/alfresco/service/cmr/publishing/channels/ChannelType.java @@ -35,6 +35,8 @@ import org.springframework.core.io.Resource; */ public interface ChannelType { + enum AuthStatus {AUTHORISED, RETRY, UNAUTHORISED}; + String getId(); QName getChannelNodeType(); NodeFinder getNodeFinder(); @@ -59,9 +61,14 @@ public interface ChannelType int getMaximumStatusLength(); String getAuthorisationUrl(Channel channel, String callbackUrl); - boolean acceptAuthorisationCallback(Channel channel, Map callbackHeaders, Map callbackParams); + AuthStatus acceptAuthorisationCallback(Channel channel, Map callbackHeaders, Map callbackParams); String getIconFileExtension(); - Resource getIcon16(); - Resource getIcon32(); + + /** + * Obtain the resource that represents an icon for this channel type. + * @param size A text representation of the icon size required. "16", "32", etc. + * @return The resource that represents the requested icon if available. null otherwise. + */ + Resource getIcon(String size); }