Toggle navigation
Toggle navigation
This project
Loading...
Sign in
grogv3
/
grog-cubi
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jean-Francois Leveque
2017-02-28 16:48:10 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
de955b6402f0d5501190a47feb733b96ec144f08
de955b64
1 parent
a80eb99c
Implémentation TDD de recherche, ajout de la page de recherche
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
105 additions
and
11 deletions
src/main/java/org/legrog/entities/IndexedPublisher.java
src/main/java/org/legrog/web/publisher/PublisherSearchView.java
src/main/java/org/legrog/web/publisher/PublisherServiceDefault.java
src/main/java/org/legrog/web/publisher/publisherSearch.xhtml
src/test/java/org/legrog/web/publisher/PublisherSearchViewTest.java
src/main/java/org/legrog/entities/IndexedPublisher.java
View file @
de955b6
...
...
@@ -28,6 +28,10 @@ public class IndexedPublisher {
this
.
publisherHistory
=
publisherVersion
.
getPublisherHistory
();
}
public
IndexedPublisher
()
{
}
public
int
getPublisherId
()
{
return
publisherId
;
}
...
...
@@ -39,4 +43,16 @@ public class IndexedPublisher {
public
String
getPublisherHistory
()
{
return
publisherHistory
;
}
public
void
setPublisherId
(
int
publisherId
)
{
this
.
publisherId
=
publisherId
;
}
public
void
setPublisherName
(
String
publisherName
)
{
this
.
publisherName
=
publisherName
;
}
public
void
setPublisherHistory
(
String
publisherHistory
)
{
this
.
publisherHistory
=
publisherHistory
;
}
}
\ No newline at end of file
...
...
src/main/java/org/legrog/web/publisher/PublisherSearchView.java
View file @
de955b6
...
...
@@ -3,15 +3,23 @@ package org.legrog.web.publisher;
import
org.legrog.entities.PublisherVersion
;
import
org.legrog.entities.SearchingException
;
import
javax.enterprise.context.RequestScoped
;
import
javax.inject.Inject
;
import
javax.inject.Named
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* View behind publisherSearch.xhtml
*/
@Named
@RequestScoped
public
class
PublisherSearchView
implements
Serializable
{
List
<
PublisherVersion
>
publisherVersions
=
new
ArrayList
<>();
String
searchString
;
transient
PublisherService
publisherService
;
/**
...
...
@@ -30,11 +38,29 @@ public class PublisherSearchView implements Serializable {
/**
*
* @param string String which you expect to find in indexed publishers
* @return List<PublisherVersion>
* @throws SearchingException when getting an error from PublisherSearchRepository
*/
public
List
<
PublisherVersion
>
search
(
String
string
)
throws
SearchingException
{
return
publisherService
.
search
(
string
);
public
void
search
()
{
try
{
this
.
publisherVersions
=
publisherService
.
search
(
this
.
searchString
);
}
catch
(
SearchingException
se
)
{
// TODO Handle Exception
}
}
public
String
getSearchString
()
{
return
searchString
;
}
public
void
setSearchString
(
String
searchString
)
{
this
.
searchString
=
searchString
;
}
public
List
<
PublisherVersion
>
getPublisherVersions
()
{
return
publisherVersions
;
}
public
void
setPublisherVersions
(
List
<
PublisherVersion
>
publisherVersions
)
{
this
.
publisherVersions
=
publisherVersions
;
}
}
...
...
src/main/java/org/legrog/web/publisher/PublisherServiceDefault.java
View file @
de955b6
...
...
@@ -145,7 +145,11 @@ public class PublisherServiceDefault implements PublisherService {
List
<
Integer
>
integers
=
new
ArrayList
<>(
indexedPublishers
.
size
());
indexedPublishers
.
forEach
(
indexedPublisher
->
integers
.
add
(
indexedPublisher
.
getPublisherId
()));
if
(
integers
.
size
()
>
0
)
{
return
publisherVersionRepository
.
findByPublisherVersionIdIn
(
integers
);
}
return
new
ArrayList
<>();
}
}
...
...
src/main/java/org/legrog/web/publisher/publisherSearch.xhtml
View file @
de955b6
...
...
@@ -4,8 +4,53 @@
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:h=
"http://xmlns.jcp.org/jsf/html"
xmlns:ui=
"http://xmlns.jcp.org/jsf/facelets"
xmlns:f=
"http://xmlns.jcp.org/jsf/core"
>
<f:view>
<h:outputLabel
value=
"Hello, world"
/>
</f:view>
xmlns:f=
"http://xmlns.jcp.org/jsf/core"
xmlns:jsf=
"http://xmlns.jcp.org/jsf"
>
<head>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"/minimal.css"
/>
</head>
<body>
<form
action=
""
jsf:id=
"search"
>
<h:panelGrid
columns=
"2"
>
<label
for=
"searchString"
>
Élément recherché dans les éditeurs
</label>
<input
type=
"text"
id=
"searchString"
jsf:value=
'#{publisherSearchView.searchString}'
/>
<button
jsf:action=
"#{publisherSearchView.search}"
>
Rechercher
</button>
</h:panelGrid>
</form>
<p
jsf:rendered=
"#{publisherSearchView.publisherVersions.isEmpty() and !publisherSearchView.searchString.isEmpty()}"
>
Aucun éditeur ne correspond à votre recherche : ${publisherSearchView.searchString}.
</p>
<h:dataTable
rendered=
"#{!publisherSearchView.publisherVersions.isEmpty()}"
value=
"#{publisherSearchView.publisherVersions}"
var=
"version"
>
<h:column>
<f:facet
name=
"header"
>
Name
</f:facet>
${version.publisherName}
</h:column>
<h:column>
<f:facet
name=
"header"
>
Address
</f:facet>
${version.publisherPostOfficeBoxNumber}
<br
/>
${version.publisherStreetAddress}
<br
/>
${version.publisherPostalCode} ${version.publisherAddressLocality}
<br
/>
${version.publisherAddressRegion}
<br
/>
${version.publisherAddressCountry.countryName}
</h:column>
<h:column>
<f:facet
name=
"header"
>
Telephone
</f:facet>
${version.publisherTelephone}
</h:column>
<h:column>
<f:facet
name=
"header"
>
Email
</f:facet>
${version.publisherEmail}
</h:column>
<h:column>
<f:facet
name=
"header"
>
URL
</f:facet>
${version.publisherURL}
</h:column>
<h:column>
<f:facet
name=
"header"
>
History
</f:facet>
<h:outputText
escape=
"false"
value=
"#{version.publisherHistory}"
/>
</h:column>
</h:dataTable>
</body>
</html>
...
...
src/test/java/org/legrog/web/publisher/PublisherSearchViewTest.java
View file @
de955b6
...
...
@@ -43,7 +43,8 @@ public class PublisherSearchViewTest {
@Test
@DisplayName
(
"when called, should delegate search to PublisherService with same string"
)
public
void
searchUsesPublisherService
(
@Mock
PublisherService
publisherService
)
throws
SearchingException
{
publisherSearchView
.
search
(
"1"
);
publisherSearchView
.
setSearchString
(
"1"
);
publisherSearchView
.
search
();
Mockito
.
verify
(
publisherService
).
search
(
"1"
);
}
...
...
@@ -52,7 +53,9 @@ public class PublisherSearchViewTest {
public
void
searchReturnsDataFromPublisherService
(
@Mock
PublisherService
publisherService
)
throws
SearchingException
{
List
<
PublisherVersion
>
publisherVersionList
=
new
ArrayList
<>();
when
(
publisherService
.
search
(
"2"
)).
thenReturn
(
publisherVersionList
);
assertThat
(
publisherSearchView
.
search
(
"2"
)).
isEqualTo
(
publisherVersionList
);
publisherSearchView
.
setSearchString
(
"2"
);
publisherSearchView
.
search
();
assertThat
(
publisherSearchView
.
getPublisherVersions
()).
isEqualTo
(
publisherVersionList
);
}
}
}
...
...
Please
register
or
login
to post a comment