diff --git a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/DateTimeFormatConfiguration.java b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/DateTimeFormatConfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..8062a99e66ef5c827049fb5883939b5c2b150708 --- /dev/null +++ b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/DateTimeFormatConfiguration.java @@ -0,0 +1,17 @@ +package com.tarento.upsmf.examsAndAdmissions; + +import org.springframework.context.annotation.Configuration; +import org.springframework.format.FormatterRegistry; +import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class DateTimeFormatConfiguration implements WebMvcConfigurer { + + @Override + public void addFormatters(FormatterRegistry registry) { + DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar(); + registrar.setUseIsoFormat(true); + registrar.registerFormatters(registry); + } +} diff --git a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/controller/StudentController.java b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/controller/StudentController.java index 571000fb7a1e60725e3cde90de2144f3f4e76358..3e3cac43b762dec07120ed3fa592e6ea2c50ec97 100644 --- a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/controller/StudentController.java +++ b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/controller/StudentController.java @@ -4,6 +4,7 @@ import com.tarento.upsmf.examsAndAdmissions.model.Student; import com.tarento.upsmf.examsAndAdmissions.model.VerificationStatus; import com.tarento.upsmf.examsAndAdmissions.model.dto.StudentDto; import com.tarento.upsmf.examsAndAdmissions.service.StudentService; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -11,13 +12,14 @@ import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.io.IOException; +import java.time.LocalDate; import java.util.List; import java.util.Optional; @RestController @RequestMapping("/students") +@Slf4j public class StudentController { - @Autowired private StudentService studentService; @@ -56,7 +58,27 @@ public class StudentController { return ResponseEntity.badRequest().build(); } } + @PutMapping("/closePendingFor14Days") + public ResponseEntity<?> updateStudentStatusToClosed() { + try { + List<Student> updatedStudents = studentService.updateStudentStatusToClosed(); + return ResponseEntity.ok(updatedStudents); + } catch (Exception e) { + log.error("Error updating student status based on days", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("An error occurred while updating student status."); + } + } + @GetMapping("/pendingFor21Days") + public ResponseEntity<?> getStudentsPendingFor21Days() { + try { + List<Student> students = studentService.getStudentsPendingForMoreThan21Days(); + return ResponseEntity.ok(students); + } catch (Exception e) { + log.error("Error fetching students pending for 21 days", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("An error occurred while fetching students."); + } + } @DeleteMapping("/{id}") public ResponseEntity<Void> deleteStudent(@PathVariable Long id) { try { @@ -68,13 +90,11 @@ public class StudentController { } @PutMapping("/{studentId}/verify") - public ResponseEntity<Student> verifyStudent(@PathVariable Long studentId, @RequestParam("status") VerificationStatus status) { - Student student = studentService.findById(studentId); - student.setVerificationStatus(status); - studentService.save(student); - return ResponseEntity.ok(student); + public ResponseEntity<Student> verifyStudent(@PathVariable Long studentId, @RequestParam("status") VerificationStatus status, @RequestParam("remarks") String remarks, @RequestParam("verificationDate") LocalDate verificationDate) { + Student updatedStudent = studentService.verifyStudent(studentId, status, remarks, verificationDate); + return ResponseEntity.ok(updatedStudent); } - @GetMapping("/pending-verification") + @GetMapping("/pendingVerification") public ResponseEntity<List<Student>> getStudentsPendingVerification() { List<Student> students = studentService.findByVerificationStatus(VerificationStatus.PENDING); return ResponseEntity.ok(students); diff --git a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/model/Student.java b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/model/Student.java index fef013f978b5a37ccb64c4ab5fb7fc6219c6f5d9..b7be6c83929e361586774f0980e96f61c2b251e2 100644 --- a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/model/Student.java +++ b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/model/Student.java @@ -51,8 +51,15 @@ public class Student { private String highSchoolYearOfPassing; private String intermediateRollNo; private String intermediateYearOfPassing; + @Enumerated(EnumType.STRING) private VerificationStatus verificationStatus = VerificationStatus.PENDING; private String provisionalEnrollmentNumber; + private String adminRemarks; + private LocalDate enrollmentDate; + private LocalDate verificationDate; + private boolean requiresRevision; + private String enrollmentNumber; + @ManyToOne @JoinColumn(name = "course_id") private Course course; diff --git a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/model/VerificationStatus.java b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/model/VerificationStatus.java index a2ae26474f4cc3d3eaf121339bb44ab0b8f73f17..c6371d305cde69ca9e3afb8a2b4c1bc609c844b6 100644 --- a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/model/VerificationStatus.java +++ b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/model/VerificationStatus.java @@ -1,5 +1,5 @@ package com.tarento.upsmf.examsAndAdmissions.model; public enum VerificationStatus { - PENDING, VERIFIED, REJECTED + PENDING, VERIFIED, REJECTED, CLOSED } diff --git a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/model/dto/StudentDto.java b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/model/dto/StudentDto.java index d68eec73a34284c3b6f6c776d6d6d0a1d0a2aebe..2c07a94ce2ab14d69f0134a8aee5279a1363ec6c 100644 --- a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/model/dto/StudentDto.java +++ b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/model/dto/StudentDto.java @@ -2,6 +2,7 @@ package com.tarento.upsmf.examsAndAdmissions.model.dto; import lombok.*; import org.springframework.web.multipart.MultipartFile; +import java.time.LocalDate; @Getter @Setter @@ -15,12 +16,12 @@ public class StudentDto { private String courseName; private String session; private String examBatch; - private String admissionDate; + private LocalDate admissionDate; private String firstName; private String surname; private String motherName; private String fatherName; - private String dateOfBirth; + private LocalDate dateOfBirth; private String gender; private String caste; private String category; @@ -39,10 +40,14 @@ public class StudentDto { private String highSchoolYearOfPassing; private String intermediateRollNo; private String intermediateYearOfPassing; + private String adminRemarks; + private LocalDate enrollmentDate; + private LocalDate verificationDate; + private boolean requiresRevision; + private String enrollmentNumber; private MultipartFile highSchoolMarksheet; private MultipartFile highSchoolCertificate; private MultipartFile intermediateMarksheet; private MultipartFile intermediateCertificate; - } diff --git a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/repository/StudentRepository.java b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/repository/StudentRepository.java index d478f90b16d530bbb204a9d0523884ed0f1c674a..972c0159f1381df5e7fbb8ad1eeb3b077e029cc1 100644 --- a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/repository/StudentRepository.java +++ b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/repository/StudentRepository.java @@ -5,10 +5,14 @@ import com.tarento.upsmf.examsAndAdmissions.model.VerificationStatus; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.time.LocalDate; import java.util.List; @Repository public interface StudentRepository extends JpaRepository<Student, Long> { List<Student> findByVerificationStatus(VerificationStatus status); + List<Student> findByEnrollmentDateBeforeAndVerificationStatus(LocalDate date, VerificationStatus status); + List<Student> findByVerificationDateBeforeAndVerificationStatus(LocalDate date, VerificationStatus status); + } diff --git a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/service/ExamCycleService.java b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/service/ExamCycleService.java index 3a5fe2e503bee1105a10157d84ab537d2aedde70..c22a75429bca6be6a2c8bbf9718fc4c81e6b3da3 100644 --- a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/service/ExamCycleService.java +++ b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/service/ExamCycleService.java @@ -2,8 +2,7 @@ package com.tarento.upsmf.examsAndAdmissions.service; import com.tarento.upsmf.examsAndAdmissions.model.ExamCycle; import com.tarento.upsmf.examsAndAdmissions.repository.ExamCycleRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -11,41 +10,40 @@ import java.util.Date; import java.util.List; @Service +@Slf4j public class ExamCycleService { - private static final Logger logger = LoggerFactory.getLogger(ExamCycleService.class); - @Autowired private ExamCycleRepository repository; // Create a new exam cycle public ExamCycle createExamCycle(ExamCycle examCycle) { - logger.info("Creating new ExamCycle: {}", examCycle); + log.info("Creating new ExamCycle: {}", examCycle); examCycle.setObsolete(0); return repository.save(examCycle); } // Fetch all active exam cycles public List<ExamCycle> getAllExamCycles() { - logger.info("Fetching all active ExamCycles..."); + log.info("Fetching all active ExamCycles..."); return repository.findByObsolete(0); } // Fetch all soft-deleted exam cycles public List<ExamCycle> getAllObsoleteExamCycles() { - logger.info("Fetching all soft-deleted ExamCycles..."); + log.info("Fetching all soft-deleted ExamCycles..."); return repository.findByObsolete(1); } // Fetch a specific exam cycle by its ID public ExamCycle getExamCycleById(Long id) { - logger.info("Fetching ExamCycle by ID: {}", id); + log.info("Fetching ExamCycle by ID: {}", id); return repository.findByIdAndObsolete(id, 0).orElse(null); } // Update an existing exam cycle public ExamCycle updateExamCycle(Long id, ExamCycle updatedExamCycle) { - logger.info("Updating ExamCycle with ID: {}", id); + log.info("Updating ExamCycle with ID: {}", id); ExamCycle existingExamCycle = repository.findById(id).orElse(null); if (existingExamCycle != null) { existingExamCycle.setExamCycleName(updatedExamCycle.getExamCycleName()); @@ -61,31 +59,31 @@ public class ExamCycleService { return repository.save(existingExamCycle); } - logger.warn("ExamCycle with ID: {} not found!", id); + log.warn("ExamCycle with ID: {} not found!", id); return null; } // Soft delete an exam cycle public void deleteExamCycle(Long id) { - logger.info("Soft-deleting ExamCycle with ID: {}", id); + log.info("Soft-deleting ExamCycle with ID: {}", id); ExamCycle examCycle = repository.findById(id).orElse(null); if (examCycle != null) { examCycle.setObsolete(1); repository.save(examCycle); } else { - logger.warn("ExamCycle with ID: {} not found for deletion!", id); + log.warn("ExamCycle with ID: {} not found for deletion!", id); } } // Restore a soft-deleted exam cycle public void restoreExamCycle(Long id) { - logger.info("Restoring soft-deleted ExamCycle with ID: {}", id); + log.info("Restoring soft-deleted ExamCycle with ID: {}", id); ExamCycle examCycle = repository.findById(id).orElse(null); if (examCycle != null && examCycle.getObsolete() == 1) { examCycle.setObsolete(0); repository.save(examCycle); } else { - logger.warn("ExamCycle with ID: {} not found for restoration!", id); + log.warn("ExamCycle with ID: {} not found for restoration!", id); } } } \ No newline at end of file diff --git a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/service/ExamService.java b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/service/ExamService.java index 7f94ed6a7a97a44fd02a641f368bfc1d2000ef01..29aae3827bff3933af7a654244e3bb922c8e3a0a 100644 --- a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/service/ExamService.java +++ b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/service/ExamService.java @@ -2,39 +2,37 @@ package com.tarento.upsmf.examsAndAdmissions.service; import com.tarento.upsmf.examsAndAdmissions.model.Exam; import com.tarento.upsmf.examsAndAdmissions.repository.ExamRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service +@Slf4j public class ExamService { - private static final Logger logger = LoggerFactory.getLogger(ExamService.class); - @Autowired private ExamRepository repository; public Exam createExam(Exam exam) { - logger.info("Creating new Exam: {}", exam); + log.info("Creating new Exam: {}", exam); exam.setObsolete(0); return repository.save(exam); } public List<Exam> getAllExams() { - logger.info("Fetching all active Exams..."); + log.info("Fetching all active Exams..."); return repository.findByObsolete(0); } public Exam getExamById(Long id) { - logger.info("Fetching Exam by ID: {}", id); + log.info("Fetching Exam by ID: {}", id); return repository.findByIdAndObsolete(id, 0).orElse(null); } public Exam updateExam(Long id, Exam updatedExam) { - logger.info("Updating Exam with ID: {}", id); + log.info("Updating Exam with ID: {}", id); Exam existingExam = repository.findById(id).orElse(null); if (existingExam != null) { existingExam.setExamCycleId(updatedExam.getExamCycleId()); @@ -49,31 +47,31 @@ public class ExamService { return repository.save(existingExam); } - logger.warn("Exam with ID: {} not found!", id); + log.warn("Exam with ID: {} not found!", id); return null; } public void deleteExam(Long id) { - logger.info("Soft-deleting Exam with ID: {}", id); + log.info("Soft-deleting Exam with ID: {}", id); Exam exam = repository.findById(id).orElse(null); if (exam != null) { exam.setObsolete(1); repository.save(exam); } else { - logger.warn("Exam with ID: {} not found for deletion!", id); + log.warn("Exam with ID: {} not found for deletion!", id); } } public void restoreExam(Long id) { - logger.info("Restoring soft-deleted Exam with ID: {}", id); + log.info("Restoring soft-deleted Exam with ID: {}", id); Exam exam = repository.findById(id).orElse(null); if (exam != null && exam.getObsolete() == 1) { exam.setObsolete(0); repository.save(exam); } else { - logger.warn("Exam with ID: {} not found for restoration!", id); + log.warn("Exam with ID: {} not found for restoration!", id); } } } \ No newline at end of file diff --git a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/service/StudentService.java b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/service/StudentService.java index 2ab1bc6b8c6b0b625bc62ff96a3fabca9d7a5038..63ace9dff9b6b3e07895a7ce4e1bd9f89eb1d381 100644 --- a/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/service/StudentService.java +++ b/upsmf-entity/src/main/java/com/tarento/upsmf/examsAndAdmissions/service/StudentService.java @@ -6,9 +6,8 @@ import com.tarento.upsmf.examsAndAdmissions.model.VerificationStatus; import com.tarento.upsmf.examsAndAdmissions.model.dto.StudentDto; import com.tarento.upsmf.examsAndAdmissions.repository.CourseRepository; import com.tarento.upsmf.examsAndAdmissions.repository.StudentRepository; +import lombok.extern.slf4j.Slf4j; import org.modelmapper.ModelMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.PropertySource; @@ -21,15 +20,16 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.UUID; @Service @PropertySource("classpath:application.properties") +@Slf4j public class StudentService { - - private static final Logger logger = LoggerFactory.getLogger(StudentService.class); private final StudentRepository studentRepository; private final CourseRepository courseRepository; private final ModelMapper modelMapper; @@ -130,6 +130,25 @@ public class StudentService { return studentRepository.save(existingStudent); } + public List<Student> updateStudentStatusToClosed() { + LocalDate cutoffDate = LocalDate.now().minusDays(14); + List<Student> rejectedStudents = studentRepository.findByVerificationDateBeforeAndVerificationStatus(cutoffDate, VerificationStatus.REJECTED); + + log.info("Rejected students found to potentially close: " + rejectedStudents.size()); + + List<Student> studentsToUpdate = new ArrayList<>(); + + for (Student student : rejectedStudents) { + student.setVerificationStatus(VerificationStatus.CLOSED); + studentsToUpdate.add(student); + } + + return studentRepository.saveAll(studentsToUpdate); + } + public List<Student> getStudentsPendingForMoreThan21Days() { + LocalDate twentyOneDaysAgo = LocalDate.now().minusDays(21); + return studentRepository.findByEnrollmentDateBeforeAndVerificationStatus(twentyOneDaysAgo, VerificationStatus.PENDING); + } private void deleteFile(String filePath) { if (filePath == null || filePath.isEmpty()) { @@ -168,6 +187,20 @@ public class StudentService { student.setVerificationStatus(status); return studentRepository.save(student); } + public Student verifyStudent(Long studentId, VerificationStatus status, String remarks, LocalDate verificationDate) { + Student student = this.findById(studentId); + student.setVerificationStatus(status); + student.setAdminRemarks(remarks); + student.setVerificationDate(verificationDate); + + if (status == VerificationStatus.VERIFIED) { + String enrollmentNumber = "EN" + LocalDate.now().getYear() + student.getCenterCode() + student.getId(); + student.setEnrollmentNumber(enrollmentNumber); + } else if (status == VerificationStatus.REJECTED) { + student.setRequiresRevision(true); + } + return this.save(student); + } public List<Student> findByVerificationStatus(VerificationStatus status) { return studentRepository.findByVerificationStatus(status); }