use of fr.wseduc.rs.ApiDoc in project statistics by OPEN-ENT-NG.
the class StatisticsController method getStructures.
@Post("/structures")
@ApiDoc("Get structures' names, UAIs and cities")
@SecuredAction("statistics.get.structures")
public void getStructures(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) {
if (user != null) {
JsonArray arr = params.getArray("schoolIdArray");
List<String> schoolIds = new ArrayList<String>();
for (int i = 0; i < arr.size(); i++) {
JsonObject obj = arr.get(i);
schoolIds.add((String) obj.getString("id"));
}
if (schoolIds == null || schoolIds.size() == 0) {
String errorMsg = i18n.translate("statistics.bad.request.invalid.schools", getHost(request), acceptLanguage(request));
badRequest(request, errorMsg);
return;
}
JsonArray structureIds = new JsonArray();
for (String school : schoolIds) {
structureIds.addString(school);
}
structureService.list(structureIds, new Handler<Either<String, JsonArray>>() {
@Override
public void handle(Either<String, JsonArray> event) {
if (event.isLeft()) {
log.error(event.left().getValue());
renderError(request);
} else {
renderJson(request, event.right().getValue());
}
}
});
}
// end if
}
});
}
});
}
Aggregations