Search in sources :

Example 16 with FeatureNotFoundException

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

the class FeatureStoreMongo method updateStatus.

/**
 * Update status of feature.
 *
 * @param uid
 *            feature id
 * @param enable
 *            enabler
 */
private void updateStatus(String uid, boolean enable) {
    if (uid == null || uid.isEmpty()) {
        throw new IllegalArgumentException(FEATURE_IDENTIFIER_CANNOT_BE_NULL_NOR_EMPTY);
    }
    if (!exist(uid)) {
        throw new FeatureNotFoundException(uid);
    }
    Document target = BUILDER.getFeatUid(uid);
    Object enabledd = BUILDER.getEnable(enable);
    getFeaturesCollection().updateOne(target, new Document(MONGO_SET, enabledd));
}
Also used : Document(org.bson.Document) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException)

Example 17 with FeatureNotFoundException

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

the class FeatureStoreMongo method addToGroup.

/**
 * {@inheritDoc}
 */
@Override
public void addToGroup(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);
    }
    Document target = BUILDER.getFeatUid(uid);
    Document nGroupName = BUILDER.getGroupName(groupName);
    getFeaturesCollection().updateOne(target, new Document(MONGO_SET, nGroupName));
}
Also used : Document(org.bson.Document) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException)

Example 18 with FeatureNotFoundException

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

the class FF4jResource method checkPOST.

/**
 * Check if feature if flipped
 *
 * @param formParams
 *      target custom params
 * @return
 *      boolean if feature if flipped
 */
@POST
@Path("/" + OPERATION_CHECK + "/{uid}")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@ApiOperation(value = "<b>Advanced check</b> feature toggle (parameterized)", response = Boolean.class)
@ApiResponses({ @ApiResponse(code = 200, message = "if feature is flipped"), @ApiResponse(code = 400, message = "Invalid parameter") })
public Response checkPOST(@Context HttpHeaders headers, @PathParam("uid") String uid, MultivaluedMap<String, String> formParams) {
    // HoldSecurity Context
    FF4JSecurityContextHolder.save(securityContext);
    if (!ff4j.getFeatureStore().exist(uid)) {
        String errMsg = new FeatureNotFoundException(uid).getMessage();
        return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build();
    }
    // Flipping Strategy may expected some dedicated parameters if not present, will return 400
    FlippingExecutionContext flipExecCtx = new FlippingExecutionContext();
    for (String key : formParams.keySet()) {
        flipExecCtx.putString(key, formParams.getFirst(key));
    }
    try {
        boolean flipped = ff4j.check(uid, flipExecCtx);
        return Response.ok(String.valueOf(flipped)).build();
    } catch (IllegalArgumentException iae) {
        String errMsg = "Invalid parameter " + iae.getMessage();
        return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
    }
}
Also used : FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 19 with FeatureNotFoundException

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

the class FeatureResource method operationRemoveRole.

/**
 * Convenient method to update partially the feature: Here removing a role
 *
 * @return http response.
 */
@POST
@RolesAllowed({ ROLE_WRITE })
@Path("/" + OPERATION_REMOVEROLE + "/{role}")
@ApiOperation(value = "Remove a permission on a feature", response = Response.class)
@ApiResponses({ @ApiResponse(code = 204, message = "Permission has been granted"), @ApiResponse(code = 404, message = "Feature not found"), @ApiResponse(code = 400, message = "Invalid RoleName") })
public Response operationRemoveRole(@PathParam("uid") String id, @PathParam("role") String role) {
    if (!ff4j.getFeatureStore().exist(id)) {
        String errMsg = new FeatureNotFoundException(id).getMessage();
        return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build();
    }
    Set<String> permissions = ff4j.getFeatureStore().read(id).getPermissions();
    if (!permissions.contains(role)) {
        String errMsg = "Invalid role should be within " + permissions;
        return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
    }
    getFeatureStore().removeRoleFromFeature(id, role);
    return Response.noContent().build();
}
Also used : FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 20 with FeatureNotFoundException

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

the class MonitoringResource method getFeatureMonitoring.

/**
 * Provide core information on store and available sub resources.
 */
@GET
@Path("/{uid}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Display <b>Monitoring</b> for a <b><u>single</u></b> feature", notes = "Each feature will display a pieChart and a barChart for hits", response = FeatureMonitoringApiBean.class)
@ApiResponses({ @ApiResponse(code = 200, message = "Status of current ff4j monitoring bean", response = FeatureMonitoringApiBean.class), @ApiResponse(code = 404, message = "Feature not found", response = String.class) })
public Response getFeatureMonitoring(@ApiParam(required = true, name = "uid", value = "Unique identifier of feature") @PathParam("uid") String uid, @ApiParam(required = false, name = "start", value = "Start of window <br>(default is today 00:00)") @QueryParam(PARAM_START) Long start, @ApiParam(required = false, name = "end", value = "End  of window <br>(default is tomorrow 00:00)") @QueryParam(PARAM_END) Long end) {
    if (!ff4j.getFeatureStore().exist(uid)) {
        String errMsg = new FeatureNotFoundException(uid).getMessage();
        return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build();
    }
    // Today
    Calendar c = Calendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    if (start == null) {
        start = c.getTimeInMillis();
    }
    // Tomorrow 00:00
    Calendar c2 = Calendar.getInstance();
    c2.setTime(new Date(System.currentTimeMillis() + 1000 * 3600 * 24));
    c2.set(Calendar.HOUR_OF_DAY, 0);
    c2.set(Calendar.MINUTE, 0);
    c2.set(Calendar.SECOND, 0);
    if (end == null) {
        end = c2.getTimeInMillis();
    }
    // Build response
    FeatureMonitoringApiBean fmab = new FeatureMonitoringApiBean(uid);
    int hitcount = 0;
    for (PieSectorApiBean sec : fmab.getEventsPie().getSectors()) {
        hitcount += sec.getValue();
    }
    fmab.setHitCount(hitcount);
    return Response.ok().entity(fmab).build();
}
Also used : FeatureMonitoringApiBean(org.ff4j.web.api.resources.domain.FeatureMonitoringApiBean) PieSectorApiBean(org.ff4j.web.api.resources.domain.PieSectorApiBean) Calendar(java.util.Calendar) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

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