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 92c45359d8
commit fa5cdf1f5b
21 changed files with 135 additions and 265 deletions

View File

@@ -19,46 +19,33 @@
package org.alfresco.repo.web.scripts.publishing;
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import org.alfresco.repo.publishing.PublishingModel;
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.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
public class AuthCallbackWebScript extends AbstractWebScript
public class AuthCallbackWebScript extends DeclarativeWebScript
{
private final static Log log = LogFactory.getLog(AuthCallbackWebScript.class);
private NodeService nodeService;
private ChannelService channelService;
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setChannelService(ChannelService channelService)
{
this.channelService = channelService;
}
@Override
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
res.setContentType("text/html");
res.setContentEncoding("UTF-8");
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
Map<String,String[]> params = new TreeMap<String, String[]>();
Map<String,String[]> headers = new TreeMap<String, String[]>();
@@ -87,24 +74,10 @@ public class AuthCallbackWebScript extends AbstractWebScript
NodeRef channelNodeRef = new NodeRef(channelNodeStoreProtocol, channelNodeStoreId, channelNodeUuid);
Channel channel = channelService.getChannelById(channelNodeRef.toString());
if (channel.getChannelType().acceptAuthorisationCallback(channel, headers, params))
{
Map<QName,Serializable> props = new HashMap<QName, Serializable>();
props.put(PublishingModel.PROP_AUTHORISATION_COMPLETE, Boolean.TRUE);
channelService.updateChannel(channel, props);
res.getWriter().write("Authorisation granted!");
}
else
{
Boolean authorised = (Boolean)nodeService.getProperty(channelNodeRef, PublishingModel.PROP_AUTHORISATION_COMPLETE);
if (authorised != null && !authorised)
{
//If we have not been granted access by the service provider then we
//simply delete this publishing channel
channelService.deleteChannel(channel);
}
res.getWriter().write("Authorisation denied!");
}
ChannelType.AuthStatus authStatus = channel.getChannelType().acceptAuthorisationCallback(channel, headers, params);
Map<String,Object> model = new TreeMap<String, Object>();
model.put("authStatus", authStatus.name());
return model;
}
}

View File

