瀏覽代碼

dev en cours

rajah 6 月之前
父節點
當前提交
d532f564aa

+ 14 - 0
src/main/java/fr/triplea/demovote/dao/BulletinRepository.java

@@ -42,5 +42,19 @@ public interface BulletinRepository extends JpaRepository<Bulletin, Integer>
 
   @NativeQuery("SELECT DISTINCT u.* FROM vote.bulletins AS u WHERE u.numero_participant = :participant ")
   List<Bulletin> findByParticipant(@Param("participant") int part_id);
+  
+  @NativeQuery("SELECT DISTINCT COUNT(u.*) AS nombre "
+             + "FROM vote.bulletins AS u "
+             + "WHERE (p.numero_production01 = :numero) "
+             + "   OR (p.numero_production02 = :numero) "
+             + "   OR (p.numero_production03 = :numero) "
+             + "   OR (p.numero_production04 = :numero) "
+             + "   OR (p.numero_production05 = :numero) "
+             + "   OR (p.numero_production06 = :numero) "
+             + "   OR (p.numero_production07 = :numero) "
+             + "   OR (p.numero_production08 = :numero) "
+             + "   OR (p.numero_production09 = :numero) "
+             + "   OR (p.numero_production10 = :numero) ")
+  Integer countIfProductionVoted(@Param("numero") int numeroProduction);
 
 }

+ 1 - 1
src/main/java/fr/triplea/demovote/model/Categorie.java

@@ -105,7 +105,7 @@ public class Categorie
   public void setNumeroOrdre(int o) { this.numeroOrdre = Integer.valueOf(o); }
   public Integer getNumeroOrdre() { return this.numeroOrdre; }
   
-  public void setAvaiable(boolean b) { this.available = Boolean.valueOf(b); }
+  public void setAvailable(boolean b) { this.available = Boolean.valueOf(b); }
   public Boolean getAvailable() { return this.available; }
   @Transient
   public boolean isAvailable() { return (getAvailable().booleanValue()); }

+ 165 - 127
src/main/java/fr/triplea/demovote/web/controller/BulletinController.java

@@ -35,8 +35,6 @@ import jakarta.servlet.http.HttpServletRequest;
 public class BulletinController 
 {
 
-  // TODO : possibilités selon flags de la catégorie
-  // TODO : validation automatique des votes à la clôture du scrutin
   // TODO : résultats
   
   @Autowired
@@ -94,24 +92,29 @@ public class BulletinController
       
       if ((categorie != null) && (participant != null))
       {
-        Bulletin nouveau = new Bulletin(); // création de l'enregistrement si absent
-        
-        nouveau.setCategorie(categorie);
-        nouveau.setParticipant(participant);
-        nouveau.setProduction01(null);
-        nouveau.setProduction02(null);
-        nouveau.setProduction03(null);
-        nouveau.setProduction04(null);
-        nouveau.setProduction05(null);
-        nouveau.setProduction06(null);
-        nouveau.setProduction07(null);
-        nouveau.setProduction08(null);
-        nouveau.setProduction09(null);
-        nouveau.setProduction10(null);
-        
-        bulletinRepository.saveAndFlush(nouveau);
-        
-        nombreChoix = nombreMax;
+        boolean possible = (categorie.isAvailable() == true) && (categorie.isPollable() == true) && (categorie.isComputed() == false) && (categorie.isDisplayable() == false);
+
+        if (possible)
+        {
+          Bulletin nouveau = new Bulletin(); // création de l'enregistrement si absent
+          
+          nouveau.setCategorie(categorie);
+          nouveau.setParticipant(participant);
+          nouveau.setProduction01(null);
+          nouveau.setProduction02(null);
+          nouveau.setProduction03(null);
+          nouveau.setProduction04(null);
+          nouveau.setProduction05(null);
+          nouveau.setProduction06(null);
+          nouveau.setProduction07(null);
+          nouveau.setProduction08(null);
+          nouveau.setProduction09(null);
+          nouveau.setProduction10(null);
+          
+          bulletinRepository.saveAndFlush(nouveau);
+          
+          nombreChoix = nombreMax;
+        }
       }
     }
 
