Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)

101331: Merge RA-SPRINT2 to HEAD-BUG-FIX (5.1)
      100711: RA-86, RA-87 & RA-88 (sub-tasks of RA-56): Move wiki service back-end classes to share services project.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@101472 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tatyana Valkevych
2015-04-08 16:23:14 +00:00
parent 1d4fc9dbe0
commit 7252dc8f76
11 changed files with 14 additions and 1768 deletions

View File

@@ -21,7 +21,6 @@
<import resource="classpath:alfresco/rendition-services-context.xml"/>
<import resource="classpath:alfresco/replication-services-context.xml"/>
<import resource="classpath:alfresco/thumbnail-service-context.xml"/>
<import resource="classpath:alfresco/wiki-services-context.xml"/>
<import resource="classpath:alfresco/preference-service-context.xml"/>
<import resource="classpath:alfresco/favourites-service-context.xml"/>
<import resource="classpath:alfresco/swf-transform-context.xml"/>

View File

@@ -1110,34 +1110,6 @@
<property name="methodName" value="listLinks" />
</bean>
<!-- ==================== -->
<!-- The Wiki Services -->
<!-- ==================== -->
<!-- The wiki service itself does not require any security restrictions, -->
<!-- they are imposed by the node and site services it uses to do its work. -->
<bean id="WikiService_security" class="org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor" />
<!-- The canned queries that the wiki services use do however need to check -->
<bean id="WikiService_CannedQuery_security" class="org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityInterceptor">
<property name="authenticationManager"><ref bean="authenticationManager"/></property>
<property name="accessDecisionManager"><ref local="accessDecisionManager"/></property>
<property name="afterInvocationManager"><ref local="afterInvocationManager"/></property>
<property name="objectDefinitionSource">
<value>
org.alfresco.service.cmr.wiki.WikiService.listWikiPages=ACL_ALLOW,AFTER_ACL_NODE.sys:base.ReadProperties
</value>
</property>
</bean>
<bean id="WikiService_security_listWikiPages" class="org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityBean">
<property name="methodSecurityInterceptor" ref="WikiService_CannedQuery_security" />
<property name="service" value="org.alfresco.service.cmr.wiki.WikiService" />
<property name="methodName" value="listWikiPages" />
</bean>
<!-- ========================= -->
<!-- The Discussions Services -->
<!-- ========================= -->

View File

@@ -1,68 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<!-- Wiki Service -->
<bean id="WikiService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>org.alfresco.service.cmr.wiki.WikiService</value>
</property>
<property name="target">
<ref bean="wikiService" />
</property>
<property name="interceptorNames">
<list>
<idref local="WikiService_transaction" />
<idref bean="AuditMethodInterceptor" />
<idref bean="exceptionTranslator" />
<idref bean="WikiService_security" />
</list>
</property>
</bean>
<!-- Wiki service transaction bean -->
<bean id="WikiService_transaction" class="org.alfresco.repo.transaction.RetryingTransactionInterceptor">
<property name="transactionService">
<ref bean="TransactionService"/>
</property>
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="get*">${server.transaction.mode.readOnly}</prop>
<prop key="list*">${server.transaction.mode.readOnly}</prop>
<prop key="*">${server.transaction.mode.default}</prop>
</props>
</property>
</bean>
<!-- List of Wiki Canned queries -->
<bean id="wikiCannedQueryRegistry" class="org.alfresco.util.registry.NamedObjectRegistry">
<property name="storageType" value="org.alfresco.query.CannedQueryFactory"/>
</bean>
<!-- The regular GetChildren Auditable Canned Query Factory -->
<bean name="wikiGetChildrenCannedQueryFactory" class="org.alfresco.repo.node.getchildren.GetChildrenAuditableCannedQueryFactory">
<property name="registry" ref="wikiCannedQueryRegistry"/>
<property name="tenantService" ref="tenantService"/>
<property name="nodeDAO" ref="nodeDAO"/>
<property name="qnameDAO" ref="qnameDAO"/>
<property name="cannedQueryDAO" ref="cannedQueryDAO"/>
<property name="methodSecurity" ref="WikiService_security_listWikiPages"/>
</bean>
<!-- Wiki Service base bean -->
<bean id="wikiService" class="org.alfresco.repo.wiki.WikiServiceImpl">
<property name="nodeDAO" ref="nodeDAO" />
<property name="nodeService" ref="NodeService"/>
<property name="siteService" ref="SiteService"/>
<property name="contentService" ref="ContentService"/>
<property name="taggingService" ref="TaggingService"/>
<property name="fileFolderService" ref="FileFolderService"/>
<property name="transactionService" ref="transactionService" />
<property name="cannedQueryRegistry" ref="wikiCannedQueryRegistry" />
</bean>
</beans>

View File

@@ -1,160 +0,0 @@
/*
* Copyright (C) 2005-2011 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.wiki;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.wiki.WikiPageInfo;
/**
* An implementation of {@link WikiPageInfo}
*
* @author Nick Burch (based on existing webscript controllers in the REST API)
* @since 4.0
*/
public class WikiPageInfoImpl implements WikiPageInfo
{
private NodeRef nodeRef;
private NodeRef containerNodeRef;
private String systemName;
private String title;
private String contents;
private String creator;
private String modifier;
private Date createdAt;
private Date modifiedAt;
private List<String> tags = new ArrayList<String>();
/**
* Creates a new, empty WikiPageInfo
*/
public WikiPageInfoImpl()
{
}
/**
* Create a WikiPageInfo object from an existing node
*/
public WikiPageInfoImpl(NodeRef nodeRef, NodeRef containerNodeRef, String systemName)
{
this.nodeRef = nodeRef;
this.containerNodeRef = containerNodeRef;
this.systemName = systemName;
}
@Override
public NodeRef getContainerNodeRef()
{
return containerNodeRef;
}
@Override
public NodeRef getNodeRef()
{
return nodeRef;
}
@Override
public String getSystemName()
{
return systemName;
}
@Override
public String getTitle()
{
return title;
}
@Override
public String getContents()
{
return contents;
}
@Override
public String getCreator()
{
return creator;
}
@Override
public String getModifier()
{
return modifier;
}
@Override
public Date getCreatedAt()
{
return createdAt;
}
@Override
public Date getModifiedAt()
{
return modifiedAt;
}
@Override
public List<String> getTags()
{
return tags;
}
@Override
public void setTitle(String title)
{
this.title = title;
}
@Override
public void setContents(String contents)
{
this.contents = contents;
}
public void setCreator(String creator)
{
this.creator = creator;
}
public void setModifier(String modifier)
{
this.modifier = modifier;
}
public void setCreatedAt(Date createdAt)
{
this.createdAt = createdAt;
}
public void setModifiedAt(Date modifiedAt)
{
this.modifiedAt = modifiedAt;
}
public void setTags(List<String> tags)
{
this.tags = tags;
}
}

