diff --git a/src/main/java/fr/istic/service/customdto/StudentResultDTO.java b/src/main/java/fr/istic/service/customdto/StudentResultDTO.java index 08fb8a3..f835542 100644 --- a/src/main/java/fr/istic/service/customdto/StudentResultDTO.java +++ b/src/main/java/fr/istic/service/customdto/StudentResultDTO.java @@ -7,13 +7,20 @@ @RegisterForReflection public class StudentResultDTO extends StudentDTO{ + Long id; String uuid; String studentNumber; String note; - boolean abi; + // abi = 0 => false, abi =1 => true abi = 2 abj + int abi; Map notequestions = new HashMap<>(); - + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } public String getUuid() { return uuid; @@ -27,10 +34,10 @@ public String getNote() { public void setNote(String note) { this.note = note; } - public boolean isAbi() { + public int isAbi() { return abi; } - public void setAbi(boolean abi) { + public void setAbi(int abi) { this.abi = abi; } @@ -56,7 +63,7 @@ public String toString() { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + (abi ? 1231 : 1237); + result = prime * result + Integer.valueOf(abi).hashCode(); result = prime * result + ((note == null) ? 0 : note.hashCode()); result = prime * result + ((notequestions == null) ? 0 : notequestions.hashCode()); result = prime * result + ((studentNumber == null) ? 0 : studentNumber.hashCode()); diff --git a/src/main/java/fr/istic/web/rest/ExamResource.java b/src/main/java/fr/istic/web/rest/ExamResource.java index cb3b405..e16207a 100644 --- a/src/main/java/fr/istic/web/rest/ExamResource.java +++ b/src/main/java/fr/istic/web/rest/ExamResource.java @@ -12,6 +12,7 @@ import fr.istic.domain.User; import fr.istic.security.AuthoritiesConstants; import fr.istic.service.ExamService; +import fr.istic.service.ExamSheetService; import fr.istic.web.rest.errors.AccountResourceException; import fr.istic.web.rest.errors.BadRequestAlertException; import fr.istic.web.util.HeaderUtil; @@ -61,6 +62,9 @@ public class ExamResource { @Inject ExamService examService; + @Inject + ExamSheetService examSheetService; + @Inject SecurityService securityService; @@ -146,18 +150,25 @@ public Response deleteStudentSheet(@PathParam("id") Long id, @Context SecurityCo } Optional ex = Exam.findByIdOptional(id); if (ex.isPresent()){ - List st = Student.findStudentsbyCourseId(ex.get().course.id).list(); - Set toRemoveS = new HashSet<>(); - for (Student student : st){ +// List st = Student.findStudentsbyCourseId(ex.get().course.id).list(); + List sheets = ExamSheet.getAll4ExamId(ex.get().id).list(); + // Set toRemoveS = new HashSet<>(); + /* for (Student student : st){ List toRemove = student.examSheets.stream().filter(es -> es.scan.id == ex.get().scanfile.id).collect(Collectors.toList()); toRemoveS.addAll(toRemove); student.examSheets.removeIf(es -> es.scan.id == ex.get().scanfile.id); Student.update(student); - } - for (ExamSheet toRemove1: toRemoveS){ - if (StudentResponse.findStudentResponsesbysheetId(toRemove1.id).count() ==0){ - toRemove1.delete(); + }*/ + for (ExamSheet toRemove1: sheets){ + try { + this.examSheetService.updateStudent(toRemove1.id, new ArrayList()); + } catch (Exception e) { + e.printStackTrace(); } + +/* if (StudentResponse.findStudentResponsesbysheetId(toRemove1.id).count() ==0){ + toRemove1.delete(); + }*/ } } diff --git a/src/main/java/fr/istic/web/rest/ExtendedAPI.java b/src/main/java/fr/istic/web/rest/ExtendedAPI.java index 1fdd3ad..cc25492 100644 --- a/src/main/java/fr/istic/web/rest/ExtendedAPI.java +++ b/src/main/java/fr/istic/web/rest/ExtendedAPI.java @@ -117,6 +117,7 @@ import static jakarta.ws.rs.core.UriBuilder.fromPath; + /** * REST controller for managing {@link fr.istic.domain.Comments}. */ @@ -125,6 +126,7 @@ @Consumes(MediaType.APPLICATION_JSON) @ApplicationScoped public class ExtendedAPI { + final int VALUEFORABJ = -100000; private final Logger log = LoggerFactory.getLogger(ExtendedAPI.class); @@ -520,9 +522,12 @@ public Exam computeFinalNote(long examId, Map finalfinalResul sh.students.forEach(student -> { var q = FinalResult.findFinalResultByStudentIdAndExamId(student.id, examId); long count = q.count(); - if (count > 0) { + var fr = q.list(); + // For managing ABJ + if (count > 0 && fr.get(0).note != VALUEFORABJ) { FinalResult.deleteById(q.firstResult().id); - + } else if (count > 0 && fr.get(0).note == VALUEFORABJ) { + finalfinalResultsByStudentId.put(student.id, fr.get(0)); } }); } else { @@ -557,7 +562,6 @@ public Exam computeFinalNote(long examId, Map finalfinalResul } } return ex; - } @POST @@ -574,6 +578,40 @@ public Response computeFinalNote4Exam(@PathParam("examId") long examId, @Context return Response.ok().build(); } + @PUT + @Path("toggleAsAbJ/{studentId}/{examId}/{abi}") + @Transactional + @RolesAllowed({ AuthoritiesConstants.USER, AuthoritiesConstants.ADMIN }) + public Response toggleAsAbJ(@PathParam("studentId") long studentId, @PathParam("examId") long examId, @PathParam("abi") long abi, @Context SecurityContext ctx) { + if (!securityService.canAccess(ctx, examId, Exam.class)) { + return Response.status(403, "Current user cannot access to this ressource").build(); + } + var frs = FinalResult.findFinalResultByStudentIdAndExamId(studentId, examId).list(); + + if (frs.size() >0) { + var fr = frs.get(0); + if (abi ==2 && fr.note != VALUEFORABJ) { + fr.note = VALUEFORABJ; + fr = FinalResult.update(fr); + } else { + fr.delete(); + } + } + else { + if (abi ==2){ + + FinalResult r = new FinalResult(); + r.student = Student.findById(Long.valueOf(studentId)); + r.exam = Exam.findById(Long.valueOf(examId)); + r.note = VALUEFORABJ; + r = FinalResult.persistOrUpdate(r); + } + + } + return Response.ok().build(); + + } + @POST @Path("sendResult/{examId}") @RolesAllowed({ AuthoritiesConstants.USER, AuthoritiesConstants.ADMIN }) @@ -699,7 +737,6 @@ public Response showResult(@PathParam("examId") long examId, @Context SecurityCo // for (Map.Entry finalResult1 : // finalfinalResultsByStudentId.entrySet()) { // FinalResult r = finalResult1.getValue(); - log.error("sheets "+finalNotes.size() ); for (Map.Entry sheetEntry : finalNotes.entrySet()) { // List sheets = finalNotes.keySet().stream() @@ -718,6 +755,7 @@ public Response showResult(@PathParam("examId") long examId, @Context SecurityCo for (Student student : sheet.students) { var res = new StudentResultDTO(); + res.setId(student.id); sheetsId.add(sheet.id); studentsId.add(student.id); @@ -729,7 +767,7 @@ public Response showResult(@PathParam("examId") long examId, @Context SecurityCo res.setNote(df.format(r.doubleValue() / 100.0)); res.setUuid(uuid); res.setStudentNumber("" + studentnumber); - res.setAbi(false); + res.setAbi(0); res.setNotequestions(new HashMap<>()); List resp = mapstudentResp.get(sheet); @@ -770,7 +808,7 @@ public Response showResult(@PathParam("examId") long examId, @Context SecurityCo res.setNote(df.format(r.doubleValue() / 100.0)); res.setUuid(uuid); res.setStudentNumber("" + studentnumber); - res.setAbi(false); + res.setAbi(0); res.setNotequestions(new HashMap<>()); List resp = mapstudentResp.get(sheet); @@ -811,9 +849,11 @@ public Response showResult(@PathParam("examId") long examId, @Context SecurityCo List sheets1 = ExamSheet.getAll4ExamIdNotInStudentIdList(examId, sheetsId).list(); for (ExamSheet sheet : sheets1) { for (Student student : sheet.students) { + String uuid = sheet.name; int studentnumber = (sheet.pagemin / (sheet.pagemax - sheet.pagemin + 1)) + 1; var res = new StudentResultDTO(); + res.setId(student.id); studentsId.add(student.id); sheetsId.add(sheet.id); res.setNom(student.name); @@ -824,7 +864,8 @@ public Response showResult(@PathParam("examId") long examId, @Context SecurityCo res.setNote(df.format(0)); res.setUuid(uuid); res.setStudentNumber("" + studentnumber); - res.setAbi(false); + res.setAbi(0); + res.setNotequestions(new HashMap<>()); results.add(res); } @@ -867,11 +908,18 @@ public int compare(Student arg0, Student arg1) { studentsAbi.forEach(student -> { var res = new StudentResultDTO(); + res.setId(student.id); res.setNom(student.name); res.setPrenom(student.firstname); res.setIne(student.ine); res.setMail(student.mail); - res.setAbi(true); + var frs = FinalResult.findFinalResultByStudentIdAndExamId(student.id, ex.id).list(); + if (frs.size()>0 && frs.get(0).note ==VALUEFORABJ){ + res.setAbi(2); + }else { + res.setAbi(1); + + } results.add(res); });