use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class SaveWikiMetaDataStep method execute.
@Override
public void execute(WikiCreationRequest request) throws WikiCreationException {
try {
String wikiId = request.getWikiId();
// Meta data about the wiki
WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
descriptor.setDescription(request.getDescription());
descriptor.setPrettyName(request.getPrettyName());
descriptor.setOwnerId(request.getOwnerId());
wikiDescriptorManager.saveDescriptor(descriptor);
// Meta data about the templates
wikiTemplateManager.setTemplate(wikiId, request.isTemplate());
// Meta data about the users
wikiUserManager.setUserScope(wikiId, request.getUserScope());
wikiUserManager.setMembershipType(wikiId, request.getMembershipType());
} catch (WikiManagerException | WikiTemplateManagerException | WikiUserManagerException e) {
throw new WikiCreationException(String.format("Failed to set metadata to the wiki [%s].", request.getWikiId()), e);
}
}
use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class DefaultWikiUserManager method saveGroupDocument.
private void saveGroupDocument(XWikiDocument document, String message) throws WikiUserManagerException {
// Get the XWiki objects
XWikiContext xcontext = xcontextProvider.get();
XWiki xwiki = xcontext.getWiki();
// The document should be hidden
document.setHidden(true);
// The document must have a creator
if (document.getCreatorReference() == null) {
document.setCreatorReference(xcontext.getUserReference());
}
// The document must have an author
if (document.getAuthorReference() == null) {
document.setAuthorReference(xcontext.getUserReference());
}
// Save the document
try {
xwiki.saveDocument(document, message, xcontext);
} catch (XWikiException e) {
throw new WikiUserManagerException("Fail to save the member group", e);
}
}
use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class DefaultWikiUserManager method askToJoin.
@Override
public MemberCandidacy askToJoin(String userId, String wikiId, String message) throws WikiUserManagerException {
MemberCandidacy candidacy = new MemberCandidacy(wikiId, userId, MemberCandidacy.CandidateType.REQUEST);
candidacy.setUserComment(message);
// Get the group document
XWikiDocument groupDoc = getMembersGroupDocument(wikiId);
// Add a candidacy object
XWikiContext xcontext = xcontextProvider.get();
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.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_USER_COMMENT, candidacy.getUserComment());
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 join request.", e);
}
// Save the document
saveGroupDocument(groupDoc, String.format("[%s] asks to join the wiki.", userId));
return candidacy;
}
use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class WikiUserManagerScriptService method getCandidacy.
/**
* Get the specified candidacy.
*
* @param wikiId Id of the wiki concerned by the candidacy
* @param candidacyId id of the candidacy
* @return the candidacy or null if problems occur
*/
public MemberCandidacy getCandidacy(String wikiId, int candidacyId) {
// Get the candidacy
MemberCandidacy candidacy = null;
try {
candidacy = wikiUserManager.getCandidacy(wikiId, candidacyId);
// Check the rights
if (!canSeeCandidacy(candidacy)) {
setLastError(new WikiUserManagerScriptServiceException("You are not allowed to see this candidacy."));
candidacy = null;
}
} catch (WikiUserManagerException e) {
setLastError(e);
}
return candidacy;
}
use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class WikiUserManagerScriptServiceTest method getMembershipTypeWithError.
@Test
public void getMembershipTypeWithError() throws Exception {
// Mocks
Exception expectedException = new WikiUserManagerException("Error in getMembershipType");
when(wikiUserManager.getMembershipType("test")).thenThrow(expectedException);
// Test
MembershipType result = mocker.getComponentUnderTest().getMembershipType("test");
// Asserts
assertNull(result);
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
}
Aggregations