Jean-Francois Leveque

Problème lors du passage à Rewrite : la liste complète ne fonctionne plus.

1 +package org.legrog.configuration;
2 +
3 +import org.ocpsoft.rewrite.annotation.RewriteConfiguration;
4 +import org.ocpsoft.rewrite.config.Configuration;
5 +import org.ocpsoft.rewrite.config.ConfigurationBuilder;
6 +import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;
7 +
8 +import javax.servlet.ServletContext;
9 +
10 +/**
11 + * Rewrite configuration provider
12 + */
13 +@RewriteConfiguration
14 +public class RewriteConfigurationProvider extends HttpConfigurationProvider
15 +{
16 + @Override
17 + public int priority()
18 + {
19 + return 10;
20 + }
21 +
22 + @Override
23 + public Configuration getConfiguration(final ServletContext context)
24 + {
25 + return ConfigurationBuilder.begin();
26 + }
27 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -3,10 +3,14 @@ package org.legrog.web.publisher; ...@@ -3,10 +3,14 @@ package org.legrog.web.publisher;
3 import org.legrog.entities.Publisher; 3 import org.legrog.entities.Publisher;
4 import org.legrog.entities.PublisherAction; 4 import org.legrog.entities.PublisherAction;
5 import org.legrog.entities.PublisherVersion; 5 import org.legrog.entities.PublisherVersion;
6 +import org.ocpsoft.rewrite.annotation.Join;
7 +import org.ocpsoft.rewrite.annotation.Parameter;
8 +import org.ocpsoft.rewrite.annotation.RequestAction;
6 import org.slf4j.Logger; 9 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory; 10 import org.slf4j.LoggerFactory;
8 11
9 -import javax.faces.view.ViewScoped; 12 +import javax.enterprise.context.RequestScoped;
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;
12 import java.io.Serializable; 16 import java.io.Serializable;
...@@ -19,22 +23,55 @@ import java.util.stream.Collectors; ...@@ -19,22 +23,55 @@ import java.util.stream.Collectors;
19 * Permet de voir l'ensemble des versions d'un éditeur et de valider l'une d'elles. 23 * Permet de voir l'ensemble des versions d'un éditeur et de valider l'une d'elles.
20 */ 24 */
21 @Named 25 @Named
22 -@ViewScoped 26 +@RequestScoped
27 +@Join(path = "/ListPublisherVersions/{stringId}", to = "/publisher/listPublisherVersions.jsf")
23 public class ListPublisherVersionsView implements Serializable { 28 public class ListPublisherVersionsView implements Serializable {
24 29
30 + @Parameter
31 + String stringId;
32 +
33 + private Integer publisherId;
34 +
25 transient Logger logger = LoggerFactory.getLogger(getClass()); 35 transient Logger logger = LoggerFactory.getLogger(getClass());
26 36
27 protected transient PublisherService publisherService; 37 protected transient PublisherService publisherService;
28 38
29 - private Integer publisherId;
30 private boolean viewAll; 39 private boolean viewAll;
31 private transient List<PublisherVersion> publisherVersions; 40 private transient List<PublisherVersion> publisherVersions;
32 41
42 + @RequestAction
43 + public void init() {
44 +
45 + if (stringId != null) {
46 + try {
47 + publisherId = new Integer(stringId);
48 + } catch (NumberFormatException ne) {
49 + publisherId = null;
50 + }
51 + } else {
52 + publisherId = null;
53 + }
54 +
55 + logger.trace("setView : publisherId = {}", publisherId);
56 + publisherVersions = publisherService.getAllPublisherVersions();
57 + viewAll = publisherId == null;
58 + if (!viewAll) {
59 + logger.trace("setView : !viewAll");
60 + filterOnID();
61 + }
62 + }
63 +
64 + protected void filterOnID() {
65 + publisherVersions = publisherVersions.stream()
66 + .filter(version -> version.getPublisher().getPublisherId() == publisherId)
67 + .collect(Collectors.toList());
68 + }
69 +
33 /** 70 /**
34 - * Uses PublisherService to access data 71 + * Uses PublisherService to access data
35 - * 72 + *
36 - * @param publisherService 73 + * @param publisherService
37 - */ 74 + */
38 @Inject 75 @Inject
39 public ListPublisherVersionsView(PublisherService publisherService) { 76 public ListPublisherVersionsView(PublisherService publisherService) {
40 this.publisherService = publisherService; 77 this.publisherService = publisherService;
...@@ -55,23 +92,10 @@ public class ListPublisherVersionsView implements Serializable { ...@@ -55,23 +92,10 @@ public class ListPublisherVersionsView implements Serializable {
55 } 92 }
56 93
57 // View Action being executed at view loading 94 // View Action being executed at view loading
95 + /*
58 public void setView() { 96 public void setView() {
59 - logger.trace("setView : publisherId = {}", publisherId);
60 - publisherVersions = publisherService.getAllPublisherVersions();
61 - viewAll = publisherId == null;
62 - if (!viewAll) {
63 - logger.trace("setView : !viewAll");
64 - filterOnID();
65 - }
66 - }
67 -
68 - protected void filterOnID() {
69 - publisherVersions = publisherVersions.stream()
70 - .filter(version -> version.getPublisher().getPublisherId() == publisherId)
71 - .collect(Collectors.toList());
72 -
73 } 97 }
74 - 98 +*/
75 /** 99 /**
76 * Validates a PublisherVersion for its Publisher 100 * Validates a PublisherVersion for its Publisher
77 * 101 *
...@@ -86,6 +110,13 @@ public class ListPublisherVersionsView implements Serializable { ...@@ -86,6 +110,13 @@ public class ListPublisherVersionsView implements Serializable {
86 filterOnID(); 110 filterOnID();
87 } 111 }
88 112
113 + public String getStringId() {
114 + return stringId;
115 + }
116 +
117 + public void setStringId(String stringId) {
118 + this.stringId = stringId;
119 + }
89 120
90 public PublisherService getPublisherService() { 121 public PublisherService getPublisherService() {
91 return publisherService; 122 return publisherService;
......
...@@ -5,10 +5,6 @@ ...@@ -5,10 +5,6 @@
5 xmlns:h="http://xmlns.jcp.org/jsf/html" 5 xmlns:h="http://xmlns.jcp.org/jsf/html"
6 xmlns:jsf="http://xmlns.jcp.org/jsf" 6 xmlns:jsf="http://xmlns.jcp.org/jsf"
7 xmlns:f="http://xmlns.jcp.org/jsf/core"> 7 xmlns:f="http://xmlns.jcp.org/jsf/core">
8 -<f:metadata>
9 - <f:viewParam name="publisherId" value="#{listPublisherVersionsView.publisherId}"/>
10 - <f:viewAction action="#{listPublisherVersionsView.setView}"/>
11 -</f:metadata>
12 <head> 8 <head>
13 <link rel="stylesheet" type="text/css" href="/minimal.css"/> 9 <link rel="stylesheet" type="text/css" href="/minimal.css"/>
14 </head> 10 </head>
...@@ -36,9 +32,7 @@ ...@@ -36,9 +32,7 @@
36 </h:column> 32 </h:column>
37 <h:column rendered="#{listPublisherVersionsView.viewAll}"> 33 <h:column rendered="#{listPublisherVersionsView.viewAll}">
38 <f:facet name="header"/> 34 <f:facet name="header"/>
39 - <a jsf:outcome="listPublisherVersions">Visualiser ou valider version éditeur 35 + <a jsf:outcome="/ListPublisherVersions/#{version.publisher.publisherId}">Visualiser ou valider version éditeur</a>
40 - <f:param name="publisherId" value="#{version.publisher.publisherId}"/>
41 - </a>
42 </h:column> 36 </h:column>
43 <h:column> 37 <h:column>
44 <f:facet name="header"/> 38 <f:facet name="header"/>
......
...@@ -78,7 +78,7 @@ public class ListPublisherVersionsViewTest { ...@@ -78,7 +78,7 @@ public class ListPublisherVersionsViewTest {
78 @DisplayName("when publisher is not set, should list all versions") 78 @DisplayName("when publisher is not set, should list all versions")
79 public void testSetViewAll() { 79 public void testSetViewAll() {
80 listPublisherVersionsView.setPublisherId(null); 80 listPublisherVersionsView.setPublisherId(null);
81 - listPublisherVersionsView.setView(); 81 + listPublisherVersionsView.init();
82 Mockito.verify(publisherService).getAllPublisherVersions(); 82 Mockito.verify(publisherService).getAllPublisherVersions();
83 assertThat(listPublisherVersionsView.isViewAll()).isTrue(); 83 assertThat(listPublisherVersionsView.isViewAll()).isTrue();
84 assertThat(listPublisherVersionsView.getPublisherVersions()).isEqualTo(publisherVersions); 84 assertThat(listPublisherVersionsView.getPublisherVersions()).isEqualTo(publisherVersions);
...@@ -87,8 +87,8 @@ public class ListPublisherVersionsViewTest { ...@@ -87,8 +87,8 @@ public class ListPublisherVersionsViewTest {
87 @Test 87 @Test
88 @DisplayName("when publisher is set, should list pulisher's versions") 88 @DisplayName("when publisher is set, should list pulisher's versions")
89 public void testSetViewNotAllAlsoTestingFilterOnId() { 89 public void testSetViewNotAllAlsoTestingFilterOnId() {
90 - listPublisherVersionsView.setPublisherId(1); 90 + listPublisherVersionsView.setStringId("1");
91 - listPublisherVersionsView.setView(); 91 + listPublisherVersionsView.init();
92 Mockito.verify(publisherService).getAllPublisherVersions(); 92 Mockito.verify(publisherService).getAllPublisherVersions();
93 assertThat(listPublisherVersionsView.isViewAll()).isFalse(); 93 assertThat(listPublisherVersionsView.isViewAll()).isFalse();
94 assertThat(listPublisherVersionsView.getPublisherVersions()).containsExactly(publisherVersion1); 94 assertThat(listPublisherVersionsView.getPublisherVersions()).containsExactly(publisherVersion1);
......