Search in sources :

Example 6 with CourseInCharge

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

the class AttendanceUploadService method updateAttendance.

@Transactional
public void updateAttendance(CourseInCharge courseInCharge, List<AttendanceUpload> uploadList) {
    Map<String, AttendanceUpload> attendanceUploadMap = uploadList.stream().collect(Collectors.toMap(AttendanceUpload::getEnrolmentNo, item -> item));
    List<Attendance> attendances = attendanceService.getAttendanceByCourseInChargeAndStudents(courseInCharge, attendanceUploadMap.keySet());
    for (Attendance attendance : attendances) {
        AttendanceUpload attendanceUpload = attendanceUploadMap.get(attendance.getCourseRegistration().getStudent().getEnrolmentNumber());
        attendance.setDelivered(attendanceUpload.getDelivered());
        attendance.setAttended(attendanceUpload.getAttended());
    }
    attendanceService.save(attendances);
    eventPublisher.publishEvent(new AttendanceUploadEvent(courseInCharge, attendances));
}
Also used : Attendance(amu.zhcet.data.attendance.Attendance) CourseInCharge(amu.zhcet.data.course.incharge.CourseInCharge) Transactional(javax.transaction.Transactional) Autowired(org.springframework.beans.factory.annotation.Autowired) AttendanceService(amu.zhcet.data.attendance.AttendanceService) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) UploadResult(amu.zhcet.storage.csv.UploadResult) Service(org.springframework.stereotype.Service) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) MultipartFile(org.springframework.web.multipart.MultipartFile) Confirmation(amu.zhcet.storage.csv.Confirmation) Attendance(amu.zhcet.data.attendance.Attendance) Transactional(javax.transaction.Transactional)

Example 7 with CourseInCharge

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

the class DiffUtilsTest method courseInChargeShouldBeDifferentWithDifferentSection.

@Test
public void courseInChargeShouldBeDifferentWithDifferentSection() {
    CourseInCharge courseInCharge1 = getCourseInCharge(23L, floatedCourse, dean, null);
    CourseInCharge courseInCharge2 = getCourseInCharge(23L, floatedCourse, dean, "A4PE");
    assertFalse(courseInCharge1.equals(courseInCharge2));
    assertFalse(courseInCharge2.equals(courseInCharge1));
}
Also used : CourseInCharge(amu.zhcet.data.course.incharge.CourseInCharge) Test(org.junit.Test)

Example 8 with CourseInCharge

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

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

Example 10 with CourseInCharge

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

the class DiffUtilsTest method courseInChargeShouldBeSameWithDifferentId.

@Test
public void courseInChargeShouldBeSameWithDifferentId() {
    CourseInCharge courseInCharge1 = getCourseInCharge(23L, floatedCourse, dean, null);
    CourseInCharge courseInCharge2 = getCourseInCharge(54L, floatedCourse, dean, null);
    assertTrue(courseInCharge1.equals(courseInCharge2));
    assertTrue(courseInCharge2.equals(courseInCharge1));
}
Also used : CourseInCharge(amu.zhcet.data.course.incharge.CourseInCharge) Test(org.junit.Test)

Aggregations

CourseInCharge (amu.zhcet.data.course.incharge.CourseInCharge)13 CourseInChargeNotFoundException (amu.zhcet.data.course.incharge.CourseInChargeNotFoundException)5 Test (org.junit.Test)4 IOException (java.io.IOException)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 CourseRegistration (amu.zhcet.data.course.registration.CourseRegistration)2 List (java.util.List)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Attendance (amu.zhcet.data.attendance.Attendance)1 AttendanceService (amu.zhcet.data.attendance.AttendanceService)1 FloatedCourse (amu.zhcet.data.course.floated.FloatedCourse)1 CourseInChargeService (amu.zhcet.data.course.incharge.CourseInChargeService)1 FacultyMember (amu.zhcet.data.user.faculty.FacultyMember)1 FacultyMemberNotFoundException (amu.zhcet.data.user.faculty.FacultyMemberNotFoundException)1 FacultyService (amu.zhcet.data.user.faculty.FacultyService)1 Confirmation (amu.zhcet.storage.csv.Confirmation)1 UploadResult (amu.zhcet.storage.csv.UploadResult)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1