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-15 15:19:42 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
69b089c30b12d7da34dc27392a80814e557e3722
69b089c3
1 parent
41c0e3f4
Passage de PublisherVersion (vue et page) en Rewrite
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
58 deletions
src/main/java/org/legrog/web/publisher/PublisherVersionView.java
src/main/java/org/legrog/web/publisher/listPublisherVersions.xhtml
src/main/java/org/legrog/web/publisher/publisherVersion.xhtml
src/test/java/org/legrog/web/publisher/PublisherVersionViewTest.java
src/main/java/org/legrog/web/publisher/PublisherVersionView.java
View file @
69b089c
...
...
@@ -2,10 +2,14 @@ package org.legrog.web.publisher;
import
org.legrog.entities.*
;
import
org.legrog.web.xyz.SharedService
;
import
org.ocpsoft.rewrite.annotation.Join
;
import
org.ocpsoft.rewrite.annotation.Parameter
;
import
org.ocpsoft.rewrite.annotation.RequestAction
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.annotation.PostConstruct
;
import
javax.enterprise.context.RequestScoped
;
import
javax.faces.view.ViewScoped
;
import
javax.inject.Inject
;
import
javax.inject.Named
;
...
...
@@ -20,8 +24,12 @@ import java.util.List;
* Update creates a new PublisherVersion linked to the Publisher
*/
@Named
@ViewScoped
@RequestScoped
@Join
(
path
=
"/PublisherVersion/{stringId}"
,
to
=
"/publisher/publisherVersion.jsf"
)
public
class
PublisherVersionView
implements
Serializable
{
@Parameter
String
stringId
;
transient
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
transient
PublisherService
publisherService
;
...
...
@@ -68,11 +76,58 @@ public class PublisherVersionView implements Serializable {
}
/**
* Loads countries
* Loads countries
and adapts to availability of parameter
*/
@PostConstruct
@RequestAction
public
void
init
()
{
availableCountries
=
sharedService
.
getAllCountries
();
PublisherVersion
publisherVersion
=
null
;
logger
.
debug
(
"stringId = {}"
,
this
.
stringId
);
if
(
stringId
!=
null
)
{
try
{
publisherVersionId
=
Integer
.
parseInt
(
stringId
);
}
catch
(
NumberFormatException
ne
)
{
publisherVersionId
=
0
;
}
}
else
{
publisherVersionId
=
0
;
}
if
(
publisherVersionId
!=
0
)
{
publisherVersion
=
publisherService
.
getPublisherVersion
(
publisherVersionId
);
publisherActions
=
publisherService
.
getAllPublisherVersionActions
(
publisherVersion
);
}
if
(
publisherVersion
!=
null
)
{
logger
.
debug
(
"Found a publisher version : {}"
,
publisherVersion
.
toString
());
publisherName
=
publisherVersion
.
getPublisherName
();
streetAddress
=
publisherVersion
.
getPublisherStreetAddress
();
postalCode
=
publisherVersion
.
getPublisherPostalCode
();
postOfficeBoxNumber
=
publisherVersion
.
getPublisherPostOfficeBoxNumber
();
addressRegion
=
publisherVersion
.
getPublisherAddressRegion
();
addressLocality
=
publisherVersion
.
getPublisherAddressLocality
();
publisherAddressCountry
=
publisherVersion
.
getPublisherAddressCountry
();
telephone
=
publisherVersion
.
getPublisherTelephone
();
email
=
publisherVersion
.
getPublisherEmail
();
uRL
=
publisherVersion
.
getPublisherURL
();
publisherHistory
=
publisherVersion
.
getPublisherHistory
();
publisher
=
publisherVersion
.
getPublisher
();
getImmutableValues
();
logger
.
debug
(
"Found a publisher : {}"
,
publisher
.
toString
());
newPublisher
=
false
;
}
else
{
logger
.
debug
(
"No publisher."
);
editMode
=
true
;
newPublisher
=
true
;
}
}
/**
...
...
@@ -87,7 +142,7 @@ public class PublisherVersionView implements Serializable {
*/
public
void
cancel
()
{
if
(!
newPublisher
)
{
loadData
();
init
();
editMode
=
false
;
}
else
{
publisherName
=
null
;
...
...
@@ -182,45 +237,6 @@ public class PublisherVersionView implements Serializable {
logger
.
trace
(
"fin update, après récupération, publisherVersion = {}"
,
publisherVersion
);
}
public
void
loadData
()
{
PublisherVersion
publisherVersion
=
null
;
logger
.
debug
(
"publisherVersionId = {}"
,
this
.
publisherVersionId
);
if
(
publisherVersionId
!=
0
)
{
publisherVersion
=
publisherService
.
getPublisherVersion
(
publisherVersionId
);
publisherActions
=
publisherService
.
getAllPublisherVersionActions
(
publisherVersion
);
}
if
(
publisherVersion
!=
null
)
{
logger
.
debug
(
"Found a publisher version : {}"
,
publisherVersion
.
toString
());
publisherName
=
publisherVersion
.
getPublisherName
();
streetAddress
=
publisherVersion
.
getPublisherStreetAddress
();
postalCode
=
publisherVersion
.
getPublisherPostalCode
();
postOfficeBoxNumber
=
publisherVersion
.
getPublisherPostOfficeBoxNumber
();
addressRegion
=
publisherVersion
.
getPublisherAddressRegion
();
addressLocality
=
publisherVersion
.
getPublisherAddressLocality
();
publisherAddressCountry
=
publisherVersion
.
getPublisherAddressCountry
();
telephone
=
publisherVersion
.
getPublisherTelephone
();
email
=
publisherVersion
.
getPublisherEmail
();
uRL
=
publisherVersion
.
getPublisherURL
();
publisherHistory
=
publisherVersion
.
getPublisherHistory
();
publisher
=
publisherVersion
.
getPublisher
();
getImmutableValues
();
logger
.
debug
(
"Found a publisher : {}"
,
publisher
.
toString
());
newPublisher
=
false
;
}
else
{
logger
.
debug
(
"No publisher."
);
editMode
=
true
;
newPublisher
=
true
;
}
}
// Accessors
public
int
getPublisherVersionId
()
{
return
publisherVersionId
;
...
...
@@ -369,4 +385,12 @@ public class PublisherVersionView implements Serializable {
public
List
<
PublisherAction
>
getPublisherActions
()
{
return
publisherActions
;
}
public
String
getStringId
()
{
return
stringId
;
}
public
void
setStringId
(
String
stringId
)
{
this
.
stringId
=
stringId
;
}
}
...
...
src/main/java/org/legrog/web/publisher/listPublisherVersions.xhtml
View file @
69b089c
...
...
@@ -26,9 +26,7 @@
<h:dataTable
value=
"#{listPublisherVersionsView.publisherVersions}"
var=
"version"
>
<h:column>
<f:facet
name=
"header"
/>
<a
jsf:outcome=
"publisherVersion"
>
Visualiser ou Modifier Version
<f:param
name=
"publisherVersionId"
value=
"#{version.publisherVersionId}"
/>
</a>
<a
jsf:value=
"/PublisherVersion/${version.publisherVersionId}"
>
Visualiser ou Modifier Version
</a>
</h:column>
<h:column
rendered=
"#{listPublisherVersionsView.viewAll}"
>
<f:facet
name=
"header"
/>
...
...
src/main/java/org/legrog/web/publisher/publisherVersion.xhtml
View file @
69b089c
...
...
@@ -7,10 +7,6 @@
xmlns:f=
"http://xmlns.jcp.org/jsf/core"
xmlns:jsf=
"http://xmlns.jcp.org/jsf"
>
<head>
<f:metadata>
<f:viewParam
name=
"publisherVersionId"
value=
"#{publisherVersionView.publisherVersionId}"
/>
<f:viewAction
action=
"#{publisherVersionView.loadData}"
/>
</f:metadata>
</head>
<body>
...
...
@@ -54,7 +50,7 @@
<input
type=
"text"
id=
"uRL"
jsf:value=
'#{publisherVersionView.uRL}'
jsf:disabled=
"#{not publisherVersionView.editMode}"
/>
<label
for=
"publisherHistory"
>
publisherHistory
</label>
<textarea
id=
"publisherHistory"
rows=
"
"
cols=
"
"
jsf:disabled=
"#{not publisherVersionView.editMode}"
jsf:value=
"#{publisherVersionView.publisherHistory}"
/>
<textarea
id=
"publisherHistory"
rows=
"
20"
cols=
"200
"
jsf:disabled=
"#{not publisherVersionView.editMode}"
jsf:value=
"#{publisherVersionView.publisherHistory}"
/>
<div
jsf:rendered=
"#{not publisherVersionView.newPublisher}"
>
publisherVersionAuthor
</div>
<div
jsf:rendered=
"#{not publisherVersionView.newPublisher}"
>
#{publisherVersionView.publisherVersionAuthor.displayName}
</div>
...
...
src/test/java/org/legrog/web/publisher/PublisherVersionViewTest.java
View file @
69b089c
...
...
@@ -108,7 +108,7 @@ public class PublisherVersionViewTest {
@Test
public
void
testCancelNewVersionOfPublisher
()
{
publisherVersionView
.
setNewPublisher
(
false
);
publisherVersionView
.
set
PublisherVersionId
(
1
);
publisherVersionView
.
set
StringId
(
"1"
);
publisherVersionView
.
setPublisherName
(
"1"
);
publisherVersionView
.
setStreetAddress
(
"2"
);
...
...
@@ -139,14 +139,14 @@ public class PublisherVersionViewTest {
}
@Nested
@DisplayName
(
"
loadData
method"
)
@DisplayName
(
"
init
method"
)
class
LoadDataTests
{
@Test
@DisplayName
(
"Loads all actions on it"
)
public
void
testLoadActions
(
@Mock
PublisherService
publisherService
)
{
publisherVersionView
.
set
PublisherVersionId
(
1
);
publisherVersionView
.
loadData
();
publisherVersionView
.
set
StringId
(
"1"
);
publisherVersionView
.
init
();
Mockito
.
verify
(
publisherService
).
getAllPublisherVersionActions
(
publisherVersion
);
}
...
...
@@ -154,8 +154,8 @@ public class PublisherVersionViewTest {
@DisplayName
(
"when called for existing publisher, should get the rigtht data into the form"
)
public
void
testLoadData
()
{
publisherVersionView
.
setNewPublisher
(
true
);
publisherVersionView
.
set
PublisherVersionId
(
1
);
publisherVersionView
.
loadData
();
publisherVersionView
.
set
StringId
(
"1"
);
publisherVersionView
.
init
();
assertThat
(
publisherVersionView
.
getPublisherName
()).
isEqualTo
(
"A"
);
assertThat
(
publisherVersionView
.
getStreetAddress
()).
isEqualTo
(
"B"
);
assertThat
(
publisherVersionView
.
getPostalCode
()).
isEqualTo
(
"C"
);
...
...
@@ -173,8 +173,8 @@ public class PublisherVersionViewTest {
@DisplayName
(
"when called for new publisher, should set form for new version"
)
public
void
testLoadDataEmpty
()
{
publisherVersionView
.
setNewPublisher
(
false
);
publisherVersionView
.
set
PublisherVersionId
(
0
);
publisherVersionView
.
loadData
();
publisherVersionView
.
set
StringId
(
"0"
);
publisherVersionView
.
init
();
assertThat
(
publisherVersionView
.
isNewPublisher
()).
isTrue
();
assertThat
(
publisherVersionView
.
isEditMode
()).
isTrue
();
}
...
...
Please
register
or
login
to post a comment