Jean-Francois Leveque

Refactoring de la validation d'une version.

package org.legrog.web.publisher;
import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -37,12 +36,11 @@ public class ListPublisherVersionsView implements Serializable {
// View Action being executed at view loading
public void setView() {
logger.trace("setView");
logger.debug("publisherId = {}", publisherId);
logger.trace("setView : publisherId = {}", publisherId);
publisherVersions = publisherService.getAllPublisherVersions();
viewAll = ( publisherId == null ) ;
if (!viewAll) {
logger.trace("!viewAll");
logger.trace("setView : !viewAll");
filterOnID();
}
}
......@@ -54,16 +52,13 @@ public class ListPublisherVersionsView implements Serializable {
}
public void validate(Integer publisherVersionId) {
public void validate(PublisherVersion publisherVersion) {
logger.trace("validate");
Publisher publisher = publisherService.getPublisher(publisherId);
logger.debug("publisher (pre-validate) = {}", publisher);
publisherService.validatePublisherVersion(publisher, publisherVersionId);
publisherService.validatePublisherVersion(publisherVersion);
publisherVersions = publisherService.getAllPublisherVersions();
filterOnID();
logger.debug("publisher (post-validate) = {}", publisher);
}
/** no args constructor to make it proxyable */
......@@ -101,4 +96,9 @@ public class ListPublisherVersionsView implements Serializable {
public void setPublisherVersions(List<PublisherVersion> publisherVersions) {
this.publisherVersions = publisherVersions;
}
@Override
public String toString() {
return "publisherId = " + publisherId + ", viewAll = " + viewAll + ", publisherVersions = " + publisherVersions;
}
}
\ No newline at end of file
......
......@@ -15,9 +15,7 @@ public interface PublisherService {
void addVersionToPublisher(Publisher publisher, PublisherVersion publisherVersion);
void validatePublisherVersion(Publisher publisher, Integer publisherVersionId);
Publisher getPublisher(Integer publisherId);
void validatePublisherVersion(PublisherVersion publisherVersion);
List<PublisherVersion> getAllPublisherVersions();
......
......@@ -35,7 +35,7 @@ public class PublisherServiceSpring implements PublisherService {
SharedService sharedService;
public void addPublisherWithVersion(Publisher publisher, PublisherVersion publisherVersion) {
Set<PublisherVersion> publisherVersions = new HashSet<PublisherVersion>();
Set<PublisherVersion> publisherVersions = new HashSet<>();
publisherVersions.add(publisherVersion);
publisher.setVersions(publisherVersions);
publisherVersion.setPublisher(publisher);
......@@ -58,8 +58,9 @@ public class PublisherServiceSpring implements PublisherService {
logger.trace("fin addVersionToPublisher, publisherVersion = {}", publisherVersion);
}
public void validatePublisherVersion(Publisher publisher, Integer publisherVersionId) {
publisher.setValidatedVersion(this.getPublisherVersion(publisherVersionId));
public void validatePublisherVersion(PublisherVersion publisherVersion) {
Publisher publisher = publisherVersion.getPublisher();
publisher.setValidatedVersion(publisherVersion);
publisher.setValidator(sharedService.getCurrentUser());
publisher.setValidationDateTime(new Timestamp(new Date().getTime()));
this.savePublisher(publisher);
......@@ -82,8 +83,4 @@ public class PublisherServiceSpring implements PublisherService {
return publisherVersionRepository.findOne(publisherVersionId);
}
public Publisher getPublisher(Integer publisherId) {
return publisherRepository.findOne(publisherId);
}
}
......
......@@ -51,7 +51,7 @@
<p jsf:rendered="#{listPublisherVersionsView.viewAll and version.publisherVersionId != version.publisher.validatedVersion.publisherVersionId}">Non validé</p>
<!-- https://www.mkyong.com/jsf2/4-ways-to-pass-parameter-from-jsf-page-to-backing-bean/ f:param, problème avec Method expression -->
<form action="" jsf:rendered="#{not listPublisherVersionsView.viewAll and version.publisherVersionId != version.publisher.validatedVersion.publisherVersionId}">
<button jsf:action="#{listPublisherVersionsView.validate(version.publisherVersionId)}">Valider
<button jsf:action="#{listPublisherVersionsView.validate(version)}">Valider
</button>
</form>
</h:column>
......