Jean-Francois Leveque

Refactoring de la validation d'une version.

1 package org.legrog.web.publisher; 1 package org.legrog.web.publisher;
2 2
3 -import org.legrog.entities.Publisher;
4 import org.legrog.entities.PublisherVersion; 3 import org.legrog.entities.PublisherVersion;
5 import org.slf4j.Logger; 4 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory; 5 import org.slf4j.LoggerFactory;
...@@ -37,12 +36,11 @@ public class ListPublisherVersionsView implements Serializable { ...@@ -37,12 +36,11 @@ public class ListPublisherVersionsView implements Serializable {
37 36
38 // View Action being executed at view loading 37 // View Action being executed at view loading
39 public void setView() { 38 public void setView() {
40 - logger.trace("setView"); 39 + logger.trace("setView : publisherId = {}", publisherId);
41 - logger.debug("publisherId = {}", publisherId);
42 publisherVersions = publisherService.getAllPublisherVersions(); 40 publisherVersions = publisherService.getAllPublisherVersions();
43 viewAll = ( publisherId == null ) ; 41 viewAll = ( publisherId == null ) ;
44 if (!viewAll) { 42 if (!viewAll) {
45 - logger.trace("!viewAll"); 43 + logger.trace("setView : !viewAll");
46 filterOnID(); 44 filterOnID();
47 } 45 }
48 } 46 }
...@@ -54,16 +52,13 @@ public class ListPublisherVersionsView implements Serializable { ...@@ -54,16 +52,13 @@ public class ListPublisherVersionsView implements Serializable {
54 52
55 } 53 }
56 54
57 - public void validate(Integer publisherVersionId) { 55 + public void validate(PublisherVersion publisherVersion) {
58 logger.trace("validate"); 56 logger.trace("validate");
59 - Publisher publisher = publisherService.getPublisher(publisherId);
60 - logger.debug("publisher (pre-validate) = {}", publisher);
61 57
62 - publisherService.validatePublisherVersion(publisher, publisherVersionId); 58 + publisherService.validatePublisherVersion(publisherVersion);
63 59
64 publisherVersions = publisherService.getAllPublisherVersions(); 60 publisherVersions = publisherService.getAllPublisherVersions();
65 filterOnID(); 61 filterOnID();
66 - logger.debug("publisher (post-validate) = {}", publisher);
67 } 62 }
68 63
69 /** no args constructor to make it proxyable */ 64 /** no args constructor to make it proxyable */
...@@ -101,4 +96,9 @@ public class ListPublisherVersionsView implements Serializable { ...@@ -101,4 +96,9 @@ public class ListPublisherVersionsView implements Serializable {
101 public void setPublisherVersions(List<PublisherVersion> publisherVersions) { 96 public void setPublisherVersions(List<PublisherVersion> publisherVersions) {
102 this.publisherVersions = publisherVersions; 97 this.publisherVersions = publisherVersions;
103 } 98 }
99 +
100 + @Override
101 + public String toString() {
102 + return "publisherId = " + publisherId + ", viewAll = " + viewAll + ", publisherVersions = " + publisherVersions;
103 + }
104 } 104 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -15,9 +15,7 @@ public interface PublisherService { ...@@ -15,9 +15,7 @@ public interface PublisherService {
15 15
16 void addVersionToPublisher(Publisher publisher, PublisherVersion publisherVersion); 16 void addVersionToPublisher(Publisher publisher, PublisherVersion publisherVersion);
17 17
18 - void validatePublisherVersion(Publisher publisher, Integer publisherVersionId); 18 + void validatePublisherVersion(PublisherVersion publisherVersion);
19 -
20 - Publisher getPublisher(Integer publisherId);
21 19
22 List<PublisherVersion> getAllPublisherVersions(); 20 List<PublisherVersion> getAllPublisherVersions();
23 21
......
...@@ -35,7 +35,7 @@ public class PublisherServiceSpring implements PublisherService { ...@@ -35,7 +35,7 @@ public class PublisherServiceSpring implements PublisherService {
35 SharedService sharedService; 35 SharedService sharedService;
36 36
37 public void addPublisherWithVersion(Publisher publisher, PublisherVersion publisherVersion) { 37 public void addPublisherWithVersion(Publisher publisher, PublisherVersion publisherVersion) {
38 - Set<PublisherVersion> publisherVersions = new HashSet<PublisherVersion>(); 38 + Set<PublisherVersion> publisherVersions = new HashSet<>();
39 publisherVersions.add(publisherVersion); 39 publisherVersions.add(publisherVersion);
40 publisher.setVersions(publisherVersions); 40 publisher.setVersions(publisherVersions);
41 publisherVersion.setPublisher(publisher); 41 publisherVersion.setPublisher(publisher);
...@@ -58,8 +58,9 @@ public class PublisherServiceSpring implements PublisherService { ...@@ -58,8 +58,9 @@ public class PublisherServiceSpring implements PublisherService {
58 logger.trace("fin addVersionToPublisher, publisherVersion = {}", publisherVersion); 58 logger.trace("fin addVersionToPublisher, publisherVersion = {}", publisherVersion);
59 } 59 }
60 60
61 - public void validatePublisherVersion(Publisher publisher, Integer publisherVersionId) { 61 + public void validatePublisherVersion(PublisherVersion publisherVersion) {
62 - publisher.setValidatedVersion(this.getPublisherVersion(publisherVersionId)); 62 + Publisher publisher = publisherVersion.getPublisher();
63 + publisher.setValidatedVersion(publisherVersion);
63 publisher.setValidator(sharedService.getCurrentUser()); 64 publisher.setValidator(sharedService.getCurrentUser());
64 publisher.setValidationDateTime(new Timestamp(new Date().getTime())); 65 publisher.setValidationDateTime(new Timestamp(new Date().getTime()));
65 this.savePublisher(publisher); 66 this.savePublisher(publisher);
...@@ -82,8 +83,4 @@ public class PublisherServiceSpring implements PublisherService { ...@@ -82,8 +83,4 @@ public class PublisherServiceSpring implements PublisherService {
82 return publisherVersionRepository.findOne(publisherVersionId); 83 return publisherVersionRepository.findOne(publisherVersionId);
83 } 84 }
84 85
85 - public Publisher getPublisher(Integer publisherId) {
86 - return publisherRepository.findOne(publisherId);
87 - }
88 -
89 } 86 }
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
51 <p jsf:rendered="#{listPublisherVersionsView.viewAll and version.publisherVersionId != version.publisher.validatedVersion.publisherVersionId}">Non validé</p> 51 <p jsf:rendered="#{listPublisherVersionsView.viewAll and version.publisherVersionId != version.publisher.validatedVersion.publisherVersionId}">Non validé</p>
52 <!-- https://www.mkyong.com/jsf2/4-ways-to-pass-parameter-from-jsf-page-to-backing-bean/ f:param, problème avec Method expression --> 52 <!-- https://www.mkyong.com/jsf2/4-ways-to-pass-parameter-from-jsf-page-to-backing-bean/ f:param, problème avec Method expression -->
53 <form action="" jsf:rendered="#{not listPublisherVersionsView.viewAll and version.publisherVersionId != version.publisher.validatedVersion.publisherVersionId}"> 53 <form action="" jsf:rendered="#{not listPublisherVersionsView.viewAll and version.publisherVersionId != version.publisher.validatedVersion.publisherVersionId}">
54 - <button jsf:action="#{listPublisherVersionsView.validate(version.publisherVersionId)}">Valider 54 + <button jsf:action="#{listPublisherVersionsView.validate(version)}">Valider
55 </button> 55 </button>
56 </form> 56 </form>
57 </h:column> 57 </h:column>
......