Search in sources :

Example 26 with Property

use of org.ff4j.property.Property in project ff4j by ff4j.

the class FeatureXmlParserTest method testParsingFeatures.

@Test
public void testParsingFeatures() throws IOException {
    // Given
    XmlParser parser = new XmlParser();
    InputStream in = getClass().getClassLoader().getResourceAsStream("ff4j-parser-features.xml");
    // When
    XmlConfig conf = parser.parseConfigurationFile(in);
    // Then
    Map<String, Feature> features = conf.getFeatures();
    Assert.assertNotNull(features);
    // Then
    Map<String, Property<?>> properties = conf.getProperties();
    Assert.assertNotNull(properties);
}
Also used : XmlParser(org.ff4j.conf.XmlParser) XmlConfig(org.ff4j.conf.XmlConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Feature(org.ff4j.core.Feature) Property(org.ff4j.property.Property) Test(org.junit.Test)

Example 27 with Property

use of org.ff4j.property.Property in project ff4j by ff4j.

the class FeatureXmlParserTest method testPropertiesParsing.

@Test
public void testPropertiesParsing() throws IOException {
    // Given
    XmlParser parser = new XmlParser();
    InputStream in = getClass().getClassLoader().getResourceAsStream("ff4j.xml");
    // When
    XmlConfig conf = parser.parseConfigurationFile(in);
    // Then
    Map<String, Feature> features = conf.getFeatures();
    Assert.assertNotNull(features);
    Feature f = features.get("first");
    Assert.assertNotNull(f);
    Assert.assertNotNull(f.getUid());
    Assert.assertNotNull(f.getCustomProperties());
    Assert.assertNotNull(f.getCustomProperties().get("ppint"));
    Assert.assertEquals(f.getCustomProperties().get("ppint").asInt(), 12);
    Assert.assertEquals(f.getCustomProperties().get("ppdouble").asDouble(), 12.5, 0);
    Assert.assertEquals(f.getCustomProperties().get("ppboolean").asBoolean(), true);
    Assert.assertEquals(f.getCustomProperties().get("ppstring").asString(), "hello");
    Assert.assertEquals(f.getCustomProperties().get("regionIdentifier").asString(), "AMER");
    Assert.assertNotNull(f.getCustomProperties().get("regionIdentifier").getFixedValues());
    Assert.assertFalse(f.getCustomProperties().get("regionIdentifier").getFixedValues().isEmpty());
    PropertyLogLevel pll = (PropertyLogLevel) f.getCustomProperties().get("myLogLevel");
    Assert.assertEquals(pll.getValue(), LogLevel.DEBUG);
    // Then
    Map<String, Property<?>> properties = conf.getProperties();
    Assert.assertNotNull(properties);
}
Also used : XmlParser(org.ff4j.conf.XmlParser) PropertyLogLevel(org.ff4j.property.PropertyLogLevel) XmlConfig(org.ff4j.conf.XmlConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Feature(org.ff4j.core.Feature) Property(org.ff4j.property.Property) Test(org.junit.Test)

Example 28 with Property

use of org.ff4j.property.Property in project ff4j by ff4j.

the class ConsoleOperations method importFile.

/**
 * User action to import Features from a properties files.
 *
 * @param in
 *            inpustream from configuration file
 * @throws IOException
 *             Error raised if the configuration cannot be read
 */
public static void importFile(FF4j ff4j, FF4jConfiguration config) throws IOException {
    if (config.isAutoCreate()) {
        ff4j.setAutocreate(true);
        LOGGER.info("Autocreate is now enabled.");
    }
    if (config.isAudit()) {
        ff4j.setEnableAudit(true);
        LOGGER.info("Audit is now enabled.");
    }
    FeatureStore store = ff4j.getFeatureStore();
    Map<String, Feature> mapsOfFeat = config.getFeatures();
    for (Entry<String, Feature> feature : mapsOfFeat.entrySet()) {
        if (store.exist(feature.getKey())) {
            store.update(feature.getValue());
        } else {
            store.create(feature.getValue());
        }
    }
    LOGGER.info(mapsOfFeat.size() + " features have been imported.");
    PropertyStore pstore = ff4j.getPropertiesStore();
    Map<String, Property<?>> mapsOfProperties = config.getProperties();
    for (Entry<String, Property<?>> p : mapsOfProperties.entrySet()) {
        if (pstore.existProperty(p.getKey())) {
            pstore.updateProperty(p.getValue());
        } else {
            pstore.createProperty(p.getValue());
        }
    }
    LOGGER.info(mapsOfProperties.size() + " features have been imported.");
}
Also used : Feature(org.ff4j.core.Feature) Property(org.ff4j.property.Property) FeatureStore(org.ff4j.core.FeatureStore) PropertyStore(org.ff4j.property.store.PropertyStore)

Example 29 with Property

use of org.ff4j.property.Property in project ff4j by ff4j.

the class PropertyStoreElastic method readProperty.

/**
 * {@inheritDoc}
 */
@Override
public Property<?> readProperty(String name) {
    assertPropertyExist(name);
    SearchResult result = getConnection().search(getBuilder().queryPropertyByName(name), true);
    return result.getFirstHit(Property.class).source;
}
Also used : SearchResult(io.searchbox.core.SearchResult) Property(org.ff4j.property.Property)

Example 30 with Property

use of org.ff4j.property.Property in project ff4j by ff4j.

the class ConsoleOperations method importFile.

/**
 * User action to import Features from a properties files.
 *
 * @param in
 *            inpustream from configuration file
 * @throws IOException
 *             Error raised if the configuration cannot be read
 */
public static void importFile(FF4j ff4j, InputStream in) throws IOException {
    FeatureStore store = ff4j.getFeatureStore();
    XmlConfig xmlConfig = new XmlParser().parseConfigurationFile(in);
    Map<String, Feature> mapsOfFeat = xmlConfig.getFeatures();
    for (Entry<String, Feature> feature : mapsOfFeat.entrySet()) {
        if (store.exist(feature.getKey())) {
            store.update(feature.getValue());
        } else {
            store.create(feature.getValue());
        }
    }
    LOGGER.info(mapsOfFeat.size() + " features have been imported.");
    PropertyStore pstore = ff4j.getPropertiesStore();
    Map<String, Property<?>> mapsOfProperties = xmlConfig.getProperties();
    for (Entry<String, Property<?>> p : mapsOfProperties.entrySet()) {
        if (pstore.existProperty(p.getKey())) {
            pstore.updateProperty(p.getValue());
        } else {
            pstore.createProperty(p.getValue());
        }
    }
    LOGGER.info(mapsOfProperties.size() + " features have been imported.");
}
Also used : XmlParser(org.ff4j.conf.XmlParser) XmlConfig(org.ff4j.conf.XmlConfig) Feature(org.ff4j.core.Feature) Property(org.ff4j.property.Property) FeatureStore(org.ff4j.core.FeatureStore) PropertyStore(org.ff4j.property.store.PropertyStore)

Aggregations

Property (org.ff4j.property.Property)56 HashMap (java.util.HashMap)20 PropertyString (org.ff4j.property.PropertyString)20 Test (org.junit.Test)20 Feature (org.ff4j.core.Feature)16 Map (java.util.Map)11 InputStream (java.io.InputStream)9 XmlParser (org.ff4j.conf.XmlParser)7 InMemoryPropertyStore (org.ff4j.property.store.InMemoryPropertyStore)7 LinkedHashMap (java.util.LinkedHashMap)6 XmlConfig (org.ff4j.conf.XmlConfig)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 FeatureStore (org.ff4j.core.FeatureStore)4 PropertyAccessException (org.ff4j.exception.PropertyAccessException)4 PropertyStore (org.ff4j.property.store.PropertyStore)4 IOException (java.io.IOException)3 Date (java.util.Date)3 HashSet (java.util.HashSet)3 FF4jCacheProxy (org.ff4j.cache.FF4jCacheProxy)3