Search in sources :

Example 11 with GroupNotFoundException

use of org.ff4j.exception.GroupNotFoundException in project ff4j by ff4j.

the class FeatureStoreMongoDB 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<String, Feature>();
    for (DBObject dbObject : getFeaturesCollection().find(BUILDER.getGroupName(groupName))) {
        Feature feature = MAPPER.mapFeature(dbObject);
        mapFP.put(feature.getUid(), feature);
    }
    return mapFP;
}
Also used : GroupNotFoundException(org.ff4j.exception.GroupNotFoundException) Feature(org.ff4j.core.Feature) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with GroupNotFoundException

use of org.ff4j.exception.GroupNotFoundException in project ff4j by ff4j.

the class FeatureStoreSpringJdbc method readGroup.

/**
 * {@inheritDoc}
 */
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<String, Feature>();
    List<Feature> lFp = getJdbcTemplate().query(getQueryBuilder().getFeatureOfGroup(), FMAPPER, groupName);
    for (Feature flipPoint : lFp) {
        mapFP.put(flipPoint.getUid(), flipPoint);
    }
    return mapFP;
}
Also used : GroupNotFoundException(org.ff4j.exception.GroupNotFoundException) Feature(org.ff4j.core.Feature) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with GroupNotFoundException

use of org.ff4j.exception.GroupNotFoundException in project ff4j by ff4j.

the class FeatureStoreRedis method removeFromGroup.

/**
 * {@inheritDoc}
 */
@Override
public void removeFromGroup(String featureId, String groupName) {
    Util.assertParamHasLength(groupName, "groupName (#2)");
    if (!existGroup(groupName)) {
        throw new GroupNotFoundException(groupName);
    }
    // retrieve
    Feature f = read(featureId);
    f.setGroup(null);
    // persist modification
    update(f);
}
Also used : GroupNotFoundException(org.ff4j.exception.GroupNotFoundException) Feature(org.ff4j.core.Feature)

Example 14 with GroupNotFoundException

use of org.ff4j.exception.GroupNotFoundException in project ff4j by ff4j.

the class FeatureStoreMongoDB 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);
    }
    DBObject target = BUILDER.getFeatUid(uid);
    DBObject nGroupName = BUILDER.getGroupName("");
    getFeaturesCollection().update(target, BasicDBObjectBuilder.start(MONGO_SET, nGroupName).get());
}
Also used : GroupNotFoundException(org.ff4j.exception.GroupNotFoundException) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Example 15 with GroupNotFoundException

use of org.ff4j.exception.GroupNotFoundException in project ff4j by ff4j.

the class FeatureStoreMongoDB method enableGroup.

/**
 * {@inheritDoc}
 */
@Override
public void enableGroup(String groupName) {
    if (groupName == null || groupName.isEmpty()) {
        throw new IllegalArgumentException(GROUPNAME_CANNOT_BE_NULL_NOR_EMPTY);
    }
    if (!existGroup(groupName)) {
        throw new GroupNotFoundException(groupName);
    }
    for (DBObject dbObject : getFeaturesCollection().find(BUILDER.getGroupName(groupName))) {
        Object enabledd = BUILDER.getEnable(true);
        getFeaturesCollection().update(dbObject, BasicDBObjectBuilder.start(MONGO_SET, enabledd).get());
    }
}
Also used : GroupNotFoundException(org.ff4j.exception.GroupNotFoundException) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Aggregations

GroupNotFoundException (org.ff4j.exception.GroupNotFoundException)18 Feature (org.ff4j.core.Feature)9 FeatureAccessException (org.ff4j.exception.FeatureAccessException)5 BasicDBObject (com.mongodb.BasicDBObject)4 DBObject (com.mongodb.DBObject)4 Response (javax.ws.rs.core.Response)4 Document (org.bson.Document)4 LinkedHashMap (java.util.LinkedHashMap)3 FeatureNotFoundException (org.ff4j.exception.FeatureNotFoundException)3 HashMap (java.util.HashMap)2 FeatureJsonParser.parseFeature (org.ff4j.utils.json.FeatureJsonParser.parseFeature)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)1