View File

@@ -1,408 +0,0 @@
/*
* Copyright (C) 2005-2011 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.wiki;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.query.CannedQueryFactory;
import org.alfresco.query.CannedQueryResults;
import org.alfresco.query.CannedQuerySortDetails;
import org.alfresco.query.EmptyPagingResults;
import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.domain.node.NodeDAO;
import org.alfresco.repo.node.getchildren.GetChildrenAuditableCannedQuery;
import org.alfresco.repo.node.getchildren.GetChildrenAuditableCannedQueryFactory;
import org.alfresco.repo.query.NodeBackedEntity;
import org.alfresco.repo.site.SiteServiceImpl;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileNotFoundException;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.tagging.TaggingService;
import org.alfresco.service.cmr.wiki.WikiPageInfo;
import org.alfresco.service.cmr.wiki.WikiService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.Pair;
import org.alfresco.util.registry.NamedObjectRegistry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author Nick Burch (based on existing webscript controllers in the REST API)
* @since 4.0
*/
public class WikiServiceImpl implements WikiService
{
public static final String WIKI_COMPONENT = "wiki";
protected static final String CANNED_QUERY_GET_CHILDREN = "wikiGetChildrenCannedQueryFactory";
/**
* The logger
*/
@SuppressWarnings("unused")
private static Log logger = LogFactory.getLog(WikiServiceImpl.class);
private NodeDAO nodeDAO;
private NodeService nodeService;
private SiteService siteService;
private ContentService contentService;
private TaggingService taggingService;
private FileFolderService fileFolderService;
private TransactionService transactionService;
private NamedObjectRegistry<CannedQueryFactory<? extends Object>> cannedQueryRegistry;
public void setNodeDAO(NodeDAO nodeDAO)
{
this.nodeDAO = nodeDAO;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setSiteService(SiteService siteService)
{
this.siteService = siteService;
}
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
public void setTaggingService(TaggingService taggingService)
{
this.taggingService = taggingService;
}
public void setFileFolderService(FileFolderService fileFolderService)
{
this.fileFolderService = fileFolderService;
}
public void setTransactionService(TransactionService transactionService)
{
this.transactionService = transactionService;
}
/**
* Set the registry of {@link CannedQueryFactory canned queries}
*/
public void setCannedQueryRegistry(NamedObjectRegistry<CannedQueryFactory<? extends Object>> cannedQueryRegistry)
{
this.cannedQueryRegistry = cannedQueryRegistry;
}
/**
* Fetches the Wiki Container on a site, creating as required if requested.
*/
protected NodeRef getSiteWikiContainer(final String siteShortName, boolean create)
{
return SiteServiceImpl.getSiteContainer(
siteShortName, WIKI_COMPONENT, create,
siteService, transactionService, taggingService);
}
/**
* Turns a Title into a Page Name.
*/
private static String buildName(String title)
{
// The name is based on the title, but with underscores
String name = title.replace(' ', '_');
name = name.replaceAll("\"", "%22");
name = name.replaceAll("[*]", "%2a");
name = name.replaceAll("<", "%3c");
name = name.replaceAll(">", "%3e");
name = name.replaceAll(":", "%3a");
name = name.replaceAll("([.]?[.]+$)", "%2e");
return name;
}
private WikiPageInfo buildPage(NodeRef nodeRef, NodeRef container, String name, String preLoadedContents)
{
WikiPageInfoImpl page = new WikiPageInfoImpl(nodeRef, container, name);
// Grab all the properties, we need the bulk of them anyway
Map<QName,Serializable> props = nodeService.getProperties(nodeRef);
// Start with the auditable properties
page.setCreator((String)props.get(ContentModel.PROP_CREATOR));
page.setModifier((String)props.get(ContentModel.PROP_MODIFIER));
page.setCreatedAt((Date)props.get(ContentModel.PROP_CREATED));
page.setModifiedAt((Date)props.get(ContentModel.PROP_MODIFIED));
// Now the wiki ones
page.setTitle(((String)props.get(ContentModel.PROP_TITLE)).replaceAll(" ", "_"));
// Finally, do the content
String contents = preLoadedContents;
if (contents == null)
{
ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
if (reader != null)
{
contents = reader.getContentString();
}
}
page.setContents(contents);
// Finally tags
page.setTags(taggingService.getTags(nodeRef));
// All done
return page;
}
@Override
public WikiPageInfo getWikiPage(String siteShortName, String pageTitle)
{
NodeRef container = getSiteWikiContainer(siteShortName, false);
if (container == null)
{
// No links
return null;
}
String pageName = buildName(pageTitle);
NodeRef link = nodeService.getChildByName(container, ContentModel.ASSOC_CONTAINS, pageName);
if (link != null)
{
return buildPage(link, container, pageName, null);
}
return null;
}
@Override
public WikiPageInfo createWikiPage(String siteShortName, String title,
String content)
{
// Grab the location to store in
NodeRef container = getSiteWikiContainer(siteShortName, true);
// Build the name
String name = buildName(title);
// Get the properties for the node
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(ContentModel.PROP_NAME, name);
props.put(ContentModel.PROP_TITLE, title);
// Build the node
NodeRef nodeRef = nodeService.createNode(
container,
ContentModel.ASSOC_CONTAINS,
QName.createQName(name),
ContentModel.TYPE_CONTENT,
props
).getChildRef();
// Store the content
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_HTML);
writer.setEncoding("UTF-8");
writer.putContent(content);
// Generate the wrapping object for it
// Build it that way, so creator and created date come through
return buildPage(nodeRef, container, name, content);
}
@Override
public WikiPageInfo updateWikiPage(WikiPageInfo page)
{
// Sanity check what we were given
if (page.getNodeRef() == null)
{
throw new IllegalArgumentException("Can't update a page that was never persisted, call create instead");
}
NodeRef nodeRef = page.getNodeRef();
String nodeName = buildName(page.getTitle());
// Handle the rename case
boolean renamed = false;
if (! nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE).equals(page.getTitle()))
{
try
{
fileFolderService.rename(nodeRef, nodeName);
renamed = true;
}
catch (FileNotFoundException e)
{
throw new AlfrescoRuntimeException("Invalid node state - wiki page no longer found");
}
nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, nodeName);
nodeService.setProperty(nodeRef, ContentModel.PROP_TITLE, page.getTitle());
}
// Change the content
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_HTML);
writer.setEncoding("UTF-8");
writer.putContent(page.getContents());
// Now do the tags
taggingService.setTags(nodeRef, page.getTags());
// If we re-named, re-create the object
if (renamed)
{
page = buildPage(nodeRef, page.getContainerNodeRef(), nodeName, page.getContents());
}
// All done
return page;
}
@Override
public void deleteWikiPage(WikiPageInfo page)
{
if (page.getNodeRef() == null)
{
throw new IllegalArgumentException("Can't delete a wiki page that was never persisted");
}
nodeService.deleteNode(page.getNodeRef());
}
@Override
public PagingResults<WikiPageInfo> listWikiPages(String siteShortName, PagingRequest paging)
{
return listWikiPages(siteShortName, null, paging);
}
@Override
public PagingResults<WikiPageInfo> listWikiPages(String siteShortName, String user,
PagingRequest paging)
{
return listWikiPages(siteShortName, user, null, null, null, null, paging);
}
@Override
public PagingResults<WikiPageInfo> listWikiPagesByCreated(String siteShortName,
Date from, Date to, PagingRequest paging)
{
return listWikiPages(siteShortName, null, from, to, null, null, paging);
}
@Override
public PagingResults<WikiPageInfo> listWikiPagesByModified(String siteShortName,
Date from, Date to, PagingRequest paging)
{
return listWikiPages(siteShortName, null, null, null, from, to, paging);
}
public PagingResults<WikiPageInfo> listWikiPages(String siteShortName, String username,
Date createdFrom, Date createdTo, Date modifiedFrom, Date modifiedTo, PagingRequest paging)
{
NodeRef container = getSiteWikiContainer(siteShortName, false);
if (container == null)
{
// No events
return new EmptyPagingResults<WikiPageInfo>();
}
// Grab the factory
GetChildrenAuditableCannedQueryFactory getChildrenCannedQueryFactory =
(GetChildrenAuditableCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_GET_CHILDREN);
// Do the sorting, newest first by created date
CannedQuerySortDetails sorting = getChildrenCannedQueryFactory.createDateDescendingCQSortDetails();
// Run the canned query
GetChildrenAuditableCannedQuery cq = (GetChildrenAuditableCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(
container, ContentModel.TYPE_CONTENT, username, createdFrom, createdTo, null,
modifiedFrom, modifiedTo, sorting, paging);
// Execute the canned query
CannedQueryResults<NodeBackedEntity> results = cq.execute();
// Convert to Link objects
return wrap(results, container);
}
/**
* Our class to wrap up paged results of NodeBackedEntities as
* WikiPageInfo instances
*/
private PagingResults<WikiPageInfo> wrap(final PagingResults<NodeBackedEntity> results, final NodeRef container)
{
// Pre-load the nodes before we create them
List<Long> ids = new ArrayList<Long>();
for (NodeBackedEntity node : results.getPage())
{
ids.add(node.getId());
}
nodeDAO.cacheNodesById(ids);
// Wrap
return new PagingResults<WikiPageInfo>()
{
@Override
public String getQueryExecutionId()
{
return results.getQueryExecutionId();
}
@Override
public List<WikiPageInfo> getPage()
{
List<WikiPageInfo> pages = new ArrayList<WikiPageInfo>();
for (NodeBackedEntity node : results.getPage())
{
NodeRef nodeRef = node.getNodeRef();
String name = node.getName();
pages.add(buildPage(nodeRef, container, name, null));
}
return pages;
}
@Override
public boolean hasMoreItems()
{
return results.hasMoreItems();
}
@Override
public Pair<Integer, Integer> getTotalResultCount()
{
return results.getTotalResultCount();
}
};
}
}

