diff --git a/src/main/java/fr/istic/domain/Answer2HybridGradedComment.java b/src/main/java/fr/istic/domain/Answer2HybridGradedComment.java index a78f93c..31c8ca2 100644 --- a/src/main/java/fr/istic/domain/Answer2HybridGradedComment.java +++ b/src/main/java/fr/istic/domain/Answer2HybridGradedComment.java @@ -100,8 +100,16 @@ public static PanacheQuery findAllWithResponseIdAndH public static PanacheQuery findAllAnswerHybridGradedCommentByAnswerId(long responseId){ return find("select c from Answer2HybridGradedComment c where c.studentResponse.id =?1", responseId); } - public static PanacheQuery findAllAnswerHybridGradedCommentByCommentId(long hybridCommentId){ - return find("select c from Answer2HybridGradedComment c join fetch c.studentResponse st join fetch st.hybridcommentsValues ah2 join fetch ah2.hybridcomments as h2 where c.hybridcomments.id =?1", hybridCommentId); + public static PanacheQuery findAllAnswerHybridGradedCommentByCommentIdWithStepvalueUpperThan0(long hybridcommentId){ + return find("select c from Answer2HybridGradedComment c where c.hybridcomments.id =?1 and c.stepValue >0", hybridcommentId); + } + + public static PanacheQuery findAllAnswerHybridGradedCommentByCommentId(long hybridcommentId){ + return find("select c from Answer2HybridGradedComment c where c.hybridcomments.id =?1", hybridcommentId); + } + + public static PanacheQuery findAllAnswerHybridGradedCommentByCommentIdWithFetchWithStepvalueUpperThan0(long hybridCommentId){ + return find("select c from Answer2HybridGradedComment c join fetch c.studentResponse st join fetch st.hybridcommentsValues ah2 join fetch ah2.hybridcomments as h2 where c.hybridcomments.id =?1 and c.stepValue >0", hybridCommentId); } public static PanacheQuery canAccess(long commentId, String login) { diff --git a/src/main/java/fr/istic/service/HybridGradedCommentService.java b/src/main/java/fr/istic/service/HybridGradedCommentService.java index 6f320b7..54ff02c 100644 --- a/src/main/java/fr/istic/service/HybridGradedCommentService.java +++ b/src/main/java/fr/istic/service/HybridGradedCommentService.java @@ -50,7 +50,7 @@ public HybridGradedCommentDTO persistOrUpdate(HybridGradedCommentDTO hybridGrade } hybridGradedComment = HybridGradedComment.persistOrUpdate(hybridGradedComment); if (shouldUpdate){ - List ans = Answer2HybridGradedComment.findAllAnswerHybridGradedCommentByCommentId(hybridGradedComment.id).list().stream().filter(an3 -> an3.stepValue>0).collect(Collectors.toList()); + 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; diff --git a/src/main/java/fr/istic/web/rest/GradedCommentResource.java b/src/main/java/fr/istic/web/rest/GradedCommentResource.java index b5bf0c9..b6c585c 100644 --- a/src/main/java/fr/istic/web/rest/GradedCommentResource.java +++ b/src/main/java/fr/istic/web/rest/GradedCommentResource.java @@ -5,6 +5,7 @@ import fr.istic.domain.Authority; import fr.istic.domain.GradedComment; import fr.istic.domain.Question; +import fr.istic.domain.StudentResponse; import fr.istic.domain.User; import fr.istic.security.AuthoritiesConstants; import fr.istic.service.GradedCommentService; @@ -185,4 +186,17 @@ public Response getGradedComment(@PathParam("id") Long id, @Context SecurityCont Optional gradedCommentDTO = gradedCommentService.findOne(id); return ResponseUtil.wrapOrNotFound(gradedCommentDTO); } + + @GET + @Path("/countHowManyUse/{id}") + @RolesAllowed({AuthoritiesConstants.USER, AuthoritiesConstants.ADMIN}) + public Response getUsedOfGradedComment(@PathParam("id") Long id, @Context SecurityContext ctx) { + log.debug("REST request to get GradedComment : {}", id); + if (!securityService.canAccess(ctx, id, GradedComment.class )){ + return Response.status(403, "Current user cannot access to this ressource").build(); + } + long l = StudentResponse.findAllByGradedCommentsIds(id).count(); + return Response.ok(Long.valueOf(l)).build(); + } + } diff --git a/src/main/java/fr/istic/web/rest/HybridGradedCommentResource.java b/src/main/java/fr/istic/web/rest/HybridGradedCommentResource.java index 8e10ea2..9242a43 100644 --- a/src/main/java/fr/istic/web/rest/HybridGradedCommentResource.java +++ b/src/main/java/fr/istic/web/rest/HybridGradedCommentResource.java @@ -2,10 +2,13 @@ import static javax.ws.rs.core.UriBuilder.fromPath; +import fr.istic.domain.Answer2HybridGradedComment; import fr.istic.domain.Authority; import fr.istic.domain.GradedComment; import fr.istic.domain.HybridGradedComment; import fr.istic.domain.Question; +import fr.istic.domain.StudentResponse; +import fr.istic.domain.TextComment; import fr.istic.domain.User; import fr.istic.security.AuthoritiesConstants; import fr.istic.service.HybridGradedCommentService; @@ -188,4 +191,16 @@ public Response getHybridGradedComment(@PathParam("id") Long id) { Optional hybridGradedCommentDTO = hybridGradedCommentService.findOne(id); return ResponseUtil.wrapOrNotFound(hybridGradedCommentDTO); } + + @GET + @Path("/countHowManyUse/{id}") + @RolesAllowed({AuthoritiesConstants.USER, AuthoritiesConstants.ADMIN}) + public Response getUsedOfGradedComment(@PathParam("id") Long id, @Context SecurityContext ctx) { + log.debug("REST request to get count HybridGradedCommentUse : {}", id); + if (!securityService.canAccess(ctx, id, HybridGradedComment.class )){ + return Response.status(403, "Current user cannot access to this ressource").build(); + } + long l = Answer2HybridGradedComment.findAllAnswerHybridGradedCommentByCommentIdWithStepvalueUpperThan0(id).count(); + return Response.ok(Long.valueOf(l)).build(); + } } diff --git a/src/main/java/fr/istic/web/rest/TextCommentResource.java b/src/main/java/fr/istic/web/rest/TextCommentResource.java index efdf8ca..9c20ca3 100644 --- a/src/main/java/fr/istic/web/rest/TextCommentResource.java +++ b/src/main/java/fr/istic/web/rest/TextCommentResource.java @@ -14,6 +14,8 @@ import org.slf4j.LoggerFactory; import fr.istic.domain.Authority; +import fr.istic.domain.GradedComment; +import fr.istic.domain.StudentResponse; import fr.istic.domain.TextComment; import fr.istic.domain.User; import fr.istic.security.AuthoritiesConstants; @@ -181,4 +183,18 @@ public Response getTextComment(@PathParam("id") Long id, @Context SecurityContex Optional textCommentDTO = textCommentService.findOne(id); return ResponseUtil.wrapOrNotFound(textCommentDTO); } + + + @GET + @Path("/countHowManyUse/{id}") + @RolesAllowed({AuthoritiesConstants.USER, AuthoritiesConstants.ADMIN}) + public Response getUsedOfGradedComment(@PathParam("id") Long id, @Context SecurityContext ctx) { + log.debug("REST request to get count textcommentUse : {}", id); + if (!securityService.canAccess(ctx, id, TextComment.class )){ + return Response.status(403, "Current user cannot access to this ressource").build(); + } + long l = StudentResponse.findAllByTextCommentsIds(id).count(); + return Response.ok(Long.valueOf(l)).build(); + } + }