Search in sources :

Example 16 with Feature

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

the class CassandraMapper method mapFeature.

/**
 * Marshall bean {@link Feature} from line in Cassandra table.
 *
 * @param row
 *      current line
 * @return
 *      Populated object
 */
public static Feature mapFeature(Row row) {
    Feature f = new Feature(row.getString(COL_FEAT_UID));
    f.setDescription(row.getString(COL_FEAT_DESCRIPTION));
    f.setEnable(1 == row.getInt(COL_FEAT_ENABLE));
    f.setGroup(row.getString(COL_FEAT_GROUPNAME));
    f.setPermissions(mapFeaturePermissions(row));
    // Custom Properties
    Map<String, String> mapOfProperties = row.getMap(COL_FEAT_CUSTOMPROPERTIES, String.class, String.class);
    if (mapOfProperties != null) {
        Map<String, Property<?>> customProperties = new HashMap<String, Property<?>>();
        for (Map.Entry<String, String> propString : mapOfProperties.entrySet()) {
            customProperties.put(propString.getKey(), PropertyJsonParser.parseProperty(propString.getValue()));
        }
        f.setCustomProperties(customProperties);
    }
    // Flipping Strategy
    String jsonFlippingStrategy = row.getString(COL_FEAT_STRATEGY);
    if (Util.hasLength(jsonFlippingStrategy)) {
        f.setFlippingStrategy(FeatureJsonParser.parseFlipStrategyAsJson(f.getUid(), jsonFlippingStrategy));
    }
    return f;
}
Also used : HashMap(java.util.HashMap) Feature(org.ff4j.core.Feature) Property(org.ff4j.property.Property) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with Feature

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

the class FeatureStoreServices method getAllFeatures.

public Collection<FeatureApiBean> getAllFeatures() {
    List<FeatureApiBean> features;
    Map<String, Feature> featureMap = ff4j.getFeatureStore().readAll();
    if (CollectionUtils.isEmpty(featureMap)) {
        features = new ArrayList<FeatureApiBean>(0);
    } else {
        features = new ArrayList<FeatureApiBean>(featureMap.size());
        for (Feature feature : featureMap.values()) {
            features.add(new FeatureApiBean(feature));
        }
    }
    return features;
}
Also used : FeatureApiBean(org.ff4j.services.domain.FeatureApiBean) Feature(org.ff4j.core.Feature)

Example 18 with Feature

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

the class FeatureStoreServices method getAllGroups.

public Collection<GroupDescApiBean> getAllGroups() {
    Map<String, GroupDescApiBean> groups = new HashMap<String, GroupDescApiBean>();
    Map<String, Feature> featureMap = ff4j.getFeatureStore().readAll();
    if (!CollectionUtils.isEmpty(featureMap)) {
        for (Feature feature : featureMap.values()) {
            initGroupMap(groups, feature.getUid(), feature.getGroup());
        }
    }
    return groups.values();
}
Also used : Feature(org.ff4j.core.Feature) GroupDescApiBean(org.ff4j.services.domain.GroupDescApiBean)

Example 19 with Feature

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

the class GroupServices method getFeaturesByGroup.

public Collection<FeatureApiBean> getFeaturesByGroup(String groupName) {
    featureValidator.assertGroupExist(groupName);
    Collection<Feature> features = ff4j.getFeatureStore().readGroup(groupName).values();
    Collection<FeatureApiBean> featureApiBeans = new ArrayList<FeatureApiBean>();
    if (!CollectionUtils.isEmpty(features)) {
        for (Feature feature : features) {
            featureApiBeans.add(new FeatureApiBean(feature));
        }
    }
    return featureApiBeans;
}
Also used : FeatureApiBean(org.ff4j.services.domain.FeatureApiBean) ArrayList(java.util.ArrayList) Feature(org.ff4j.core.Feature)

Example 20 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)

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