Jean-Francois Leveque

https://tree.taiga.io/project/jr-utily-grog-v3/us/44 Implementer l'historisation pour les éditeurs

1 package org.legrog.application; 1 package org.legrog.application;
2 2
3 import org.legrog.entities.Publisher; 3 import org.legrog.entities.Publisher;
4 +import org.legrog.entities.PublisherRevision;
4 5
5 import java.util.List; 6 import java.util.List;
6 7
7 public interface PublisherService { 8 public interface PublisherService {
8 void addPublisher(Publisher publisher); 9 void addPublisher(Publisher publisher);
9 10
11 + void addRevisionToPublisher(Publisher publisher, PublisherRevision publisherRevision);
12 +
10 List<Publisher> getAllPublishers(); 13 List<Publisher> getAllPublishers();
11 } 14 }
......
...@@ -3,10 +3,12 @@ package org.legrog.application; ...@@ -3,10 +3,12 @@ package org.legrog.application;
3 3
4 import org.legrog.entities.Publisher; 4 import org.legrog.entities.Publisher;
5 import org.legrog.entities.PublisherRepository; 5 import org.legrog.entities.PublisherRepository;
6 +import org.legrog.entities.PublisherRevision;
6 7
7 import javax.ejb.Stateless; 8 import javax.ejb.Stateless;
8 import javax.inject.Inject; 9 import javax.inject.Inject;
9 import java.util.List; 10 import java.util.List;
11 +import java.util.Set;
10 12
11 @Stateless 13 @Stateless
12 public class PublisherServiceSpring implements PublisherService { 14 public class PublisherServiceSpring implements PublisherService {
...@@ -17,6 +19,14 @@ public class PublisherServiceSpring implements PublisherService { ...@@ -17,6 +19,14 @@ public class PublisherServiceSpring implements PublisherService {
17 publisherRepository.save(publisher); 19 publisherRepository.save(publisher);
18 } 20 }
19 21
22 + public void addRevisionToPublisher(Publisher publisher, PublisherRevision publisherRevision) {
23 + Set<PublisherRevision> publisherRevisionSet = publisher.getRevisions();
24 + publisherRevisionSet.add(publisherRevision);
25 + publisher.setRevisions(publisherRevisionSet);
26 + publisherRevision.setPublisher(publisher);
27 + publisherRepository.save(publisher);
28 + }
29 +
20 public List<Publisher> getAllPublishers() { 30 public List<Publisher> getAllPublishers() {
21 return publisherRepository.findAll(); 31 return publisherRepository.findAll();
22 } 32 }
......
...@@ -22,7 +22,7 @@ public class Publisher /* extends org.roliste.data.DbLinkableEntity */ { ...@@ -22,7 +22,7 @@ public class Publisher /* extends org.roliste.data.DbLinkableEntity */ {
22 22
23 private Timestamp validationDateTime; 23 private Timestamp validationDateTime;
24 24
25 - @OneToMany(mappedBy = "publisher") 25 + @OneToMany(mappedBy = "publisher", fetch = FetchType.EAGER)
26 private Set<PublisherRevision> revisions; 26 private Set<PublisherRevision> revisions;
27 27
28 public int getPublisherId() { 28 public int getPublisherId() {
......
...@@ -158,4 +158,12 @@ public class PublisherRevision { ...@@ -158,4 +158,12 @@ public class PublisherRevision {
158 ", URL = " + publisherURL + ", actif = " + publisherActive + ", History = " + publisherHistory + 158 ", URL = " + publisherURL + ", actif = " + publisherActive + ", History = " + publisherHistory +
159 ", Revision Author = " + publisherRevisionAuthor + ", Revision DateTime = " + publisherRevisionDatetime; 159 ", Revision Author = " + publisherRevisionAuthor + ", Revision DateTime = " + publisherRevisionDatetime;
160 } 160 }
161 +
162 + public Publisher getPublisher() {
163 + return publisher;
164 + }
165 +
166 + public void setPublisher(Publisher publisher) {
167 + this.publisher = publisher;
168 + }
161 } 169 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -59,11 +59,11 @@ public class AddPublisherBean { ...@@ -59,11 +59,11 @@ public class AddPublisherBean {
59 publisherRevisions.add(publisherRevision); 59 publisherRevisions.add(publisherRevision);
60 publisher.setRevisions(publisherRevisions); 60 publisher.setRevisions(publisherRevisions);
61 logger.info(publisher.toString()); 61 logger.info(publisher.toString());
62 + publisherRevision.setPublisher(publisher);
62 publisherRevision.setPublisherActive(publisherActive); 63 publisherRevision.setPublisherActive(publisherActive);
63 publisherRevision.setPublisherAddressCountry(publisherAddressCountry); 64 publisherRevision.setPublisherAddressCountry(publisherAddressCountry);
64 publisherRevision.setPublisherAddressLocality(publisherAddressLocality); 65 publisherRevision.setPublisherAddressLocality(publisherAddressLocality);
65 publisherRevision.setPublisherAddressRegion(publisherAddressRegion); 66 publisherRevision.setPublisherAddressRegion(publisherAddressRegion);
66 - publisherRevision.setPublisherAddressLocality(publisherAddressLocality);
67 publisherRevision.setPublisherEmail(publisherEmail); 67 publisherRevision.setPublisherEmail(publisherEmail);
68 publisherRevision.setPublisherHistory(publisherHistory); 68 publisherRevision.setPublisherHistory(publisherHistory);
69 publisherRevision.setPublisherName(publisherName); 69 publisherRevision.setPublisherName(publisherName);
...@@ -82,8 +82,8 @@ public class AddPublisherBean { ...@@ -82,8 +82,8 @@ public class AddPublisherBean {
82 // End TODO 82 // End TODO
83 publisherRevision.setPublisherRevisionAuthor(user); 83 publisherRevision.setPublisherRevisionAuthor(user);
84 logger.info(publisherRevision.toString()); 84 logger.info(publisherRevision.toString());
85 - publisherRevisionService.addPublisherRevision(publisherRevision);
86 publisherService.addPublisher(publisher); 85 publisherService.addPublisher(publisher);
86 + publisherRevisionService.addPublisherRevision(publisherRevision);
87 // Test de récupération de l'Id 87 // Test de récupération de l'Id
88 logger.info(publisherRevision.toString()); 88 logger.info(publisherRevision.toString());
89 return "success"; 89 return "success";
......
1 package org.legrog.presentation; 1 package org.legrog.presentation;
2 2
3 import org.legrog.application.PublisherRevisionService; 3 import org.legrog.application.PublisherRevisionService;
4 +import org.legrog.application.PublisherService;
4 import org.legrog.application.SharedService; 5 import org.legrog.application.SharedService;
6 +import org.legrog.application.UserService;
5 import org.legrog.entities.Country; 7 import org.legrog.entities.Country;
8 +import org.legrog.entities.Publisher;
6 import org.legrog.entities.PublisherRevision; 9 import org.legrog.entities.PublisherRevision;
7 import org.legrog.entities.User; 10 import org.legrog.entities.User;
8 import org.slf4j.Logger; 11 import org.slf4j.Logger;
...@@ -14,7 +17,10 @@ import javax.inject.Inject; ...@@ -14,7 +17,10 @@ import javax.inject.Inject;
14 import javax.inject.Named; 17 import javax.inject.Named;
15 import java.io.Serializable; 18 import java.io.Serializable;
16 import java.sql.Timestamp; 19 import java.sql.Timestamp;
20 +import java.util.Date;
17 import java.util.List; 21 import java.util.List;
22 +import java.util.Random;
23 +import java.util.Set;
18 24
19 @Named 25 @Named
20 @ViewScoped 26 @ViewScoped
...@@ -22,8 +28,12 @@ public class PublisherRevisionView implements Serializable { ...@@ -22,8 +28,12 @@ public class PublisherRevisionView implements Serializable {
22 Logger logger = LoggerFactory.getLogger(getClass()); 28 Logger logger = LoggerFactory.getLogger(getClass());
23 29
24 @Inject 30 @Inject
31 + private PublisherService publisherService;
32 + @Inject
25 PublisherRevisionService publisherRevisionService; 33 PublisherRevisionService publisherRevisionService;
26 @Inject 34 @Inject
35 + UserService userService;
36 + @Inject
27 private SharedService sharedService; 37 private SharedService sharedService;
28 38
29 private boolean editMode; 39 private boolean editMode;
...@@ -44,6 +54,7 @@ public class PublisherRevisionView implements Serializable { ...@@ -44,6 +54,7 @@ public class PublisherRevisionView implements Serializable {
44 private String publisherHistory; 54 private String publisherHistory;
45 private User publisherRevisionAuthor; 55 private User publisherRevisionAuthor;
46 private Timestamp publisherRevisionDatetime; 56 private Timestamp publisherRevisionDatetime;
57 + private Publisher publisher;
47 58
48 // Table de codification 59 // Table de codification
49 private List<Country> availableCountries; 60 private List<Country> availableCountries;
...@@ -65,6 +76,36 @@ public class PublisherRevisionView implements Serializable { ...@@ -65,6 +76,36 @@ public class PublisherRevisionView implements Serializable {
65 return editMode; 76 return editMode;
66 } 77 }
67 78
79 + public void update() {
80 + PublisherRevision publisherRevision = new PublisherRevision();
81 +
82 + publisherRevision.setPublisherActive(publisherActive);
83 + publisherRevision.setPublisherAddressCountry(publisherAddressCountry);
84 + publisherRevision.setPublisherAddressLocality(publisherAddressLocality);
85 + publisherRevision.setPublisherAddressRegion(publisherAddressRegion);
86 + publisherRevision.setPublisherEmail(publisherEmail);
87 + publisherRevision.setPublisherHistory(publisherHistory);
88 + publisherRevision.setPublisherName(publisherName);
89 + publisherRevision.setPublisherPostalCode(publisherPostalCode);
90 + publisherRevision.setPublisherPostOfficeBoxNumber(publisherPostOfficeBoxNumber);
91 + publisherRevision.setPublisherStreetAddress(publisherStreetAddress);
92 + publisherRevision.setPublisherTelephone(publisherTelephone);
93 + publisherRevision.setPublisherURL(publisherURL);
94 +
95 + publisherRevision.setPublisherRevisionDatetime(new Timestamp(new Date().getTime()));
96 +
97 + // TODO Remplacer l'astuce par une vraie récupération de l'utilisateur
98 + List<User> users = userService.getAllUsers();
99 + Random random = new Random();
100 + User user = users.get(random.nextInt(users.size()));
101 + // End TODO
102 + publisherRevision.setPublisherRevisionAuthor(user);
103 +
104 + publisherService.addRevisionToPublisher(publisher, publisherRevision);
105 + publisherRevisionService.addPublisherRevision(publisherRevision);
106 + editMode = false;
107 + }
108 +
68 public void loadData() { 109 public void loadData() {
69 logger.debug("publisherRevisionId = {}", this.publisherRevisionId); 110 logger.debug("publisherRevisionId = {}", this.publisherRevisionId);
70 111
...@@ -86,7 +127,9 @@ public class PublisherRevisionView implements Serializable { ...@@ -86,7 +127,9 @@ public class PublisherRevisionView implements Serializable {
86 publisherHistory = publisherRevision.getPublisherHistory(); 127 publisherHistory = publisherRevision.getPublisherHistory();
87 publisherRevisionAuthor = publisherRevision.getPublisherRevisionAuthor(); 128 publisherRevisionAuthor = publisherRevision.getPublisherRevisionAuthor();
88 publisherRevisionDatetime = publisherRevision.getPublisherRevisionDatetime(); 129 publisherRevisionDatetime = publisherRevision.getPublisherRevisionDatetime();
130 + publisher = publisherRevision.getPublisher();
89 131
132 + logger.debug("Found a publisher : {}", publisher.toString());
90 133
91 // Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); 134 // Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
92 // 135 //
......
...@@ -43,6 +43,11 @@ ...@@ -43,6 +43,11 @@
43 <h:outputText value="Add Publisher"/> 43 <h:outputText value="Add Publisher"/>
44 </h:commandLink> 44 </h:commandLink>
45 </li> 45 </li>
46 + <li>
47 + <h:commandLink action="listPublisherRevisions">
48 + <h:outputText value="List Publisher Revisions"/>
49 + </h:commandLink>
50 + </li>
46 </ul> 51 </ul>
47 </h:form> 52 </h:form>
48 </body> 53 </body>
......
...@@ -6,15 +6,25 @@ ...@@ -6,15 +6,25 @@
6 xmlns:ui="http://xmlns.jcp.org/jsf/facelets" 6 xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
7 xmlns:f="http://xmlns.jcp.org/jsf/core"> 7 xmlns:f="http://xmlns.jcp.org/jsf/core">
8 <h:body> 8 <h:body>
9 + <h:form>
10 + <h:commandLink action="home">
11 + <h:outputText value="Menu principal"/>
12 + </h:commandLink>
13 + </h:form>
14 +
9 <h:outputText rendered="#{listPublisherRevisionsBean.publisherRevisions.isEmpty()}">Liste des révisions est vide</h:outputText> 15 <h:outputText rendered="#{listPublisherRevisionsBean.publisherRevisions.isEmpty()}">Liste des révisions est vide</h:outputText>
10 <h:dataTable value="#{listPublisherRevisionsBean.publisherRevisions}" var="revision"> 16 <h:dataTable value="#{listPublisherRevisionsBean.publisherRevisions}" var="revision">
11 <h:column> 17 <h:column>
12 - <f:facet name="header">Visualiser<!--ou Modifier--></f:facet> 18 + <f:facet name="header">Visualiser ou Modifier</f:facet>
13 - <h:link outcome="view">Visualiser<!--ou Modifier--> 19 + <h:link outcome="view">Visualiser ou Modifier Version
14 <f:param name="publisherRevisionId" value="#{revision.publisherRevisionId}"/> 20 <f:param name="publisherRevisionId" value="#{revision.publisherRevisionId}"/>
15 </h:link> 21 </h:link>
16 </h:column> 22 </h:column>
17 <h:column> 23 <h:column>
24 + <f:facet name="header">Editeur</f:facet>
25 + #{revision.publisher.publisherId}
26 + </h:column>
27 + <h:column>
18 <f:facet name="header">Name</f:facet> 28 <f:facet name="header">Name</f:facet>
19 #{revision.publisherName} 29 #{revision.publisherName}
20 </h:column> 30 </h:column>
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
62 <h:outputText value="publisherRevisionDatetime"/> 62 <h:outputText value="publisherRevisionDatetime"/>
63 <h:outputText value="#{publisherRevisionView.publisherRevisionDatetime}"/> 63 <h:outputText value="#{publisherRevisionView.publisherRevisionDatetime}"/>
64 <h:commandButton value="Edit" action="#{publisherRevisionView.edit}" rendered="#{not publisherRevisionView.editMode}"/> 64 <h:commandButton value="Edit" action="#{publisherRevisionView.edit}" rendered="#{not publisherRevisionView.editMode}"/>
65 + <h:commandButton value="Save" action="#{publisherRevisionView.update}" rendered="#{publisherRevisionView.editMode}"/>
65 <h:commandButton value="Cancel" action="#{publisherRevisionView.cancel}" rendered="#{publisherRevisionView.editMode}"/> 66 <h:commandButton value="Cancel" action="#{publisherRevisionView.cancel}" rendered="#{publisherRevisionView.editMode}"/>
66 <ui:remove> 67 <ui:remove>
67 <h:outputText value='Add'/> 68 <h:outputText value='Add'/>
......