new HashMap<ExecutionSemester, ExecutionPeriodStatisticsBean>();
for (StudentCurricularPlan studentCurricularPlan : getSortedStudentCurricularPlans(registration)) {
for (ExecutionSemester executionSemester : studentCurricularPlan.getEnrolmentsExecutionPeriods()) {
if (enrolmentsByExecutionPeriod.containsKey(executionSemester)) {
ExecutionPeriodStatisticsBean executionPeriodStatisticsBean =
enrolmentsByExecutionPeriod.get(executionSemester);
executionPeriodStatisticsBean.addEnrolmentsWithinExecutionPeriod(studentCurricularPlan
.getEnrolmentsByExecutionPeriod(executionSemester));
enrolmentsByExecutionPeriod.put(executionSemester, executionPeriodStatisticsBean);
} else {
ExecutionPeriodStatisticsBean executionPeriodStatisticsBean =
new ExecutionPeriodStatisticsBean(executionSemester);
executionPeriodStatisticsBean.addEnrolmentsWithinExecutionPeriod(studentCurricularPlan
.getEnrolmentsByExecutionPeriod(executionSemester));
enrolmentsByExecutionPeriod.put(executionSemester, executionPeriodStatisticsBean);
}
}
}
studentStatistics.addAll(enrolmentsByExecutionPeriod.values());
Collections.sort(studentStatistics, new BeanComparator("executionPeriod"));
/* Put all the info in the required JSON format */
JsonObject curricularInfoJSONObject = new JsonObject();
JsonArray periodsJSONArray = new JsonArray();
for (ExecutionPeriodStatisticsBean executionPeriodStatisticsBean : studentStatistics) {
JsonArray jsonArray = new JsonArray();
jsonArray.add(new JsonPrimitive(executionPeriodStatisticsBean.getExecutionPeriod().getExecutionYear().getYear()
+ " - " + executionPeriodStatisticsBean.getExecutionPeriod().getSemester().toString() + "ยบ sem"));
jsonArray.add(new JsonPrimitive(executionPeriodStatisticsBean.getTotalEnrolmentsNumber()));
jsonArray.add(new JsonPrimitive(executionPeriodStatisticsBean.getApprovedEnrolmentsNumber()));
periodsJSONArray.add(jsonArray);
}
curricularInfoJSONObject.add("periods", periodsJSONArray);
/* Serve the JSON object */