use of org.ff4j.couchdb.document.CouchDbFeature in project ff4j by ff4j.
the class FeatureStoreCouchDb method create.
/**
* {@inheritDoc}
*/
@Override
public void create(Feature fp) {
if (fp == null) {
throw new IllegalArgumentException("Feature cannot be null nor empty");
}
if (exist(fp.getUid())) {
throw new FeatureAlreadyExistException(fp.getUid());
}
CouchDbFeature couchDbFeature = new CouchDbFeature();
couchDbFeature.setType(DEFAULT_FEATURE_TYPE);
couchDbFeature.setFeature(fp.toJson());
couchDbFeature.setId(fp.getUid());
createFeature(couchDbFeature);
}
use of org.ff4j.couchdb.document.CouchDbFeature in project ff4j by ff4j.
the class FeatureStoreCouchDb method disableGroup.
/**
* {@inheritDoc}
*/
@Override
public void disableGroup(String groupName) {
if (groupName == null || groupName.isEmpty()) {
throw new IllegalArgumentException(GROUPNAME_CANNOT_BE_NULL_NOR_EMPTY);
}
if (!existGroup(groupName)) {
throw new GroupNotFoundException(groupName);
}
List<CouchDbFeature> features = getFeatures(groupName);
if (null != features) {
features.forEach(f -> {
Feature feat = fromJson(f.getFeature());
if (null != feat) {
feat.setEnable(false);
f.setFeature(feat.toJson());
updateFeature(f);
}
});
}
}
use of org.ff4j.couchdb.document.CouchDbFeature in project ff4j by ff4j.
the class FeatureStoreCouchDb method removeRoleFromFeature.
/**
* {@inheritDoc}
*/
@Override
public void removeRoleFromFeature(String uid, String roleName) {
if (uid == null || uid.isEmpty()) {
throw new IllegalArgumentException(FEATURE_IDENTIFIER_CANNOT_BE_NULL_NOR_EMPTY);
}
if (roleName == null || roleName.isEmpty()) {
throw new IllegalArgumentException("roleName cannot be null nor empty");
}
if (!exist(uid)) {
throw new FeatureNotFoundException(uid);
}
CouchDbFeature couchDbFeature = getFeature(uid);
Feature feature = fromJson(couchDbFeature.getFeature());
if (null != feature) {
feature.getPermissions().remove(roleName);
couchDbFeature.setFeature(feature.toJson());
updateFeature(couchDbFeature);
}
}
use of org.ff4j.couchdb.document.CouchDbFeature in project ff4j by ff4j.
the class FeatureStoreCouchDb method readAllGroups.
/**
* {@inheritDoc}
*/
@Override
public Set<String> readAllGroups() {
Set<String> setOfGroups = new HashSet<>();
List<CouchDbFeature> features = getFeatures();
features.forEach(f -> {
Feature feat = fromJson(f.getFeature());
if (null != feat) {
setOfGroups.add(feat.getGroup());
}
});
setOfGroups.remove(null);
setOfGroups.remove("");
return setOfGroups;
}
use of org.ff4j.couchdb.document.CouchDbFeature in project ff4j by ff4j.
the class FeatureStoreCouchDb method grantRoleOnFeature.
/**
* {@inheritDoc}
*/
@Override
public void grantRoleOnFeature(String uid, String roleName) {
if (uid == null || uid.isEmpty()) {
throw new IllegalArgumentException(FEATURE_IDENTIFIER_CANNOT_BE_NULL_NOR_EMPTY);
}
if (roleName == null || roleName.isEmpty()) {
throw new IllegalArgumentException("roleName cannot be null nor empty");
}
if (!exist(uid)) {
throw new FeatureNotFoundException(uid);
}
CouchDbFeature couchDbFeature = getFeature(uid);
Feature feature = fromJson(couchDbFeature.getFeature());
if (null != feature) {
feature.getPermissions().add(roleName);
couchDbFeature.setFeature(feature.toJson());
updateFeature(couchDbFeature);
}
}
Aggregations