@@ -181,43 +184,50 @@ public class BulletinController
     int numeroParticipant = this.getNumeroUser(authentication);
     
     BulletinShort bulletin = bulletinRepository.findByCategorieAndParticipant(numeroCategorie, numeroParticipant); 
-    
+        
+    Categorie categorie = categorieRepository.findById(numeroCategorie); 
+
     Production production = productionRepository.findByIdLinkedByCategorie(numeroCategorie, numeroProduction);
     
-    if ((bulletin != null) && (production != null)) 
+    if ((bulletin != null) && (production != null) && (categorie != null)) 
     { 
-      int nombreMax = Math.max(1, Math.min(Integer.parseInt(variableRepository.findByTypeAndCode("Résultats", "NOMBRE_CHOIX")), 10));        
+      boolean possible = (categorie.isAvailable() == true) && (categorie.isPollable() == true) && (categorie.isComputed() == false) && (categorie.isDisplayable() == false);
 
-      boolean existe = (bulletin.getPlace(numeroProduction, nombreMax) > 0);
-      
-      if (!existe)
+      if (possible)
       {
-        int place = bulletin.getPlaceLibre(nombreMax);
+        int nombreMax = Math.max(1, Math.min(Integer.parseInt(variableRepository.findByTypeAndCode("Résultats", "NOMBRE_CHOIX")), 10));        
+
+        boolean existe = (bulletin.getPlace(numeroProduction, nombreMax) > 0);
         
-        if (place > 0)
+        if (!existe)
         {
-          Bulletin vote = bulletinRepository.getByCategorieAndParticipant(numeroCategorie, numeroParticipant); 
-
-          switch (place)
+          int place = bulletin.getPlaceLibre(nombreMax);
+          
+          if (place > 0)
           {
-            case 1: vote.setProduction01(production); break;
-            case 2: vote.setProduction02(production); break;
-            case 3: vote.setProduction03(production); break;
-            case 4: vote.setProduction04(production); break;
-            case 5: vote.setProduction05(production); break;
-            case 6: vote.setProduction06(production); break;
-            case 7: vote.setProduction07(production); break;
-            case 8: vote.setProduction08(production); break;
-            case 9: vote.setProduction09(production); break;
-            case 10: vote.setProduction10(production); break;
+            Bulletin vote = bulletinRepository.getByCategorieAndParticipant(numeroCategorie, numeroParticipant); 
+
+            switch (place)
+            {
+              case 1: vote.setProduction01(production); break;
+              case 2: vote.setProduction02(production); break;
+              case 3: vote.setProduction03(production); break;
+              case 4: vote.setProduction04(production); break;
+              case 5: vote.setProduction05(production); break;
+              case 6: vote.setProduction06(production); break;
+              case 7: vote.setProduction07(production); break;
+              case 8: vote.setProduction08(production); break;
+              case 9: vote.setProduction09(production); break;
+              case 10: vote.setProduction10(production); break;
+            }
+            
+            bulletinRepository.saveAndFlush(vote);          
+
+            MessagesTransfer mt = new MessagesTransfer();
+            mt.setInformation(messageSource.getMessage("vote.chosen", null, locale));
+
+            return ResponseEntity.ok(mt);
           }
-          
-          bulletinRepository.saveAndFlush(vote);          
-
-          MessagesTransfer mt = new MessagesTransfer();
-          mt.setInformation(messageSource.getMessage("vote.chosen", null, locale));
-
-          return ResponseEntity.ok(mt);
         }
       }
     }
@@ -235,38 +245,45 @@ public class BulletinController
         
     BulletinShort bulletin = bulletinRepository.findByCategorieAndParticipant(numeroCategorie, numeroParticipant); 
 
+    Categorie categorie = categorieRepository.findById(numeroCategorie); 
+
     Production production = productionRepository.findByIdLinkedByCategorie(numeroCategorie, numeroProduction);
     
