Search in sources :

Example 1 with FeatureNotFoundException

use of org.ff4j.exception.FeatureNotFoundException 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 2 with FeatureNotFoundException

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

the class FeatureStoreHttp method removeRoleFromFeature.

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

Example 3 with FeatureNotFoundException

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

the class FeatureStoreHttp method read.

/**
 * {@inheritDoc}
 */
@Override
public Feature read(String uid) {
    Util.assertHasLength(uid);
    Response cRes = ClientHttpUtils.invokeGetMethod(getStore().path(uid), authorizationHeaderValue);
    log.info(String.valueOf(getStore().path(uid)));
    if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) {
        throw new FeatureNotFoundException(uid);
    } else if (Status.OK.getStatusCode() != cRes.getStatus()) {
        throw new FeatureAccessException("Error when reaching API code:[" + cRes.getStatus() + "] MSG:" + cRes.getStatusInfo());
    }
    return parseFeature(cRes.readEntity(String.class));
}
Also used : Response(javax.ws.rs.core.Response) FeatureAccessException(org.ff4j.exception.FeatureAccessException) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException)

Example 4 with FeatureNotFoundException

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

the class FeatureStoreHttp method grantRoleOnFeature.

/**
 * {@inheritDoc}
 */
@Override
public void grantRoleOnFeature(String uid, String roleName) {
    Util.assertHasLength(uid, roleName);
    Response cRes = ClientHttpUtils.invokePostMethod(getStore().path(uid).path(OPERATION_GRANTROLE).path(roleName), authorizationHeaderValue);
    if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) {
        throw new FeatureNotFoundException(uid);
    }
    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) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException)

Example 5 with FeatureNotFoundException

use of org.ff4j.exception.FeatureNotFoundException 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)

Aggregations

FeatureNotFoundException (org.ff4j.exception.FeatureNotFoundException)23 Response (javax.ws.rs.core.Response)8 FeatureAccessException (org.ff4j.exception.FeatureAccessException)7 BasicDBObject (com.mongodb.BasicDBObject)3 DBObject (com.mongodb.DBObject)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Path (javax.ws.rs.Path)3 Document (org.bson.Document)3 GroupNotFoundException (org.ff4j.exception.GroupNotFoundException)3 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 Jedis (redis.clients.jedis.Jedis)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1