mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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
This commit is contained in:
@@ -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<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
Map<String, String> params = req.getServiceMatch().getTemplateVars();
|
||||
String siteId = params.get(SITE_ID);
|
||||
|
||||
NodeRef node = WebScriptUtil.getNodeRef(params);
|
||||
|
||||
List<Channel> publishingChannels;
|
||||
List<Channel> 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();
|
||||
}
|
||||
|
@@ -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<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
String siteId = getSiteId(req);
|
||||
PublishingQueue queue = getQueue(siteId);
|
||||
String content = null;
|
||||
Map<String, String> 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<PublishingEvent> events = jsonParser.query(queue, content);
|
||||
List<Map<String, Object>> model = builder.buildPublishingEvents(events, channelService);
|
||||
ArrayList<PublishingEvent> events = getSortedPublishingEvents(node);
|
||||
List<Map<String, Object>> 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<PublishingEvent> getSortedPublishingEvents(NodeRef node)
|
||||
{
|
||||
List<PublishingEvent> publishedEvents = publishingService.getEventsForPublishedNode(node);
|
||||
List<PublishingEvent> unpublishedEvents = publishingService.getEventsForUnpublishedNode(node);
|
||||
ArrayList<PublishingEvent> allEvents = new ArrayList<PublishingEvent>(publishedEvents);
|
||||
allEvents.addAll(unpublishedEvents);
|
||||
Collections.sort(allEvents);
|
||||
return allEvents;
|
||||
}
|
||||
}
|
@@ -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<PublishingEvent> 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<NodeRef> publishNodes = toNodes(json.optJSONArray(PUBLISH_NODES));
|
||||
List<NodeRef> unpublishNodes = toNodes(json.optJSONArray(UNPUBLISH_NODES));
|
||||
List<String> 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);
|
||||
|
@@ -50,6 +50,26 @@ import org.springframework.extensions.surf.util.URLEncoder;
|
||||
*/
|
||||
public class PublishingModelBuilder implements PublishingWebScriptConstants
|
||||
{
|
||||
public Map<String, Object> buildPublishingEventForNode(PublishingEvent event, NodeRef node, ChannelService channelService)
|
||||
{
|
||||
Map<String, Object> 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<Map<String, Object>> buildPublishingEventsForNode(List<PublishingEvent> events,
|
||||
final NodeRef node, final ChannelService channelService)
|
||||
{
|
||||
return transform(events, new Function<PublishingEvent, Map<String, Object>>()
|
||||
{
|
||||
public Map<String, Object> apply(PublishingEvent event)
|
||||
{
|
||||
return buildPublishingEventForNode(event, node, channelService);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Map<String, Object> buildPublishingEvent(PublishingEvent event, ChannelService channelService)
|
||||
{
|
||||
@@ -89,7 +109,7 @@ public class PublishingModelBuilder implements PublishingWebScriptConstants
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Object> buildChannel(Channel channel)
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
|
@@ -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<String, Object> 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<String, Object> eventModel = builder.buildPublishingEvent(event, channelService);
|
||||
return WebScriptUtil.createBaseModel(eventModel);
|
||||
|
@@ -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<PublishingEvent> events = new ArrayList<PublishingEvent>();
|
||||
private List<Channel> channels = new ArrayList<Channel>();
|
||||
|
||||
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<PublishingEvent> events = queue.getPublishingEvents(filter);
|
||||
assertEquals(1, events.size());
|
||||
List<PublishingEvent> 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<Channel, String> transformer = new Function<Channel, String>()
|
||||
{
|
||||
@@ -528,7 +494,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest
|
||||
return channel.getId();
|
||||
}
|
||||
};
|
||||
List<String> ids = CollectionUtils.transform(transformer, channels);
|
||||
List<String> 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<PublishingEvent> 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);
|
||||
|
@@ -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<String, String> 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();
|
||||
}
|
||||
|
||||
/**
|
@@ -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";
|
||||
|
Reference in New Issue
Block a user