Search in sources :

Example 6 with CouchDbFeature

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);
}
Also used : CouchDbFeature(org.ff4j.couchdb.document.CouchDbFeature)

Example 7 with CouchDbFeature

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;
}
Also used : CouchDbFeature(org.ff4j.couchdb.document.CouchDbFeature) GroupNotFoundException(org.ff4j.exception.GroupNotFoundException) CouchDbFeature(org.ff4j.couchdb.document.CouchDbFeature) Feature(org.ff4j.core.Feature) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with CouchDbFeature

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);
    }
}
Also used : CouchDbFeature(org.ff4j.couchdb.document.CouchDbFeature) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException) CouchDbFeature(org.ff4j.couchdb.document.CouchDbFeature) Feature(org.ff4j.core.Feature)

Example 9 with 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);
    }
}
Also used : CouchDbFeature(org.ff4j.couchdb.document.CouchDbFeature) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException) CouchDbFeature(org.ff4j.couchdb.document.CouchDbFeature) Feature(org.ff4j.core.Feature)

Example 10 with 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);
    }
}
Also used : CouchDbFeature(org.ff4j.couchdb.document.CouchDbFeature) GroupNotFoundException(org.ff4j.exception.GroupNotFoundException) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException) CouchDbFeature(org.ff4j.couchdb.document.CouchDbFeature) Feature(org.ff4j.core.Feature)

Aggregations

CouchDbFeature (org.ff4j.couchdb.document.CouchDbFeature)12 Feature (org.ff4j.core.Feature)9 FeatureNotFoundException (org.ff4j.exception.FeatureNotFoundException)6 GroupNotFoundException (org.ff4j.exception.GroupNotFoundException)4 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 FeatureAlreadyExistException (org.ff4j.exception.FeatureAlreadyExistException)1