Search in sources :

Example 1 with CouchDbFeature

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

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

Example 3 with CouchDbFeature

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

Example 5 with CouchDbFeature

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