Publishing:

- Return JSON status in response to authform.post
- Remove authstatus webscript 
- Add icon URL to channel type data on REST API
- Add authorise status to channel data on REST API
- Add delete channel to REST API
- Altered get icon operation on channel type so the required size can be specified freely (previously limited to known sizes)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29275 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Brian Remmington
2011-07-22 10:44:32 +00:00
parent 3b95ca79da
commit 1546669ade
9 changed files with 69 additions and 33 deletions

View File

@@ -145,16 +145,15 @@ public abstract class AbstractChannelType implements ChannelType, InitializingBe
@Override @Override
public String getAuthorisationUrl(Channel channel, String callbackUrl) 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; return null;
} }
@Override @Override
public boolean acceptAuthorisationCallback(Channel channel, Map<String, String[]> callbackHeaders, public final AuthStatus acceptAuthorisationCallback(Channel channel, Map<String, String[]> callbackHeaders,
Map<String, String[]> callbackParams) Map<String, String[]> callbackParams)
{ {
boolean result = false;
ParameterCheck.mandatory("channel", channel); ParameterCheck.mandatory("channel", channel);
ParameterCheck.mandatory("callbackHeaders", callbackHeaders); ParameterCheck.mandatory("callbackHeaders", callbackHeaders);
ParameterCheck.mandatory("callbackParams", callbackParams); ParameterCheck.mandatory("callbackParams", callbackParams);
@@ -164,6 +163,18 @@ public abstract class AbstractChannelType implements ChannelType, InitializingBe
+ "; Received " + channel.getChannelType().getId()); + "; Received " + channel.getChannelType().getId());
} }
AuthStatus result = internalAcceptAuthorisation(channel, callbackHeaders, callbackParams);
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(PublishingModel.PROP_AUTHORISATION_COMPLETE, Boolean.valueOf(AuthStatus.AUTHORISED.equals(result)));
channelService.updateChannel(channel, props);
return result;
}
protected AuthStatus internalAcceptAuthorisation(Channel channel, Map<String, String[]> callbackHeaders,
Map<String, String[]> callbackParams)
{
AuthStatus result = AuthStatus.UNAUTHORISED;
String[] username = callbackParams.get("username"); String[] username = callbackParams.get("username");
String[] password = callbackParams.get("password"); String[] password = callbackParams.get("password");
if (username != null && password != null) if (username != null && password != null)
@@ -173,22 +184,12 @@ public abstract class AbstractChannelType implements ChannelType, InitializingBe
props.put(PublishingModel.PROP_CHANNEL_PASSWORD, password[0]); props.put(PublishingModel.PROP_CHANNEL_PASSWORD, password[0]);
channelService.updateChannel(channel, props); channelService.updateChannel(channel, props);
// TODO: BJR: 20110707: Should test the connection here // TODO: BJR: 20110707: Should test the connection here
result = true; result = AuthStatus.AUTHORISED;
} }
return result; return result;
} }
public Resource getIcon16() public Resource getIcon(String sizeSuffix)
{
return getIcon("16");
}
public Resource getIcon32()
{
return getIcon("32");
}
protected Resource getIcon(String sizeSuffix)
{ {
String className = this.getClass().getCanonicalName(); String className = this.getClass().getCanonicalName();
className = className.replaceAll("\\.", "\\/"); className = className.replaceAll("\\.", "\\/");

View File

@@ -363,5 +363,13 @@ public class ChannelHelper
this.fileFolderService = fileFolderService; 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;
}
} }

View File

@@ -133,4 +133,10 @@ public class ChannelImpl implements Channel
NodeRef mappedNode = channelHelper.mapSourceToEnvironment(publishedNode, nodeRef); NodeRef mappedNode = channelHelper.mapSourceToEnvironment(publishedNode, nodeRef);
return channelType.getNodeUrl(mappedNode); return channelType.getNodeUrl(mappedNode);
} }
@Override
public boolean isAuthorised()
{
return channelHelper.isChannelAuthorised(getNodeRef());
}
} }

View File

