Search in sources :

Example 21 with Feature

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

the class FeatureStoreStepDef method the_following_features_are_cached.

@Given("^the following features are cached$")
public void the_following_features_are_cached(List<FeaturePojo> features) throws Throwable {
    for (FeaturePojo featurePojo : features) {
        Feature feature = new Feature(featurePojo.getUid(), Boolean.valueOf(featurePojo.getEnable()), featurePojo.getDescription(), featurePojo.getGroup(), Arrays.asList(featurePojo.getPermissions().split(",")));
        ((FF4jCacheProxy) ff4j.getFeatureStore()).getCacheManager().putFeature(feature);
    }
}
Also used : Feature(org.ff4j.core.Feature) Given(cucumber.api.java.en.Given)

Example 22 with Feature

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

the class FeatureStoreServicesStepDef method the_following_features_are_cached.

@Given("^the following features are cached$")
public void the_following_features_are_cached(List<FeaturePojo> features) throws Throwable {
    for (FeaturePojo featurePojo : features) {
        Feature feature = new Feature(featurePojo.getUid(), Boolean.valueOf(featurePojo.getEnable()), featurePojo.getDescription(), featurePojo.getGroup(), Arrays.asList(featurePojo.getPermissions().split(",")));
        ((FF4jCacheProxy) ff4j.getFeatureStore()).getCacheManager().putFeature(feature);
    }
}
Also used : Feature(org.ff4j.core.Feature) Given(cucumber.api.java.en.Given)

Example 23 with Feature

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

the class AbstractStepDef method createFeatures.

protected void createFeatures(List<FeaturePojo> features) {
    for (FeaturePojo featurePojo : features) {
        Feature feature = new Feature(featurePojo.getUid(), Boolean.valueOf(featurePojo.getEnable()), featurePojo.getDescription(), featurePojo.getGroup(), Arrays.asList(featurePojo.getPermissions().split(",")));
        createFeature(feature);
    }
}
Also used : Feature(org.ff4j.core.Feature)

Example 24 with Feature

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

the class FF4jCliDisplay method displayFeatures.

/**
 * Command line uptime
 */
public static void displayFeatures(Map<String, Feature> features) {
    if (features == null || features.isEmpty()) {
        System.out.println(" There are no features in the store");
    }
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
    System.out.println("+--------------------+--------+---------------+--------------------------------+");
    System.out.print("|");
    AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.CYAN);
    System.out.print(" Feature names      ");
    AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
    System.out.print("|");
    AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.CYAN);
    System.out.print(" State  ");
    AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
    System.out.print("|");
    AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.CYAN);
    System.out.print(" Group         ");
    AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
    System.out.print("|");
    AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.CYAN);
    System.out.print(" Roles                          ");
    AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
    System.out.println("|");
    System.out.println("+--------------------+--------+---------------+--------------------------------+");
    for (Feature feat : features.values()) {
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
        System.out.print("| ");
        AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.GREEN);
        System.out.print(StringUtils.rightPad(feat.getUid(), 19));
        AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
        System.out.print("| ");
        if (feat.isEnable()) {
            AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
            AnsiTerminal.foreGroundColor(AnsiForegroundColor.GREEN);
            System.out.print(StringUtils.rightPad("ON", 7));
        } else {
            AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
            AnsiTerminal.foreGroundColor(AnsiForegroundColor.RED);
            System.out.print(StringUtils.rightPad("OFF", 7));
        }
        AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
        System.out.print("| ");
        AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.WHITE);
        String groupName = "---";
        if (!StringUtils.isEmpty(feat.getGroup())) {
            groupName = feat.getGroup();
        }
        System.out.print(StringUtils.rightPad(groupName, 14));
        AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
        System.out.print("| ");
        AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.WHITE);
        String roles = feat.getPermissions().toString();
        roles = roles.substring(1, roles.length() - 1);
        if ("".equals(roles)) {
            roles = "---";
        }
        System.out.print(StringUtils.rightPad(roles, 31));
        AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
        System.out.println("| ");
    }
    AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
    System.out.println("+--------------------+--------+---------------+--------------------------------+");
}
Also used : PropertyString(org.ff4j.property.PropertyString) Feature(org.ff4j.core.Feature)

Example 25 with Feature

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

the class AutowiredFF4JBeanPostProcessor method autoWiredFeature.

private void autoWiredFeature(Object bean, Field field) {
    // Find the required and name parameters
    FF4JFeature annFeature = field.getAnnotation(FF4JFeature.class);
    String annValue = annFeature.value();
    String featureName = field.getName();
    if (annValue != null && !"".equals(annValue)) {
        featureName = annValue;
    }
    Feature feature = readFeature(field, featureName, annFeature.required());
    if (feature != null) {
        if (Feature.class.isAssignableFrom(field.getType())) {
            injectValue(field, bean, featureName, feature);
        } else if (Boolean.class.isAssignableFrom(field.getType())) {
            injectValue(field, bean, featureName, new Boolean(feature.isEnable()));
        } else if (boolean.class.isAssignableFrom(field.getType())) {
            injectValue(field, bean, featureName, feature.isEnable());
        } else {
            throw new IllegalArgumentException("Field annotated with @FF4JFeature" + " must inherit from org.ff4j.Feature or be boolean " + field.getType() + " [class=" + bean.getClass().getName() + ", field=" + field.getName() + "]");
        }
    }
}
Also used : Feature(org.ff4j.core.Feature)

Aggregations

Feature (org.ff4j.core.Feature)258 Test (org.junit.Test)136 PropertyString (org.ff4j.property.PropertyString)49 HashMap (java.util.HashMap)29 HashSet (java.util.HashSet)29 PonderationStrategy (org.ff4j.strategy.PonderationStrategy)19 LinkedHashMap (java.util.LinkedHashMap)15 AbstractFf4jTest (org.ff4j.test.AbstractFf4jTest)14 Property (org.ff4j.property.Property)12 Set (java.util.Set)11 FeatureAccessException (org.ff4j.exception.FeatureAccessException)11 FeatureApiBean (org.ff4j.web.api.resources.domain.FeatureApiBean)11 XmlParser (org.ff4j.conf.XmlParser)10 InputStream (java.io.InputStream)9 Map (java.util.Map)9 FlippingStrategy (org.ff4j.core.FlippingStrategy)9 GroupNotFoundException (org.ff4j.exception.GroupNotFoundException)9 ClientResponse (com.sun.jersey.api.client.ClientResponse)8 ArrayList (java.util.ArrayList)8 Response (javax.ws.rs.core.Response)8