-    if ((bulletin != null) && (production != null)) 
+    if ((bulletin != null) && (production != null) && (categorie != null)) 
     { 
-      int nombreMax = Math.max(1, Math.min(Integer.parseInt(variableRepository.findByTypeAndCode("Résultats", "NOMBRE_CHOIX")), 10));        
+      boolean possible = (categorie.isAvailable() == true) && (categorie.isPollable() == true) && (categorie.isComputed() == false) && (categorie.isDisplayable() == false);
 
-      int place = bulletin.getPlace(numeroProduction, nombreMax);
-      
-      if (place > 0)
+      if (possible)
       {
-        Bulletin vote = bulletinRepository.getByCategorieAndParticipant(numeroCategorie, numeroParticipant); 
+        int nombreMax = Math.max(1, Math.min(Integer.parseInt(variableRepository.findByTypeAndCode("Résultats", "NOMBRE_CHOIX")), 10));        
 
-        switch (place) // pas de break; pour continuer les décalages jusqu'à la place 10
-        {
-          case 1: vote.setProduction01(vote.getProduction02()); 
-          case 2: vote.setProduction02(vote.getProduction03()); 
-          case 3: vote.setProduction03(vote.getProduction04()); 
-          case 4: vote.setProduction04(vote.getProduction05()); 
-          case 5: vote.setProduction05(vote.getProduction06()); 
-          case 6: vote.setProduction06(vote.getProduction07()); 
-          case 7: vote.setProduction07(vote.getProduction08()); 
-          case 8: vote.setProduction08(vote.getProduction09()); 
-          case 9: vote.setProduction09(vote.getProduction10()); 
-          case 10: vote.setProduction10(null); 
-        }
+        int place = bulletin.getPlace(numeroProduction, nombreMax);
         
-        bulletinRepository.saveAndFlush(vote);          
-        
-        MessagesTransfer mt = new MessagesTransfer();
-        mt.setInformation(messageSource.getMessage("vote.discarded", null, locale));
+        if (place > 0)
+        {
+          Bulletin vote = bulletinRepository.getByCategorieAndParticipant(numeroCategorie, numeroParticipant); 
 
-        return ResponseEntity.ok(mt);
+          switch (place) // pas de break; pour continuer les décalages jusqu'à la place 10
+          {
+            case 1: vote.setProduction01(vote.getProduction02()); 
+            case 2: vote.setProduction02(vote.getProduction03()); 
+            case 3: vote.setProduction03(vote.getProduction04()); 
+            case 4: vote.setProduction04(vote.getProduction05()); 
+            case 5: vote.setProduction05(vote.getProduction06()); 
+            case 6: vote.setProduction06(vote.getProduction07()); 
+            case 7: vote.setProduction07(vote.getProduction08()); 
+            case 8: vote.setProduction08(vote.getProduction09()); 
+            case 9: vote.setProduction09(vote.getProduction10()); 
+            case 10: vote.setProduction10(null); 
+          }
+          
+          bulletinRepository.saveAndFlush(vote);          
+          
+          MessagesTransfer mt = new MessagesTransfer();
+          mt.setInformation(messageSource.getMessage("vote.discarded", null, locale));
+
+          return ResponseEntity.ok(mt);
+        }
       }
     }
      
@@ -283,40 +300,47 @@ public class BulletinController
     
     BulletinShort bulletin = bulletinRepository.findByCategorieAndParticipant(numeroCategorie, numeroParticipant); 
     
+    Categorie categorie = categorieRepository.findById(numeroCategorie); 
+
     Production production = productionRepository.findByIdLinkedByCategorie(numeroCategorie, numeroProduction);
     
