Jean-Francois Leveque

Elimination des annotations BD et refactoring de User en Person car user est un mot réservé en BD.

......@@ -11,12 +11,10 @@ import java.util.*;
Migréee depuis la v2.
*/
@Entity
@Table(name="UserTable")
public class User /* extends org.roliste.data.DbTraceableEntity */ implements DisplayNameConfigurable /*, DbValidationEntity */ {
public class Person /* extends org.roliste.data.DbTraceableEntity */ implements DisplayNameConfigurable /*, DbValidationEntity */ {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="USER_ID")
private int userId;
// TODO traiter Traceable
......@@ -183,7 +181,7 @@ public class User /* extends org.roliste.data.DbTraceableEntity */ implements Di
{
if ((role != null) && !(getRoles().contains(role)) )
{
role.getUsers().add(this);
role.getPersons().add(this);
getRoles().add(role);
}
}
......@@ -191,7 +189,7 @@ public class User /* extends org.roliste.data.DbTraceableEntity */ implements Di
*/
/**
* Remove the user from a given {@link UserRole}s.
* @param role the {@link UserRole} this {@link User} will lose. Ignored if <code>null</code>.
* @param role the {@link UserRole} this {@link Person} will lose. Ignored if <code>null</code>.
* @see #getRoles()
* @see #setRoles(List)
* @see #addToRole(UserRole)
......@@ -202,7 +200,7 @@ public class User /* extends org.roliste.data.DbTraceableEntity */ implements Di
{
if ((role != null) && (getRoles().contains(role)) )
{
role.getUsers().remove(this);
role.getPersons().remove(this);
getRoles().remove(role);
}
}
......@@ -303,7 +301,7 @@ public class User /* extends org.roliste.data.DbTraceableEntity */ implements Di
*/
/**
* Remove a book from user's collection.
* @param book the {@link org.roliste.data.db.BookDetails} this {@link User} will lose. Ignored if <code>null</code>.
* @param book the {@link org.roliste.data.db.BookDetails} this {@link Person} will lose. Ignored if <code>null</code>.
* @see #getCollection()
* @see #setCollection(List)
* @see #addToCollection(BookDetails)
......@@ -392,7 +390,7 @@ public class User /* extends org.roliste.data.DbTraceableEntity */ implements Di
*/
/**
* Remove delegation on a given {@link Traceable} from this user.
* @param object the delegation this {@link User} will lose. Ignored if <code>null</code>.
* @param object the delegation this {@link Person} will lose. Ignored if <code>null</code>.
* @see #getDelegations()
* @see #setDelegations(List)
* @see #giveDelegation(Traceable)
......
......@@ -2,5 +2,5 @@ package org.legrog.entities;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserRepository extends JpaRepository<User, Integer> {
public interface PersonRepository extends JpaRepository<Person, Integer> {
}
......
......@@ -15,7 +15,7 @@ public class PublisherAction {
@ManyToOne
private UserAction userAction;
@ManyToOne
private User publisherActionAuthor;
private Person publisherActionAuthor;
@ManyToOne
private PublisherVersion publisherVersion;
......@@ -25,7 +25,7 @@ public class PublisherAction {
@ManyToOne
private Publisher publisher;
public void setPublisherActionAuthor(User publisherActionAuthor) {
public void setPublisherActionAuthor(Person publisherActionAuthor) {
this.publisherActionAuthor = publisherActionAuthor;
}
......@@ -49,7 +49,7 @@ public class PublisherAction {
return userAction;
}
public User getPublisherActionAuthor() {
public Person getPublisherActionAuthor() {
return publisherActionAuthor;
}
......
......@@ -31,7 +31,7 @@ public class PublisherVersion {
private boolean publisherActive;
private String publisherHistory;
@ManyToOne
private User publisherVersionAuthor;
private Person publisherVersionAuthor;
private Timestamp publisherVersionDatetime;
public Timestamp getPublisherVersionDatetime() {
......@@ -146,11 +146,11 @@ public class PublisherVersion {
this.publisherAddressCountry = publisherAddressCountry;
}
public User getPublisherVersionAuthor() {
public Person getPublisherVersionAuthor() {
return publisherVersionAuthor;
}
public void setPublisherVersionAuthor(User publisherVersionAuthor) {
public void setPublisherVersionAuthor(Person publisherVersionAuthor) {
this.publisherVersionAuthor = publisherVersionAuthor;
}
......
......@@ -17,37 +17,37 @@ public class UserAttribute {
}
/**
* The linked user.
* The linked person.
*/
@ManyToOne
@JoinColumn(name = "USER_ID")
private User user;
private Person person;
/**
* Retrieve the user this attribute is attached to.
* Retrieve the person this attribute is attached to.
* hibernate.many-to-one
* column="ID_UTILISATEUR"
* class="org.roliste.data.db.User"
* class="org.roliste.data.db.Person"
* not-null="true"
* access="property"
* lazy="proxy"
* properties-name="PropertyPerUser"
* foreign-key="FK_ATTRIBUTUTILISATEUR_UTILISATEUR"
* @return the {link org.roliste.data.db.User} this attribute is attached to.
* @return the {link org.roliste.data.db.Person} this attribute is attached to.
* Shall not be <code>null</code>.
* see #setUser(org.roliste.data.db.User)
* see #setPerson(org.roliste.data.db.Person)
*/
public User getUser() {
return user;
public Person getPerson() {
return person;
}
/**
* Set the user this attribute is attached to.
* @param user the new {link org.roliste.data.db.User} this attribute will be attached to. Shall not be <code>null</code>.
* @see #getUser()
* 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()
*/
public void setUser(User user) {
this.user = user;
public void setPerson(Person person) {
this.person = person;
}
/**
......@@ -114,8 +114,8 @@ public class UserAttribute {
}
/**
* Returns a string representation of this user attribute definition.
* @return a string representing this user attribute definition.
* Returns a string representation of this person attribute definition.
* @return a string representing this person attribute definition.
* hidden
*/
@Override
......
......@@ -7,7 +7,7 @@ import javax.persistence.*;
/**
* The database representation of a user role or group.
* A given {@link User} may be part of one or more {@link UserRole}.
* A given {@link Person} may be part of one or more {@link UserRole}.
* <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.
......@@ -23,7 +23,6 @@ public class UserRole /* extends org.roliste.data.DbEntity */
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="USER_ROLE_ID")
private int userRoleId;
/**
......@@ -32,11 +31,10 @@ public class UserRole /* extends org.roliste.data.DbEntity */
private String rolename;
/**
* The {@link User}s for this user role.
* The {@link Person}s for this user role.
*/
@ManyToMany(mappedBy = "roles")
@Column(name = "USER_ID")
private Set<User> users;
private Set<Person> persons;
/**
* Builds a new and empty user role definition.
......@@ -49,7 +47,7 @@ public class UserRole /* extends org.roliste.data.DbEntity */
rolename = null;
visible = true;
// no need to synchronize this
users = new HashSet<User>();
persons = new HashSet<Person>();
}
public int getUserRoleId() {
......@@ -92,7 +90,7 @@ public class UserRole /* extends org.roliste.data.DbEntity */
/**
* Indicates if the role is visible.
* If not, users should not be able to access the privileges
* If not, persons should not be able to access the privileges
* they inherit from being part of this role.
* @return the visible flag.
* @see #setVisible(boolean)
......@@ -114,15 +112,15 @@ public class UserRole /* extends org.roliste.data.DbEntity */
}
/**
* Retrieves the list of {@link User}s for this user role.
* Retrieves the list of {@link Person}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 User}. May be <code>null</code>.
* @see #setUsers(Set)
* @return a {@link Set} of {@link Person}. May be <code>null</code>.
* @see #setPersons(Set)
* hibernate.many-to-many
* column="UTILISATEUR_FK"
* class="org.roliste.data.db.User"
* class="org.roliste.data.db.Person"
* foreign-key="FK_UTILISATEURROLE_UTILISATEUR"
* hibernate.key
* column="ROLE_FK"
......@@ -134,18 +132,18 @@ public class UserRole /* extends org.roliste.data.DbEntity */
* lazy="true"
* inverse="true"
*/
public Set<User> getUsers() {
return users;
public Set<Person> getPersons() {
return persons;
}
/**
* Sets the list of {@link User}s for this user role.
* @param users the new {@link Set} of {@link User}s. May be
* Sets the list of {@link Person}s for this user role.
* @param persons the new {@link Set} of {@link Person}s. May be
* <code>null</code> (we don't handle the relation from this side).
* @see #getUsers()
* @see #getPersons()
*/
protected void setUsers(Set<User> users) {
this.users = users;
protected void setPersons(Set<Person> persons) {
this.persons = persons;
}
/**
......
......@@ -4,7 +4,7 @@ import org.legrog.entities.PublisherVersion;
import org.legrog.web.xyz.SharedService;
import org.legrog.entities.Country;
import org.legrog.entities.Publisher;
import org.legrog.entities.User;
import org.legrog.entities.Person;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -47,7 +47,7 @@ public class PublisherVersionView implements Serializable {
private String publisherURL;
private boolean publisherActive;
private String publisherHistory;
private User publisherVersionAuthor;
private Person publisherVersionAuthor;
private Timestamp publisherVersionDatetime;
private Publisher publisher;
......@@ -313,11 +313,11 @@ public class PublisherVersionView implements Serializable {
this.publisherHistory = publisherHistory;
}
public User getPublisherVersionAuthor() {
public Person getPublisherVersionAuthor() {
return publisherVersionAuthor;
}
public void setPublisherVersionAuthor(User publisherVersionAuthor) {
public void setPublisherVersionAuthor(Person publisherVersionAuthor) {
this.publisherVersionAuthor = publisherVersionAuthor;
}
......
package org.legrog.web.user;
import org.legrog.entities.User;
import org.legrog.entities.Person;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
......@@ -14,19 +14,19 @@ public class ListUsersBean {
@Inject
private UserService userService;
private List<User> users;
private List<Person> persons;
public List<User> getUsers() {
return users;
public List<Person> getPersons() {
return persons;
}
public void setUsers(List<User> users) {
this.users = users;
public void setPersons(List<Person> persons) {
this.persons = persons;
}
@PostConstruct
public void init() {
users = userService.getAllUsers();
persons = userService.getAllUsers();
}
}
......
......@@ -65,35 +65,35 @@ public class UpdateUserBean {
public String add() {
User user = new User();
user.setActivated(activated);
user.setAnonymous(anonymous);
Person person = new Person();
person.setActivated(activated);
person.setAnonymous(anonymous);
if (userAttributes != null) {
user.setAttributes(userAttributes);
person.setAttributes(userAttributes);
}
user.setCriticProvider(criticProvider);
person.setCriticProvider(criticProvider);
if (displayNameMask != null) {
user.setDisplayNameMask(displayNameMask);
person.setDisplayNameMask(displayNameMask);
} else {
user.setDisplayNameMask(DisplayNameMask.PRENOMNOM);
person.setDisplayNameMask(DisplayNameMask.PRENOMNOM);
}
user.setEmail(email);
user.setFirstName(firstName);
user.setLastName(lastName);
person.setEmail(email);
person.setFirstName(firstName);
person.setLastName(lastName);
if (nickName != null && !nickName.isEmpty()) {
user.setNickName(nickName);
person.setNickName(nickName);
}
user.setPassword(password);
person.setPassword(password);
if (presentation != null) {
user.setPresentation(presentation);
person.setPresentation(presentation);
}
if (roles != null) {
user.setRoles(roles);
person.setRoles(roles);
}
user.setUsername(username);
user.setVisible(visible);
user.setCreationDate(new Date());
userService.addUser(user);
person.setUsername(username);
person.setVisible(visible);
person.setCreationDate(new Date());
userService.addUser(person);
return "success";
}
......@@ -103,25 +103,25 @@ public class UpdateUserBean {
logger.info("userId =" + userId);
this.userId = userId;
if (userId != 0) {
User user = userService.findUserById(userId);
if (user != null) {
activated = user.isActivated();
anonymous = user.isAnonymous();
userAttributes = user.getAttributes();
criticProvider = user.isCriticProvider();
displayNameMask = user.getDisplayNameMask();
email = user.getEmail();
firstName = user.getFirstName();
lastName = user.getLastName();
nickName = user.getNickName();
password = user.getPassword();
presentation = user.getPresentation();
roles = user.getRoles();
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();
if (roles == null) {
roles = new ArrayList<UserRole>();
}
username = user.getUsername();
visible = user.isVisible();
username = person.getUsername();
visible = person.isVisible();
return "updateUser.xhtml";
}
}
......@@ -132,22 +132,22 @@ public class UpdateUserBean {
logger.info("update");
logger.info("userId =" + userId);
User user = userService.findUserById(userId);
user.setActivated(activated);
user.setAnonymous(anonymous);
user.setAttributes(userAttributes);
user.setCriticProvider(criticProvider);
user.setDisplayNameMask(displayNameMask);
user.setEmail(email);
user.setFirstName(firstName);
user.setLastName(lastName);
user.setNickName(nickName);
user.setPassword(password);
user.setPresentation(presentation);
user.setRoles(roles);
user.setUsername(username);
user.setVisible(visible);
userService.updateUser(user);
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);
return "success";
}
......
package org.legrog.web.user;
import org.legrog.entities.User;
import org.legrog.entities.Person;
import java.util.List;
public interface UserService {
void addUser(User user);
void addUser(Person person);
List<User> getAllUsers();
List<Person> getAllUsers();
User findUserById(int id);
Person findUserById(int id);
void updateUser(User user);
void updateUser(Person person);
}
......
package org.legrog.web.user;
import org.legrog.entities.User;
import org.legrog.entities.UserRepository;
import org.legrog.entities.Person;
import org.legrog.entities.PersonRepository;
import javax.ejb.Stateless;
import javax.inject.Inject;
......@@ -10,21 +10,21 @@ import java.util.List;
@Stateless
public class UserServiceSpring implements UserService {
@Inject
UserRepository userRepository;
PersonRepository personRepository;
public void addUser(User user) {
userRepository.save(user);
public void addUser(Person person) {
personRepository.save(person);
}
public List<User> getAllUsers() {
return userRepository.findAll();
public List<Person> getAllUsers() {
return personRepository.findAll();
}
public User findUserById(int id) {
return userRepository.findOne(new Integer(id));
public Person findUserById(int id) {
return personRepository.findOne(new Integer(id));
}
public void updateUser(User user) {
userRepository.save(user);
public void updateUser(Person person) {
personRepository.save(person);
}
}
\ No newline at end of file
......
......@@ -32,17 +32,17 @@
<div id="listElements">
<h:commandLink styleClass="fRight acLink" action="add" rendered="#{not empty listUsersBean.users}" >
<h:commandLink styleClass="fRight acLink" action="add" rendered="#{not empty listUsersBean.persons}" >
<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.users}"
var="user" value="#{listUsersBean.users}"
<p:dataTable id="tableElements" rendered="#{not empty listUsersBean.persons}"
var="person" value="#{listUsersBean.persons}"
styleClass="results" rowClasses="altRichRow,altRow">
<!-- TODO Grer la pagination -->
<!-- <p:dataTable id="tableElements" rendered="#{listUsersBean.users.size>0}"
var="user" value="#{listUsersBean.users}" rows="#{userListMgr.pageSize}"
<!-- <p:dataTable id="tableElements" rendered="#{listUsersBean.persons.size>0}"
var="person" value="#{listUsersBean.persons}" 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(user.userId)}">
<h:commandLink action="#{updateUserBean.prepareUpdate(person.userId)}">
<img src="/images/structure/vide.gif" class="icEdit" alt="Modifier" title="Modifier" />
</h:commandLink>
</p:column>
<p:column styleClass="third" sortBy="#{user.username}">
<p:column styleClass="third" sortBy="#{person.username}">
<f:facet name="header">Identifiant</f:facet>
<!-- TODO Dcider de l'avenir de traceable -->
<ui:remove>
<!-- <h:outputLink value="#{user.traceable.urlRewrite}">-->
<!-- <h:outputLink value="#{person.traceable.urlRewrite}">-->
</ui:remove>
<h:outputText value="#{user.username}" />
<h:outputText value="#{person.username}" />
<!-- </h:outputLink>-->
</p:column>
<p:column styleClass="third" sortBy="#{user.firstName} #{user.lastName}">
<p:column styleClass="third" sortBy="#{person.firstName} #{person.lastName}">
<f:facet name="header">Nom</f:facet>
<ui:remove>
<!--<h:outputLink value="#{user.traceable.urlRewrite}">-->
<!--<h:outputLink value="#{person.traceable.urlRewrite}">-->
</ui:remove>
<h:outputText value="#{user.firstName} #{user.lastName}" />
<h:outputText value="#{person.firstName} #{person.lastName}" />
<!--</h:outputLink>-->
</p:column>
<p:column styleClass="third" sortBy="#{user.email}">
<p:column styleClass="third" sortBy="#{person.email}">
<f:facet name="header">Email</f:facet>
<h:outputText value="#{user.email}" />
<h:outputText value="#{person.email}" />
</p:column>
<p:column>
<h:graphicImage value="/images/structure/dVert.gif" rendered="#{user.visible and user.activated}" title="Utilisateur activ" />
<h:graphicImage value="/images/structure/dOrange.gif" rendered="#{(not user.visible) and user.activated}" title="Utilisateur dsactiv" />
<h:graphicImage value="/images/structure/dRouge.gif" rendered="#{not user.activated}" title="Utilisateur non enregistr" />
<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" />
</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.users}">
rendered="#{empty listUsersBean.persons}">
</h:commandLink>
</p>
</h:form>
......
......@@ -12,8 +12,8 @@
</h:commandLink>
</h:form>
<ul>
<ui:repeat value="#{listUsersBean.users}" var="user">
<li>#{user.username}</li>
<ui:repeat value="#{listUsersBean.persons}" var="person">
<li>#{person.username}</li>
</ui:repeat>
</ul>
</f:view>
......
......@@ -16,5 +16,5 @@ public interface SharedService {
List<UserProperty> getAvailableUserProperties();
User getCurrentUser();
Person getCurrentUser();
}
\ No newline at end of file
......
......@@ -52,12 +52,12 @@ public class SharedServiceSpring implements SharedService {
public List<UserProperty> getAvailableUserProperties() { return userPropertyRepository.findAll(); }
public User getCurrentUser() {
public Person getCurrentUser() {
// TODO Remplacer l'astuce par une vraie récupération de l'utilisateur
List<User> users = userService.getAllUsers();
List<Person> persons = userService.getAllUsers();
Random random = new Random();
User user = users.get(random.nextInt(users.size()));
Person person = persons.get(random.nextInt(persons.size()));
// End TODO
return user;
return person;
}
}
......
......@@ -65,7 +65,7 @@ public class PublisherVersionViewTest {
}
@Test
@DisplayName("depends on Shared Service and User Service")
@DisplayName("depends on Shared Service and Person Service")
public void testDependencies() {
assertThat(publisherVersionView).isNotNull();
}
......
......@@ -20,10 +20,10 @@ import static org.mockito.Mockito.when;
/**
* Created by jai on 15/11/16.
*/
@DisplayName("Update User Bean")
@DisplayName("Update Person Bean")
@ExtendWith(MockitoExtension.class)
@RunWith(JUnitPlatform.class)
public class UpdateUserBeanTest {
public class UpdatePersonBeanTest {
UpdateUserBean updateUserBean;
......@@ -33,7 +33,7 @@ public class UpdateUserBeanTest {
}
@Test
@DisplayName("depends on Shared Service and User Service")
@DisplayName("depends on Shared Service and Person Service")
public void testDependencies() {
assertThat(updateUserBean).isNotNull();
}
......