JR Utily
Committed by Jean-Francois Leveque

petit refactoriing (injection par constructeur)

filter avec un stream
+
configuration du compilateur en java 8 dans le pom pour avoir les lambdas
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
36 <debug.jvm.args /> 36 <debug.jvm.args />
37 <tomee.autoreload /> 37 <tomee.autoreload />
38 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 38 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
39 + <maven.compiler.source>1.8</maven.compiler.source>
40 + <maven.compiler.target>1.8</maven.compiler.target>
39 41
40 </properties> 42 </properties>
41 43
......
...@@ -5,14 +5,13 @@ import org.legrog.entities.PublisherVersion; ...@@ -5,14 +5,13 @@ import org.legrog.entities.PublisherVersion;
5 import org.slf4j.Logger; 5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory; 6 import org.slf4j.LoggerFactory;
7 7
8 -import javax.annotation.PostConstruct;
9 import javax.enterprise.context.RequestScoped; 8 import javax.enterprise.context.RequestScoped;
10 import javax.faces.context.FacesContext; 9 import javax.faces.context.FacesContext;
11 import javax.inject.Inject; 10 import javax.inject.Inject;
12 import javax.inject.Named; 11 import javax.inject.Named;
13 -import java.util.ArrayList;
14 import java.util.List; 12 import java.util.List;
15 import java.util.Map; 13 import java.util.Map;
14 +import java.util.stream.Collectors;
16 15
17 /* 16 /*
18 Vue de listPublisherVersions.xhtml 17 Vue de listPublisherVersions.xhtml
...@@ -22,61 +21,65 @@ import java.util.Map; ...@@ -22,61 +21,65 @@ import java.util.Map;
22 @Named 21 @Named
23 @RequestScoped 22 @RequestScoped
24 public class ListPublisherVersionsView { 23 public class ListPublisherVersionsView {
24 +
25 Logger logger = LoggerFactory.getLogger(getClass()); 25 Logger logger = LoggerFactory.getLogger(getClass());
26 26
27 - @Inject 27 + protected PublisherService publisherService;
28 - PublisherService publisherService;
29 28
30 private Integer publisherId; 29 private Integer publisherId;
31 -
32 private boolean viewAll; 30 private boolean viewAll;
33 -
34 private List<PublisherVersion> publisherVersions; 31 private List<PublisherVersion> publisherVersions;
35 32
33 + @Inject
34 + public ListPublisherVersionsView(PublisherService publisherService) {
35 + this.publisherService = publisherService;
36 + }
37 +
38 + // View Action being executed at view loading
39 + public void setView() {
40 + logger.trace("setView");
41 + logger.debug("publisherId = {}", publisherId);
42 + publisherVersions = publisherService.getAllPublisherVersions();
43 + viewAll = ( publisherId == null ) ;
44 + if (!viewAll) {
45 + logger.trace("!viewAll");
46 + filterOnID();
47 + }
48 + }
49 +
50 + protected void filterOnID() {
51 + publisherVersions = publisherVersions.stream()
52 + .filter(version -> version.getPublisher().getPublisherId() == publisherId)
53 + .collect(Collectors.toList());
54 +
55 + }
56 +
36 public void validate() { 57 public void validate() {
37 - logger.debug("validate"); 58 + logger.trace("validate");
38 Publisher publisher = publisherService.getPublisher(publisherId); 59 Publisher publisher = publisherService.getPublisher(publisherId);
39 logger.debug("publisher (pre-validate) = {}", publisher); 60 logger.debug("publisher (pre-validate) = {}", publisher);
40 Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); 61 Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
41 Integer publisherVersionId = new Integer(params.get("publisherVersionId")); 62 Integer publisherVersionId = new Integer(params.get("publisherVersionId"));
42 63
43 publisherService.validatePublisherVersion(publisher, publisherVersionId); 64 publisherService.validatePublisherVersion(publisher, publisherVersionId);
44 -// TODO : comprendre pourquoi ceci est nécessaire
45 - publisherVersions = publisherService.getAllPublisherVersions();
46 - publisherVersions = filter();
47 - logger.debug("publisher (post-validate) = {}", publisher);
48 - }
49 65
50 - @PostConstruct 66 + // TODO : comprendre pourquoi ceci est nécessaire
51 - public void init() { 67 + // JAI : je pense que c'est le refresh, sinon
52 publisherVersions = publisherService.getAllPublisherVersions(); 68 publisherVersions = publisherService.getAllPublisherVersions();
53 - logger.debug("init"); 69 + filterOnID();
70 + logger.debug("publisher (post-validate) = {}", publisher);
54 } 71 }
55 72
56 - protected List<PublisherVersion> filter() { 73 + /** no args constructor to make it proxyable */
57 - ArrayList<PublisherVersion> filteredPublisherVersions = new ArrayList<PublisherVersion>(); 74 + protected ListPublisherVersionsView() {
58 -
59 - for(PublisherVersion publisherVersion : publisherVersions) {
60 - if (publisherVersion.getPublisher().getPublisherId() == publisherId) {
61 - filteredPublisherVersions.add(publisherVersion);
62 - }
63 - }
64 - return filteredPublisherVersions;
65 } 75 }
66 76
67 - public void setView() { 77 + public PublisherService getPublisherService() {
68 - logger.debug("setView"); 78 + return publisherService;
69 - logger.debug("publisherId = " + publisherId);
70 - viewAll = ( publisherId == null ) ;
71 - if (!viewAll) {
72 - logger.debug("!viewAll");
73 - publisherVersions = filter();
74 - }
75 } 79 }
76 80
77 - // get, set et is 81 + public void setPublisherService(PublisherService publisherService) {
78 - public List<PublisherVersion> getPublisherVersions() { 82 + this.publisherService = publisherService;
79 - return publisherVersions;
80 } 83 }
81 84
82 public Integer getPublisherId() { 85 public Integer getPublisherId() {
...@@ -90,4 +93,16 @@ public class ListPublisherVersionsView { ...@@ -90,4 +93,16 @@ public class ListPublisherVersionsView {
90 public boolean isViewAll() { 93 public boolean isViewAll() {
91 return viewAll; 94 return viewAll;
92 } 95 }
96 +
97 + public void setViewAll(boolean viewAll) {
98 + this.viewAll = viewAll;
99 + }
100 +
101 + public List<PublisherVersion> getPublisherVersions() {
102 + return publisherVersions;
103 + }
104 +
105 + public void setPublisherVersions(List<PublisherVersion> publisherVersions) {
106 + this.publisherVersions = publisherVersions;
107 + }
93 } 108 }
...\ No newline at end of file ...\ No newline at end of file
......