Search in sources :

Example 1 with CourseInChargeNotFoundException

use of amu.zhcet.data.course.incharge.CourseInChargeNotFoundException 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 CourseInChargeNotFoundException

use of amu.zhcet.data.course.incharge.CourseInChargeNotFoundException 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 CourseInChargeNotFoundException

use of amu.zhcet.data.course.incharge.CourseInChargeNotFoundException in project zhcet-web by zhcet-amu.

the class AttendanceUploadController method uploadAttendance.

@PostMapping("/confirm")
public String uploadAttendance(RedirectAttributes attributes, @PathVariable String code, @Valid @ModelAttribute AttendanceModel attendanceModel, BindingResult bindingResult) {
    CourseInCharge courseInCharge = courseInChargeService.getCourseInCharge(code).orElseThrow(CourseInChargeNotFoundException::new);
    if (bindingResult.hasErrors()) {
        attributes.addFlashAttribute("attendanceModel", attendanceModel);
        attributes.addFlashAttribute("org.springframework.validation.BindingResult.attendanceModel", bindingResult);
    } else {
        try {
            attendanceUploadService.updateAttendance(courseInCharge, attendanceModel.getUploadList());
            attributes.addFlashAttribute("updated", true);
        } catch (Exception e) {
            log.error("Attendance Confirm", e);
            attributes.addFlashAttribute("attendanceModel", attendanceModel);
            attributes.addFlashAttribute("unknown_error", true);
        }
    }
    return "redirect:/admin/faculty/courses/{code}/attendance";
}
Also used : CourseInCharge(amu.zhcet.data.course.incharge.CourseInCharge) CourseInChargeNotFoundException(amu.zhcet.data.course.incharge.CourseInChargeNotFoundException) IOException(java.io.IOException) CourseInChargeNotFoundException(amu.zhcet.data.course.incharge.CourseInChargeNotFoundException)

Example 4 with CourseInChargeNotFoundException

use of amu.zhcet.data.course.incharge.CourseInChargeNotFoundException in project zhcet-web by zhcet-amu.

the class AttendanceUploadController method uploadFile.

@PostMapping
public String uploadFile(RedirectAttributes attributes, @PathVariable String code, @RequestParam MultipartFile file) {
    CourseInCharge courseInCharge = courseInChargeService.getCourseInCharge(code).orElseThrow(CourseInChargeNotFoundException::new);
    try {
        UploadResult<AttendanceUpload> result = attendanceUploadService.handleUpload(file);
        if (!result.getErrors().isEmpty()) {
            attributes.addFlashAttribute("errors", result.getErrors());
        } else {
            attributes.addFlashAttribute("success", true);
            Confirmation<AttendanceUpload> confirmation = attendanceUploadService.confirmUpload(courseInCharge, result);
            if (confirmation.getErrors().isEmpty()) {
                AttendanceModel attendanceModel = new AttendanceModel();
                List<AttendanceUpload> attendanceUploads = new ArrayList<>(confirmation.getData());
                SortUtils.sortAttendanceUpload(attendanceUploads);
                attendanceModel.setUploadList(attendanceUploads);
                attributes.addFlashAttribute("attendanceModel", attendanceModel);
            } else {
                attributes.addFlashAttribute("confirmAttendanceErrors", confirmation);
            }
        }
    } catch (IOException ioe) {
        log.error("Attendance Upload", ioe);
    }
    return "redirect:/admin/faculty/courses/{code}/attendance";
}
Also used : CourseInCharge(amu.zhcet.data.course.incharge.CourseInCharge) ArrayList(java.util.ArrayList) CourseInChargeNotFoundException(amu.zhcet.data.course.incharge.CourseInChargeNotFoundException) IOException(java.io.IOException)

Example 5 with CourseInChargeNotFoundException

use of amu.zhcet.data.course.incharge.CourseInChargeNotFoundException in project zhcet-web by zhcet-amu.

the class AttendanceUploadController method edit.

@GetMapping
public String edit(RedirectAttributes attributes, @PathVariable String code) {
    CourseInCharge courseInCharge = courseInChargeService.getCourseInCharge(code).orElseThrow(CourseInChargeNotFoundException::new);
    AttendanceModel attendanceModel = new AttendanceModel();
    List<AttendanceUpload> attendanceUploads = courseInChargeService.getCourseRegistrations(courseInCharge).stream().map(attendanceMapper::fromCourseRegistration).collect(Collectors.toList());
    SortUtils.sortAttendanceUpload(attendanceUploads);
    attendanceModel.setUploadList(attendanceUploads);
    attributes.addFlashAttribute("attendanceModel", attendanceModel);
    return "redirect:/admin/faculty/courses/{code}/attendance";
}
Also used : CourseInCharge(amu.zhcet.data.course.incharge.CourseInCharge) CourseInChargeNotFoundException(amu.zhcet.data.course.incharge.CourseInChargeNotFoundException)

Aggregations

CourseInCharge (amu.zhcet.data.course.incharge.CourseInCharge)5 CourseInChargeNotFoundException (amu.zhcet.data.course.incharge.CourseInChargeNotFoundException)5 CourseRegistration (amu.zhcet.data.course.registration.CourseRegistration)2 IOException (java.io.IOException)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ArrayList (java.util.ArrayList)1