use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class DefaultWikiUserManager method addMemberObject.
private void addMemberObject(XWikiDocument groupDoc, String userId) throws WikiUserManagerException {
try {
XWikiContext xcontext = xcontextProvider.get();
int objectNumber = groupDoc.createXObject(GROUPCLASS_REFERENCE, xcontext);
BaseObject object = groupDoc.getXObject(GROUPCLASS_REFERENCE, objectNumber);
object.set(GROUP_CLASS_MEMBER_FIELD, userId, xcontext);
} catch (XWikiException e) {
throw new WikiUserManagerException("Fail to add a member to the group", e);
}
}
use of com.xpn.xwiki.XWikiException 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.XWikiException in project xwiki-platform by xwiki.
the class WikiUserFromXEMMigration method upgradeWorkspaceConfiguration.
/**
* Convert the old WorkspaceManager.WorkspaceClass objects to the new configuration format.
*
* @param oldObject old workspace object
* @param wikiId id of the wiki to upgrade
* @param oldWikiDescriptor document that holds the old object
* @throws DataMigrationException if problems occur
* @throws XWikiException if problems occur
*/
private void upgradeWorkspaceConfiguration(BaseObject oldObject, String wikiId, XWikiDocument oldWikiDescriptor) throws DataMigrationException, XWikiException {
// Context, XWiki
XWikiContext context = getXWikiContext();
XWiki xwiki = context.getWiki();
// Create the new configuration
WikiUserConfiguration configuration = new WikiUserConfiguration();
// No local users
configuration.setUserScope(UserScope.GLOBAL_ONLY);
// Set the membershipType value
if (oldObject != null) {
// Get the membershipType value
String membershipTypeValue = oldObject.getStringValue("membershipType");
MembershipType membershipType;
try {
membershipType = MembershipType.valueOf(membershipTypeValue.toUpperCase());
} catch (Exception e) {
// Default value
membershipType = MembershipType.INVITE;
}
configuration.setMembershipType(membershipType);
} else {
// If there is no workspace object, we put a default value.
configuration.setMembershipType(MembershipType.INVITE);
}
// Save the new configuration
saveConfiguration(configuration, wikiId);
}
use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class WorkspaceMigrationTest method errorWhenRestoringFromXAR.
@Test
public void errorWhenRestoringFromXAR() throws Exception {
// Mocks about the descriptor
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("workspace");
XWikiDocument oldDescriptorDocument = mock(XWikiDocument.class);
when(xwiki.getDocument(eq(new DocumentReference("mainWiki", XWiki.SYSTEM_SPACE, "XWikiServerWorkspace")), any(XWikiContext.class))).thenReturn(oldDescriptorDocument);
// Mocks about the old workspace object
BaseObject oldWorkspaceObject = mock(BaseObject.class);
when(oldDescriptorDocument.getXObject(eq(new DocumentReference("mainWiki", "WorkspaceManager", "WorkspaceClass")))).thenReturn(oldWorkspaceObject);
doThrow(new XWikiException()).when(documentRestorerFromAttachedXAR).restoreDocumentFromAttachedXAR(any(DocumentReference.class), any(String.class), any(List.class));
// Run
mocker.getComponentUnderTest().hibernateMigrate();
// Verify
verify(mocker.getMockedLogger()).error(eq("Error while restoring documents from the Workspace XAR"), any(XWikiException.class));
}
use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class WikiTemplatePropertyGroupProvider method save.
@Override
public void save(WikiPropertyGroup group, String wikiId) throws WikiPropertyGroupException {
XWikiContext context = xcontextProvider.get();
XWiki xwiki = context.getWiki();
WikiTemplatePropertyGroup templateGroup = (WikiTemplatePropertyGroup) group;
try {
XWikiDocument descriptorDocument = wikiDescriptorDocumentHelper.getDocumentFromWikiId(wikiId);
BaseObject object = descriptorDocument.getXObject(WikiTemplateClassDocumentInitializer.SERVER_CLASS, true, context);
object.setIntValue(WikiTemplateClassDocumentInitializer.FIELD_ISWIKITEMPLATE, templateGroup.isTemplate() ? 1 : 0);
// The document must have a creator
if (descriptorDocument.getCreatorReference() == null) {
descriptorDocument.setCreatorReference(context.getUserReference());
}
// The document must have an author
if (descriptorDocument.getAuthorReference() == null) {
descriptorDocument.setAuthorReference(context.getUserReference());
}
xwiki.saveDocument(descriptorDocument, String.format("Changed property group [%s].", GROUP_NAME), context);
} catch (WikiManagerException e) {
throw new WikiPropertyGroupException(String.format(ERROR_MESSAGE_NO_DESCRIPTOR_DOCUMENT, wikiId), e);
} catch (XWikiException e) {
throw new WikiPropertyGroupException("Unable to save descriptor document.", e);
}
}
Aggregations