View File

@@ -1,95 +0,0 @@
/*
* Copyright (C) 2005-2011 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.service.cmr.wiki;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import org.alfresco.repo.security.permissions.PermissionCheckValue;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* This class represents a Wiki Paeg in a site
*
* @author Nick Burch
* @since 4.0
*/
public interface WikiPageInfo extends Serializable, PermissionCheckValue
{
/**
* @return the NodeRef of the underlying wiki page
*/
NodeRef getNodeRef();
/**
* @return the NodeRef of the site container this belongs to
*/
NodeRef getContainerNodeRef();
/**
* @return the name of the wiki page
*/
String getSystemName();
/**
* @return the Title of the wiki page
*/
String getTitle();
/**
* Sets the Title of the wiki page
*/
void setTitle(String title);
/**
* @return the HTML Content of the wiki page
*/
String getContents();
/**
* Sets the (HTML) Content of the wiki page
*/
void setContents(String contentHTML);
/**
* @return the creator of the wiki page
*/
String getCreator();
/**
* @return the modifier of the wiki page
*/
String getModifier();
/**
* @return the creation date and time
*/
Date getCreatedAt();
/**
* @return the modification date and time
*/
Date getModifiedAt();
/**
* @return the Tags associated with the wiki page
*/
List<String> getTags();
}

View File

@@ -1,91 +0,0 @@
/*
* Copyright (C) 2005-2011 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.service.cmr.wiki;
import java.util.Date;
import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults;
import org.alfresco.service.NotAuditable;
/**
* The Wiki service.
*
* @author Nick Burch
* @since 4.0
*/
public interface WikiService
{
/**
* Creates a new {@link WikiPageInfo} in the given site, with the
* specified contents
*
* @return The newly created {@link WikiPageInfo}
*/
@NotAuditable
WikiPageInfo createWikiPage(String siteShortName, String title, String contents);
/**
* Updates an existing {@link WikiPageInfo} in the repository.
*
* @return The updated {@link WikiPageInfo}
*/
@NotAuditable
WikiPageInfo updateWikiPage(WikiPageInfo wikiPage);
/**
* Deletes an existing {@link WikiPageInfo} from the repository
*/
@NotAuditable
void deleteWikiPage(WikiPageInfo wikiPage);
/**
* Retrieves an existing {@link WikiPageInfo} from the repository
*/
@NotAuditable
WikiPageInfo getWikiPage(String siteShortName, String pageName);
/**
* Retrieves all {@link WikiPageInfo} instances in the repository
* for the given site.
*/
@NotAuditable
PagingResults<WikiPageInfo> listWikiPages(String siteShortName, PagingRequest paging);
/**
* Retrieves all {@link WikiPageInfo} instances in the repository
* for the given site and the specified user.
*/
@NotAuditable
PagingResults<WikiPageInfo> listWikiPages(String siteShortName, String user, PagingRequest paging);
/**
* Retrieves all {@link WikiPageInfo} instances in the repository
* for the given site, created in the specified date range
*/
@NotAuditable
PagingResults<WikiPageInfo> listWikiPagesByCreated(String siteShortName, Date from, Date to, PagingRequest paging);
/**
* Retrieves all {@link WikiPageInfo} instances in the repository
* for the given site, modified in the specified date range
*/
@NotAuditable
PagingResults<WikiPageInfo> listWikiPagesByModified(String siteShortName, Date from, Date to, PagingRequest paging);
}

