Browse Source

dev en cours

rajah 1 year ago
parent
commit
7f4a4a6d62

BIN
.gradle/8.11.1/checksums/checksums.lock


BIN
.gradle/8.11.1/executionHistory/executionHistory.bin


BIN
.gradle/8.11.1/executionHistory/executionHistory.lock


BIN
.gradle/8.11.1/fileHashes/fileHashes.bin


BIN
.gradle/8.11.1/fileHashes/fileHashes.lock


BIN
.gradle/buildOutputCleanup/buildOutputCleanup.lock


BIN
.gradle/file-system.probe


+ 3 - 0
build.gradle

@@ -22,6 +22,9 @@ dependencies {
 
   implementation 'io.hypersistence:hypersistence-utils-hibernate-63:3.9.0'
   implementation 'org.hibernate.validator:hibernate-validator:8.0.2.Final'
+  implementation 'com.google.guava:guava:33.4.0-jre'
+  implementation 'com.twelvemonkeys.imageio:imageio-core:3.12.0'
+  implementation 'net.coobird:thumbnailator:0.4.20'
 	
   runtimeOnly 'org.postgresql:postgresql'
 

+ 4 - 0
src/main/java/fr/triplea/demovote/persistence/dao/ParticipantRepository.java

@@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.NativeQuery;
 import org.springframework.data.repository.query.Param;
 
+import fr.triplea.demovote.persistence.dto.ParticipantOptionList;
 import fr.triplea.demovote.persistence.model.Participant;
 import fr.triplea.demovote.persistence.model.Role;
 
@@ -36,4 +37,7 @@ public interface ParticipantRepository extends JpaRepository<Participant, Intege
   @Override
   void delete(Participant participant);
 
+  @NativeQuery("SELECT DISTINCT p.numero_participant, p.nom, p.prenom, p.pseudonyme FROM vote.participants AS p WHERE p.flag_actif IS TRUE ORDER BY p.pseudonyme ASC, p.nom ASC, p.prenom ASC ")
+  List<ParticipantOptionList> getOptionList();
+
 }

+ 1 - 1
src/main/java/fr/triplea/demovote/persistence/dao/ProductionRepository.java

@@ -12,7 +12,7 @@ import fr.triplea.demovote.persistence.model.Production;
 public interface ProductionRepository extends JpaRepository<Production, Integer> 
 {
 
-  @NativeQuery("SELECT DISTINCT p.* FROM vote.productions AS p WHERE p.numero_production = :id p.flag_actif IS TRUE ")
+  @NativeQuery("SELECT DISTINCT p.* FROM vote.productions AS p WHERE p.numero_production = :id AND p.flag_actif IS TRUE ")
   Production findById(@Param("id") int id);
   
   @NativeQuery("SELECT DISTINCT p.* FROM vote.productions AS p WHERE p.flag_actif IS TRUE ORDER BY p.titre ASC ")

+ 5 - 0
src/main/java/fr/triplea/demovote/persistence/dao/VariableRepository.java

@@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.NativeQuery;
 import org.springframework.data.repository.query.Param;
 
+import fr.triplea.demovote.persistence.dto.VariableTypeOptionList;
 import fr.triplea.demovote.persistence.model.Variable;
 
 public interface VariableRepository extends JpaRepository<Variable, Integer> 
@@ -23,4 +24,8 @@ public interface VariableRepository extends JpaRepository<Variable, Integer>
   @NativeQuery("SELECT DISTINCT v.* FROM vote.variables AS v WHERE v.type = :type AND v.code = :code ")
   Variable findByTypeAndCode(@Param("type") String type, @Param("code") String code);
 
+  @NativeQuery("SELECT DISTINCT v.type FROM vote.variables AS v ORDER BY v.type ASC ")
+  List<VariableTypeOptionList> getTypes();
+
+  
 }

+ 3 - 0
src/main/java/fr/triplea/demovote/persistence/dto/ParticipantOptionList.java

@@ -0,0 +1,3 @@
+package fr.triplea.demovote.persistence.dto;
+
+public record ParticipantOptionList(Integer numeroParticipant, String pseudonyme, String nom, String prenom) { }

+ 3 - 0
src/main/java/fr/triplea/demovote/persistence/dto/VariableTypeOptionList.java

@@ -0,0 +1,3 @@
+package fr.triplea.demovote.persistence.dto;
+
+public record VariableTypeOptionList(String type) { }

+ 45 - 5
src/main/java/fr/triplea/demovote/persistence/model/Production.java

@@ -1,9 +1,17 @@
 package fr.triplea.demovote.persistence.model;
 
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.sql.Types;
 import java.time.LocalDateTime;
+import java.util.Base64;
 import java.util.List;
 
+import javax.imageio.ImageIO;
+import net.coobird.thumbnailator.Thumbnails;
+import net.coobird.thumbnailator.geometry.Positions;
+
 import org.hibernate.annotations.CreationTimestamp;
 import org.hibernate.annotations.JdbcTypeCode;
 import org.hibernate.annotations.Type;
@@ -95,7 +103,7 @@ public class Production
   @Column(name="vignette")
   private byte[] vignette;
   
-  private Integer numeroVersion = 1;
+  private Integer numeroVersion = 0;
   
 
 
