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 @@
<debug.jvm.args />
<tomee.autoreload />
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
......
......@@ -5,14 +5,13 @@ import org.legrog.entities.PublisherVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/*
Vue de listPublisherVersions.xhtml
......@@ -22,61 +21,65 @@ import java.util.Map;
@Named
@RequestScoped
public class ListPublisherVersionsView {
Logger logger = LoggerFactory.getLogger(getClass());
@Inject
PublisherService publisherService;
protected PublisherService publisherService;
private Integer publisherId;
private boolean viewAll;
private List<PublisherVersion> publisherVersions;
@Inject
public ListPublisherVersionsView(PublisherService publisherService) {
this.publisherService = publisherService;
}
// View Action being executed at view loading
public void setView() {
logger.trace("setView");
logger.debug("publisherId = {}", publisherId);
publisherVersions = publisherService.getAllPublisherVersions();
viewAll = ( publisherId == null ) ;
if (!viewAll) {
logger.trace("!viewAll");
filterOnID();
}
}
protected void filterOnID() {
publisherVersions = publisherVersions.stream()
.filter(version -> version.getPublisher().getPublisherId() == publisherId)
.collect(Collectors.toList());
}
public void validate() {
logger.debug("validate");
logger.trace("validate");
Publisher publisher = publisherService.getPublisher(publisherId);
logger.debug("publisher (pre-validate) = {}", publisher);
Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
Integer publisherVersionId = new Integer(params.get("publisherVersionId"));
publisherService.validatePublisherVersion(publisher, publisherVersionId);
// TODO : comprendre pourquoi ceci est nécessaire
publisherVersions = publisherService.getAllPublisherVersions();
publisherVersions = filter();
logger.debug("publisher (post-validate) = {}", publisher);
}
@PostConstruct
public void init() {
// TODO : comprendre pourquoi ceci est nécessaire
// JAI : je pense que c'est le refresh, sinon
publisherVersions = publisherService.getAllPublisherVersions();
logger.debug("init");
filterOnID();
logger.debug("publisher (post-validate) = {}", publisher);
}
protected List<PublisherVersion> filter() {
ArrayList<PublisherVersion> filteredPublisherVersions = new ArrayList<PublisherVersion>();
for(PublisherVersion publisherVersion : publisherVersions) {
if (publisherVersion.getPublisher().getPublisherId() == publisherId) {
filteredPublisherVersions.add(publisherVersion);
}
}
return filteredPublisherVersions;
/** no args constructor to make it proxyable */
protected ListPublisherVersionsView() {
}
public void setView() {
logger.debug("setView");
logger.debug("publisherId = " + publisherId);
viewAll = ( publisherId == null ) ;
if (!viewAll) {
logger.debug("!viewAll");
publisherVersions = filter();
}
public PublisherService getPublisherService() {
return publisherService;
}
// get, set et is
public List<PublisherVersion> getPublisherVersions() {
return publisherVersions;
public void setPublisherService(PublisherService publisherService) {
this.publisherService = publisherService;
}
public Integer getPublisherId() {
......@@ -90,4 +93,16 @@ public class ListPublisherVersionsView {
public boolean isViewAll() {
return viewAll;
}
public void setViewAll(boolean viewAll) {
this.viewAll = viewAll;
}
public List<PublisherVersion> getPublisherVersions() {
return publisherVersions;
}
public void setPublisherVersions(List<PublisherVersion> publisherVersions) {
this.publisherVersions = publisherVersions;
}
}
\ No newline at end of file
......