Search in sources :

Example 16 with GroupNotFoundException

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

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

Example 17 with GroupNotFoundException

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

the class FeatureStoreMongo 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 (Document document : getFeaturesCollection().find(BUILDER.getGroupName(groupName))) {
        Feature feature = FMAPPER.fromStore(document);
        mapFP.put(feature.getUid(), feature);
    }
    return mapFP;
}
Also used : GroupNotFoundException(org.ff4j.exception.GroupNotFoundException) Document(org.bson.Document) Feature(org.ff4j.core.Feature) LinkedHashMap(java.util.LinkedHashMap)

Example 18 with GroupNotFoundException

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

the class FeatureStoreHttp method enableGroup.

/**
 * {@inheritDoc}
 */
@Override
public void enableGroup(String groupName) {
    Util.assertHasLength(groupName);
    Response cRes = ClientHttpUtils.invokePostMethod(getGroups().path(groupName).path(OPERATION_ENABLE), authorizationHeaderValue);
    if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) {
        throw new GroupNotFoundException(groupName);
    }
    if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) {
        throw new FeatureAccessException(CANNOT_GRANT_ROLE_ON_FEATURE_AN_HTTP_ERROR + cRes.getStatus() + OCCURED);
    }
}
Also used : Response(javax.ws.rs.core.Response) FeatureAccessException(org.ff4j.exception.FeatureAccessException) GroupNotFoundException(org.ff4j.exception.GroupNotFoundException)

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