Package org.togglz.core.repository

Examples of org.togglz.core.repository.FeatureState


                    try {

                        if (resultSet.next()) {

                            boolean enabled = resultSet.getInt(Columns.FEATURE_ENABLED) > 0;
                            FeatureState state = new FeatureState(feature, enabled);

                            String strategyId = resultSet.getString(Columns.STRATEGY_ID);
                            if (Strings.isNotBlank(strategyId)) {
                                state.setStrategyId(strategyId.trim());
                            }

                            String paramData = resultSet.getString(Columns.STRATEGY_PARAMS);
                            if (Strings.isNotBlank(paramData)) {
                                Map<String, String> params = serializer.deserialize(paramData);
                                for (Entry<String, String> param : params.entrySet()) {
                                    state.setParameter(param.getKey(), param.getValue());
                                }
                            }

                            return state;
View Full Code Here


    @Override
    public boolean isActive(Feature feature) {

        Validate.notNull(feature, "feature is required");

        FeatureState state = stateRepository.getFeatureState(feature);

        if (state == null) {
            return getMetaData(feature).isEnabledByDefault();
        }

        if (state.isEnabled()) {

            // if no strategy is selected, the decision is simple
            String strategyId = state.getStrategyId();
            if (strategyId == null) {
                return true;
            }

            FeatureUser user = userProvider.getCurrentUser();
View Full Code Here

    }

    @Override
    public FeatureState getFeatureState(Feature feature) {
        Validate.notNull(feature, "feature is required");
        FeatureState state = stateRepository.getFeatureState(feature);
        if (state == null) {
            boolean enabled = getMetaData(feature).isEnabledByDefault();
            state = new FeatureState(feature, enabled);
        }
        return state;
    }
View Full Code Here

        for (int i = 0; i < NUMBER_OF_FEATURES; i++) {

            // build up a feature state containing some data
            String name = "FEATURE" + i;
            Feature feature = new TestFeature(name);
            final FeatureState state = new FeatureState(feature)
                .setStrategyId("strategy-for-" + name)
                .setParameter("param-of-" + name, "some-value-of-" + name);

            // queue a thread writing that state
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    repo.setFeatureState(state);
                }
            });

        }

        // Step 2: Wait for all threads to finish
        executor.shutdown();
        executor.awaitTermination(5, TimeUnit.SECONDS);

        // Step 3: Verify the state written to the repository
        for (int i = 0; i < NUMBER_OF_FEATURES; i++) {

            // read the state
            String name = "FEATURE" + i;
            TestFeature feature = new TestFeature(name);
            FeatureState state = repo.getFeatureState(feature);

            // verify that the state is as expected
            assertThat(state).isNotNull();
            assertThat(state.getStrategyId()).isEqualTo("strategy-for-" + name);
            assertThat(state.getParameterMap())
                .hasSize(1)
                .contains(MapEntry.entry("param-of-" + name, "some-value-of-" + name));

        }
View Full Code Here

    @Before
    public void setup() {
        delegate = Mockito.mock(StateRepository.class);
        // the mock supports the ENUM
        Mockito.when(delegate.getFeatureState(DummyFeature.TEST))
            .thenReturn(new FeatureState(DummyFeature.TEST, true));
        // and NamedFeature
        Mockito.when(delegate.getFeatureState(new NamedFeature("TEST")))
            .thenReturn(new FeatureState(DummyFeature.TEST, true));
    }
View Full Code Here

            assertTrue(repository.getFeatureState(DummyFeature.TEST).isEnabled());
            Thread.sleep(10);
        }

        // now modify the feature state
        repository.setFeatureState(new FeatureState(DummyFeature.TEST, true));

        // do some lookups
        for (int i = 0; i < 5; i++) {
            assertTrue(repository.getFeatureState(DummyFeature.TEST).isEnabled());
            Thread.sleep(10);
View Full Code Here

    }

    @Override
    public StateRepository getStateRepository() {
        InMemoryStateRepository repository = new InMemoryStateRepository();
        repository.setFeatureState(new FeatureState(JspTaglibFeature.ACTIVE_FEATURE, true));
        repository.setFeatureState(new FeatureState(JspTaglibFeature.INACTIVE_FEATURE, false));
        return repository;
    }
View Full Code Here

    public FeatureState toFeatureState() {

        Validate.isTrue(getValidationErrors().isEmpty(),
            "Calling toFeatureState() is only allowed for a valid model");

        FeatureState state = new FeatureState(feature, enabled);

        if (strategy != null) {

            state.setStrategyId(strategy.getId());

            for (ParameterModel param : strategy.getParameters()) {
                state.setParameter(param.getId(), Strings.trimToNull(param.getValue()));
            }

        }

        return state;
View Full Code Here

        DBObject result = togglzCollection().findOne(queryFor(feature));

        if (result != null) {

            FeatureState state = new FeatureState(feature);

            Object enabledValue = result.get(FIELD_ENABLED);
            if (enabledValue instanceof Boolean) {
                state.setEnabled(((Boolean) enabledValue).booleanValue());
            }

            Object strategyValue = result.get(FIELD_STRATEGY);
            if (strategyValue != null) {
                state.setStrategyId(strategyValue.toString().trim());
            }

            Object paramsValue = result.get(FIELD_PARAMS);
            if (paramsValue instanceof DBObject) {
                DBObject params = (DBObject) paramsValue;
                for (String key : params.keySet()) {
                    state.setParameter(key, params.get(key).toString().trim());
                }

            }

            return state;
View Full Code Here

        IndexPageTabView tabView = new IndexPageTabView(strategies);

        for (Feature feature : featureManager.getFeatures()) {
            FeatureMetaData metadata = featureManager.getMetaData(feature);
            FeatureState featureState = featureManager.getFeatureState(feature);
            tabView.add(feature, metadata, featureState);
        }

        Map<String, Object> model = new HashMap<String, Object>();
        model.put("tabView", tabView);
View Full Code Here

TOP

Related Classes of org.togglz.core.repository.FeatureState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.