Jean-Francois Leveque

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

Passage à la page unique pour CRU
...@@ -231,17 +231,17 @@ ...@@ -231,17 +231,17 @@
231 <plugin> 231 <plugin>
232 <groupId>org.apache.maven.plugins</groupId> 232 <groupId>org.apache.maven.plugins</groupId>
233 <artifactId>maven-compiler-plugin</artifactId> 233 <artifactId>maven-compiler-plugin</artifactId>
234 -<!-- <version>3.5.1</version>--> 234 + <version>3.5.1</version>
235 </plugin> 235 </plugin>
236 <plugin> 236 <plugin>
237 <groupId>org.apache.maven.plugins</groupId> 237 <groupId>org.apache.maven.plugins</groupId>
238 <artifactId>maven-surefire-plugin</artifactId> 238 <artifactId>maven-surefire-plugin</artifactId>
239 -<!-- <version>2.19.1</version>--> 239 + <version>2.19.1</version>
240 </plugin> 240 </plugin>
241 <plugin> 241 <plugin>
242 <groupId>org.apache.maven.plugins</groupId> 242 <groupId>org.apache.maven.plugins</groupId>
243 <artifactId>maven-war-plugin</artifactId> 243 <artifactId>maven-war-plugin</artifactId>
244 -<!-- <version>2.6</version>--> 244 + <version>2.6</version>
245 <configuration> 245 <configuration>
246 <failOnMissingWebXml>false</failOnMissingWebXml> 246 <failOnMissingWebXml>false</failOnMissingWebXml>
247 </configuration> 247 </configuration>
...@@ -249,7 +249,7 @@ ...@@ -249,7 +249,7 @@
249 <plugin> 249 <plugin>
250 <groupId>org.apache.tomee.maven</groupId> 250 <groupId>org.apache.tomee.maven</groupId>
251 <artifactId>tomee-maven-plugin</artifactId> 251 <artifactId>tomee-maven-plugin</artifactId>
252 -<!-- <version>7.0.1</version>--> 252 + <version>7.0.1</version>
253 <configuration> 253 <configuration>
254 <context>ROOT</context> 254 <context>ROOT</context>
255 </configuration> 255 </configuration>
......
...@@ -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 }
......
...@@ -17,10 +17,7 @@ import javax.inject.Inject; ...@@ -17,10 +17,7 @@ import javax.inject.Inject;
17 import javax.inject.Named; 17 import javax.inject.Named;
18 import java.io.Serializable; 18 import java.io.Serializable;
19 import java.sql.Timestamp; 19 import java.sql.Timestamp;
20 -import java.util.Date; 20 +import java.util.*;
21 -import java.util.List;
22 -import java.util.Random;
23 -import java.util.Set;
24 21
25 @Named 22 @Named
26 @ViewScoped 23 @ViewScoped
...@@ -37,7 +34,9 @@ public class PublisherRevisionView implements Serializable { ...@@ -37,7 +34,9 @@ public class PublisherRevisionView implements Serializable {
37 private SharedService sharedService; 34 private SharedService sharedService;
38 35
39 private boolean editMode; 36 private boolean editMode;
37 + private boolean newPublisher;
40 38
39 + private int publisherId;
41 // Données temporaires d'un PublisherRevision 40 // Données temporaires d'un PublisherRevision
42 private int publisherRevisionId; 41 private int publisherRevisionId;
43 private String publisherName; 42 private String publisherName;
...@@ -76,9 +75,15 @@ public class PublisherRevisionView implements Serializable { ...@@ -76,9 +75,15 @@ public class PublisherRevisionView implements Serializable {
76 return editMode; 75 return editMode;
77 } 76 }
78 77
79 - public void update() { 78 + public void save() {
80 - PublisherRevision publisherRevision = new PublisherRevision(); 79 + if (newPublisher) {
80 + add();
81 + } else {
82 + update();
83 + }
84 + }
81 85
86 + private void setValues(PublisherRevision publisherRevision) {
82 publisherRevision.setPublisherActive(publisherActive); 87 publisherRevision.setPublisherActive(publisherActive);
83 publisherRevision.setPublisherAddressCountry(publisherAddressCountry); 88 publisherRevision.setPublisherAddressCountry(publisherAddressCountry);
84 publisherRevision.setPublisherAddressLocality(publisherAddressLocality); 89 publisherRevision.setPublisherAddressLocality(publisherAddressLocality);
...@@ -101,6 +106,35 @@ public class PublisherRevisionView implements Serializable { ...@@ -101,6 +106,35 @@ public class PublisherRevisionView implements Serializable {
101 // End TODO 106 // End TODO
102 publisherRevision.setPublisherRevisionAuthor(user); 107 publisherRevision.setPublisherRevisionAuthor(user);
103 108
109 + }
110 +
111 + public void add() {
112 + Publisher publisher = new Publisher();
113 + PublisherRevision publisherRevision = new PublisherRevision();
114 + HashSet<PublisherRevision> publisherRevisions = new HashSet<PublisherRevision>();
115 + publisherRevisions.add(publisherRevision);
116 + publisher.setRevisions(publisherRevisions);
117 +
118 + publisherRevision.setPublisher(publisher);
119 +
120 + setValues(publisherRevision);
121 +
122 + publisherService.addPublisher(publisher);
123 + publisherRevisionService.addPublisherRevision(publisherRevision);
124 + newPublisher = false;
125 + publisherRevisionId = publisherRevision.getPublisherRevisionId();
126 + publisherId = publisher.getPublisherId();
127 + this.publisher = publisher;
128 + publisherRevisionAuthor = publisherRevision.getPublisherRevisionAuthor();
129 + publisherRevisionDatetime = publisherRevision.getPublisherRevisionDatetime();
130 + editMode = false;
131 + }
132 +
133 + public void update() {
134 + PublisherRevision publisherRevision = new PublisherRevision();
135 +
136 + setValues(publisherRevision);
137 +
104 publisherService.addRevisionToPublisher(publisher, publisherRevision); 138 publisherService.addRevisionToPublisher(publisher, publisherRevision);
105 publisherRevisionService.addPublisherRevision(publisherRevision); 139 publisherRevisionService.addPublisherRevision(publisherRevision);
106 editMode = false; 140 editMode = false;
...@@ -109,33 +143,35 @@ public class PublisherRevisionView implements Serializable { ...@@ -109,33 +143,35 @@ public class PublisherRevisionView implements Serializable {
109 public void loadData() { 143 public void loadData() {
110 logger.debug("publisherRevisionId = {}", this.publisherRevisionId); 144 logger.debug("publisherRevisionId = {}", this.publisherRevisionId);
111 145
112 - PublisherRevision publisherRevision = publisherRevisionService.getPublisherRevision(publisherRevisionId); 146 + if (publisherRevisionId != 0) {
113 - 147 + PublisherRevision publisherRevision = publisherRevisionService.getPublisherRevision(publisherRevisionId);
114 - logger.debug("Found a publisher revision : {}", publisherRevision.toString()); 148 +
115 - 149 + logger.debug("Found a publisher revision : {}", publisherRevision.toString());
116 - publisherName = publisherRevision.getPublisherName(); 150 +
117 - publisherStreetAddress = publisherRevision.getPublisherStreetAddress(); 151 + publisherName = publisherRevision.getPublisherName();
118 - publisherPostalCode = publisherRevision.getPublisherPostalCode(); 152 + publisherStreetAddress = publisherRevision.getPublisherStreetAddress();
119 - publisherPostOfficeBoxNumber = publisherRevision.getPublisherPostOfficeBoxNumber(); 153 + publisherPostalCode = publisherRevision.getPublisherPostalCode();
120 - publisherAddressRegion = publisherRevision.getPublisherAddressRegion(); 154 + publisherPostOfficeBoxNumber = publisherRevision.getPublisherPostOfficeBoxNumber();
121 - publisherAddressLocality = publisherRevision.getPublisherAddressLocality(); 155 + publisherAddressRegion = publisherRevision.getPublisherAddressRegion();
122 - publisherAddressCountry = publisherRevision.getPublisherAddressCountry(); 156 + publisherAddressLocality = publisherRevision.getPublisherAddressLocality();
123 - publisherTelephone = publisherRevision.getPublisherTelephone(); 157 + publisherAddressCountry = publisherRevision.getPublisherAddressCountry();
124 - publisherEmail = publisherRevision.getPublisherEmail(); 158 + publisherTelephone = publisherRevision.getPublisherTelephone();
125 - publisherURL = publisherRevision.getPublisherURL(); 159 + publisherEmail = publisherRevision.getPublisherEmail();
126 - publisherActive = publisherRevision.isPublisherActive(); 160 + publisherURL = publisherRevision.getPublisherURL();
127 - publisherHistory = publisherRevision.getPublisherHistory(); 161 + publisherActive = publisherRevision.isPublisherActive();
128 - publisherRevisionAuthor = publisherRevision.getPublisherRevisionAuthor(); 162 + publisherHistory = publisherRevision.getPublisherHistory();
129 - publisherRevisionDatetime = publisherRevision.getPublisherRevisionDatetime(); 163 + publisherRevisionAuthor = publisherRevision.getPublisherRevisionAuthor();
130 - publisher = publisherRevision.getPublisher(); 164 + publisherRevisionDatetime = publisherRevision.getPublisherRevisionDatetime();
131 - 165 + publisher = publisherRevision.getPublisher();
132 - logger.debug("Found a publisher : {}", publisher.toString()); 166 +
167 + logger.debug("Found a publisher : {}", publisher.toString());
168 + newPublisher = false;
169 + } else {
170 + logger.debug("No publisher.");
171 + editMode = true;
172 + newPublisher = true;
173 + }
133 174
134 -// Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
135 -//
136 -// PublisherRevision publisherRevision = publisherRevisionService.getPublisherRevision(new Integer(params.get("publisherRevisionId")));
137 -// setPublisherRevisionId(publisherRevision.getPublisherRevisionId());
138 -// logger.info("publisherRevisionId = " + getPublisherRevisionId());
139 } 175 }
140 176
141 public int getPublisherRevisionId() { 177 public int getPublisherRevisionId() {
...@@ -265,4 +301,8 @@ public class PublisherRevisionView implements Serializable { ...@@ -265,4 +301,8 @@ public class PublisherRevisionView implements Serializable {
265 public void setAvailableCountries(List<Country> availableCountries) { 301 public void setAvailableCountries(List<Country> availableCountries) {
266 this.availableCountries = availableCountries; 302 this.availableCountries = availableCountries;
267 } 303 }
304 +
305 + public boolean isNewPublisher() {
306 + return newPublisher;
307 + }
268 } 308 }
......
...@@ -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'/>
......