Search in sources :

Example 81 with XWikiDocument

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

the class DefaultWikiUserManager method cancelCandidacy.

@Override
public void cancelCandidacy(MemberCandidacy candidacy) throws WikiUserManagerException {
    // Get the group document
    XWikiDocument groupDoc = getMembersGroupDocument(candidacy.getWikiId());
    // Get the candidacy object
    BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, candidacy.getId());
    // Remove the candidacy, if any
    if (object != null) {
        groupDoc.removeXObject(object);
        saveGroupDocument(groupDoc, String.format("Candidacy [%d] is canceled.", candidacy.getId()));
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 82 with XWikiDocument

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

the class DefaultWikiUserManager method getCandidacy.

@Override
public MemberCandidacy getCandidacy(String wikiId, int candidacyId) throws WikiUserManagerException {
    // Get the group document
    XWikiDocument groupDoc = getMembersGroupDocument(wikiId);
    // Get the candidacy
    BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, candidacyId);
    return readCandidacyFromObject(object, wikiId);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 83 with XWikiDocument

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

the class DefaultWikiUserManager method addMember.

@Override
public void addMember(String userId, String wikiId) throws WikiUserManagerException {
    Collection<String> members = getMembers(wikiId);
    if (members.contains(userId)) {
        // Nothing to do !
        return;
    }
    // Get the group document
    XWikiDocument groupDoc = getMembersGroupDocument(wikiId);
    // Add a member object
    // If the group does not contain any user yet, add an empty member (cf: XWIKI-6275).
    List<BaseObject> memberObjects = groupDoc.getXObjects(GROUPCLASS_REFERENCE);
    if (memberObjects == null || memberObjects.isEmpty()) {
        addMemberObject(groupDoc, "");
    }
    // Add the user
    addMemberObject(groupDoc, userId);
    // Save the document
    saveGroupDocument(groupDoc, String.format("Add [%s] to the group.", userId));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 84 with XWikiDocument

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

the class DefaultWikiUserManager method removeMember.

@Override
public void removeMember(String userId, String wikiId) throws WikiUserManagerException {
    // Get the group document
    XWikiDocument groupDoc = getMembersGroupDocument(wikiId);
    // Get the member objects
    List<BaseObject> objects = groupDoc.getXObjects(GROUPCLASS_REFERENCE);
    if (objects != null) {
        // Get the member objects to remove
        List<BaseObject> objectsToRemove = new ArrayList<>();
        for (BaseObject object : objects) {
            if (object == null) {
                continue;
            }
            String member = object.getStringValue(GROUP_CLASS_MEMBER_FIELD);
            if (userId.equals(member)) {
                objectsToRemove.add(object);
            }
        }
        // Remove them
        for (BaseObject object : objectsToRemove) {
            groupDoc.removeXObject(object);
        }
        // Save the document
        saveGroupDocument(groupDoc, String.format("Remove [%s] from the group.", userId));
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArrayList(java.util.ArrayList) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 85 with XWikiDocument

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

the class DefaultWikiUserManager method acceptInvitation.

@Override
public void acceptInvitation(MemberCandidacy invitation, String message) throws WikiUserManagerException {
    // Add the user to the members
    addMember(invitation.getUserId(), invitation.getWikiId());
    // Set the values
    invitation.setUserComment(message);
    invitation.setStatus(MemberCandidacy.Status.ACCEPTED);
    invitation.setDateOfClosure(new Date());
    // Get the group document
    XWikiDocument groupDoc = getMembersGroupDocument(invitation.getWikiId());
    // Get the candidacy object
    BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, invitation.getId());
    // Set the new values
    object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_USER_COMMENT, invitation.getUserComment());
    object.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE, invitation.getDateOfClosure());
    object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, invitation.getStatus().name().toLowerCase());
    // Save the document
    saveGroupDocument(groupDoc, String.format("User [%s] has accepted to join the wiki. ", invitation.getUserId()));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Date(java.util.Date) BaseObject(com.xpn.xwiki.objects.BaseObject)

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