Search in sources :

Example 1 with GroupNotFoundException

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

the class FeatureStoreHttp 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);
    }
    ClientResponse cRes = getGroups().path(groupName).get(ClientResponse.class);
    if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) {
        throw new GroupNotFoundException(groupName);
    }
    if (Status.OK.getStatusCode() != cRes.getStatus()) {
        throw new FeatureAccessException(CANNOT_GRANT_ROLE_ON_FEATURE_AN_HTTP_ERROR + cRes.getStatus() + OCCURED);
    }
    String resEntity = cRes.getEntity(String.class);
    Feature[] fArray = parseFeatureArray(resEntity);
    Map<String, Feature> features = new HashMap<String, Feature>();
    for (Feature feature : fArray) {
        features.put(feature.getUid(), feature);
    }
    return features;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FeatureAccessException(org.ff4j.exception.FeatureAccessException) HashMap(java.util.HashMap) GroupNotFoundException(org.ff4j.exception.GroupNotFoundException) FeatureJsonParser.parseFeature(org.ff4j.utils.json.FeatureJsonParser.parseFeature) Feature(org.ff4j.core.Feature)

Example 2 with GroupNotFoundException

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

the class FeatureStoreMongo 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);
    }
    for (Document document : getFeaturesCollection().find(BUILDER.getGroupName(groupName))) {
        Object enabled = BUILDER.getEnable(false);
        getFeaturesCollection().updateOne(document, new Document(MONGO_SET, enabled));
    }
}
Also used : GroupNotFoundException(org.ff4j.exception.GroupNotFoundException) Document(org.bson.Document)

Example 3 with GroupNotFoundException

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

the class FeatureStoreMongo 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);
    }
    Document target = BUILDER.getFeatUid(uid);
    Document nGroupName = BUILDER.getGroupName("");
    getFeaturesCollection().updateOne(target, new Document(MONGO_SET, nGroupName));
}
Also used : GroupNotFoundException(org.ff4j.exception.GroupNotFoundException) Document(org.bson.Document) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException)

Example 4 with GroupNotFoundException

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

the class FeatureStoreEhCache 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 5 with GroupNotFoundException

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

the class FeatureStoreJCache 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)

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