diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-types.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-types.get.desc.xml new file mode 100644 index 0000000000..91adb66204 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-types.get.desc.xml @@ -0,0 +1,40 @@ + + Get Publishing Channels + Get the publishing channels for a Share Site.or specified NodeRef + /api/publishing/channel-types + + user + required + public_api + + + json + + + + + + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-types.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-types.get.json.ftl new file mode 100644 index 0000000000..87d85a360c --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channel-types.get.json.ftl @@ -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>, + + + ] +} diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index f539b3f1e3..d57e1d3207 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1109,6 +1109,13 @@ + + + + + . + */ + +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 executeImpl(WebScriptRequest req, Status status, Cache cache) + { + List types = channelService.getChannelTypes(); + List> channelTypesModel = builder.buildChannelTypes(types); + return WebScriptUtil.createBaseModel(channelTypesModel); + } + + /** + * @param channelService the channelService to set + */ + public void setChannelService(ChannelService channelService) + { + this.channelService = channelService; + } +} diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingModelBuilder.java b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingModelBuilder.java index a148f977a1..4ef151f9cc 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingModelBuilder.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingModelBuilder.java @@ -157,6 +157,17 @@ public class PublishingModelBuilder return model; } + public List> buildChannelTypes(List types) + { + return transform(types, new Function>() + { + public Map 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); } diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingRestApiTest.java b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingRestApiTest.java index a2d9cc15f8..c55e9a0b15 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingRestApiTest.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingRestApiTest.java @@ -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 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());