From b646a6384da1b1125e3f418c93f1c53d70f56567 Mon Sep 17 00:00:00 2001 From: Olivier Barais Date: Mon, 20 Oct 2025 13:54:13 +0200 Subject: [PATCH 1/3] update readme --- src/main/java/fr/istic/domain/Exam.java | 1 + .../fr/istic/service/CacheUploadService.java | 69 +++++++++---------- .../java/fr/istic/service/ZoneService.java | 9 ++- 3 files changed, 39 insertions(+), 40 deletions(-) diff --git a/src/main/java/fr/istic/domain/Exam.java b/src/main/java/fr/istic/domain/Exam.java index 739f9e03..521894ae 100644 --- a/src/main/java/fr/istic/domain/Exam.java +++ b/src/main/java/fr/istic/domain/Exam.java @@ -166,6 +166,7 @@ public static long removeIdZoneId(Exam exam) { if (exam.id == null) { return 0; } else { + exam.idzone = null; return update("idzone = ?1 where id = ?2", null, exam.id); } diff --git a/src/main/java/fr/istic/service/CacheUploadService.java b/src/main/java/fr/istic/service/CacheUploadService.java index 926087a9..6bff56d7 100644 --- a/src/main/java/fr/istic/service/CacheUploadService.java +++ b/src/main/java/fr/istic/service/CacheUploadService.java @@ -70,16 +70,15 @@ protected InputStream getObject(String name) protected void putObject(String name, byte[] bytes, String contenttype) throws InvalidKeyException, NoSuchAlgorithmException, IllegalArgumentException, IOException { - if (this.fichierS3Service.isObjectExist(name)) { - try { - this.fichierS3Service.deleteObject(name); - } catch (ErrorResponseException | InsufficientDataException | InternalException - | InvalidResponseException | ServerException | XmlParserException e) { - e.printStackTrace(); - } - + if (this.fichierS3Service.isObjectExist(name)) { + try { + this.fichierS3Service.deleteObject(name); + } catch (ErrorResponseException | InsufficientDataException | InternalException + | InvalidResponseException | ServerException | XmlParserException e) { + e.printStackTrace(); + } - } + } this.fichierS3Service.putObject(name, bytes, contenttype); } @@ -160,7 +159,7 @@ protected void deleteFile(long id) { if (!customDir.exists()) { customDir.mkdirs(); } - String fileName = "cache" +File.separator + id + "indexdb.json"; + String fileName = "cache" + File.separator + id + "indexdb.json"; fileName = customDir.getAbsolutePath() + File.separator + fileName; @@ -169,11 +168,11 @@ protected void deleteFile(long id) { } else { long k = 1; fileName = customDir.getAbsolutePath() + - File.separator + "cache"+ File.separator + id + "_part_" + k + "_indexdb.json"; + File.separator + "cache" + File.separator + id + "_part_" + k + "_indexdb.json"; while (Paths.get(fileName).toFile().exists()) { Paths.get(fileName).toFile().delete(); k = k + 1; - fileName = "cache" +File.separator + id + "_part_" + k + "_indexdb.json"; + fileName = "cache" + File.separator + id + "_part_" + k + "_indexdb.json"; } } @@ -237,7 +236,7 @@ public InputStream getFile(String fileName) throws Exception { if (!customDir.exists()) { customDir.mkdirs(); } - File customDir1 = new File(UPLOAD_DIR + File.separator + "cache" ); + File customDir1 = new File(UPLOAD_DIR + File.separator + "cache"); if (!customDir1.exists()) { customDir1.mkdirs(); } @@ -371,7 +370,7 @@ public long getCachePageInTemplateSqlite(long id) throws IOException { // create a connection to the database conn = DriverManager.getConnection(url); - //TODO + // TODO String query = "select count(*) from template"; try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery(query); @@ -401,7 +400,7 @@ public long getCachePageInTemplateSqlite(long id) throws IOException { return 0; } - public long getCacheTimeStampSqlite(long id) throws IOException { + public long getCacheTimeStampSqlite(long id) throws IOException { InputStream inputStream = null; String dbpath = ""; @@ -471,10 +470,8 @@ public long getCacheTimeStampSqlite(long id) throws IOException { return 0; } - - -public long getCacheTimeStamp(long id) throws IOException{ - InputStream inputStream = null; + public long getCacheTimeStamp(long id) throws IOException { + InputStream inputStream = null; long timestamp = 0; if (this.uses3) { String fileName = "cache/" + id + "indexdb.json"; @@ -510,7 +507,7 @@ public long getCacheTimeStamp(long id) throws IOException{ inputStream = Files.newInputStream(Paths.get(fileName)); } else { - fileName = "cache/" + id + "_exam_template_indexdb.json"; + fileName = "cache/" + id + "_exam_template_indexdb.json"; fileName = customDir.getAbsolutePath() + File.separator + fileName; if (Paths.get(fileName).toFile().exists()) { @@ -548,34 +545,31 @@ public long getCacheTimeStamp(long id) throws IOException{ reader.beginObject(); reader.nextName(); reader.nextString(); - reader.nextName(); + reader.nextName(); reader.skipValue(); reader.nextName(); reader.beginArray(); - while (reader.hasNext()){ - reader.beginObject(); - reader.nextName(); - reader.nextLong(); - if (reader.hasNext()){ + while (reader.hasNext()) { + reader.beginObject(); reader.nextName(); - timestamp= reader.nextLong(); - } - reader.endObject(); + reader.nextLong(); + if (reader.hasNext()) { + reader.nextName(); + timestamp = reader.nextLong(); + } + reader.endObject(); } reader.endArray(); - reader.endObject(); - // reader.endObject(); reader.close(); inputStream.close(); return timestamp; -} - + } public long getCachePageInTemplate(long id) throws IOException { InputStream inputStream = null; @@ -614,7 +608,7 @@ public long getCachePageInTemplate(long id) throws IOException { inputStream = Files.newInputStream(Paths.get(fileName)); } else { - fileName = "cache/" + id + "_exam_template_indexdb.json"; + fileName = "cache/" + id + "_exam_template_indexdb.json"; fileName = customDir.getAbsolutePath() + File.separator + fileName; if (Paths.get(fileName).toFile().exists()) { @@ -666,16 +660,16 @@ public long getCachePageInTemplate(long id) throws IOException { reader.nextName(); reader.skipValue(); reader.nextName(); - //reader.skipValue(); + // reader.skipValue(); reader.beginArray(); - while (reader.hasNext()){ + while (reader.hasNext()) { reader.beginObject(); reader.nextName(); reader.nextString(); reader.nextName(); long l = reader.nextLong(); - if (l > pageNumber){ + if (l > pageNumber) { pageNumber = l; } reader.nextName(); @@ -694,7 +688,6 @@ public long getCachePageInTemplate(long id) throws IOException { } - public String getAlignPage(long id, int pagefileter, boolean nonalign) throws IOException { InputStream inputStream = null; if (this.uses3) { diff --git a/src/main/java/fr/istic/service/ZoneService.java b/src/main/java/fr/istic/service/ZoneService.java index 32a2efa2..3bf6edab 100644 --- a/src/main/java/fr/istic/service/ZoneService.java +++ b/src/main/java/fr/istic/service/ZoneService.java @@ -42,7 +42,8 @@ public ZoneDTO persistOrUpdate(ZoneDTO zoneDTO) { @Transactional void deleteZone (long id){ - Zone.deleteById(id); + Zone z = Zone.findById(id); + z.delete(); } @@ -53,13 +54,15 @@ void deleteZone (long id){ */ @Transactional public void delete(Long id) { - log.debug("Request to delete Zone : {}", id); + log.error("Request to delete Zone : {}", id); Optional q = Question.findQuestionbyZoneId(id).firstResultOptional(); if (q.isPresent()) { questionSerivce.cleanAllCorrectionAndComment(q.get()); questionSerivce.delete(q.get().id); } else{ Optional exam = Exam.findExamThatMatchZoneId(id).firstResultOptional(); + + log.debug("Exam found to clean zone : {}", exam.get().id); if (exam.isPresent()) { if (exam.get().namezone != null && exam.get().namezone.id.equals(id)){ Exam.removeNameZoneId(exam.get()); @@ -70,6 +73,8 @@ else if (exam.get().firstnamezone != null && exam.get().firstnamezone.id.equals } else if (exam.get().idzone != null && exam.get().idzone.id.equals(id)){ Exam.removeIdZoneId(exam.get()); + exam.get().idzone = null; + } else if (exam.get().notezone != null && exam.get().notezone.id.equals(id)) { From c038ea7ab583d58760d45e067335d649e3a2a34a Mon Sep 17 00:00:00 2001 From: Olivier Barais Date: Mon, 20 Oct 2025 13:57:22 +0200 Subject: [PATCH 2/3] remove log --- src/main/java/fr/istic/service/ZoneService.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/fr/istic/service/ZoneService.java b/src/main/java/fr/istic/service/ZoneService.java index 3bf6edab..6125655e 100644 --- a/src/main/java/fr/istic/service/ZoneService.java +++ b/src/main/java/fr/istic/service/ZoneService.java @@ -54,15 +54,13 @@ void deleteZone (long id){ */ @Transactional public void delete(Long id) { - log.error("Request to delete Zone : {}", id); + log.debug("Request to delete Zone : {}", id); Optional q = Question.findQuestionbyZoneId(id).firstResultOptional(); if (q.isPresent()) { questionSerivce.cleanAllCorrectionAndComment(q.get()); questionSerivce.delete(q.get().id); } else{ Optional exam = Exam.findExamThatMatchZoneId(id).firstResultOptional(); - - log.debug("Exam found to clean zone : {}", exam.get().id); if (exam.isPresent()) { if (exam.get().namezone != null && exam.get().namezone.id.equals(id)){ Exam.removeNameZoneId(exam.get()); From a63b447e58be4be2c6f108c7f6d62d11a8ebb0ac Mon Sep 17 00:00:00 2001 From: Olivier Barais Date: Tue, 4 Nov 2025 15:04:08 +0100 Subject: [PATCH 3/3] update the correction of gybrid graded comment --- .../service/HybridGradedCommentService.java | 125 ++++++++++-------- 1 file changed, 70 insertions(+), 55 deletions(-) diff --git a/src/main/java/fr/istic/service/HybridGradedCommentService.java b/src/main/java/fr/istic/service/HybridGradedCommentService.java index f952c8bd..8275d57e 100644 --- a/src/main/java/fr/istic/service/HybridGradedCommentService.java +++ b/src/main/java/fr/istic/service/HybridGradedCommentService.java @@ -34,59 +34,72 @@ public class HybridGradedCommentService { public HybridGradedCommentDTO persistOrUpdate(HybridGradedCommentDTO hybridGradedCommentDTO) { log.debug("Request to save HybridGradedComment : {}", hybridGradedCommentDTO); var hybridGradedComment = hybridGradedCommentMapper.toEntity(hybridGradedCommentDTO); - boolean shouldUpdate =false; +// boolean shouldUpdate = false; - if (hybridGradedComment.id!= null){ + if (hybridGradedComment.id != null) { HybridGradedComment h2 = HybridGradedComment.findById(hybridGradedComment.id); - if (h2 != null){ - var oldGrade = h2.grade; - var oldRelative = h2.relative; - var oldStep = h2.step; - if (hybridGradedComment.grade != oldGrade || hybridGradedComment.step != oldStep || hybridGradedComment.relative!= oldRelative){ - shouldUpdate =true; - } - - } - } - hybridGradedComment = HybridGradedComment.persistOrUpdate(hybridGradedComment); - if (shouldUpdate){ - List ans = Answer2HybridGradedComment.findAllAnswerHybridGradedCommentByCommentIdWithFetchWithStepvalueUpperThan0(hybridGradedComment.id).list(); //.stream().filter(an3 -> an3.stepValue>0).collect(Collectors.toList()); - for( Answer2HybridGradedComment an : ans){ - var st = an.studentResponse; - var ans2 = an.studentResponse.hybridcommentsValues; - - var currentNote = 0.0; - var absoluteNote2Add = 0.0; - double pourcentage = 0.0; - if (st.question != null && st.question.defaultpoint != null){ - pourcentage = st.question.defaultpoint.doubleValue() *4; - - } - for (Answer2HybridGradedComment an2 : ans2){ - var stepValue = an2.stepValue !=null ? an2.stepValue.doubleValue(): 0.0; - if (stepValue > 0) { - var relative = an2.hybridcomments.relative != null ? an2.hybridcomments.relative : false; - var step = an2.hybridcomments.step != null ? an2.hybridcomments.step.doubleValue() : 1.0; - var grade = an2.hybridcomments.grade != null ? an2.hybridcomments.grade.doubleValue() : 0.0; - if (relative) { - pourcentage = pourcentage + (stepValue / step) * grade; - } else { - absoluteNote2Add = absoluteNote2Add + (stepValue / step) * grade; + if (h2 != null) { + var oldGrade = h2.grade; + var oldRelative = h2.relative; + var oldStep = h2.step; + if (hybridGradedComment.grade != oldGrade || hybridGradedComment.step != oldStep + || hybridGradedComment.relative != oldRelative) { + List ans = Answer2HybridGradedComment + .findAllAnswerHybridGradedCommentByCommentIdWithFetchWithStepvalueUpperThan0( + hybridGradedComment.id) + .list(); // .stream().filter(an3 -> an3.stepValue>0).collect(Collectors.toList()); + for (Answer2HybridGradedComment an : ans) { + var st = an.studentResponse; + var ans2 = an.studentResponse.hybridcommentsValues; + + var currentNote = 0.0; + var absoluteNote2Add = 0.0; + double pourcentage = 0.0; + if (st.question != null && st.question.defaultpoint != null) { + pourcentage = st.question.defaultpoint.doubleValue() * 4; + + } + for (Answer2HybridGradedComment an2 : ans2) { + var stepValue = an2.stepValue != null ? an2.stepValue.doubleValue() : 0.0; + if (stepValue > 0) { + var relative = an2.hybridcomments.relative != null ? an2.hybridcomments.relative + : false; + var step = an2.hybridcomments.step != null ? an2.hybridcomments.step.doubleValue() + : 1.0; + var grade = an2.hybridcomments.grade != null ? an2.hybridcomments.grade.doubleValue() + : 0.0; + if (relative) { + pourcentage = pourcentage + (stepValue / step) * grade; + } else { + absoluteNote2Add = absoluteNote2Add + (stepValue / step) * grade; + } } - } - } - var point = st.question.quarterpoint !=null ? st.question.quarterpoint.doubleValue(): 0.0; - currentNote = (point * pourcentage) / 400.0 + absoluteNote2Add; - if (currentNote > point && !st.question.canExceedTheMax) { - currentNote = point; - } else if (currentNote < 0 && !st.question.canBeNegative) { - currentNote = 0; + } + var point = st.question.quarterpoint != null ? st.question.quarterpoint.doubleValue() : 0.0; + currentNote = (point * pourcentage) / 400.0 + absoluteNote2Add; + if (currentNote > point && !st.question.canExceedTheMax) { + currentNote = point; + } else if (currentNote < 0 && !st.question.canBeNegative) { + currentNote = 0; + } + st.quarternote = Double.valueOf(currentNote * 100).intValue(); + st.persistOrUpdate(); } - st.quarternote = Double.valueOf(currentNote*100).intValue(); - st.persistOrUpdate(); } + } + h2.description = hybridGradedComment.description; + h2.grade = hybridGradedComment.grade; + h2.relative = hybridGradedComment.relative; + h2.step = hybridGradedComment.step; + h2.text = hybridGradedComment.text; + hybridGradedComment = HybridGradedComment.persistOrUpdate(h2); + + + } else { + hybridGradedComment = HybridGradedComment.persistOrUpdate(hybridGradedComment); + } return hybridGradedCommentMapper.toDto(hybridGradedComment); } @@ -101,10 +114,10 @@ public void delete(Long id) { log.debug("Request to delete HybridGradedComment : {}", id); this.answer2HybridGradedCommentService.deleteAllAnswerHybridGradedCommentByCommentId(id); HybridGradedComment - .findByIdOptional(id) - .ifPresent(hybridGradedComment -> { - hybridGradedComment.delete(); - }); + .findByIdOptional(id) + .ifPresent(hybridGradedComment -> { + hybridGradedComment.delete(); + }); } /** @@ -116,23 +129,25 @@ public void delete(Long id) { public Optional findOne(Long id) { log.debug("Request to get HybridGradedComment : {}", id); return HybridGradedComment - .findByIdOptional(id) - .map(hybridGradedComment -> hybridGradedCommentMapper.toDto((HybridGradedComment) hybridGradedComment)); + .findByIdOptional(id) + .map(hybridGradedComment -> hybridGradedCommentMapper.toDto((HybridGradedComment) hybridGradedComment)); } /** * Get all the hybridGradedComments. + * * @param page the pagination information. * @return the list of entities. */ public Paged findAll(Page page) { log.debug("Request to get all HybridGradedComments"); return new Paged<>(HybridGradedComment.findAll().page(page)) - .map(hybridGradedComment -> hybridGradedCommentMapper.toDto((HybridGradedComment) hybridGradedComment)); + .map(hybridGradedComment -> hybridGradedCommentMapper.toDto((HybridGradedComment) hybridGradedComment)); } public Paged findHybridGradedCommentByQuestionId(Page page, long qId) { - log.debug("Request to get all GradedComments by QID"); + log.debug("Request to get all GradedComments by QID"); return new Paged<>(HybridGradedComment.findByQuestionId(qId).page(page)) - .map(hgradedComment -> hybridGradedCommentMapper.toDto((HybridGradedComment) hgradedComment)); } + .map(hgradedComment -> hybridGradedCommentMapper.toDto((HybridGradedComment) hgradedComment)); + } }