public class DownloadStudentsWithAttendsByExecutionCourseListWithGradesActionForTeacher extends FenixDispatchAction {
public ActionForward downloadStudentListForGradesForm(final ActionMapping mapping, final ActionForm form,
final HttpServletRequest request, final HttpServletResponse response) {
final ExecutionCourse executionCourse = getDomainObject(request, "executionCourseOID");
final Spreadsheet spreadsheet = new Spreadsheet(executionCourse.getSigla());
spreadsheet.setHeader(BundleUtil.getString(Bundle.APPLICATION, "label.username"));
spreadsheet.setHeader(BundleUtil.getString(Bundle.APPLICATION, "label.number"));
spreadsheet.setHeader(BundleUtil.getString(Bundle.APPLICATION, "label.name"));
spreadsheet.setHeader(BundleUtil.getString(Bundle.APPLICATION, "label.degree.code"));
spreadsheet.setHeader(BundleUtil.getString(Bundle.APPLICATION, "label.attends.enrollmentState"));
final List<Evaluation> evaluations = executionCourse.getOrderedAssociatedEvaluations();
for (final Evaluation evaluation : evaluations) {
spreadsheet.setHeader(evaluation.getPresentationName());
}
for (final Attends attends : executionCourse.getOrderedAttends()) {
final Registration registration = attends.getRegistration();
final Row row = spreadsheet.addRow();
row.setCell(registration.getPerson().getUsername());
row.setCell(registration.getNumber());
row.setCell(registration.getName());
row.setCell(registration.getDegree().getSigla());
if (attends.getEnrolment() != null) {
final EnrolmentEvaluationType enrolmentEvaluationType = attends.getEnrolmentEvaluationType();
row.setCell(enrolmentEvaluationType.getDescription());
} else {
row.setCell(BundleUtil.getString(Bundle.APPLICATION, "label.attends.enrollmentState.notEnrolled"));
}
for (final Evaluation evaluation : evaluations) {
final Mark mark = findMark(attends, evaluation);
if (mark == null) {
row.setCell(" ");
} else {
row.setCell(mark.getMark());
}
}
}
try {
response.setHeader("Content-disposition", "attachment; filename=" + executionCourse.getSigla() + ".xls");
response.setContentType("application/vnd.ms-excel");
final ServletOutputStream outputStream = response.getOutputStream();
spreadsheet.exportToXLSSheet(outputStream);
outputStream.close();