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;
}
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));
}
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));
}
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;
}
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;
}
Aggregations