Jean-Francois Leveque

Passage de PublisherVersion (vue et page) en Rewrite

......@@ -2,10 +2,14 @@ package org.legrog.web.publisher;
import org.legrog.entities.*;
import org.legrog.web.xyz.SharedService;
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;
......@@ -20,8 +24,12 @@ import java.util.List;
* Update creates a new PublisherVersion linked to the Publisher
*/
@Named
@ViewScoped
@RequestScoped
@Join(path = "/PublisherVersion/{stringId}", to = "/publisher/publisherVersion.jsf")
public class PublisherVersionView implements Serializable {
@Parameter
String stringId;
transient Logger logger = LoggerFactory.getLogger(getClass());
transient PublisherService publisherService;
......@@ -68,11 +76,58 @@ public class PublisherVersionView implements Serializable {
}
/**
* Loads countries
* Loads countries and adapts to availability of parameter
*/
@PostConstruct
@RequestAction
public void init() {
availableCountries = sharedService.getAllCountries();
PublisherVersion publisherVersion = null;
logger.debug("stringId = {}", this.stringId);
if (stringId != null) {
try {
publisherVersionId = Integer.parseInt(stringId);
} catch (NumberFormatException ne) {
publisherVersionId = 0;
}
} else {
publisherVersionId = 0;
}
if (publisherVersionId != 0) {
publisherVersion = publisherService.getPublisherVersion(publisherVersionId);
publisherActions = publisherService.getAllPublisherVersionActions(publisherVersion);
}
if (publisherVersion != null) {
logger.debug("Found a publisher version : {}", publisherVersion.toString());
publisherName = publisherVersion.getPublisherName();
streetAddress = publisherVersion.getPublisherStreetAddress();
postalCode = publisherVersion.getPublisherPostalCode();
postOfficeBoxNumber = publisherVersion.getPublisherPostOfficeBoxNumber();
addressRegion = publisherVersion.getPublisherAddressRegion();
addressLocality = publisherVersion.getPublisherAddressLocality();
publisherAddressCountry = publisherVersion.getPublisherAddressCountry();
telephone = publisherVersion.getPublisherTelephone();
email = publisherVersion.getPublisherEmail();
uRL = publisherVersion.getPublisherURL();
publisherHistory = publisherVersion.getPublisherHistory();
publisher = publisherVersion.getPublisher();
getImmutableValues();
logger.debug("Found a publisher : {}", publisher.toString());
newPublisher = false;
} else {
logger.debug("No publisher.");
editMode = true;
newPublisher = true;
}
}
/**
......@@ -87,7 +142,7 @@ public class PublisherVersionView implements Serializable {
*/
public void cancel() {
if (!newPublisher) {
loadData();
init();
editMode = false;
} else {
publisherName = null;
......@@ -182,45 +237,6 @@ public class PublisherVersionView implements Serializable {
logger.trace("fin update, après récupération, publisherVersion = {}", publisherVersion);
}
public void loadData() {
PublisherVersion publisherVersion = null;
logger.debug("publisherVersionId = {}", this.publisherVersionId);
if (publisherVersionId != 0) {
publisherVersion = publisherService.getPublisherVersion(publisherVersionId);
publisherActions = publisherService.getAllPublisherVersionActions(publisherVersion);
}
if (publisherVersion != null) {
logger.debug("Found a publisher version : {}", publisherVersion.toString());
publisherName = publisherVersion.getPublisherName();
streetAddress = publisherVersion.getPublisherStreetAddress();
postalCode = publisherVersion.getPublisherPostalCode();
postOfficeBoxNumber = publisherVersion.getPublisherPostOfficeBoxNumber();
addressRegion = publisherVersion.getPublisherAddressRegion();
addressLocality = publisherVersion.getPublisherAddressLocality();
publisherAddressCountry = publisherVersion.getPublisherAddressCountry();
telephone = publisherVersion.getPublisherTelephone();
email = publisherVersion.getPublisherEmail();
uRL = publisherVersion.getPublisherURL();
publisherHistory = publisherVersion.getPublisherHistory();
publisher = publisherVersion.getPublisher();
getImmutableValues();
logger.debug("Found a publisher : {}", publisher.toString());
newPublisher = false;
} else {
logger.debug("No publisher.");
editMode = true;
newPublisher = true;
}
}
// Accessors
public int getPublisherVersionId() {
return publisherVersionId;
......@@ -369,4 +385,12 @@ public class PublisherVersionView implements Serializable {
public List<PublisherAction> getPublisherActions() {
return publisherActions;
}
public String getStringId() {
return stringId;
}
public void setStringId(String stringId) {
this.stringId = stringId;
}
}
......
......@@ -26,9 +26,7 @@
<h:dataTable value="#{listPublisherVersionsView.publisherVersions}" var="version">
<h:column>
<f:facet name="header"/>
<a jsf:outcome="publisherVersion">Visualiser ou Modifier Version
<f:param name="publisherVersionId" value="#{version.publisherVersionId}"/>
</a>
<a jsf:value="/PublisherVersion/${version.publisherVersionId}">Visualiser ou Modifier Version</a>
</h:column>
<h:column rendered="#{listPublisherVersionsView.viewAll}">
<f:facet name="header"/>
......
......@@ -7,10 +7,6 @@
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:jsf="http://xmlns.jcp.org/jsf">
<head>
<f:metadata>
<f:viewParam name="publisherVersionId" value="#{publisherVersionView.publisherVersionId}" />
<f:viewAction action="#{publisherVersionView.loadData}" />
</f:metadata>
</head>
<body>
......@@ -54,7 +50,7 @@
<input type="text" id="uRL" jsf:value='#{publisherVersionView.uRL}' jsf:disabled="#{not publisherVersionView.editMode}"/>
<label for="publisherHistory">publisherHistory</label>
<textarea id="publisherHistory" rows="" cols="" jsf:disabled="#{not publisherVersionView.editMode}" jsf:value="#{publisherVersionView.publisherHistory}"/>
<textarea id="publisherHistory" rows="20" cols="200" jsf:disabled="#{not publisherVersionView.editMode}" jsf:value="#{publisherVersionView.publisherHistory}"/>
<div jsf:rendered="#{not publisherVersionView.newPublisher}">publisherVersionAuthor</div>
<div jsf:rendered="#{not publisherVersionView.newPublisher}">#{publisherVersionView.publisherVersionAuthor.displayName}</div>
......
......@@ -108,7 +108,7 @@ public class PublisherVersionViewTest {
@Test
public void testCancelNewVersionOfPublisher() {
publisherVersionView.setNewPublisher(false);
publisherVersionView.setPublisherVersionId(1);
publisherVersionView.setStringId("1");
publisherVersionView.setPublisherName("1");
publisherVersionView.setStreetAddress("2");
......@@ -139,14 +139,14 @@ public class PublisherVersionViewTest {
}
@Nested
@DisplayName("loadData method")
@DisplayName("init method")
class LoadDataTests{
@Test
@DisplayName("Loads all actions on it")
public void testLoadActions(@Mock PublisherService publisherService) {
publisherVersionView.setPublisherVersionId(1);
publisherVersionView.loadData();
publisherVersionView.setStringId("1");
publisherVersionView.init();
Mockito.verify(publisherService).getAllPublisherVersionActions(publisherVersion);
}
......@@ -154,8 +154,8 @@ public class PublisherVersionViewTest {
@DisplayName("when called for existing publisher, should get the rigtht data into the form")
public void testLoadData() {
publisherVersionView.setNewPublisher(true);
publisherVersionView.setPublisherVersionId(1);
publisherVersionView.loadData();
publisherVersionView.setStringId("1");
publisherVersionView.init();
assertThat(publisherVersionView.getPublisherName()).isEqualTo("A");
assertThat(publisherVersionView.getStreetAddress()).isEqualTo("B");
assertThat(publisherVersionView.getPostalCode()).isEqualTo("C");
......@@ -173,8 +173,8 @@ public class PublisherVersionViewTest {
@DisplayName("when called for new publisher, should set form for new version")
public void testLoadDataEmpty() {
publisherVersionView.setNewPublisher(false);
publisherVersionView.setPublisherVersionId(0);
publisherVersionView.loadData();
publisherVersionView.setStringId("0");
publisherVersionView.init();
assertThat(publisherVersionView.isNewPublisher()).isTrue();
assertThat(publisherVersionView.isEditMode()).isTrue();
}
......