-    if ((bulletin != null) && (production != null)) 
+    if ((bulletin != null) && (production != null) && (categorie != null)) 
     { 
-      int nombreMax = Math.max(1, Math.min(Integer.parseInt(variableRepository.findByTypeAndCode("Résultats", "NOMBRE_CHOIX")), 10));        
+      boolean possible = (categorie.isAvailable() == true) && (categorie.isPollable() == true) && (categorie.isComputed() == false) && (categorie.isDisplayable() == false);
 
-      int place = bulletin.getPlace(numeroProduction, nombreMax);
-      
-      if (place > 1)
+      if (possible)
       {
-        Production precedent = productionRepository.findByIdLinkedByCategorie(numeroCategorie, bulletin.getNumeroProduction(place - 1, nombreMax));
+        int nombreMax = Math.max(1, Math.min(Integer.parseInt(variableRepository.findByTypeAndCode("Résultats", "NOMBRE_CHOIX")), 10));        
 
-        Bulletin vote = bulletinRepository.getByCategorieAndParticipant(numeroCategorie, numeroParticipant); 
+        int place = bulletin.getPlace(numeroProduction, nombreMax);
         
-        switch (place)
+        if (place > 1)
         {
-          case 2: vote.setProduction01(production); vote.setProduction02(precedent); break;
-          case 3: vote.setProduction02(production); vote.setProduction03(precedent); break;
-          case 4: vote.setProduction03(production); vote.setProduction04(precedent); break;
-          case 5: vote.setProduction04(production); vote.setProduction05(precedent); break;
-          case 6: vote.setProduction05(production); vote.setProduction06(precedent); break;
-          case 7: vote.setProduction06(production); vote.setProduction07(precedent); break;
-          case 8: vote.setProduction07(production); vote.setProduction08(precedent); break;
-          case 9: vote.setProduction08(production); vote.setProduction09(precedent); break;
-          case 10: vote.setProduction09(production); vote.setProduction10(precedent); break;
+          Production precedent = productionRepository.findByIdLinkedByCategorie(numeroCategorie, bulletin.getNumeroProduction(place - 1, nombreMax));
+
+          Bulletin vote = bulletinRepository.getByCategorieAndParticipant(numeroCategorie, numeroParticipant); 
+          
+          switch (place)
+          {
+            case 2: vote.setProduction01(production); vote.setProduction02(precedent); break;
+            case 3: vote.setProduction02(production); vote.setProduction03(precedent); break;
+            case 4: vote.setProduction03(production); vote.setProduction04(precedent); break;
+            case 5: vote.setProduction04(production); vote.setProduction05(precedent); break;
+            case 6: vote.setProduction05(production); vote.setProduction06(precedent); break;
+            case 7: vote.setProduction06(production); vote.setProduction07(precedent); break;
+            case 8: vote.setProduction07(production); vote.setProduction08(precedent); break;
+            case 9: vote.setProduction08(production); vote.setProduction09(precedent); break;
+            case 10: vote.setProduction09(production); vote.setProduction10(precedent); break;
+          }
+          
+          bulletinRepository.saveAndFlush(vote);          
         }
         
-        bulletinRepository.saveAndFlush(vote);          
-      }
-      
-      MessagesTransfer mt = new MessagesTransfer();
-      mt.setInformation(messageSource.getMessage("vote.topped", null, locale));
+        MessagesTransfer mt = new MessagesTransfer();
+        mt.setInformation(messageSource.getMessage("vote.topped", null, locale));
 
-      return ResponseEntity.ok(mt);
+        return ResponseEntity.ok(mt);
+      }
     }
      
     return ResponseEntity.notFound().build(); 
@@ -332,40 +356,47 @@ public class BulletinController
     
     BulletinShort bulletin = bulletinRepository.findByCategorieAndParticipant(numeroCategorie, numeroParticipant); 
     
+    Categorie categorie = categorieRepository.findById(numeroCategorie); 
+
     Production production = productionRepository.findByIdLinkedByCategorie(numeroCategorie, numeroProduction);
     
