mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)
57027: Merged V4.2-BUG-FIX (4.2.1) to HEAD-BUG-FIX (Cloud/4.3) 56494: Merged HEAD-BUG-FIX to V4.2-BUG-FIX (4.2.1) 55500: <<NOT IN 4.1.6>> Merged V4.1-BUG-FIX (4.1.7) to HEAD-BUG-FIX (4.2) 55434: Merged DEV to V4.1-BUG-FIX (4.1.7) 54939 : MNT-9413 : NullPointerException thrown when a wiki page with a null title is renamed using Share - Using wiki page name, if page title isn't provided - Unit test was added git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@61660 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -78,7 +78,7 @@ public class WikiPageMovePost extends AbstractWikiWebScript
|
|||||||
|
|
||||||
|
|
||||||
// Have the page re-named, if possible
|
// Have the page re-named, if possible
|
||||||
String oldTitle = page.getTitle();
|
String oldTitle = page.getTitle().length() == 0 ? pageTitle : page.getTitle();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
page.setTitle(newTitle);
|
page.setTitle(newTitle);
|
||||||
|
@@ -273,46 +273,62 @@ public class WikiRestApiTest extends BaseWebScriptTest
|
|||||||
private JSONObject createOrUpdatePage(String title, String contents, String version, int expectedStatus)
|
private JSONObject createOrUpdatePage(String title, String contents, String version, int expectedStatus)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
String name = title.replace(' ', '_');
|
return createOrUpdatePage(null, title, contents, version, expectedStatus);
|
||||||
|
}
|
||||||
|
|
||||||
JSONObject json = new JSONObject();
|
/**
|
||||||
json.put("site", SITE_SHORT_NAME_WIKI);
|
* Creates a single wiki page based on the supplied details
|
||||||
json.put("title", title);
|
*/
|
||||||
json.put("pagecontent", contents);
|
private JSONObject createOrUpdatePage(String pageName, String title, String contents, String version, int expectedStatus) throws Exception
|
||||||
json.put("tags", "");
|
{
|
||||||
json.put("page", "wiki-page"); // TODO Is this really needed?
|
String name = null;
|
||||||
|
if (pageName == null)
|
||||||
|
{
|
||||||
|
name = title.replace(' ', '_');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
name = pageName;
|
||||||
|
}
|
||||||
|
|
||||||
if (version == null || "force".equals(version))
|
JSONObject json = new JSONObject();
|
||||||
{
|
json.put("site", SITE_SHORT_NAME_WIKI);
|
||||||
// Allow the save as-is, no versioning check
|
json.put("title", title);
|
||||||
json.put("forceSave", "true"); // Allow the save as-is
|
json.put("pagecontent", contents);
|
||||||
}
|
json.put("tags", "");
|
||||||
else
|
json.put("page", "wiki-page"); // TODO Is this really needed?
|
||||||
{
|
|
||||||
if ("none".equals(version))
|
|
||||||
{
|
|
||||||
// No versioning
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
json.put("currentVersion", version);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Response response = sendRequest(new PutRequest(URL_WIKI_UPDATE + name, json.toString(), "application/json"), expectedStatus);
|
if (version == null || "force".equals(version))
|
||||||
if (expectedStatus == Status.STATUS_OK)
|
{
|
||||||
{
|
// Allow the save as-is, no versioning check
|
||||||
JSONObject result = new JSONObject(response.getContentAsString());
|
json.put("forceSave", "true"); // Allow the save as-is
|
||||||
if (result.has("page"))
|
}
|
||||||
{
|
else
|
||||||
return result.getJSONObject("page");
|
{
|
||||||
}
|
if ("none".equals(version))
|
||||||
return result;
|
{
|
||||||
}
|
// No versioning
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
return null;
|
{
|
||||||
}
|
json.put("currentVersion", version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Response response = sendRequest(new PutRequest(URL_WIKI_UPDATE + name, json.toString(), "application/json"), expectedStatus);
|
||||||
|
if (expectedStatus == Status.STATUS_OK)
|
||||||
|
{
|
||||||
|
JSONObject result = new JSONObject(response.getContentAsString());
|
||||||
|
if (result.has("page"))
|
||||||
|
{
|
||||||
|
return result.getJSONObject("page");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -549,6 +565,56 @@ public class WikiRestApiTest extends BaseWebScriptTest
|
|||||||
assertEquals(PAGE_TITLE_ONE, page.getString("title"));
|
assertEquals(PAGE_TITLE_ONE, page.getString("title"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testRenamePageWithEmptyTitle() throws Exception
|
||||||
|
{
|
||||||
|
JSONObject page;
|
||||||
|
String name = System.currentTimeMillis()+"";
|
||||||
|
String name2 = System.currentTimeMillis()+1+"";
|
||||||
|
|
||||||
|
// Create a page
|
||||||
|
page = createOrUpdatePage(name, name, null, Status.STATUS_OK);
|
||||||
|
assertEquals("Incorrect JSON: " + page.toString(), true, page.has("title"));
|
||||||
|
|
||||||
|
// Fetch it and check
|
||||||
|
page = getPage(name, Status.STATUS_OK);
|
||||||
|
assertEquals(name, page.getString("name"));
|
||||||
|
assertEquals(name, page.getString("title"));
|
||||||
|
|
||||||
|
//update title
|
||||||
|
SiteInfo site = siteService.getSite(SITE_SHORT_NAME_WIKI);
|
||||||
|
WikiPageInfo pageInfo = wikiService.getWikiPage(site.getShortName(), name);
|
||||||
|
NodeRef pageRef = pageInfo.getNodeRef();
|
||||||
|
nodeService.setProperty(pageRef, ContentModel.PROP_TITLE, "");
|
||||||
|
|
||||||
|
// Fetch it and check
|
||||||
|
page = getPage(name, Status.STATUS_OK);
|
||||||
|
JSONArray versions = page.getJSONArray("versionhistory");
|
||||||
|
|
||||||
|
int maxVersionIndex = versions.length()-1;
|
||||||
|
double vNum = Double.parseDouble(versions.getJSONObject(maxVersionIndex).getString("version"));
|
||||||
|
String newTitle =versions.getJSONObject(maxVersionIndex).getString("title");
|
||||||
|
for (int i = versions.length()-2; i>=0; i--)
|
||||||
|
{
|
||||||
|
JSONObject version = versions.getJSONObject(i);
|
||||||
|
String ver = version.getString("version");
|
||||||
|
if (Double.parseDouble(ver)>vNum)
|
||||||
|
{
|
||||||
|
maxVersionIndex = i;
|
||||||
|
vNum = Double.parseDouble(ver);
|
||||||
|
newTitle =versions.getJSONObject(maxVersionIndex).getString("title");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(name, page.getString("name"));
|
||||||
|
assertEquals("", newTitle);
|
||||||
|
|
||||||
|
renamePage(name, name2, Status.STATUS_OK);
|
||||||
|
|
||||||
|
// Fetch it at the new address
|
||||||
|
page = getPage(name2, Status.STATUS_OK);
|
||||||
|
assertEquals(name2, page.getString("name"));
|
||||||
|
assertEquals(name2, page.getString("title"));
|
||||||
|
}
|
||||||
|
|
||||||
public void testVersioning() throws Exception
|
public void testVersioning() throws Exception
|
||||||
{
|
{
|
||||||
WikiPageInfo wikiInfo;
|
WikiPageInfo wikiInfo;
|
||||||
|
Reference in New Issue
Block a user