Jean-Francois Leveque

Implémentation TDD de recherche, ajout de la page de recherche

...@@ -28,6 +28,10 @@ public class IndexedPublisher { ...@@ -28,6 +28,10 @@ public class IndexedPublisher {
28 this.publisherHistory = publisherVersion.getPublisherHistory(); 28 this.publisherHistory = publisherVersion.getPublisherHistory();
29 } 29 }
30 30
31 + public IndexedPublisher() {
32 +
33 + }
34 +
31 public int getPublisherId() { 35 public int getPublisherId() {
32 return publisherId; 36 return publisherId;
33 } 37 }
...@@ -39,4 +43,16 @@ public class IndexedPublisher { ...@@ -39,4 +43,16 @@ public class IndexedPublisher {
39 public String getPublisherHistory() { 43 public String getPublisherHistory() {
40 return publisherHistory; 44 return publisherHistory;
41 } 45 }
46 +
47 + public void setPublisherId(int publisherId) {
48 + this.publisherId = publisherId;
49 + }
50 +
51 + public void setPublisherName(String publisherName) {
52 + this.publisherName = publisherName;
53 + }
54 +
55 + public void setPublisherHistory(String publisherHistory) {
56 + this.publisherHistory = publisherHistory;
57 + }
42 } 58 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -3,15 +3,23 @@ package org.legrog.web.publisher; ...@@ -3,15 +3,23 @@ package org.legrog.web.publisher;
3 import org.legrog.entities.PublisherVersion; 3 import org.legrog.entities.PublisherVersion;
4 import org.legrog.entities.SearchingException; 4 import org.legrog.entities.SearchingException;
5 5
6 +import javax.enterprise.context.RequestScoped;
6 import javax.inject.Inject; 7 import javax.inject.Inject;
8 +import javax.inject.Named;
7 import java.io.Serializable; 9 import java.io.Serializable;
10 +import java.util.ArrayList;
8 import java.util.List; 11 import java.util.List;
9 12
10 /** 13 /**
11 * View behind publisherSearch.xhtml 14 * View behind publisherSearch.xhtml
12 */ 15 */
16 +@Named
17 +@RequestScoped
13 public class PublisherSearchView implements Serializable { 18 public class PublisherSearchView implements Serializable {
14 19
20 + List<PublisherVersion> publisherVersions = new ArrayList<>();
21 + String searchString;
22 +
15 transient PublisherService publisherService; 23 transient PublisherService publisherService;
16 24
17 /** 25 /**
...@@ -30,11 +38,29 @@ public class PublisherSearchView implements Serializable { ...@@ -30,11 +38,29 @@ public class PublisherSearchView implements Serializable {
30 38
31 /** 39 /**
32 * 40 *
33 - * @param string String which you expect to find in indexed publishers
34 - * @return List<PublisherVersion>
35 - * @throws SearchingException when getting an error from PublisherSearchRepository
36 */ 41 */
37 - public List<PublisherVersion> search(String string) throws SearchingException{ 42 + public void search() {
38 - return publisherService.search(string); 43 + try {
44 + this.publisherVersions = publisherService.search(this.searchString);
45 + } catch (SearchingException se) {
46 + // TODO Handle Exception
47 + }
48 + }
49 +
50 + public String getSearchString() {
51 + return searchString;
52 + }
53 +
54 + public void setSearchString(String searchString) {
55 + this.searchString = searchString;
39 } 56 }
57 +
58 + public List<PublisherVersion> getPublisherVersions() {
59 + return publisherVersions;
60 + }
61 +
62 + public void setPublisherVersions(List<PublisherVersion> publisherVersions) {
63 + this.publisherVersions = publisherVersions;
64 + }
65 +
40 } 66 }
......
...@@ -142,10 +142,14 @@ public class PublisherServiceDefault implements PublisherService { ...@@ -142,10 +142,14 @@ public class PublisherServiceDefault implements PublisherService {
142 142
143 @Override 143 @Override
144 public List<PublisherVersion> convert(List<IndexedPublisher> indexedPublishers) { 144 public List<PublisherVersion> convert(List<IndexedPublisher> indexedPublishers) {
145 - List<Integer> integers = new ArrayList<>(indexedPublishers.size()); 145 + List<Integer> integers = new ArrayList<>(indexedPublishers.size());
146 - indexedPublishers.forEach(indexedPublisher -> integers.add(indexedPublisher.getPublisherId())); 146 + indexedPublishers.forEach(indexedPublisher -> integers.add(indexedPublisher.getPublisherId()));
147 147
148 - return publisherVersionRepository.findByPublisherVersionIdIn(integers); 148 + if (integers.size() > 0) {
149 + return publisherVersionRepository.findByPublisherVersionIdIn(integers);
150 + }
151 +
152 + return new ArrayList<>();
149 } 153 }
150 154
151 } 155 }
......
...@@ -4,8 +4,53 @@ ...@@ -4,8 +4,53 @@
4 <html xmlns="http://www.w3.org/1999/xhtml" 4 <html xmlns="http://www.w3.org/1999/xhtml"
5 xmlns:h="http://xmlns.jcp.org/jsf/html" 5 xmlns:h="http://xmlns.jcp.org/jsf/html"
6 xmlns:ui="http://xmlns.jcp.org/jsf/facelets" 6 xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
7 - xmlns:f="http://xmlns.jcp.org/jsf/core"> 7 + xmlns:f="http://xmlns.jcp.org/jsf/core"
8 -<f:view> 8 + xmlns:jsf="http://xmlns.jcp.org/jsf">
9 - <h:outputLabel value="Hello, world"/> 9 +<head>
10 -</f:view> 10 + <link rel="stylesheet" type="text/css" href="/minimal.css"/>
11 +</head>
12 +<body>
13 +<form action="" jsf:id="search">
14 + <h:panelGrid columns="2">
15 + <label for="searchString">Élément recherché dans les éditeurs</label>
16 + <input type="text" id="searchString" jsf:value='#{publisherSearchView.searchString}'/>
17 +
18 + <button jsf:action="#{publisherSearchView.search}">Rechercher</button>
19 + </h:panelGrid>
20 +</form>
21 +
22 +<p jsf:rendered="#{publisherSearchView.publisherVersions.isEmpty() and !publisherSearchView.searchString.isEmpty()}">Aucun éditeur ne correspond à votre recherche : ${publisherSearchView.searchString}.</p>
23 +
24 +<h:dataTable rendered="#{!publisherSearchView.publisherVersions.isEmpty()}" value="#{publisherSearchView.publisherVersions}" var="version">
25 + <h:column>
26 + <f:facet name="header">Name</f:facet>
27 + ${version.publisherName}
28 + </h:column>
29 + <h:column>
30 + <f:facet name="header">Address</f:facet>
31 + ${version.publisherPostOfficeBoxNumber}<br />
32 + ${version.publisherStreetAddress}<br />
33 + ${version.publisherPostalCode} ${version.publisherAddressLocality}<br />
34 + ${version.publisherAddressRegion}<br />
35 + ${version.publisherAddressCountry.countryName}
36 + </h:column>
37 + <h:column>
38 + <f:facet name="header">Telephone</f:facet>
39 + ${version.publisherTelephone}
40 + </h:column>
41 + <h:column>
42 + <f:facet name="header">Email</f:facet>
43 + ${version.publisherEmail}
44 + </h:column>
45 + <h:column>
46 + <f:facet name="header">URL</f:facet>
47 + ${version.publisherURL}
48 + </h:column>
49 + <h:column>
50 + <f:facet name="header">History</f:facet>
51 + <h:outputText escape="false" value="#{version.publisherHistory}"/>
52 + </h:column>
53 +</h:dataTable>
54 +
55 +</body>
11 </html> 56 </html>
......
...@@ -43,7 +43,8 @@ public class PublisherSearchViewTest { ...@@ -43,7 +43,8 @@ public class PublisherSearchViewTest {
43 @Test 43 @Test
44 @DisplayName("when called, should delegate search to PublisherService with same string") 44 @DisplayName("when called, should delegate search to PublisherService with same string")
45 public void searchUsesPublisherService(@Mock PublisherService publisherService) throws SearchingException{ 45 public void searchUsesPublisherService(@Mock PublisherService publisherService) throws SearchingException{
46 - publisherSearchView.search("1"); 46 + publisherSearchView.setSearchString("1");
47 + publisherSearchView.search();
47 Mockito.verify(publisherService).search("1"); 48 Mockito.verify(publisherService).search("1");
48 } 49 }
49 50
...@@ -52,7 +53,9 @@ public class PublisherSearchViewTest { ...@@ -52,7 +53,9 @@ public class PublisherSearchViewTest {
52 public void searchReturnsDataFromPublisherService(@Mock PublisherService publisherService) throws SearchingException { 53 public void searchReturnsDataFromPublisherService(@Mock PublisherService publisherService) throws SearchingException {
53 List<PublisherVersion> publisherVersionList = new ArrayList<>(); 54 List<PublisherVersion> publisherVersionList = new ArrayList<>();
54 when(publisherService.search("2")).thenReturn(publisherVersionList); 55 when(publisherService.search("2")).thenReturn(publisherVersionList);
55 - assertThat(publisherSearchView.search("2")).isEqualTo(publisherVersionList); 56 + publisherSearchView.setSearchString("2");
57 + publisherSearchView.search();
58 + assertThat(publisherSearchView.getPublisherVersions()).isEqualTo(publisherVersionList);
56 } 59 }
57 } 60 }
58 } 61 }
......