-    if ((bulletin != null) && (production != null)) 
+    if ((bulletin != null) && (production != null) && (categorie != null)) 
     { 
-      int nombreMax = Math.max(1, Math.min(Integer.parseInt(variableRepository.findByTypeAndCode("Résultats", "NOMBRE_CHOIX")), 10));        
+      boolean possible = (categorie.isAvailable() == true) && (categorie.isPollable() == true) && (categorie.isComputed() == false) && (categorie.isDisplayable() == false);
 
-      int place = bulletin.getPlace(numeroProduction, nombreMax);
-      
-      if (place < nombreMax)
+      if (possible)
       {
-        Production suivant = productionRepository.findByIdLinkedByCategorie(numeroCategorie, bulletin.getNumeroProduction(place + 1, nombreMax));
+        int nombreMax = Math.max(1, Math.min(Integer.parseInt(variableRepository.findByTypeAndCode("Résultats", "NOMBRE_CHOIX")), 10));        
 
-        Bulletin vote = bulletinRepository.getByCategorieAndParticipant(numeroCategorie, numeroParticipant); 
+        int place = bulletin.getPlace(numeroProduction, nombreMax);
         
-        switch (place)
+        if (place < nombreMax)
         {
-          case 1: vote.setProduction01(suivant); vote.setProduction02(production); break;
-          case 2: vote.setProduction02(suivant); vote.setProduction03(production); break;
-          case 3: vote.setProduction03(suivant); vote.setProduction04(production); break;
-          case 4: vote.setProduction04(suivant); vote.setProduction05(production); break;
-          case 5: vote.setProduction05(suivant); vote.setProduction06(production); break;
-          case 6: vote.setProduction06(suivant); vote.setProduction07(production); break;
-          case 7: vote.setProduction07(suivant); vote.setProduction08(production); break;
-          case 8: vote.setProduction08(suivant); vote.setProduction09(production); break;
-          case 9: vote.setProduction09(suivant); vote.setProduction10(production); break;
+          Production suivant = productionRepository.findByIdLinkedByCategorie(numeroCategorie, bulletin.getNumeroProduction(place + 1, nombreMax));
+
+          Bulletin vote = bulletinRepository.getByCategorieAndParticipant(numeroCategorie, numeroParticipant); 
+          
+          switch (place)
+          {
+            case 1: vote.setProduction01(suivant); vote.setProduction02(production); break;
+            case 2: vote.setProduction02(suivant); vote.setProduction03(production); break;
+            case 3: vote.setProduction03(suivant); vote.setProduction04(production); break;
+            case 4: vote.setProduction04(suivant); vote.setProduction05(production); break;
+            case 5: vote.setProduction05(suivant); vote.setProduction06(production); break;
+            case 6: vote.setProduction06(suivant); vote.setProduction07(production); break;
+            case 7: vote.setProduction07(suivant); vote.setProduction08(production); break;
+            case 8: vote.setProduction08(suivant); vote.setProduction09(production); break;
+            case 9: vote.setProduction09(suivant); vote.setProduction10(production); break;
+          }
+          
+          bulletinRepository.saveAndFlush(vote);          
         }
-        
-        bulletinRepository.saveAndFlush(vote);          
-      }
 
-      MessagesTransfer mt = new MessagesTransfer();
-      mt.setInformation(messageSource.getMessage("vote.bottomed", null, locale));
+        MessagesTransfer mt = new MessagesTransfer();
+        mt.setInformation(messageSource.getMessage("vote.bottomed", null, locale));
 
-      return ResponseEntity.ok(mt);
+        return ResponseEntity.ok(mt);
+      }
     }
      
     return ResponseEntity.notFound().build(); 
@@ -381,19 +412,26 @@ public class BulletinController
     int numeroParticipant = this.getNumeroUser(authentication);
     
     Bulletin bulletin = bulletinRepository.getByCategorieAndParticipant(numeroCategorie, numeroParticipant); 
+    
+    Categorie categorie = categorieRepository.findById(numeroCategorie); 
    
