Search in sources :

Example 86 with XWikiDocument

use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.

the class DefaultWikiUserManager method acceptRequest.

@Override
public void acceptRequest(MemberCandidacy request, String message, String privateComment) throws WikiUserManagerException {
    // Add the user to the members
    addMember(request.getUserId(), request.getWikiId());
    // Then, update the candidacy object
    XWikiContext xcontext = xcontextProvider.get();
    // Set the values
    request.setAdminId(documentReferenceSerializer.serialize(xcontext.getUserReference()));
    request.setAdminComment(message);
    request.setAdminPrivateComment(privateComment);
    request.setStatus(MemberCandidacy.Status.ACCEPTED);
    request.setDateOfClosure(new Date());
    // Get the group document
    XWikiDocument groupDoc = getMembersGroupDocument(request.getWikiId());
    // Get the candidacy object
    BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, request.getId());
    // Set the new values
    object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN, request.getAdminId());
    object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_COMMENT, request.getAdminComment());
    object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_PRIVATE_COMMENT, request.getAdminPrivateComment());
    object.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE, request.getDateOfClosure());
    object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, request.getStatus().name().toLowerCase());
    // Save the document
    saveGroupDocument(groupDoc, String.format("Accept join request from user [%s]", request.getUserId()));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) Date(java.util.Date) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 87 with XWikiDocument

use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.

the class DefaultWikiUserManager method invite.

@Override
public MemberCandidacy invite(String userId, String wikiId, String message) throws WikiUserManagerException {
    XWikiContext xcontext = xcontextProvider.get();
    // Create the candidacy
    MemberCandidacy candidacy = new MemberCandidacy(wikiId, userId, MemberCandidacy.CandidateType.INVITATION);
    candidacy.setUserComment(message);
    candidacy.setAdminId(documentReferenceSerializer.serialize(xcontext.getUserReference()));
    // Get the group document
    XWikiDocument groupDoc = getMembersGroupDocument(wikiId);
    // Add a candidacy object
    try {
        int objectNumber = groupDoc.createXObject(WikiCandidateMemberClassInitializer.REFERENCE, xcontext);
        candidacy.setId(objectNumber);
        BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, objectNumber);
        object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_USER, candidacy.getUserId());
        object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN, candidacy.getAdminId());
        object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_COMMENT, message);
        object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, candidacy.getStatus().name().toLowerCase());
        object.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CREATION, candidacy.getDateOfCreation());
        object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_TYPE, candidacy.getType().name().toLowerCase());
    } catch (XWikiException e) {
        throw new WikiUserManagerException("Failed to create a new invitation object.", e);
    }
    // Save the document
    saveGroupDocument(groupDoc, String.format("[%s] is invited to join the wiki.", userId));
    return candidacy;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 88 with XWikiDocument

use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.

the class WikiUserFromXEMMigration method hibernateMigrate.

@Override
protected void hibernateMigrate() throws DataMigrationException, XWikiException {
    // Context, XWiki
    XWikiContext context = getXWikiContext();
    XWiki xwiki = context.getWiki();
    // Current wiki
    String currentWikiId = wikiDescriptorManager.getCurrentWikiId();
    // Get the old wiki descriptor
    DocumentReference oldWikiDescriptorReference = new DocumentReference(wikiDescriptorManager.getMainWikiId(), XWiki.SYSTEM_SPACE, String.format("XWikiServer%s", StringUtils.capitalize(currentWikiId)));
    XWikiDocument oldWikiDescriptor = xwiki.getDocument(oldWikiDescriptorReference, context);
    // Try to get the old workspace object
    DocumentReference oldClassDocument = new DocumentReference(wikiDescriptorManager.getMainWikiId(), WORKSPACE_CLASS_SPACE, WORKSPACE_CLASS_PAGE);
    BaseObject oldObject = oldWikiDescriptor.getXObject(oldClassDocument);
    // Upgrade depending of the type
    if (oldObject != null || isWorkspaceTemplate(currentWikiId)) {
        // It's a workspace
        upgradeWorkspace(oldObject, currentWikiId, oldWikiDescriptor);
    } else {
        // It's a regular subwiki
        upgradeRegularSubwiki(currentWikiId);
    }
}
Also used : 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)

