mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-07 18:25:23 +00:00
29482: Publishing: - Added support for LinkedIn status updates 29486: Social Publishing UI Updates, including: - Dialogue: Complete UI rework - Publishing History: display of unpublish event support - Created Alfresco.util.toggleClass function 29491: Publishing: - Added correct list of supported MIME types the the YouTube channel type 29493: Publishing: - Added video/mp4 to YouTube supported MIME types 29496: ChannelsGet now filters out channels that are not authorised. Added a space before the node URL on status updates. Extended unit tests to check behaviour for non-Admin users. 29513: Adds specific http client libraries to prevent the mac falling back to it's buggy default implementation (which, e.g. doesn't send Content-Length headers if the content length is zero). Required for Flickr support (their publish API requires both a content length header and zero length content. It returns a 411 error using the default Mac libs). 29534: Fixed PublishingEventsGet REST method. ChannelService getChannels() methods now support filtering by publish permissions. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29542 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
277 lines
9.2 KiB
Java
277 lines
9.2 KiB
Java
/*
|
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
|
*
|
|
* This file is part of Alfresco
|
|
*
|
|
* Alfresco is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Alfresco is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package org.alfresco.repo.publishing;
|
|
|
|
import static org.alfresco.model.ContentModel.TYPE_CONTENT;
|
|
import static org.alfresco.repo.publishing.PublishingModel.TYPE_DELIVERY_CHANNEL;
|
|
import static org.alfresco.repo.publishing.PublishingModel.PROP_AUTHORISATION_COMPLETE;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.reset;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
import java.io.File;
|
|
import java.io.Serializable;
|
|
import java.util.Calendar;
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.alfresco.model.ContentModel;
|
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
|
import org.alfresco.service.cmr.model.FileFolderService;
|
|
import org.alfresco.service.cmr.publishing.PublishingPackage;
|
|
import org.alfresco.service.cmr.publishing.PublishingQueue;
|
|
import org.alfresco.service.cmr.publishing.PublishingService;
|
|
import org.alfresco.service.cmr.publishing.StatusUpdate;
|
|
import org.alfresco.service.cmr.publishing.channels.Channel;
|
|
import org.alfresco.service.cmr.publishing.channels.ChannelService;
|
|
import org.alfresco.service.cmr.publishing.channels.ChannelType;
|
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
|
import org.alfresco.service.cmr.repository.NodeRef;
|
|
import org.alfresco.service.cmr.security.PermissionService;
|
|
import org.alfresco.service.cmr.site.SiteService;
|
|
import org.alfresco.service.cmr.site.SiteVisibility;
|
|
import org.alfresco.service.namespace.QName;
|
|
import org.alfresco.util.GUID;
|
|
import org.alfresco.util.collections.CollectionUtils;
|
|
|
|
/**
|
|
* @author Nick Smith
|
|
* @since 4.0
|
|
*
|
|
*/
|
|
public class PublishingTestHelper
|
|
{
|
|
private final ChannelService channelService;
|
|
private final PublishingService publishingService;
|
|
private final SiteService siteService;
|
|
private final FileFolderService fileFolderService;
|
|
private final PermissionService permissionService;
|
|
|
|
private final NodeRef docLib;
|
|
private final String siteId = GUID.generate();
|
|
|
|
private final List<Channel> channels = new LinkedList<Channel>();
|
|
private final List<String> events = new LinkedList<String>();
|
|
|
|
public PublishingTestHelper(ChannelService channelService,
|
|
PublishingService publishingService,
|
|
SiteService siteService,
|
|
FileFolderService fileFolderService,
|
|
PermissionService permissionService)
|
|
{
|
|
this.channelService = channelService;
|
|
this.publishingService = publishingService;
|
|
this.siteService = siteService;
|
|
this.fileFolderService = fileFolderService;
|
|
this.permissionService = permissionService;
|
|
|
|
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
|
|
siteService.createSite("test", siteId,
|
|
"Test site created by ChannelServiceImplIntegratedTest",
|
|
"Test site created by ChannelServiceImplIntegratedTest",
|
|
SiteVisibility.PUBLIC);
|
|
this.docLib = siteService.createContainer(siteId, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
|
|
}
|
|
|
|
|
|
public void tearDown() throws Exception
|
|
{
|
|
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
|
|
try
|
|
{
|
|
cancelAllEvents();
|
|
}
|
|
finally
|
|
{
|
|
try
|
|
{
|
|
deleteAllChannels();
|
|
}
|
|
finally
|
|
{
|
|
deleteSite();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void deleteSite()
|
|
{
|
|
try
|
|
{
|
|
siteService.deleteSite(siteId);
|
|
}
|
|
catch(Throwable t)
|
|
{
|
|
//NOOP
|
|
}
|
|
}
|
|
|
|
private void deleteAllChannels()
|
|
{
|
|
for (Channel channel : channels)
|
|
{
|
|
try
|
|
{
|
|
channelService.deleteChannel(channel);
|
|
}
|
|
catch(Throwable t)
|
|
{
|
|
//NOOP
|
|
}
|
|
}
|
|
}
|
|
|
|
private void cancelAllEvents()
|
|
{
|
|
for (String event : events)
|
|
{
|
|
try
|
|
{
|
|
publishingService.cancelPublishingEvent(event);
|
|
}
|
|
catch(Throwable t)
|
|
{
|
|
//NOOP
|
|
}
|
|
}
|
|
}
|
|
|
|
public ChannelType mockChannelType(String channelTypeId)
|
|
{
|
|
ChannelType channelType = channelService.getChannelType(channelTypeId);
|
|
if(channelType != null)
|
|
{
|
|
reset(channelType);
|
|
when(channelType.getId()).thenReturn(channelTypeId);
|
|
}
|
|
else
|
|
{
|
|
channelType = mock(ChannelType.class);
|
|
when(channelType.getId()).thenReturn(channelTypeId);
|
|
channelService.register(channelType);
|
|
}
|
|
when(channelType.getChannelNodeType()).thenReturn(TYPE_DELIVERY_CHANNEL);
|
|
return channelType;
|
|
}
|
|
|
|
public Channel createChannel(String typeId)
|
|
{
|
|
String channelName = GUID.generate();
|
|
return createChannel(typeId, channelName);
|
|
}
|
|
|
|
public Channel createChannel(String typeId, String channelName)
|
|
{
|
|
return createChannel(typeId, channelName, true);
|
|
}
|
|
|
|
public Channel createChannel(String typeId, String channelName, boolean isAuthorised)
|
|
{
|
|
Channel channel = channelService.createChannel(typeId, channelName, null);
|
|
channels.add(channel);
|
|
Map<QName, Serializable> properties = Collections.singletonMap(PROP_AUTHORISATION_COMPLETE, (Serializable)isAuthorised);
|
|
channelService.updateChannel(channel, properties);
|
|
return channel;
|
|
}
|
|
|
|
public void allowChannelAccess(String username, String channelId)
|
|
{
|
|
setChannelPermission(username, channelId, PermissionService.ADD_CHILDREN);
|
|
}
|
|
|
|
public void setChannelPermission(final String username, String channelId, final String permission)
|
|
{
|
|
final NodeRef channel = new NodeRef(channelId);
|
|
AuthenticationUtil.runAs(new RunAsWork<Void>()
|
|
{
|
|
public Void doWork() throws Exception
|
|
{
|
|
permissionService.setPermission(channel, username, permission, true);
|
|
return null;
|
|
}
|
|
}, AuthenticationUtil.getSystemUserName());
|
|
}
|
|
|
|
public String scheduleEvent1Year(PublishingPackage pckg, String channelId, String comment, StatusUpdate statusUpdate)
|
|
{
|
|
Calendar schedule = Calendar.getInstance();
|
|
schedule.add(Calendar.YEAR, 1);
|
|
return scheduleEvent(pckg, channelId, schedule, comment, statusUpdate);
|
|
}
|
|
|
|
public String scheduleEvent(PublishingPackage pckg, String channelId, Calendar schedule, String comment, StatusUpdate statusUpdate)
|
|
{
|
|
PublishingQueue queue = publishingService.getPublishingQueue();
|
|
String eventId = queue.scheduleNewEvent(pckg, channelId, schedule, comment, statusUpdate);
|
|
events.add(eventId);
|
|
return eventId;
|
|
}
|
|
|
|
public void addEvent(String eventId)
|
|
{
|
|
events.add(eventId);
|
|
}
|
|
|
|
public void addEvents(Collection<String> eventIds)
|
|
{
|
|
events.addAll(eventIds);
|
|
}
|
|
|
|
public NodeRef createContentNode(String name)
|
|
{
|
|
return fileFolderService.create(docLib, name, TYPE_CONTENT).getNodeRef();
|
|
}
|
|
|
|
public NodeRef createContentNode(String name, File theContent, String mimetype)
|
|
{
|
|
NodeRef source = createContentNode(name);
|
|
writeContent(source, theContent, mimetype);
|
|
return source;
|
|
}
|
|
|
|
public NodeRef createContentNode(String name, String theContent, String mimetype)
|
|
{
|
|
NodeRef source = fileFolderService.create(docLib, name, TYPE_CONTENT).getNodeRef();
|
|
writeContent(source, theContent, mimetype);
|
|
return source;
|
|
}
|
|
|
|
public void writeContent(NodeRef source, String theContent, String mimetype)
|
|
{
|
|
ContentWriter writer = fileFolderService.getWriter(source);
|
|
writer.setEncoding("UTF-8");
|
|
writer.putContent(theContent);
|
|
writer.setMimetype(mimetype);
|
|
}
|
|
|
|
public void writeContent(NodeRef source, File theContent, String mimetype)
|
|
{
|
|
ContentWriter writer = fileFolderService.getWriter(source);
|
|
writer.setMimetype(mimetype);
|
|
writer.setEncoding("UTF-8");
|
|
writer.putContent(theContent);
|
|
}
|
|
|
|
}
|