Skip to content

Commit

Permalink
save who and when someone correct a specific question and a specific …
Browse files Browse the repository at this point in the history
…sheet
  • Loading branch information
barais committed Mar 6, 2024
1 parent 91e5708 commit 53ae9f2
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 63 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ alter table hybrid_graded_comment add constraint FKrrl2y7dngtnqlklwt0scsy8jq for

ALTER TABLE `gradeScopeIstic`.`answer_2_hybrid_graded_comment` ADD UNIQUE `UniqueHybridcommentsIdAndStudentResponseId` (`student_response_id`, `hybridcomments_id`);

ALTER TABLE `student_response` ADD UNIQUE(`question_id`, `sheet_id`);

alter table student_response add column lastmodified datetime(6);
alter table student_response add column correctedby_id bigint;
alter table student_response add constraint FKinrpshecm7c6aiqo6000ju87c foreign key (correctedby_id) references jhi_user (id);



[x] unique constraint for answer_2_hybrid_graded_comment
[x] delete correctly when removing exam or course
[x] Import Export with HybridComment
Expand All @@ -134,3 +142,22 @@ ALTER TABLE `gradeScopeIstic`.`answer_2_hybrid_graded_comment` ADD UNIQUE `Uniqu
[x] Update view copie4student
[x] update show all with this hybridComment
[x] update apply to all the same grade



SELECT resp.id FROM `student_response` as resp WHERE EXISTS( SELECT * FROM `student_response` as resp2 WHERE resp.id <> resp2.id and resp.question_id = resp2.question_id and resp.sheet_id = resp2.sheet_id);

select * from student_response_textcomments as st3 where st3.student_response_id IN(
SELECT resp.id FROM `student_response` as resp WHERE EXISTS( SELECT * FROM `student_response` as resp2 WHERE resp.id <> resp2.id and resp.question_id = resp2.question_id and resp.sheet_id = resp2.sheet_id));



DELETE from answer_2_hybrid_graded_comment as an where an.student_response_id IN(
SELECT resp.id FROM `student_response` as resp WHERE EXISTS( SELECT * FROM `student_response` as resp2 WHERE resp.id <> resp2.id and resp.question_id = resp2.question_id and resp.sheet_id = resp2.sheet_id));

select an.* from answer_2_hybrid_graded_comment as an where an.student_response_id IN(SELECT resp.id FROM `student_response` as resp WHERE EXISTS( SELECT * FROM `student_response` as resp2 WHERE resp.id <> resp2.id and resp.question_id = resp2.question_id and resp.sheet_id = resp2.sheet_id));

delete an.* from answer_2_hybrid_graded_comment as an where an.student_response_id IN(
SELECT resp.id FROM `student_response` as resp WHERE EXISTS( SELECT * FROM `student_response` as resp2 WHERE resp.id <> resp2.id and resp.question_id = resp2.question_id and resp.sheet_id = resp2.sheet_id));

DELETE FROM `student_response` WHERE id in (53044,53045,53046,53047,53050,53051,53052,53053,53054,53055,53056,53057,53058,53059,53061,53062,53063,53064,53065,53066,53067,53068,53106,53107,53108,53109,53110,53111,53112,53113,53114,53115,53117,53118,53119,53120,53121,53122,53124,53125,53126,53127,53128,53129,53130,53131,53133,53134,53135,53136,53184,53185,53240,53241,53242,53243,53244,53245,53248,53249,53250,53251);
20 changes: 19 additions & 1 deletion src/main/java/fr/istic/domain/StudentResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import jakarta.transaction.Transactional;

import java.io.Serializable;
import java.time.Instant;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -38,6 +39,10 @@ public class StudentResponse extends PanacheEntityBase implements Serializable {
@Column(name = "worststar")
public Boolean worststar;

@Column(name = "lastmodified")
public Instant lastModifiedDate = Instant.now();


@OneToMany(mappedBy = "studentResponse", cascade = {CascadeType.REMOVE})
public Set<Comments> comments = new HashSet<>();

Expand Down Expand Up @@ -73,6 +78,13 @@ public ExamSheet getCSheet(){
return sheet;
}

@ManyToOne
@JoinColumn(name = "correctedby_id")
@JsonbTransient
public User correctedBy;




@ManyToOne
@JoinColumn(name = "sheet_id")
Expand Down Expand Up @@ -221,9 +233,15 @@ public static Optional<StudentResponse> findOne(Long id) {
}


public static PanacheQuery<StudentResponse> findStudentResponsesbysheetIdAndquestionId( long sheetId, List<Long> questionsId) {
public static PanacheQuery<StudentResponse> findStudentResponsesbysheetIdAndquestionsId( long sheetId, List<Long> questionsId) {
return find("select sr from StudentResponse sr where sr.sheet.id =?1 and question.id in ?2", sheetId, questionsId);
}

public static PanacheQuery<StudentResponse> findStudentResponsesbysheetIdAndquestionId( long sheetId, Long questionId) {
return find("select sr from StudentResponse sr where sr.sheet.id =?1 and question.id = ?2", sheetId, questionId);
}


public static PanacheQuery<StudentResponse> findStudentResponsesbysheetId( long sheetId) {
return find("select sr from StudentResponse sr where sr.sheet.id =?1 ", sheetId );
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/fr/istic/service/SecurityService.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ else if (user.get().authorities.size() >= 1 && user.get().authorities.stream().a
}


public User getCurrentLoggedUser(SecurityContext ctx){
if (ctx.getUserPrincipal() == null ) return null;
var userLogin = Optional
.ofNullable(ctx.getUserPrincipal().getName());
if (!userLogin.isPresent()){
throw new AccountResourceException("Current user login not found");
}
var user = User.findOneByLogin(userLogin.get());
if (!user.isPresent()) {
throw new AccountResourceException("User could not be found");
}else {
return user.get();
}


}



Expand Down
15 changes: 10 additions & 5 deletions src/main/java/fr/istic/service/StudentResponseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.quarkus.panache.common.Page;
import fr.istic.domain.StudentResponse;
import fr.istic.domain.User;
import fr.istic.service.customdto.StudentResponseNote;
import fr.istic.service.dto.StudentResponseDTO;
import fr.istic.service.mapper.StudentResponseMapper;
Expand All @@ -12,6 +13,7 @@
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;

import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
Expand All @@ -29,15 +31,15 @@ public class StudentResponseService {
Answer2HybridGradedCommentService answer2HybridGradedCommentService;

@Transactional
public StudentResponseDTO persistOrUpdate(StudentResponseDTO studentResponseDTO) {
public StudentResponseDTO persistOrUpdate(StudentResponseDTO studentResponseDTO, User updatedBy) {
log.debug("Request to save StudentResponse : {}", studentResponseDTO);
long l = 0;
if (studentResponseDTO.sheetId != null && studentResponseDTO.questionId != null) {
l = StudentResponse.findStudentResponsesbysheetIdAndquestionId(studentResponseDTO.sheetId,Collections.singletonList( studentResponseDTO.questionId) ).count();
l = StudentResponse.findStudentResponsesbysheetIdAndquestionId(studentResponseDTO.sheetId,studentResponseDTO.questionId ).count();

}
if (l>0) {
StudentResponse sr = StudentResponse.findStudentResponsesbysheetIdAndquestionId(studentResponseDTO.sheetId,Collections.singletonList(studentResponseDTO.questionId)).firstResult();
StudentResponse sr = StudentResponse.findStudentResponsesbysheetIdAndquestionId(studentResponseDTO.sheetId,studentResponseDTO.questionId).firstResult();
var studentResponse = studentResponseMapper.toEntity(studentResponseDTO);
sr.quarternote = studentResponse.quarternote;
sr.star = studentResponse.star;
Expand All @@ -48,12 +50,15 @@ public StudentResponseDTO persistOrUpdate(StudentResponseDTO studentResponseDTO)
sr.gradedcomments.addAll(studentResponse.gradedcomments);
sr.textcomments.clear();
sr.textcomments.addAll(studentResponse.textcomments);
sr.lastModifiedDate = Instant.now();
sr.correctedBy = updatedBy;
studentResponse = StudentResponse.persistOrUpdate(sr);
return studentResponseMapper.toDto(sr);

} else{
var studentResponse = studentResponseMapper.toEntity(studentResponseDTO);

studentResponse.lastModifiedDate = Instant.now();
studentResponse.correctedBy = updatedBy;
studentResponse = StudentResponse.persistOrUpdate(studentResponse);
return studentResponseMapper.toDto(studentResponse);

Expand Down Expand Up @@ -120,7 +125,7 @@ public Paged<StudentResponseDTO> findAllWithEagerRelationships(Page page) {
*/
public Paged<StudentResponseDTO> findStudentResponsesbysheetIdAndquestionId(Page page, Long sheetId, List<Long> questionsId) {
log.debug("Request to get all StudentResponses");
return new Paged<>(StudentResponse.findStudentResponsesbysheetIdAndquestionId(sheetId, questionsId).page(page))
return new Paged<>(StudentResponse.findStudentResponsesbysheetIdAndquestionsId(sheetId, questionsId).page(page))
.map(studentResponse -> studentResponseMapper.toDto((StudentResponse) studentResponse));
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/fr/istic/service/dto/StudentResponseDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import io.quarkus.runtime.annotations.RegisterForReflection;
import java.io.Serializable;
import java.time.Instant;
import java.util.HashSet;
import java.util.Set;

Expand All @@ -24,6 +25,10 @@ public class StudentResponseDTO implements Serializable {
public String questionNumero;
public Long sheetId;
public String sheetName;
public String correctedByInfo;
public String correctedByMail;
public Instant lastModifiedDate;

public Set<TextCommentDTO> textcomments = new HashSet<>();
public Set<GradedCommentDTO> gradedcomments = new HashSet<>();

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/fr/istic/service/mapper/StudentResponseMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ public interface StudentResponseMapper extends EntityMapper<StudentResponseDTO,
@Mapping(source = "sheet.id", target = "sheetId")
@Mapping(source = "sheet.name", target = "sheetName")
@Mapping(source = "quarternote", target = "note", qualifiedByName = "quarternote2note")
@Mapping(source = "correctedBy", target = "correctedByInfo", qualifiedByName = "correctedByTranslation")
@Mapping(source = "correctedBy", target = "correctedByMail", qualifiedByName = "correctedByTranslationMail")
StudentResponseDTO toDto(StudentResponse studentResponse);

@Mapping(target = "comments", ignore = true)
@Mapping(target = "hybridcommentsValues", ignore = true)
@Mapping(target = "correctedBy", ignore = true)
@Mapping(source = "questionId", target = "question")
@Mapping(source = "sheetId", target = "sheet")
@Mapping(source = "note", target = "quarternote", qualifiedByName = "note2quarternote")
Expand All @@ -44,4 +47,22 @@ public static double quarterpoint2point(int quarternote) {
public static int point2quarterpoint(double note) {
return Double.valueOf(note *4).intValue();
}
@Named("correctedByTranslation")
public static String correctedByTranslation(User correctedBy) {
if (correctedBy != null){
return correctedBy.firstName + " " + correctedBy.lastName + " ( " + correctedBy.email + " )";
} else {
return null;
}
}

@Named("correctedByTranslationMail")
public static String correctedByTranslationMail(User correctedBy) {
if (correctedBy != null){
return correctedBy.email;
} else {
return null;
}
}

}
15 changes: 15 additions & 0 deletions src/main/java/fr/istic/web/rest/ExtendedAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.text.DecimalFormat;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
Expand Down Expand Up @@ -2000,6 +2001,10 @@ public int compare(ExamSheet arg0, ExamSheet arg1) {
final List<StudentResponse> responsesForQ = _responsesForQ.stream()
.filter(r -> r.sheet != null && r.sheet.pagemin != -1 && r.sheet.pagemax != -1)
.collect(Collectors.toList());
/* log.error(quest.numero + " " + responsesForQ.size());
if (quest.numero == 9){
responsesForQ.forEach(e-> log.error(""+ e.id +" "+e.sheet.id + " " + e.question.id));
}*/
// Getting the ID of the sheets that have an answer for this question
responsesForQ.sort(new ComparatorImplementation());
QuestionStateDTO qs = q.get(quest.numero.longValue());
Expand Down Expand Up @@ -2682,6 +2687,7 @@ public Response updateStudentResponse4Cluster(ClusterDTO clusterDto, @PathParam(
if (!securityService.canAccess(ctx, examId, Exam.class)) {
return Response.status(403, "Current user cannot access this ressource").build();
}
User correctedBy =securityService.getCurrentLoggedUser(ctx);

Question question = Question.findById(qid);
// ZoneSameCommentDTO dto = new ZoneSameCommentDTO();
Expand Down Expand Up @@ -2766,9 +2772,15 @@ public Response updateStudentResponse4Cluster(ClusterDTO clusterDto, @PathParam(
stToUpdate.textcomments.addAll(textcomments.values().stream()
.filter(gs2 -> answerdtotempalate.textComments.contains(gs2.id))
.collect(Collectors.toList()));
stToUpdate.lastModifiedDate = Instant.now();
stToUpdate.correctedBy = correctedBy;

StudentResponse.persist(stToUpdate);

} else if (question.gradeType == GradeType.HYBRID) {
stToUpdate.lastModifiedDate = Instant.now();
stToUpdate.correctedBy = correctedBy;

StudentResponse.persist(stToUpdate);
Answer2HybridGradedComment.findAllAnswerHybridGradedCommentByAnswerId(
answerdtotempalate.studentResponseId).list().forEach(an1 -> {
Expand All @@ -2785,6 +2797,9 @@ public Response updateStudentResponse4Cluster(ClusterDTO clusterDto, @PathParam(
stToUpdate.gradedcomments.addAll(gradedcomments.values().stream()
.filter(gs2 -> answerdtotempalate.gradedComments.contains(gs2.id))
.collect(Collectors.toList()));

stToUpdate.lastModifiedDate = Instant.now();
stToUpdate.correctedBy =correctedBy;
StudentResponse.persist(stToUpdate);

}
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/fr/istic/web/rest/StudentResponseResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.slf4j.LoggerFactory;

import fr.istic.domain.Authority;
import fr.istic.domain.ExamSheet;
import fr.istic.domain.StudentResponse;
import fr.istic.domain.User;
import fr.istic.security.AuthoritiesConstants;
Expand Down Expand Up @@ -68,13 +69,18 @@ public class StudentResponseResource {
*/
@POST
@RolesAllowed({ AuthoritiesConstants.USER, AuthoritiesConstants.ADMIN })
public Response createStudentResponse(StudentResponseDTO studentResponseDTO, @Context UriInfo uriInfo) {
public Response createStudentResponse(StudentResponseDTO studentResponseDTO, @Context UriInfo uriInfo,@Context final SecurityContext ctx) {
log.debug("REST request to save StudentResponse : {}", studentResponseDTO);
if (studentResponseDTO.id != null) {
throw new BadRequestAlertException("A new studentResponse cannot already have an ID", ENTITY_NAME,
"idexists");
}
var result = studentResponseService.persistOrUpdate(studentResponseDTO);
if (studentResponseDTO.sheetId != null && studentResponseDTO.sheetId.longValue() >0 && !securityService.canAccess(ctx, studentResponseDTO.sheetId, ExamSheet.class)) {
return Response.status(403, "Current user cannot access to this ressource").build();
}

User correctedBy = this.securityService.getCurrentLoggedUser(ctx);
var result = studentResponseService.persistOrUpdate(studentResponseDTO,correctedBy);
var response = Response.created(fromPath(uriInfo.getPath()).path(result.id.toString()).build()).entity(result);
HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, result.id.toString())
.forEach(response::header);
Expand Down Expand Up @@ -102,8 +108,9 @@ public Response updateStudentResponse(StudentResponseDTO studentResponseDTO, @Co
if (!securityService.canAccess(ctx, studentResponseDTO.id, StudentResponse.class)) {
return Response.status(403, "Current user cannot access to this ressource").build();
}
User correctedBy = this.securityService.getCurrentLoggedUser(ctx);

var result = studentResponseService.persistOrUpdate(studentResponseDTO);
var result = studentResponseService.persistOrUpdate(studentResponseDTO,correctedBy);
var response = Response.ok().entity(result);
HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, studentResponseDTO.id.toString())
.forEach(response::header);
Expand Down
Loading

0 comments on commit 53ae9f2

Please sign in to comment.