/** * Convenient method to update partially the feature: Here enabling * * @return http response. */ @POST @Path("/" + OPERATION_UPDATE) @RolesAllowed({ROLE_WRITE}) @ApiOperation(value= "Update a property", response=Response.class) @ApiResponses({ @ApiResponse(code = 204, message= "Property has been updated"), @ApiResponse(code = 404, message= "Property not found"), @ApiResponse(code = 400, message= "Invalid new value") }) public Response operationUpdate(@PathParam("name") String name, @PathParam("groupName") String newValue) { if (!ff4j.getPropertiesStore().existProperty(name)) { String errMsg = new FeatureNotFoundException(name).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } getPropertyStore().updateProperty(name, newValue); return Response.noContent().build(); }
/** * Convenient method to update partially the feature: Adding to a group * * @return http response. */ @POST @RolesAllowed({ROLE_WRITE}) @Path("/" + OPERATION_ADDGROUP + "/{groupName}" ) @ApiOperation(value= "Define the group of the feature", response=Response.class) @ApiResponses({ @ApiResponse(code = 204, message= "Group has been defined"), @ApiResponse(code = 404, message= "Feature not found"), @ApiResponse(code = 400, message= "Invalid GroupName") }) public Response operationAddGroup(@PathParam("uid") String id, @PathParam("groupName") String groupName) { if (!ff4j.getFeatureStore().exist(id)) { String errMsg = new FeatureNotFoundException(id).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } if ("".equals(groupName)) { String errMsg = "Invalid groupName should not be null nor empty"; return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build(); } getFeatureStore().addToGroup(id, groupName); return Response.noContent().build(); }
/** * Convenient method to update partially the feature: Here disabling * * @return http response. */ @POST @Path("/" + OPERATION_DISABLE) @RolesAllowed({ROLE_WRITE}) @ApiOperation(value= "Disable a feature", response=Response.class) @ApiResponses({ @ApiResponse(code = 204, message= "Features has been disabled"), @ApiResponse(code = 404, message= "Feature not found") }) public Response operationDisable(@PathParam("uid") String id) { if (!ff4j.getFeatureStore().exist(id)) { String errMsg = new FeatureNotFoundException(id).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } getFeatureStore().disable(id); return Response.noContent().build(); }
/** * Check if feature if flipped * * @param formParams * target custom params * @return * boolean if feature if flipped */ @GET @Path("/" + OPERATION_CHECK + "/{uid}") @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value= "<b>Simple check</b> feature toggle", response=Boolean.class) @ApiResponses({ @ApiResponse(code = 200, message= "if feature is flipped"), @ApiResponse(code = 400, message= "Invalid parameter"), @ApiResponse(code = 404, message= "feature has not been found")}) public Response check(@Context HttpHeaders headers, @PathParam("uid") String uid) { // HoldSecurity Context FF4JSecurityContextHolder.save(securityContext); // Expected Custom FlipStrategy (JSON) if (!ff4j.getFeatureStore().exist(uid)) { String errMsg = new FeatureNotFoundException(uid).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } return Response.ok(String.valueOf(ff4j.check(uid))).build(); }
/** * Convenient method to update partially the feature: Here grant a role * * @return http response. */ @POST @RolesAllowed({ROLE_WRITE}) @Path("/" + OPERATION_GRANTROLE + "/{role}" ) @ApiOperation(value= "Grant 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 operationGrantRole(@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(); } if ("".equals(role)) { String errMsg = "Invalid role should not be null nor empty"; return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build(); } getFeatureStore().grantRoleOnFeature(id, role); return Response.noContent().build(); }
/** * Convenient method to update partially the feature: Here enabling * * @return http response. */ @POST @Path("/" + OPERATION_ENABLE) @RolesAllowed({ROLE_WRITE}) @ApiOperation(value= "Enable a feature", response=Response.class) @ApiResponses({ @ApiResponse(code = 204, message= "Features has been enabled"), @ApiResponse(code = 404, message= "Feature not found") }) public Response operationEnable(@PathParam("uid") String id) { if (!ff4j.getFeatureStore().exist(id)) { String errMsg = new FeatureNotFoundException(id).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } getFeatureStore().enable(id); return Response.noContent().build(); }
/** * Delete feature by its id. * * @return delete by its id. */ @DELETE @RolesAllowed({ROLE_WRITE}) @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value= "Delete a feature", response=Response.class) @ApiResponses({ @ApiResponse(code = 404, message= "Feature has not been found"), @ApiResponse(code = 204, message= "No content, feature is deleted"), @ApiResponse(code = 400, message= "Bad identifier"), }) public Response deleteFeature(@PathParam("uid") String id) { if (id == null || "".equals(id)) { String errMsg = "Invalid URL : Must be '/features/{uid}' with {uid} not null nor empty"; return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build(); } if (!ff4j.getFeatureStore().exist(id)) { String errMsg = new FeatureNotFoundException(id).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } getFeatureStore().delete(id); return Response.noContent().build(); }
/** * Delete feature by its id. * * @return delete by its id. */ @DELETE @RolesAllowed({ROLE_WRITE}) @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value= "Delete a Property", response=Response.class) @ApiResponses({ @ApiResponse(code = 404, message= "Property has not been found"), @ApiResponse(code = 204, message= "No content, Property is deleted"), @ApiResponse(code = 400, message= "Bad identifier"), }) public Response deleteProperty(@PathParam("name") String name) { if (name == null || "".equals(name)) { String errMsg = "Invalid URL : Must be '/properties/{name}' with {name} not null nor empty"; return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build(); } if (!ff4j.getPropertiesStore().existProperty(name)) { String errMsg = new FeatureNotFoundException(name).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } getPropertyStore().deleteProperty(name); return Response.noContent().build(); }
String errMsg = new FeatureNotFoundException(uid).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build();
/** * Allows to retrieve feature by its id. * * @param featId * target feature identifier * @return feature is exist */ @GET @RolesAllowed({ROLE_READ}) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value= "Read information about a feature", response=FeatureApiBean.class) @ApiResponses({ @ApiResponse(code = 200, message= "Information about features"), @ApiResponse(code = 404, message= "Feature not found") }) public Response read(@PathParam("uid") String id) { if (!ff4j.getFeatureStore().exist(id)) { String errMsg = new FeatureNotFoundException(id).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } return Response.ok(new FeatureApiBean(ff4j.getFeatureStore().read(id))).build(); }
/** * Convenient method to update partially the feature: Removing from a group * * @return http response. */ @POST @RolesAllowed({ROLE_WRITE}) @Path("/" + OPERATION_REMOVEGROUP + "/{groupName}") @ApiOperation(value= "Remove the group of the feature", response=Response.class) @ApiResponses({ @ApiResponse(code = 204, message= "Group has been removed"), @ApiResponse(code = 404, message= "Feature not found"), @ApiResponse(code = 400, message= "Invalid GroupName") }) public Response operationRemoveGroup(@PathParam("uid") String id, @PathParam("groupName") String groupName) { if (!ff4j.getFeatureStore().exist(id)) { String errMsg = new FeatureNotFoundException(id).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } // Expected behaviour is no error even if invalid groupname // .. but invalid if group does not exist... if (!ff4j.getFeatureStore().existGroup(groupName)) { String errMsg = "Invalid groupName should be " + groupName; return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build(); } getFeatureStore().removeFromGroup(id, groupName); return Response.noContent().build(); }
@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();
/** * 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(); }