@@ -1,82 +0,0 @@
/*
* 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.web.scripts.publishing;
import java.util.Map;
import java.util.TreeMap;
import org.alfresco.service.cmr.publishing.channels.Channel;
import org.alfresco.service.cmr.publishing.channels.ChannelService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
public class ChannelPostWebScript extends DeclarativeWebScript
{
private ChannelService channelService;
public void setChannelService(ChannelService channelService)
{
this.channelService = channelService;
}
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
String channelType = req.getParameter("channelType");
String siteId = req.getParameter("siteId");
String channelName = req.getParameter("channelName");
Channel newChannel = channelService.createChannel(channelType, channelName, null);
NodeRef channelNodeRef = newChannel.getNodeRef();
StringBuilder urlBuilder = new StringBuilder(req.getServerPath());
urlBuilder.append(req.getServiceContextPath());
urlBuilder.append("/api/publishing/channel/");
urlBuilder.append(channelNodeRef.getStoreRef().getProtocol());
urlBuilder.append('/');
urlBuilder.append(channelNodeRef.getStoreRef().getIdentifier());
urlBuilder.append('/');
urlBuilder.append(channelNodeRef.getId());
urlBuilder.append('/');
String baseUrl = urlBuilder.toString();
String pollUrl = baseUrl + "authstatus";
String callbackUrl = baseUrl + "authcallback";
String authoriseUrl = channelService.getChannelType(channelType).getAuthorisationUrl(newChannel, callbackUrl);
if (authoriseUrl == null)
{
// If a channel type returns null as the authorise URL then we
// assume credentials are to be supplied to us directly. We'll point the
// user at our own credential-gathering form.
authoriseUrl = baseUrl + "authform";
}
Map<String, Object> model = new TreeMap<String, Object>();
model.put("pollUrl", pollUrl);
model.put("authoriseUrl", authoriseUrl);
model.put("channelId", channelNodeRef.toString());
return model;
}
}

View File

@@ -27,8 +27,6 @@ import java.util.Map;
import org.alfresco.service.cmr.publishing.channels.ChannelService;
import org.alfresco.service.cmr.publishing.channels.ChannelType;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.WebScriptRequest;
@@ -37,7 +35,6 @@ import org.springframework.util.FileCopyUtils;
public class ChannelTypeIconGetWebScript extends AbstractWebScript
{
private final static Log log = LogFactory.getLog(ChannelTypeIconGetWebScript.class);
private ChannelService channelService;
private MimetypeService mimetypeService;
@@ -73,15 +70,7 @@ public class ChannelTypeIconGetWebScript extends AbstractWebScript
return;
}
Resource iconFile = null;
if (iconSize.equals("16"))
{
iconFile = channelType.getIcon16();
}
else if (iconSize.equals("32"))
{
iconFile = channelType.getIcon32();
}
Resource iconFile = channelType.getIcon(iconSize);
if (iconFile == null || !iconFile.exists())
{
res.setStatus(404); //Not found

View File

@@ -19,52 +19,57 @@
package org.alfresco.repo.web.scripts.publishing;
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
import org.alfresco.repo.publishing.PublishingModel;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.publishing.channels.Channel;
import org.alfresco.service.cmr.publishing.channels.ChannelService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
public class AuthStatusGetWebScript extends DeclarativeWebScript
public class ChannelsDeleteWebScript extends AbstractWebScript
{
private NodeService nodeService;
private ChannelService channelService;
public void setNodeService(NodeService nodeService)
public void setChannelService(ChannelService channelService)
{
this.nodeService = nodeService;
this.channelService = channelService;
}
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
{
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String channelNodeUuid = templateVars.get("node_id");
String channelNodeStoreProtocol = templateVars.get("store_protocol");
String channelNodeStoreId = templateVars.get("store_id");
String authStatus = "REJECTED";
NodeRef channelNodeRef = new NodeRef(channelNodeStoreProtocol, channelNodeStoreId, channelNodeUuid);
if (nodeService.exists(channelNodeRef))
if (channelNodeStoreId == null || channelNodeStoreProtocol == null || channelNodeUuid == null)
{
Boolean authComplete = (Boolean)nodeService.getProperty(channelNodeRef, PublishingModel.PROP_AUTHORISATION_COMPLETE);
if (authComplete)
{
authStatus = "AUTHORISED";
}
else
{
authStatus = "PENDING";
}
res.setStatus(Status.STATUS_BAD_REQUEST);
return;
}
Map<String,Object> model = new TreeMap<String, Object>();
model.put("channelId", channelNodeRef.toString());
model.put("authStatus", authStatus);
return model;
NodeRef channelNodeRef = new NodeRef(channelNodeStoreProtocol, channelNodeStoreId, channelNodeUuid);
Channel channel = channelService.getChannelById(channelNodeRef.toString());
if (channel == null)
{
res.setStatus(Status.STATUS_NOT_FOUND);
return;
}
try
{
channelService.deleteChannel(channel);
}
catch (AccessDeniedException ex)
{
res.setStatus(Status.STATUS_UNAUTHORIZED);
}
}
}

View File

@@ -22,9 +22,11 @@ package org.alfresco.repo.web.scripts.publishing;
import java.util.Map;
import java.util.TreeMap;
import org.alfresco.repo.admin.SysAdminParams;
import org.alfresco.service.cmr.publishing.channels.Channel;
import org.alfresco.service.cmr.publishing.channels.ChannelService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.UrlUtil;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
@@ -33,12 +35,18 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
public class ChannelsPostWebScript extends DeclarativeWebScript
{
private ChannelService channelService;
private SysAdminParams sysAdminParams;
public void setChannelService(ChannelService channelService)
{
this.channelService = channelService;
}
public void setSysAdminParams(SysAdminParams sysAdminParams)
{
this.sysAdminParams = sysAdminParams;
}
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
@@ -48,9 +56,8 @@ public class ChannelsPostWebScript extends DeclarativeWebScript
Channel newChannel = channelService.createChannel(channelType, channelName, null);
NodeRef channelNodeRef = newChannel.getNodeRef();
StringBuilder urlBuilder = new StringBuilder(req.getServerPath());
urlBuilder.append(req.getServiceContextPath());
urlBuilder.append("/api/publishing/channel/");
StringBuilder urlBuilder = new StringBuilder(UrlUtil.getShareUrl(sysAdminParams));
urlBuilder.append("/proxy/alfresco/api/publishing/channels/");
urlBuilder.append(channelNodeRef.getStoreRef().getProtocol());
urlBuilder.append('/');
urlBuilder.append(channelNodeRef.getStoreRef().getIdentifier());
@@ -59,7 +66,6 @@ public class ChannelsPostWebScript extends DeclarativeWebScript
urlBuilder.append('/');
String baseUrl = urlBuilder.toString();
String pollUrl = baseUrl + "authstatus";
String callbackUrl = baseUrl + "authcallback";
String authoriseUrl = channelService.getChannelType(channelType).getAuthorisationUrl(newChannel, callbackUrl);
@@ -72,9 +78,8 @@ public class ChannelsPostWebScript extends DeclarativeWebScript
}
Map<String, Object> model = new TreeMap<String, Object>();
model.put("pollUrl", pollUrl);
model.put("authoriseUrl", authoriseUrl);
model.put("channelId", channelNodeRef.toString());
model.put("channelId", newChannel.getId());
model.put("authCallbackUrl", callbackUrl);
return model;

View File

@@ -21,29 +21,6 @@ package org.alfresco.repo.web.scripts.publishing;
import static org.alfresco.repo.web.scripts.WebScriptUtil.buildCalendarModel;
import static org.alfresco.repo.web.scripts.WebScriptUtil.buildDateModel;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CAN_PUBLISH;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CAN_PUBLISH_STATUS_UPDATES;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CAN_UNPUBLISH;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CHANNEL;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CHANNEL_NODE_TYPE;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CHANNEL_TYPE;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.COMMENT;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CREATED_TIME;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CREATOR;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.ICON;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.ID;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.MAX_STATUS_LENGTH;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.NAME;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.NODEREF;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.PUBLISH_NODES;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.SCHEDULED_TIME;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.STATUS;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.SUPPORTED_CONTENT_TYPES;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.SUPPORTED_MIME_TYPES;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.TITLE;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.UNPUBLISH_NODES;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.URL;
import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.VERSION;
import static org.alfresco.util.collections.CollectionUtils.toListOfStrings;
import static org.alfresco.util.collections.CollectionUtils.transform;
@@ -71,7 +48,7 @@ import org.springframework.extensions.surf.util.URLEncoder;
* @since 4.0
*
*/
public class PublishingModelBuilder
public class PublishingModelBuilder implements PublishingWebScriptConstants
{
public Map<String, Object> buildPublishingEvent(PublishingEvent event, ChannelService channelService)
@@ -122,6 +99,7 @@ public class PublishingModelBuilder
//TODO Localize the title.
model.put(TITLE, channel.getName());
model.put(CHANNEL_TYPE, buildChannelType(channel.getChannelType()));
model.put(CHANNEL_AUTH_STATUS, toString(channel.isAuthorised()));
return model;
}
@@ -153,7 +131,7 @@ public class PublishingModelBuilder
model.put(CAN_UNPUBLISH, toString(type.canUnpublish()));
model.put(MAX_STATUS_LENGTH, type.getMaximumStatusLength());
model.put(ICON, "");
model.put(ICON, getUrl(type) + "/icon/");
return model;
}
@@ -175,7 +153,7 @@ public class PublishingModelBuilder
public static String getUrl(ChannelType type)
{
return "api/publishing/channelTypes/"+URLEncoder.encode(type.getId());
return "api/publishing/channel-types/"+URLEncoder.encode(type.getId());
}
public static String getUrl(Channel channel)

View File

@@ -580,7 +580,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest
check(ID, jsonType, channelType.getId());
check(TITLE, jsonType, channelType.getId());
String expUrl = "api/publishing/channelTypes/"+URLEncoder.encode(channelType.getId());
String expUrl = "api/publishing/channel-types/"+URLEncoder.encode(channelType.getId());
check(URL, jsonType, expUrl);
check(CHANNEL_NODE_TYPE, jsonType, channelType.getChannelNodeType().toString());

View File

@@ -48,6 +48,7 @@ public interface PublishingWebScriptConstants
// Channel Keys
public static final String NAME = "name";
public static final String CHANNEL_TYPE = "channelType";
public static final String CHANNEL_AUTH_STATUS = "authorised";
// Publishing Event Model Keys
public static final String CHANNEL = "channel";