Search in sources :

Example 36 with LocalDocumentReference

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());
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 37 with LocalDocumentReference

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);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference)

Example 38 with 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);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) WikiReference(org.xwiki.model.reference.WikiReference)

Example 39 with 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);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) WikiReference(org.xwiki.model.reference.WikiReference)

Example 40 with LocalDocumentReference

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);
    }
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)58 Test (org.junit.Test)28 DocumentReference (org.xwiki.model.reference.DocumentReference)25 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)23 BaseObject (com.xpn.xwiki.objects.BaseObject)19 XWikiContext (com.xpn.xwiki.XWikiContext)10 EntityReference (org.xwiki.model.reference.EntityReference)10 ArrayList (java.util.ArrayList)8 ViewPage (org.xwiki.test.ui.po.ViewPage)6 Page (org.xwiki.rest.model.jaxb.Page)5 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)4 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)4 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)4 Event (org.xwiki.observation.event.Event)4 XWiki (com.xpn.xwiki.XWiki)3 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)2 Principal (java.security.Principal)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2