Search in sources :

Example 1 with FlippingExecutionContext

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);
}
Also used : FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Map(java.util.Map)

Example 2 with FlippingExecutionContext

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);
}
Also used : FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Map(java.util.Map)

Example 3 with FlippingExecutionContext

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);
}
Also used : FlippingStrategy(org.ff4j.core.FlippingStrategy) MappingUtil.instanceFlippingStrategy(org.ff4j.utils.MappingUtil.instanceFlippingStrategy) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext)

Example 4 with FlippingExecutionContext

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"));
}
Also used : FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Test(org.junit.Test)

Example 5 with FlippingExecutionContext

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"));
}
Also used : FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Test(org.junit.Test)

Aggregations

FlippingExecutionContext (org.ff4j.core.FlippingExecutionContext)28 Test (org.junit.Test)21 AbstractFf4jTest (org.ff4j.test.AbstractFf4jTest)8 HashMap (java.util.HashMap)6 Feature (org.ff4j.core.Feature)6 PropertyString (org.ff4j.property.PropertyString)6 Map (java.util.Map)4 FlippingStrategy (org.ff4j.core.FlippingStrategy)4 ClientFilterStrategy (org.ff4j.strategy.ClientFilterStrategy)4 InMemoryFeatureStore (org.ff4j.store.InMemoryFeatureStore)3 ServerFilterStrategy (org.ff4j.strategy.ServerFilterStrategy)3 Date (java.util.Date)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Calendar (java.util.Calendar)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 FF4j (org.ff4j.FF4j)1