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()));
}
}
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);
}
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));
}
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));
}
}
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()));
}
Aggregations