https://tree.taiga.io/project/jr-utily-grog-v3/us/44 Implementer l'historisation pour les éditeurs
Passage à la page unique pour CRU
Showing
6 changed files
with
112 additions
and
48 deletions
... | @@ -11,4 +11,6 @@ public interface PublisherService { | ... | @@ -11,4 +11,6 @@ public interface PublisherService { |
11 | void addRevisionToPublisher(Publisher publisher, PublisherRevision publisherRevision); | 11 | void addRevisionToPublisher(Publisher publisher, PublisherRevision publisherRevision); |
12 | 12 | ||
13 | List<Publisher> getAllPublishers(); | 13 | List<Publisher> getAllPublishers(); |
14 | + | ||
15 | + Publisher getPublisher(Integer publisherId); | ||
14 | } | 16 | } | ... | ... |
... | @@ -27,6 +27,10 @@ public class PublisherServiceSpring implements PublisherService { | ... | @@ -27,6 +27,10 @@ public class PublisherServiceSpring implements PublisherService { |
27 | publisherRepository.save(publisher); | 27 | publisherRepository.save(publisher); |
28 | } | 28 | } |
29 | 29 | ||
30 | + public Publisher getPublisher(Integer publisherId) { | ||
31 | + return publisherRepository.findOne(publisherId); | ||
32 | + } | ||
33 | + | ||
30 | public List<Publisher> getAllPublishers() { | 34 | public List<Publisher> getAllPublishers() { |
31 | return publisherRepository.findAll(); | 35 | return publisherRepository.findAll(); |
32 | } | 36 | } | ... | ... |
... | @@ -18,10 +18,7 @@ import javax.inject.Inject; | ... | @@ -18,10 +18,7 @@ import javax.inject.Inject; |
18 | import javax.inject.Named; | 18 | import javax.inject.Named; |
19 | import java.io.Serializable; | 19 | import java.io.Serializable; |
20 | import java.sql.Timestamp; | 20 | import java.sql.Timestamp; |
21 | -import java.util.Date; | 21 | +import java.util.*; |
22 | -import java.util.List; | ||
23 | -import java.util.Random; | ||
24 | -import java.util.Set; | ||
25 | 22 | ||
26 | @Named | 23 | @Named |
27 | @ViewScoped | 24 | @ViewScoped |
... | @@ -38,7 +35,9 @@ public class PublisherRevisionView implements Serializable { | ... | @@ -38,7 +35,9 @@ public class PublisherRevisionView implements Serializable { |
38 | private SharedService sharedService; | 35 | private SharedService sharedService; |
39 | 36 | ||
40 | private boolean editMode; | 37 | private boolean editMode; |
38 | + private boolean newPublisher; | ||
41 | 39 | ||
40 | + private int publisherId; | ||
42 | // Données temporaires d'un PublisherRevision | 41 | // Données temporaires d'un PublisherRevision |
43 | private int publisherRevisionId; | 42 | private int publisherRevisionId; |
44 | private String publisherName; | 43 | private String publisherName; |
... | @@ -77,9 +76,15 @@ public class PublisherRevisionView implements Serializable { | ... | @@ -77,9 +76,15 @@ public class PublisherRevisionView implements Serializable { |
77 | return editMode; | 76 | return editMode; |
78 | } | 77 | } |
79 | 78 | ||
80 | - public void update() { | 79 | + public void save() { |
81 | - PublisherRevision publisherRevision = new PublisherRevision(); | 80 | + if (newPublisher) { |
81 | + add(); | ||
82 | + } else { | ||
83 | + update(); | ||
84 | + } | ||
85 | + } | ||
82 | 86 | ||
87 | + private void setValues(PublisherRevision publisherRevision) { | ||
83 | publisherRevision.setPublisherActive(publisherActive); | 88 | publisherRevision.setPublisherActive(publisherActive); |
84 | publisherRevision.setPublisherAddressCountry(publisherAddressCountry); | 89 | publisherRevision.setPublisherAddressCountry(publisherAddressCountry); |
85 | publisherRevision.setPublisherAddressLocality(publisherAddressLocality); | 90 | publisherRevision.setPublisherAddressLocality(publisherAddressLocality); |
... | @@ -102,6 +107,35 @@ public class PublisherRevisionView implements Serializable { | ... | @@ -102,6 +107,35 @@ public class PublisherRevisionView implements Serializable { |
102 | // End TODO | 107 | // End TODO |
103 | publisherRevision.setPublisherRevisionAuthor(user); | 108 | publisherRevision.setPublisherRevisionAuthor(user); |
104 | 109 | ||
110 | + } | ||
111 | + | ||
112 | + public void add() { | ||
113 | + Publisher publisher = new Publisher(); | ||
114 | + PublisherRevision publisherRevision = new PublisherRevision(); | ||
115 | + HashSet<PublisherRevision> publisherRevisions = new HashSet<PublisherRevision>(); | ||
116 | + publisherRevisions.add(publisherRevision); | ||
117 | + publisher.setRevisions(publisherRevisions); | ||
118 | + | ||
119 | + publisherRevision.setPublisher(publisher); | ||
120 | + | ||
121 | + setValues(publisherRevision); | ||
122 | + | ||
123 | + publisherService.addPublisher(publisher); | ||
124 | + publisherRevisionService.addPublisherRevision(publisherRevision); | ||
125 | + newPublisher = false; | ||
126 | + publisherRevisionId = publisherRevision.getPublisherRevisionId(); | ||
127 | + publisherId = publisher.getPublisherId(); | ||
128 | + this.publisher = publisher; | ||
129 | + publisherRevisionAuthor = publisherRevision.getPublisherRevisionAuthor(); | ||
130 | + publisherRevisionDatetime = publisherRevision.getPublisherRevisionDatetime(); | ||
131 | + editMode = false; | ||
132 | + } | ||
133 | + | ||
134 | + public void update() { | ||
135 | + PublisherRevision publisherRevision = new PublisherRevision(); | ||
136 | + | ||
137 | + setValues(publisherRevision); | ||
138 | + | ||
105 | publisherService.addRevisionToPublisher(publisher, publisherRevision); | 139 | publisherService.addRevisionToPublisher(publisher, publisherRevision); |
106 | publisherRevisionService.addPublisherRevision(publisherRevision); | 140 | publisherRevisionService.addPublisherRevision(publisherRevision); |
107 | editMode = false; | 141 | editMode = false; |
... | @@ -110,33 +144,35 @@ public class PublisherRevisionView implements Serializable { | ... | @@ -110,33 +144,35 @@ public class PublisherRevisionView implements Serializable { |
110 | public void loadData() { | 144 | public void loadData() { |
111 | logger.debug("publisherRevisionId = {}", this.publisherRevisionId); | 145 | logger.debug("publisherRevisionId = {}", this.publisherRevisionId); |
112 | 146 | ||
113 | - PublisherRevision publisherRevision = publisherRevisionService.getPublisherRevision(publisherRevisionId); | 147 | + if (publisherRevisionId != 0) { |
114 | - | 148 | + PublisherRevision publisherRevision = publisherRevisionService.getPublisherRevision(publisherRevisionId); |
115 | - logger.debug("Found a publisher revision : {}", publisherRevision.toString()); | 149 | + |
116 | - | 150 | + logger.debug("Found a publisher revision : {}", publisherRevision.toString()); |
117 | - publisherName = publisherRevision.getPublisherName(); | 151 | + |
118 | - publisherStreetAddress = publisherRevision.getPublisherStreetAddress(); | 152 | + publisherName = publisherRevision.getPublisherName(); |
119 | - publisherPostalCode = publisherRevision.getPublisherPostalCode(); | 153 | + publisherStreetAddress = publisherRevision.getPublisherStreetAddress(); |
120 | - publisherPostOfficeBoxNumber = publisherRevision.getPublisherPostOfficeBoxNumber(); | 154 | + publisherPostalCode = publisherRevision.getPublisherPostalCode(); |
121 | - publisherAddressRegion = publisherRevision.getPublisherAddressRegion(); | 155 | + publisherPostOfficeBoxNumber = publisherRevision.getPublisherPostOfficeBoxNumber(); |
122 | - publisherAddressLocality = publisherRevision.getPublisherAddressLocality(); | 156 | + publisherAddressRegion = publisherRevision.getPublisherAddressRegion(); |
123 | - publisherAddressCountry = publisherRevision.getPublisherAddressCountry(); | 157 | + publisherAddressLocality = publisherRevision.getPublisherAddressLocality(); |
124 | - publisherTelephone = publisherRevision.getPublisherTelephone(); | 158 | + publisherAddressCountry = publisherRevision.getPublisherAddressCountry(); |
125 | - publisherEmail = publisherRevision.getPublisherEmail(); | 159 | + publisherTelephone = publisherRevision.getPublisherTelephone(); |
126 | - publisherURL = publisherRevision.getPublisherURL(); | 160 | + publisherEmail = publisherRevision.getPublisherEmail(); |
127 | - publisherActive = publisherRevision.isPublisherActive(); | 161 | + publisherURL = publisherRevision.getPublisherURL(); |
128 | - publisherHistory = publisherRevision.getPublisherHistory(); | 162 | + publisherActive = publisherRevision.isPublisherActive(); |
129 | - publisherRevisionAuthor = publisherRevision.getPublisherRevisionAuthor(); | 163 | + publisherHistory = publisherRevision.getPublisherHistory(); |
130 | - publisherRevisionDatetime = publisherRevision.getPublisherRevisionDatetime(); | 164 | + publisherRevisionAuthor = publisherRevision.getPublisherRevisionAuthor(); |
131 | - publisher = publisherRevision.getPublisher(); | 165 | + publisherRevisionDatetime = publisherRevision.getPublisherRevisionDatetime(); |
132 | - | 166 | + publisher = publisherRevision.getPublisher(); |
133 | - logger.debug("Found a publisher : {}", publisher.toString()); | 167 | + |
168 | + logger.debug("Found a publisher : {}", publisher.toString()); | ||
169 | + newPublisher = false; | ||
170 | + } else { | ||
171 | + logger.debug("No publisher."); | ||
172 | + editMode = true; | ||
173 | + newPublisher = true; | ||
174 | + } | ||
134 | 175 | ||
135 | -// Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); | ||
136 | -// | ||
137 | -// PublisherRevision publisherRevision = publisherRevisionService.getPublisherRevision(new Integer(params.get("publisherRevisionId"))); | ||
138 | -// setPublisherRevisionId(publisherRevision.getPublisherRevisionId()); | ||
139 | -// logger.info("publisherRevisionId = " + getPublisherRevisionId()); | ||
140 | } | 176 | } |
141 | 177 | ||
142 | public int getPublisherRevisionId() { | 178 | public int getPublisherRevisionId() { |
... | @@ -266,4 +302,8 @@ public class PublisherRevisionView implements Serializable { | ... | @@ -266,4 +302,8 @@ public class PublisherRevisionView implements Serializable { |
266 | public void setAvailableCountries(List<Country> availableCountries) { | 302 | public void setAvailableCountries(List<Country> availableCountries) { |
267 | this.availableCountries = availableCountries; | 303 | this.availableCountries = availableCountries; |
268 | } | 304 | } |
305 | + | ||
306 | + public boolean isNewPublisher() { | ||
307 | + return newPublisher; | ||
308 | + } | ||
269 | } | 309 | } | ... | ... |
... | @@ -39,13 +39,13 @@ | ... | @@ -39,13 +39,13 @@ |
39 | </h:commandLink> | 39 | </h:commandLink> |
40 | </li> | 40 | </li> |
41 | <li> | 41 | <li> |
42 | - <h:link outcome="/addPublisher.xhtml"> | 42 | + <h:link outcome="/publisherRevision"> |
43 | - <h:outputText value="Add a Publisher"/> | 43 | + <h:outputText value="Ajouter un éditeur"/> |
44 | </h:link> | 44 | </h:link> |
45 | </li> | 45 | </li> |
46 | <li> | 46 | <li> |
47 | - <h:link outcome="/listPublisherRevisions.xhtml"> | 47 | + <h:link outcome="/listPublisherRevisions"> |
48 | - <h:outputText value="List Publisher Revisions"/> | 48 | + <h:outputText value="Liste des versions des éditeurs"/> |
49 | </h:link> | 49 | </h:link> |
50 | </li> | 50 | </li> |
51 | </ul> | 51 | </ul> | ... | ... |
... | @@ -11,9 +11,18 @@ | ... | @@ -11,9 +11,18 @@ |
11 | </f:metadata> | 11 | </f:metadata> |
12 | <h:body> | 12 | <h:body> |
13 | <h:form> | 13 | <h:form> |
14 | - <h:commandLink action="home"> | 14 | + <ul> |
15 | - <h:outputText value="Menu principal"/> | 15 | + <li> |
16 | - </h:commandLink> | 16 | + <h:link outcome="/index"> |
17 | + <h:outputText value="Menu principal"/> | ||
18 | + </h:link> | ||
19 | + </li> | ||
20 | + <li> | ||
21 | + <h:link outcome="/publisherRevision"> | ||
22 | + <h:outputText value="Ajouter un éditeur"/> | ||
23 | + </h:link> | ||
24 | + </li> | ||
25 | + </ul> | ||
17 | </h:form> | 26 | </h:form> |
18 | 27 | ||
19 | <h:link rendered="#{not listPublisherRevisionsBean.viewAll}" outcome="/listPublisherRevisions.xhtml">Voir tous les éditeurs</h:link> | 28 | <h:link rendered="#{not listPublisherRevisionsBean.viewAll}" outcome="/listPublisherRevisions.xhtml">Voir tous les éditeurs</h:link> | ... | ... |
... | @@ -16,9 +16,18 @@ | ... | @@ -16,9 +16,18 @@ |
16 | <body> | 16 | <body> |
17 | 17 | ||
18 | <h:form> | 18 | <h:form> |
19 | - <h:commandLink action="home"> | 19 | + <ul> |
20 | - <h:outputText value="Menu principal"/> | 20 | + <li> |
21 | - </h:commandLink> | 21 | + <h:link outcome="/index"> |
22 | + <h:outputText value="Menu principal"/> | ||
23 | + </h:link> | ||
24 | + </li> | ||
25 | + <li> | ||
26 | + <h:link outcome="/listPublisherRevisions"> | ||
27 | + <h:outputText value="Versions des éditeurs"/> | ||
28 | + </h:link> | ||
29 | + </li> | ||
30 | + </ul> | ||
22 | 31 | ||
23 | <h:panelGrid columns="2"> | 32 | <h:panelGrid columns="2"> |
24 | <h:outputText value='publisherName'/> | 33 | <h:outputText value='publisherName'/> |
... | @@ -56,13 +65,13 @@ | ... | @@ -56,13 +65,13 @@ |
56 | <h:selectBooleanCheckbox value="#{publisherRevisionView.publisherActive}" disabled="#{not publisherRevisionView.editMode}"/> | 65 | <h:selectBooleanCheckbox value="#{publisherRevisionView.publisherActive}" disabled="#{not publisherRevisionView.editMode}"/> |
57 | 66 | ||
58 | <h:outputText value='publisherHistory'/> | 67 | <h:outputText value='publisherHistory'/> |
59 | - <h:inputText value='#{publisherRevisionView.publisherHistory}' disabled="#{not publisherRevisionView.editMode}"/> | 68 | + <h:inputTextarea value='#{publisherRevisionView.publisherHistory}' disabled="#{not publisherRevisionView.editMode}"/> |
60 | - <h:outputText value="publisherRevisionAuthor"/> | 69 | + <h:outputText value="publisherRevisionAuthor" rendered="#{not publisherRevisionView.newPublisher}"/> |
61 | - <h:outputText value="#{publisherRevisionView.publisherRevisionAuthor.displayName}"/> | 70 | + <h:outputText value="#{publisherRevisionView.publisherRevisionAuthor.displayName}" rendered="#{not publisherRevisionView.newPublisher}"/> |
62 | - <h:outputText value="publisherRevisionDatetime"/> | 71 | + <h:outputText value="publisherRevisionDatetime" rendered="#{not publisherRevisionView.newPublisher}"/> |
63 | - <h:outputText value="#{publisherRevisionView.publisherRevisionDatetime}"/> | 72 | + <h:outputText value="#{publisherRevisionView.publisherRevisionDatetime}" rendered="#{not publisherRevisionView.newPublisher}"/> |
64 | <h:commandButton value="Edit" action="#{publisherRevisionView.edit}" rendered="#{not publisherRevisionView.editMode}"/> | 73 | <h:commandButton value="Edit" action="#{publisherRevisionView.edit}" rendered="#{not publisherRevisionView.editMode}"/> |
65 | - <h:commandButton value="Save" action="#{publisherRevisionView.update}" rendered="#{publisherRevisionView.editMode}"/> | 74 | + <h:commandButton value="Save" action="#{publisherRevisionView.save}" rendered="#{publisherRevisionView.editMode}"/> |
66 | <h:commandButton value="Cancel" action="#{publisherRevisionView.cancel}" rendered="#{publisherRevisionView.editMode}"/> | 75 | <h:commandButton value="Cancel" action="#{publisherRevisionView.cancel}" rendered="#{publisherRevisionView.editMode}"/> |
67 | <ui:remove> | 76 | <ui:remove> |
68 | <h:outputText value='Add'/> | 77 | <h:outputText value='Add'/> | ... | ... |
-
Please register or login to post a comment