Search in sources :

Example 1 with CourseRegistration

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);
}
Also used : CourseRegistration(amu.zhcet.data.course.registration.CourseRegistration) CourseInCharge(amu.zhcet.data.course.incharge.CourseInCharge) CourseInChargeNotFoundException(amu.zhcet.data.course.incharge.CourseInChargeNotFoundException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with CourseRegistration

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";
}
Also used : CourseRegistration(amu.zhcet.data.course.registration.CourseRegistration) CourseInCharge(amu.zhcet.data.course.incharge.CourseInCharge) CourseInChargeNotFoundException(amu.zhcet.data.course.incharge.CourseInChargeNotFoundException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with CourseRegistration

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;
}
Also used : CourseRegistration(amu.zhcet.data.course.registration.CourseRegistration) FloatedCourse(amu.zhcet.data.course.floated.FloatedCourse) ArrayList(java.util.ArrayList) Transactional(javax.transaction.Transactional)

Example 4 with CourseRegistration

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));
}
Also used : CourseRegistration(amu.zhcet.data.course.registration.CourseRegistration) ArrayList(java.util.ArrayList) Student(amu.zhcet.data.user.student.Student) Test(org.junit.Test)

Example 5 with CourseRegistration

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();
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) CourseRegistration(amu.zhcet.data.course.registration.CourseRegistration) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) ErrorUtils(amu.zhcet.core.error.ErrorUtils) InputStreamResource(org.springframework.core.io.InputStreamResource) FloatedCourseNotFoundException(amu.zhcet.data.course.floated.FloatedCourseNotFoundException) GetMapping(org.springframework.web.bind.annotation.GetMapping) CourseInChargeNotFoundException(amu.zhcet.data.course.incharge.CourseInChargeNotFoundException) Attendance(amu.zhcet.data.attendance.Attendance) CourseInCharge(amu.zhcet.data.course.incharge.CourseInCharge) StringUtils(amu.zhcet.common.utils.StringUtils) Department(amu.zhcet.data.department.Department) MediaType(org.springframework.http.MediaType) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) CourseInChargeService(amu.zhcet.data.course.incharge.CourseInChargeService) Course(amu.zhcet.data.course.Course) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) FloatedCourse(amu.zhcet.data.course.floated.FloatedCourse) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) Comparator(java.util.Comparator) FloatedCourseService(amu.zhcet.data.course.floated.FloatedCourseService) InputStream(java.io.InputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) InputStreamResource(org.springframework.core.io.InputStreamResource)

Aggregations

CourseRegistration (amu.zhcet.data.course.registration.CourseRegistration)8 FloatedCourse (amu.zhcet.data.course.floated.FloatedCourse)4 FloatedCourseNotFoundException (amu.zhcet.data.course.floated.FloatedCourseNotFoundException)3 CourseInCharge (amu.zhcet.data.course.incharge.CourseInCharge)3 CourseInChargeNotFoundException (amu.zhcet.data.course.incharge.CourseInChargeNotFoundException)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 Student (amu.zhcet.data.user.student.Student)2 ArrayList (java.util.ArrayList)2 StringUtils (amu.zhcet.common.utils.StringUtils)1 ErrorUtils (amu.zhcet.core.error.ErrorUtils)1 Attendance (amu.zhcet.data.attendance.Attendance)1 Course (amu.zhcet.data.course.Course)1 FloatedCourseService (amu.zhcet.data.course.floated.FloatedCourseService)1 CourseInChargeService (amu.zhcet.data.course.incharge.CourseInChargeService)1 Department (amu.zhcet.data.department.Department)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 LocalDateTime (java.time.LocalDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 Comparator (java.util.Comparator)1