Skip to content

Commit

Permalink
close #476
Browse files Browse the repository at this point in the history
  • Loading branch information
barais committed Jan 28, 2024
1 parent 26b9456 commit c7df28c
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 20 deletions.
17 changes: 12 additions & 5 deletions src/main/java/fr/istic/service/customdto/StudentResultDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer, String> notequestions = new HashMap<>();


public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}

public String getUuid() {
return uuid;
Expand All @@ -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;
}

Expand All @@ -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());
Expand Down
25 changes: 18 additions & 7 deletions src/main/java/fr/istic/web/rest/ExamResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,6 +62,9 @@ public class ExamResource {
@Inject
ExamService examService;

@Inject
ExamSheetService examSheetService;

@Inject
SecurityService securityService;

Expand Down Expand Up @@ -146,18 +150,25 @@ public Response deleteStudentSheet(@PathParam("id") Long id, @Context SecurityCo
}
Optional<Exam> ex = Exam.findByIdOptional(id);
if (ex.isPresent()){
List<Student> st = Student.findStudentsbyCourseId(ex.get().course.id).list();
Set<ExamSheet> toRemoveS = new HashSet<>();
for (Student student : st){
// List<Student> st = Student.findStudentsbyCourseId(ex.get().course.id).list();
List<ExamSheet> sheets = ExamSheet.getAll4ExamId(ex.get().id).list();
// Set<ExamSheet> toRemoveS = new HashSet<>();
/* for (Student student : st){
List<ExamSheet> 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<Long>());
} catch (Exception e) {
e.printStackTrace();
}

/* if (StudentResponse.findStudentResponsesbysheetId(toRemove1.id).count() ==0){
toRemove1.delete();
}*/
}

}
Expand Down
64 changes: 56 additions & 8 deletions src/main/java/fr/istic/web/rest/ExtendedAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@

import static jakarta.ws.rs.core.UriBuilder.fromPath;


/**
* REST controller for managing {@link fr.istic.domain.Comments}.
*/
Expand All @@ -125,6 +126,7 @@
@Consumes(MediaType.APPLICATION_JSON)
@ApplicationScoped
public class ExtendedAPI {
final int VALUEFORABJ = -100000;

private final Logger log = LoggerFactory.getLogger(ExtendedAPI.class);

Expand Down Expand Up @@ -520,9 +522,12 @@ public Exam computeFinalNote(long examId, Map<Long, FinalResult> 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 {
Expand Down Expand Up @@ -557,7 +562,6 @@ public Exam computeFinalNote(long examId, Map<Long, FinalResult> finalfinalResul
}
}
return ex;

}

@POST
Expand All @@ -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 })
Expand Down Expand Up @@ -699,7 +737,6 @@ public Response showResult(@PathParam("examId") long examId, @Context SecurityCo
// for (Map.Entry<Long, FinalResult> finalResult1 :
// finalfinalResultsByStudentId.entrySet()) {
// FinalResult r = finalResult1.getValue();
log.error("sheets "+finalNotes.size() );

for (Map.Entry<ExamSheet, Integer> sheetEntry : finalNotes.entrySet()) {
// List<ExamSheet> sheets = finalNotes.keySet().stream()
Expand All @@ -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);
Expand All @@ -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<StudentResponse> resp = mapstudentResp.get(sheet);

Expand Down Expand Up @@ -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<StudentResponse> resp = mapstudentResp.get(sheet);

Expand Down Expand Up @@ -811,9 +849,11 @@ public Response showResult(@PathParam("examId") long examId, @Context SecurityCo
List<ExamSheet> 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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
});

Expand Down

0 comments on commit c7df28c

Please sign in to comment.