use of org.ff4j.audit.EventQueryDefinition in project ff4j by ff4j.
the class ConsoleRenderer method renderAuditRows.
private static final String renderAuditRows(FF4j ff4j, HttpServletRequest req) {
StringBuilder sb = new StringBuilder();
EventRepository er = ff4j.getEventRepository();
EventQueryDefinition query = new EventQueryDefinition();
for (Event event : er.searchFeatureUsageEvents(query)) {
sb.append("<tr>" + END_OF_LINE);
sb.append("<td>" + SDF.format(new Date(event.getTimestamp())) + "</td>");
sb.append("<td>" + event.getType() + "</td>");
sb.append("<td>" + event.getName() + "</td>");
sb.append("<td>" + event.getAction() + "</td>");
sb.append("</tr>");
}
return sb.toString();
}
use of org.ff4j.audit.EventQueryDefinition in project ff4j by ff4j.
the class OperationsController method graphFeatureUsageHitCountasJson.
/**
* Generation of JSON to render Features.
*
* @param req
* current request
* @param res
* current response
* @throws IOException
*/
private void graphFeatureUsageHitCountasJson(HttpServletRequest req, HttpServletResponse res) throws IOException {
res.setContentType(CONTENT_TYPE_JSON);
String[] pathParts = req.getPathInfo().split("/");
EventQueryDefinition query = parseQuery(req);
if (pathParts.length > 3) {
String graphName = pathParts[3];
if (GRAPH_PIE_HITRATIO.equalsIgnoreCase(graphName)) {
PieChart pc = getFf4j().getEventRepository().getFeatureUsagePieChart(query);
res.getWriter().println(pc.toJson());
} else if (GRAPH_BAR_HITRATIO.equalsIgnoreCase(graphName)) {
BarChart bc = getFf4j().getEventRepository().getFeatureUsageBarChart(query);
res.getWriter().println(bc.toJson());
} else if (GRAPH_PIE_HOST.equalsIgnoreCase(graphName)) {
PieChart pc = getFf4j().getEventRepository().getHostPieChart(query);
res.getWriter().println(pc.toJson());
} else if (GRAPH_PIE_SOURCE.equalsIgnoreCase(graphName)) {
PieChart pc = getFf4j().getEventRepository().getSourcePieChart(query);
res.getWriter().println(pc.toJson());
} else if (GRAPH_PIE_USER.equalsIgnoreCase(graphName)) {
PieChart pc = getFf4j().getEventRepository().getUserPieChart(query);
res.getWriter().println(pc.toJson());
}
}
}
use of org.ff4j.audit.EventQueryDefinition in project ff4j by ff4j.
the class OperationsController method graphTimeSeriesasJson.
/**
* Generation of JSON to render Features.
*
* @param req
* current request
* @param res
* current response
* @throws IOException
*/
private void graphTimeSeriesasJson(HttpServletRequest req, HttpServletResponse res) throws IOException {
res.setContentType(CONTENT_TYPE_JSON);
EventQueryDefinition query = parseQuery(req);
TimeSeriesChart tsc = getFf4j().getEventRepository().getFeatureUsageHistory(query, TimeUnit.HOURS);
res.getWriter().println(tsc.toString());
}
use of org.ff4j.audit.EventQueryDefinition in project ff4j by ff4j.
the class AbstractEventRepository method toString.
/**
* {@inheritDoc}
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder("{");
sb.append("\"type\":\"" + this.getClass().getName() + "\"");
EventQueryDefinition q = new EventQueryDefinition();
sb.append(",\"todayHitsPieChart\": " + getFeatureUsagePieChart(q).toJson());
sb.append(",\"todayHitsBarChart\": " + getFeatureUsageBarChart(q).toJson());
getFeatureUsageHistory(q, TimeUnit.HOURS);
sb.append(",\"todayTotalHitCount\":" + getFeatureUsageTotalHitCount(q));
sb.append("}");
return sb.toString();
}
use of org.ff4j.audit.EventQueryDefinition in project ff4j by ff4j.
the class AbstractEventRepositoryTest method testSearchFeatureUsageEvents.
@Test
public void testSearchFeatureUsageEvents() throws InterruptedException {
long start = System.currentTimeMillis();
repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CREATE));
for (int i = 0; i < 8; i++) {
Thread.sleep(100);
repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OK));
repo.saveEvent(new Event(SOURCE_WEB, TARGET_FEATURE, "f2", ACTION_CHECK_OK));
}
Thread.sleep(100);
// Then
EventQueryDefinition testQuery = new EventQueryDefinition(start - 20, System.currentTimeMillis());
EventSeries es = repo.searchFeatureUsageEvents(testQuery);
Assert.assertEquals(16, es.size());
// Then
}
Aggregations