mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-9157 Add title/name rules for wikis to the wiki service, with tests
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29583 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -127,6 +127,13 @@ public class WikiServiceImpl implements WikiService
|
||||
siteService, transactionService, taggingService);
|
||||
}
|
||||
|
||||
private String buildName(String title)
|
||||
{
|
||||
// The name is based on the title, but with underscores
|
||||
String name = title.replace(' ', '_');
|
||||
return name;
|
||||
}
|
||||
|
||||
private WikiPageInfo buildPage(NodeRef nodeRef, NodeRef container, String name, String preLoadedContents)
|
||||
{
|
||||
WikiPageInfoImpl page = new WikiPageInfoImpl(nodeRef, container, name);
|
||||
@@ -188,16 +195,19 @@ public class WikiServiceImpl implements WikiService
|
||||
// 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, title);
|
||||
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(title),
|
||||
QName.createQName(name),
|
||||
ContentModel.TYPE_CONTENT,
|
||||
props
|
||||
).getChildRef();
|
||||
@@ -209,7 +219,7 @@ public class WikiServiceImpl implements WikiService
|
||||
|
||||
// Generate the wrapping object for it
|
||||
// Build it that way, so creator and created date come through
|
||||
return buildPage(nodeRef, container, title, content);
|
||||
return buildPage(nodeRef, container, name, content);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -222,21 +232,22 @@ public class WikiServiceImpl implements WikiService
|
||||
}
|
||||
|
||||
NodeRef nodeRef = page.getNodeRef();
|
||||
String nodeName = buildName(page.getTitle());
|
||||
|
||||
// Handle the rename case
|
||||
boolean renamed = false;
|
||||
if(! nodeService.getProperty(nodeRef, ContentModel.PROP_NAME).equals(page.getTitle()))
|
||||
if(! nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE).equals(page.getTitle()))
|
||||
{
|
||||
try
|
||||
{
|
||||
fileFolderService.rename(nodeRef, page.getTitle());
|
||||
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, page.getTitle());
|
||||
nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, nodeName);
|
||||
nodeService.setProperty(nodeRef, ContentModel.PROP_TITLE, page.getTitle());
|
||||
}
|
||||
|
||||
@@ -251,7 +262,7 @@ public class WikiServiceImpl implements WikiService
|
||||
// If we re-named, re-create the object
|
||||
if(renamed)
|
||||
{
|
||||
page = buildPage(nodeRef, page.getContainerNodeRef(), page.getTitle(), page.getContents());
|
||||
page = buildPage(nodeRef, page.getContainerNodeRef(), nodeName, page.getContents());
|
||||
}
|
||||
|
||||
// All done
|
||||
|
@@ -186,6 +186,7 @@ public class WikiServiceImplTest
|
||||
page = WIKI_SERVICE.createWikiPage(
|
||||
WIKI_SITE.getShortName(), "Title", "This Is Some Content"
|
||||
);
|
||||
testNodesToTidy.add(page.getNodeRef());
|
||||
|
||||
|
||||
// Check it
|
||||
@@ -201,11 +202,13 @@ public class WikiServiceImplTest
|
||||
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());
|
||||
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());
|
||||
@@ -217,6 +220,46 @@ public class WikiServiceImplTest
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -503,7 +546,7 @@ public class WikiServiceImplTest
|
||||
* Checks that the correct permission checking occurs on fetching
|
||||
* links listings (which go through canned queries)
|
||||
*/
|
||||
@Test public void linksListingPermissionsChecking() throws Exception
|
||||
@Test public void pagesListingPermissionsChecking() throws Exception
|
||||
{
|
||||
PagingRequest paging = new PagingRequest(10);
|
||||
PagingResults<WikiPageInfo> results;
|
||||
|
Reference in New Issue
Block a user