use of org.ff4j.couchdb.document.CouchDbFeature in project ff4j by ff4j.
the class FeatureStoreCouchDb method update.
/**
* {@inheritDoc}
*/
@Override
public void update(Feature fp) {
if (fp == null) {
throw new IllegalArgumentException("Feature cannot be null nor empty");
}
CouchDbFeature feature = getFeature(fp.getUid());
feature.setFeature(fp.toJson());
updateFeature(feature);
}
use of org.ff4j.couchdb.document.CouchDbFeature in project ff4j by ff4j.
the class FeatureStoreCouchDb method readGroup.
/**
* {@inheritDoc}
*/
@Override
public Map<String, Feature> readGroup(String groupName) {
if (groupName == null || groupName.isEmpty()) {
throw new IllegalArgumentException(GROUPNAME_CANNOT_BE_NULL_NOR_EMPTY);
}
if (!existGroup(groupName)) {
throw new GroupNotFoundException(groupName);
}
LinkedHashMap<String, Feature> mapFP = new LinkedHashMap<>();
List<CouchDbFeature> features = getFeatures(groupName);
if (null != features) {
features.forEach(f -> {
Feature feat = fromJson(f.getFeature());
if (null != feat) {
mapFP.put(f.getId(), feat);
}
});
}
return mapFP;
}
use of org.ff4j.couchdb.document.CouchDbFeature in project ff4j by ff4j.
the class FeatureStoreCouchDb method updateStatus.
/**
* Update status of feature.
*
* @param uid feature id
* @param enable enabler
*/
private void updateStatus(String uid, boolean enable) {
if (uid == null || uid.isEmpty()) {
throw new IllegalArgumentException(FEATURE_IDENTIFIER_CANNOT_BE_NULL_NOR_EMPTY);
}
if (!exist(uid)) {
throw new FeatureNotFoundException(uid);
}
CouchDbFeature couchDbFeature = couchDbConnector.find(CouchDbFeature.class, uid);
Feature feature = fromJson(couchDbFeature.getFeature());
if (null != feature) {
feature.setEnable(enable);
couchDbFeature.setFeature(feature.toJson());
updateFeature(couchDbFeature);
}
}
use of org.ff4j.couchdb.document.CouchDbFeature in project ff4j by ff4j.
the class FeatureStoreCouchDb method addToGroup.
/**
* {@inheritDoc}
*/
@Override
public void addToGroup(String uid, String groupName) {
if (uid == null || uid.isEmpty()) {
throw new IllegalArgumentException(FEATURE_IDENTIFIER_CANNOT_BE_NULL_NOR_EMPTY);
}
if (groupName == null || groupName.isEmpty()) {
throw new IllegalArgumentException(GROUPNAME_CANNOT_BE_NULL_NOR_EMPTY);
}
if (!exist(uid)) {
throw new FeatureNotFoundException(uid);
}
CouchDbFeature couchDbFeature = getFeature(uid);
Feature feat = fromJson(couchDbFeature.getFeature());
if (null != feat) {
feat.setGroup(groupName);
couchDbFeature.setFeature(feat.toJson());
updateFeature(couchDbFeature);
}
}
use of org.ff4j.couchdb.document.CouchDbFeature in project ff4j by ff4j.
the class FeatureStoreCouchDb method removeFromGroup.
/**
* {@inheritDoc}
*/
@Override
public void removeFromGroup(String uid, String groupName) {
if (uid == null || uid.isEmpty()) {
throw new IllegalArgumentException(FEATURE_IDENTIFIER_CANNOT_BE_NULL_NOR_EMPTY);
}
if (groupName == null || groupName.isEmpty()) {
throw new IllegalArgumentException(GROUPNAME_CANNOT_BE_NULL_NOR_EMPTY);
}
if (!exist(uid)) {
throw new FeatureNotFoundException(uid);
}
if (!existGroup(groupName)) {
throw new GroupNotFoundException(groupName);
}
CouchDbFeature couchDbFeature = getFeature(uid);
Feature feat = fromJson(couchDbFeature.getFeature());
if (null != feat) {
feat.setGroup("");
couchDbFeature.setFeature(feat.toJson());
updateFeature(couchDbFeature);
}
}
Aggregations