Example 89 with XWikiDocument

use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.

the class WikiUserFromXEMMigrationTest method upgradeRegularSubWiki.

@Test
public void upgradeRegularSubWiki() throws Exception {
    // Mocks
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("subwiki");
    XWikiDocument oldDescriptorDocument = mock(XWikiDocument.class);
    when(xwiki.getDocument(eq(new DocumentReference("mainWiki", XWiki.SYSTEM_SPACE, "XWikiServerSubwiki")), any(XWikiContext.class))).thenReturn(oldDescriptorDocument);
    when(oldDescriptorDocument.getXObject(eq(new DocumentReference("mainWiki", "WorkspaceManager", "WorkspaceClass")))).thenReturn(null);
    // Run
    mocker.getComponentUnderTest().hibernateMigrate();
    // Verify
    WikiUserConfiguration expectedConfiguration = new WikiUserConfiguration();
    expectedConfiguration.setUserScope(UserScope.LOCAL_AND_GLOBAL);
    expectedConfiguration.setMembershipType(MembershipType.INVITE);
    verify(wikiUserConfigurationHelper).saveConfiguration(eq(expectedConfiguration), eq("subwiki"));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiUserConfiguration(org.xwiki.wiki.user.WikiUserConfiguration) XWikiContext(com.xpn.xwiki.XWikiContext) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 90 with XWikiDocument

use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.

the class WikiUserFromXEMMigrationTest method upgradeOldWorkspaceTemplate.

@Test
public void upgradeOldWorkspaceTemplate() throws Exception {
    // Mocks about the descriptor
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("workspacetemplate");
    XWikiDocument oldDescriptorDocument = mock(XWikiDocument.class);
    when(xwiki.getDocument(eq(new DocumentReference("mainWiki", XWiki.SYSTEM_SPACE, "XWikiServerWorkspacetemplate")), any(XWikiContext.class))).thenReturn(oldDescriptorDocument);
    // Mock about the workspace special page
    when(xwiki.exists(eq(new DocumentReference("workspacetemplate", "XWiki", "ManageWorkspace")), any(XWikiContext.class))).thenReturn(true);
    // Mocks about candidacies
    DocumentReference memberGroupRef = new DocumentReference("workspacetemplate", XWiki.SYSTEM_SPACE, "XWikiAllGroup");
    XWikiDocument memberGroupDoc = mock(XWikiDocument.class);
    when(xwiki.getDocument(eq(memberGroupRef), any(XWikiContext.class))).thenReturn(memberGroupDoc);
    // Run
    mocker.getComponentUnderTest().hibernateMigrate();
    // Verify the user configuration is accurate
    WikiUserConfiguration expectedConfiguration = new WikiUserConfiguration();
    expectedConfiguration.setUserScope(UserScope.GLOBAL_ONLY);
    expectedConfiguration.setMembershipType(MembershipType.INVITE);
    verify(wikiUserConfigurationHelper).saveConfiguration(eq(expectedConfiguration), eq("workspacetemplate"));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiUserConfiguration(org.xwiki.wiki.user.WikiUserConfiguration) XWikiContext(com.xpn.xwiki.XWikiContext) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)869 DocumentReference (org.xwiki.model.reference.DocumentReference)469 BaseObject (com.xpn.xwiki.objects.BaseObject)318 Test (org.junit.Test)284 XWikiContext (com.xpn.xwiki.XWikiContext)232 XWikiException (com.xpn.xwiki.XWikiException)178 ArrayList (java.util.ArrayList)99 XWiki (com.xpn.xwiki.XWiki)97 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)86 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)71 Document (com.xpn.xwiki.api.Document)48 EntityReference (org.xwiki.model.reference.EntityReference)48 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)41 Date (java.util.Date)41 IOException (java.io.IOException)40 HashMap (java.util.HashMap)33 QueryException (org.xwiki.query.QueryException)27 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)25 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)23 IncludeServletAsString (com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)23