Package org.ff4j.core

Examples of org.ff4j.core.FlippingStrategy


     */
    private FlippingStrategy mapStrategy(String featUid, DBObject dbObject) {
        String strategy = (String) dbObject.get(STRATEGY);
        if (strategy != null && !"".equals(strategy)) {
            try {
                FlippingStrategy flipStrategy = (FlippingStrategy) Class.forName(strategy).newInstance();
                flipStrategy.init(featUid, ParameterUtils.toMap((String) dbObject.get(EXPRESSION)));
                return flipStrategy;
            } catch (InstantiationException ie) {
                throw new FeatureAccessException("Cannot instantiate Strategy, no default constructor available", ie);
            } catch (IllegalAccessException iae) {
                throw new FeatureAccessException("Cannot instantiate Strategy, no visible constructor", iae);
View Full Code Here


            // Strategy
            final String strategy = req.getParameter(STRATEGY);
            if (null != strategy && !strategy.isEmpty()) {
                try {
                    Class<?> strategyClass = Class.forName(strategy);
                    FlippingStrategy fstrategy = (FlippingStrategy) strategyClass.newInstance();

                    final String strategyParams = req.getParameter(STRATEGY_INIT);
                    if (null != strategyParams && !strategyParams.isEmpty()) {
                        Map<String, String> initParams = new HashMap<String, String>();
                        String[] params = strategyParams.split(";");
                        for (String currentP : params) {
                            String[] cur = currentP.split("=");
                            if (cur.length < 2) {
                                throw new IllegalArgumentException("Invalid Syntax : param1=val1,val2;param2=val3,val4");
                            }
                            initParams.put(cur[0], cur[1]);
                        }
                        fstrategy.init(featureId, initParams);
                    }
                    fp.setFlippingStrategy(fstrategy);

                } catch (ClassNotFoundException e) {
                    throw new IllegalArgumentException("Cannot find strategy class", e);
View Full Code Here

            // Strategy
            final String strategy = req.getParameter(STRATEGY);
            if (null != strategy && !strategy.isEmpty()) {
                try {
                    Class<?> strategyClass = Class.forName(strategy);
                    FlippingStrategy fstrategy = (FlippingStrategy) strategyClass.newInstance();

                    final String strategyParams = req.getParameter(STRATEGY_INIT);
                    if (null != strategyParams && !strategyParams.isEmpty()) {
                        Map<String, String> initParams = new HashMap<String, String>();
                        String[] params = strategyParams.split(";");
                        for (String currentP : params) {
                            String[] cur = currentP.split("=");
                            if (cur.length < 2) {
                                throw new IllegalArgumentException("Invalid Syntax : param1=val1,val2;param2=val3,val4");
                            }
                            initParams.put(cur[0], cur[1]);
                        }
                        fstrategy.init(featureId, initParams);
                    }
                    fp.setFlippingStrategy(fstrategy);

                } catch (ClassNotFoundException e) {
                    throw new IllegalArgumentException("Cannot find strategy class", e);
View Full Code Here

        }

        // If specific strategy is defined
        boolean flipped = false;
        if (formParams.containsKey(POST_PARAMNAME_FLIPSTRATEGY)) {
            FlippingStrategy fs = FeatureJsonParser.parseFlipStrategyAsJson(uid, formParams.getFirst(POST_PARAMNAME_FLIPSTRATEGY));
            FlippingExecutionContext fec = new FlippingExecutionContext();
            for (String key : formParams.keySet()) {
                if (!POST_PARAMNAME_FLIPSTRATEGY.equals(key) && !POST_PARAMNAME_FEATURE_UID.equals(key)) {
                    fec.putString(key, formParams.getFirst(key));
                }
View Full Code Here

                sb.append("--");
            }
           
            // Colonne Strategy
            sb.append("</td><td>");
            FlippingStrategy fs = currentFeature.getFlippingStrategy();
            if (null != fs) {
                sb.append(fs.getClass().getCanonicalName());
                sb.append("<br/>&nbsp;" + fs.getInitParams());
            } else {
                sb.append("--");
            }
           
            // Colonne 'Holy' Toggle
View Full Code Here

        // Build Flipping Strategy From DataBase
        String strategy = rs.getString(COL_FEAT_STRATEGY);
        if (strategy != null && !"".equals(strategy)) {
            try {
                FlippingStrategy flipStrategy = (FlippingStrategy) Class.forName(strategy).newInstance();
                flipStrategy.init(featUid, ParameterUtils.toMap(rs.getString(COL_FEAT_EXPRESSION)));
                f.setFlippingStrategy(flipStrategy);
            } catch (InstantiationException ie) {
                throw new FeatureAccessException("Cannot instantiate Strategy, no default constructor available", ie);
            } catch (IllegalAccessException iae) {
                throw new FeatureAccessException("Cannot instantiate Strategy, no visible constructor", iae);
View Full Code Here

                } catch (IllegalAccessException e) {
                    throw new IllegalArgumentException("ff4j-aop: Cannot instanciate alterbean " + strategyClassName
                            + " please check constructor visibility", e);
                }
            }
            FlippingStrategy targetStrategy = strategySingletons.get(strategyClassName);
            shouldFlip = getFf4j().checkOveridingStrategy(ff.name(), targetStrategy);
        } else {
            // no strategy, simple flip
            shouldFlip = getFf4j().check(ff.name());
        }
View Full Code Here

     */
    @Test
    public void testUpdateFeatureCoreData() {
        // Parameters
        String newDescription = "new-description";
        FlippingStrategy newStrategy = new PonderationStrategy(0.12);
        // Given
        assertFf4j.assertThatFeatureExist(F1);
        Assert.assertFalse(newDescription.equals(testedStore.read(F1).getDescription()));
        // When
        Feature fpBis = testedStore.read(F1);
        fpBis.setDescription(newDescription);
        fpBis.setFlippingStrategy(newStrategy);
        testedStore.update(fpBis);
        // Then
        Feature updatedFeature = testedStore.read(F1);
        Assert.assertTrue(newDescription.equals(updatedFeature.getDescription()));
        Assert.assertEquals(newStrategy.toString(), updatedFeature.getFlippingStrategy().toString());
    }
View Full Code Here

        // Second
        storeMongoDB.create(new Feature("second", false, "description", "GRP0", Arrays.asList("USER")));
        // Third
        storeMongoDB.create(new Feature("third", false, "ThirdJDBC", "GRP1", Arrays.asList("ADMINISTRATOR", "BETA-TESTER")));
        // Forth ?? Fourth ?
        FlippingStrategy strategy = new org.ff4j.strategy.el.ExpressionFlipStrategy();
        strategy.init("forth", ParameterUtils.toMap("expression=third|second"));
        storeMongoDB.create(new Feature("forth", true, "ForthJDBC", "GRP1", Arrays.asList("ADMINISTRATOR", "BETA-TESTER"),
                strategy));

        return storeMongoDB;
    }
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    public static FlippingStrategy parseFlipStrategy(String uid, HashMap<String, Object> flipMap) {
        if (null == flipMap || flipMap.isEmpty()) return null;
        String classType = null;
        FlippingStrategy strategy = null;
        try {
            //Map<String, Object> flipMap = objectMapper.readValue(json, HashMap.class);
            classType = (String) flipMap.get("classType");
            strategy = (FlippingStrategy) Class.forName(classType).newInstance();
            HashMap<String, String> initparams = (HashMap<String, String>) flipMap.get("initParams");
            // Initialized
            strategy.init(uid, initparams);
        } catch (InstantiationException e) {
            throw new IllegalArgumentException(classType + " does not seems to have a DEFAULT constructor", e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException(classType + " does not seems to have a PUBLIC constructor", e);
        } catch (ClassNotFoundException e) {
View Full Code Here

TOP

Related Classes of org.ff4j.core.FlippingStrategy

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.