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);
}
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);
}
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);
}
}
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;
}
}
}
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;
}
Aggregations