diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.get.desc.xml new file mode 100644 index 0000000000..652fc5e82d --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.get.desc.xml @@ -0,0 +1,48 @@ + + Get Publishing Channels + Get the publishing channels for a Share Site. + /api/publishing/site/{site_id}/channels + + user + required + public_api + + + site_id + The id of the site to retrieve channels for. + + + + + json + + + + + + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.get.json.ftl new file mode 100644 index 0000000000..f62df898ae --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/channels.get.json.ftl @@ -0,0 +1,11 @@ +<#-- List Channels --> +<#import "publishing.lib.ftl" as publishLib /> +{ + "data": + [ + <#list data as channel> + <@publishLib.channelJSON channel=channel /> + <#if channel_has_next>, + + ] +} diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing.lib.ftl new file mode 100644 index 0000000000..b30875664c --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing.lib.ftl @@ -0,0 +1,42 @@ +<#-- Renders a Channel. --> +<#macro channelJSON channel> +<#escape x as jsonUtils.encodeJSONString(x)> + { + "url": "${channel.url}", + "name": "${channel.name}", + "channelType": + <@channelTypeJSON type=channel.channelType /> + } + + + +<#-- Renders a Channel Type. --> +<#macro channelTypeJSON type> +<#escape x as jsonUtils.encodeJSONString(x)> + { + "id": "${type.id}", + "url": "${type.url}", + "channelNodeType": "${type.channelNodeType}", + "contentRootNodeType": "${type.contentRootNodeType}", + "supportedContentTypes": + <@iterateStringsJSON strings=type.supportedContentTypes />, + "supportedMimeTypes": + <@iterateStringsJSON strings=type.supportedMimeTypes/>, + "canPublish": "${type.canPublish}", + "canPublishStatusUpdates": "${type.canPublishStatusUpdates}", + "canUnpublish": "${type.canUnpublish}" + } + + + +<#-- Renders a List of Strings. --> +<#macro iterateStringsJSON strings> +<#escape x as jsonUtils.encodeJSONString(x)> + [ + <#list strings as string> + "${string}" + <#if string_has_next>, + + ] + + diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/AbstractPublishingWebscript.java b/source/java/org/alfresco/repo/web/scripts/publishing/AbstractPublishingWebscript.java new file mode 100644 index 0000000000..0b6637d6e1 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/publishing/AbstractPublishingWebscript.java @@ -0,0 +1,30 @@ +/* + * 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 . + */ + +package org.alfresco.repo.web.scripts.publishing; + +/** + * @author Nick Smith + * @since 4.0 + * + */ +public class AbstractPublishingWebscript +{ + +} diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsGet.java b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsGet.java new file mode 100644 index 0000000000..13cd86c795 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsGet.java @@ -0,0 +1,95 @@ +/* + * 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 . + */ + +package org.alfresco.repo.web.scripts.publishing; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletResponse; + +import org.alfresco.service.cmr.publishing.channels.Channel; +import org.alfresco.service.cmr.publishing.channels.ChannelService; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.DeclarativeWebScript; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptException; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * @author Nick Smith + * @since 4.0 + * + */ +public class ChannelsGet extends DeclarativeWebScript +{ + public static final String DATA_KEY = "data"; + public static final String SITE_ID = "site_id"; + + private ChannelService channelService; + + /** + * {@inheritDoc} + */ + @Override + protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) + { + + PublishingModelBuilder builder = new PublishingModelBuilder(); + return buildModel(builder, req, status, cache); + } + + private Map buildModel(PublishingModelBuilder builder, + WebScriptRequest req, Status status, Cache cache) + { + Map params = req.getServiceMatch().getTemplateVars(); + String siteId = params.get(SITE_ID); + if (siteId== null) + { + throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "A Site ID must be specified!"); + } + + List channels = channelService.getChannels(siteId); + List> results = builder.buildChannels(channels); + return createBaseModel(results); + } + + protected Map createBaseModel(Map result) + { + Map model = new HashMap(); + model.put(DATA_KEY, result); + return model; + } + + protected Map createBaseModel(List> results) + { + Map model = new HashMap(); + model.put(DATA_KEY, results); + return model; + } + + /** + * @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 new file mode 100644 index 0000000000..95b4e4d5c7 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingModelBuilder.java @@ -0,0 +1,120 @@ +/* + * 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 . + */ + +package org.alfresco.repo.web.scripts.publishing; + +import static org.alfresco.util.collections.CollectionUtils.*; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.service.cmr.publishing.channels.Channel; +import org.alfresco.service.cmr.publishing.channels.ChannelType; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.util.collections.Function; +import org.springframework.extensions.surf.util.URLEncoder; + +/** + * @author Nick Smith + * @since 4.0 + * + */ +public class PublishingModelBuilder +{ + // General Keys + public static final String ID = "id"; + public static final String URL = "url"; + + // Channel Type Keys + public static final String CHANNEL_NODE_TYP = "channelNodeType"; + public static final String CONTENT_ROOT_NODE_TYP = "contentRootNodeType"; + public static final String SUPPORTED_CONTENT_TYPES = "supportedContentTypes"; + public static final String SUPPORTED_MIME_TYPES = "supportedMimeTypes"; + public static final String CAN_PUBLISH = "canPublish"; + public static final String CAN_PUBLISH_STATUS_UPDATES = "canPublishStatusUpdates"; + public static final String CAN_UNPUBLISH = "canUnpublish"; + + // Channel Keys + public static final String CHANNEL_TYPE = "channelType"; + public static final String NAME = "name"; + + public Map buildChannel(Channel channel) + { + Map model = new HashMap(); + + model.put(NAME, channel.getName()); + model.put(URL, getUrl(channel)); + model.put(CHANNEL_TYPE, buildChannelType(channel.getChannelType())); + + return model; + } + + public List> buildChannels(List channels) + { + return transform(channels, new Function>() + { + public Map apply(Channel value) + { + return buildChannel(value); + } + }); + } + + public Map buildChannelType(ChannelType type) + { + Map model = new HashMap(); + model.put(ID, type.getId()); + model.put(URL, getUrl(type)); + + model.put(CHANNEL_NODE_TYP, type.getChannelNodeType().toString()); + model.put(CONTENT_ROOT_NODE_TYP, type.getContentRootNodeType().toString()); + model.put(SUPPORTED_CONTENT_TYPES, toListOfStrings(type.getSupportedContentTypes())); + model.put(SUPPORTED_MIME_TYPES, type.getSupportedMimetypes()); + model.put(CAN_PUBLISH, toString(type.canPublish())); + model.put(CAN_PUBLISH_STATUS_UPDATES, toString(type.canPublishStatusUpdates())); + model.put(CAN_UNPUBLISH, toString(type.canUnpublish())); + + return model; + } + + public static String getUrl(ChannelType type) + { + return "api/publishing/channelTypes/"+URLEncoder.encode(type.getId()); + } + + public static String getUrl(Channel channel) + { + NodeRef node = channel.getNodeRef(); + StoreRef storeRef = node.getStoreRef(); + + StringBuilder sb = new StringBuilder("api/publishing/channels/"); + sb.append(storeRef.getProtocol()).append("/") + .append(storeRef.getIdentifier()).append("/") + .append(node.getId()); + return sb.toString(); + } + + private String toString(boolean b) + { + return Boolean.toString(b); + } + +}