Search in sources :

Example 26 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 27 with Feature

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

the class FeatureStoreElastic method grantRoleOnFeature.

/**
 * {@inheritDoc}
 */
@Override
public void grantRoleOnFeature(String flipId, String roleName) {
    assertFeatureExist(flipId);
    Util.assertHasLength(roleName);
    Feature feature = read(flipId);
    feature.getPermissions().add(roleName);
    getConnection().execute(getBuilder().queryUpdateFeature(feature));
}
Also used : Feature(org.ff4j.core.Feature)

Example 28 with Feature

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

the class FeatureStoreElastic method removeRoleFromFeature.

/**
 * {@inheritDoc}
 */
@Override
public void removeRoleFromFeature(String flipId, String roleName) {
    assertFeatureExist(flipId);
    Util.assertHasLength(roleName);
    Feature feature = read(flipId);
    feature.getPermissions().remove(roleName);
    getConnection().execute(getBuilder().queryUpdateFeature(feature));
}
Also used : Feature(org.ff4j.core.Feature)

Example 29 with Feature

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

the class FeatureStoreElastic method readGroup.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, Feature> readGroup(String groupName) {
    assertGroupExist(groupName);
    SearchResult result = getConnection().search(getBuilder().queryReadGroup(groupName));
    LinkedHashMap<String, Feature> mapOfFeatures = new LinkedHashMap<String, Feature>();
    if (null != result && result.isSucceeded()) {
        for (Hit<Feature, Void> hit : result.getHits(Feature.class)) {
            mapOfFeatures.put(hit.source.getUid(), hit.source);
        }
    }
    return mapOfFeatures;
}
Also used : SearchResult(io.searchbox.core.SearchResult) Feature(org.ff4j.core.Feature) LinkedHashMap(java.util.LinkedHashMap)

Example 30 with Feature

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

the class HBaseFeatureMapper method fromStore.

/**
 * {@inheritDoc}
 */
public Feature fromStore(Result result) {
    // uid
    String uid = Bytes.toString(result.getValue(B_FEATURES_CF_CORE, B_FEAT_UID));
    Feature fout = new Feature(uid);
    // description
    fout.setDescription(Bytes.toString(result.getValue(B_FEATURES_CF_CORE, B_FEAT_DESCRIPTION)));
    // enable
    fout.setEnable(Bytes.toBoolean(result.getValue(B_FEATURES_CF_CORE, B_FEAT_ENABLE)));
    // group
    fout.setGroup(Bytes.toString(result.getValue(B_FEATURES_CF_CORE, B_FEAT_GROUPNAME)));
    if ("null".equals(fout.getGroup())) {
        fout.setGroup(null);
    }
    // permissions
    fout.setPermissions(FeatureJsonParser.parsePermissions(Bytes.toString(result.getValue(B_FEATURES_CF_CORE, B_FEAT_ROLES))));
    // Flipping Strategy
    fout.setFlippingStrategy(FeatureJsonParser.parseFlipStrategyAsJson(uid, Bytes.toString(result.getValue(B_FEATURES_CF_CORE, B_FEAT_STRATEGY))));
    // Custom Properties
    NavigableMap<byte[], byte[]> map = result.getFamilyMap(B_FEATURES_CF_PROPERTIES);
    for (Map.Entry<byte[], byte[]> property : map.entrySet()) {
        fout.getCustomProperties().put(Bytes.toString(property.getKey()), PropertyJsonParser.parseProperty(Bytes.toString(property.getValue())));
    }
    return fout;
}
Also used : Feature(org.ff4j.core.Feature) NavigableMap(java.util.NavigableMap) Map(java.util.Map)

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