mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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
This commit is contained in:
@@ -52,7 +52,7 @@ public class PUblishingEventsQueryPost extends PublishingEnvironmentWebScript
|
||||
{
|
||||
content = WebScriptUtil.getContent(req);
|
||||
List<PublishingEvent> events = jsonParser.query(queue, content);
|
||||
List<Map<String, Object>> model = builder.buildPublishingEvents(events, channelService, siteId);
|
||||
List<Map<String, Object>> model = builder.buildPublishingEvents(events, channelService);
|
||||
return WebScriptUtil.createBaseModel(model);
|
||||
}
|
||||
catch(Exception e)
|
||||
|
@@ -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<String> channelNames = toStrings(json.optJSONArray(CHANNEL_NAMES));
|
||||
Collection<String> channelNames = toStrings(json.optJSONArray(CHANNEL_IDS));
|
||||
return queue.createStatusUpdate(message, nodeToLinkTo, channelNames);
|
||||
}
|
||||
|
||||
|
@@ -74,7 +74,7 @@ import org.springframework.extensions.surf.util.URLEncoder;
|
||||
public class PublishingModelBuilder
|
||||
{
|
||||
|
||||
public Map<String, Object> buildPublishingEvent(PublishingEvent event, ChannelService channelService, String siteId)
|
||||
public Map<String, Object> buildPublishingEvent(PublishingEvent event, ChannelService channelService)
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
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<Map<String, Object>> buildPublishingEvents(List<PublishingEvent> events,
|
||||
final ChannelService channelService,
|
||||
final String siteId)
|
||||
final ChannelService channelService)
|
||||
{
|
||||
return transform(events, new Function<PublishingEvent, Map<String, Object>>()
|
||||
{
|
||||
public Map<String, Object> apply(PublishingEvent event)
|
||||
{
|
||||
return buildPublishingEvent(event, channelService, siteId);
|
||||
return buildPublishingEvent(event, channelService);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -118,6 +117,7 @@ public class PublishingModelBuilder
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put(URL, getUrl(channel));
|
||||
model.put(ID, channel.getId());
|
||||
model.put(NAME, channel.getName());
|
||||
//TODO Localize the title.
|
||||
model.put(TITLE, channel.getName());
|
||||
|
@@ -57,7 +57,7 @@ public class PublishingQueuePost extends PublishingEnvironmentWebScript
|
||||
}
|
||||
String eventId = jsonParser.schedulePublishingEvent(queue, content);
|
||||
PublishingEvent event = publishingService.getPublishingEvent(eventId);
|
||||
Map<String, Object> eventModel = builder.buildPublishingEvent(event, channelService, siteId);
|
||||
Map<String, Object> eventModel = builder.buildPublishingEvent(event, channelService);
|
||||
return WebScriptUtil.createBaseModel(eventModel);
|
||||
}
|
||||
catch(WebScriptException we)
|
||||
|
@@ -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<PublishingEvent> 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<String> channelNames = statusUpdate.getChannelNames();
|
||||
assertEquals(1, channelNames.size());
|
||||
assertTrue(channelNames.contains(statusChannel.getName()));
|
||||
Set<String> 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<String> channelNames = new ArrayList<String>(channels.length);
|
||||
for (Channel channel : channels)
|
||||
Function<Channel, String> transformer = new Function<Channel, String>()
|
||||
{
|
||||
channelNames.add(channel.getName());
|
||||
}
|
||||
public String apply(Channel channel)
|
||||
{
|
||||
return channel.getId();
|
||||
}
|
||||
};
|
||||
List<String> 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;
|
||||
}
|
||||
|
||||
|
@@ -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";
|
||||
|
||||
|
Reference in New Issue
Block a user