-    if ((bulletin != null)) 
+    if ((bulletin != null) && (categorie != null)) 
     { 
-      if (bulletin.getProduction01() != null) // au moins une production choisie pour valider
+      boolean possible = (categorie.isAvailable() == true) && (categorie.isPollable() == true) && (categorie.isComputed() == false) && (categorie.isDisplayable() == false);
+
+      if (possible)
       {
-        bulletin.setConfirmed(true);
-        
-        bulletinRepository.saveAndFlush(bulletin);          
-        
-        MessagesTransfer mt = new MessagesTransfer();
-        mt.setInformation(messageSource.getMessage("vote.validated", null, locale));
+        if (bulletin.getProduction01() != null) // au moins une production choisie pour valider
+        {
+          bulletin.setConfirmed(true);
+          
+          bulletinRepository.saveAndFlush(bulletin);          
+          
+          MessagesTransfer mt = new MessagesTransfer();
+          mt.setInformation(messageSource.getMessage("vote.validated", null, locale));
 
-        return ResponseEntity.ok(mt);
+          return ResponseEntity.ok(mt);
+        }
       }
     }
      

+ 59 - 1
src/main/java/fr/triplea/demovote/web/controller/CategorieController.java

@@ -100,7 +100,7 @@ public class CategorieController
       found.setNumeroOrdre(categorie.getNumeroOrdre());
       found.setEnabled(true);
       
-      found.setAvaiable(categorie.isAvailable());
+      found.setAvailable(categorie.isAvailable());
       found.setUploadable(categorie.isUploadable());
       found.setDisplayable(categorie.isDisplayable());
       found.setPollable(categorie.isPollable());
@@ -117,6 +117,64 @@ public class CategorieController
     return ResponseEntity.notFound().build(); 
   }
 
+  @GetMapping(value = "/open-poll/{id}")
+  @PreAuthorize("hasRole('ADMIN')")
+  public ResponseEntity<Object> openPoll(@PathVariable int id, HttpServletRequest request) 
+  { 
+    Locale locale = localeResolver.resolveLocale(request);
+
+    Categorie c = categorieRepository.findById(id);
+    
+    if (c != null)
+    {
+      c.setPollable(true); 
+      
+      categorieRepository.saveAndFlush(c);
+      
+      MessagesTransfer mt = new MessagesTransfer();
+      mt.setAlerte(messageSource.getMessage("categorie.poll.opened", null, locale));
+
+      return ResponseEntity.ok(mt);
+    }      
+    
+    return ResponseEntity.notFound().build(); 
+  }
+
+  @GetMapping(value = "/close-polls")
+  @PreAuthorize("hasRole('ADMIN')")
+  public ResponseEntity<Object> closePolls(HttpServletRequest request) 
+  { 
+    Locale locale = localeResolver.resolveLocale(request);
+
+    List<Categorie> categories = categorieRepository.findAll(0, true);
+    
+    if (categories != null)
+    {
+      if (categories.size() > 0)
+      {
+        for (int i = 0; i < categories.size(); i++)
+        {
+          Categorie c = categories.get(i);
+          
+          c.setPollable(false);
+          
+          // TODO : valider les votes, dépouiller les votes et calculer les résultats pour chaque catégorie
+          
+          c.setComputed(true);
+          
+          categorieRepository.saveAndFlush(c);
+        }
+
+        MessagesTransfer mt = new MessagesTransfer();
+        mt.setAlerte(messageSource.getMessage("categorie.polls.closed", null, locale));
+
+        return ResponseEntity.ok(mt);
+      }
+    }
+    
+    return ResponseEntity.notFound().build(); 
+  }
+
   @DeleteMapping(value = "/delete/{id}")
   @PreAuthorize("hasRole('ADMIN')")
   public ResponseEntity<Object> disableCategorie(@PathVariable int id, HttpServletRequest request) 

+ 1 - 1
src/main/java/fr/triplea/demovote/web/controller/PreferenceController.java

