mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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:
@@ -4,8 +4,8 @@
|
||||
Used to receive authorisation callbacks from publishing service providers
|
||||
]]></description>
|
||||
<description></description>
|
||||
<url>/api/publishing/channel/{store_protocol}/{store_id}/{node_id}/authcallback</url>
|
||||
<format default="json"/>
|
||||
<url>/api/publishing/channels/{store_protocol}/{store_id}/{node_id}/authcallback</url>
|
||||
<format default="html"/>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
<lifecycle>public_api</lifecycle>
|
||||
|
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
AuthStatus == ${authStatus}
|
||||
</body>
|
||||
</html>
|
@@ -3,7 +3,7 @@
|
||||
<description><![CDATA[
|
||||
Used to obtain a form to provide credentials to publish to a channel.
|
||||
]]></description>
|
||||
<url>/api/publishing/channel/{store_protocol}/{store_id}/{node_id}/authform</url>
|
||||
<url>/api/publishing/channels/{store_protocol}/{store_id}/{node_id}/authform</url>
|
||||
<format default="html"/>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
|
@@ -1,10 +1,12 @@
|
||||
<webscript>
|
||||
<shortname>Channel Authorisation Form</shortname>
|
||||
<description><![CDATA[
|
||||
Used to post back credentials to publish to a channel.
|
||||
Used to post back credentials to publish to a channel. Returns a JSON object with one text property: "authStatus".
|
||||
This property has one of three values: "AUTHORISED", "RETRY", or "UNAUTHORISED". The RETRY status indicates that
|
||||
the last authorisation attempt failed, but the user may retry at least once more.
|
||||
]]></description>
|
||||
<url>/api/publishing/channel/{store_protocol}/{store_id}/{node_id}/authform</url>
|
||||
<format default="html"/>
|
||||
<url>/api/publishing/channels/{store_protocol}/{store_id}/{node_id}/authform</url>
|
||||
<format default="json"/>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
<lifecycle>public_api</lifecycle>
|
||||
@@ -22,4 +24,16 @@
|
||||
<description>The identifier of the node that represents the relevant publishing channel.</description>
|
||||
</arg>
|
||||
</args>
|
||||
<responses>
|
||||
<response>
|
||||
<format>json</format>
|
||||
<type>
|
||||
<![CDATA[
|
||||
{
|
||||
"authStatus": string
|
||||
}
|
||||
]]>
|
||||
</type>
|
||||
</response>
|
||||
</responses>
|
||||
</webscript>
|
@@ -0,0 +1,6 @@
|
||||
<#-- Response to a request to create a publishing channel -->
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
{
|
||||
"authStatus" : "${authStatus}",
|
||||
}
|
||||
</#escape>
|
@@ -1,48 +0,0 @@
|
||||
<webscript>
|
||||
<shortname>Authorisation status check for a new publishing channel</shortname>
|
||||
<description><![CDATA[
|
||||
Used to check whether a specified publishing channel has been authorised by the target
|
||||
service provider. The returned "authStatus" value is one of:
|
||||
<ul>
|
||||
<li>PENDING - we haven't finished the necessary exchanges with the service provider yet.</li>
|
||||
<li>REJECTED - our request to authorise the channel has been rejected. The channel creation has failed.</li>
|
||||
<li>AUTHORISED - the channel has been authorised and is now ready to be used.</li>
|
||||
</ul>
|
||||
]]></description>
|
||||
<description></description>
|
||||
<url>/api/publishing/channel/{store_protocol}/{store_id}/{node_id}/authstatus</url>
|
||||
<format default="json"/>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
<lifecycle>public_api</lifecycle>
|
||||
<args>
|
||||
<arg>
|
||||
<shortname>store_protocol</shortname>
|
||||
<description>The protocol of the store in which the relevant publishing channel lives.</description>
|
||||
</arg>
|
||||
<arg>
|
||||
<shortname>store_id</shortname>
|
||||
<description>The identifier of the store in which the relevant publishing channel lives.</description>
|
||||
</arg>
|
||||
<arg>
|
||||
<shortname>node_id</shortname>
|
||||
<description>The identifier of the node that represents the relevant publishing channel.</description>
|
||||
</arg>
|
||||
</args>
|
||||
<responses>
|
||||
<response>
|
||||
<format>json</format>
|
||||
<type>
|
||||
<![CDATA[
|
||||
{
|
||||
"data":
|
||||
{
|
||||
"channelId": string,
|
||||
"authStatus": string
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</type>
|
||||
</response>
|
||||
</responses>
|
||||
</webscript>
|
@@ -1,10 +0,0 @@
|
||||
<#-- Response to a request to check the authorisation status of a publishing channel -->
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
{
|
||||
"data":
|
||||
{
|
||||
"channelId" : "${channelId}",
|
||||
"authStatus": "${authStatus}",
|
||||
}
|
||||
}
|
||||
</#escape>
|
@@ -11,7 +11,7 @@
|
||||
are missing then a 400 status code is returned.
|
||||
]]></description>
|
||||
<description></description>
|
||||
<url>/api/publishing/channel-type/{channelType}/icon/{iconSize}</url>
|
||||
<url>/api/publishing/channel-types/{channelType}/icon/{iconSize}</url>
|
||||
<format default="json"/>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
|
@@ -0,0 +1,34 @@
|
||||
<webscript>
|
||||
<shortname>Delete specified publishing channel</shortname>
|
||||
<description><![CDATA[
|
||||
Request the deletion of the publishing channel specified on the URL.
|
||||
<br />
|
||||
Response status indicates result:
|
||||
<dl>
|
||||
<dt>200</dt><dd>deletion successful</dd>
|
||||
<dt>400</dt><dd>invalid data received from caller</dd>
|
||||
<dt>401</dt><dd>user doesn't have permission to delete the specified channel</dd>
|
||||
<dt>404</dt><dd>the specified channel cannot be found</dd>
|
||||
</dl>
|
||||
|
||||
]]></description>
|
||||
<url>/api/publishing/channels/{store_protocol}/{store_id}/{node_id}</url>
|
||||
<format default="json"/>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
<lifecycle>public_api</lifecycle>
|
||||
<args>
|
||||
<arg>
|
||||
<shortname>store_protocol</shortname>
|
||||
<description>The protocol of the store in which the relevant publishing channel lives.</description>
|
||||
</arg>
|
||||
<arg>
|
||||
<shortname>store_id</shortname>
|
||||
<description>The identifier of the store in which the relevant publishing channel lives.</description>
|
||||
</arg>
|
||||
<arg>
|
||||
<shortname>node_id</shortname>
|
||||
<description>The identifier of the node that represents the relevant publishing channel.</description>
|
||||
</arg>
|
||||
</args>
|
||||
</webscript>
|
@@ -41,6 +41,7 @@
|
||||
"id": string,
|
||||
"name": string,
|
||||
"title": string,
|
||||
"authorised": boolean,
|
||||
"channelType":
|
||||
{
|
||||
"id": string,
|
||||
|
@@ -4,7 +4,6 @@
|
||||
"data":
|
||||
{
|
||||
"channelId" : "${channelId}",
|
||||
"pollUrl": "${pollUrl}",
|
||||
"authoriseUrl": "${authoriseUrl}",
|
||||
"authCallbackUrl": "${authCallbackUrl}"
|
||||
}
|
||||
|
@@ -78,6 +78,7 @@
|
||||
"id": "${channel.id}",
|
||||
"name": "${channel.name}",
|
||||
"title": "${channel.title}",
|
||||
"authorised": "${channel.authorised}",
|
||||
"channelType":
|
||||
<@channelTypeJSON type=channel.channelType />
|
||||
}
|
||||
|
@@ -1130,25 +1130,18 @@
|
||||
class="org.alfresco.repo.web.scripts.publishing.ChannelsPostWebScript"
|
||||
parent="webscript">
|
||||
<property name="channelService" ref="channelService" />
|
||||
<property name="sysAdminParams" ref="sysAdminParams" />
|
||||
</bean>
|
||||
|
||||
<bean id="webscript.org.alfresco.repository.publishing.authcallback.get"
|
||||
class="org.alfresco.repo.web.scripts.publishing.AuthCallbackWebScript"
|
||||
parent="webscript">
|
||||
<property name="nodeService" ref="NodeService" />
|
||||
<property name="channelService" ref="channelService" />
|
||||
</bean>
|
||||
|
||||
<bean id="webscript.org.alfresco.repository.publishing.authstatus.get"
|
||||
class="org.alfresco.repo.web.scripts.publishing.AuthStatusGetWebScript"
|
||||
parent="webscript">
|
||||
<property name="nodeService" ref="NodeService" />
|
||||
</bean>
|
||||
|
||||
<bean id="webscript.org.alfresco.repository.publishing.authform.post"
|
||||
class="org.alfresco.repo.web.scripts.publishing.AuthCallbackWebScript"
|
||||
parent="webscript">
|
||||
<property name="nodeService" ref="NodeService" />
|
||||
<property name="channelService" ref="channelService" />
|
||||
</bean>
|
||||
|
||||
@@ -1168,6 +1161,12 @@
|
||||
<property name="mimetypeService" ref="mimetypeService" />
|
||||
</bean>
|
||||
|
||||
<bean id="webscript.org.alfresco.repository.publishing.channels.delete"
|
||||
class="org.alfresco.repo.web.scripts.publishing.ChannelsDeleteWebScript"
|
||||
parent="webscript">
|
||||
<property name="channelService" ref="channelService" />
|
||||
</bean>
|
||||
|
||||
<!-- -->
|
||||
<!-- Audit Service REST API -->
|
||||
<!-- -->
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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
|
||||
|
@@ -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";
|
||||
res.setStatus(Status.STATUS_BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
authStatus = "PENDING";
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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;
|
||||
|
@@ -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)
|
||||
|
@@ -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());
|
||||
|
||||
|
@@ -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";
|
||||
|
Reference in New Issue
Block a user