Search in sources :

Example 1 with Get

use of fr.wseduc.rs.Get 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);
                                }
                            }
                        }
                    });
                }
            });
        }
    });
}
Also used : JsonArray(org.vertx.java.core.json.JsonArray) JsonObject(org.vertx.java.core.json.JsonObject) Handler(org.vertx.java.core.Handler) Either(fr.wseduc.webutils.Either) UserInfos(org.entcore.common.user.UserInfos) Statistics(net.atos.entng.statistics.Statistics) ResourceFilter(org.entcore.common.http.filter.ResourceFilter) SecuredAction(fr.wseduc.security.SecuredAction) Get(fr.wseduc.rs.Get)

Aggregations

Get (fr.wseduc.rs.Get)1 SecuredAction (fr.wseduc.security.SecuredAction)1 Either (fr.wseduc.webutils.Either)1 Statistics (net.atos.entng.statistics.Statistics)1 ResourceFilter (org.entcore.common.http.filter.ResourceFilter)1 UserInfos (org.entcore.common.user.UserInfos)1 Handler (org.vertx.java.core.Handler)1 JsonArray (org.vertx.java.core.json.JsonArray)1 JsonObject (org.vertx.java.core.json.JsonObject)1