Search in sources :

Example 1 with PreferenceScope

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();
}
Also used : PreferenceScope(org.uberfire.preferences.shared.PreferenceScope) PreferenceScopeResolutionStrategy(org.uberfire.preferences.shared.PreferenceScopeResolutionStrategy)

Example 2 with PreferenceScope

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.");
}
Also used : InvalidPreferenceScopeException(org.uberfire.preferences.shared.impl.exception.InvalidPreferenceScopeException) PreferenceScope(org.uberfire.preferences.shared.PreferenceScope)

Example 3 with PreferenceScope

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());
}
Also used : PreferenceScope(org.uberfire.preferences.shared.PreferenceScope) Test(org.junit.Test)

Example 4 with PreferenceScope

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);
}
Also used : PreferenceScope(org.uberfire.preferences.shared.PreferenceScope) ArrayList(java.util.ArrayList) PreferenceScopeImpl(org.uberfire.preferences.shared.impl.PreferenceScopeImpl) Before(org.junit.Before)

Example 5 with PreferenceScope

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));
}
Also used : PreferenceScope(org.uberfire.preferences.shared.PreferenceScope) Test(org.junit.Test)

Aggregations

PreferenceScope (org.uberfire.preferences.shared.PreferenceScope)9 Test (org.junit.Test)6 PreferenceScopeResolutionStrategyInfo (org.uberfire.preferences.shared.impl.PreferenceScopeResolutionStrategyInfo)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 PreferenceScopeResolutionStrategy (org.uberfire.preferences.shared.PreferenceScopeResolutionStrategy)1 PreferenceScopeImpl (org.uberfire.preferences.shared.impl.PreferenceScopeImpl)1 InvalidPreferenceScopeException (org.uberfire.preferences.shared.impl.exception.InvalidPreferenceScopeException)1