Search in sources :

Example 6 with FlippingStrategy

use of org.ff4j.core.FlippingStrategy in project ff4j by ff4j.

the class ClientFilterStrategyTest method testInitialisationProgramServer.

@Test
public void testInitialisationProgramServer() {
    FlippingStrategy fs = new ServerFilterStrategy("serv1,serv2");
    fs.init("f1", null);
    fs.init("f1", new HashMap<String, String>());
    FlippingExecutionContext context = new FlippingExecutionContext();
    fs.evaluate("f1", new InMemoryFeatureStore(), context);
}
Also used : ServerFilterStrategy(org.ff4j.strategy.ServerFilterStrategy) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) FlippingStrategy(org.ff4j.core.FlippingStrategy) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Test(org.junit.Test) AbstractFf4jTest(org.ff4j.test.AbstractFf4jTest)

Example 7 with FlippingStrategy

use of org.ff4j.core.FlippingStrategy in project ff4j by ff4j.

the class FeatureJsonMarshallTest method testJsonUtils.

@Test
public void testJsonUtils() {
    FlippingStrategy ps = new FlippingStrategy() {

        public void init(String featureName, Map<String, String> initParam) {
        }

        public Map<String, String> getInitParams() {
            return null;
        }

        public boolean evaluate(String fn, FeatureStore s, FlippingExecutionContext ex) {
            return false;
        }
    };
    JsonUtils.flippingStrategyAsJson(ps);
}
Also used : FlippingStrategy(org.ff4j.core.FlippingStrategy) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Map(java.util.Map) FeatureStore(org.ff4j.core.FeatureStore) Test(org.junit.Test)

Example 8 with FlippingStrategy

use of org.ff4j.core.FlippingStrategy in project ff4j by ff4j.

the class MappingUtil method instanceFlippingStrategy.

/**
 * Instanciate flipping strategy from its class name.
 *
 * @param className
 *      current class name
 * @return
 *      the flipping strategy
 */
@SuppressWarnings("unchecked")
public static FlippingStrategy instanceFlippingStrategy(String uid, String className, Map<String, String> initparams) {
    try {
        Class<FlippingStrategy> clazz = (Class<FlippingStrategy>) (classLoader == null ? Class.forName(className) : classLoader.loadClass(className));
        FlippingStrategy flipStrategy = clazz.newInstance();
        flipStrategy.init(uid, initparams);
        return flipStrategy;
    } catch (Exception ie) {
        throw new FeatureAccessException("Cannot instantiate Strategy, no default constructor available", ie);
    }
}
Also used : FeatureAccessException(org.ff4j.exception.FeatureAccessException) FlippingStrategy(org.ff4j.core.FlippingStrategy) FeatureAccessException(org.ff4j.exception.FeatureAccessException)

Example 9 with FlippingStrategy

use of org.ff4j.core.FlippingStrategy in project ff4j by ff4j.

the class FeatureStoreNeo4J method addNeighBour2Feature.

/**
 * Parse node related to feature and create sub component.
 *
 * @param targetFeature
 *      current feature
 * @param nodeOther
 *      current neighbour
 */
private void addNeighBour2Feature(Feature targetFeature, Node nodeOther) {
    Util.assertNotNull(targetFeature);
    if (nodeOther != null && nodeOther.getLabels().iterator().hasNext()) {
        String nodeLabel = nodeOther.getLabels().iterator().next().toString();
        FF4jNeo4jLabels lblb = FF4jNeo4jLabels.valueOf(nodeLabel);
        switch(lblb) {
            case FF4J_FLIPPING_STRATEGY:
                FlippingStrategy fs = fromNode2FlippingStrategy(targetFeature.getUid(), nodeOther);
                targetFeature.setFlippingStrategy(fs);
                break;
            case FF4J_FEATURE_PROPERTY:
                Property<?> ap = fromNode2Property(nodeOther);
                targetFeature.getCustomProperties().put(ap.getName(), ap);
                break;
            case FF4J_FEATURE_GROUP:
                targetFeature.setGroup((String) nodeOther.getProperty(NODEGROUP_ATT_NAME));
                break;
            default:
                break;
        }
    }
}
Also used : Neo4jMapper.fromNode2FlippingStrategy(org.ff4j.neo4j.mapper.Neo4jMapper.fromNode2FlippingStrategy) FlippingStrategy(org.ff4j.core.FlippingStrategy) FF4jNeo4jLabels(org.ff4j.neo4j.FF4jNeo4jLabels)

Example 10 with FlippingStrategy

use of org.ff4j.core.FlippingStrategy in project ff4j by ff4j.

the class FeatureRowMapper method mapRow.

/**
 * {@inheritDoc}
 */
@Override
public Feature mapRow(ResultSet rs, int rowNum) throws SQLException {
    String featUid = rs.getString(COL_FEAT_UID);
    Feature f = new Feature(featUid, rs.getInt(COL_FEAT_ENABLE) > 0);
    f.setDescription(rs.getString(COL_FEAT_DESCRIPTION));
    f.setGroup(rs.getString(COL_FEAT_GROUPNAME));
    // Build Flipping Strategy From DataBase
    String strategy = rs.getString(COL_FEAT_STRATEGY);
    if (strategy != null && !"".equals(strategy)) {
        Map<String, String> initParams = MappingUtil.toMap(rs.getString(COL_FEAT_EXPRESSION));
        FlippingStrategy flipStrategy = MappingUtil.instanceFlippingStrategy(featUid, strategy, initParams);
        f.setFlippingStrategy(flipStrategy);
    }
    return f;
}
Also used : FlippingStrategy(org.ff4j.core.FlippingStrategy) Feature(org.ff4j.core.Feature)

Aggregations

FlippingStrategy (org.ff4j.core.FlippingStrategy)18 Feature (org.ff4j.core.Feature)9 PropertyString (org.ff4j.property.PropertyString)7 Test (org.junit.Test)7 HashMap (java.util.HashMap)6 FlippingExecutionContext (org.ff4j.core.FlippingExecutionContext)4 PonderationStrategy (org.ff4j.strategy.PonderationStrategy)4 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 InMemoryFeatureStore (org.ff4j.store.InMemoryFeatureStore)2 AbstractFf4jTest (org.ff4j.test.AbstractFf4jTest)2 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 NodeList (org.w3c.dom.NodeList)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 FeatureStore (org.ff4j.core.FeatureStore)1 FeatureAccessException (org.ff4j.exception.FeatureAccessException)1