use of org.ff4j.core.FlippingExecutionContext in project ff4j by ff4j.
the class FeatureTagEnable method eval.
/**
* {@inheritDoc}
*/
protected boolean eval(FF4j ff4j, PageContext jspContext) {
FlippingExecutionContext executionContext = new FlippingExecutionContext();
if (isShareHttpSession()) {
executionContext.putString("LOCALE", pageContext.getRequest().getLocalName());
@SuppressWarnings("unchecked") Map<String, String[]> parameters = pageContext.getRequest().getParameterMap();
for (Map.Entry<String, String[]> param : parameters.entrySet()) {
String[] innerParams = param.getValue();
if (innerParams != null) {
StringBuilder sb = new StringBuilder();
for (String innerParam : innerParams) {
sb.append(innerParam);
sb.append(",");
}
String expression = sb.toString();
executionContext.putString(param.getKey(), expression.substring(0, expression.length() - 1));
}
}
}
return ff4j.check(getFeatureid(), executionContext);
}
use of org.ff4j.core.FlippingExecutionContext in project ff4j by ff4j.
the class FF4jServices method check.
public Boolean check(String featureUID, Map<String, String> map) {
featureValidator.assertFeatureExists(featureUID);
FlippingExecutionContext flipExecCtx = new FlippingExecutionContext();
for (Map.Entry<String, String> entry : map.entrySet()) {
flipExecCtx.putString(entry.getKey(), entry.getValue());
}
return ff4j.check(featureUID, flipExecCtx);
}
use of org.ff4j.core.FlippingExecutionContext in project ff4j by ff4j.
the class FeatureAdvisor method check.
/**
* Call if Flipped based on different parameters of the annotation
*
* @param ff
* annotation over current method
* @param context
* @return if flippinf should be considere
*/
protected boolean check(Flip ff, MethodInvocation mi) {
// Retrieve optional context with ThreadLocal
FlippingExecutionContext context = getFlippingContext(ff, mi);
// Check ff4j
String featureId = ff.name();
if (ff.flippingStrategy() != NullType.class) {
String fsClassName = ff.flippingStrategy().getName();
FlippingStrategy fs = instanceFlippingStrategy(featureId, fsClassName, toMap(ff.flippingInitParams()));
return getFf4j().checkOveridingStrategy(featureId, fs, context);
}
return getFf4j().check(featureId, context);
}
use of org.ff4j.core.FlippingExecutionContext in project ff4j by ff4j.
the class GreetingServiceTest method testAOPWithParameter.
@Test
public void testAOPWithParameter() {
ff4j.enable("context-french");
Assert.assertTrue(context.sayHelloWithParameter("CLU", null).startsWith("Hello"));
FlippingExecutionContext executionContext = new FlippingExecutionContext();
executionContext.putString("user.settings.language", "english");
Assert.assertTrue(context.sayHelloWithParameter("CLU", executionContext).startsWith("Hello"));
executionContext.putString("user.settings.language", "french");
Assert.assertTrue(context.sayHelloWithParameter("CLU", executionContext).startsWith("Bonjour"));
}
use of org.ff4j.core.FlippingExecutionContext in project ff4j by ff4j.
the class GreetingServiceTest method testAOPWithThreadLocal.
@Test
public void testAOPWithThreadLocal() {
ff4j.enable("context-french");
FlippingExecutionContext executionContext = ff4j.getCurrentContext();
executionContext.putString("user.settings.language", "english");
Assert.assertTrue(context.sayHelloWithThreadLocal("CLU").startsWith("Hello"));
executionContext.putString("user.settings.language", "french");
Assert.assertTrue(context.sayHelloWithThreadLocal("CLU").startsWith("Bonjour"));
}
Aggregations