Jean-Francois Leveque

Passage de PublisherVersion (vue et page) en Rewrite

...@@ -2,10 +2,14 @@ package org.legrog.web.publisher; ...@@ -2,10 +2,14 @@ package org.legrog.web.publisher;
2 2
3 import org.legrog.entities.*; 3 import org.legrog.entities.*;
4 import org.legrog.web.xyz.SharedService; 4 import org.legrog.web.xyz.SharedService;
5 +import org.ocpsoft.rewrite.annotation.Join;
6 +import org.ocpsoft.rewrite.annotation.Parameter;
7 +import org.ocpsoft.rewrite.annotation.RequestAction;
5 import org.slf4j.Logger; 8 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory; 9 import org.slf4j.LoggerFactory;
7 10
8 import javax.annotation.PostConstruct; 11 import javax.annotation.PostConstruct;
12 +import javax.enterprise.context.RequestScoped;
9 import javax.faces.view.ViewScoped; 13 import javax.faces.view.ViewScoped;
10 import javax.inject.Inject; 14 import javax.inject.Inject;
11 import javax.inject.Named; 15 import javax.inject.Named;
...@@ -20,8 +24,12 @@ import java.util.List; ...@@ -20,8 +24,12 @@ import java.util.List;
20 * Update creates a new PublisherVersion linked to the Publisher 24 * Update creates a new PublisherVersion linked to the Publisher
21 */ 25 */
22 @Named 26 @Named
23 -@ViewScoped 27 +@RequestScoped
28 +@Join(path = "/PublisherVersion/{stringId}", to = "/publisher/publisherVersion.jsf")
24 public class PublisherVersionView implements Serializable { 29 public class PublisherVersionView implements Serializable {
30 + @Parameter
31 + String stringId;
32 +
25 transient Logger logger = LoggerFactory.getLogger(getClass()); 33 transient Logger logger = LoggerFactory.getLogger(getClass());
26 34
27 transient PublisherService publisherService; 35 transient PublisherService publisherService;
...@@ -68,11 +76,58 @@ public class PublisherVersionView implements Serializable { ...@@ -68,11 +76,58 @@ public class PublisherVersionView implements Serializable {
68 } 76 }
69 77
70 /** 78 /**
71 - * Loads countries 79 + * Loads countries and adapts to availability of parameter
72 */ 80 */
73 @PostConstruct 81 @PostConstruct
82 + @RequestAction
74 public void init() { 83 public void init() {
75 availableCountries = sharedService.getAllCountries(); 84 availableCountries = sharedService.getAllCountries();
85 +
86 + PublisherVersion publisherVersion = null;
87 +
88 + logger.debug("stringId = {}", this.stringId);
89 +
90 + if (stringId != null) {
91 + try {
92 + publisherVersionId = Integer.parseInt(stringId);
93 + } catch (NumberFormatException ne) {
94 + publisherVersionId = 0;
95 + }
96 + } else {
97 + publisherVersionId = 0;
98 + }
99 +
100 + if (publisherVersionId != 0) {
101 + publisherVersion = publisherService.getPublisherVersion(publisherVersionId);
102 + publisherActions = publisherService.getAllPublisherVersionActions(publisherVersion);
103 + }
104 +
105 + if (publisherVersion != null) {
106 +
107 + logger.debug("Found a publisher version : {}", publisherVersion.toString());
108 +
109 + publisherName = publisherVersion.getPublisherName();
110 + streetAddress = publisherVersion.getPublisherStreetAddress();
111 + postalCode = publisherVersion.getPublisherPostalCode();
112 + postOfficeBoxNumber = publisherVersion.getPublisherPostOfficeBoxNumber();
113 + addressRegion = publisherVersion.getPublisherAddressRegion();
114 + addressLocality = publisherVersion.getPublisherAddressLocality();
115 + publisherAddressCountry = publisherVersion.getPublisherAddressCountry();
116 + telephone = publisherVersion.getPublisherTelephone();
117 + email = publisherVersion.getPublisherEmail();
118 + uRL = publisherVersion.getPublisherURL();
119 + publisherHistory = publisherVersion.getPublisherHistory();
120 + publisher = publisherVersion.getPublisher();
121 +
122 + getImmutableValues();
123 +
124 + logger.debug("Found a publisher : {}", publisher.toString());
125 + newPublisher = false;
126 + } else {
127 + logger.debug("No publisher.");
128 + editMode = true;
129 + newPublisher = true;
130 + }
76 } 131 }
77 132
78 /** 133 /**
...@@ -87,7 +142,7 @@ public class PublisherVersionView implements Serializable { ...@@ -87,7 +142,7 @@ public class PublisherVersionView implements Serializable {
87 */ 142 */
88 public void cancel() { 143 public void cancel() {
89 if (!newPublisher) { 144 if (!newPublisher) {
90 - loadData(); 145 + init();
91 editMode = false; 146 editMode = false;
92 } else { 147 } else {
93 publisherName = null; 148 publisherName = null;
...@@ -182,45 +237,6 @@ public class PublisherVersionView implements Serializable { ...@@ -182,45 +237,6 @@ public class PublisherVersionView implements Serializable {
182 logger.trace("fin update, après récupération, publisherVersion = {}", publisherVersion); 237 logger.trace("fin update, après récupération, publisherVersion = {}", publisherVersion);
183 } 238 }
184 239
185 - public void loadData() {
186 - PublisherVersion publisherVersion = null;
187 -
188 - logger.debug("publisherVersionId = {}", this.publisherVersionId);
189 -
190 - if (publisherVersionId != 0) {
191 - publisherVersion = publisherService.getPublisherVersion(publisherVersionId);
192 - publisherActions = publisherService.getAllPublisherVersionActions(publisherVersion);
193 - }
194 -
195 - if (publisherVersion != null) {
196 -
197 - logger.debug("Found a publisher version : {}", publisherVersion.toString());
198 -
199 - publisherName = publisherVersion.getPublisherName();
200 - streetAddress = publisherVersion.getPublisherStreetAddress();
201 - postalCode = publisherVersion.getPublisherPostalCode();
202 - postOfficeBoxNumber = publisherVersion.getPublisherPostOfficeBoxNumber();
203 - addressRegion = publisherVersion.getPublisherAddressRegion();
204 - addressLocality = publisherVersion.getPublisherAddressLocality();
205 - publisherAddressCountry = publisherVersion.getPublisherAddressCountry();
206 - telephone = publisherVersion.getPublisherTelephone();
207 - email = publisherVersion.getPublisherEmail();
208 - uRL = publisherVersion.getPublisherURL();
209 - publisherHistory = publisherVersion.getPublisherHistory();
210 - publisher = publisherVersion.getPublisher();
211 -
212 - getImmutableValues();
213 -
214 - logger.debug("Found a publisher : {}", publisher.toString());
215 - newPublisher = false;
216 - } else {
217 - logger.debug("No publisher.");
218 - editMode = true;
219 - newPublisher = true;
220 - }
221 -
222 - }
223 -
224 // Accessors 240 // Accessors
225 public int getPublisherVersionId() { 241 public int getPublisherVersionId() {
226 return publisherVersionId; 242 return publisherVersionId;
...@@ -369,4 +385,12 @@ public class PublisherVersionView implements Serializable { ...@@ -369,4 +385,12 @@ public class PublisherVersionView implements Serializable {
369 public List<PublisherAction> getPublisherActions() { 385 public List<PublisherAction> getPublisherActions() {
370 return publisherActions; 386 return publisherActions;
371 } 387 }
388 +
389 + public String getStringId() {
390 + return stringId;
391 + }
392 +
393 + public void setStringId(String stringId) {
394 + this.stringId = stringId;
395 + }
372 } 396 }
......
...@@ -26,9 +26,7 @@ ...@@ -26,9 +26,7 @@
26 <h:dataTable value="#{listPublisherVersionsView.publisherVersions}" var="version"> 26 <h:dataTable value="#{listPublisherVersionsView.publisherVersions}" var="version">
27 <h:column> 27 <h:column>
28 <f:facet name="header"/> 28 <f:facet name="header"/>
29 - <a jsf:outcome="publisherVersion">Visualiser ou Modifier Version 29 + <a jsf:value="/PublisherVersion/${version.publisherVersionId}">Visualiser ou Modifier Version</a>
30 - <f:param name="publisherVersionId" value="#{version.publisherVersionId}"/>
31 - </a>
32 </h:column> 30 </h:column>
33 <h:column rendered="#{listPublisherVersionsView.viewAll}"> 31 <h:column rendered="#{listPublisherVersionsView.viewAll}">
34 <f:facet name="header"/> 32 <f:facet name="header"/>
......
...@@ -7,10 +7,6 @@ ...@@ -7,10 +7,6 @@
7 xmlns:f="http://xmlns.jcp.org/jsf/core" 7 xmlns:f="http://xmlns.jcp.org/jsf/core"
8 xmlns:jsf="http://xmlns.jcp.org/jsf"> 8 xmlns:jsf="http://xmlns.jcp.org/jsf">
9 <head> 9 <head>
10 -<f:metadata>
11 - <f:viewParam name="publisherVersionId" value="#{publisherVersionView.publisherVersionId}" />
12 - <f:viewAction action="#{publisherVersionView.loadData}" />
13 -</f:metadata>
14 </head> 10 </head>
15 <body> 11 <body>
16 12
...@@ -54,7 +50,7 @@ ...@@ -54,7 +50,7 @@
54 <input type="text" id="uRL" jsf:value='#{publisherVersionView.uRL}' jsf:disabled="#{not publisherVersionView.editMode}"/> 50 <input type="text" id="uRL" jsf:value='#{publisherVersionView.uRL}' jsf:disabled="#{not publisherVersionView.editMode}"/>
55 51
56 <label for="publisherHistory">publisherHistory</label> 52 <label for="publisherHistory">publisherHistory</label>
57 - <textarea id="publisherHistory" rows="" cols="" jsf:disabled="#{not publisherVersionView.editMode}" jsf:value="#{publisherVersionView.publisherHistory}"/> 53 + <textarea id="publisherHistory" rows="20" cols="200" jsf:disabled="#{not publisherVersionView.editMode}" jsf:value="#{publisherVersionView.publisherHistory}"/>
58 54
59 <div jsf:rendered="#{not publisherVersionView.newPublisher}">publisherVersionAuthor</div> 55 <div jsf:rendered="#{not publisherVersionView.newPublisher}">publisherVersionAuthor</div>
60 <div jsf:rendered="#{not publisherVersionView.newPublisher}">#{publisherVersionView.publisherVersionAuthor.displayName}</div> 56 <div jsf:rendered="#{not publisherVersionView.newPublisher}">#{publisherVersionView.publisherVersionAuthor.displayName}</div>
......
...@@ -108,7 +108,7 @@ public class PublisherVersionViewTest { ...@@ -108,7 +108,7 @@ public class PublisherVersionViewTest {
108 @Test 108 @Test
109 public void testCancelNewVersionOfPublisher() { 109 public void testCancelNewVersionOfPublisher() {
110 publisherVersionView.setNewPublisher(false); 110 publisherVersionView.setNewPublisher(false);
111 - publisherVersionView.setPublisherVersionId(1); 111 + publisherVersionView.setStringId("1");
112 112
113 publisherVersionView.setPublisherName("1"); 113 publisherVersionView.setPublisherName("1");
114 publisherVersionView.setStreetAddress("2"); 114 publisherVersionView.setStreetAddress("2");
...@@ -139,14 +139,14 @@ public class PublisherVersionViewTest { ...@@ -139,14 +139,14 @@ public class PublisherVersionViewTest {
139 } 139 }
140 140
141 @Nested 141 @Nested
142 - @DisplayName("loadData method") 142 + @DisplayName("init method")
143 class LoadDataTests{ 143 class LoadDataTests{
144 144
145 @Test 145 @Test
146 @DisplayName("Loads all actions on it") 146 @DisplayName("Loads all actions on it")
147 public void testLoadActions(@Mock PublisherService publisherService) { 147 public void testLoadActions(@Mock PublisherService publisherService) {
148 - publisherVersionView.setPublisherVersionId(1); 148 + publisherVersionView.setStringId("1");
149 - publisherVersionView.loadData(); 149 + publisherVersionView.init();
150 Mockito.verify(publisherService).getAllPublisherVersionActions(publisherVersion); 150 Mockito.verify(publisherService).getAllPublisherVersionActions(publisherVersion);
151 } 151 }
152 152
...@@ -154,8 +154,8 @@ public class PublisherVersionViewTest { ...@@ -154,8 +154,8 @@ public class PublisherVersionViewTest {
154 @DisplayName("when called for existing publisher, should get the rigtht data into the form") 154 @DisplayName("when called for existing publisher, should get the rigtht data into the form")
155 public void testLoadData() { 155 public void testLoadData() {
156 publisherVersionView.setNewPublisher(true); 156 publisherVersionView.setNewPublisher(true);
157 - publisherVersionView.setPublisherVersionId(1); 157 + publisherVersionView.setStringId("1");
158 - publisherVersionView.loadData(); 158 + publisherVersionView.init();
159 assertThat(publisherVersionView.getPublisherName()).isEqualTo("A"); 159 assertThat(publisherVersionView.getPublisherName()).isEqualTo("A");
160 assertThat(publisherVersionView.getStreetAddress()).isEqualTo("B"); 160 assertThat(publisherVersionView.getStreetAddress()).isEqualTo("B");
161 assertThat(publisherVersionView.getPostalCode()).isEqualTo("C"); 161 assertThat(publisherVersionView.getPostalCode()).isEqualTo("C");
...@@ -173,8 +173,8 @@ public class PublisherVersionViewTest { ...@@ -173,8 +173,8 @@ public class PublisherVersionViewTest {
173 @DisplayName("when called for new publisher, should set form for new version") 173 @DisplayName("when called for new publisher, should set form for new version")
174 public void testLoadDataEmpty() { 174 public void testLoadDataEmpty() {
175 publisherVersionView.setNewPublisher(false); 175 publisherVersionView.setNewPublisher(false);
176 - publisherVersionView.setPublisherVersionId(0); 176 + publisherVersionView.setStringId("0");
177 - publisherVersionView.loadData(); 177 + publisherVersionView.init();
178 assertThat(publisherVersionView.isNewPublisher()).isTrue(); 178 assertThat(publisherVersionView.isNewPublisher()).isTrue();
179 assertThat(publisherVersionView.isEditMode()).isTrue(); 179 assertThat(publisherVersionView.isEditMode()).isTrue();
180 } 180 }
......