Search in sources :

Example 1 with PieSectorApiBean

use of org.ff4j.web.api.resources.domain.PieSectorApiBean 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

ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 FeatureNotFoundException (org.ff4j.exception.FeatureNotFoundException)1 FeatureMonitoringApiBean (org.ff4j.web.api.resources.domain.FeatureMonitoringApiBean)1 PieSectorApiBean (org.ff4j.web.api.resources.domain.PieSectorApiBean)1