@@ -319,7 +319,10 @@ public class ChannelServiceImpl implements ChannelService
HashMap<QName, Serializable> actualProps = new HashMap<QName, Serializable>(properties); HashMap<QName, Serializable> actualProps = new HashMap<QName, Serializable>(properties);
actualProps.remove(ContentModel.PROP_NODE_UUID); actualProps.remove(ContentModel.PROP_NODE_UUID);
NodeRef editorialNode = channel.getNodeRef(); NodeRef editorialNode = channel.getNodeRef();
nodeService.setProperties(editorialNode, actualProps); for (Map.Entry<QName, Serializable> entry : actualProps.entrySet())
{
nodeService.setProperty(editorialNode, entry.getKey(), entry.getValue());
}
} }
/** /**

View File

@@ -139,10 +139,10 @@ public class FacebookChannelType extends AbstractChannelType
} }
@Override @Override
public boolean acceptAuthorisationCallback(Channel channel, Map<String, String[]> callbackHeaders, protected AuthStatus internalAcceptAuthorisation(Channel channel, Map<String, String[]> callbackHeaders,
Map<String, String[]> callbackParams) Map<String, String[]> callbackParams)
{ {
boolean authorised = false; AuthStatus authorised = AuthStatus.UNAUTHORISED;
String accessToken = null; String accessToken = null;
if (callbackParams.containsKey("access_token")) if (callbackParams.containsKey("access_token"))
@@ -162,7 +162,7 @@ public class FacebookChannelType extends AbstractChannelType
Map<QName,Serializable> channelProps = new HashMap<QName, Serializable>(); Map<QName,Serializable> channelProps = new HashMap<QName, Serializable>();
channelProps.put(PublishingModel.PROP_OAUTH2_TOKEN, accessToken); channelProps.put(PublishingModel.PROP_OAUTH2_TOKEN, accessToken);
getChannelService().updateChannel(channel, channelProps); getChannelService().updateChannel(channel, channelProps);
authorised = true; authorised = AuthStatus.AUTHORISED;
} }
return authorised; return authorised;
} }

View File

@@ -173,10 +173,10 @@ public class FlickrChannelType extends AbstractChannelType
} }
@Override @Override
public boolean acceptAuthorisationCallback(Channel channel, Map<String, String[]> callbackHeaders, protected AuthStatus internalAcceptAuthorisation(Channel channel, Map<String, String[]> callbackHeaders,
Map<String, String[]> callbackParams) Map<String, String[]> callbackParams)
{ {
boolean authorised = false; AuthStatus authorised = AuthStatus.UNAUTHORISED;
String[] verifier = callbackParams.get("oauth_verifier"); String[] verifier = callbackParams.get("oauth_verifier");
if (verifier != null) 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_VALUE, accessToken.getValue());
newProps.put(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, accessToken.getSecret()); newProps.put(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, accessToken.getSecret());
getChannelService().updateChannel(channel, newProps); getChannelService().updateChannel(channel, newProps);
authorised = true; authorised = AuthStatus.AUTHORISED;
} }
return authorised; return authorised;
} }

View File

@@ -145,10 +145,10 @@ public class TwitterChannelType extends AbstractChannelType
} }
@Override @Override
public boolean acceptAuthorisationCallback(Channel channel, Map<String, String[]> callbackHeaders, protected AuthStatus internalAcceptAuthorisation(Channel channel, Map<String, String[]> callbackHeaders,
Map<String, String[]> callbackParams) Map<String, String[]> callbackParams)
{ {
boolean authorised = false; AuthStatus authorised = AuthStatus.UNAUTHORISED;
String[] verifier = callbackParams.get("oauth_verifier"); String[] verifier = callbackParams.get("oauth_verifier");
if (verifier != null) 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_VALUE, accessToken.getValue());
newProps.put(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, accessToken.getSecret()); newProps.put(PublishingModel.PROP_OAUTH1_TOKEN_SECRET, accessToken.getSecret());
getChannelService().updateChannel(channel, newProps); getChannelService().updateChannel(channel, newProps);
authorised = true; authorised = AuthStatus.AUTHORISED;
} }
return authorised; return authorised;
} }

View File

@@ -58,4 +58,15 @@ public interface Channel
* @return a URL for the published content. * @return a URL for the published content.
*/ */
String getUrl(NodeRef publishedNode); 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();
} }

View File

@@ -35,6 +35,8 @@ import org.springframework.core.io.Resource;
*/ */
public interface ChannelType public interface ChannelType
{ {
enum AuthStatus {AUTHORISED, RETRY, UNAUTHORISED};
String getId(); String getId();
QName getChannelNodeType(); QName getChannelNodeType();
NodeFinder getNodeFinder(); NodeFinder getNodeFinder();
@@ -59,9 +61,14 @@ public interface ChannelType
int getMaximumStatusLength(); int getMaximumStatusLength();
String getAuthorisationUrl(Channel channel, String callbackUrl); String getAuthorisationUrl(Channel channel, String callbackUrl);
boolean acceptAuthorisationCallback(Channel channel, Map<String, String[]> callbackHeaders, Map<String, String[]> callbackParams); AuthStatus acceptAuthorisationCallback(Channel channel, Map<String, String[]> callbackHeaders, Map<String, String[]> callbackParams);
String getIconFileExtension(); 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. <code>null</code> otherwise.
*/
Resource getIcon(String size);
} }