Merge pull request #2 from Arimihanta/main

delete comments
This commit is contained in:
ArenMg 2021-05-19 11:21:17 +04:00 committed by GitHub
commit 551b4fa3a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 9 deletions

View File

@ -1,14 +1,12 @@
package fr.lirmm.aren.service;
import java.util.List;
import java.util.*;
import javax.ws.rs.NotFoundException;
import fr.lirmm.aren.model.Comment;
import fr.lirmm.aren.model.TagSet;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
import java.util.function.BiConsumer;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
@ -90,6 +88,51 @@ public class CommentService extends AbstractService<Comment> {
.getResultList());
}
/**
*
* @param commentId
* @return
*/
public void clear(Long commentId) {
Comment comment=this.find(commentId) ;
super.remove(comment);
this.afterRemove(comment) ;
}
public void removeTreeComment(Long id){
System.out.println("id : "+id);
List<Comment> comments = getEntityManager().createNativeQuery("WITH RECURSIVE _comments AS ( "
+ "SELECT id, created,argumentation,end_container,end_offset,hypostases,moderated,opinion,proposed_tags,reformulation,selection,signaled,start_container,start_offset,tags,owner_id,debate_id,parent_id "
+"FROM comments "
+ "WHERE id=?1 "
+"UNION SELECT c.id, c.created,c.argumentation,c.end_container,c.end_offset,c.hypostases,c.moderated,c.opinion,c.proposed_tags,c.reformulation,c.selection,c.signaled,c.start_container,c.start_offset,c.tags,c.owner_id,c.debate_id,c.parent_id "
+"FROM comments c "
+"INNER JOIN _comments _coms ON _coms.id=c.parent_id"
+") SELECT * FROM _comments "
+"ORDER BY id DESC", Comment.class)
.setParameter(1,id)
.getResultList();
if (!comments.isEmpty()) {
//Collections.sort(comments, (c1, c2) -> (c1.getParent()!=null && c2.getParent()!=null)?c1.getParent().getId().compareTo(c1.getParent().getId()):-1);
for(Comment comment : comments){
this.deleteNotification(comment.getId()) ;
this.remove(comment);
}
}
}
private void deleteNotification(Long idComment){
this.transactionBegin();
getEntityManager().createQuery("DELETE FROM Notification notif "
+ "WHERE notif.comment.id = :idComment")
.setParameter("idComment", idComment)
.executeUpdate();
this.commit();
}
/**
*
* @param comment
@ -181,4 +224,5 @@ public class CommentService extends AbstractService<Comment> {
public void updateAllTags() {
this.updateAllTags(null);
}
}

View File

@ -1,23 +1,22 @@
package fr.lirmm.aren.ws.rest;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.*;
import fr.lirmm.aren.service.CommentService;
import fr.lirmm.aren.model.Comment;
import fr.lirmm.aren.model.TagSet;
import fr.lirmm.aren.service.BroadcasterService;
import fr.lirmm.aren.service.HttpRequestService;
import javax.ws.rs.PUT;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.sse.Sse;
import javax.ws.rs.sse.SseEventSink;
import java.util.Set;
/**
* JAX-RS resource class for Comments managment
@ -127,4 +126,11 @@ public class CommentRESTFacade extends AbstractRESTFacade<Comment> {
broadcasterService.broadcastComment(comment);
return comment.getTags();
}
@DELETE
@Path("/delete/{id}")
@PermitAll
public void findTreeById(@PathParam("id") Long id){
commentService.removeTreeComment(id) ;
}
}