use of amu.zhcet.data.course.registration.CourseRegistration in project zhcet-web by zhcet-amu.
the class AttendanceDownloadController method downloadAttendanceForFaculty.
/**
* Downloads attendance for course taught by faculty. Shown in attendance upload section of the course in Faculty Panel
* @param response Response object to be sent, containing the attendance CSV
* @param code The course and section code for faculty, of the form course:section
*/
@GetMapping("/admin/faculty/courses/{code}/attendance.csv")
public ResponseEntity<InputStreamResource> downloadAttendanceForFaculty(HttpServletResponse response, @PathVariable String code) {
CourseInCharge courseInCharge = courseInChargeService.getCourseInCharge(code).orElseThrow(CourseInChargeNotFoundException::new);
String section = StringUtils.defaultString(CourseInChargeService.getCodeAndSection(code).getRight(), "all");
List<CourseRegistration> courseRegistrations = courseInChargeService.getCourseRegistrations(courseInCharge);
String suffix = courseInCharge.getFloatedCourse().getCourse().getCode() + "_" + section;
return downloadAttendance("faculty", suffix, courseRegistrations);
}
use of amu.zhcet.data.course.registration.CourseRegistration in project zhcet-web by zhcet-amu.
the class FacultyCourseAttendanceController method attendance.
@GetMapping
public String attendance(Model model, @PathVariable String code) {
CourseInCharge courseInCharge = courseInChargeService.getCourseInCharge(code).orElseThrow(CourseInChargeNotFoundException::new);
model.addAttribute("page_title", courseInCharge.getFloatedCourse().getCourse().getCode() + " - " + courseInCharge.getFloatedCourse().getCourse().getTitle());
model.addAttribute("page_subtitle", "Attendance management for " + courseInCharge.getFloatedCourse().getCourse().getCode());
model.addAttribute("page_description", "Upload attendance for the floated course");
List<CourseRegistration> courseRegistrations = courseInChargeService.getCourseRegistrations(courseInCharge);
List<String> emails = FloatedCourseService.getEmailsFromCourseRegistrations(courseRegistrations.stream()).collect(Collectors.toList());
SortUtils.sortCourseAttendance(courseRegistrations);
model.addAttribute("incharge", courseInCharge);
model.addAttribute("courseRegistrations", courseRegistrations);
model.addAttribute("course", courseInCharge.getFloatedCourse().getCourse());
model.addAttribute("email_list", emails);
return "faculty/course_attendance";
}
use of amu.zhcet.data.course.registration.CourseRegistration in project zhcet-web by zhcet-amu.
the class CourseRegistrationUploadService method registerStudents.
@Transactional
public List<CourseRegistration> registerStudents(Course course, Confirmation<CourseRegistration> confirmation) {
Optional<FloatedCourse> floatedCourseOptional = floatedCourseService.getFloatedCourse(course);
if (!floatedCourseOptional.isPresent())
return Collections.emptyList();
FloatedCourse floatedCourse = floatedCourseOptional.get();
List<CourseRegistration> registrations = new ArrayList<>();
for (CourseRegistration registration : confirmation.getData()) {
registration.setFloatedCourse(floatedCourse);
registration.getAttendance().setId(registration.generateId());
registrations.add(registration);
}
floatedCourse.getCourseRegistrations().addAll(registrations);
floatedCourseService.save(floatedCourse);
return registrations;
}
use of amu.zhcet.data.course.registration.CourseRegistration in project zhcet-web by zhcet-amu.
the class SortUtilsTest method testSortCourseRegistrations.
@Test
public void testSortCourseRegistrations() {
CourseRegistration areebRegistration = new CourseRegistration();
CourseRegistration divyRegistration = new CourseRegistration();
CourseRegistration saimRegistration = new CourseRegistration();
Student areeb = new Student();
Student divy = new Student();
Student saim = new Student();
areebRegistration.setStudent(areeb);
divyRegistration.setStudent(divy);
saimRegistration.setStudent(saim);
areeb.setFacultyNumber(AREEB_FACULTY_NO);
areeb.setSection(SECTION_A4PE);
divy.setFacultyNumber(DIVY_FACULTY_NO);
divy.setSection(SECTION_A4PE);
saim.setFacultyNumber(SAIM_FACULTY_NO);
saim.setSection(SECTION_A5PE);
List<CourseRegistration> courseRegistrations = new ArrayList<>();
courseRegistrations.addAll(Arrays.asList(divyRegistration, saimRegistration, areebRegistration));
SortUtils.sortCourseAttendance(courseRegistrations);
assertThat(courseRegistrations, contains(areebRegistration, divyRegistration, saimRegistration));
}
use of amu.zhcet.data.course.registration.CourseRegistration in project zhcet-web by zhcet-amu.
the class AttendanceDownloadController method downloadAttendance.
private ResponseEntity<InputStreamResource> downloadAttendance(String context, String suffix, List<CourseRegistration> courseRegistrations) {
try {
InputStream stream = attendanceDownloadService.getAttendanceStream(suffix, context, courseRegistrations);
String lastModified = getLastModifiedDate(courseRegistrations).map(localDateTime -> "_" + localDateTime.format(DateTimeFormatter.ISO_DATE_TIME)).orElse("");
return ResponseEntity.ok().contentType(MediaType.parseMediaType("text/csv")).header("Content-disposition", "attachment;filename=attendance_" + suffix + lastModified + ".csv").body(new InputStreamResource(stream));
} catch (IOException e) {
log.error("Attendance Download Error", e);
return ResponseEntity.notFound().build();
}
}
Aggregations