View File

@@ -46,6 +46,20 @@ public class ApplicationContextHelper extends BaseApplicationContextHelper
return BaseApplicationContextHelper.getApplicationContext(CONFIG_LOCATIONS);
}
/**
* Provides a static, single instance of an application context represented by the given
* array of config locations. This method can be called repeatedly.
* <p/>
* If the configuration requested differs from one used previously, then the previously-created
* context is shut down.
*
* @return Returns an application context for the given config locations
*/
public synchronized static ApplicationContext getApplicationContext(String[] configLocations)
{
return BaseApplicationContextHelper.getApplicationContext(configLocations);
}
public static void main(String ... args)
{
ClassPathXmlApplicationContext ctx = (ClassPathXmlApplicationContext) getApplicationContext();

View File

@@ -383,11 +383,6 @@ public class Repository01TestSuite extends TestSuite
suite.addTest(org.alfresco.repo.version.VersionTestSuite.suite());
}
static void tests60(TestSuite suite)
{
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.wiki.WikiServiceImplTest.class));
}
static void tests61(TestSuite suite)
{
suite.addTest(org.alfresco.repo.workflow.WorkflowTestSuite.suite());

View File

@@ -1,37 +0,0 @@
/*
* Copyright (C) 2005-2014 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;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* See {@link Repository01TestSuite}
*
* @Author Alan Davis
*/
public class Repository60TestSuite extends TestSuite
{
public static Test suite()
{
TestSuite suite = new TestSuite();
Repository01TestSuite.tests60(suite);
return suite;
}
}

View File

@@ -1,875 +0,0 @@
/*
* Copyright (C) 2005-2011 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.wiki;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.site.SiteModel;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.service.cmr.tagging.TaggingService;
import org.alfresco.service.cmr.wiki.WikiPageInfo;
import org.alfresco.service.cmr.wiki.WikiService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.PropertyMap;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
/**
* Test cases for {@link WikiServiceImpl}.
*
* @author Nick Burch
* @since 4.0
*/
public class WikiServiceImplTest
{
private static final String TEST_SITE_PREFIX = "WikiSiteTest";
private static final long ONE_DAY_MS = 24*60*60*1000;
private static final ApplicationContext testContext = ApplicationContextHelper.getApplicationContext();
// injected services
private static MutableAuthenticationService AUTHENTICATION_SERVICE;
private static BehaviourFilter BEHAVIOUR_FILTER;
private static WikiService WIKI_SERVICE;
private static ContentService CONTENT_SERVICE;
@SuppressWarnings("unused")
private static DictionaryService DICTIONARY_SERVICE;
private static NodeService NODE_SERVICE;
private static NodeService PUBLIC_NODE_SERVICE;
private static PersonService PERSON_SERVICE;
private static RetryingTransactionHelper TRANSACTION_HELPER;
@SuppressWarnings("unused")
private static TransactionService TRANSACTION_SERVICE;
private static PermissionService PERMISSION_SERVICE;
private static SiteService SITE_SERVICE;
private static TaggingService TAGGING_SERVICE;
private static final String TEST_USER = WikiServiceImplTest.class.getSimpleName() + "_testuser";
private static final String ADMIN_USER = AuthenticationUtil.getAdminUserName();
private static SiteInfo WIKI_SITE;
private static SiteInfo ALTERNATE_WIKI_SITE;
/**
* Temporary test nodes (created during a test method) that need deletion after the test method.
*/
private List<NodeRef> testNodesToTidy = new ArrayList<NodeRef>();
/**
* Temporary test nodes (created BeforeClass) that need deletion after this test class.
*/
private static List<NodeRef> CLASS_TEST_NODES_TO_TIDY = new ArrayList<NodeRef>();
@BeforeClass public static void initTestsContext() throws Exception
{
AUTHENTICATION_SERVICE = (MutableAuthenticationService)testContext.getBean("authenticationService");
BEHAVIOUR_FILTER = (BehaviourFilter)testContext.getBean("policyBehaviourFilter");
WIKI_SERVICE = (WikiService)testContext.getBean("WikiService");
CONTENT_SERVICE = (ContentService)testContext.getBean("ContentService");
DICTIONARY_SERVICE = (DictionaryService)testContext.getBean("dictionaryService");
NODE_SERVICE = (NodeService)testContext.getBean("nodeService");
PUBLIC_NODE_SERVICE = (NodeService)testContext.getBean("NodeService");
PERSON_SERVICE = (PersonService)testContext.getBean("personService");
TRANSACTION_HELPER = (RetryingTransactionHelper)testContext.getBean("retryingTransactionHelper");
TRANSACTION_SERVICE = (TransactionService)testContext.getBean("TransactionService");
PERMISSION_SERVICE = (PermissionService)testContext.getBean("permissionService");
SITE_SERVICE = (SiteService)testContext.getBean("siteService");
TAGGING_SERVICE = (TaggingService)testContext.getBean("TaggingService");
// Do the setup as admin
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
createUser(TEST_USER);
// We need to create the test site as the test user so that they can contribute content to it in tests below.
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
createTestSites();
}
@Test public void createNewEntry() throws Exception
{
WikiPageInfo page;
// Nothing to start with
PagingResults<WikiPageInfo> results =
WIKI_SERVICE.listWikiPages(WIKI_SITE.getShortName(), new PagingRequest(10));
assertEquals(0, results.getPage().size());
// Get with an arbitrary name gives nothing
page = WIKI_SERVICE.getWikiPage(WIKI_SITE.getShortName(), "madeUp");
assertEquals(null, page);
page = WIKI_SERVICE.getWikiPage(WIKI_SITE.getShortName(), "madeUp2");
assertEquals(null, page);
// Create one
page = WIKI_SERVICE.createWikiPage(
WIKI_SITE.getShortName(), "Title", "This Is Some Content");
// Ensure it got a noderef, and the correct site
assertNotNull(page.getNodeRef());
assertNotNull(page.getSystemName());
NodeRef container = PUBLIC_NODE_SERVICE.getPrimaryParent(page.getNodeRef()).getParentRef();
NodeRef site = PUBLIC_NODE_SERVICE.getPrimaryParent(container).getParentRef();
assertEquals(WIKI_SITE.getNodeRef(), site);
// Ensure the content was correctly set up
ContentReader reader = CONTENT_SERVICE.getReader(page.getNodeRef(), ContentModel.PROP_CONTENT);
assertEquals("This Is Some Content", reader.getContentString());
assertEquals(MimetypeMap.MIMETYPE_HTML, reader.getMimetype());
assertEquals("UTF-8", reader.getEncoding());
// Check the details on the object
assertEquals("Title", page.getTitle());
assertEquals("This Is Some Content", page.getContents());
assertEquals(ADMIN_USER, page.getCreator());
assertEquals(0, page.getTags().size());
// Fetch it, and check the details
page = WIKI_SERVICE.getWikiPage(WIKI_SITE.getShortName(), page.getSystemName());
assertEquals("Title", page.getTitle());
assertEquals("This Is Some Content", page.getContents());
assertEquals(ADMIN_USER, page.getCreator());
assertEquals(0, page.getTags().size());
// Mark it as done with
testNodesToTidy.add(page.getNodeRef());
}
@Test public void createUpdateDeleteEntry() throws Exception
{
WikiPageInfo page;
// Run as the test user instead
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
// Create a page
page = WIKI_SERVICE.createWikiPage(
WIKI_SITE.getShortName(), "Title", "This Is Some Content");
testNodesToTidy.add(page.getNodeRef());
// Check it
assertEquals("Title", page.getSystemName());
assertEquals("Title", page.getTitle());
assertEquals("This Is Some Content", page.getContents());
assertEquals(TEST_USER, page.getCreator());
assertEquals(0, page.getTags().size());
// Change it
page.setTitle("New Title");
page.setContents("This is new content");
page = WIKI_SERVICE.updateWikiPage(page);
assertEquals("New_Title", page.getSystemName()); // Name has underscores
assertEquals("New_Title", page.getTitle());
// Fetch, and check
page = WIKI_SERVICE.getWikiPage(WIKI_SITE.getShortName(), page.getSystemName());
assertEquals("New_Title", page.getSystemName()); // Name has underscores
assertEquals("New_Title", page.getTitle());
assertEquals("This is new content", page.getContents());
assertEquals(TEST_USER, page.getCreator());
assertEquals(0, page.getTags().size());
// Delete it
WIKI_SERVICE.deleteWikiPage(page);
// Check it went
assertEquals(null, WIKI_SERVICE.getWikiPage(WIKI_SITE.getShortName(), page.getSystemName()));
// Create a new node with spaces in title
page = WIKI_SERVICE.createWikiPage(
WIKI_SITE.getShortName(), "Title Space", "This Is Some Content");
testNodesToTidy.add(page.getNodeRef());
// Check it
assertEquals("Title_Space", page.getSystemName());
assertEquals("Title_Space", page.getTitle());
assertEquals("This Is Some Content", page.getContents());
assertEquals(TEST_USER, page.getCreator());
assertEquals(0, page.getTags().size());
// Edit it without renaming
page.setContents("Changed contents");
page = WIKI_SERVICE.updateWikiPage(page);
// Check
page = WIKI_SERVICE.getWikiPage(WIKI_SITE.getShortName(), page.getSystemName());
assertEquals("Title_Space", page.getSystemName());
assertEquals("Title_Space", page.getTitle());
assertEquals("Changed contents", page.getContents());
assertEquals(TEST_USER, page.getCreator());
assertEquals(0, page.getTags().size());
// Now edit with renaming
page.setTitle("Alternate Title");
page = WIKI_SERVICE.updateWikiPage(page);
// Check
page = WIKI_SERVICE.getWikiPage(WIKI_SITE.getShortName(), page.getSystemName());
assertEquals("Alternate_Title", page.getSystemName());
assertEquals("Alternate_Title", page.getTitle());
assertEquals("Changed contents", page.getContents());
assertEquals(TEST_USER, page.getCreator());
assertEquals(0, page.getTags().size());
}
/**
* Ensures that when we try to write an entry to the
* container of a new site, it is correctly setup for us.
* This test does it's own transactions
*/
@Test public void newContainerSetup() throws Exception
{
final String TEST_SITE_NAME = "WikiTestNewTestSite";
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
if(SITE_SERVICE.getSite(TEST_SITE_NAME) != null)
{
SITE_SERVICE.deleteSite(TEST_SITE_NAME);
}
SITE_SERVICE.createSite(
TEST_SITE_PREFIX, TEST_SITE_NAME, "Test", "Test", SiteVisibility.PUBLIC);
// Won't have the container to start with
assertFalse(SITE_SERVICE.hasContainer(TEST_SITE_NAME, WikiServiceImpl.WIKI_COMPONENT));
// Create a link
WIKI_SERVICE.createWikiPage(
TEST_SITE_NAME, "Title", "TextTextText");
// It will now exist
assertTrue(SITE_SERVICE.hasContainer(TEST_SITE_NAME, WikiServiceImpl.WIKI_COMPONENT));
// It'll be a tag scope too
NodeRef container = SITE_SERVICE.getContainer(TEST_SITE_NAME, WikiServiceImpl.WIKI_COMPONENT);
assertTrue(TAGGING_SERVICE.isTagScope(container));
// Tidy up
SITE_SERVICE.deleteSite(TEST_SITE_NAME);
return null;
}
});
}
@Test public void tagging() throws Exception
{
WikiPageInfo page;
final String TAG_1 = "link_tag_1";
final String TAG_2 = "link_tag_2";
final String TAG_3 = "link_tag_3";
// Create one without tagging
page = WIKI_SERVICE.createWikiPage(
WIKI_SITE.getShortName(), "Title", "This Is Some Content");
testNodesToTidy.add(page.getNodeRef());
// Check
assertEquals(0, page.getTags().size());
page = WIKI_SERVICE.getWikiPage(WIKI_SITE.getShortName(), page.getSystemName());
assertEquals(0, page.getTags().size());
// Update it to have tags
page.getTags().add(TAG_1);
page.getTags().add(TAG_2);
page.getTags().add(TAG_1);
assertEquals(3, page.getTags().size());
WIKI_SERVICE.updateWikiPage(page);
// Check
page = WIKI_SERVICE.getWikiPage(WIKI_SITE.getShortName(), page.getSystemName());
assertEquals(2, page.getTags().size());
assertEquals(true, page.getTags().contains(TAG_1));
assertEquals(true, page.getTags().contains(TAG_2));
assertEquals(false, page.getTags().contains(TAG_3));
// Update it to have different tags
page.getTags().remove(TAG_2);
page.getTags().add(TAG_3);
page.getTags().add(TAG_1);
WIKI_SERVICE.updateWikiPage(page);
// Check it as-is
assertEquals(3, page.getTags().size()); // Includes duplicate tag until re-loaded
assertEquals(true, page.getTags().contains(TAG_1));
assertEquals(false, page.getTags().contains(TAG_2));
assertEquals(true, page.getTags().contains(TAG_3));
// Now load and re-check
page = WIKI_SERVICE.getWikiPage(WIKI_SITE.getShortName(), page.getSystemName());
assertEquals(2, page.getTags().size()); // Duplicate now gone
assertEquals(true, page.getTags().contains(TAG_1));
assertEquals(false, page.getTags().contains(TAG_2));
assertEquals(true, page.getTags().contains(TAG_3));
// Update it to have no tags
page.getTags().clear();
WIKI_SERVICE.updateWikiPage(page);
// Check
page = WIKI_SERVICE.getWikiPage(WIKI_SITE.getShortName(), page.getSystemName());
assertEquals(0, page.getTags().size());
// Update it to have tags again
page.getTags().add(TAG_1);
page.getTags().add(TAG_2);
page.getTags().add(TAG_3);
WIKI_SERVICE.updateWikiPage(page);
// Check
page = WIKI_SERVICE.getWikiPage(WIKI_SITE.getShortName(), page.getSystemName());
assertEquals(3, page.getTags().size());
assertEquals(true, page.getTags().contains(TAG_1));
assertEquals(true, page.getTags().contains(TAG_2));
assertEquals(true, page.getTags().contains(TAG_3));
// Tidy
WIKI_SERVICE.deleteWikiPage(page);
}
/**
* Tests for listing the wiki pages of a site, possibly by user or date range
*/
@Test public void pagesListing() throws Exception
{
PagingRequest paging = new PagingRequest(10);
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
// Nothing to start with
PagingResults<WikiPageInfo> results =
WIKI_SERVICE.listWikiPages(WIKI_SITE.getShortName(), paging);
assertEquals(0, results.getPage().size());
// Add a few
WikiPageInfo pageA = WIKI_SERVICE.createWikiPage(
WIKI_SITE.getShortName(), "TitleA", "ContentA");
WikiPageInfo pageB = WIKI_SERVICE.createWikiPage(
WIKI_SITE.getShortName(), "TitleB", "ContentB");
WikiPageInfo pageC = WIKI_SERVICE.createWikiPage(
WIKI_SITE.getShortName(), "TitleC", "ContentC");
testNodesToTidy.add(pageA.getNodeRef());
testNodesToTidy.add(pageB.getNodeRef());
testNodesToTidy.add(pageC.getNodeRef());
// Check now, should be newest first
results = WIKI_SERVICE.listWikiPages(WIKI_SITE.getShortName(), paging);
assertEquals(3, results.getPage().size());
assertEquals("TitleC", results.getPage().get(0).getTitle());
assertEquals("TitleB", results.getPage().get(1).getTitle());
assertEquals("TitleA", results.getPage().get(2).getTitle());
// Add one more, as a different user, and drop the page size
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
WikiPageInfo pageD = WIKI_SERVICE.createWikiPage(
WIKI_SITE.getShortName(), "TitleD", "ContentD");
testNodesToTidy.add(pageD.getNodeRef());
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
paging = new PagingRequest(3);
results = WIKI_SERVICE.listWikiPages(WIKI_SITE.getShortName(), paging);
assertEquals(3, results.getPage().size());
assertEquals("TitleD", results.getPage().get(0).getTitle());
assertEquals("TitleC", results.getPage().get(1).getTitle());
assertEquals("TitleB", results.getPage().get(2).getTitle());
paging = new PagingRequest(3, 3);
results = WIKI_SERVICE.listWikiPages(WIKI_SITE.getShortName(), paging);
assertEquals(1, results.getPage().size());
assertEquals("TitleA", results.getPage().get(0).getTitle());
// Now check filtering by user
paging = new PagingRequest(10);
results = WIKI_SERVICE.listWikiPages(WIKI_SITE.getShortName(), TEST_USER, paging);
assertEquals(3, results.getPage().size());
assertEquals("TitleC", results.getPage().get(0).getTitle());
assertEquals("TitleB", results.getPage().get(1).getTitle());
assertEquals("TitleA", results.getPage().get(2).getTitle());
results = WIKI_SERVICE.listWikiPages(WIKI_SITE.getShortName(), ADMIN_USER, paging);
assertEquals(1, results.getPage().size());
assertEquals("TitleD", results.getPage().get(0).getTitle());
// Now check filtering by date range
// Arrange it so that the orders are:
// Created -> C B A D
// Modified -> D C B A
pushAuditableDatesBack(pageB, 10, 0);
pushAuditableDatesBack(pageC, 100, 10);
pushAuditableDatesBack(pageD, 0, 100);
pageA.setContents("UpdatedContentsA");
pageA = WIKI_SERVICE.updateWikiPage(pageA);
Date today = new Date();
Date tomorrow = new Date(today.getTime()+ONE_DAY_MS);
Date yesterday = new Date(today.getTime()-ONE_DAY_MS);
Date twoWeeksAgo = new Date(today.getTime()-14*ONE_DAY_MS);
// Check by created date
// Very recent ones
results = WIKI_SERVICE.listWikiPagesByCreated(WIKI_SITE.getShortName(), yesterday, tomorrow, paging);
assertEquals(2, results.getPage().size());
assertEquals("TitleD", results.getPage().get(0).getTitle());
assertEquals("TitleA", results.getPage().get(1).getTitle());
// Fairly old ones
results = WIKI_SERVICE.listWikiPagesByCreated(WIKI_SITE.getShortName(), twoWeeksAgo, yesterday, paging);
assertEquals(1, results.getPage().size());
assertEquals("TitleB", results.getPage().get(0).getTitle());
// Fairly old to current
results = WIKI_SERVICE.listWikiPagesByCreated(WIKI_SITE.getShortName(), twoWeeksAgo, tomorrow, paging);
assertEquals(3, results.getPage().size());
assertEquals("TitleD", results.getPage().get(0).getTitle());
assertEquals("TitleA", results.getPage().get(1).getTitle());
assertEquals("TitleB", results.getPage().get(2).getTitle());
// Check by modified date
// Very recent ones
results = WIKI_SERVICE.listWikiPagesByModified(WIKI_SITE.getShortName(), yesterday, tomorrow, paging);
assertEquals(2, results.getPage().size());
assertEquals("TitleA", results.getPage().get(0).getTitle());
assertEquals("TitleB", results.getPage().get(1).getTitle());
// Fairly old ones
results = WIKI_SERVICE.listWikiPagesByModified(WIKI_SITE.getShortName(), twoWeeksAgo, yesterday, paging);
assertEquals(1, results.getPage().size());
assertEquals("TitleC", results.getPage().get(0).getTitle());
// Fairly old to current
results = WIKI_SERVICE.listWikiPagesByModified(WIKI_SITE.getShortName(), twoWeeksAgo, tomorrow, paging);
assertEquals(3, results.getPage().size());
assertEquals("TitleA", results.getPage().get(0).getTitle());
assertEquals("TitleB", results.getPage().get(1).getTitle());
assertEquals("TitleC", results.getPage().get(2).getTitle());
// Bring C back to current and re-check
pageC.setContents("Changed C");
pageC = WIKI_SERVICE.updateWikiPage(pageC);
// Order doesn't change, sorting is by created date not modified date
results = WIKI_SERVICE.listWikiPagesByModified(WIKI_SITE.getShortName(), twoWeeksAgo, tomorrow, paging);
assertEquals(3, results.getPage().size());
assertEquals("TitleA", results.getPage().get(0).getTitle());
assertEquals("TitleB", results.getPage().get(1).getTitle());
assertEquals("TitleC", results.getPage().get(2).getTitle());
// Tidy
paging = new PagingRequest(10);
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
results = WIKI_SERVICE.listWikiPages(WIKI_SITE.getShortName(), paging);
for (WikiPageInfo link : results.getPage())
{
PUBLIC_NODE_SERVICE.deleteNode(link.getNodeRef());
}
results = WIKI_SERVICE.listWikiPages(ALTERNATE_WIKI_SITE.getShortName(), paging);
for (WikiPageInfo link : results.getPage())
{
PUBLIC_NODE_SERVICE.deleteNode(link.getNodeRef());
}
}
/**
* Checks that the correct permission checking occurs on fetching
* links listings (which go through canned queries)
*/
@Test public void pagesListingPermissionsChecking() throws Exception
{
PagingRequest paging = new PagingRequest(10);
PagingResults<WikiPageInfo> results;
// Nothing to start with in either site
results = WIKI_SERVICE.listWikiPages(WIKI_SITE.getShortName(), paging);
assertEquals(0, results.getPage().size());
results = WIKI_SERVICE.listWikiPages(ALTERNATE_WIKI_SITE.getShortName(), paging);
assertEquals(0, results.getPage().size());
// Double check that we're only allowed to see the 1st site
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override public Void execute() throws Throwable
{
assertEquals(true, SITE_SERVICE.isMember(WIKI_SITE.getShortName(), TEST_USER));
assertEquals(false, SITE_SERVICE.isMember(ALTERNATE_WIKI_SITE.getShortName(), TEST_USER));
return null;
}
});
// Now become the test user
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
// Add two events to one site and three to the other
// Note - add the events as a different user for the site that the
// test user isn't a member of!
WikiPageInfo pageA = WIKI_SERVICE.createWikiPage(
WIKI_SITE.getShortName(), "TitleA", "ContentA");
WikiPageInfo pageB = WIKI_SERVICE.createWikiPage(
WIKI_SITE.getShortName(), "TitleB", "ContentB");
testNodesToTidy.add(pageA.getNodeRef());
testNodesToTidy.add(pageB.getNodeRef());
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
WikiPageInfo pagePrivA = WIKI_SERVICE.createWikiPage(
ALTERNATE_WIKI_SITE.getShortName(), "PrivTitleA", "Contents A");
WikiPageInfo pagePrivB = WIKI_SERVICE.createWikiPage(
ALTERNATE_WIKI_SITE.getShortName(), "PrivTitleB", "Contents B");
WikiPageInfo pagePrivC = WIKI_SERVICE.createWikiPage(
ALTERNATE_WIKI_SITE.getShortName(), "PrivTitleC", "Contents C");
testNodesToTidy.add(pagePrivA.getNodeRef());
testNodesToTidy.add(pagePrivB.getNodeRef());
testNodesToTidy.add(pagePrivC.getNodeRef());
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
// Check again, as we're not in the 2nd site won't see any there
results = WIKI_SERVICE.listWikiPages(WIKI_SITE.getShortName(), paging);
assertEquals(2, results.getPage().size());
results = WIKI_SERVICE.listWikiPages(ALTERNATE_WIKI_SITE.getShortName(), paging);
assertEquals(0, results.getPage().size());
// Join the site, now we can see both
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
SITE_SERVICE.setMembership(ALTERNATE_WIKI_SITE.getShortName(), TEST_USER, SiteModel.SITE_COLLABORATOR);
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
return null;
}
});
results = WIKI_SERVICE.listWikiPages(WIKI_SITE.getShortName(), paging);
assertEquals(2, results.getPage().size());
results = WIKI_SERVICE.listWikiPages(ALTERNATE_WIKI_SITE.getShortName(), paging);
assertEquals(3, results.getPage().size());
// Explicitly remove their permissions from one node, check it vanishes from the list
PERMISSION_SERVICE.setInheritParentPermissions(pagePrivC.getNodeRef(), false);
PERMISSION_SERVICE.clearPermission(pagePrivC.getNodeRef(), TEST_USER);
results = WIKI_SERVICE.listWikiPages(WIKI_SITE.getShortName(), paging);
assertEquals(2, results.getPage().size());
results = WIKI_SERVICE.listWikiPages(ALTERNATE_WIKI_SITE.getShortName(), paging);
assertEquals(2, results.getPage().size());
// Leave, they go away again
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
SITE_SERVICE.removeMembership(ALTERNATE_WIKI_SITE.getShortName(), TEST_USER);
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
return null;
}
});
results = WIKI_SERVICE.listWikiPages(WIKI_SITE.getShortName(), paging);
assertEquals(2, results.getPage().size());
results = WIKI_SERVICE.listWikiPages(ALTERNATE_WIKI_SITE.getShortName(), paging);
assertEquals(0, results.getPage().size());
// Tidy
paging = new PagingRequest(10);
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
results = WIKI_SERVICE.listWikiPages(WIKI_SITE.getShortName(), paging);
for (WikiPageInfo link : results.getPage())
{
PUBLIC_NODE_SERVICE.deleteNode(link.getNodeRef());
}
results = WIKI_SERVICE.listWikiPages(ALTERNATE_WIKI_SITE.getShortName(), paging);
for (WikiPageInfo link : results.getPage())
{
PUBLIC_NODE_SERVICE.deleteNode(link.getNodeRef());
}
}
// --------------------------------------------------------------------------------
/**
* Alters the created date on a wiki page for testing
*/
private void pushAuditableDatesBack(WikiPageInfo page, int createdDaysAgo, int modifiedDaysAgo) throws Exception
{
final NodeRef node = page.getNodeRef();
final Date created = page.getCreatedAt();
final Date newCreated = new Date(created.getTime() - createdDaysAgo*ONE_DAY_MS);
final Date modified = page.getModifiedAt();
final Date newModified = new Date(modified.getTime() - modifiedDaysAgo*ONE_DAY_MS);
// Update the created date
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
BEHAVIOUR_FILTER.disableBehaviour(ContentModel.ASPECT_AUDITABLE);
NODE_SERVICE.setProperty(node, ContentModel.PROP_CREATED, newCreated);
NODE_SERVICE.setProperty(node, ContentModel.PROP_MODIFIED, newModified);
return null;
}
}, false, true);
// Change something else too in the public nodeservice, to force a re-index
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
BEHAVIOUR_FILTER.disableBehaviour(ContentModel.ASPECT_AUDITABLE);
PUBLIC_NODE_SERVICE.setProperty(node, ContentModel.PROP_CREATED, newCreated);
PUBLIC_NODE_SERVICE.setProperty(node, ContentModel.PROP_MODIFIED, newModified);
PUBLIC_NODE_SERVICE.setProperty(node, ContentModel.PROP_DESCRIPTION, "Forced Change");
return null;
}
}, false, true);
// Check it was taken
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
assertEquals(newCreated, NODE_SERVICE.getProperty(node, ContentModel.PROP_CREATED));
assertEquals(newCreated, PUBLIC_NODE_SERVICE.getProperty(node, ContentModel.PROP_CREATED));
assertEquals(newModified, NODE_SERVICE.getProperty(node, ContentModel.PROP_MODIFIED));
assertEquals(newModified, PUBLIC_NODE_SERVICE.getProperty(node, ContentModel.PROP_MODIFIED));
return null;
}
}, false, true);
// Update the object itself
((WikiPageInfoImpl)page).setCreatedAt(newCreated);
((WikiPageInfoImpl)page).setModifiedAt(newModified);
}
private static void createTestSites() throws Exception
{
final WikiServiceImpl privateWikiPageService = (WikiServiceImpl)testContext.getBean("wikiService");
WIKI_SITE = TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<SiteInfo>()
{
@Override
public SiteInfo execute() throws Throwable
{
SiteInfo site = SITE_SERVICE.createSite(
TEST_SITE_PREFIX,
WikiServiceImplTest.class.getSimpleName() + "_testSite" + System.currentTimeMillis(),
"test site title", "test site description",
SiteVisibility.PUBLIC);
privateWikiPageService.getSiteWikiContainer(site.getShortName(), true);
CLASS_TEST_NODES_TO_TIDY.add(site.getNodeRef());
return site;
}
});
// Create the alternate site as admin
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
ALTERNATE_WIKI_SITE = TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<SiteInfo>()
{
@Override
public SiteInfo execute() throws Throwable
{
SiteInfo site = SITE_SERVICE.createSite(
TEST_SITE_PREFIX,
WikiServiceImplTest.class.getSimpleName() + "_testAltSite" + System.currentTimeMillis(),
"alternate site title", "alternate site description",
SiteVisibility.PRIVATE);
privateWikiPageService.getSiteWikiContainer(site.getShortName(), true);
CLASS_TEST_NODES_TO_TIDY.add(site.getNodeRef());
return site;
}
});
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
}
/**
* By default, all tests are run as the admin user.
*/
@Before public void setAdminUser()
{
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
}
@After public void deleteTestNodes() throws Exception
{
performDeletionOfNodes(testNodesToTidy);
}
@AfterClass public static void deleteClassTestNodesAndUsers() throws Exception
{
performDeletionOfNodes(CLASS_TEST_NODES_TO_TIDY);
deleteUser(TEST_USER);
}
/**
* Deletes the specified NodeRefs, if they exist.
* @param nodesToDelete
*/
private static void performDeletionOfNodes(final List<NodeRef> nodesToDelete)
{
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
for (NodeRef node : nodesToDelete)
{
if (NODE_SERVICE.exists(node))
{
// st:site nodes can only be deleted via the SiteService
if (NODE_SERVICE.getType(node).equals(SiteModel.TYPE_SITE))
{
SiteInfo siteInfo = SITE_SERVICE.getSite(node);
SITE_SERVICE.deleteSite(siteInfo.getShortName());
}
else
{
NODE_SERVICE.deleteNode(node);
}
}
}
return null;
}
});
}
private static void createUser(final String userName)
{
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
if (!AUTHENTICATION_SERVICE.authenticationExists(userName))
{
AUTHENTICATION_SERVICE.createAuthentication(userName, "PWD".toCharArray());
}
if (!PERSON_SERVICE.personExists(userName))
{
PropertyMap ppOne = new PropertyMap();
ppOne.put(ContentModel.PROP_USERNAME, userName);
ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName");
ppOne.put(ContentModel.PROP_LASTNAME, "lastName");
ppOne.put(ContentModel.PROP_EMAIL, "email@email.com");
ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
PERSON_SERVICE.createPerson(ppOne);
}
return null;
}
});
}
private static void deleteUser(final String userName)
{
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
if (PERSON_SERVICE.personExists(userName))
{
PERSON_SERVICE.deletePerson(userName);
}
return null;
}
});
}
}