Merge pull request #1 from Arimihanta/main

delete themes sondage
This commit is contained in:
ArenMg 2021-05-10 08:45:26 +03:00 committed by GitHub
commit 9e91bbfcf5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 6 deletions

View file

@ -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"/>`

View file

@ -55,6 +55,4 @@ public class FDChoiceService extends AbstractService<FDChoice> {
}
return results.get(0);
}
}

View file

@ -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();
}
}

View file

@ -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