Jean-Francois Leveque

Formulaire création éditeur OK (à 2 TODO près) en amont enregistrement dans la base

1 package org.legrog.entities; 1 package org.legrog.entities;
2 2
3 import javax.persistence.*; 3 import javax.persistence.*;
4 +import java.sql.Timestamp;
4 import java.util.Set; 5 import java.util.Set;
5 6
6 @Entity 7 @Entity
...@@ -19,6 +20,8 @@ public class Publisher /* extends org.roliste.data.DbLinkableEntity */ { ...@@ -19,6 +20,8 @@ public class Publisher /* extends org.roliste.data.DbLinkableEntity */ {
19 @OneToOne 20 @OneToOne
20 private User activeValidator; 21 private User activeValidator;
21 22
23 + private Timestamp validationDateTime;
24 +
22 @OneToMany(mappedBy = "publisher") 25 @OneToMany(mappedBy = "publisher")
23 private Set<PublisherRevision> revisions; 26 private Set<PublisherRevision> revisions;
24 27
...@@ -53,4 +56,17 @@ public class Publisher /* extends org.roliste.data.DbLinkableEntity */ { ...@@ -53,4 +56,17 @@ public class Publisher /* extends org.roliste.data.DbLinkableEntity */ {
53 public void setActiveValidator(User activeValidator) { 56 public void setActiveValidator(User activeValidator) {
54 this.activeValidator = activeValidator; 57 this.activeValidator = activeValidator;
55 } 58 }
59 +
60 + public Timestamp getValidationDateTime() {
61 + return validationDateTime;
62 + }
63 +
64 + public void setValidationDateTime(Timestamp validationDateTime) {
65 + this.validationDateTime = validationDateTime;
66 + }
67 +
68 + @Override
69 + public String toString() {
70 + return "PUBLISHER_ID = " + publisherId + ", Active Revision = " + activeRevision + ", Validator = " + activeValidator + ", Validation DateTime = " + validationDateTime;
71 + }
56 } 72 }
......
...@@ -147,4 +147,14 @@ public class PublisherRevision { ...@@ -147,4 +147,14 @@ public class PublisherRevision {
147 public void setPublisherRevisionAuthor(User publisherRevisionAuthor) { 147 public void setPublisherRevisionAuthor(User publisherRevisionAuthor) {
148 this.publisherRevisionAuthor = publisherRevisionAuthor; 148 this.publisherRevisionAuthor = publisherRevisionAuthor;
149 } 149 }
150 +
151 + @Override
152 + public String toString() {
153 + return "PUBLISHER_REVISION_ID = " + publisherRevisionId + ", Name = " + publisherName + ", St Address = " +
154 + publisherStreetAddress + ", CP = " + publisherPostalCode + ", BP = " + publisherPostOfficeBoxNumber +
155 + ", Region = " + publisherAddressRegion + ", Ville = " + publisherAddressLocality + ", Pays = " +
156 + publisherAddressCountry + ", Telephone = " + publisherTelephone + ", email = " + publisherEmail +
157 + ", URL = " + publisherURL + ", actif = " + publisherActive + ", History = " + publisherHistory +
158 + ", Revision Author = " + publisherRevisionAuthor + ", Revision DateTime = " + publisherRevisionDatetime;
159 + }
150 } 160 }
...\ No newline at end of file ...\ No newline at end of file
......
1 package org.legrog.presentation; 1 package org.legrog.presentation;
2 2
3 import org.legrog.application.SharedService; 3 import org.legrog.application.SharedService;
4 +import org.legrog.application.UserService;
4 import org.legrog.entities.Country; 5 import org.legrog.entities.Country;
6 +import org.legrog.entities.Publisher;
7 +import org.legrog.entities.PublisherRevision;
5 import org.legrog.entities.User; 8 import org.legrog.entities.User;
9 +import org.slf4j.Logger;
10 +import org.slf4j.LoggerFactory;
6 11
7 import javax.annotation.PostConstruct; 12 import javax.annotation.PostConstruct;
8 import javax.enterprise.context.RequestScoped; 13 import javax.enterprise.context.RequestScoped;
9 import javax.inject.Inject; 14 import javax.inject.Inject;
10 import javax.inject.Named; 15 import javax.inject.Named;
11 import java.sql.Timestamp; 16 import java.sql.Timestamp;
17 +import java.util.HashSet;
12 import java.util.List; 18 import java.util.List;
19 +import java.util.Random;
13 20
14 @Named 21 @Named
15 @RequestScoped 22 @RequestScoped
16 public class AddPublisherBean { 23 public class AddPublisherBean {
24 + Logger logger = LoggerFactory.getLogger(getClass());
25 +
17 @Inject 26 @Inject
18 private SharedService sharedService; 27 private SharedService sharedService;
28 + @Inject
29 + private UserService userService;
19 30
20 private String publisherName; 31 private String publisherName;
21 private String publisherStreetAddress; 32 private String publisherStreetAddress;
...@@ -35,6 +46,37 @@ public class AddPublisherBean { ...@@ -35,6 +46,37 @@ public class AddPublisherBean {
35 private List<Country> availableCountries; 46 private List<Country> availableCountries;
36 47
37 public String add() { 48 public String add() {
49 + logger.info("add");
50 + Publisher publisher = new Publisher();
51 + PublisherRevision publisherRevision = new PublisherRevision();
52 + HashSet<PublisherRevision> publisherRevisions = new HashSet<PublisherRevision>();
53 + publisherRevisions.add(publisherRevision);
54 + publisher.setRevisions(publisherRevisions);
55 + logger.info(publisher.toString());
56 + publisherRevision.setPublisherActive(publisherActive);
57 + publisherRevision.setPublisherAddressCountry(publisherAddressCountry);
58 + publisherRevision.setPublisherAddressLocality(publisherAddressLocality);
59 + publisherRevision.setPublisherAddressRegion(publisherAddressRegion);
60 + publisherRevision.setPublisherAddressLocality(publisherAddressLocality);
61 + publisherRevision.setPublisherEmail(publisherEmail);
62 + publisherRevision.setPublisherHistory(publisherHistory);
63 + publisherRevision.setPublisherName(publisherName);
64 + publisherRevision.setPublisherPostalCode(publisherPostalCode);
65 + publisherRevision.setPublisherPostOfficeBoxNumber(publisherPostOfficeBoxNumber);
66 + publisherRevision.setPublisherStreetAddress(publisherStreetAddress);
67 + publisherRevision.setPublisherTelephone(publisherTelephone);
68 + publisherRevision.setPublisherURL(publisherURL);
69 +
70 + // TODO Remplacer Timestamp de date horloge interne par celui de date locale
71 + publisherRevision.setPublisherRevisionDatetime(new Timestamp(System.currentTimeMillis()));
72 +
73 + // TODO Remplacer l'astuce par une vraie récupération de l'utilisateur
74 + List<User> users = userService.getAllUsers();
75 + Random random = new Random();
76 + User user = users.get(random.nextInt(users.size()));
77 + // End TODO
78 + publisherRevision.setPublisherRevisionAuthor(user);
79 + logger.info(publisherRevision.toString());
38 return "success"; 80 return "success";
39 } 81 }
40 82
......