use of com.xpn.xwiki.objects.BaseObject 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()));
}
use of com.xpn.xwiki.objects.BaseObject 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;
}
use of com.xpn.xwiki.objects.BaseObject 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);
}
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class DefaultSearchSuggestCustomConfigDeleter method deleteSearchSuggestCustomConfig.
@Override
public void deleteSearchSuggestCustomConfig(String wikiId) throws XWikiException {
XWikiContext xcontext = xcontextProvider.get();
XWiki xwiki = xcontext.getWiki();
DocumentReference searchConfigDocRef = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "SearchSuggestConfig");
DocumentReference searchConfigClass = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "SearchSuggestSourceClass");
XWikiDocument searchConfigDoc = xwiki.getDocument(searchConfigDocRef, xcontext);
// Get the config objects
List<BaseObject> objects = searchConfigDoc.getXObjects(searchConfigClass);
if (objects != null) {
boolean found = false;
// Find the object to remove
for (BaseObject object : objects) {
if (object == null) {
continue;
}
// Look if the object is to remove
String name = object.getStringValue("name");
if (name.equals("platform.workspace.searchSuggestSourceWorkspaces")) {
String query = object.getStringValue("query");
String engine = object.getStringValue("engine");
String url = object.getStringValue("url");
if (isSolrObject(query, engine, url) || isLuceneObject(query, engine, url)) {
searchConfigDoc.removeXObject(object);
found = true;
}
}
}
if (found) {
xwiki.saveDocument(searchConfigDoc, "Remove object previously introduced by WorkspaceManager.Install", xcontext);
}
}
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class WorkspacesMigration method isWorkspace.
private boolean isWorkspace(String wikiId) throws DataMigrationException, XWikiException {
// The main wiki is not a workspace
if (wikiId.equals(wikiDescriptorManager.getMainWikiId())) {
return false;
}
// Context, XWiki
XWikiContext context = getXWikiContext();
XWiki xwiki = context.getWiki();
// Get the old wiki descriptor
DocumentReference oldWikiDescriptorReference = new DocumentReference(wikiDescriptorManager.getMainWikiId(), XWiki.SYSTEM_SPACE, String.format("XWikiServer%s", StringUtils.capitalize(wikiId)));
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);
return (oldObject != null) || isWorkspaceTemplate(wikiId);
}
Aggregations