mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Added channel-types.get REST method. Also made the versioning work when publishing nodes.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28923 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<webscript>
|
||||
<shortname>Get Publishing Channels</shortname>
|
||||
<description>Get the publishing channels for a Share Site.or specified NodeRef</description>
|
||||
<url>/api/publishing/channel-types</url>
|
||||
<format default="json"/>
|
||||
<authentication>user</authentication>
|
||||
<transaction allow="readonly">required</transaction>
|
||||
<lifecycle>public_api</lifecycle>
|
||||
<responses>
|
||||
<response>
|
||||
<format>json</format>
|
||||
<type>
|
||||
<![CDATA[
|
||||
{
|
||||
"data":
|
||||
{
|
||||
[
|
||||
{
|
||||
"id": string,
|
||||
"title": string,
|
||||
"url": string,
|
||||
"channelNodeType": string,
|
||||
"contentRootNodeType": string,
|
||||
"supportedContentTypes": [string, ...],
|
||||
"supportedMimeTypes": [string, ...],
|
||||
"canPublish": boolean,
|
||||
"canPublishStatusUpdates": boolean,
|
||||
"canUnpublish": boolean,
|
||||
"maxStatusLength": number,
|
||||
"icon": string
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</type>
|
||||
</response>
|
||||
</responses>
|
||||
</webscript>
|
@@ -0,0 +1,13 @@
|
||||
<#-- List Channels -->
|
||||
<#import "publishing.lib.ftl" as publishLib />
|
||||
{
|
||||
"data":
|
||||
[
|
||||
<#if data??>
|
||||
<#list data as type>
|
||||
<@publishLib.channelTypeJSON type=type/>
|
||||
<#if type_has_next>,</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
]
|
||||
}
|
@@ -1109,6 +1109,13 @@
|
||||
<property name="channelService" ref="channelService" />
|
||||
</bean>
|
||||
|
||||
<!-- Get Channel Types web script -->
|
||||
<bean id="webscript.org.alfresco.repository.publishing.channel-types.get"
|
||||
class="org.alfresco.repo.web.scripts.publishing.ChannelTypesGet"
|
||||
parent="webscript">
|
||||
<property name="channelService" ref="channelService" />
|
||||
</bean>
|
||||
|
||||
<!-- Post Event to a Publishing Queue web script -->
|
||||
<bean id="webscript.org.alfresco.repository.publishing.publishing-queue.post"
|
||||
class="org.alfresco.repo.web.scripts.publishing.PublishingQueuePost"
|
||||
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.web.scripts.WebScriptUtil;
|
||||
import org.alfresco.service.cmr.publishing.channels.ChannelService;
|
||||
import org.alfresco.service.cmr.publishing.channels.ChannelType;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
* @since 4.0
|
||||
*
|
||||
*/
|
||||
public class ChannelTypesGet extends DeclarativeWebScript
|
||||
{
|
||||
private final PublishingModelBuilder builder = new PublishingModelBuilder();
|
||||
private ChannelService channelService;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
List<ChannelType> types = channelService.getChannelTypes();
|
||||
List<Map<String, Object>> channelTypesModel = builder.buildChannelTypes(types);
|
||||
return WebScriptUtil.createBaseModel(channelTypesModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param channelService the channelService to set
|
||||
*/
|
||||
public void setChannelService(ChannelService channelService)
|
||||
{
|
||||
this.channelService = channelService;
|
||||
}
|
||||
}
|
@@ -157,6 +157,17 @@ public class PublishingModelBuilder
|
||||
return model;
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> buildChannelTypes(List<ChannelType> types)
|
||||
{
|
||||
return transform(types, new Function<ChannelType, Map<String, Object>>()
|
||||
{
|
||||
public Map<String, Object> apply(ChannelType value)
|
||||
{
|
||||
return buildChannelType(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static String getUrl(PublishingEvent event)
|
||||
{
|
||||
return "api/publishing/events/"+URLEncoder.encode(event.getId());
|
||||
@@ -209,7 +220,7 @@ public class PublishingModelBuilder
|
||||
NodeSnapshot snapshot = entry.getSnapshot();
|
||||
model.put(NODEREF, snapshot.getNodeRef().toString());
|
||||
String version = snapshot.getVersion();
|
||||
if(version!=null && version.isEmpty())
|
||||
if(version!=null && version.isEmpty()==false)
|
||||
{
|
||||
model.put(VERSION, version);
|
||||
}
|
||||
|
@@ -132,6 +132,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest
|
||||
private static final int maxStatusLength = 100;
|
||||
|
||||
private static final String CHANNELS_SITE_URL = "api/publishing/site/{0}/channels";
|
||||
private static final String CHANNEL_TYPES_URL = "api/publishing/channel-types";
|
||||
private static final String CHANNELS_NODE_URL = "api/publishing/{0}/{1}/{2}/channels";
|
||||
private static final String PUBLISHING_QUEUE_URL = "api/publishing/{0}/queue";
|
||||
private static final String PUBLISHING_EVENT_QUERY_URL = "api/publishing/{0}/events/query";
|
||||
@@ -381,6 +382,37 @@ public class PublishingRestApiTest extends BaseWebScriptTest
|
||||
checkContainsEvent(data, event1Id);
|
||||
}
|
||||
|
||||
public void testChannelTypesGet() throws Exception
|
||||
{
|
||||
Response response = sendRequest(new GetRequest(CHANNEL_TYPES_URL), 200);
|
||||
JSONArray data = getDataArray(response);
|
||||
checkChannelTypes(data, channelService.getChannelTypes());
|
||||
}
|
||||
|
||||
private void checkChannelTypes(JSONArray data, List<ChannelType> channelTypes) throws Exception
|
||||
{
|
||||
assertEquals(channelTypes.size(), data.length());
|
||||
for (ChannelType type : channelTypes)
|
||||
{
|
||||
checkContainsChannelType(data, type);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkContainsChannelType(JSONArray data, ChannelType type) throws Exception
|
||||
{
|
||||
String typeId = type.getId();
|
||||
for (int i = 0; i < data.length(); i++)
|
||||
{
|
||||
JSONObject json = data.optJSONObject(i);
|
||||
if(typeId.equals(json.optString(ID)))
|
||||
{
|
||||
checkChannelType(json, type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
fail("Failed to find Channel Type: " + typeId);
|
||||
}
|
||||
|
||||
private void checkContainsEvents(JSONArray data, String... eventIds) throws Exception
|
||||
{
|
||||
assertEquals(eventIds.length, data.length());
|
||||
|
Reference in New Issue
Block a user