Jean-Francois Leveque

Refactoring des comptes vers dénomination Account

Showing 21 changed files with 232 additions and 230 deletions
......@@ -11,7 +11,7 @@ import java.util.*;
Migréee depuis la v2.
*/
@Entity
public class Person /* extends org.roliste.data.DbTraceableEntity */ implements DisplayNameConfigurable /*, DbValidationEntity */ {
public class Account /* extends org.roliste.data.DbTraceableEntity */ implements DisplayNameConfigurable /*, DbValidationEntity */ {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......@@ -117,23 +117,23 @@ public class Person /* extends org.roliste.data.DbTraceableEntity */ implements
private String email;
/**
* The {link org.roliste.data.db.UserRole}s for this user.
* The {link org.roliste.data.db.AccountRole}s for this user.
*/
@ManyToMany(fetch = FetchType.EAGER)
private List<UserRole> roles;
private List<AccountRole> roles;
/**
* Retrieves the list of {@link UserRole}s for this user.
* Retrieves the list of {@link AccountRole}s for this user.
* SHALL be used as a read-only attribute. In particular, avoid
* using {@link List#add(Object)} or {@link List#remove(Object)} on
* the returned value without caution.
* @return a {@link List} of {@link UserRole}. Shall not be <code>null</code>.
* @return a {@link List} of {@link AccountRole}. Shall not be <code>null</code>.
* @see #setRoles(List)
* see #addToRole(UserRole)
* see #removeFromRole(UserRole)
* see #addToRole(AccountRole)
* see #removeFromRole(AccountRole)
* hibernate.many-to-many
* column="ROLE_FK"
* class="org.roliste.data.db.UserRole"
* class="org.roliste.data.db.AccountRole"
* foreign-key="FK_UTILISATEURROLE_ROLEUTILISATEUR"
* @hibernate.key
* column="UTILISATEUR_FK"
......@@ -146,20 +146,20 @@ public class Person /* extends org.roliste.data.DbTraceableEntity */ implements
* lazy="true"
*/
public List<UserRole> getRoles() {
public List<AccountRole> getRoles() {
return roles;
}
/**
* Lists the list of {@link UserRole}s for this user.
* @param roles the new {@link List} of {@link UserRole}s. Shall not be <code>null</code>.
* Lists the list of {@link AccountRole}s for this user.
* @param roles the new {@link List} of {@link AccountRole}s. Shall not be <code>null</code>.
* @throws NullPointerException if roles is <code>null</code>.
* @see #getRoles()
* see #addToRole(UserRole)
* see #removeFromRole(UserRole)
* see #addToRole(AccountRole)
* see #removeFromRole(AccountRole)
*/
public void setRoles(List<UserRole> roles) {
public void setRoles(List<AccountRole> roles) {
if (roles == null)
{
throw new NullPointerException("Impossible d'affecter un ensemble nul aux r�les d'un utilisateur");
......@@ -168,38 +168,38 @@ public class Person /* extends org.roliste.data.DbTraceableEntity */ implements
}
/**
* Add the user to a given {@link UserRole}s.
* @param role the new {@link UserRole}. Ignored if <code>null</code>.
* Add the user to a given {@link AccountRole}s.
* @param role the new {@link AccountRole}. Ignored if <code>null</code>.
* @see #getRoles()
* @see #setRoles(List)
* @see #removeFromRole(UserRole)
* @see #removeFromRole(AccountRole)
*/
/*
public void addToRole(UserRole role) {
public void addToRole(AccountRole role) {
synchronized (this)
{
if ((role != null) && !(getRoles().contains(role)) )
{
role.getPersons().add(this);
role.getAccounts().add(this);
getRoles().add(role);
}
}
}
*/
/**
* Remove the user from a given {@link UserRole}s.
* @param role the {@link UserRole} this {@link Person} will lose. Ignored if <code>null</code>.
* Remove the user from a given {@link AccountRole}s.
* @param role the {@link AccountRole} this {@link Account} will lose. Ignored if <code>null</code>.
* @see #getRoles()
* @see #setRoles(List)
* @see #addToRole(UserRole)
* @see #addToRole(AccountRole)
*/
/*
public void removeFromRole(UserRole role) {
public void removeFromRole(AccountRole role) {
synchronized (this)
{
if ((role != null) && (getRoles().contains(role)) )
{
role.getPersons().remove(this);
role.getAccounts().remove(this);
getRoles().remove(role);
}
}
......@@ -300,7 +300,7 @@ public class Person /* extends org.roliste.data.DbTraceableEntity */ implements
*/
/**
* Remove a book from user's collection.
* @param book the {@link org.roliste.data.db.BookDetails} this {@link Person} will lose. Ignored if <code>null</code>.
* @param book the {@link org.roliste.data.db.BookDetails} this {@link Account} will lose. Ignored if <code>null</code>.
* @see #getCollection()
* @see #setCollection(List)
* @see #addToCollection(BookDetails)
......@@ -326,7 +326,7 @@ public class Person /* extends org.roliste.data.DbTraceableEntity */ implements
* Retrieves the list of delegations for this user.
* Each delegation is a link to a {@link org.roliste.data.db.Traceable} object.
* A user having delegation may update field values for delegated object.
* @return a {@link List} of {@link UserRole}. Shall not be <code>null</code>. SHALL be used as a
* @return a {@link List} of {@link AccountRole}. Shall not be <code>null</code>. SHALL be used as a
* read-only attribute. In particular, avoid using {@link List#add(Object)} or {@link List#remove(Object)}
* on the returned value without caution.
* @see #setDelegations(List)
......@@ -389,7 +389,7 @@ public class Person /* extends org.roliste.data.DbTraceableEntity */ implements
*/
/**
* Remove delegation on a given {@link Traceable} from this user.
* @param object the delegation this {@link Person} will lose. Ignored if <code>null</code>.
* @param object the delegation this {@link Account} will lose. Ignored if <code>null</code>.
* @see #getDelegations()
* @see #setDelegations(List)
* @see #giveDelegation(Traceable)
......@@ -426,12 +426,12 @@ public class Person /* extends org.roliste.data.DbTraceableEntity */ implements
* The list of attributes / properties for this user.
*/
@OneToMany(mappedBy = "person")
private List<UserAttribute> userAttributes;
private List<AccountAttribute> accountAttributes;
/**
* Retrieve this user's attributes.
* @hibernate.one-to-many
* class="org.roliste.data.db.UserAttribute"
* class="org.roliste.data.db.AccountAttribute"
* @hibernate.bag
* cascade="all"
* lazy="true"
......@@ -442,9 +442,9 @@ public class Person /* extends org.roliste.data.DbTraceableEntity */ implements
* @see #setAttributes(java.util.List)
*/
public List<UserAttribute> getAttributes()
public List<AccountAttribute> getAttributes()
{
return userAttributes;
return accountAttributes;
}
/**
......@@ -452,9 +452,9 @@ public class Person /* extends org.roliste.data.DbTraceableEntity */ implements
* @see #getAttributes()
*/
public void setAttributes(List<UserAttribute> attribs)
public void setAttributes(List<AccountAttribute> attribs)
{
this.userAttributes = attribs;
this.accountAttributes = attribs;
}
/**
......
......@@ -7,7 +7,7 @@ import javax.persistence.*;
Migréee depuis la v2.
*/
@Entity
public class UserAttribute {
public class AccountAttribute {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int userAttributeId;
......@@ -17,69 +17,69 @@ public class UserAttribute {
}
/**
* The linked person.
* The linked account.
*/
@ManyToOne
private Person person;
private Account account;
/**
* Retrieve the person this attribute is attached to.
* Retrieve the account this attribute is attached to.
* hibernate.many-to-one
* column="ID_UTILISATEUR"
* class="org.roliste.data.db.Person"
* class="org.roliste.data.db.Account"
* not-null="true"
* access="property"
* lazy="proxy"
* properties-name="PropertyPerUser"
* foreign-key="FK_ATTRIBUTUTILISATEUR_UTILISATEUR"
* @return the {link org.roliste.data.db.Person} this attribute is attached to.
* @return the {link org.roliste.data.db.Account} this attribute is attached to.
* Shall not be <code>null</code>.
* see #setPerson(org.roliste.data.db.Person)
* see #setAccount(org.roliste.data.db.Account)
*/
public Person getPerson() {
return person;
public Account getAccount() {
return account;
}
/**
* Set the person this attribute is attached to.
* @param person the new {link org.roliste.data.db.Person} this attribute will be attached to. Shall not be <code>null</code>.
* @see #getPerson()
* Set the account this attribute is attached to.
* @param account the new {link org.roliste.data.db.Account} this attribute will be attached to. Shall not be <code>null</code>.
* @see #getAccount()
*/
public void setPerson(Person person) {
this.person = person;
public void setAccount(Account account) {
this.account = account;
}
/**
* The linked property.
*/
@ManyToOne
private UserProperty userProperty;
private AccountProperty accountProperty;
/**
* Retrieve the property this attribute is attached to.
* hibernate.many-to-one
* column="ID_PROP"
* class="org.roliste.data.db.UserProperty"
* class="org.roliste.data.db.AccountProperty"
* not-null="true"
* access="property"
* lazy="false"
* properties-name="PropertyPerUser"
* foreign-key="FK_ATTRIBUTUTILISATEUR_PROPRIETE"
* @return the {link org.roliste.data.db.UserProperty} this attribute is attached to.
* @return the {link org.roliste.data.db.AccountProperty} this attribute is attached to.
* Shall not be <code>null</code>.
* see #setProperty(org.roliste.data.db.UserProperty)
* see #setProperty(org.roliste.data.db.AccountProperty)
*/
public UserProperty getProperty() {
return userProperty;
public AccountProperty getProperty() {
return accountProperty;
}
/**
* Set the property this attribute is attached to.
* @param prop the new {link org.roliste.data.db.UserProperty} this attribute will be attached to. Shall not be <code>null</code>.
* @param prop the new {link org.roliste.data.db.AccountProperty} this attribute will be attached to. Shall not be <code>null</code>.
* @see #getProperty()
*/
public void setProperty(UserProperty prop) {
userProperty = prop;
public void setProperty(AccountProperty prop) {
accountProperty = prop;
}
/**
......@@ -112,14 +112,14 @@ public class UserAttribute {
}
/**
* Returns a string representation of this person attribute definition.
* @return a string representing this person attribute definition.
* Returns a string representation of this account attribute definition.
* @return a string representing this account attribute definition.
* hidden
*/
@Override
public String toString()
{
return "ID_ATTR=" + getUserAttributeId() + " ATTR_PROP=" + userProperty + " ATTR_VALUE=" + value;
return "ID_ATTR=" + getUserAttributeId() + " ATTR_PROP=" + accountProperty + " ATTR_VALUE=" + value;
}
}
......
......@@ -2,5 +2,5 @@ package org.legrog.entities;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserPropertyRepository extends JpaRepository<UserProperty, Integer> {
public interface AccountAttributeRepository extends JpaRepository<AccountAttribute, Integer> {
}
......
......@@ -7,7 +7,7 @@ import javax.persistence.*;
Importée depuis la v2.
*/
@Entity
public class UserProperty {
public class AccountProperty {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY) /* Permet la population */
private int userPropertyId;
......
......@@ -2,5 +2,5 @@ package org.legrog.entities;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserRoleRepository extends JpaRepository<UserRole, Integer> {
}
\ No newline at end of file
public interface AccountPropertyRepository extends JpaRepository<AccountProperty, Integer> {
}
......
......@@ -2,5 +2,5 @@ package org.legrog.entities;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PersonRepository extends JpaRepository<Person, Integer> {
public interface AccountRepository extends JpaRepository<Account, Integer> {
}
......
......@@ -7,11 +7,11 @@ import javax.persistence.*;
/**
* The database representation of a user role or group.
* A given {@link Person} may be part of one or more {@link UserRole}.
* 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.
* You shall always use the getter/setter methods.
* alias UserRole
* alias AccountRole
*
*/
/*
......@@ -19,7 +19,7 @@ import javax.persistence.*;
*/
@Entity
// TODO évaluer extend v2
public class UserRole /* extends org.roliste.data.DbEntity */
public class AccountRole /* extends org.roliste.data.DbEntity */
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......@@ -31,10 +31,10 @@ public class UserRole /* extends org.roliste.data.DbEntity */
private String rolename;
/**
* The {@link Person}s for this user role.
* The {@link Account}s for this user role.
*/
@ManyToMany(mappedBy = "roles")
private Set<Person> persons;
private Set<Account> accounts;
/**
* Builds a new and empty user role definition.
......@@ -42,12 +42,12 @@ public class UserRole /* extends org.roliste.data.DbEntity */
* <br/>
* Needed by Hibernate for Java reflection.
*/
public UserRole() {
public AccountRole() {
super();
rolename = null;
visible = true;
// no need to synchronize this
persons = new HashSet<Person>();
accounts = new HashSet<Account>();
}
public int getUserRoleId() {
......@@ -90,7 +90,7 @@ public class UserRole /* extends org.roliste.data.DbEntity */
/**
* Indicates if the role is visible.
* If not, persons should not be able to access the privileges
* If not, accounts should not be able to access the privileges
* they inherit from being part of this role.
* @return the visible flag.
* @see #setVisible(boolean)
......@@ -112,12 +112,12 @@ public class UserRole /* extends org.roliste.data.DbEntity */
}
/**
* Retrieves the list of {@link Person}s for this user role.
* Retrieves the list of {@link Account}s for this user 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.
* @return a {@link Set} of {@link Person}. May be <code>null</code>.
* @see #setPersons(Set)
* @return a {@link Set} of {@link Account}. May be <code>null</code>.
* @see #setAccounts(Set)
* hibernate.many-to-many
* column="UTILISATEUR_FK"
* class="org.roliste.data.db.Person"
......@@ -132,18 +132,18 @@ public class UserRole /* extends org.roliste.data.DbEntity */
* lazy="true"
* inverse="true"
*/
public Set<Person> getPersons() {
return persons;
public Set<Account> getAccounts() {
return accounts;
}
/**
* Sets the list of {@link Person}s for this user role.
* @param persons the new {@link Set} of {@link Person}s. May be
* Sets the list of {@link Account}s for this user 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 #getPersons()
* @see #getAccounts()
*/
protected void setPersons(Set<Person> persons) {
this.persons = persons;
protected void setAccounts(Set<Account> accounts) {
this.accounts = accounts;
}
/**
......
......@@ -2,5 +2,5 @@ package org.legrog.entities;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserAttributeRepository extends JpaRepository<UserAttribute, Integer> {
}
public interface AccountRoleRepository extends JpaRepository<AccountRole, Integer> {
}
\ No newline at end of file
......
......@@ -15,7 +15,7 @@ public class PublisherAction {
@Enumerated
private ActionType actionType;
@ManyToOne
private Person publisherActionAuthor;
private Account publisherActionAuthor;
@ManyToOne
private PublisherVersion publisherVersion;
......@@ -25,7 +25,7 @@ public class PublisherAction {
@ManyToOne
private Publisher publisher;
public void setPublisherActionAuthor(Person publisherActionAuthor) {
public void setPublisherActionAuthor(Account publisherActionAuthor) {
this.publisherActionAuthor = publisherActionAuthor;
}
......@@ -49,7 +49,7 @@ public class PublisherAction {
return actionType;
}
public Person getPublisherActionAuthor() {
public Account getPublisherActionAuthor() {
return publisherActionAuthor;
}
......
......@@ -31,7 +31,7 @@ public class PublisherVersion {
private boolean publisherActive;
private String publisherHistory;
@ManyToOne
private Person publisherVersionAuthor;
private Account publisherVersionAuthor;
private Timestamp publisherVersionDatetime;
public Timestamp getPublisherVersionDatetime() {
......@@ -146,11 +146,11 @@ public class PublisherVersion {
this.publisherAddressCountry = publisherAddressCountry;
}
public Person getPublisherVersionAuthor() {
public Account getPublisherVersionAuthor() {
return publisherVersionAuthor;
}
public void setPublisherVersionAuthor(Person publisherVersionAuthor) {
public void setPublisherVersionAuthor(Account publisherVersionAuthor) {
this.publisherVersionAuthor = publisherVersionAuthor;
}
......
......@@ -43,7 +43,7 @@ public class PublisherVersionView implements Serializable {
private String publisherURL;
private boolean publisherActive;
private String publisherHistory;
private transient Person publisherVersionAuthor;
private transient Account publisherVersionAuthor;
private Timestamp publisherVersionDatetime;
private transient Publisher publisher;
......@@ -312,11 +312,11 @@ public class PublisherVersionView implements Serializable {
this.publisherHistory = publisherHistory;
}
public Person getPublisherVersionAuthor() {
public Account getPublisherVersionAuthor() {
return publisherVersionAuthor;
}
public void setPublisherVersionAuthor(Person publisherVersionAuthor) {
public void setPublisherVersionAuthor(Account publisherVersionAuthor) {
this.publisherVersionAuthor = publisherVersionAuthor;
}
......
package org.legrog.web.user;
import org.legrog.entities.Person;
import org.legrog.entities.Account;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
......@@ -14,19 +14,19 @@ public class ListUsersBean {
@Inject
private UserService userService;
private List<Person> persons;
private List<Account> accounts;
public List<Person> getPersons() {
return persons;
public List<Account> getAccounts() {
return accounts;
}
public void setPersons(List<Person> persons) {
this.persons = persons;
public void setAccounts(List<Account> accounts) {
this.accounts = accounts;
}
@PostConstruct
public void init() {
persons = userService.getAllUsers();
accounts = userService.getAllUsers();
}
}
......
......@@ -24,8 +24,8 @@ public class UpdateUserBean {
private SharedService sharedService;
private List<DisplayNameMask> allDisplayNameMasks;
private List<UserRole> availableUserRoles;
private List<UserProperty> availableUserProperties;
private List<AccountRole> availableAccountRoles;
private List<AccountProperty> availableUserProperties;
@ManagedProperty("#{param.userId}")
private int userId;
......@@ -37,9 +37,9 @@ public class UpdateUserBean {
private String email;
private boolean anonymous;
private String password;
private List<UserRole> roles;
private List<AccountRole> roles;
private String presentation;
private List<UserAttribute> userAttributes;
private List<AccountAttribute> accountAttributes;
private boolean criticProvider;
private boolean visible;
private boolean activated;
......@@ -59,41 +59,41 @@ public class UpdateUserBean {
public void init() {
logger.info("init");
allDisplayNameMasks = sharedService.getAllDisplayNameMasks();
availableUserRoles = sharedService.getAvailableUserRoles();
availableAccountRoles = sharedService.getAvailableUserRoles();
availableUserProperties = sharedService.getAvailableUserProperties();
}
public String add() {
Person person = new Person();
person.setActivated(activated);
person.setAnonymous(anonymous);
if (userAttributes != null) {
person.setAttributes(userAttributes);
Account account = new Account();
account.setActivated(activated);
account.setAnonymous(anonymous);
if (accountAttributes != null) {
account.setAttributes(accountAttributes);
}
person.setCriticProvider(criticProvider);
account.setCriticProvider(criticProvider);
if (displayNameMask != null) {
person.setDisplayNameMask(displayNameMask);
account.setDisplayNameMask(displayNameMask);
} else {
person.setDisplayNameMask(DisplayNameMask.PRENOMNOM);
account.setDisplayNameMask(DisplayNameMask.PRENOMNOM);
}
person.setEmail(email);
person.setFirstName(firstName);
person.setLastName(lastName);
account.setEmail(email);
account.setFirstName(firstName);
account.setLastName(lastName);
if (nickName != null && !nickName.isEmpty()) {
person.setNickName(nickName);
account.setNickName(nickName);
}
person.setPassword(password);
account.setPassword(password);
if (presentation != null) {
person.setPresentation(presentation);
account.setPresentation(presentation);
}
if (roles != null) {
person.setRoles(roles);
account.setRoles(roles);
}
person.setUsername(username);
person.setVisible(visible);
person.setCreationDate(new Date());
userService.addUser(person);
account.setUsername(username);
account.setVisible(visible);
account.setCreationDate(new Date());
userService.addUser(account);
return "success";
}
......@@ -103,25 +103,25 @@ public class UpdateUserBean {
logger.info("userId =" + userId);
this.userId = userId;
if (userId != 0) {
Person person = userService.findUserById(userId);
if (person != null) {
activated = person.isActivated();
anonymous = person.isAnonymous();
userAttributes = person.getAttributes();
criticProvider = person.isCriticProvider();
displayNameMask = person.getDisplayNameMask();
email = person.getEmail();
firstName = person.getFirstName();
lastName = person.getLastName();
nickName = person.getNickName();
password = person.getPassword();
presentation = person.getPresentation();
roles = person.getRoles();
Account account = userService.findUserById(userId);
if (account != null) {
activated = account.isActivated();
anonymous = account.isAnonymous();
accountAttributes = account.getAttributes();
criticProvider = account.isCriticProvider();
displayNameMask = account.getDisplayNameMask();
email = account.getEmail();
firstName = account.getFirstName();
lastName = account.getLastName();
nickName = account.getNickName();
password = account.getPassword();
presentation = account.getPresentation();
roles = account.getRoles();
if (roles == null) {
roles = new ArrayList<UserRole>();
roles = new ArrayList<AccountRole>();
}
username = person.getUsername();
visible = person.isVisible();
username = account.getUsername();
visible = account.isVisible();
return "updateUser.xhtml";
}
}
......@@ -132,32 +132,32 @@ public class UpdateUserBean {
logger.info("update");
logger.info("userId =" + userId);
Person person = userService.findUserById(userId);
person.setActivated(activated);
person.setAnonymous(anonymous);
person.setAttributes(userAttributes);
person.setCriticProvider(criticProvider);
person.setDisplayNameMask(displayNameMask);
person.setEmail(email);
person.setFirstName(firstName);
person.setLastName(lastName);
person.setNickName(nickName);
person.setPassword(password);
person.setPresentation(presentation);
person.setRoles(roles);
person.setUsername(username);
person.setVisible(visible);
userService.updateUser(person);
Account account = userService.findUserById(userId);
account.setActivated(activated);
account.setAnonymous(anonymous);
account.setAttributes(accountAttributes);
account.setCriticProvider(criticProvider);
account.setDisplayNameMask(displayNameMask);
account.setEmail(email);
account.setFirstName(firstName);
account.setLastName(lastName);
account.setNickName(nickName);
account.setPassword(password);
account.setPresentation(presentation);
account.setRoles(roles);
account.setUsername(username);
account.setVisible(visible);
userService.updateUser(account);
return "success";
}
public List<UserRole> getAvailableUserRoles() {
return availableUserRoles;
public List<AccountRole> getAvailableAccountRoles() {
return availableAccountRoles;
}
public void setAvailableUserRoles(List<UserRole> availableUserRoles) {
this.availableUserRoles = availableUserRoles;
public void setAvailableAccountRoles(List<AccountRole> availableAccountRoles) {
this.availableAccountRoles = availableAccountRoles;
}
public String getPresentation() {
......@@ -168,20 +168,20 @@ public class UpdateUserBean {
this.presentation = presentation;
}
public List<UserProperty> getAvailableUserProperties() {
public List<AccountProperty> getAvailableUserProperties() {
return availableUserProperties;
}
public void setAvailableUserProperties(List<UserProperty> availableUserProperties) {
public void setAvailableUserProperties(List<AccountProperty> availableUserProperties) {
this.availableUserProperties = availableUserProperties;
}
public List<UserAttribute> getUserAttributes() {
return userAttributes;
public List<AccountAttribute> getAccountAttributes() {
return accountAttributes;
}
public void setUserAttributes(List<UserAttribute> userAttributes) {
this.userAttributes = userAttributes;
public void setAccountAttributes(List<AccountAttribute> accountAttributes) {
this.accountAttributes = accountAttributes;
}
public boolean isCriticProvider() {
......@@ -304,11 +304,11 @@ public class UpdateUserBean {
this.password = password;
}
public List<UserRole> getRoles() {
public List<AccountRole> getRoles() {
return roles;
}
public void setRoles(List<UserRole> roles) {
public void setRoles(List<AccountRole> roles) {
this.roles = roles;
}
}
\ No newline at end of file
......
package org.legrog.web.user;
import org.legrog.entities.Person;
import org.legrog.entities.Account;
import java.util.List;
public interface UserService {
void addUser(Person person);
void addUser(Account account);
List<Person> getAllUsers();
List<Account> getAllUsers();
Person findUserById(int id);
Account findUserById(int id);
void updateUser(Person person);
void updateUser(Account account);
}
......
package org.legrog.web.user;
import org.legrog.entities.Person;
import org.legrog.entities.PersonRepository;
import org.legrog.entities.Account;
import org.legrog.entities.AccountRepository;
import javax.ejb.Stateless;
import javax.inject.Inject;
......@@ -10,21 +10,21 @@ import java.util.List;
@Stateless
public class UserServiceSpring implements UserService {
@Inject
PersonRepository personRepository;
AccountRepository accountRepository;
public void addUser(Person person) {
personRepository.save(person);
public void addUser(Account account) {
accountRepository.save(account);
}
public List<Person> getAllUsers() {
return personRepository.findAll();
public List<Account> getAllUsers() {
return accountRepository.findAll();
}
public Person findUserById(int id) {
return personRepository.findOne(new Integer(id));
public Account findUserById(int id) {
return accountRepository.findOne(new Integer(id));
}
public void updateUser(Person person) {
personRepository.save(person);
public void updateUser(Account account) {
accountRepository.save(account);
}
}
\ No newline at end of file
......
......@@ -32,17 +32,17 @@
<div id="listElements">
<h:commandLink styleClass="fRight acLink" action="add" rendered="#{not empty listUsersBean.persons}" >
<h:commandLink styleClass="fRight acLink" action="add" rendered="#{not empty listUsersBean.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.persons}"
var="person" value="#{listUsersBean.persons}"
<p:dataTable id="tableElements" rendered="#{not empty listUsersBean.accounts}"
var="account" value="#{listUsersBean.accounts}"
styleClass="results" rowClasses="altRichRow,altRow">
<!-- TODO Grer la pagination -->
<!-- <p:dataTable id="tableElements" rendered="#{listUsersBean.persons.size>0}"
var="person" value="#{listUsersBean.persons}" rows="#{userListMgr.pageSize}"
<!-- <p:dataTable id="tableElements" rendered="#{listUsersBean.accounts.size>0}"
var="account" value="#{listUsersBean.accounts}" rows="#{userListMgr.pageSize}"
styleClass="results" rowClasses="altRichRow,altRow">-->
<f:facet name="header">
<p:dataScroller for="tableElements"
......@@ -61,35 +61,35 @@
</h:commandLink>-->
</p:column>
<p:column>
<h:commandLink action="#{updateUserBean.prepareUpdate(person.userId)}">
<h:commandLink action="#{updateUserBean.prepareUpdate(account.userId)}">
<img src="/images/structure/vide.gif" class="icEdit" alt="Modifier" title="Modifier" />
</h:commandLink>
</p:column>
<p:column styleClass="third" sortBy="#{person.username}">
<p:column styleClass="third" sortBy="#{account.username}">
<f:facet name="header">Identifiant</f:facet>
<!-- TODO Dcider de l'avenir de traceable -->
<ui:remove>
<!-- <h:outputLink value="#{person.traceable.urlRewrite}">-->
<!-- <h:outputLink value="#{account.traceable.urlRewrite}">-->
</ui:remove>
<h:outputText value="#{person.username}" />
<h:outputText value="#{account.username}" />
<!-- </h:outputLink>-->
</p:column>
<p:column styleClass="third" sortBy="#{person.firstName} #{person.lastName}">
<p:column styleClass="third" sortBy="#{account.firstName} #{account.lastName}">
<f:facet name="header">Nom</f:facet>
<ui:remove>
<!--<h:outputLink value="#{person.traceable.urlRewrite}">-->
<!--<h:outputLink value="#{account.traceable.urlRewrite}">-->
</ui:remove>
<h:outputText value="#{person.firstName} #{person.lastName}" />
<h:outputText value="#{account.firstName} #{account.lastName}" />
<!--</h:outputLink>-->
</p:column>
<p:column styleClass="third" sortBy="#{person.email}">
<p:column styleClass="third" sortBy="#{account.email}">
<f:facet name="header">Email</f:facet>
<h:outputText value="#{person.email}" />
<h:outputText value="#{account.email}" />
</p:column>
<p:column>
<h:graphicImage value="/images/structure/dVert.gif" rendered="#{person.visible and person.activated}" title="Utilisateur activ" />
<h:graphicImage value="/images/structure/dOrange.gif" rendered="#{(not person.visible) and person.activated}" title="Utilisateur dsactiv" />
<h:graphicImage value="/images/structure/dRouge.gif" rendered="#{not person.activated}" title="Utilisateur non enregistr" />
<h:graphicImage value="/images/structure/dVert.gif" rendered="#{account.visible and account.activated}" title="Utilisateur activ" />
<h:graphicImage value="/images/structure/dOrange.gif" rendered="#{(not account.visible) and account.activated}" title="Utilisateur dsactiv" />
<h:graphicImage value="/images/structure/dRouge.gif" rendered="#{not account.activated}" title="Utilisateur non enregistr" />
</p:column>
<f:facet name="footer">
<h:commandLink action="add" value="Crer un nouvel utilisateur" >
......@@ -99,7 +99,7 @@
</div>
<p>
<h:commandLink action="add" value="Crer un nouvel utilisateur"
rendered="#{empty listUsersBean.persons}">
rendered="#{empty listUsersBean.accounts}">
</h:commandLink>
</p>
</h:form>
......
......@@ -12,8 +12,8 @@
</h:commandLink>
</h:form>
<ul>
<ui:repeat value="#{listUsersBean.persons}" var="person">
<li>#{person.username}</li>
<ui:repeat value="#{listUsersBean.accounts}" var="account">
<li>#{account.username}</li>
</ui:repeat>
</ul>
</f:view>
......
......@@ -86,7 +86,7 @@
<td><h:outputLabel for="roles">Rles</h:outputLabel></td>
<td>
<h:selectManyCheckbox id="roles" value="#{updateUserBean.roles}" converter="omnifaces.SelectItemsConverter" layout="pageDirection" >
<f:selectItems value="#{updateUserBean.availableUserRoles}" var="role" itemLabel="#{role.rolename}" />
<f:selectItems value="#{updateUserBean.availableAccountRoles}" var="role" itemLabel="#{role.rolename}" />
</h:selectManyCheckbox>
</td>
<td><h:message errorClass="errorMsg" infoClass="infoMsg" for="roles"/></td>
......@@ -110,7 +110,7 @@
<h:outputText value="#{userProperty.tag}"/>
</h:column>
<h:column>
<h:inputText id="prop_#{userProperty.name}" value="#{updateUserBean.userAttributes[userProperty.name].value}" style="width: 175px;">
<h:inputText id="prop_#{userProperty.name}" value="#{updateUserBean.accountAttributes[userProperty.name].value}" style="width: 175px;">
<f:validateLength maximum="200"/>
</h:inputText>
</h:column>
......
......@@ -12,9 +12,9 @@ public interface SharedService {
List<DisplayNameMask> getAllDisplayNameMasks();
List<UserRole> getAvailableUserRoles();
List<AccountRole> getAvailableUserRoles();
List<UserProperty> getAvailableUserProperties();
List<AccountProperty> getAvailableUserProperties();
Person getCurrentUser();
Account getCurrentUser();
}
\ No newline at end of file
......
......@@ -15,16 +15,16 @@ import java.util.Vector;
public class SharedServiceSpring implements SharedService {
CountryRepository countryRepository;
UserRoleRepository userRoleRepository;
UserPropertyRepository userPropertyRepository;
AccountRoleRepository accountRoleRepository;
AccountPropertyRepository accountPropertyRepository;
UserService userService;
@Inject
public SharedServiceSpring(CountryRepository countryRepository, UserRoleRepository userRoleRepository,
UserPropertyRepository userPropertyRepository, UserService userService) {
public SharedServiceSpring(CountryRepository countryRepository, AccountRoleRepository accountRoleRepository,
AccountPropertyRepository accountPropertyRepository, UserService userService) {
this.countryRepository = countryRepository;
this.userRoleRepository = userRoleRepository;
this.userPropertyRepository = userPropertyRepository;
this.accountRoleRepository = accountRoleRepository;
this.accountPropertyRepository = accountPropertyRepository;
this.userService = userService;
}
......@@ -52,18 +52,18 @@ public class SharedServiceSpring implements SharedService {
return allDisplayNameMasks;
}
public List<UserRole> getAvailableUserRoles() {
return userRoleRepository.findAll();
public List<AccountRole> getAvailableUserRoles() {
return accountRoleRepository.findAll();
}
public List<UserProperty> getAvailableUserProperties() { return userPropertyRepository.findAll(); }
public List<AccountProperty> getAvailableUserProperties() { return accountPropertyRepository.findAll(); }
public Person getCurrentUser() {
public Account getCurrentUser() {
// TODO Remplacer l'astuce par une vraie récupération de l'utilisateur
List<Person> persons = userService.getAllUsers();
List<Account> accounts = userService.getAllUsers();
Random random = new Random();
Person person = persons.get(random.nextInt(persons.size()));
Account account = accounts.get(random.nextInt(accounts.size()));
// End TODO
return person;
return account;
}
}
......
......@@ -7,6 +7,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.legrog.entities.AccountProperty;
import org.legrog.entities.AccountRole;
import org.legrog.entities.DisplayNameMask;
import org.legrog.test.MockitoExtension;
import org.legrog.web.xyz.SharedService;
......@@ -20,10 +22,10 @@ import static org.mockito.Mockito.when;
/**
* Created by jai on 15/11/16.
*/
@DisplayName("Update Person Bean")
@DisplayName("Update Account Bean")
@ExtendWith(MockitoExtension.class)
@RunWith(JUnitPlatform.class)
public class UpdatePersonBeanTest {
public class UpdateAccountBeanTest {
UpdateUserBean updateUserBean;
......@@ -33,7 +35,7 @@ public class UpdatePersonBeanTest {
}
@Test
@DisplayName("depends on Shared Service and Person Service")
@DisplayName("depends on Shared Service and Account Service")
public void testDependencies() {
assertThat(updateUserBean).isNotNull();
}
......@@ -43,14 +45,14 @@ public class UpdatePersonBeanTest {
class init {
private List<DisplayNameMask> displayNameMasks;
private List<org.legrog.entities.UserProperty> userProperties;
private List<org.legrog.entities.UserRole> userRoles;
private List<AccountProperty> userProperties;
private List<AccountRole> accountRoles;
@BeforeEach
public void setUp(@Mock SharedService sharedService) {
when(sharedService.getAllDisplayNameMasks()).thenReturn(displayNameMasks);
when(sharedService.getAvailableUserProperties()).thenReturn(userProperties);
when(sharedService.getAvailableUserRoles()).thenReturn(userRoles);
when(sharedService.getAvailableUserRoles()).thenReturn(accountRoles);
}
@Test
......@@ -59,7 +61,7 @@ public class UpdatePersonBeanTest {
updateUserBean.init();
assertThat(updateUserBean.getAllDisplayNameMasks()).isEqualTo(displayNameMasks);
assertThat(updateUserBean.getAvailableUserProperties()).isEqualTo(userProperties);
assertThat(updateUserBean.getAvailableUserRoles()).isEqualTo(userRoles);
assertThat(updateUserBean.getAvailableAccountRoles()).isEqualTo(accountRoles);
}
}
......