use of org.uberfire.preferences.shared.PreferenceScope in project kie-wb-common by kiegroup.
the class WorkbenchPreferenceScopeResolutionStrategiesImpl method getUserInfoFor.
@Override
public PreferenceScopeResolutionStrategyInfo getUserInfoFor(final String scopeType, final String scopeKey) {
PreferenceScopeResolutionStrategy scopeResolutionStrategy;
if (scopeType != null) {
PreferenceScope userScope = scopeFactory.createScope(WorkbenchPreferenceScopes.USER);
PreferenceScope userScopedScope;
if (scopeKey != null) {
userScopedScope = scopeFactory.createScope(scopeType, scopeKey);
} else {
userScopedScope = scopeFactory.createScope(scopeType);
}
PreferenceScope projectUserScope = scopeFactory.createScope(userScope, userScopedScope);
scopeResolutionStrategy = new WorkbenchPreferenceScopeResolutionStrategy(scopeFactory, projectUserScope);
} else {
scopeResolutionStrategy = new WorkbenchPreferenceScopeResolutionStrategy(scopeFactory);
}
return scopeResolutionStrategy.getInfo();
}
use of org.uberfire.preferences.shared.PreferenceScope in project kie-wb-common by kiegroup.
the class WorkbenchPreferenceScopeResolver method getScopeFromOrder.
private PreferenceScope getScopeFromOrder(final String... scopeTypes) {
for (PreferenceScope scope : order) {
boolean match = true;
PreferenceScope currentScope = scope;
for (int i = 0; i < scopeTypes.length; i++) {
if (currentScope == null || !currentScope.type().equals(scopeTypes[i])) {
match = false;
break;
}
currentScope = currentScope.childScope();
}
if (match && currentScope == null) {
return scope;
}
}
throw new InvalidPreferenceScopeException("The passed scope types are invalid.");
}
use of org.uberfire.preferences.shared.PreferenceScope in project kie-wb-common by kiegroup.
the class WorkbenchPreferenceScopeResolutionStrategyTest method defaultScopeInfoTest.
@Test
public void defaultScopeInfoTest() {
final List<PreferenceScope> order = defaultPreferenceScopeResolutionStrategy.getInfo().order();
assertEquals(2, order.size());
final PreferenceScope firstScope = order.get(0);
assertEquals("user", firstScope.type());
assertEquals("admin", firstScope.key());
final PreferenceScope secondScope = order.get(1);
assertEquals("global", secondScope.type());
assertEquals("global", secondScope.key());
final PreferenceScope defaultScope = defaultPreferenceScopeResolutionStrategy.getInfo().defaultScope();
assertEquals("user", defaultScope.type());
assertEquals("admin", defaultScope.key());
}
use of org.uberfire.preferences.shared.PreferenceScope in project kie-wb-common by kiegroup.
the class WorkbenchPreferenceScopeResolverTest method setup.
@Before
public void setup() {
final List<PreferenceScope> order = new ArrayList<>();
globalScope = new PreferenceScopeImpl("global", "global", null);
userScope = new PreferenceScopeImpl("user", "my-user", null);
projectScope = new PreferenceScopeImpl("user", "my-user", new PreferenceScopeImpl("project", "my-project", null));
order.add(projectScope);
order.add(userScope);
order.add(globalScope);
scopeResolver = new WorkbenchPreferenceScopeResolver(order);
}
use of org.uberfire.preferences.shared.PreferenceScope in project kie-wb-common by kiegroup.
the class DefaultAdminPageHelperTest method preferencesShouldBeSavedOnGlobalScopeWhenUserHasPermissionTest.
@Test
public void preferencesShouldBeSavedOnGlobalScopeWhenUserHasPermissionTest() {
final PreferenceScope globalScope = mock(PreferenceScope.class);
doReturn(globalScope).when(scopeFactory).createScope(GuvnorPreferenceScopes.GLOBAL);
doReturn(true).when(authorizationManager).authorize(eq(WorkbenchFeatures.EDIT_GLOBAL_PREFERENCES), any());
defaultAdminPageHelper.setup();
verify(adminPage, times(3)).addPreference(anyString(), anyString(), anyString(), anyString(), anyString(), any(PreferenceScope.class), eq(AdminPageOptions.WITH_BREADCRUMBS));
verify(adminPage, times(3)).addPreference(anyString(), anyString(), anyString(), anyString(), anyString(), eq(globalScope), eq(AdminPageOptions.WITH_BREADCRUMBS));
}
Aggregations