mirror of
https://github.com/ArenMg/aren.git
synced 2024-11-22 00:20:52 +00:00
delete comments
This commit is contained in:
parent
b02b208af0
commit
057a034780
2 changed files with 59 additions and 9 deletions
|
@ -1,14 +1,12 @@
|
||||||
package fr.lirmm.aren.service;
|
package fr.lirmm.aren.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
|
||||||
import javax.ws.rs.NotFoundException;
|
import javax.ws.rs.NotFoundException;
|
||||||
|
|
||||||
import fr.lirmm.aren.model.Comment;
|
import fr.lirmm.aren.model.Comment;
|
||||||
import fr.lirmm.aren.model.TagSet;
|
import fr.lirmm.aren.model.TagSet;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import javax.enterprise.context.ApplicationScoped;
|
import javax.enterprise.context.ApplicationScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -90,6 +88,51 @@ public class CommentService extends AbstractService<Comment> {
|
||||||
.getResultList());
|
.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
|
* @param comment
|
||||||
|
@ -181,4 +224,5 @@ public class CommentService extends AbstractService<Comment> {
|
||||||
public void updateAllTags() {
|
public void updateAllTags() {
|
||||||
this.updateAllTags(null);
|
this.updateAllTags(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,22 @@
|
||||||
package fr.lirmm.aren.ws.rest;
|
package fr.lirmm.aren.ws.rest;
|
||||||
|
|
||||||
|
import javax.annotation.security.PermitAll;
|
||||||
import javax.annotation.security.RolesAllowed;
|
import javax.annotation.security.RolesAllowed;
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.Path;
|
|
||||||
|
|
||||||
import fr.lirmm.aren.service.CommentService;
|
import fr.lirmm.aren.service.CommentService;
|
||||||
import fr.lirmm.aren.model.Comment;
|
import fr.lirmm.aren.model.Comment;
|
||||||
import fr.lirmm.aren.model.TagSet;
|
import fr.lirmm.aren.model.TagSet;
|
||||||
import fr.lirmm.aren.service.BroadcasterService;
|
import fr.lirmm.aren.service.BroadcasterService;
|
||||||
import fr.lirmm.aren.service.HttpRequestService;
|
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.Context;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.sse.Sse;
|
import javax.ws.rs.sse.Sse;
|
||||||
import javax.ws.rs.sse.SseEventSink;
|
import javax.ws.rs.sse.SseEventSink;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JAX-RS resource class for Comments managment
|
* JAX-RS resource class for Comments managment
|
||||||
|
@ -127,4 +126,11 @@ public class CommentRESTFacade extends AbstractRESTFacade<Comment> {
|
||||||
broadcasterService.broadcastComment(comment);
|
broadcasterService.broadcastComment(comment);
|
||||||
return comment.getTags();
|
return comment.getTags();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DELETE
|
||||||
|
@Path("/delete/{id}")
|
||||||
|
@PermitAll
|
||||||
|
public void findTreeById(@PathParam("id") Long id){
|
||||||
|
commentService.removeTreeComment(id) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue