use of net.atos.entng.statistics.Statistics in project statistics by OPEN-ENT-NG.
the class StatisticsController method generation.
@Get("/generation")
@SecuredAction(value = "", type = ActionType.RESOURCE)
@ResourceFilter(SuperAdminFilter.class)
public /**
* Generation of statistics to mongoDB database. Calls the same treatment as the one called by cron
* Before the generation, deletes the records who will be regenerated.
*/
void generation(final HttpServerRequest request) {
RequestUtils.bodyToJson(request, pathPrefix + "schoolquery", new Handler<JsonObject>() {
@Override
public void handle(JsonObject data) {
// parameters from the model (schoolIdArray / indicator / startDate / endDate / module)
final JsonObject params = data;
UserUtils.getUserInfos(eb, request, new Handler<UserInfos>() {
@Override
public void handle(final UserInfos user) {
final Date startDate = new Date(params.getLong("startDate") * 1000L);
final Date endDate = new Date(params.getLong("endDate") * 1000L);
// final Date startDate = new Date(Long.parseLong(request.params().get(PARAM_START_DATE)) * 1000L);
// final Date endDate = new Date(Long.parseLong(request.params().get(PARAM_END_DATE)) * 1000L);
deleteRegeneratedStatistics(startDate, endDate, new Handler<Either<String, JsonArray>>() {
@Override
public void handle(Either<String, JsonArray> event) {
if (event.isLeft()) {
log.error(event.left().getValue());
renderError(request);
} else {
if (user != null) {
Statistics st = new Statistics();
st.aggregateEvents(StatisticsController.this.vertx, startDate, endDate);
JsonArray jarray = new JsonArray();
jarray.add(String.valueOf(params.getInteger("startDate")));
renderJson(request, jarray);
}
}
}
});
}
});
}
});
}
Aggregations