Search in sources :

Example 46 with BaseObject

use of com.xpn.xwiki.objects.BaseObject 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 47 with BaseObject

use of com.xpn.xwiki.objects.BaseObject 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 48 with BaseObject

use of com.xpn.xwiki.objects.BaseObject 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 49 with BaseObject

use of com.xpn.xwiki.objects.BaseObject 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 50 with BaseObject

use of com.xpn.xwiki.objects.BaseObject 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

BaseObject (com.xpn.xwiki.objects.BaseObject)484 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)309 DocumentReference (org.xwiki.model.reference.DocumentReference)225 Test (org.junit.Test)137 XWikiException (com.xpn.xwiki.XWikiException)102 XWikiContext (com.xpn.xwiki.XWikiContext)99 ArrayList (java.util.ArrayList)92 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)69 EntityReference (org.xwiki.model.reference.EntityReference)42 XWiki (com.xpn.xwiki.XWiki)41 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)40 List (java.util.List)30 Date (java.util.Date)24 BaseProperty (com.xpn.xwiki.objects.BaseProperty)23 Document (com.xpn.xwiki.api.Document)22 HashMap (java.util.HashMap)21 QueryException (org.xwiki.query.QueryException)18 AbstractComponentTest (com.celements.common.test.AbstractComponentTest)16 IOException (java.io.IOException)16 Vector (java.util.Vector)16