Jean-Francois Leveque

Refactoring de User en Account (fin sur le nom des classes et fichiers).

...@@ -6,7 +6,7 @@ import java.util.Set; ...@@ -6,7 +6,7 @@ import java.util.Set;
6 import javax.persistence.*; 6 import javax.persistence.*;
7 7
8 /** 8 /**
9 - * The database representation of a user role or group. 9 + * The database representation of a account role or group.
10 * A given {@link Account} may be part of one or more {@link AccountRole}. 10 * A given {@link Account} may be part of one or more {@link AccountRole}.
11 * <br/> 11 * <br/>
12 * Warning: due to laziness of mapped objects, private attributes of all DB entities shall never be used directly. 12 * Warning: due to laziness of mapped objects, private attributes of all DB entities shall never be used directly.
...@@ -31,13 +31,13 @@ public class AccountRole /* extends org.roliste.data.DbEntity */ ...@@ -31,13 +31,13 @@ public class AccountRole /* extends org.roliste.data.DbEntity */
31 private String rolename; 31 private String rolename;
32 32
33 /** 33 /**
34 - * The {@link Account}s for this user role. 34 + * The {@link Account}s for this account role.
35 */ 35 */
36 @ManyToMany(mappedBy = "roles") 36 @ManyToMany(mappedBy = "roles")
37 private Set<Account> accounts; 37 private Set<Account> accounts;
38 38
39 /** 39 /**
40 - * Builds a new and empty user role definition. 40 + * Builds a new and empty account role definition.
41 * All attributes are set to their default value. 41 * All attributes are set to their default value.
42 * <br/> 42 * <br/>
43 * Needed by Hibernate for Java reflection. 43 * Needed by Hibernate for Java reflection.
...@@ -103,7 +103,7 @@ public class AccountRole /* extends org.roliste.data.DbEntity */ ...@@ -103,7 +103,7 @@ public class AccountRole /* extends org.roliste.data.DbEntity */
103 } 103 }
104 104
105 /** 105 /**
106 - * Initializes the user visible flag. 106 + * Initializes the account visible flag.
107 * @param visible the new flag value. 107 * @param visible the new flag value.
108 * @see #isVisible 108 * @see #isVisible
109 */ 109 */
...@@ -112,7 +112,7 @@ public class AccountRole /* extends org.roliste.data.DbEntity */ ...@@ -112,7 +112,7 @@ public class AccountRole /* extends org.roliste.data.DbEntity */
112 } 112 }
113 113
114 /** 114 /**
115 - * Retrieves the list of {@link Account}s for this user role. 115 + * Retrieves the list of {@link Account}s for this account role.
116 * SHALL be used as a read-only attribute. In particular, avoid 116 * SHALL be used as a read-only attribute. In particular, avoid
117 * using {@link Set#add(Object)} or {@link Set#remove(Object)} on 117 * using {@link Set#add(Object)} or {@link Set#remove(Object)} on
118 * the returned value without caution. 118 * the returned value without caution.
...@@ -137,7 +137,7 @@ public class AccountRole /* extends org.roliste.data.DbEntity */ ...@@ -137,7 +137,7 @@ public class AccountRole /* extends org.roliste.data.DbEntity */
137 } 137 }
138 138
139 /** 139 /**
140 - * Sets the list of {@link Account}s for this user role. 140 + * Sets the list of {@link Account}s for this account role.
141 * @param accounts the new {@link Set} of {@link Account}s. May be 141 * @param accounts the new {@link Set} of {@link Account}s. May be
142 * <code>null</code> (we don't handle the relation from this side). 142 * <code>null</code> (we don't handle the relation from this side).
143 * @see #getAccounts() 143 * @see #getAccounts()
...@@ -147,8 +147,8 @@ public class AccountRole /* extends org.roliste.data.DbEntity */ ...@@ -147,8 +147,8 @@ public class AccountRole /* extends org.roliste.data.DbEntity */
147 } 147 }
148 148
149 /** 149 /**
150 - * Returns a string representation of this user role definition. 150 + * Returns a string representation of this account role definition.
151 - * @return a string representing this user role definition. 151 + * @return a string representing this account role definition.
152 * hidden 152 * hidden
153 */ 153 */
154 @Override 154 @Override
......
1 -package org.legrog.web.user; 1 +package org.legrog.web.account;
2 2
3 import org.legrog.entities.Account; 3 import org.legrog.entities.Account;
4 4
5 import java.util.List; 5 import java.util.List;
6 6
7 -public interface UserService { 7 +public interface AccountService {
8 void addUser(Account account); 8 void addUser(Account account);
9 9
10 List<Account> getAllUsers(); 10 List<Account> getAllUsers();
......
1 -package org.legrog.web.user; 1 +package org.legrog.web.account;
2 2
3 import org.legrog.entities.Account; 3 import org.legrog.entities.Account;
4 import org.legrog.entities.AccountRepository; 4 import org.legrog.entities.AccountRepository;
...@@ -8,7 +8,7 @@ import javax.inject.Inject; ...@@ -8,7 +8,7 @@ import javax.inject.Inject;
8 import java.util.List; 8 import java.util.List;
9 9
10 @Stateless 10 @Stateless
11 -public class UserServiceDefault implements UserService { 11 +public class AccountServiceDefault implements AccountService {
12 @Inject 12 @Inject
13 AccountRepository accountRepository; 13 AccountRepository accountRepository;
14 14
......
1 -package org.legrog.web.user; 1 +package org.legrog.web.account;
2 2
3 import org.legrog.entities.Account; 3 import org.legrog.entities.Account;
4 4
...@@ -10,9 +10,9 @@ import java.util.List; ...@@ -10,9 +10,9 @@ import java.util.List;
10 10
11 @Named 11 @Named
12 @RequestScoped 12 @RequestScoped
13 -public class ListUsersBean { 13 +public class ListAccountsBean {
14 @Inject 14 @Inject
15 - private UserService userService; 15 + private AccountService userService;
16 16
17 private List<Account> accounts; 17 private List<Account> accounts;
18 18
......
1 -package org.legrog.web.user; 1 +package org.legrog.web.account;
2 2
3 import org.legrog.web.xyz.SharedService; 3 import org.legrog.web.xyz.SharedService;
4 import org.legrog.entities.*; 4 import org.legrog.entities.*;
...@@ -16,11 +16,11 @@ import java.util.List; ...@@ -16,11 +16,11 @@ import java.util.List;
16 16
17 @Named 17 @Named
18 @SessionScoped 18 @SessionScoped
19 -public class UpdateUserBean { 19 +public class UpdateAccountBean {
20 20
21 Logger logger = LoggerFactory.getLogger(getClass()); 21 Logger logger = LoggerFactory.getLogger(getClass());
22 22
23 - private UserService userService; 23 + private AccountService userService;
24 private SharedService sharedService; 24 private SharedService sharedService;
25 25
26 private List<DisplayNameMask> allDisplayNameMasks; 26 private List<DisplayNameMask> allDisplayNameMasks;
...@@ -45,12 +45,12 @@ public class UpdateUserBean { ...@@ -45,12 +45,12 @@ public class UpdateUserBean {
45 private boolean activated; 45 private boolean activated;
46 46
47 @Inject 47 @Inject
48 - public UpdateUserBean(UserService userService, SharedService sharedService) { 48 + public UpdateAccountBean(AccountService userService, SharedService sharedService) {
49 this.userService = userService; 49 this.userService = userService;
50 this.sharedService = sharedService; 50 this.sharedService = sharedService;
51 } 51 }
52 52
53 - UpdateUserBean() { 53 + UpdateAccountBean() {
54 //no args constructor to make it proxyable 54 //no args constructor to make it proxyable
55 } 55 }
56 56
...@@ -122,10 +122,10 @@ public class UpdateUserBean { ...@@ -122,10 +122,10 @@ public class UpdateUserBean {
122 } 122 }
123 username = account.getUsername(); 123 username = account.getUsername();
124 visible = account.isVisible(); 124 visible = account.isVisible();
125 - return "updateUser.xhtml"; 125 + return "updateAccount.xhtml";
126 } 126 }
127 } 127 }
128 - return "listUsers.xhtml"; 128 + return "listAccounts.xhtml";
129 } 129 }
130 130
131 public String update() { 131 public String update() {
...@@ -208,11 +208,11 @@ public class UpdateUserBean { ...@@ -208,11 +208,11 @@ public class UpdateUserBean {
208 this.activated = activated; 208 this.activated = activated;
209 } 209 }
210 210
211 - public UserService getUserService() { 211 + public AccountService getUserService() {
212 return userService; 212 return userService;
213 } 213 }
214 214
215 - public void setUserService(UserService userService) { 215 + public void setUserService(AccountService userService) {
216 this.userService = userService; 216 this.userService = userService;
217 } 217 }
218 218
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
13 13
14 <h:panelGrid columns="2"> 14 <h:panelGrid columns="2">
15 <h:outputText value="Username de l'utilisateur"/> 15 <h:outputText value="Username de l'utilisateur"/>
16 - <h:inputText value='#{updateUserBean.username}'/> 16 + <h:inputText value='#{updateAccountBean.username}'/>
17 <h:outputText value='Add'/> 17 <h:outputText value='Add'/>
18 - <h:commandButton action="#{updateUserBean.add}" value="Add"/> 18 + <h:commandButton action="#{updateAccountBean.add}" value="Add"/>
19 </h:panelGrid> 19 </h:panelGrid>
20 </h:form> 20 </h:form>
21 </body> 21 </body>
......
...@@ -32,13 +32,13 @@ ...@@ -32,13 +32,13 @@
32 32
33 <div id="listElements"> 33 <div id="listElements">
34 34
35 - <h:commandLink styleClass="fRight acLink" action="add" rendered="#{not empty listUsersBean.accounts}" > 35 + <h:commandLink styleClass="fRight acLink" action="add" rendered="#{not empty listAccountsBean.accounts}" >
36 <img src="/images/structure/vide.gif" class="icAddC" alt="" title="Crer un nouvel utilisateur" /> 36 <img src="/images/structure/vide.gif" class="icAddC" alt="" title="Crer un nouvel utilisateur" />
37 Nouvel Utilisateur 37 Nouvel Utilisateur
38 </h:commandLink> 38 </h:commandLink>
39 39
40 - <p:dataTable id="tableElements" rendered="#{not empty listUsersBean.accounts}" 40 + <p:dataTable id="tableElements" rendered="#{not empty listAccountsBean.accounts}"
41 - var="account" value="#{listUsersBean.accounts}" 41 + var="account" value="#{listAccountsBean.accounts}"
42 styleClass="results" rowClasses="altRichRow,altRow"> 42 styleClass="results" rowClasses="altRichRow,altRow">
43 <!-- TODO Grer la pagination --> 43 <!-- TODO Grer la pagination -->
44 <!-- <p:dataTable id="tableElements" rendered="#{listUsersBean.accounts.size>0}" 44 <!-- <p:dataTable id="tableElements" rendered="#{listUsersBean.accounts.size>0}"
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
61 </h:commandLink>--> 61 </h:commandLink>-->
62 </p:column> 62 </p:column>
63 <p:column> 63 <p:column>
64 - <h:commandLink action="#{updateUserBean.prepareUpdate(account.userId)}"> 64 + <h:commandLink action="#{updateAccountBean.prepareUpdate(account.userId)}">
65 <img src="/images/structure/vide.gif" class="icEdit" alt="Modifier" title="Modifier" /> 65 <img src="/images/structure/vide.gif" class="icEdit" alt="Modifier" title="Modifier" />
66 </h:commandLink> 66 </h:commandLink>
67 </p:column> 67 </p:column>
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
99 </div> 99 </div>
100 <p> 100 <p>
101 <h:commandLink action="add" value="Crer un nouvel utilisateur" 101 <h:commandLink action="add" value="Crer un nouvel utilisateur"
102 - rendered="#{empty listUsersBean.accounts}"> 102 + rendered="#{empty listAccountsBean.accounts}">
103 </h:commandLink> 103 </h:commandLink>
104 </p> 104 </p>
105 </h:form> 105 </h:form>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
12 </h:commandLink> 12 </h:commandLink>
13 </h:form> 13 </h:form>
14 <ul> 14 <ul>
15 - <ui:repeat value="#{listUsersBean.accounts}" var="account"> 15 + <ui:repeat value="#{listAccountsBean.accounts}" var="account">
16 <li>#{account.username}</li> 16 <li>#{account.username}</li>
17 </ui:repeat> 17 </ui:repeat>
18 </ul> 18 </ul>
......
1 package org.legrog.web.xyz; 1 package org.legrog.web.xyz;
2 2
3 import org.legrog.entities.*; 3 import org.legrog.entities.*;
4 -import org.legrog.web.user.UserService; 4 +import org.legrog.web.account.AccountService;
5 5
6 import javax.ejb.Stateless; 6 import javax.ejb.Stateless;
7 import javax.inject.Inject; 7 import javax.inject.Inject;
...@@ -18,7 +18,7 @@ public class SharedServiceDefault implements SharedService { ...@@ -18,7 +18,7 @@ public class SharedServiceDefault implements SharedService {
18 CountryRepository countryRepository; 18 CountryRepository countryRepository;
19 AccountRoleRepository accountRoleRepository; 19 AccountRoleRepository accountRoleRepository;
20 AccountPropertyRepository accountPropertyRepository; 20 AccountPropertyRepository accountPropertyRepository;
21 - UserService userService; 21 + AccountService accountService;
22 22
23 private List<DisplayNameMask> allDisplayNameMasks; 23 private List<DisplayNameMask> allDisplayNameMasks;
24 24
...@@ -28,15 +28,15 @@ public class SharedServiceDefault implements SharedService { ...@@ -28,15 +28,15 @@ public class SharedServiceDefault implements SharedService {
28 * @param countryRepository 28 * @param countryRepository
29 * @param accountRoleRepository 29 * @param accountRoleRepository
30 * @param accountPropertyRepository 30 * @param accountPropertyRepository
31 - * @param userService 31 + * @param accountService
32 */ 32 */
33 @Inject 33 @Inject
34 public SharedServiceDefault(CountryRepository countryRepository, AccountRoleRepository accountRoleRepository, 34 public SharedServiceDefault(CountryRepository countryRepository, AccountRoleRepository accountRoleRepository,
35 - AccountPropertyRepository accountPropertyRepository, UserService userService) { 35 + AccountPropertyRepository accountPropertyRepository, AccountService accountService) {
36 this.countryRepository = countryRepository; 36 this.countryRepository = countryRepository;
37 this.accountRoleRepository = accountRoleRepository; 37 this.accountRoleRepository = accountRoleRepository;
38 this.accountPropertyRepository = accountPropertyRepository; 38 this.accountPropertyRepository = accountPropertyRepository;
39 - this.userService = userService; 39 + this.accountService = accountService;
40 } 40 }
41 41
42 @Override 42 @Override
...@@ -75,7 +75,7 @@ public class SharedServiceDefault implements SharedService { ...@@ -75,7 +75,7 @@ public class SharedServiceDefault implements SharedService {
75 @Override 75 @Override
76 public Account getCurrentUser() { 76 public Account getCurrentUser() {
77 // TODO Remplacer l'astuce par une vraie récupération de l'utilisateur 77 // TODO Remplacer l'astuce par une vraie récupération de l'utilisateur
78 - List<Account> accounts = userService.getAllUsers(); 78 + List<Account> accounts = accountService.getAllUsers();
79 Random random = new Random(); 79 Random random = new Random();
80 80
81 return accounts.get(random.nextInt(accounts.size())); 81 return accounts.get(random.nextInt(accounts.size()));
......
1 -package org.legrog.web.user; 1 +package org.legrog.web.account;
2 2
3 import org.junit.jupiter.api.BeforeEach; 3 import org.junit.jupiter.api.BeforeEach;
4 import org.junit.jupiter.api.DisplayName; 4 import org.junit.jupiter.api.DisplayName;
...@@ -27,11 +27,11 @@ import static org.mockito.Mockito.when; ...@@ -27,11 +27,11 @@ import static org.mockito.Mockito.when;
27 @RunWith(JUnitPlatform.class) 27 @RunWith(JUnitPlatform.class)
28 public class UpdateAccountBeanTest { 28 public class UpdateAccountBeanTest {
29 29
30 - UpdateUserBean updateUserBean; 30 + UpdateAccountBean updateUserBean;
31 31
32 @BeforeEach 32 @BeforeEach
33 - public void setUp(@Mock UserService userService, @Mock SharedService sharedService) throws Exception { 33 + public void setUp(@Mock AccountService userService, @Mock SharedService sharedService) throws Exception {
34 - updateUserBean = new UpdateUserBean(userService, sharedService) ; 34 + updateUserBean = new UpdateAccountBean(userService, sharedService) ;
35 } 35 }
36 36
37 @Test 37 @Test
...@@ -56,7 +56,7 @@ public class UpdateAccountBeanTest { ...@@ -56,7 +56,7 @@ public class UpdateAccountBeanTest {
56 } 56 }
57 57
58 @Test 58 @Test
59 - @DisplayName("should set lists of available masks, user roles, and user properties from shared service") 59 + @DisplayName("should set lists of available masks, account roles, and account properties from shared service")
60 public void testList(@Mock SharedService sharedService) { 60 public void testList(@Mock SharedService sharedService) {
61 updateUserBean.init(); 61 updateUserBean.init();
62 assertThat(updateUserBean.getAllDisplayNameMasks()).isEqualTo(displayNameMasks); 62 assertThat(updateUserBean.getAllDisplayNameMasks()).isEqualTo(displayNameMasks);
......
...@@ -252,7 +252,7 @@ public class PublisherVersionViewTest { ...@@ -252,7 +252,7 @@ public class PublisherVersionViewTest {
252 } 252 }
253 253
254 @Test 254 @Test
255 - @DisplayName("should set lists of available masks, user roles, and user properties from shared service") 255 + @DisplayName("should set lists of available masks, account roles, and account properties from shared service")
256 public void testList(@Mock SharedService sharedService) { 256 public void testList(@Mock SharedService sharedService) {
257 publisherVersionView.init(); 257 publisherVersionView.init();
258 assertThat(publisherVersionView.getAvailableCountries()).isEqualTo(countries); 258 assertThat(publisherVersionView.getAvailableCountries()).isEqualTo(countries);
......
...@@ -12,7 +12,7 @@ import org.legrog.entities.AccountRoleRepository; ...@@ -12,7 +12,7 @@ import org.legrog.entities.AccountRoleRepository;
12 import org.legrog.entities.Country; 12 import org.legrog.entities.Country;
13 import org.legrog.entities.CountryRepository; 13 import org.legrog.entities.CountryRepository;
14 import org.legrog.test.MockitoExtension; 14 import org.legrog.test.MockitoExtension;
15 -import org.legrog.web.user.UserService; 15 +import org.legrog.web.account.AccountService;
16 import org.mockito.Mock; 16 import org.mockito.Mock;
17 import org.mockito.*; 17 import org.mockito.*;
18 18
...@@ -31,9 +31,9 @@ public class SharedServiceDefaultTest { ...@@ -31,9 +31,9 @@ public class SharedServiceDefaultTest {
31 public void setUp(@Mock CountryRepository countryRepository, 31 public void setUp(@Mock CountryRepository countryRepository,
32 @Mock AccountRoleRepository accountRoleRepository, 32 @Mock AccountRoleRepository accountRoleRepository,
33 @Mock AccountPropertyRepository accountPropertyRepository, 33 @Mock AccountPropertyRepository accountPropertyRepository,
34 - @Mock UserService userService) { 34 + @Mock AccountService accountService) {
35 sharedServiceDefault = new SharedServiceDefault(countryRepository, accountRoleRepository, 35 sharedServiceDefault = new SharedServiceDefault(countryRepository, accountRoleRepository,
36 - accountPropertyRepository, userService); 36 + accountPropertyRepository, accountService);
37 } 37 }
38 38
39 @Nested 39 @Nested
......