From a6fabd4a5cdadabc47a694b0fcd8fb2712a79e19 Mon Sep 17 00:00:00 2001 From: Andrew Sameh Adel Date: Sun, 23 Nov 2025 18:00:42 +0200 Subject: [PATCH 1/2] remove md --- IMPLEMENTATION_SUMMARY.md | 249 -------------------------------------- 1 file changed, 249 deletions(-) delete mode 100644 IMPLEMENTATION_SUMMARY.md diff --git a/IMPLEMENTATION_SUMMARY.md b/IMPLEMENTATION_SUMMARY.md deleted file mode 100644 index d9b7729..0000000 --- a/IMPLEMENTATION_SUMMARY.md +++ /dev/null @@ -1,249 +0,0 @@ -# Implementation Summary - -## Overview -This document summarizes all changes made to implement the quiz functionality, certificate download, and enhanced user experience features. - ---- - -## 1. Files Modified - -### Core Model Classes -- `src/models/QuizAttempt.java` - Enhanced with timestamp, status, question answers, and wrong question count - -### Database Classes -- `src/databases/CourseDatabase.java` - Added methods for starting, updating, finishing, and abandoning quiz attempts - -### Service Classes -- `src/services/CourseService.java` - Added null safety checks in getCertificate method -- `src/services/CertificateService.java` - NEW: Complete PDF certificate generation service - -### Page Classes -- `src/pages/StudentDashBoard.java` - Added Download Certificate button for completed courses -- `src/pages/StudentLessons.java` - Updated to use new quiz-based lesson card system -- `src/pages/components/LessonCard.java` - Completely redesigned to show "Take Quiz" button and attempts history icon - -### NEW Page Classes -- `src/pages/QuizView.java` - Complete quiz taking interface with Back/Finish buttons, question navigation, and review mode -- `src/pages/AttemptsSummaryDialog.java` - Dialog showing attempt history with View Details button -- `src/pages/AttemptDetailsDialog.java` - Dialog showing detailed quiz attempt results with color-coded answers - -### Configuration Files -- `pom.xml` - Added Apache PDFBox dependency for PDF certificate generation - ---- - -## 2. New Services/Endpoints Added - -### CertificateService -- `generateCertificatePDF(int studentId, int courseId)` - Generates professional PDF certificate -- `downloadCertificate(String filepath)` - Triggers file download -- `getOrCreateCertificate(int studentId, int courseId)` - Gets or creates certificate for student -- `isCourseCompleted(int studentId, int courseId)` - Checks if course is completed -- `generateCertificateCode(int certId, int studentId, int courseId)` - Generates unique certificate code -- `sanitizeFilename(String name)` - Sanitizes filenames for safe storage - -### CourseDatabase (Extended Methods) -- `startQuizAttempt(int studentId, int quizId)` - Creates new quiz attempt with "started" status -- `updateQuizAttemptAnswers(int studentId, int quizId, int attemptIndex, Map answers)` - Updates attempt with student answers -- `finishQuizAttempt(int studentId, int quizId, int attemptIndex, Map answers)` - Finishes attempt, grades it, and marks as "finished" -- `abandonQuizAttempt(int studentId, int quizId, int attemptIndex)` - Marks attempt as "abandoned" - ---- - -## 3. Database Schema Changes - -### QuizAttempt Model Enhanced -Added fields: -- `startTime` (LocalDateTime) - When attempt was started -- `finishTime` (LocalDateTime) - When attempt was finished or abandoned -- `status` (String) - "started", "finished", or "abandoned" -- `questionAnswers` (Map) - Maps question index to selected choice index -- `wrongQuestions` (int) - Count of wrong answers - -### Certificate Model -No changes needed - existing model supports certificate functionality - ---- - -## 4. UI Flow Notes - -### Student Dashboard (Course Cards) -- **Location**: Student Dashboard → My Courses section -- **New Feature**: "Download Certificate" button appears below "View Course Lessons" button -- **Visibility**: Only shown when course is completed -- **Action**: Generates and downloads PDF certificate - -### Student Lessons Panel (Lesson Cards) -- **Location**: Student Dashboard → View Course Lessons → Lessons list -- **New Features**: - - "Take Quiz" button replaces "Complete" button for lessons with quizzes - - "Completed" button (green, disabled) shown when all attempts used or lesson completed - - Attempts history icon (📋) appears to the left of "Take Quiz" when student has previous attempts -- **Actions**: - - Click "Take Quiz" → Confirmation dialog → QuizView opens - - Click attempts history icon → AttemptsSummaryDialog opens - -### Quiz View Panel -- **Location**: Started from Lesson Card → Take Quiz button -- **Features**: - - Back button (top left) - Shows warning if leaving before finish - - Attempt info (top center) - Shows attempt number and answered count - - Question display (center) - Shows current question with multiple choice options - - Previous/Next buttons (bottom) - Navigate between questions - - Finish button (bottom right) - Validates all questions answered, confirms, grades, and shows review -- **Review Mode**: - - Highlights correct answers in green with ✓ - - Highlights wrong answers in red with ✗ - - Shows "Your Answer" for selected incorrect answers - - Displays overall score and pass/fail status - -### Attempts Summary Dialog -- **Location**: Lesson Card → Attempts history icon (📋) -- **Features**: - - Shows max attempts allowed - - Shows attempts used - - Table listing all attempts with: - - Attempt number - - Date/Time - - Status (started/finished/abandoned) - - Score - - Correct/Wrong counts - - "View Details" button for each attempt - -### Attempt Details Dialog -- **Location**: Attempts Summary Dialog → View Details button -- **Features**: - - Shows attempt summary (start/finish time, status, score) - - Lists all questions with: - - Student's selected answer - - Correct answer - - Color coding (green for correct, red for wrong) - - Visual indicators (✓ and ✗) - ---- - -## 5. Configuration & Third-Party Libraries - -### Dependencies Added -- **Apache PDFBox 2.0.29** - For PDF certificate generation - - Used for creating professional landscape certificate PDFs - - Supports fonts, colors, borders, and formatting - -### Configuration Notes -- Certificate PDFs are stored in `certificates/` directory (created automatically) -- Filename format: `certificate_[StudentName]_[CourseTitle]_[IssueDate]_[CertificateCode].pdf` - ---- - -## 6. Manual Test Steps - -### Test 1: Certificate Download for Completed Course -1. Log in as a student -2. Complete a course (all lessons with quizzes passed) -3. Go to Student Dashboard -4. Verify "Download Certificate" button appears on completed course card -5. Click "Download Certificate" -6. Verify toast message appears: "Generating certificate — preparing your download..." -7. Verify PDF opens/downloads successfully -8. Verify PDF contains correct student name, course title, issue date, and certificate code - -### Test 2: Lesson Card Quiz Button Behavior -1. Log in as a student -2. Navigate to a course with lessons containing quizzes -3. Verify lesson cards show "Take Quiz" button (not "Complete") -4. If student has previous attempts, verify attempts history icon (📋) appears -5. If all attempts used, verify "Completed" button (green, disabled) appears - -### Test 3: Take Quiz Flow -1. Click "Take Quiz" on a lesson card -2. Verify confirmation dialog appears with message: "Are you sure you want to start the quiz for '[Lesson Title]'? This will use one attempt." -3. Click "Yes" -4. Verify QuizView opens -5. Answer all questions (navigate with Previous/Next buttons) -6. Verify "Answered: X/Y" count updates -7. Click "Finish" -8. Verify warning if not all questions answered: "You must finish the quiz before clicking Finish. Answer all required questions." -9. Answer all questions and click "Finish" again -10. Verify confirmation: "Are you sure you want to finish your attempt now? You will not be able to change your answers." -11. Click "Yes" -12. Verify review mode shows with correct answers in green, wrong in red -13. Verify score and pass/fail status displayed - -### Test 4: Back Button Warning -1. Start a quiz attempt -2. Answer some questions -3. Click "Back" button -4. Verify warning appears: "IF you leave now you will lose this attempt in this quiz." -5. Click "Yes" (Leave) -6. Verify attempt is marked as "abandoned" and returns to Student Lessons panel - -### Test 5: Attempts Summary Dialog -1. Click attempts history icon (📋) on a lesson card with previous attempts -2. Verify AttemptsSummaryDialog opens -3. Verify it shows: - - Max attempts allowed - - Attempts used count - - Table with all attempts -4. Click "View Details" on an attempt -5. Verify AttemptDetailsDialog opens showing detailed results - -### Test 6: Attempt Details Dialog -1. Open Attempt Details from Attempts Summary -2. Verify it shows: - - Start and finish times - - Status - - Score (with color coding) - - Correct/Wrong counts - - All questions with: - - Student's answer highlighted - - Correct answer highlighted - - Color coding (green/red) - -### Test 7: Course Completion Check -1. Complete all lessons in a course (pass all quizzes) -2. Verify course completion status updates -3. Return to Student Dashboard -4. Verify "Download Certificate" button appears on course card -5. Verify certificate can be generated and downloaded - ---- - -## 7. Known Issues & Considerations - -### Notes -- Certificate generation requires file system write permissions -- PDFBox library must be downloaded via Maven (check `pom.xml` dependencies) -- Certificate PDFs are stored in project root `certificates/` directory -- Quiz attempts are stored in JSON database files -- All attempts are tracked even if abandoned - -### Recommendations -- Consider adding file size limits for certificate storage -- Consider adding certificate expiration dates if needed -- Consider adding attempt time limits for quizzes -- Consider adding quiz retake policies (wait period between attempts) - ---- - -## 8. Acceptance Criteria Verification - -✅ **Certificate Download**: Course card shows Download Certificate only for completed courses; clicking downloads correctly populated PDF - -✅ **Lesson Card Quiz Button**: Displays Take Quiz, Attempts icon (when applicable), or Completed (green, disabled) depending on student state - -✅ **Take Quiz Confirmation**: Requires confirmation, creates attempt, and navigates to Quiz Panel - -✅ **Back Before Finish Warning**: Warns and abandons attempt when confirmed - -✅ **Finish Validation**: Enforces answering all required questions, confirms finish, grades attempt, and shows review mode with red/green highlights - -✅ **Attempts Summary Dialog**: Shows correct attempt metadata and detailed per-question views - -✅ **Certificate Generation**: Generation and storage work; certificates can be verified/downloaded by student - ---- - -## Implementation Complete ✓ - -All features have been implemented and integrated according to specifications. - From 98d1ef53eff457d255088fa4485395a761923c9e Mon Sep 17 00:00:00 2001 From: Andrew Sameh Adel Date: Sun, 23 Nov 2025 18:02:48 +0200 Subject: [PATCH 2/2] fix certificate null in json --- src/models/User.java | 5 +---- src/resources/users.json | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/models/User.java b/src/models/User.java index 08a364e..6208e69 100644 --- a/src/models/User.java +++ b/src/models/User.java @@ -11,15 +11,12 @@ public class User implements Model { private String email; private String name; private String role; - private List certificates; + private List certificates = new ArrayList<>(); /* This constructor is necessary for JSON parsing */ public User() {} public void addCertificate(Certificate certificate) { - if (this.certificates == null) { - this.certificates = new ArrayList<>(); - } this.certificates.add(certificate); } diff --git a/src/resources/users.json b/src/resources/users.json index 2c391c3..a3a5733 100644 --- a/src/resources/users.json +++ b/src/resources/users.json @@ -30,14 +30,14 @@ "password" : "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918", "role" : "Admin" }, { - "certificates" : null, + "certificates" : [ ], "email" : "ahmed@gmail.com", "id" : 4, "name" : "ahmed sherif", "password" : "8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92", "role" : "Instructor" }, { - "certificates" : null, + "certificates" : [ ], "email" : "malek@gmail.com", "id" : 5, "name" : "malek",