1414import fr .istic .domain .FinalResult ;
1515import fr .istic .domain .GradedComment ;
1616import fr .istic .domain .HybridGradedComment ;
17+ import fr .istic .domain .Prediction ;
1718import fr .istic .domain .Question ;
1819import fr .istic .domain .QuestionType ;
1920import fr .istic .domain .Scan ;
@@ -76,20 +77,29 @@ public ExamDTO persistOrUpdate(ExamDTO examDTO) {
7677 *
7778 * @param id the id of the entity.
7879 */
79- @ Transactional
8080 public void delete (Long id ) {
8181 log .debug ("Request to delete Exam : {}" , id );
82- Exam .findByIdOptional (id ).ifPresent (exam -> {
83- StudentResponse .getAll4ExamIdEvenOrphan (id ).list ().forEach (sr -> {
82+ this .prepareDeleteExam (id );
83+ this .deleteExam (id );
84+
85+
86+ }
87+
88+ @ Transactional
89+ public void prepareDeleteExam (long id ){
90+ Exam .findByIdOptional (id ).ifPresent (exam -> {
91+ ExamSheet .getAll4ExamIdEvenOrphan (id ).list ().forEach (sr -> sr .cleanBeforDelete ());
92+ /*StudentResponse.getAll4ExamIdEvenOrphan(id).list().forEach(sr -> {
8493 sr.clearComments();
8594 Answer2HybridGradedComment.deleteAllAnswerHybridGradedCommentByAnswerId(sr.id);
8695 });
8796
88- ExamSheet .getAll4ExamIdEvenOrphan (id ).list ().forEach (sr -> sr .cleanBeforDelete ());
8997 StudentResponse.getAll4ExamIdEvenOrphan(id).list().forEach(sr -> sr.delete());
9098 FinalResult.getAll4ExamId(id).list().forEach(f -> f.delete());
99+ var s = HybridGradedComment.deleteByQIds(e.questions.stream().map(q -> q.id).collect(Collectors.toSet()));
100+ log.error("to remove" + s);*/
101+ this .deleteQuestionCommentAndZone (id );
91102 Exam e = Exam .findById (id );
92- HybridGradedComment .deleteByQIds (e .questions .stream ().map (q -> q .id ).collect (Collectors .toSet ()));
93103
94104 if (e .scanfile != null && this .fichierS3Service .isObjectExist ("scan/" + e .scanfile .id + ".pdf" )) {
95105 try {
@@ -109,11 +119,18 @@ public void delete(Long id) {
109119 e1 .printStackTrace ();
110120 }
111121 }
112- exam .delete ();
113122 Comments .deleteCommentByExamId ("" + id );
114-
115123 this .cacheService .deleteFile (id );
116124 });
125+
126+ }
127+
128+
129+ @ Transactional
130+ protected void deleteExam (long id ){
131+ var e = Exam .findById (id );
132+ e .delete ();
133+
117134 }
118135
119136 @ Transactional
@@ -169,11 +186,18 @@ protected void cleanExamZone(Set<Long> zoneids) {
169186
170187 @ Transactional
171188 protected void cleanQuestion (long examId , Set <Long > qids ) {
172- StudentResponse .deleteByQIds (qids );
173- TextComment .deleteByQIds (qids );
174- GradedComment .deleteByQIds (qids );
189+ var s = Answer2HybridGradedComment .deleteAllByQIds (qids );
190+ Set <Long > cids = HybridGradedComment .findByExamId (examId ).list ().stream ().map (ex -> ex .id ).collect (Collectors .toSet ());
191+ s = Answer2HybridGradedComment .deleteAllAnswerHybridGradedCommentByCommentIds (cids );
192+ s = StudentResponse .deleteByQIds (qids );
193+ s = TextComment .deleteByQIds (qids );
194+ s = GradedComment .deleteByQIds (qids );
195+ s = HybridGradedComment .deleteByQIds (qids );
196+ s =Prediction .deleteByQIds (qids );
197+ }
198+ @ Transactional
199+ protected void removeQuestion (long examId , Set <Long > qids ) {
175200 Question .deleteAllExamId (examId );
176-
177201 }
178202
179203 @ Transactional
@@ -187,16 +211,16 @@ protected void cleanFinalResult(long id) {
187211 *
188212 * @param id the id of the entity.
189213 */
190- @ Transactional
191- public void deleteQuestionCommentAndZone (Long id ) {
192- log .debug ("Request to delete Exam : {}" , id );
193- Set <Long > qids = Question .findQuestionbyExamId (id ).list ().stream ().map (ex -> ex .id ).collect (Collectors .toSet ());
214+ public void deleteQuestionCommentAndZone (Long examid ) {
215+ log .debug ("Request to delete Exam : {}" , examid );
216+ Set <Long > qids = Question .findQuestionbyExamId (examid ).list ().stream ().map (ex -> ex .id ).collect (Collectors .toSet ());
194217
195- this .cleanFinalResult (id );
196- Set <Long > zonesids = this .cleanExamZone (id );
218+ this .cleanFinalResult (examid );
219+ Set <Long > zonesids = this .cleanExamZone (examid );
197220 this .cleanExamZone (zonesids );
198221 // this.cleanStudentRssponse(id);
199- this .cleanQuestion (id , qids );
222+ this .cleanQuestion (examid , qids );
223+ this .removeQuestion (examid , qids );
200224
201225 }
202226
0 commit comments