https://tree.taiga.io/project/jr-utily-grog-v3/us/44 Implementer l'historisation pour les éditeurs
Showing
9 changed files
with
85 additions
and
5 deletions
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; |
... | @@ -15,7 +18,10 @@ import javax.inject.Inject; | ... | @@ -15,7 +18,10 @@ import javax.inject.Inject; |
15 | import javax.inject.Named; | 18 | import javax.inject.Named; |
16 | import java.io.Serializable; | 19 | import java.io.Serializable; |
17 | import java.sql.Timestamp; | 20 | import java.sql.Timestamp; |
21 | +import java.util.Date; | ||
18 | import java.util.List; | 22 | import java.util.List; |
23 | +import java.util.Random; | ||
24 | +import java.util.Set; | ||
19 | 25 | ||
20 | @Named | 26 | @Named |
21 | @ViewScoped | 27 | @ViewScoped |
... | @@ -23,8 +29,12 @@ public class PublisherRevisionView implements Serializable { | ... | @@ -23,8 +29,12 @@ public class PublisherRevisionView implements Serializable { |
23 | Logger logger = LoggerFactory.getLogger(getClass()); | 29 | Logger logger = LoggerFactory.getLogger(getClass()); |
24 | 30 | ||
25 | @Inject | 31 | @Inject |
32 | + private PublisherService publisherService; | ||
33 | + @Inject | ||
26 | PublisherRevisionService publisherRevisionService; | 34 | PublisherRevisionService publisherRevisionService; |
27 | @Inject | 35 | @Inject |
36 | + UserService userService; | ||
37 | + @Inject | ||
28 | private SharedService sharedService; | 38 | private SharedService sharedService; |
29 | 39 | ||
30 | private boolean editMode; | 40 | private boolean editMode; |
... | @@ -45,6 +55,7 @@ public class PublisherRevisionView implements Serializable { | ... | @@ -45,6 +55,7 @@ public class PublisherRevisionView implements Serializable { |
45 | private String publisherHistory; | 55 | private String publisherHistory; |
46 | private User publisherRevisionAuthor; | 56 | private User publisherRevisionAuthor; |
47 | private Timestamp publisherRevisionDatetime; | 57 | private Timestamp publisherRevisionDatetime; |
58 | + private Publisher publisher; | ||
48 | 59 | ||
49 | // Table de codification | 60 | // Table de codification |
50 | private List<Country> availableCountries; | 61 | private List<Country> availableCountries; |
... | @@ -66,6 +77,36 @@ public class PublisherRevisionView implements Serializable { | ... | @@ -66,6 +77,36 @@ public class PublisherRevisionView implements Serializable { |
66 | return editMode; | 77 | return editMode; |
67 | } | 78 | } |
68 | 79 | ||
80 | + public void update() { | ||
81 | + PublisherRevision publisherRevision = new PublisherRevision(); | ||
82 | + | ||
83 | + publisherRevision.setPublisherActive(publisherActive); | ||
84 | + publisherRevision.setPublisherAddressCountry(publisherAddressCountry); | ||
85 | + publisherRevision.setPublisherAddressLocality(publisherAddressLocality); | ||
86 | + publisherRevision.setPublisherAddressRegion(publisherAddressRegion); | ||
87 | + publisherRevision.setPublisherEmail(publisherEmail); | ||
88 | + publisherRevision.setPublisherHistory(publisherHistory); | ||
89 | + publisherRevision.setPublisherName(publisherName); | ||
90 | + publisherRevision.setPublisherPostalCode(publisherPostalCode); | ||
91 | + publisherRevision.setPublisherPostOfficeBoxNumber(publisherPostOfficeBoxNumber); | ||
92 | + publisherRevision.setPublisherStreetAddress(publisherStreetAddress); | ||
93 | + publisherRevision.setPublisherTelephone(publisherTelephone); | ||
94 | + publisherRevision.setPublisherURL(publisherURL); | ||
95 | + | ||
96 | + publisherRevision.setPublisherRevisionDatetime(new Timestamp(new Date().getTime())); | ||
97 | + | ||
98 | + // TODO Remplacer l'astuce par une vraie récupération de l'utilisateur | ||
99 | + List<User> users = userService.getAllUsers(); | ||
100 | + Random random = new Random(); | ||
101 | + User user = users.get(random.nextInt(users.size())); | ||
102 | + // End TODO | ||
103 | + publisherRevision.setPublisherRevisionAuthor(user); | ||
104 | + | ||
105 | + publisherService.addRevisionToPublisher(publisher, publisherRevision); | ||
106 | + publisherRevisionService.addPublisherRevision(publisherRevision); | ||
107 | + editMode = false; | ||
108 | + } | ||
109 | + | ||
69 | public void loadData() { | 110 | public void loadData() { |
70 | logger.debug("publisherRevisionId = {}", this.publisherRevisionId); | 111 | logger.debug("publisherRevisionId = {}", this.publisherRevisionId); |
71 | 112 | ||
... | @@ -87,7 +128,9 @@ public class PublisherRevisionView implements Serializable { | ... | @@ -87,7 +128,9 @@ public class PublisherRevisionView implements Serializable { |
87 | publisherHistory = publisherRevision.getPublisherHistory(); | 128 | publisherHistory = publisherRevision.getPublisherHistory(); |
88 | publisherRevisionAuthor = publisherRevision.getPublisherRevisionAuthor(); | 129 | publisherRevisionAuthor = publisherRevision.getPublisherRevisionAuthor(); |
89 | publisherRevisionDatetime = publisherRevision.getPublisherRevisionDatetime(); | 130 | publisherRevisionDatetime = publisherRevision.getPublisherRevisionDatetime(); |
131 | + publisher = publisherRevision.getPublisher(); | ||
90 | 132 | ||
133 | + logger.debug("Found a publisher : {}", publisher.toString()); | ||
91 | 134 | ||
92 | // Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); | 135 | // Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); |
93 | // | 136 | // | ... | ... |
... | @@ -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'/> | ... | ... |
-
Please register or login to post a comment