Jean-Francois Leveque

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

......@@ -6,7 +6,7 @@ import java.util.Set;
import javax.persistence.*;
/**
* The database representation of a user role or group.
* The database representation of a account role or group.
* A given {@link Account} may be part of one or more {@link AccountRole}.
* <br/>
* 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 */
private String rolename;
/**
* The {@link Account}s for this user role.
* The {@link Account}s for this account role.
*/
@ManyToMany(mappedBy = "roles")
private Set<Account> accounts;
/**
* Builds a new and empty user role definition.
* Builds a new and empty account role definition.
* All attributes are set to their default value.
* <br/>
* Needed by Hibernate for Java reflection.
......@@ -103,7 +103,7 @@ public class AccountRole /* extends org.roliste.data.DbEntity */
}
/**
* Initializes the user visible flag.
* Initializes the account visible flag.
* @param visible the new flag value.
* @see #isVisible
*/
......@@ -112,7 +112,7 @@ public class AccountRole /* extends org.roliste.data.DbEntity */
}
/**
* Retrieves the list of {@link Account}s for this user role.
* Retrieves the list of {@link Account}s for this account role.
* SHALL be used as a read-only attribute. In particular, avoid
* using {@link Set#add(Object)} or {@link Set#remove(Object)} on
* the returned value without caution.
......@@ -137,7 +137,7 @@ public class AccountRole /* extends org.roliste.data.DbEntity */
}
/**
* Sets the list of {@link Account}s for this user role.
* Sets the list of {@link Account}s for this account role.
* @param accounts the new {@link Set} of {@link Account}s. May be
* <code>null</code> (we don't handle the relation from this side).
* @see #getAccounts()
......@@ -147,8 +147,8 @@ public class AccountRole /* extends org.roliste.data.DbEntity */
}
/**
* Returns a string representation of this user role definition.
* @return a string representing this user role definition.
* Returns a string representation of this account role definition.
* @return a string representing this account role definition.
* hidden
*/
@Override
......
package org.legrog.web.user;
package org.legrog.web.account;
import org.legrog.entities.Account;
import java.util.List;
public interface UserService {
public interface AccountService {
void addUser(Account account);
List<Account> getAllUsers();
......
package org.legrog.web.user;
package org.legrog.web.account;
import org.legrog.entities.Account;
import org.legrog.entities.AccountRepository;
......@@ -8,7 +8,7 @@ import javax.inject.Inject;
import java.util.List;
@Stateless
public class UserServiceDefault implements UserService {
public class AccountServiceDefault implements AccountService {
@Inject
AccountRepository accountRepository;
......
package org.legrog.web.user;
package org.legrog.web.account;
import org.legrog.entities.Account;
......@@ -10,9 +10,9 @@ import java.util.List;
@Named
@RequestScoped
public class ListUsersBean {
public class ListAccountsBean {
@Inject
private UserService userService;
private AccountService userService;
private List<Account> accounts;
......
package org.legrog.web.user;
package org.legrog.web.account;
import org.legrog.web.xyz.SharedService;
import org.legrog.entities.*;
......@@ -16,11 +16,11 @@ import java.util.List;
@Named
@SessionScoped
public class UpdateUserBean {
public class UpdateAccountBean {
Logger logger = LoggerFactory.getLogger(getClass());
private UserService userService;
private AccountService userService;
private SharedService sharedService;
private List<DisplayNameMask> allDisplayNameMasks;
......@@ -45,12 +45,12 @@ public class UpdateUserBean {
private boolean activated;
@Inject
public UpdateUserBean(UserService userService, SharedService sharedService) {
public UpdateAccountBean(AccountService userService, SharedService sharedService) {
this.userService = userService;
this.sharedService = sharedService;
}
UpdateUserBean() {
UpdateAccountBean() {
//no args constructor to make it proxyable
}
......@@ -122,10 +122,10 @@ public class UpdateUserBean {
}
username = account.getUsername();
visible = account.isVisible();
return "updateUser.xhtml";
return "updateAccount.xhtml";
}
}
return "listUsers.xhtml";
return "listAccounts.xhtml";
}
public String update() {
......@@ -208,11 +208,11 @@ public class UpdateUserBean {
this.activated = activated;
}
public UserService getUserService() {
public AccountService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
public void setUserService(AccountService userService) {
this.userService = userService;
}
......
......@@ -13,9 +13,9 @@
<h:panelGrid columns="2">
<h:outputText value="Username de l'utilisateur"/>
<h:inputText value='#{updateUserBean.username}'/>
<h:inputText value='#{updateAccountBean.username}'/>
<h:outputText value='Add'/>
<h:commandButton action="#{updateUserBean.add}" value="Add"/>
<h:commandButton action="#{updateAccountBean.add}" value="Add"/>
</h:panelGrid>
</h:form>
</body>
......
......@@ -32,13 +32,13 @@
<div id="listElements">
<h:commandLink styleClass="fRight acLink" action="add" rendered="#{not empty listUsersBean.accounts}" >
<h:commandLink styleClass="fRight acLink" action="add" rendered="#{not empty listAccountsBean.accounts}" >
<img src="/images/structure/vide.gif" class="icAddC" alt="" title="Crer un nouvel utilisateur" />
Nouvel Utilisateur
</h:commandLink>
<p:dataTable id="tableElements" rendered="#{not empty listUsersBean.accounts}"
var="account" value="#{listUsersBean.accounts}"
<p:dataTable id="tableElements" rendered="#{not empty listAccountsBean.accounts}"
var="account" value="#{listAccountsBean.accounts}"
styleClass="results" rowClasses="altRichRow,altRow">
<!-- TODO Grer la pagination -->
<!-- <p:dataTable id="tableElements" rendered="#{listUsersBean.accounts.size>0}"
......@@ -61,7 +61,7 @@
</h:commandLink>-->
</p:column>
<p:column>
<h:commandLink action="#{updateUserBean.prepareUpdate(account.userId)}">
<h:commandLink action="#{updateAccountBean.prepareUpdate(account.userId)}">
<img src="/images/structure/vide.gif" class="icEdit" alt="Modifier" title="Modifier" />
</h:commandLink>
</p:column>
......@@ -99,7 +99,7 @@
</div>
<p>
<h:commandLink action="add" value="Crer un nouvel utilisateur"
rendered="#{empty listUsersBean.accounts}">
rendered="#{empty listAccountsBean.accounts}">
</h:commandLink>
</p>
</h:form>
......
......@@ -12,7 +12,7 @@
</h:commandLink>
</h:form>
<ul>
<ui:repeat value="#{listUsersBean.accounts}" var="account">
<ui:repeat value="#{listAccountsBean.accounts}" var="account">
<li>#{account.username}</li>
</ui:repeat>
</ul>
......
package org.legrog.web.xyz;
import org.legrog.entities.*;
import org.legrog.web.user.UserService;
import org.legrog.web.account.AccountService;
import javax.ejb.Stateless;
import javax.inject.Inject;
......@@ -18,7 +18,7 @@ public class SharedServiceDefault implements SharedService {
CountryRepository countryRepository;
AccountRoleRepository accountRoleRepository;
AccountPropertyRepository accountPropertyRepository;
UserService userService;
AccountService accountService;
private List<DisplayNameMask> allDisplayNameMasks;
......@@ -28,15 +28,15 @@ public class SharedServiceDefault implements SharedService {
* @param countryRepository
* @param accountRoleRepository
* @param accountPropertyRepository
* @param userService
* @param accountService
*/
@Inject
public SharedServiceDefault(CountryRepository countryRepository, AccountRoleRepository accountRoleRepository,
AccountPropertyRepository accountPropertyRepository, UserService userService) {
AccountPropertyRepository accountPropertyRepository, AccountService accountService) {
this.countryRepository = countryRepository;
this.accountRoleRepository = accountRoleRepository;
this.accountPropertyRepository = accountPropertyRepository;
this.userService = userService;
this.accountService = accountService;
}
@Override
......@@ -75,7 +75,7 @@ public class SharedServiceDefault implements SharedService {
@Override
public Account getCurrentUser() {
// TODO Remplacer l'astuce par une vraie récupération de l'utilisateur
List<Account> accounts = userService.getAllUsers();
List<Account> accounts = accountService.getAllUsers();
Random random = new Random();
return accounts.get(random.nextInt(accounts.size()));
......
package org.legrog.web.user;
package org.legrog.web.account;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
......@@ -27,11 +27,11 @@ import static org.mockito.Mockito.when;
@RunWith(JUnitPlatform.class)
public class UpdateAccountBeanTest {
UpdateUserBean updateUserBean;
UpdateAccountBean updateUserBean;
@BeforeEach
public void setUp(@Mock UserService userService, @Mock SharedService sharedService) throws Exception {
updateUserBean = new UpdateUserBean(userService, sharedService) ;
public void setUp(@Mock AccountService userService, @Mock SharedService sharedService) throws Exception {
updateUserBean = new UpdateAccountBean(userService, sharedService) ;
}
@Test
......@@ -56,7 +56,7 @@ public class UpdateAccountBeanTest {
}
@Test
@DisplayName("should set lists of available masks, user roles, and user properties from shared service")
@DisplayName("should set lists of available masks, account roles, and account properties from shared service")
public void testList(@Mock SharedService sharedService) {
updateUserBean.init();
assertThat(updateUserBean.getAllDisplayNameMasks()).isEqualTo(displayNameMasks);
......
......@@ -252,7 +252,7 @@ public class PublisherVersionViewTest {
}
@Test
@DisplayName("should set lists of available masks, user roles, and user properties from shared service")
@DisplayName("should set lists of available masks, account roles, and account properties from shared service")
public void testList(@Mock SharedService sharedService) {
publisherVersionView.init();
assertThat(publisherVersionView.getAvailableCountries()).isEqualTo(countries);
......
......@@ -12,7 +12,7 @@ import org.legrog.entities.AccountRoleRepository;
import org.legrog.entities.Country;
import org.legrog.entities.CountryRepository;
import org.legrog.test.MockitoExtension;
import org.legrog.web.user.UserService;
import org.legrog.web.account.AccountService;
import org.mockito.Mock;
import org.mockito.*;
......@@ -31,9 +31,9 @@ public class SharedServiceDefaultTest {
public void setUp(@Mock CountryRepository countryRepository,
@Mock AccountRoleRepository accountRoleRepository,
@Mock AccountPropertyRepository accountPropertyRepository,
@Mock UserService userService) {
@Mock AccountService accountService) {
sharedServiceDefault = new SharedServiceDefault(countryRepository, accountRoleRepository,
accountPropertyRepository, userService);
accountPropertyRepository, accountService);
}
@Nested
......