use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class XarExtensionHandlerTest method testUpgradeOnWiki.
@Test
public void testUpgradeOnWiki() throws Throwable {
install(this.localXarExtensiontId1, "wiki", this.contextUser);
verifyHasAdminRight(2);
// Do some local modifications
XWikiDocument deletedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "deletedpage"), getXWikiContext());
this.oldcore.getSpyXWiki().deleteDocument(deletedpage, getXWikiContext());
XWikiDocument modifieddeletedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "modifieddeletedpage"), getXWikiContext());
this.oldcore.getSpyXWiki().deleteDocument(modifieddeletedpage, getXWikiContext());
XWikiDocument pagewithobject = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "pagewithobject"), getXWikiContext());
pagewithobject.removeXObjects(new LocalDocumentReference("XWiki", "XWikiGroups"));
this.oldcore.getSpyXWiki().saveDocument(pagewithobject, getXWikiContext());
XWikiDocument deletedpagewithmodifications = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space1", "modified"), getXWikiContext());
deletedpagewithmodifications.setContent("modified content");
// upgrade
install(this.localXarExtensiontId2, "wiki", this.contextUser);
verifyHasAdminRight(3);
// validate
// samespace.samepage
XWikiDocument samepage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "samespace", "samepage"), getXWikiContext());
Assert.assertFalse("Document samespace has been removed from the database", samepage.isNew());
Assert.assertEquals("Wrong versions", "1.1", samepage.getVersion());
// space.page
XWikiDocument modifiedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "page"), getXWikiContext());
Assert.assertFalse("Document wiki.space.page has not been saved in the database", modifiedpage.isNew());
Assert.assertEquals("Wrong content", "content 2", modifiedpage.getContent());
Assert.assertEquals("Wrong author", this.contextUser, modifiedpage.getAuthorReference());
Assert.assertEquals("Wrong versions", "2.1", modifiedpage.getVersion());
Assert.assertEquals("Wrong version", Locale.ROOT, modifiedpage.getLocale());
Assert.assertEquals("Wrong customclass", "customclass2", modifiedpage.getCustomClass());
Assert.assertEquals("Wrong defaultTemplate", "defaultTemplate2", modifiedpage.getDefaultTemplate());
Assert.assertEquals("Wrong hidden", true, modifiedpage.isHidden());
Assert.assertEquals("Wrong ValidationScript", "validationScript2", modifiedpage.getValidationScript());
BaseClass baseClass = modifiedpage.getXClass();
Assert.assertNotNull(baseClass.getField("property"));
Assert.assertEquals("property", baseClass.getField("property").getName());
Assert.assertSame(NumberClass.class, baseClass.getField("property").getClass());
XWikiAttachment attachment = modifiedpage.getAttachment("attachment.txt");
Assert.assertNotNull(attachment);
Assert.assertEquals("attachment.txt", attachment.getFilename());
Assert.assertEquals(18, attachment.getContentLongSize(getXWikiContext()));
Assert.assertEquals("attachment content", IOUtils.toString(attachment.getContentInputStream(getXWikiContext()), StandardCharsets.UTF_8));
// space2.page2
XWikiDocument newPage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space2", "page2"), getXWikiContext());
Assert.assertFalse("Document wiki:space2.page2 has not been saved in the database", newPage.isNew());
// space1.page1
XWikiDocument removedPage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space1", "page1"), getXWikiContext());
Assert.assertTrue("Document wiki:space1.page1 has not been removed from the database", removedPage.isNew());
// space.deletedpage
deletedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "deletedpage"), getXWikiContext());
Assert.assertTrue("Document wiki:space.deleted has been restored", deletedpage.isNew());
// space.modifieddeletedpage
modifieddeletedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "modifieddeletedpage"), getXWikiContext());
Assert.assertTrue("Document wiki:space.modifieddeletedpage has been restored", modifieddeletedpage.isNew());
// space.pagewithobject
pagewithobject = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "pagewithobject"), getXWikiContext());
Assert.assertNull("Document wiki:space.pagewithobject does not contain an XWiki.XWikiGroups object", pagewithobject.getXObject(new LocalDocumentReference("XWiki", "XWikiGroups")));
// space1.modified
XWikiDocument space1modified = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space1", "modified"), getXWikiContext());
Assert.assertFalse("Document wiki:space.modified has been removed from the database", space1modified.isNew());
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class XarExtensionPlan method getPreviousXarExtensionPlanEntry.
public XarExtensionPlanEntry getPreviousXarExtensionPlanEntry(DocumentReference documentReference) {
String wiki = documentReference.getWikiReference().getName();
LocalDocumentReference localDocumentReference = new LocalDocumentReference(documentReference);
return getPreviousXarExtensionPlanEntry(wiki, localDocumentReference);
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class XarExtensionPlan method containsNewPage.
public boolean containsNewPage(DocumentReference documentReference) {
WikiReference wikiReference = documentReference.getWikiReference();
LocalDocumentReference localDocumentReference = new LocalDocumentReference(documentReference);
return containsNewPage(wikiReference, localDocumentReference);
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class XarExtensionPlan method getPreviousXWikiDocument.
public XWikiDocument getPreviousXWikiDocument(DocumentReference documentReference, Packager packager) throws XarException, IOException {
WikiReference wikiReference = documentReference.getWikiReference();
LocalDocumentReference localDocumentReference = new LocalDocumentReference(documentReference);
return getPreviousXWikiDocument(wikiReference, localDocumentReference, packager);
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class WikiUserFromXEMMigration method upgradeWorkspaceCandidacies.
/**
* Convert the old WorkspaceManager.WorkspaceCandidateMemberClass objects to the new candidacies format.
*
* @param wikiId id of the wiki to upgrade
* @throws XWikiException if problems occur
*/
private void upgradeWorkspaceCandidacies(String wikiId) throws XWikiException {
XWikiContext xcontext = getXWikiContext();
XWiki xwiki = xcontext.getWiki();
// We need to get the document that holds the candidacies
DocumentReference candidaciesDocumentReference = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "XWikiAllGroup");
XWikiDocument candidaciesDocument = xwiki.getDocument(candidaciesDocumentReference, xcontext);
// We need to get all the old candidacies
DocumentReference oldCandidateClassReference = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "WorkspaceCandidateMemberClass");
List<BaseObject> candidacyObjects = candidaciesDocument.getXObjects(oldCandidateClassReference);
if (candidacyObjects != null) {
LocalDocumentReference newCandidateClassReference = WikiCandidateMemberClassInitializer.REFERENCE;
for (BaseObject oldObject : candidacyObjects) {
if (oldObject == null) {
continue;
}
// Transform the candidacy to the new class
BaseObject newObject = candidaciesDocument.newXObject(newCandidateClassReference, xcontext);
newObject.setStringValue(WikiCandidateMemberClassInitializer.FIELD_TYPE, oldObject.getStringValue("type"));
newObject.setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, oldObject.getStringValue("status"));
newObject.setStringValue(WikiCandidateMemberClassInitializer.FIELD_USER, oldObject.getStringValue("userName"));
newObject.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_USER_COMMENT, oldObject.getLargeStringValue("userComment"));
newObject.setStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN, oldObject.getStringValue("reviewer"));
newObject.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_COMMENT, oldObject.getLargeStringValue("reviewerComment"));
newObject.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_PRIVATE_COMMENT, oldObject.getLargeStringValue("reviewerPrivateComment"));
newObject.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CREATION, oldObject.getDateValue("date"));
newObject.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE, oldObject.getDateValue("resolutionDate"));
// Remove the old object
candidaciesDocument.removeXObject(oldObject);
}
// Save
xwiki.saveDocument(candidaciesDocument, "Upgrade candidacies from the old Workspace Application to the " + "new Wiki Application.", xcontext);
}
}
Aggregations