Search in sources :

Example 1 with Attendance

use of amu.zhcet.data.attendance.Attendance 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 2 with Attendance

use of amu.zhcet.data.attendance.Attendance 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

Attendance (amu.zhcet.data.attendance.Attendance)2 CourseInCharge (amu.zhcet.data.course.incharge.CourseInCharge)2 IOException (java.io.IOException)2 List (java.util.List)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 StringUtils (amu.zhcet.common.utils.StringUtils)1 ErrorUtils (amu.zhcet.core.error.ErrorUtils)1 AttendanceService (amu.zhcet.data.attendance.AttendanceService)1 Course (amu.zhcet.data.course.Course)1 FloatedCourse (amu.zhcet.data.course.floated.FloatedCourse)1 FloatedCourseNotFoundException (amu.zhcet.data.course.floated.FloatedCourseNotFoundException)1 FloatedCourseService (amu.zhcet.data.course.floated.FloatedCourseService)1 CourseInChargeNotFoundException (amu.zhcet.data.course.incharge.CourseInChargeNotFoundException)1 CourseInChargeService (amu.zhcet.data.course.incharge.CourseInChargeService)1 CourseRegistration (amu.zhcet.data.course.registration.CourseRegistration)1 Department (amu.zhcet.data.department.Department)1 Confirmation (amu.zhcet.storage.csv.Confirmation)1 UploadResult (amu.zhcet.storage.csv.UploadResult)1 InputStream (java.io.InputStream)1