Jean-Francois Leveque

ListPublisherActions en Rewrite

package org.legrog.web.publisher;
import org.legrog.entities.PublisherAction;
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.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
......@@ -17,9 +22,13 @@ import java.util.stream.Collectors;
* Permet de voir l'ensemble des actions d'un éditeur.
*/
@Named
@ViewScoped
@RequestScoped
@Join(path = "/ListPublisherActions/{stringId}", to = "/publisher/listPublisherActions.jsf")
public class ListPublisherActionsView implements Serializable {
@Parameter
String stringId;
transient Logger logger = LoggerFactory.getLogger(getClass());
protected transient PublisherService publisherService;
......@@ -41,13 +50,23 @@ public class ListPublisherActionsView implements Serializable {
ListPublisherActionsView() {
//no args constructor to make it proxyable
}
@PostConstruct
@RequestAction
public void init() {
if (stringId != null) {
try {
publisherId = new Integer(stringId);
} catch (NumberFormatException ne) {
publisherId = null;
}
} else {
publisherId = null;
}
public void setView() {
logger.trace("setView : publisherId = {}", publisherId);
publisherActions = publisherService.getAllPublisherActions();
viewAll = publisherId == null;
if (!viewAll) {
logger.trace("setView : !viewAll");
filterOnID();
}
}
......@@ -81,4 +100,12 @@ public class ListPublisherActionsView implements Serializable {
public void setPublisherActions(List<PublisherAction> publisherActions) {
this.publisherActions = publisherActions;
}
public String getStringId() {
return stringId;
}
public void setStringId(String stringId) {
this.stringId = stringId;
}
}
......
......@@ -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="#{listPublisherActionsView.publisherId}"/>
<f:viewAction action="#{listPublisherActionsView.setView}"/>
</f:metadata>
<head>
<link rel="stylesheet" type="text/css" href="/minimal.css"/>
</head>
......
......@@ -48,7 +48,7 @@ public class ListPublisherActionsViewTest {
public void showAll(@Mock PublisherService publisherServiceMock) {
listPublisherActionsView.setPublisherId(null);
listPublisherActionsView.setViewAll(false);
listPublisherActionsView.setView();
listPublisherActionsView.init();
Mockito.verify(publisherServiceMock).getAllPublisherActions();
assertThat(listPublisherActionsView.isViewAll()).isTrue();
assertThat(filtered).isFalse();
......@@ -57,9 +57,9 @@ public class ListPublisherActionsViewTest {
@Test
@DisplayName("when publisher is set, should be in filtered not all actions state")
public void showFiltered(@Mock PublisherService publisherServiceMock) {
listPublisherActionsView.setPublisherId(1);
listPublisherActionsView.setStringId("1");
listPublisherActionsView.setViewAll(true);
listPublisherActionsView.setView();
listPublisherActionsView.init();
Mockito.verify(publisherServiceMock).getAllPublisherActions();
assertThat(listPublisherActionsView.isViewAll()).isFalse();
assertThat(filtered).isTrue();
......