@@ -178,11 +186,43 @@ public class Production
   public void setNomArchive(String str) { if (str != null) { this.nomArchive = StringUtils.truncate(str, 256); } }
   public String getNomArchive() { return this.nomArchive; }
   
-  public void setArchive(byte[] a) { this.archive = a; }
-  public byte[] getArchive() { return this.archive; }
+  public void setArchive(String a) 
+  { 
+    if (a.startsWith("data:") && a.contains(",")) { a = a.split(",")[1]; } 
+  
+    try { this.archive = Base64.getDecoder().decode(a); } catch(Exception e) { this.archive = null; }
+  }
+  public String getArchive() { return "data:application/zip;base64," + Base64.getEncoder().encodeToString(this.archive); }
   
-  public void setVignette(byte[] v) { this.vignette = v; }
-  public byte[] getVignette() { return this.vignette; }
+  public void setVignette(String v) 
+  { 
+    String[] s;
+    
+    if (v.startsWith("data:") && v.contains(",")) 
+    { 
+      s = v.split(",");
+      v = s[1]; 
+    } 
+    
+    try 
+    { 
+      byte[] img = Base64.getDecoder().decode(v); 
+      
+      ByteArrayInputStream bais = new ByteArrayInputStream(img);
+      
+      BufferedImage originalImage = ImageIO.read(bais);
+      
+      BufferedImage thumbnail = Thumbnails.of(originalImage).crop(Positions.CENTER).size(300, 300).asBufferedImage();
+      
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      
+      ImageIO.write(thumbnail, "png", baos);
+      
+      this.vignette = baos.toByteArray();
+    } 
+    catch(Exception e) { this.vignette = null; }
+  }
+  public String getVignette() { return "data:image/png;base64," + Base64.getEncoder().encodeToString(this.vignette); }
  
   //@Version
   public void setNumeroVersion(int n) { this.numeroVersion = Integer.valueOf(n); }

+ 9 - 0
src/main/java/fr/triplea/demovote/web/controller/ParticipantController.java

@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import fr.triplea.demovote.persistence.dao.ParticipantRepository;
+import fr.triplea.demovote.persistence.dto.ParticipantOptionList;
 import fr.triplea.demovote.persistence.model.Participant;
 import fr.triplea.demovote.persistence.model.ParticipantModePaiement;
 import fr.triplea.demovote.persistence.model.ParticipantStatus;
@@ -41,6 +42,14 @@ public class ParticipantController
     return participantRepository.findAll(); 
   }
 
+  
+  @GetMapping(value = "/option-list")
+  //@PreAuthorize("hasRole('LISTE_PARTICIPANTS')")
+  public List<ParticipantOptionList> getOptionList() 
+  { 
+    return participantRepository.getOptionList(); 
+  }
+
   @GetMapping(value = "/form/{id}")
   //@PreAuthorize("hasRole('LISTE_PARTICIPANTS')")
   public ResponseEntity<Participant> getForm(@PathVariable int id) 

+ 6 - 3
src/main/java/fr/triplea/demovote/web/controller/ProductionController.java

@@ -38,7 +38,7 @@ public class ProductionController
   private HttpServletRequest request;
 
   
-  @GetMapping(value = "/list", params = {"type"})
+  @GetMapping(value = "/list")
   //@PreAuthorize("hasAnyRole('LISTE_PRODUCTIONS_ADMIN', 'LISTE_PRODUCTIONS_USER')")
   public List<Production> getList(@RequestParam(required = false) String type) 
   { 
@@ -58,13 +58,16 @@ public class ProductionController
 
   @PostMapping(value = "/create")
   //@PreAuthorize("hasAnyRole('LISTE_PRODUCTIONS_ADMIN', 'LISTE_PRODUCTIONS_USER')")
-  public Production create(@RequestBody(required = true) Production production) 
+  public Production create(@RequestBody(required = true) Production production, HttpServletRequest request) 
   { 
     Production found = productionRepository.findById(0);
     
-    if (found== null) { production.setNumeroProduction(null); }
+    if (found == null) { production.setNumeroProduction(null); }
 
+    production.setAdresseIP(new Inet(request.getRemoteAddr()));
+    
     if (production.getType() == null) { production.setType(ProductionType.AUTRE); }
+    
     if (production.getNumeroVersion() == null) { production.setNumeroVersion(1); }
     
     return productionRepository.save(production);

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

@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import fr.triplea.demovote.persistence.dao.VariableRepository;
+import fr.triplea.demovote.persistence.dto.VariableTypeOptionList;
 import fr.triplea.demovote.persistence.model.Variable;
 
 @CrossOrigin(origins = "http://localhost:4200")
@@ -36,9 +37,18 @@ public class VariableController
   //@PreAuthorize("hasRole('LISTE_VARIABLES')")
   public List<Variable> getList(@RequestParam(required = false) String type) 
   { 
-    if (type != null) { return variableRepository.findByType(type); } 
+    if (type == null) { return variableRepository.findAll(); }
+    else 
+    if (type.isBlank()) { return variableRepository.findAll(); }
  
-    return variableRepository.findAll(); 
+    return variableRepository.findByType(type); 
+  }
+  
+  @GetMapping(value = "/option-list")
+  //@PreAuthorize("hasRole('LISTE_VARIABLES')")
+  public List<VariableTypeOptionList> getOptionList() 
+  { 
+    return variableRepository.getTypes(); 
   }
  
   @GetMapping(value = "/form/{id}")