Search in sources :

Example 6 with GroupNotFoundException

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

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

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

the class FeatureStoreHttp method readGroup.

/**
 * {@inheritDoc}
 */
public Map<String, Feature> readGroup(String groupName) {
    Util.assertHasLength(groupName);
    Response cRes = ClientHttpUtils.invokeGetMethod(getGroups().path(groupName), authorizationHeaderValue);
    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.readEntity(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 : Response(javax.ws.rs.core.Response) 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 8 with GroupNotFoundException

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

the class FeatureStoreHttp method disableGroup.

/**
 * {@inheritDoc}
 */
@Override
public void disableGroup(String groupName) {
    Util.assertHasLength(groupName);
    Response cRes = ClientHttpUtils.invokePostMethod(getGroups().path(groupName).path(OPERATION_DISABLE), 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)

Example 9 with GroupNotFoundException

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

the class FeatureStoreHttp method removeFromGroup.

/**
 * {@inheritDoc}
 */
@Override
public void removeFromGroup(String uid, String groupName) {
    Util.assertHasLength(uid, groupName);
    Response cRes = ClientHttpUtils.invokePostMethod(getStore().path(uid).path(OPERATION_REMOVEGROUP).path(groupName), authorizationHeaderValue);
    if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) {
        throw new FeatureNotFoundException(uid);
    }
    if (Status.BAD_REQUEST.getStatusCode() == cRes.getStatus()) {
        throw new GroupNotFoundException(groupName);
    }
    if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) {
        throw new FeatureAccessException("Cannot remove feature from group, an HTTP error " + cRes.getStatus() + OCCURED);
    }
}
Also used : Response(javax.ws.rs.core.Response) FeatureAccessException(org.ff4j.exception.FeatureAccessException) GroupNotFoundException(org.ff4j.exception.GroupNotFoundException) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException)

Example 10 with GroupNotFoundException

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

the class FeatureStoreMongoDB 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 (DBObject dbObject : getFeaturesCollection().find(BUILDER.getGroupName(groupName))) {
        Object enabledd = BUILDER.getEnable(false);
        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