@@ -22,7 +22,7 @@ import fr.triplea.demovote.model.Preference;
 public class PreferenceController 
 {
 
-  // TODO ?
+  // TODO : préférences éventuelles, thèmes, accessibilité ?
 
   @Autowired
   private PreferenceRepository preferenceRepository;

+ 12 - 12
src/main/java/fr/triplea/demovote/web/controller/PresentationController.java

@@ -56,8 +56,6 @@ public class PresentationController
 {
   //@SuppressWarnings("unused") 
   private static final Logger LOG = LoggerFactory.getLogger(PresentationController.class);
-
-  // TODO : raccourci ouvrir/fermer/calculer les votes
   
   @Autowired
   private PresentationRepository presentationRepository;
@@ -95,7 +93,7 @@ public class PresentationController
   { 
     Locale locale = localeResolver.resolveLocale(request);
 
-    List<Categorie> categories = categorieRepository.findAll();
+    List<Categorie> categories = categorieRepository.findAll(0, true);
     
     List<ProductionShort> productions = productionRepository.findLinkedWithoutArchive();
    
@@ -584,9 +582,9 @@ public class PresentationController
 
   @GetMapping(value = "/formfile/{id}")
   @PreAuthorize("hasRole('USER')")
-  public ResponseEntity<PresentationFile> getFormFile(@PathVariable int id)
+  public ResponseEntity<PresentationFile> getFormFile(@PathVariable("id") int numeroProduction)
   { 
-    Presentation found = presentationRepository.findByProduction(id);
+    Presentation found = presentationRepository.findByProduction(numeroProduction);
     
     if (found != null) 
     { 
@@ -598,21 +596,23 @@ public class PresentationController
 
   @PutMapping(value = "/upload/{id}")
   @PreAuthorize("hasRole('ADMIN')")
-  public ResponseEntity<Object> update(@PathVariable int id, @RequestBody(required = true) PresentationFile presentation, HttpServletRequest request) 
+  public ResponseEntity<Object> update(@PathVariable("id") int numeroProduction, @RequestBody(required = true) PresentationFile presentation, HttpServletRequest request) 
   { 
     Locale locale = localeResolver.resolveLocale(request);
 
-    Presentation found = presentationRepository.findByProduction(id);
+    Presentation found = presentationRepository.findByProduction(numeroProduction);
     
-    if (found != null)
+    Categorie categorie = found.getCategorie();
+
+    if ((found != null) && (categorie != null))
     {
-      if (presentation.mediaData() != null)
+      boolean possible = (categorie.isAvailable() == true) && (categorie.isPollable() == false) && (categorie.isComputed() == false) && (categorie.isDisplayable() == false);
+
+      if ((presentation.mediaData() != null) && possible)
       {
         int etat = presentation.etatMedia();
         String nom = presentation.mediaName();
-        
-        // TODO : réinitialiser l'état si une nouvelle archive a été uploadé au niveau de la production
-        
+                
         if (presentation.mediaData() == null) { etat = 0; }
         
         MessagesTransfer mt = new MessagesTransfer();

+ 44 - 15
src/main/java/fr/triplea/demovote/web/controller/ProductionController.java

@@ -36,6 +36,7 @@ import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.servlet.LocaleResolver;
 
+import fr.triplea.demovote.dao.BulletinRepository;
 import fr.triplea.demovote.dao.ParticipantRepository;
 import fr.triplea.demovote.dao.PresentationRepository;
 import fr.triplea.demovote.dao.ProductionRepository;
@@ -68,6 +69,9 @@ public class ProductionController
   @Autowired
   private ParticipantRepository participantRepository;
 
+  @Autowired
+  private BulletinRepository bulletinRepository;
+
   @Autowired
   private LocaleResolver localeResolver;
   
@@ -328,11 +332,11 @@ public class ProductionController
   }
   @PostMapping(value = "/merge-chunks/{id}")
   @PreAuthorize("hasRole('USER')")
-  public ResponseEntity<Object> merge_chunks(@PathVariable int id, @RequestParam String fileName, @RequestParam int lastChunkIndex, @RequestParam String checksum, final Authentication authentication, HttpServletRequest request) 
+  public ResponseEntity<Object> merge_chunks(@PathVariable("id") int numeroProduction, @RequestParam String fileName, @RequestParam int lastChunkIndex, @RequestParam String checksum, final Authentication authentication, HttpServletRequest request) 
   { 
     Locale locale = localeResolver.resolveLocale(request);
 
-    Production found = productionRepository.findById(id);
+    Production found = productionRepository.findById(numeroProduction);
     
     if (found != null)
     {
@@ -344,9 +348,9 @@ public class ProductionController
       {
         MessagesTransfer mt = new MessagesTransfer();
 
-        File dir = new File("../uploads-temp/" + id + "-" + fileName);
+        File dir = new File("../uploads-temp/" + numeroProduction + "-" + fileName);
         
-        String nomLocal = UUID.nameUUIDFromBytes(("" + id + "-" + fileName).getBytes()).toString() + ".zip";
+        String nomLocal = UUID.nameUUIDFromBytes(("" + numeroProduction + "-" + fileName).getBytes()).toString() + ".zip";
 
         File fic = new File("../uploads/" + nomLocal);
 
@@ -392,7 +396,19 @@ public class ProductionController
               found.setNomArchive(fileName);
               found.setNomLocal(nomLocal);
               found.setNumeroVersion(found.getNumeroVersion() + 1);
+             
+              Presentation show = presentationRepository.findByProduction(numeroProduction);
 
+              if (show != null)
+              {
+                // si nouvelle archive uploadée, remet à zéro le média lié à la présentation pour forcer l'actualisation manuelle du média.
+                
+                show.setEtatMedia(0); 
+                show.setDataMedia(null, null);
+                
+                presentationRepository.saveAndFlush(show);
+              }
+              
               succes = true;
             }
             else { LOG.error(messageSource.getMessage("chunk.checksum.failed", new Object[] { fileName, checksum, digestat }, locale)); }
@@ -441,20 +457,33 @@ public class ProductionController
 
       if ((numeroUser == 0) || (found.getParticipant().getNumeroParticipant() == numeroUser))
       {
-        // TODO : pas de suppression logique si présence dans les bulletins
+        boolean absence = (bulletinRepository.countIfProductionVoted(id) == 0);
         
-        found.setEnabled(false); 
-        
-        productionRepository.saveAndFlush(found);
+        if (absence)
+        {
+          found.setEnabled(false); 
+          
+          productionRepository.saveAndFlush(found);
+   
+          Presentation presente = presentationRepository.findByProduction(id);
+          
+          if (presente != null) { presentationRepository.delete(presente); }
+          
+          MessagesTransfer mt = new MessagesTransfer();
+          mt.setInformation(messageSource.getMessage("production.deleted", null, locale));
+
+          return ResponseEntity.ok(mt);
+        }
+        else
+        {
+          found.setEnabled(true); 
  
-        Presentation presente = presentationRepository.findByProduction(id);
-        
-        if (presente != null) { presentationRepository.delete(presente); }
-        
-        MessagesTransfer mt = new MessagesTransfer();
-        mt.setInformation(messageSource.getMessage("production.deleted", null, locale));
+          MessagesTransfer mt = new MessagesTransfer();
+          mt.setInformation(messageSource.getMessage("production.indelible", null, locale));
 
-        return ResponseEntity.ok(mt);
+          return ResponseEntity.ok(mt);
+        }
+        
       }
     }      
     

+ 1 - 0
src/main/resources/langs/messages_en.properties

@@ -20,6 +20,7 @@ production.created=The new production was correctly created.
 production.updated=The production informations were updated.
 production.file.updated=The production archive was updated.
 production.deleted=This production is removed from the list.
+production.indelible=This production is indelible (people has voted for it).
 production.linked=This production was added to this compo.
 production.unlinked=This production was removed from this compo.
 production.topped=This production was moved top in this compo list.

+ 1 - 0
src/main/resources/langs/messages_fr.properties

@@ -20,6 +20,7 @@ production.created=La nouvelle production a bien 
 production.updated=Les informations de cette production ont bien été mises à jour.
 production.file.updated=L'archive de cette production a bien été mise à jour.
 production.deleted=La production a été retirée des enregistrements.
+production.indelible=La production n'est pas supprimable (présence de votes).
 production.linked=La production a été ajoutée dans la catégorie.
 production.unlinked=La production a été retirée de la catégorie.
 production.topped=La production a été avancée dans la catégorie.