-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataLoader_SDjpa.java
More file actions
734 lines (608 loc) · 34.3 KB
/
DataLoader_SDjpa.java
File metadata and controls
734 lines (608 loc) · 34.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
package com.secure_srm.bootstrap;
import com.secure_srm.model.academic.*;
import com.secure_srm.model.people.*;
import com.secure_srm.model.security.*;
import com.secure_srm.services.academicServices.*;
import com.secure_srm.services.peopleServices.*;
import com.secure_srm.services.securityServices.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import java.util.HashSet;
import java.util.Set;
@Component
@Slf4j
@RequiredArgsConstructor
@Profile(value = {"SQL", "SDjpa"})
public class DataLoader_SDjpa implements CommandLineRunner {
private final UserService userService;
private final AuthorityService authorityService;
private final RoleService roleService;
private final AdminUserService adminUserService;
private final GuardianUserService guardianUserService;
private final TeacherUserService teacherUserService;
private final PasswordEncoder passwordEncoder;
//SRM related
private final StudentService studentService;
private final SubjectService subjectService;
private final AddressService addressService;
private final ContactDetailService contactDetailService;
private final FormGroupListService formGroupListService;
private final AssignmentTypeService assignmentTypeService;
private final SubjectClassListService subjectClassListService;
private final StudentTaskService studentTaskService;
private final StudentResultService studentResultService;
private final ThresholdService thresholdService;
private final ThresholdListService thresholdListService;
private final ReportService reportService;
@Override
public void run(String... args) {
log.debug("Starting Bootloader...");
if (authorityService.findAll().isEmpty() || roleService.findAll().isEmpty()){
loadSecurityData();
} else {
log.debug("Authority and Roles already found. No changes made.");
}
if (adminUserService.findAll().isEmpty()){
loadAdminUsers();
} else {
log.debug("Admin users already found. No changes made.");
}
if (teacherUserService.findAll().isEmpty()){
loadTeacherUsers();
} else {
log.debug("Teacher users already found. No changes made.");
}
if (guardianUserService.findAll().isEmpty()){
loadGuardianUsers();
} else {
log.debug("Guardian users already found. No changes made.");
}
loadSRM_personnel_data();
loadSRM_academic_data();
}
private void loadSecurityData(){
// Privileges Root > Admin > Teacher > Guardian
// A separate set of permissions for each object type (in schools, assignment, report, exam score etc.) could be
// implemented in future (e.g. admin to view exam results would be 'admin.examScore.read' for example
//root authorities
Authority createRoot = authorityService.save(Authority.builder().permission("root.create").build());
Authority updateRoot = authorityService.save(Authority.builder().permission("root.update").build());
Authority readRoot = authorityService.save(Authority.builder().permission("root.read").build());
Authority deleteRoot = authorityService.save(Authority.builder().permission("root.delete").build());
//admin authorities
Authority createAdmin = authorityService.save(Authority.builder().permission("admin.create").build());
Authority updateAdmin = authorityService.save(Authority.builder().permission("admin.update").build());
Authority readAdmin = authorityService.save(Authority.builder().permission("admin.read").build());
Authority deleteAdmin = authorityService.save(Authority.builder().permission("admin.delete").build());
//teacher authorities
Authority createTeacher = authorityService.save(Authority.builder().permission("teacher.create").build());
Authority updateTeacher = authorityService.save(Authority.builder().permission("teacher.update").build());
Authority readTeacher = authorityService.save(Authority.builder().permission("teacher.read").build());
Authority deleteTeacher = authorityService.save(Authority.builder().permission("teacher.delete").build());
//guardian authorities
Authority createGuardian = authorityService.save(Authority.builder().permission("guardian.create").build());
Authority updateGuardian = authorityService.save(Authority.builder().permission("guardian.update").build());
Authority readGuardian = authorityService.save(Authority.builder().permission("guardian.read").build());
Authority deleteGuardian = authorityService.save(Authority.builder().permission("guardian.delete").build());
Role rootRole = roleService.save(Role.builder().roleName("ROOT").build());
Role adminRole = roleService.save(Role.builder().roleName("ADMIN").build());
Role teacherRole = roleService.save(Role.builder().roleName("TEACHER").build());
Role guardianRole = roleService.save(Role.builder().roleName("GUARDIAN").build());
//Set.Of returns an immutable set, so new HashSet instantiates a mutable Set
rootRole.setAuthorities(new HashSet<>(Set.of(createRoot, readRoot, updateRoot, deleteRoot,
createAdmin, updateAdmin, readAdmin, deleteAdmin,
createTeacher, readTeacher, updateTeacher, deleteTeacher,
createGuardian, readGuardian, updateGuardian, deleteGuardian)));
adminRole.setAuthorities(new HashSet<>(Set.of(createAdmin, updateAdmin, readAdmin, deleteAdmin,
createTeacher, readTeacher, updateTeacher, deleteTeacher,
createGuardian, readGuardian, updateGuardian, deleteGuardian)));
teacherRole.setAuthorities(new HashSet<>(Set.of(createTeacher, readTeacher, updateTeacher, deleteTeacher,
createGuardian, readGuardian, updateGuardian, deleteGuardian)));
guardianRole.setAuthorities(new HashSet<>(Set.of(createGuardian, readGuardian, updateGuardian, deleteGuardian)));
roleService.save(rootRole);
roleService.save(adminRole);
roleService.save(teacherRole);
roleService.save(guardianRole);
log.debug("Roles added: " + roleService.findAll().size());
log.debug("Authorities added: " + authorityService.findAll().size());
}
public void loadAdminUsers(){
Role adminRole = roleService.findByRoleName("ADMIN");
// Instantiating the admin users (this must be done after Users)
// AdminUsers can store non-Security related fields (department, academic year etc.)
// Note, UserName is not Username
AdminUser johnSmith = AdminUser.builder().firstName("John").lastName("Smith").build();
AdminUser amySmith = AdminUser.builder().firstName("Amy").lastName("Smith").build();
//set contact details to Admin
ContactDetail johnContacts = contactDetailService.save(
ContactDetail.builder().email("jsAdmin@school.com").phoneNumber("92874328").build());
ContactDetail amyContacts = contactDetailService.save(
ContactDetail.builder().email("asAdmin@school.com").phoneNumber("46364345").build());
johnSmith.setContactDetail(johnContacts);
amySmith.setContactDetail(amyContacts);
//save Adminuser's
adminUserService.save(johnSmith);
adminUserService.save(amySmith);
//passwords are not displayed on the schema...?
User johnSmithUser = userService.save(User.builder().username("johnsmith")
.password(passwordEncoder.encode("johnsmith123"))
.adminUser(johnSmith)
.role(adminRole).build());
User amySmithUser = userService.save(User.builder().username("amysmith")
.password(passwordEncoder.encode("amysmith123"))
.adminUser(amySmith)
.role(adminRole).build());
log.debug("AdminUsers added: " + johnSmithUser.getUsername() + " " + amySmithUser.getUsername());
}
public void loadGuardianUsers(){
Role guardianRole = roleService.findByRoleName("GUARDIAN");
// Instantiating the admin users (this must be done after Users)
GuardianUser paulSmith = guardianUserService.save(GuardianUser.builder().firstName("Paul").lastName("Smith").build());
GuardianUser alexSmith = guardianUserService.save(GuardianUser.builder().firstName("Alex").lastName("Smith").build());
//passwords are not displayed on the schema...?
User paulSmithUser = userService.save(User.builder().username("paulsmith")
.password(passwordEncoder.encode("paulsmith123"))
.guardianUser(paulSmith)
.role(guardianRole).build());
//other GuardianUsers can be assigned to paulsmith, with the same roles
User alexSmithUser = userService.save(User.builder().username("alexsmith")
.password(passwordEncoder.encode("alexsmith123"))
.guardianUser(alexSmith)
.role(guardianRole).build());
log.debug("GuardianUsers added: " + paulSmithUser.getUsername() + " " + alexSmithUser.getUsername());
}
public void loadTeacherUsers(){
Role teacherRole = roleService.findByRoleName("TEACHER");
// Instantiating the admin users (this must be done after Users)
TeacherUser keithJones = teacherUserService.save(TeacherUser.builder().firstName("Keith").lastName("Jones")
.department("Mathematics dept.").build());
TeacherUser maryManning = teacherUserService.save(TeacherUser.builder().firstName("Mary").lastName("Manning")
.department("English dept.").build());
//passwords are not displayed on the schema...?
User keithJonesUser = userService.save(User.builder().username("keithjones")
.password(passwordEncoder.encode("keithjones123"))
.teacherUser(keithJones)
.role(teacherRole).build());
User maryManningUser = userService.save(User.builder().username("marymanning")
.password(passwordEncoder.encode("marymanning123"))
.teacherUser(maryManning)
.role(teacherRole).build());
log.debug("TeacherUsers added: " + keithJonesUser.getUsername() + " " + maryManningUser.getUsername());
}
public void loadSRM_personnel_data(){
//build a temporary POJO from Student, Teacher and Guardian classes and add (inject) to each respective service
//three students, two teachers and two guardians
//contact details
ContactDetail teacher1Contact = ContactDetail.builder().email("teacher1@school.com").phoneNumber("9847324").build();
ContactDetail teacher2Contact = ContactDetail.builder().email("teacher2@school.com").phoneNumber("4023307").build();
contactDetailService.save(teacher1Contact);
contactDetailService.save(teacher2Contact);
ContactDetail guardianContactDetail1 = ContactDetail.builder().phoneNumber("3479324732").email("guardian1@email.com").build();
ContactDetail guardianContactDetail2 = ContactDetail.builder().phoneNumber("02374320427").email("guardian2@email.com").build();
contactDetailService.save(guardianContactDetail1);
contactDetailService.save(guardianContactDetail2);
log.debug("Contact details loaded to DB");
//addresses
Address address1 = Address.builder().firstLine("88 Penine Way").secondLine("Farnborough").postcode("CHG9475JF").build();
Address address2 = Address.builder().firstLine("7B Gossfer Drive").secondLine("Racoon City").postcode("ZJGKF97657DD").build();
addressService.save(address1);
addressService.save(address2);
log.debug("Addresses loaded to DB");
Student johnSmithStudent = Student.builder().firstName("John").lastName("Smith").build();
Student elizabethJonesStudent = Student.builder().firstName("Elizabeth").lastName("Jones").build();
Student helenJonesStudent = Student.builder().firstName("Helen").lastName("Jones").build();
TeacherUser keithJonesTeacher = teacherUserService.findByFirstNameAndLastName("Keith", "Jones");
keithJonesTeacher.setContactDetail(teacher1Contact);
TeacherUser maryManningTeacher = teacherUserService.findByFirstNameAndLastName("Mary", "Manning");
maryManningTeacher.setContactDetail(teacher2Contact);
//academic details
Subject mathematics = Subject.builder().subjectName("Mathematics").build();
Set<TeacherUser> teachers1 = new HashSet<>();
teachers1.add(keithJonesTeacher);
mathematics.setTeachers(teachers1);
Set<Subject> teacher1subjects = new HashSet<>();
teacher1subjects.add(mathematics);
keithJonesTeacher.setSubjects(teacher1subjects);
Subject english = Subject.builder().subjectName("English").build();
Set<TeacherUser> teachers2 = new HashSet<>();
teachers2.add(maryManningTeacher);
english.setTeachers(teachers2);
Set<Subject> teacher2subjects = new HashSet<>();
teacher2subjects.add(english);
maryManningTeacher.setSubjects(teacher2subjects);
subjectService.save(mathematics);
subjectService.save(english);
log.debug("Subjects loaded to DB");
teacherUserService.save(keithJonesTeacher);
teacherUserService.save(maryManningTeacher);
log.debug("Teachers re-loaded to DB");
GuardianUser guardian1 = guardianUserService.findByFirstNameAndLastName("Paul", "Smith");
guardian1.setAddress(address1);
guardian1.setContactDetail(guardianContactDetail1);
GuardianUser guardian2 = guardianUserService.findByFirstNameAndLastName("Alex", "Smith");
guardian2.setAddress(address2);
guardian2.setContactDetail(guardianContactDetail2);
//set students' tutors
johnSmithStudent.setTeacher(keithJonesTeacher);
elizabethJonesStudent.setTeacher(maryManningTeacher);
helenJonesStudent.setTeacher(maryManningTeacher);
//set students' contact details and guardians
johnSmithStudent.setContactDetail(guardianContactDetail1);
elizabethJonesStudent.setContactDetail(guardianContactDetail2);
helenJonesStudent.setContactDetail(guardianContactDetail2);
//set Guardian 1 and student 1 relationships
Set<GuardianUser> student1Guardians = new HashSet<>();
student1Guardians.add(guardian1);
johnSmithStudent.setGuardians(student1Guardians);
Set<Student> guardian1Students = new HashSet<>();
guardian1Students.add(johnSmithStudent);
guardian1.setStudents(guardian1Students);
//set Guardian 2 and students 2&3 relationships
Set<GuardianUser> student2Guardians = new HashSet<>();
Set<Student> guardian2Students = new HashSet<>();
student2Guardians.add(guardian2);
elizabethJonesStudent.setGuardians(student2Guardians);
helenJonesStudent.setGuardians(student2Guardians);
guardian2Students.add(elizabethJonesStudent);
guardian2Students.add(helenJonesStudent);
guardian2.setStudents(guardian2Students);
guardianUserService.save(guardian1);
guardianUserService.save(guardian2);
log.debug("Guardians re-loaded to DB");
//Pastoral (form) groups
Set<Student> studentGroup1 = new HashSet<>();
studentGroup1.add(johnSmithStudent);
Set<Student> studentGroup2 = new HashSet<>();
studentGroup1.add(elizabethJonesStudent);
studentGroup2.add(helenJonesStudent);
FormGroupList formGroupList1 = FormGroupList.builder().studentList(studentGroup1).groupName("Group 1").teacher(keithJonesTeacher).build();
FormGroupList formGroupList2 = FormGroupList.builder().studentList(studentGroup2).groupName("Group 2").teacher(maryManningTeacher).build();
johnSmithStudent.setFormGroupList(formGroupList1);
elizabethJonesStudent.setFormGroupList(formGroupList2);
helenJonesStudent.setFormGroupList(formGroupList2);
formGroupListService.save(formGroupList1);
formGroupListService.save(formGroupList2);
log.debug("FormGroupList loaded to DB");
//Subject class lists
SubjectClassList subjectClassList_Math = SubjectClassList.builder().subject(mathematics).teacher(keithJonesTeacher).groupName("Math_101").build();
SubjectClassList subjectClassList_Eng = SubjectClassList.builder().subject(english).teacher(maryManningTeacher).groupName("English_101").build();
//add Students to class lists
Set<SubjectClassList> studentSubjectsList = new HashSet<>(Set.of(subjectClassList_Eng, subjectClassList_Math));
johnSmithStudent.setSubjectClassLists(studentSubjectsList);
elizabethJonesStudent.setSubjectClassLists(studentSubjectsList);
helenJonesStudent.setSubjectClassLists(studentSubjectsList);
subjectClassList_Eng.setStudentList(Set.of(johnSmithStudent, elizabethJonesStudent, helenJonesStudent));
subjectClassList_Math.setStudentList(Set.of(johnSmithStudent, elizabethJonesStudent, helenJonesStudent));
subjectClassListService.save(subjectClassList_Eng);
subjectClassListService.save(subjectClassList_Math);
log.debug("SubjectClassList loaded to DB");
studentService.save(johnSmithStudent);
studentService.save(elizabethJonesStudent);
studentService.save(helenJonesStudent);
log.debug("Students loaded to DB");
assignmentTypeService.save(AssignmentType.builder().description("Mock exam").build());
assignmentTypeService.save(AssignmentType.builder().description("Coursework").build());
assignmentTypeService.save(AssignmentType.builder().description("Quiz").build());
assignmentTypeService.save(AssignmentType.builder().description("Interview").build());
assignmentTypeService.save(AssignmentType.builder().description("Service").build());
log.debug("Assignment types loaded to DB");
Report johnSmithReport = Report.builder().comments("Doing well this term! Keep it up.")
.student(johnSmithStudent)
.subject(mathematics)
.teacher(keithJonesTeacher)
.uniqueIdentifier("MathJohnSmith").build();
Report elizabethJonesReport = Report.builder().comments("Has made good progress so far.")
.student(elizabethJonesStudent)
.subject(english)
.teacher(maryManningTeacher)
.uniqueIdentifier("EngElizabethJones").build();
Report helenJonesReport = Report.builder().comments("Well done Helen, you have made a great start!")
.student(helenJonesStudent)
.subject(english)
.teacher(maryManningTeacher)
.uniqueIdentifier("EngHelenJones").build();
reportService.save(johnSmithReport);
reportService.save(elizabethJonesReport);
reportService.save(helenJonesReport);
log.debug("Student reports saved");
log.debug("================ Finished uploading SRM personnel data to DB ============");
}
private void loadSRM_academic_data() {
TeacherUser keithjones = teacherUserService.findByFirstNameAndLastName("Keith", "Jones");
TeacherUser marymanning = teacherUserService.findByFirstNameAndLastName("Mary", "Manning");
AssignmentType coursework = assignmentTypeService.findByDescription("Coursework");
AssignmentType interview = assignmentTypeService.findByDescription("Interview");
AssignmentType quiz = assignmentTypeService.findByDescription("Quiz");
//Build studentTasks
StudentTask EnglishEssayTask = StudentTask.builder()
.assignmentType(coursework)
.contributor(true)
.maxScore("60")
.studentResults(new HashSet<>())
.subject(subjectService.findBySubjectName("English"))
.teacherUploader(marymanning)
.title("William Wordsworth")
.build();
StudentTask EnglishEssayPlay = StudentTask.builder()
.assignmentType(interview)
.contributor(true)
.maxScore("40")
.studentResults(new HashSet<>())
.subject(subjectService.findBySubjectName("English"))
.teacherUploader(marymanning)
.title("Elizabethan times")
.build();
StudentTask Calculus1Quiz = StudentTask.builder()
.assignmentType(quiz)
.contributor(true)
.maxScore("100")
.studentResults(new HashSet<>())
.subject(subjectService.findBySubjectName("Mathematics"))
.teacherUploader(keithjones)
.title("Single variable calc. 1")
.build();
StudentTask Statistics3Quiz = StudentTask.builder()
.assignmentType(quiz)
.contributor(true)
.maxScore("100")
.studentResults(new HashSet<>())
.subject(subjectService.findBySubjectName("Mathematics"))
.teacherUploader(keithjones)
.title("Intro Stats 3")
.build();
//build StudentResults: EnglishEssayTask /60
StudentResult student1EnglishEssayTask = StudentResult.builder()
.studentTask(EnglishEssayTask)
.student(studentService.findById(1L))
.score("38")
.comments("Good!")
.teacher(marymanning)
.build();
StudentResult student2EnglishEssayTask = StudentResult.builder()
.studentTask(EnglishEssayTask)
.student(studentService.findById(2L))
.score("30")
.comments("Well written!")
.teacher(marymanning)
.build();
StudentResult student3EnglishEssayTask = StudentResult.builder()
.studentTask(EnglishEssayTask)
.student(studentService.findById(3L))
.score("48")
.comments("Great work!")
.teacher(marymanning)
.build();
EnglishEssayTask.setStudentResults(Set.of(student1EnglishEssayTask, student2EnglishEssayTask, student3EnglishEssayTask));
coursework.setStudentResults(Set.of(student1EnglishEssayTask, student2EnglishEssayTask, student3EnglishEssayTask));
//build StudentResults: EnglishEssayPlay /40
StudentResult student1EnglishEssayPlay = StudentResult.builder()
.studentTask(EnglishEssayPlay)
.student(studentService.findById(1L))
.score("25")
.comments("Good stuff!")
.teacher(keithjones)
.build();
StudentResult student2EnglishEssayPlay = StudentResult.builder()
.studentTask(EnglishEssayPlay)
.student(studentService.findById(2L))
.comments("Absent")
.teacher(marymanning)
.build();
StudentResult student3EnglishEssayPlay = StudentResult.builder()
.studentTask(EnglishEssayPlay)
.student(studentService.findById(3L))
.score("35")
.comments("Did very well!")
.teacher(marymanning)
.build();
EnglishEssayPlay.setStudentResults(Set.of(student1EnglishEssayPlay, student2EnglishEssayPlay, student3EnglishEssayPlay));
interview.setStudentResults(Set.of(student1EnglishEssayPlay, student2EnglishEssayPlay, student3EnglishEssayPlay));
//build StudentResults: Calculus1Quiz /100
StudentResult student1Calculus1Quiz = StudentResult.builder()
.studentTask(Calculus1Quiz)
.student(studentService.findById(1L))
.score("83")
.comments("Excellent")
.teacher(keithjones)
.build();
StudentResult student2Calculus1Quiz = StudentResult.builder()
.studentTask(Calculus1Quiz)
.student(studentService.findById(2L))
.score("61")
.comments("Good effort")
.teacher(keithjones)
.build();
StudentResult student3Calculus1Quiz = StudentResult.builder()
.studentTask(Calculus1Quiz)
.student(studentService.findById(3L))
.score("65")
.comments("Did well")
.teacher(keithjones)
.build();
Calculus1Quiz.setStudentResults(Set.of(student1Calculus1Quiz, student2Calculus1Quiz, student3Calculus1Quiz));
//build StudentResults: Statistics3Quiz /100
StudentResult student1Statistics3Quiz = StudentResult.builder()
.studentTask(Statistics3Quiz)
.student(studentService.findById(1L))
.score("88")
.comments("Excellent")
.teacher(keithjones)
.build();
StudentResult student2Statistics3Quiz = StudentResult.builder()
.studentTask(Statistics3Quiz)
.student(studentService.findById(2L))
.score("70")
.comments("Good work")
.teacher(keithjones)
.build();
StudentResult student3Statistics3Quiz = StudentResult.builder()
.studentTask(Statistics3Quiz)
.student(studentService.findById(3L))
.score("71")
.comments("Did very well")
.teacher(keithjones)
.build();
quiz.setStudentResults(Set.of(student1Calculus1Quiz, student2Calculus1Quiz, student3Calculus1Quiz,
student1Statistics3Quiz, student2Statistics3Quiz, student3Statistics3Quiz));
StudentTask savedEngEssPlay = studentTaskService.save(EnglishEssayPlay);
StudentTask savedEngEssTask = studentTaskService.save(EnglishEssayTask);
StudentTask savedMathCalc = studentTaskService.save(Calculus1Quiz);
StudentTask savedMathStat = studentTaskService.save(Statistics3Quiz);
log.debug("Student tasks saved");
studentResultService.save(student1Calculus1Quiz);
studentResultService.save(student1Statistics3Quiz);
studentResultService.save(student1EnglishEssayPlay);
studentResultService.save(student1EnglishEssayTask);
studentResultService.save(student2Calculus1Quiz);
studentResultService.save(student2Statistics3Quiz);
studentResultService.save(student2EnglishEssayPlay);
studentResultService.save(student2EnglishEssayTask);
studentResultService.save(student3Calculus1Quiz);
studentResultService.save(student3Statistics3Quiz);
studentResultService.save(student3EnglishEssayPlay);
studentResultService.save(student3EnglishEssayTask);
log.debug("Student results saved");
assignmentTypeService.save(quiz);
assignmentTypeService.save(coursework);
assignmentTypeService.save(interview);
log.debug("Assignment types updated");
//English thresholds, EnglishEssayTask /60, EnglishEssayPlay /40
Threshold EnglishEssayPassThreshold = Threshold.builder().thresholdLists(new HashSet<>())
.numerical(25)
.alphabetical("PASS")
.uniqueId("EnglishEssayPassThreshold")
.uploader(marymanning)
.build();
Threshold EnglishEssayMeritThreshold = Threshold.builder().thresholdLists(new HashSet<>())
.numerical(35)
.alphabetical("MERIT")
.uniqueId("EnglishEssayMeritThreshold")
.uploader(marymanning)
.build();
Threshold EnglishEssayDistinctionThreshold = Threshold.builder().thresholdLists(new HashSet<>())
.numerical(45)
.alphabetical("DISTINCTION")
.uniqueId("EnglishEssayDistinctionThreshold")
.uploader(marymanning)
.build();
Threshold EnglishPlayPassThreshold = Threshold.builder().thresholdLists(new HashSet<>())
.numerical(15)
.alphabetical("PASS")
.uniqueId("EnglishPlayPassThreshold")
.uploader(marymanning)
.build();
Threshold EnglishPlayMeritThreshold = Threshold.builder().thresholdLists(new HashSet<>())
.numerical(25)
.alphabetical("MERIT")
.uniqueId("EnglishPlayMeritThreshold")
.uploader(marymanning)
.build();
Threshold EnglishPlayDistinctionThreshold = Threshold.builder().thresholdLists(new HashSet<>())
.numerical(33)
.alphabetical("DISTINCTION")
.uniqueId("EnglishPlayDistinctionThreshold")
.uploader(marymanning)
.build();
//Math thresholds, /100
Threshold MathPassThreshold = Threshold.builder().thresholdLists(new HashSet<>())
.numerical(40)
.alphabetical("PASS")
.uniqueId("MathPassThreshold")
.uploader(keithjones)
.build();
Threshold MathDThreshold = Threshold.builder().thresholdLists(new HashSet<>())
.numerical(50)
.alphabetical("D")
.uniqueId("MathDThreshold")
.uploader(keithjones)
.build();
Threshold MathCThreshold = Threshold.builder().thresholdLists(new HashSet<>())
.numerical(60)
.alphabetical("C")
.uniqueId("MathCThreshold")
.uploader(keithjones)
.build();
Threshold MathBThreshold = Threshold.builder().thresholdLists(new HashSet<>())
.numerical(70)
.alphabetical("B")
.uniqueId("MathBThreshold")
.uploader(keithjones)
.build();
Threshold MathAThreshold = Threshold.builder().thresholdLists(new HashSet<>())
.numerical(80)
.alphabetical("A")
.uniqueId("MathAThreshold")
.uploader(keithjones)
.build();
Threshold MathAPlusThreshold = Threshold.builder().thresholdLists(new HashSet<>())
.numerical(90)
.alphabetical("A+")
.uniqueId("MathAPlusThreshold")
.uploader(keithjones)
.build();
//threshold lists (assign thresholds too)
ThresholdList EnglishEssayThresholds = ThresholdList.builder()
.thresholds(Set.of(EnglishEssayDistinctionThreshold, EnglishEssayMeritThreshold, EnglishEssayPassThreshold))
.uniqueID("English essay grades")
.uploader(marymanning).build();
ThresholdList EnglishPlayThresholds = ThresholdList.builder()
.thresholds(Set.of(EnglishPlayDistinctionThreshold, EnglishPlayMeritThreshold, EnglishPlayPassThreshold))
.uniqueID("English play grades")
.uploader(marymanning).build();
ThresholdList MathThresholds = ThresholdList.builder()
.thresholds(Set.of(MathPassThreshold, MathDThreshold, MathCThreshold, MathBThreshold, MathAThreshold, MathAPlusThreshold))
.uniqueID("Math thresholds")
.uploader(keithjones).build();
//assign threshold-lists to thresholds
EnglishEssayDistinctionThreshold.setThresholdLists(Set.of(EnglishEssayThresholds));
EnglishEssayMeritThreshold.setThresholdLists(Set.of(EnglishEssayThresholds));
EnglishEssayPassThreshold.setThresholdLists(Set.of(EnglishEssayThresholds));
EnglishPlayDistinctionThreshold.setThresholdLists(Set.of(EnglishPlayThresholds));
EnglishPlayMeritThreshold.setThresholdLists(Set.of(EnglishPlayThresholds));
EnglishPlayPassThreshold.setThresholdLists(Set.of(EnglishPlayThresholds));
MathPassThreshold.setThresholdLists(Set.of(MathThresholds));
MathDThreshold.setThresholdLists(Set.of(MathThresholds));
MathCThreshold.setThresholdLists(Set.of(MathThresholds));
MathBThreshold.setThresholdLists(Set.of(MathThresholds));
MathAThreshold.setThresholdLists(Set.of(MathThresholds));
MathAPlusThreshold.setThresholdLists(Set.of(MathThresholds));
thresholdService.save(EnglishEssayDistinctionThreshold);
thresholdService.save(EnglishEssayMeritThreshold);
thresholdService.save(EnglishEssayPassThreshold);
thresholdService.save(EnglishPlayDistinctionThreshold);
thresholdService.save(EnglishPlayMeritThreshold);
thresholdService.save(EnglishPlayPassThreshold);
thresholdService.save(MathPassThreshold);
thresholdService.save(MathDThreshold);
thresholdService.save(MathCThreshold);
thresholdService.save(MathBThreshold);
thresholdService.save(MathAThreshold);
thresholdService.save(MathAPlusThreshold);
log.debug("Thresholds saved");
//save threshold-lists AFTER thresholds
ThresholdList savedEngEss = thresholdListService.save(EnglishEssayThresholds);
ThresholdList savedEngPla = thresholdListService.save(EnglishPlayThresholds);
ThresholdList savedMath = thresholdListService.save(MathThresholds);
log.debug("Threshold lists saved");
savedEngEssPlay.setThresholdListSet(Set.of(savedEngPla));
savedEngPla.setStudentTaskSet(Set.of(savedEngEssPlay));
savedEngEssTask.setThresholdListSet(Set.of(savedEngEss));
savedEngEss.setStudentTaskSet(Set.of(savedEngEssTask));
savedMathCalc.setThresholdListSet(Set.of(savedMath));
savedMathStat.setThresholdListSet(Set.of(savedMath));
savedMath.setStudentTaskSet(Set.of(savedMathCalc, savedMathStat));
thresholdListService.save(EnglishEssayThresholds);
thresholdListService.save(EnglishPlayThresholds);
thresholdListService.save(MathThresholds);
studentTaskService.save(EnglishEssayPlay);
studentTaskService.save(EnglishEssayTask);
studentTaskService.save(Calculus1Quiz);
studentTaskService.save(Statistics3Quiz);
log.debug("Thresholds and student tasks linked");
log.debug("================ Finished uploading SRM academic data to DB ============");
}
}