Search in sources :

Example 46 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 47 with Feature

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

the class YamlParserTest method importYaml_should_be_same_asXMLImport.

@Test
public void importYaml_should_be_same_asXMLImport() {
    // Give XML an YAML files
    InputStream xmlFile = getClass().getClassLoader().getResourceAsStream("test-ff4j-features.xml");
    InputStream ymlFile = getClass().getClassLoader().getResourceAsStream("test-ff4j-features.yml");
    // When parsing those files
    XmlConfig xmlConfig = new XmlParser().parseConfigurationFile(xmlFile);
    FF4jConfiguration ymlConfig = new YamlParser().parseConfigurationFile(ymlFile);
    // Than both config are even
    assertEquals(xmlConfig.getFeatures().size(), ymlConfig.getFeatures().size());
    assertEquals(xmlConfig.getProperties().size(), ymlConfig.getProperties().size());
    // Custom-properties
    Feature f1Xml = xmlConfig.getFeatures().get("first");
    Feature f1Yml = ymlConfig.getFeatures().get("first");
    assertEquals(f1Xml.getDescription(), f1Yml.getDescription());
    assertEquals(f1Xml.getCustomProperties().size(), f1Yml.getCustomProperties().size());
    // FlipStrategy & Permission
    Feature f3Xml = xmlConfig.getFeatures().get("third");
    Feature f3Yml = ymlConfig.getFeatures().get("third");
    assertEquals(f3Xml.getFlippingStrategy().getClass(), f3Yml.getFlippingStrategy().getClass());
    assertEquals(f3Xml.getFlippingStrategy().getInitParams().get("expression"), f3Yml.getFlippingStrategy().getInitParams().get("expression"));
    assertEquals(f3Xml.getPermissions(), f3Yml.getPermissions());
}
Also used : XmlParser(org.ff4j.conf.XmlParser) XmlConfig(org.ff4j.conf.XmlConfig) InputStream(java.io.InputStream) Feature(org.ff4j.core.Feature) FF4jConfiguration(org.ff4j.conf.FF4jConfiguration) Test(org.junit.Test)

Example 48 with Feature

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

the class FF4j method checkOveridingStrategy.

/**
 * Overriding strategy on feature.
 *
 * @param featureID
 *            feature unique identifier.
 * @param executionContext
 *            current execution context
 * @return
 */
public boolean checkOveridingStrategy(String featureID, FlippingStrategy strats, FlippingExecutionContext executionContext) {
    Feature fp = getFeature(featureID);
    boolean flipped = fp.isEnable() && isAllowed(fp);
    if (strats != null) {
        flipped = flipped && strats.evaluate(featureID, getFeatureStore(), executionContext);
    }
    publishCheck(featureID, flipped);
    return flipped;
}
Also used : Feature(org.ff4j.core.Feature)

Example 49 with Feature

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

the class FeatureStoreDynamoDBIT method addEmptyStringAsRole.

@Test
public void addEmptyStringAsRole() {
    // given
    Feature feature = testedStore.read(AWESOME);
    Assert.assertTrue(feature.getPermissions().isEmpty());
    // when
    feature.getPermissions().add("");
    testedStore.update(feature);
    // then
    Assert.assertTrue(feature.getPermissions().isEmpty());
}
Also used : Feature(org.ff4j.core.Feature)

Example 50 with Feature

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

the class FeatureStoreArangoDB method getGroupFeatures.

private List<Feature> getGroupFeatures(String group) {
    Predicate<Feature> groupNonNull = f -> Objects.nonNull(f.getGroup());
    Predicate<Feature> groupMatch = f -> group.equals(f.getGroup());
    try {
        return getAllFeatures().stream().filter(groupNonNull.and(groupMatch)).collect(toList());
    } catch (ArangoDBException e) {
        throw new GroupNotFoundException(group);
    }
}
Also used : java.util(java.util) GroupNotFoundException(org.ff4j.exception.GroupNotFoundException) Predicate(java.util.function.Predicate) AbstractFeatureStore(org.ff4j.store.AbstractFeatureStore) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArangoDBFeature(org.ff4j.arangodb.document.ArangoDBFeature) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException) Slf4j(lombok.extern.slf4j.Slf4j) StoreMapper(org.ff4j.arangodb.StoreMapper) ArangoDBException(com.arangodb.ArangoDBException) FeatureAccessException(org.ff4j.exception.FeatureAccessException) ArangoCollection(com.arangodb.ArangoCollection) Util(org.ff4j.utils.Util) Feature(org.ff4j.core.Feature) GroupNotFoundException(org.ff4j.exception.GroupNotFoundException) ArangoDBFeature(org.ff4j.arangodb.document.ArangoDBFeature) Feature(org.ff4j.core.Feature) ArangoDBException(com.arangodb.ArangoDBException)

Aggregations

Feature (org.ff4j.core.Feature)295 Test (org.junit.Test)144 PropertyString (org.ff4j.property.PropertyString)53 HashMap (java.util.HashMap)38 HashSet (java.util.HashSet)27 PonderationStrategy (org.ff4j.strategy.PonderationStrategy)19 Property (org.ff4j.property.Property)16 LinkedHashMap (java.util.LinkedHashMap)15 GroupNotFoundException (org.ff4j.exception.GroupNotFoundException)15 Map (java.util.Map)14 XmlParser (org.ff4j.conf.XmlParser)14 AbstractFf4jTest (org.ff4j.test.AbstractFf4jTest)14 FeatureAccessException (org.ff4j.exception.FeatureAccessException)13 InputStream (java.io.InputStream)11 FeatureApiBean (org.ff4j.web.api.resources.domain.FeatureApiBean)11 Set (java.util.Set)10 Response (javax.ws.rs.core.Response)10 FlippingStrategy (org.ff4j.core.FlippingStrategy)10 CouchDbFeature (org.ff4j.couchdb.document.CouchDbFeature)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9