Jean-Francois Leveque

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

package org.legrog.configuration;
import org.ocpsoft.rewrite.annotation.RewriteConfiguration;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;
import javax.servlet.ServletContext;
/**
* Rewrite configuration provider
*/
@RewriteConfiguration
public class RewriteConfigurationProvider extends HttpConfigurationProvider
{
@Override
public int priority()
{
return 10;
}
@Override
public Configuration getConfiguration(final ServletContext context)
{
return ConfigurationBuilder.begin();
}
}
\ No newline at end of file
......@@ -3,10 +3,14 @@ package org.legrog.web.publisher;
import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherAction;
import org.legrog.entities.PublisherVersion;
import org.ocpsoft.rewrite.annotation.Join;
import org.ocpsoft.rewrite.annotation.Parameter;
import org.ocpsoft.rewrite.annotation.RequestAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.faces.view.ViewScoped;
import javax.enterprise.context.RequestScoped;
//import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
......@@ -19,17 +23,50 @@ import java.util.stream.Collectors;
* Permet de voir l'ensemble des versions d'un éditeur et de valider l'une d'elles.
*/
@Named
@ViewScoped
@RequestScoped
@Join(path = "/ListPublisherVersions/{stringId}", to = "/publisher/listPublisherVersions.jsf")
public class ListPublisherVersionsView implements Serializable {
@Parameter
String stringId;
private Integer publisherId;
transient Logger logger = LoggerFactory.getLogger(getClass());
protected transient PublisherService publisherService;
private Integer publisherId;
private boolean viewAll;
private transient List<PublisherVersion> publisherVersions;
@RequestAction
public void init() {
if (stringId != null) {
try {
publisherId = new Integer(stringId);
} catch (NumberFormatException ne) {
publisherId = null;
}
} else {
publisherId = null;
}
logger.trace("setView : publisherId = {}", publisherId);
publisherVersions = publisherService.getAllPublisherVersions();
viewAll = publisherId == null;
if (!viewAll) {
logger.trace("setView : !viewAll");
filterOnID();
}
}
protected void filterOnID() {
publisherVersions = publisherVersions.stream()
.filter(version -> version.getPublisher().getPublisherId() == publisherId)
.collect(Collectors.toList());
}
/**
* Uses PublisherService to access data
*
......@@ -55,23 +92,10 @@ public class ListPublisherVersionsView implements Serializable {
}
// View Action being executed at view loading
/*
public void setView() {
logger.trace("setView : publisherId = {}", publisherId);
publisherVersions = publisherService.getAllPublisherVersions();
viewAll = publisherId == null;
if (!viewAll) {
logger.trace("setView : !viewAll");
filterOnID();
}
}
protected void filterOnID() {
publisherVersions = publisherVersions.stream()
.filter(version -> version.getPublisher().getPublisherId() == publisherId)
.collect(Collectors.toList());
}
*/
/**
* Validates a PublisherVersion for its Publisher
*
......@@ -86,6 +110,13 @@ public class ListPublisherVersionsView implements Serializable {
filterOnID();
}
public String getStringId() {
return stringId;
}
public void setStringId(String stringId) {
this.stringId = stringId;
}
public PublisherService getPublisherService() {
return publisherService;
......
......@@ -5,10 +5,6 @@
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:metadata>
<f:viewParam name="publisherId" value="#{listPublisherVersionsView.publisherId}"/>
<f:viewAction action="#{listPublisherVersionsView.setView}"/>
</f:metadata>
<head>
<link rel="stylesheet" type="text/css" href="/minimal.css"/>
</head>
......@@ -36,9 +32,7 @@
</h:column>
<h:column rendered="#{listPublisherVersionsView.viewAll}">
<f:facet name="header"/>
<a jsf:outcome="listPublisherVersions">Visualiser ou valider version éditeur
<f:param name="publisherId" value="#{version.publisher.publisherId}"/>
</a>
<a jsf:outcome="/ListPublisherVersions/#{version.publisher.publisherId}">Visualiser ou valider version éditeur</a>
</h:column>
<h:column>
<f:facet name="header"/>
......
......@@ -78,7 +78,7 @@ public class ListPublisherVersionsViewTest {
@DisplayName("when publisher is not set, should list all versions")
public void testSetViewAll() {
listPublisherVersionsView.setPublisherId(null);
listPublisherVersionsView.setView();
listPublisherVersionsView.init();
Mockito.verify(publisherService).getAllPublisherVersions();
assertThat(listPublisherVersionsView.isViewAll()).isTrue();
assertThat(listPublisherVersionsView.getPublisherVersions()).isEqualTo(publisherVersions);
......@@ -87,8 +87,8 @@ public class ListPublisherVersionsViewTest {
@Test
@DisplayName("when publisher is set, should list pulisher's versions")
public void testSetViewNotAllAlsoTestingFilterOnId() {
listPublisherVersionsView.setPublisherId(1);
listPublisherVersionsView.setView();
listPublisherVersionsView.setStringId("1");
listPublisherVersionsView.init();
Mockito.verify(publisherService).getAllPublisherVersions();
assertThat(listPublisherVersionsView.isViewAll()).isFalse();
assertThat(listPublisherVersionsView.getPublisherVersions()).containsExactly(publisherVersion1);
......