From 485fc352af73adb06241d3299e8e6c17cddad123 Mon Sep 17 00:00:00 2001 From: N Smith Date: Tue, 19 Jul 2011 11:39:11 +0000 Subject: [PATCH] Removed the Environment from the publishing implementation. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29183 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../publishing/channels.get.desc.xml | 1 + .../publishing/publishing-queue.post.desc.xml | 2 +- .../repository/publishing/publishing.lib.ftl | 1 + .../publishing/PUblishingEventsQueryPost.java | 2 +- .../publishing/PublishingJsonParser.java | 10 ++--- .../publishing/PublishingModelBuilder.java | 14 +++---- .../publishing/PublishingQueuePost.java | 2 +- .../publishing/PublishingRestApiTest.java | 37 ++++++++++--------- .../PublishingWebScriptConstants.java | 3 +- 9 files changed, 39 insertions(+), 33 deletions(-) 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 index 69691f85bb..e836184c39 100644 --- 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 @@ -38,6 +38,7 @@ [ { "url": string, + "id": string, "name": string, "title": string, "channelType": diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-queue.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-queue.post.desc.xml index 3d4d4519b5..d12f466308 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-queue.post.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-queue.post.desc.xml @@ -32,7 +32,7 @@ { "message": string, "nodeRef": string, - "channelNames": [string, ... ] + "channelIds": [string, ... ] } } ]]> 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 index 910c86e077..a5213f8a42 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing.lib.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing.lib.ftl @@ -75,6 +75,7 @@ <#macro channelJSON channel> { "url": "${channel.url}", + "id": "${channel.id}", "name": "${channel.name}", "title": "${channel.title}", "channelType": diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/PUblishingEventsQueryPost.java b/source/java/org/alfresco/repo/web/scripts/publishing/PUblishingEventsQueryPost.java index 5d8f7e0099..905cb5ec88 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PUblishingEventsQueryPost.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PUblishingEventsQueryPost.java @@ -52,7 +52,7 @@ public class PUblishingEventsQueryPost extends PublishingEnvironmentWebScript { content = WebScriptUtil.getContent(req); List events = jsonParser.query(queue, content); - List> model = builder.buildPublishingEvents(events, channelService, siteId); + List> model = builder.buildPublishingEvents(events, channelService); return WebScriptUtil.createBaseModel(model); } catch(Exception e) diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingJsonParser.java b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingJsonParser.java index 45abb67b93..c33d2720ae 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingJsonParser.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingJsonParser.java @@ -20,8 +20,8 @@ package org.alfresco.repo.web.scripts.publishing; import static org.alfresco.repo.web.scripts.WebScriptUtil.getCalendar; -import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CHANNEL_NAME; -import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CHANNEL_NAMES; +import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CHANNEL_ID; +import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CHANNEL_IDS; import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.COMMENT; import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.IDS; import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.MESSAGE; @@ -93,12 +93,12 @@ public class PublishingJsonParser public String schedulePublishingEvent(PublishingQueue queue, String jsonStr) throws ParseException, JSONException { JSONObject json = getJson(jsonStr); - String channelName = json.optString(CHANNEL_NAME); + String channelId= json.optString(CHANNEL_ID); String comment = json.optString(COMMENT); Calendar schedule = getCalendar(json.optJSONObject(SCHEDULED_TIME)); PublishingPackage publishingPackage = getPublishingPackage(queue, json); StatusUpdate statusUpdate = getStatusUpdate(queue, json.optJSONObject(STATUS_UPDATE)); - return queue.scheduleNewEvent(publishingPackage, channelName, schedule, comment, statusUpdate); + return queue.scheduleNewEvent(publishingPackage, channelId, schedule, comment, statusUpdate); } public StatusUpdate getStatusUpdate(PublishingQueue queue, JSONObject json) @@ -114,7 +114,7 @@ public class PublishingJsonParser { nodeToLinkTo = new NodeRef(nodeStr); } - Collection channelNames = toStrings(json.optJSONArray(CHANNEL_NAMES)); + Collection channelNames = toStrings(json.optJSONArray(CHANNEL_IDS)); return queue.createStatusUpdate(message, nodeToLinkTo, channelNames); } 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 4ef151f9cc..9b6a1111d2 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingModelBuilder.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingModelBuilder.java @@ -74,7 +74,7 @@ import org.springframework.extensions.surf.util.URLEncoder; public class PublishingModelBuilder { - public Map buildPublishingEvent(PublishingEvent event, ChannelService channelService, String siteId) + public Map buildPublishingEvent(PublishingEvent event, ChannelService channelService) { Map model = new HashMap(); model.put(ID, event.getId()); @@ -88,28 +88,27 @@ public class PublishingModelBuilder model.put(PUBLISH_NODES, buildNodes(event.getPackage(), true)); model.put(UNPUBLISH_NODES, buildNodes(event.getPackage(), false)); - String channelName = event.getChannelName(); - Channel channel = channelService.getChannel(siteId, channelName); + String channelId = event.getChannelId(); + Channel channel = channelService.getChannel(channelId); if(channel!= null) { model.put(CHANNEL, buildChannel(channel)); } else { - model.put(CHANNEL_TYPE, channelName); + model.put(CHANNEL_TYPE, channelId); } return model; } public List> buildPublishingEvents(List events, - final ChannelService channelService, - final String siteId) + final ChannelService channelService) { return transform(events, new Function>() { public Map apply(PublishingEvent event) { - return buildPublishingEvent(event, channelService, siteId); + return buildPublishingEvent(event, channelService); } }); } @@ -118,6 +117,7 @@ public class PublishingModelBuilder { Map model = new HashMap(); model.put(URL, getUrl(channel)); + model.put(ID, channel.getId()); model.put(NAME, channel.getName()); //TODO Localize the title. model.put(TITLE, channel.getName()); diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingQueuePost.java b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingQueuePost.java index b6e19b04f3..84af94216f 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingQueuePost.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingQueuePost.java @@ -57,7 +57,7 @@ public class PublishingQueuePost extends PublishingEnvironmentWebScript } String eventId = jsonParser.schedulePublishingEvent(queue, content); PublishingEvent event = publishingService.getPublishingEvent(eventId); - Map eventModel = builder.buildPublishingEvent(event, channelService, siteId); + Map eventModel = builder.buildPublishingEvent(event, channelService); return WebScriptUtil.createBaseModel(eventModel); } catch(WebScriptException we) 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 e988f7185d..2c6e041ffe 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingRestApiTest.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingRestApiTest.java @@ -25,8 +25,8 @@ import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConsta 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_NAME; -import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CHANNEL_NAMES; +import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CHANNEL_ID; +import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.CHANNEL_IDS; 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; @@ -64,7 +64,6 @@ import static org.mockito.Mockito.when; import java.io.File; import java.io.UnsupportedEncodingException; import java.text.MessageFormat; -import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Collection; @@ -108,6 +107,7 @@ import org.alfresco.service.cmr.site.SiteVisibility; import org.alfresco.util.GUID; import org.alfresco.util.ISO8601DateFormat; import org.alfresco.util.collections.CollectionUtils; +import org.alfresco.util.collections.Function; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -265,7 +265,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest List events = queue.getPublishingEvents(filter); assertEquals(1, events.size()); PublishingEvent event = events.get(0); - assertEquals(publishChannel.getName(), event.getChannelName()); + assertEquals(publishChannel.getId(), event.getChannelId()); assertEquals(comment, event.getComment()); assertEquals(Status.SCHEDULED, event.getStatus()); @@ -280,9 +280,9 @@ public class PublishingRestApiTest extends BaseWebScriptTest StatusUpdate statusUpdate = event.getStatusUpdate(); assertEquals(statusMessage, statusUpdate.getMessage()); assertEquals(textNode, statusUpdate.getNodeToLinkTo()); - Set channelNames = statusUpdate.getChannelNames(); - assertEquals(1, channelNames.size()); - assertTrue(channelNames.contains(statusChannel.getName())); + Set channelIds = statusUpdate.getChannelIds(); + assertEquals(1, channelIds.size()); + assertTrue(channelIds.contains(statusChannel.getId())); // Wait for Publishing Event to execute asynchronously Thread.sleep(3000); @@ -290,8 +290,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest ChannelType publishAnyChannelType = channelService.getChannelType(publishAnyType); ChannelType statusUpdateChannelType = channelService.getChannelType(statusUpdateType); - NodeRef environmentNode = new NodeRef(environment.getId()); - NodeRef mappedTextNode = channelHelper.mapSourceToEnvironment(textNode, environmentNode, publishChannel.getName()); + NodeRef mappedTextNode = channelHelper.mapSourceToEnvironment(textNode, publishChannel.getNodeRef()); // Check publish is called. verify(publishAnyChannelType) @@ -349,7 +348,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest Calendar schedule = Calendar.getInstance(); schedule.add(Calendar.YEAR, 1); - String event1Id = queue.scheduleNewEvent(pckg1, publishChannel.getName(), schedule, comment, statusUpdate); + String event1Id = queue.scheduleNewEvent(pckg1, publishChannel.getId(), schedule, comment, statusUpdate); // Query for all events. response = sendRequest(new PostRequest(queryUrl, "", JSON), 200); @@ -452,7 +451,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest checkContainsNodes(pckg, json.getJSONArray(PUBLISH_NODES), true); checkContainsNodes(pckg, json.getJSONArray(UNPUBLISH_NODES), false); - Channel channel = channelService.getChannel(siteId, event.getChannelName()); + Channel channel = channelService.getChannel(event.getChannelId()); checkChannel(json.optJSONObject(CHANNEL), channel); } @@ -521,7 +520,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest Channel... statusChannels) throws JSONException { JSONObject json = new JSONObject(); - json.put(CHANNEL_NAME, publishChannel.getName()); + json.put(CHANNEL_ID, publishChannel.getId()); json.put(COMMENT, comment); Calendar schedule = Calendar.getInstance(); schedule.add(Calendar.SECOND, 1); @@ -534,15 +533,19 @@ public class PublishingRestApiTest extends BaseWebScriptTest private JSONObject buildStatusUpdate(String message, NodeRef textNode, Channel... channels) throws JSONException { - ArrayList channelNames = new ArrayList(channels.length); - for (Channel channel : channels) + Function transformer = new Function() { - channelNames.add(channel.getName()); - } + public String apply(Channel channel) + { + return channel.getId(); + } + }; + List ids = CollectionUtils.transform(transformer, channels); + JSONObject statusUpdate = new JSONObject(); statusUpdate.put(MESSAGE, message); statusUpdate.put(NODE_REF, textNode.toString()); - statusUpdate.put(CHANNEL_NAMES, channelNames); + statusUpdate.put(CHANNEL_IDS, ids); return statusUpdate; } diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScriptConstants.java b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScriptConstants.java index 1e25c5b495..a84c046f26 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScriptConstants.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScriptConstants.java @@ -62,9 +62,10 @@ public interface PublishingWebScriptConstants public static final String VERSION = "version"; public static final String STATUS_UPDATE = "statusUpdate"; public static final String CHANNEL_NAME = "channelName"; + public static final String CHANNEL_ID = "channelId"; // Status Update Model Keys - public static final String CHANNEL_NAMES = "channelNames"; + public static final String CHANNEL_IDS = "channelIds"; public static final String NODE_REF = "nodeRef"; public static final String MESSAGE = "message";