From e4870c0afa1f8ee850a27bbb41af41e69d0fe524 Mon Sep 17 00:00:00 2001 From: N Smith Date: Mon, 25 Jul 2011 09:30:08 +0000 Subject: [PATCH] Removed all references to Site from publishing REST API. Replaced publishing-events-query.post with publishing-events-for-node.get. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29301 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../publishing/channels.get.desc.xml | 8 +- .../publishing-events-for-node.get.desc.xml | 160 ++++++++++++++++++ ...> publishing-events-for-node.get.json.ftl} | 0 .../publishing-events-query.post.desc.xml | 100 ----------- .../publishing/publishing-queue.post.desc.xml | 10 +- .../repository/publishing/publishing.lib.ftl | 1 + .../web-scripts-application-context.xml | 6 +- .../web/scripts/publishing/ChannelsGet.java | 16 +- ...t.java => PUblishingEventsForNodeGet.java} | 33 +++- .../publishing/PublishingJsonParser.java | 23 --- .../publishing/PublishingModelBuilder.java | 22 ++- .../publishing/PublishingQueuePost.java | 8 +- .../publishing/PublishingRestApiTest.java | 152 +++++++---------- ...ebScript.java => PublishingWebScript.java} | 33 +--- .../PublishingWebScriptConstants.java | 7 +- 15 files changed, 287 insertions(+), 292 deletions(-) create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events-for-node.get.desc.xml rename config/alfresco/templates/webscripts/org/alfresco/repository/publishing/{publishing-events-query.post.json.ftl => publishing-events-for-node.get.json.ftl} (100%) delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events-query.post.desc.xml rename source/java/org/alfresco/repo/web/scripts/publishing/{PUblishingEventsQueryPost.java => PUblishingEventsForNodeGet.java} (57%) rename source/java/org/alfresco/repo/web/scripts/publishing/{PublishingEnvironmentWebScript.java => PublishingWebScript.java} (61%) 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 16a8fc30c1..3af7d551e2 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 @@ -1,17 +1,13 @@ Get Publishing Channels - Get the publishing channels for a Share Site.or specified NodeRef - /api/publishing/site/{site_id}/channels + Get the publishing channels for specified NodeRef or returns all Publishing Channels + /api/publishing/channels /api/publishing/{store_protocol}/{store_id}/{node_id}/channels user required public_api - - site_id - The id of the site to retrieve channels for. - store_protocol The protocol used by the StoreRef to retrieve channels for. diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events-for-node.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events-for-node.get.desc.xml new file mode 100644 index 0000000000..cbc1b3f13f --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events-for-node.get.desc.xml @@ -0,0 +1,160 @@ + + Get Publishing Events For Node + Find all PublishingEvents that publish or unpublish the specified node. + /api/publishing/{store_protocol}/{store_id}/{node_id}/events + + user + required + public_api + + + store_protocol + The store protocol for the published/unpublished node. + + + store_id + The store id for the published/unpublished node. + + + node_id + The node id for the published/unpublished node. + + + + + json + + + + + + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events-query.post.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events-for-node.get.json.ftl similarity index 100% rename from config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events-query.post.json.ftl rename to config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events-for-node.get.json.ftl diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events-query.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events-query.post.desc.xml deleted file mode 100644 index f1d7313fde..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/publishing/publishing-events-query.post.desc.xml +++ /dev/null @@ -1,100 +0,0 @@ - - Query Publishing Events - Queries for Publishing Events on an Environment. - /api/publishing/{site_id}/events/query - - user - required - public_api - - - site_id - The id of the site to query. - - - - - json - - - - - - - - json - - - - - - \ No newline at end of file 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 e035b309de..f6cb05f485 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 @@ -1,17 +1,11 @@ Post Content to Publishing Queue - Place a new Publishing Event on the Publishing Queue for the specified Environment. - /api/publishing/{site_id}/queue + Place a new Publishing Event on the Publishing Queue.. + /api/publishing/queue user required public_api - - - site_id - The id of the site to publish to. - - json 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 18fdf0ffb7..b614326793 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 @@ -20,6 +20,7 @@ "url": "${event.url}", "status": "${event.status}", <#if event.comment?? >"comment": "${event.comment}", + <#if event.eventType?? >"eventType": "${event.eventType}", <#if event.scheduledTime?? > "scheduledTime": <@calendarJSON calendar=event.scheduledTime />, diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index 5d0ead8c3f..f0cda6c1c9 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1146,9 +1146,9 @@ - - + diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsGet.java b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsGet.java index 8ea80f4b51..1db8d17965 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsGet.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsGet.java @@ -20,7 +20,6 @@ package org.alfresco.repo.web.scripts.publishing; import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.PUBLISHING_CHANNELS; -import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.SITE_ID; import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.STATUS_UPDATE_CHANNELS; import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.URL_LENGTH; @@ -28,8 +27,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.servlet.http.HttpServletResponse; - import org.alfresco.repo.web.scripts.WebScriptUtil; import org.alfresco.service.cmr.publishing.channels.Channel; import org.alfresco.service.cmr.publishing.channels.ChannelService; @@ -38,7 +35,6 @@ import org.alfresco.service.cmr.urlshortening.UrlShortener; 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; /** @@ -59,23 +55,17 @@ public class ChannelsGet extends DeclarativeWebScript protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) { Map params = req.getServiceMatch().getTemplateVars(); - String siteId = params.get(SITE_ID); - + NodeRef node = WebScriptUtil.getNodeRef(params); + List publishingChannels; List statusUpdateChannels; - if (siteId!= null) + if (node == null) { publishingChannels = channelService.getPublishingChannels(); statusUpdateChannels = channelService.getStatusUpdateChannels(); } else { - NodeRef node = WebScriptUtil.getNodeRef(params); - if(node == null) - { - String msg = "Either a Site ID or valid NodeRef must be specified!"; - throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg); - } publishingChannels = channelService.getRelevantPublishingChannels(node); statusUpdateChannels = channelService.getStatusUpdateChannels(); } diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/PUblishingEventsQueryPost.java b/source/java/org/alfresco/repo/web/scripts/publishing/PUblishingEventsForNodeGet.java similarity index 57% rename from source/java/org/alfresco/repo/web/scripts/publishing/PUblishingEventsQueryPost.java rename to source/java/org/alfresco/repo/web/scripts/publishing/PUblishingEventsForNodeGet.java index 905cb5ec88..f6728cc39a 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PUblishingEventsQueryPost.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PUblishingEventsForNodeGet.java @@ -19,6 +19,8 @@ package org.alfresco.repo.web.scripts.publishing; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -26,7 +28,7 @@ import javax.servlet.http.HttpServletResponse; import org.alfresco.repo.web.scripts.WebScriptUtil; import org.alfresco.service.cmr.publishing.PublishingEvent; -import org.alfresco.service.cmr.publishing.PublishingQueue; +import org.alfresco.service.cmr.repository.NodeRef; import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptException; @@ -37,7 +39,7 @@ import org.springframework.extensions.webscripts.WebScriptRequest; * @since 4.0 * */ -public class PUblishingEventsQueryPost extends PublishingEnvironmentWebScript +public class PUblishingEventsForNodeGet extends PublishingWebScript { /** * {@inheritDoc} @@ -45,20 +47,33 @@ public class PUblishingEventsQueryPost extends PublishingEnvironmentWebScript @Override protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) { - String siteId = getSiteId(req); - PublishingQueue queue = getQueue(siteId); - String content = null; + Map params = req.getServiceMatch().getTemplateVars(); + NodeRef node = WebScriptUtil.getNodeRef(params); + if(node == null) + { + String msg = "A valid NodeRef must be specified!"; + throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg); + } try { - content = WebScriptUtil.getContent(req); - List events = jsonParser.query(queue, content); - List> model = builder.buildPublishingEvents(events, channelService); + ArrayList events = getSortedPublishingEvents(node); + List> model = builder.buildPublishingEventsForNode(events, node, channelService); return WebScriptUtil.createBaseModel(model); } catch(Exception e) { - String msg = "Failed to query for publishing events. POST body: " + content; + String msg = "Failed to query for publishing events for node: " + node; throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); } } + + private ArrayList getSortedPublishingEvents(NodeRef node) + { + List publishedEvents = publishingService.getEventsForPublishedNode(node); + List unpublishedEvents = publishingService.getEventsForUnpublishedNode(node); + ArrayList allEvents = new ArrayList(publishedEvents); + allEvents.addAll(unpublishedEvents); + Collections.sort(allEvents); + return allEvents; + } } \ No newline at end of file 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 c33d2720ae..1ccc6fc13b 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingJsonParser.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingJsonParser.java @@ -23,7 +23,6 @@ import static org.alfresco.repo.web.scripts.WebScriptUtil.getCalendar; 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; import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.NODE_REF; import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.PUBLISH_NODES; @@ -40,8 +39,6 @@ import java.util.List; import org.alfresco.repo.node.NodeUtils; import org.alfresco.service.cmr.publishing.MutablePublishingPackage; -import org.alfresco.service.cmr.publishing.PublishingEvent; -import org.alfresco.service.cmr.publishing.PublishingEventFilter; import org.alfresco.service.cmr.publishing.PublishingPackage; import org.alfresco.service.cmr.publishing.PublishingQueue; import org.alfresco.service.cmr.publishing.StatusUpdate; @@ -70,26 +67,6 @@ public class PublishingJsonParser return new JSONObject(); } - public List query(PublishingQueue queue, String content) throws JSONException - { - JSONObject json = getJson(content); - PublishingEventFilter filter = buildFilter(queue, json); - return queue.getPublishingEvents(filter); - } - - private PublishingEventFilter buildFilter(PublishingQueue queue, JSONObject json) - { - List publishNodes = toNodes(json.optJSONArray(PUBLISH_NODES)); - List unpublishNodes = toNodes(json.optJSONArray(UNPUBLISH_NODES)); - List ids = JsonUtils.toListOfStrings(json.optJSONArray(IDS)); - - PublishingEventFilter filter = queue.createPublishingEventFilter() - .setIds(ids) - .setPublishedNodes(publishNodes) - .setUnpublishedNodes(unpublishNodes); - return filter; - } - public String schedulePublishingEvent(PublishingQueue queue, String jsonStr) throws ParseException, JSONException { JSONObject json = getJson(jsonStr); 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 ec00debea3..f2e5293ecc 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingModelBuilder.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingModelBuilder.java @@ -50,6 +50,26 @@ import org.springframework.extensions.surf.util.URLEncoder; */ public class PublishingModelBuilder implements PublishingWebScriptConstants { + public Map buildPublishingEventForNode(PublishingEvent event, NodeRef node, ChannelService channelService) + { + Map model = buildPublishingEvent(event, channelService); + boolean isPublish = event.getPackage().getNodesToPublish().contains(node); + String type = isPublish ? "published" : "unpublished"; + model.put(EVENT_TYPE, type); + return model; + } + + public List> buildPublishingEventsForNode(List events, + final NodeRef node, final ChannelService channelService) + { + return transform(events, new Function>() + { + public Map apply(PublishingEvent event) + { + return buildPublishingEventForNode(event, node, channelService); + } + }); + } public Map buildPublishingEvent(PublishingEvent event, ChannelService channelService) { @@ -89,7 +109,7 @@ public class PublishingModelBuilder implements PublishingWebScriptConstants } }); } - + public Map buildChannel(Channel channel) { Map model = new HashMap(); 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 84af94216f..069169fad5 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingQueuePost.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingQueuePost.java @@ -25,7 +25,6 @@ import javax.servlet.http.HttpServletResponse; import org.alfresco.repo.web.scripts.WebScriptUtil; import org.alfresco.service.cmr.publishing.PublishingEvent; -import org.alfresco.service.cmr.publishing.PublishingQueue; import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptException; @@ -36,7 +35,7 @@ import org.springframework.extensions.webscripts.WebScriptRequest; * @since 4.0 * */ -public class PublishingQueuePost extends PublishingEnvironmentWebScript +public class PublishingQueuePost extends PublishingWebScript { /** * {@inheritDoc} @@ -44,9 +43,6 @@ public class PublishingQueuePost extends PublishingEnvironmentWebScript @Override protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) { - String siteId = getSiteId(req); - PublishingQueue queue = getQueue(siteId); - String content = null; try { @@ -55,7 +51,7 @@ public class PublishingQueuePost extends PublishingEnvironmentWebScript { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "No publishing event was posted!"); } - String eventId = jsonParser.schedulePublishingEvent(queue, content); + String eventId = jsonParser.schedulePublishingEvent(getQueue(), content); PublishingEvent event = publishingService.getPublishingEvent(eventId); Map eventModel = builder.buildPublishingEvent(event, channelService); return WebScriptUtil.createBaseModel(eventModel); 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 a9a2627790..fe1c89f312 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingRestApiTest.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingRestApiTest.java @@ -64,7 +64,7 @@ import static org.mockito.Mockito.when; import java.io.File; import java.io.UnsupportedEncodingException; import java.text.MessageFormat; -import java.util.Arrays; +import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; import java.util.Collections; @@ -88,8 +88,6 @@ import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.publishing.MutablePublishingPackage; import org.alfresco.service.cmr.publishing.NodeSnapshot; import org.alfresco.service.cmr.publishing.PublishingEvent; -import org.alfresco.service.cmr.publishing.PublishingEvent.Status; -import org.alfresco.service.cmr.publishing.PublishingEventFilter; import org.alfresco.service.cmr.publishing.PublishingPackage; import org.alfresco.service.cmr.publishing.PublishingPackageEntry; import org.alfresco.service.cmr.publishing.PublishingQueue; @@ -129,12 +127,12 @@ public class PublishingRestApiTest extends BaseWebScriptTest private static final String statusUpdateType = "statusUpdateForTest"; 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_URL = "api/publishing/channels"; 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"; - + private static final String CHANNEL_TYPES_URL = "api/publishing/channel-types"; + private static final String PUBLISHING_QUEUE_URL = "api/publishing/queue"; + private static final String PUBLISHING_EVENTS_FOR_NODE_url = "api/publishing/{0}/{1}/{2}/events"; + private static final String JSON = "application/json"; private SiteService siteService; @@ -147,6 +145,9 @@ public class PublishingRestApiTest extends BaseWebScriptTest private NodeRef docLib; private String siteId; + private List events = new ArrayList(); + private List channels = new ArrayList(); + public void testGetChannelsForNode() throws Exception { NodeRef textNode = createContentNode("plainContent", "Some plain text", MimetypeMap.MIMETYPE_TEXT_PLAIN); @@ -158,22 +159,14 @@ public class PublishingRestApiTest extends BaseWebScriptTest assertEquals(MimetypeMap.MIMETYPE_PDF, fileFolderService.getReader(xmlNode).getMimetype()); String plainTextNodeUrl = MessageFormat.format(CHANNELS_NODE_URL, store.getProtocol(), store.getIdentifier(), textNode.getId() ); - Response response = sendRequest(new GetRequest(plainTextNodeUrl), 200); - - // Call with no channels defined on site. - response = sendRequest(new GetRequest(plainTextNodeUrl), 200); - JSONObject data = getJsonData(response); - - //TODO Fix hard coding. - assertEquals(20, data.getInt(URL_LENGTH)); Channel publishAnyChannel = createChannel(publishAnyType); Channel publishPdfChannel = createChannel(publishPdfType); Channel statusUpdateChannel= createChannel(statusUpdateType); // Call with channels defined. - response = sendRequest(new GetRequest(plainTextNodeUrl), 200); - data = getJsonData(response); + Response response = sendRequest(new GetRequest(plainTextNodeUrl), 200); + JSONObject data = getJsonData(response); //TODO Fix hard coding. assertEquals(20, data.getInt(URL_LENGTH)); @@ -196,33 +189,20 @@ public class PublishingRestApiTest extends BaseWebScriptTest checkChannels(statusChannels, statusUpdateChannel); } - public void testGetChannelsForSite() throws Exception + public void testGetChannels() throws Exception { - // Call with no channels defined on site. - String siteUrl = MessageFormat.format(CHANNELS_SITE_URL, siteId); - Response response = sendRequest(new GetRequest(siteUrl), 200); - JSONObject data = getJsonData(response); - - //TODO Fix hard coding. - assertEquals(20, data.getInt(URL_LENGTH)); - JSONArray publishingChannels = data.getJSONArray(PUBLISHING_CHANNELS); - int startPublishChannelsSize = publishingChannels.length(); - - JSONArray statusChannels = data.getJSONArray(STATUS_UPDATE_CHANNELS); - int startStatusChannelsSize = statusChannels.length(); - Channel publishAnyChannel = createChannel(publishAnyType); Channel publishPdfChannel = createChannel(publishPdfType); Channel statusUpdateChannel= createChannel(statusUpdateType); // Call channels defined. - response = sendRequest(new GetRequest(siteUrl), 200); - data = getJsonData(response); + Response response = sendRequest(new GetRequest(CHANNELS_URL), 200); + JSONObject data = getJsonData(response); //TODO Fix hard coding. assertEquals(20, data.getInt(URL_LENGTH)); - publishingChannels = data.getJSONArray(PUBLISHING_CHANNELS); - statusChannels = data.getJSONArray(STATUS_UPDATE_CHANNELS); + JSONArray publishingChannels = data.getJSONArray(PUBLISHING_CHANNELS); + JSONArray statusChannels = data.getJSONArray(STATUS_UPDATE_CHANNELS); checkChannels(publishingChannels, publishAnyChannel, publishPdfChannel); checkChannels(statusChannels, statusUpdateChannel); @@ -232,16 +212,14 @@ public class PublishingRestApiTest extends BaseWebScriptTest public void testPublishingQueuePost() throws Exception { // Create publish and status update channels. - Channel publishChannel = channelService.createChannel(publishAnyType, GUID.generate(), null); - Channel statusChannel = channelService.createChannel(statusUpdateType, GUID.generate(), null); + Channel publishChannel = createChannel(publishAnyType); + Channel statusChannel = createChannel(statusUpdateType); // Create some content. NodeRef textNode = createContentNode("plainContent", "Some plain text", MimetypeMap.MIMETYPE_TEXT_PLAIN); - String pubQueueUrl = MessageFormat.format(PUBLISHING_QUEUE_URL, siteId); - // Post empty content. - sendRequest(new PostRequest(pubQueueUrl, "", JSON), 400); + sendRequest(new PostRequest(PUBLISHING_QUEUE_URL, "", JSON), 400); String comment = "The comment"; String statusMessage = "The status message"; @@ -251,17 +229,16 @@ public class PublishingRestApiTest extends BaseWebScriptTest String jsonStr = json.toString(); // Post JSON content. - sendRequest(new PostRequest(pubQueueUrl, jsonStr, JSON), 200); + sendRequest(new PostRequest(PUBLISHING_QUEUE_URL, jsonStr, JSON), 200); - PublishingEventFilter filter = queue.createPublishingEventFilter(); - filter.setPublishedNodes(textNode); - List events = queue.getPublishingEvents(filter); - assertEquals(1, events.size()); + List publishedEvents = publishingService.getEventsForPublishedNode(textNode); - PublishingEvent event = events.get(0); + assertEquals(1, publishedEvents.size()); + + PublishingEvent event = publishedEvents.get(0); assertEquals(publishChannel.getId(), event.getChannelId()); assertEquals(comment, event.getComment()); - assertEquals(Status.SCHEDULED, event.getStatus()); + assertEquals(PublishingEvent.Status.SCHEDULED, event.getStatus()); // Check Package PublishingPackage pckg = event.getPackage(); @@ -305,28 +282,32 @@ public class PublishingRestApiTest extends BaseWebScriptTest jsonStr = json.toString(); // Post JSON without NodeRef in status. - sendRequest(new PostRequest(pubQueueUrl, jsonStr, JSON), 200); + sendRequest(new PostRequest(PUBLISHING_QUEUE_URL, jsonStr, JSON), 200); json.remove(STATUS_UPDATE); jsonStr = json.toString(); // Post JSON without Status Update. - sendRequest(new PostRequest(pubQueueUrl, jsonStr, JSON), 200); + sendRequest(new PostRequest(PUBLISHING_QUEUE_URL, jsonStr, JSON), 200); + + events.addAll(publishingService.getEventsForPublishedNode(textNode)); } - public void testPublishingEventsQueryPostPublishedNode() throws Exception + public void testPublishingEventsForNodeGet() throws Exception { Channel publishChannel = createChannel(publishAnyType); NodeRef textNode1 = createContentNode("plain1.txt", "This is some plain text", MimetypeMap.MIMETYPE_TEXT_PLAIN); NodeRef textNode2 = createContentNode("plain2.txt", "This is some more plain text", MimetypeMap.MIMETYPE_TEXT_PLAIN); - String queryUrl = MessageFormat.format(PUBLISHING_EVENT_QUERY_URL, siteId); + String protocol = textNode1.getStoreRef().getProtocol(); + String storeId = textNode1.getStoreRef().getIdentifier(); + String nodeId1 = textNode1.getId(); + String textNode1Url = MessageFormat.format(PUBLISHING_EVENTS_FOR_NODE_url, protocol, storeId, nodeId1); - // Post empty string with correct site name. - Response response = sendRequest(new PostRequest(queryUrl, "", JSON), 200); - + // Get events on textNode1 before any events created. + Response response = sendRequest(new GetRequest(textNode1Url), 200); JSONArray data = getDataArray(response); - int startingSize = data.length(); + assertEquals(0, data.length()); // Create publishing event for textNode1. MutablePublishingPackage pckg1 = queue.createPublishingPackage(); @@ -337,35 +318,20 @@ public class PublishingRestApiTest extends BaseWebScriptTest schedule.add(Calendar.YEAR, 1); String event1Id = queue.scheduleNewEvent(pckg1, publishChannel.getId(), schedule, comment, statusUpdate); - - // Query for all events. - response = sendRequest(new PostRequest(queryUrl, "", JSON), 200); - data = getDataArray(response); - checkContainsEvents(data, startingSize, event1Id); - - JSONObject json = new JSONObject(); - json.put(PUBLISH_NODES, Arrays.asList(textNode1.toString())); + PublishingEvent event1 = publishingService.getPublishingEvent(event1Id); + events.add(event1); // Query for events on textNode1. - response = sendRequest(new PostRequest(queryUrl, json.toString(), JSON), 200); + response = sendRequest(new GetRequest(textNode1Url), 200); data = getDataArray(response); - checkContainsEvents(data, 0, event1Id); - - json = new JSONObject(); - json.put(PUBLISH_NODES, Arrays.asList(textNode2.toString())); + checkContainsEvents(data, event1Id); // Query for events on textNode2. - response = sendRequest(new PostRequest(queryUrl, json.toString(), JSON), 200); + String nodeId2 = textNode2.getId(); + String textNode2Url = MessageFormat.format(PUBLISHING_EVENTS_FOR_NODE_url, protocol, storeId, nodeId2); + response = sendRequest(new GetRequest(textNode2Url), 200); data = getDataArray(response); assertEquals(0, data.length()); - - json = new JSONObject(); - json.put(PUBLISH_NODES, Arrays.asList(textNode1.toString(), textNode2.toString())); - - // Query for events on both textNode1 and textNode2. - response = sendRequest(new PostRequest(queryUrl, json.toString(), JSON), 200); - data = getDataArray(response); - checkContainsEvent(data, event1Id); } public void testChannelTypesGet() throws Exception @@ -399,9 +365,9 @@ public class PublishingRestApiTest extends BaseWebScriptTest fail("Failed to find Channel Type: " + typeId); } - private void checkContainsEvents(JSONArray data, int startSize, String... eventIds) throws Exception + private void checkContainsEvents(JSONArray data, String... eventIds) throws Exception { - assertEquals(eventIds.length + startSize, data.length()); + assertEquals(eventIds.length, data.length()); for (String eventId : eventIds) { checkContainsEvent(data, eventId); @@ -519,7 +485,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest return json; } - private JSONObject buildStatusUpdate(String message, NodeRef textNode, Channel... channels) throws JSONException + private JSONObject buildStatusUpdate(String message, NodeRef textNode, Channel... theChannels) throws JSONException { Function transformer = new Function() { @@ -528,7 +494,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest return channel.getId(); } }; - List ids = CollectionUtils.transform(transformer, channels); + List ids = CollectionUtils.transform(transformer, theChannels); JSONObject statusUpdate = new JSONObject(); statusUpdate.put(MESSAGE, message); @@ -537,9 +503,9 @@ public class PublishingRestApiTest extends BaseWebScriptTest return statusUpdate; } - private void checkChannels(JSONArray json, Channel... channels)throws Exception + private void checkChannels(JSONArray json, Channel... theChannels)throws Exception { - for (Channel channel : channels) + for (Channel channel : theChannels) { checkContainsChannel(json, channel); } @@ -625,7 +591,9 @@ public class PublishingRestApiTest extends BaseWebScriptTest private Channel createChannel(String typeId) { - return channelService.createChannel(typeId, GUID.generate(), null); + Channel channel = channelService.createChannel(typeId, GUID.generate(), null); + channels.add(channel); + return channel; } private JSONObject getJsonData(Response response) throws Exception @@ -737,9 +705,6 @@ public class PublishingRestApiTest extends BaseWebScriptTest @Override public void tearDown() throws Exception { - //FInd all events - PublishingEventFilter filter = queue.createPublishingEventFilter(); - List events = queue.getPublishingEvents(filter); for (PublishingEvent event : events) { try @@ -751,6 +716,17 @@ public class PublishingRestApiTest extends BaseWebScriptTest //NOOP } } + for (Channel channel : channels) + { + try + { + channelService.deleteChannel(channel); + } + catch(Throwable t) + { + //NOOP + } + } try { siteService.deleteSite(siteId); diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingEnvironmentWebScript.java b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScript.java similarity index 61% rename from source/java/org/alfresco/repo/web/scripts/publishing/PublishingEnvironmentWebScript.java rename to source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScript.java index eeaf3aaac2..3fbee83c9c 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingEnvironmentWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScript.java @@ -19,54 +19,27 @@ package org.alfresco.repo.web.scripts.publishing; -import static org.alfresco.repo.web.scripts.publishing.PublishingWebScriptConstants.SITE_ID; - -import java.util.Map; - -import javax.servlet.http.HttpServletResponse; - import org.alfresco.service.cmr.publishing.PublishingQueue; import org.alfresco.service.cmr.publishing.PublishingService; import org.alfresco.service.cmr.publishing.channels.ChannelService; import org.springframework.extensions.webscripts.DeclarativeWebScript; -import org.springframework.extensions.webscripts.WebScriptException; -import org.springframework.extensions.webscripts.WebScriptRequest; /** * @author Nick Smith * @since 4.0 * */ -public abstract class PublishingEnvironmentWebScript extends DeclarativeWebScript +public abstract class PublishingWebScript extends DeclarativeWebScript { protected final PublishingJsonParser jsonParser = new PublishingJsonParser(); protected final PublishingModelBuilder builder= new PublishingModelBuilder(); protected PublishingService publishingService; protected ChannelService channelService; - - protected String getSiteId(WebScriptRequest req) - { - Map params = req.getServiceMatch().getTemplateVars(); - String siteId = params.get(SITE_ID); - - if(siteId == null) - { - String msg = "A Site ID must be specified!"; - throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg); - } - return siteId; - } - - protected PublishingQueue getQueue(WebScriptRequest req) - { - String siteId = getSiteId(req); - return getQueue(siteId); - } - protected PublishingQueue getQueue(String siteId) + protected PublishingQueue getQueue() { - return publishingService.getPublishingQueue(siteId); + return publishingService.getPublishingQueue(); } /** 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 9c230abf86..dc374c95dc 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScriptConstants.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScriptConstants.java @@ -26,9 +26,6 @@ package org.alfresco.repo.web.scripts.publishing; */ public interface PublishingWebScriptConstants { - // URL Template Keys. - public static final String SITE_ID = "site_id"; - // General Model Keys public static final String ID = "id"; public static final String URL = "url"; @@ -70,8 +67,8 @@ public interface PublishingWebScriptConstants public static final String NODE_REF = "nodeRef"; public static final String MESSAGE = "message"; - // Publishing Event Filter Modek Keys - public static final String IDS = "ids"; + // Publishing Events For Node Modek Keys + public static final String EVENT_TYPE = "eventType"; // channels.get Model Keys public static final String URL_LENGTH = "urlLength";