mirror of
https://github.com/ArenMg/aren.git
synced 2024-11-21 08:00:52 +00:00
delete themes
This commit is contained in:
parent
44d74afc91
commit
5e4fc84381
4 changed files with 60 additions and 6 deletions
|
@ -57,7 +57,7 @@ Uncomment the two following lines to allow the application to build the whole da
|
|||
|
||||
<!--property name="hibernate.hbm2ddl.auto" value="drop-and-create"/-->
|
||||
<!--property name="hibernate.hbm2ddl.import_files" value="META-INF/init.sql"/-->
|
||||
Restart your webserver.
|
||||
####Restart your webserver.
|
||||
|
||||
Uncomment the line
|
||||
`<property name="hibernate.hbm2ddl.auto" value="update"/>`
|
||||
|
|
|
@ -55,6 +55,4 @@ public class FDChoiceService extends AbstractService<FDChoice> {
|
|||
}
|
||||
return results.get(0);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
package fr.lirmm.aren.service.framadate;
|
||||
import fr.lirmm.aren.model.Comment;
|
||||
import fr.lirmm.aren.model.framadate.FDChoice;
|
||||
import fr.lirmm.aren.model.framadate.FDTheme;
|
||||
import fr.lirmm.aren.service.AbstractService;
|
||||
|
||||
|
@ -45,4 +47,50 @@ public class FDThemeService extends AbstractService<FDTheme> {
|
|||
}
|
||||
return results.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fdThemeId
|
||||
*/
|
||||
public void clear(Long fdThemeId) {
|
||||
this.transactionBegin();
|
||||
List<FDChoice> choices = getEntityManager().createQuery("SELECT c "
|
||||
+ "FROM FDChoice c "
|
||||
+ "WHERE c.themeId.id = :fdThemeId ", FDChoice.class)
|
||||
.setParameter("fdThemeId", fdThemeId)
|
||||
.getResultList();
|
||||
if (!choices.isEmpty()) {
|
||||
for(FDChoice choice : choices){
|
||||
this.clearVotes(choice.getId());
|
||||
}
|
||||
}
|
||||
try{
|
||||
getEntityManager().createQuery("DELETE FROM FDChoice fdChoice "
|
||||
+ "WHERE fdChoice.themeId.id = :fdThemeId")
|
||||
.setParameter("fdThemeId", fdThemeId)
|
||||
.executeUpdate();
|
||||
|
||||
getEntityManager().createQuery("DELETE FROM FDTheme fdTheme "
|
||||
+ "WHERE fdTheme.id = :fdThemeId")
|
||||
.setParameter("fdThemeId", fdThemeId)
|
||||
.executeUpdate();
|
||||
}catch(Exception ex){
|
||||
System.err.println("Erreur : "+ex.getMessage());
|
||||
}
|
||||
|
||||
this.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fdChoiceId
|
||||
*/
|
||||
public void clearVotes(Long fdChoiceId) {
|
||||
this.transactionBegin();
|
||||
getEntityManager().createQuery("DELETE FROM FDVote fdVote "
|
||||
+ "WHERE fdVote.subThemeId.id = :fdChoiceId")
|
||||
.setParameter("fdChoiceId", fdChoiceId)
|
||||
.executeUpdate();
|
||||
this.commit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,9 @@ import javax.annotation.security.PermitAll;
|
|||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import java.util.Set;
|
||||
|
||||
@RequestScoped
|
||||
|
@ -51,10 +53,16 @@ public class FDThemeRESTFacade extends AbstractRESTFacade<FDTheme>{
|
|||
return fdThemeService.findAll(withChoices, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Remove all the choices and votes of a theme
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@DELETE
|
||||
@Path("delete/{id}")
|
||||
@RolesAllowed({"ADMIN"})
|
||||
public void remove(Long id) {
|
||||
super.remove(id);
|
||||
public void clear(@PathParam("id") Long id) {
|
||||
fdThemeService.clear(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue