use of org.xwiki.wiki.user.MembershipType 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 org.xwiki.wiki.user.MembershipType in project xwiki-platform by xwiki.
the class DefaultWikiUserConfigurationHelper method getConfiguration.
@Override
public WikiUserConfiguration getConfiguration(String wikiId) throws WikiUserManagerException {
// Create the configuration object to return
WikiUserConfiguration configuration = new WikiUserConfiguration();
// Get the document
XWikiDocument document = getDocument(wikiId);
// Get the XWiki object
BaseObject object = document.getXObject(WikiUserClassDocumentInitializer.CONFIGURATION_CLASS);
if (object != null) {
// Get the user scope
String scopeValue = object.getStringValue(WikiUserClassDocumentInitializer.FIELD_USERSCOPE);
UserScope userScope;
try {
userScope = UserScope.valueOf(scopeValue.toUpperCase());
} catch (Exception e) {
// Default value
userScope = UserScope.LOCAL_AND_GLOBAL;
}
configuration.setUserScope(userScope);
// Get the membershipType value
String membershipTypeValue = object.getStringValue(WikiUserClassDocumentInitializer.FIELD_MEMBERSHIPTYPE);
MembershipType membershipType;
try {
membershipType = MembershipType.valueOf(membershipTypeValue.toUpperCase());
} catch (Exception e) {
// Default value
membershipType = MembershipType.INVITE;
}
configuration.setMembershipType(membershipType);
}
return configuration;
}
use of org.xwiki.wiki.user.MembershipType 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());
}
use of org.xwiki.wiki.user.MembershipType in project xwiki-platform by xwiki.
the class WikiUserManagerScriptServiceTest method getMembershipType.
@Test
public void getMembershipType() throws Exception {
// Mocks
when(wikiUserManager.getMembershipType("subwiki")).thenReturn(MembershipType.INVITE);
// Test
MembershipType result = mocker.getComponentUnderTest().getMembershipType();
// Asserts
assertEquals(MembershipType.INVITE, result);
}
Aggregations