Core : Ajout du systeme d'invitation.
Creation de l'entite InvitationToken et implementation des methodes d'acces dans les Managers. Prise en compte des invitations lors de l'ajout d'utilisateur
This commit is contained in:
@@ -66,7 +66,7 @@ public class ArticleManagerBean implements IArticleManager, Serializable {
|
|||||||
public List<Article> getArticles(Integer confId) throws ConferenceDoesntExistException {
|
public List<Article> getArticles(Integer confId) throws ConferenceDoesntExistException {
|
||||||
Conference conf = em.find(Conference.class, confId);
|
Conference conf = em.find(Conference.class, confId);
|
||||||
if(conf == null){
|
if(conf == null){
|
||||||
throw new ConferenceDoesntExistException();
|
throw new ConferenceDoesntExistException(confId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Query query = em.createQuery("from Article a WHERE a.conference = ? ORDER BY a.title");
|
Query query = em.createQuery("from Article a WHERE a.conference = ? ORDER BY a.title");
|
||||||
|
|||||||
@@ -9,8 +9,12 @@ import javax.persistence.EntityManager;
|
|||||||
import javax.persistence.PersistenceContext;
|
import javax.persistence.PersistenceContext;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
|
|
||||||
|
import org.yacos.core.exceptions.ConferenceDoesntExistException;
|
||||||
|
import org.yacos.core.system.InvitationToken;
|
||||||
|
import org.yacos.core.system.InvitationTokenPK;
|
||||||
import org.yacos.core.users.Role;
|
import org.yacos.core.users.Role;
|
||||||
import org.yacos.core.users.User;
|
import org.yacos.core.users.User;
|
||||||
|
import org.yacos.core.users.Role.RoleType;
|
||||||
|
|
||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
@@ -111,4 +115,53 @@ public class ConferenceManagerBean implements IConferenceManager {
|
|||||||
return (this.getConference(conferenceId)!=null);
|
return (this.getConference(conferenceId)!=null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================================================ */
|
||||||
|
/* = Invitation management methods implementation = */
|
||||||
|
/* ================================================ */
|
||||||
|
|
||||||
|
public InvitationToken addInvitationToken(String email, RoleType role,
|
||||||
|
Integer conferenceId) throws ConferenceDoesntExistException {
|
||||||
|
Conference conf = getConference(conferenceId);
|
||||||
|
|
||||||
|
if(conf == null){
|
||||||
|
throw new ConferenceDoesntExistException(conferenceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
InvitationTokenPK tokenPK = new InvitationTokenPK();
|
||||||
|
tokenPK.email = email;
|
||||||
|
tokenPK.role = role;
|
||||||
|
tokenPK.conference = conf;
|
||||||
|
|
||||||
|
InvitationToken newToken = em.find(InvitationToken.class, tokenPK);
|
||||||
|
|
||||||
|
if(newToken == null){
|
||||||
|
newToken = new InvitationToken();
|
||||||
|
newToken.setEmail(email);
|
||||||
|
newToken.setRole(role);
|
||||||
|
newToken.setConference(conf);
|
||||||
|
|
||||||
|
em.persist(newToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeInvitationToken(InvitationToken token) {
|
||||||
|
token = em.find(InvitationToken.class, token.getId());
|
||||||
|
em.remove(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InvitationToken getInvitationToken(InvitationTokenPK tokenId) {
|
||||||
|
return em.find(InvitationToken.class, tokenId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public List<InvitationToken> getInvitationTokensForConference(Integer conferenceId) {
|
||||||
|
Conference conf = em.find(Conference.class, conferenceId);
|
||||||
|
Query query = em.createQuery("from InvitationToken where conference=?");
|
||||||
|
query.setParameter(1, conf);
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,17 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.ejb.Remote;
|
import javax.ejb.Remote;
|
||||||
|
|
||||||
|
import org.yacos.core.exceptions.ConferenceDoesntExistException;
|
||||||
|
import org.yacos.core.system.InvitationToken;
|
||||||
|
import org.yacos.core.system.InvitationTokenPK;
|
||||||
import org.yacos.core.users.Role;
|
import org.yacos.core.users.Role;
|
||||||
import org.yacos.core.users.User;
|
import org.yacos.core.users.User;
|
||||||
|
import org.yacos.core.users.Role.RoleType;
|
||||||
|
|
||||||
@Remote
|
@Remote
|
||||||
public interface IConferenceManager {
|
public interface IConferenceManager {
|
||||||
|
|
||||||
//CRUD methodes
|
// CRUD methods
|
||||||
public Conference addConference(String titre, String descirption, String infoComplementray, Date dataAbstract, Date dateArticle, Date dateEvaluation, Date dateStart, Date dateEnd);
|
public Conference addConference(String titre, String descirption, String infoComplementray, Date dataAbstract, Date dateArticle, Date dateEvaluation, Date dateStart, Date dateEnd);
|
||||||
public Conference getConference(Integer id);
|
public Conference getConference(Integer id);
|
||||||
|
|
||||||
@@ -24,16 +28,22 @@ public interface IConferenceManager {
|
|||||||
//public void addArticle(User user);
|
//public void addArticle(User user);
|
||||||
//public Collection<Article> getArticles(Integer id);
|
//public Collection<Article> getArticles(Integer id);
|
||||||
|
|
||||||
//list methodes
|
// Listing methods
|
||||||
public List<Conference> getConferences();
|
public List<Conference> getConferences();
|
||||||
public List<Conference> getConferences(User user);
|
public List<Conference> getConferences(User user);
|
||||||
|
|
||||||
|
|
||||||
//role et user methode
|
// Role and User management methods
|
||||||
public Role addRole(Role.RoleType roleType, String login, Integer confId);
|
public Role addRole(Role.RoleType roleType, String login, Integer confId);
|
||||||
public void removeRole(Role role);
|
public void removeRole(Role role);
|
||||||
public List<Role> getRoles(Conference conf);
|
public List<Role> getRoles(Conference conf);
|
||||||
public List<Role> getRoles(String userLogin, Integer confId);
|
public List<Role> getRoles(String userLogin, Integer confId);
|
||||||
public void updateRole(Role role);
|
public void updateRole(Role role);
|
||||||
public boolean exists(Integer conferenceId);
|
public boolean exists(Integer conferenceId);
|
||||||
|
|
||||||
|
// Invitation management methods
|
||||||
|
public InvitationToken getInvitationToken(InvitationTokenPK tokenId);
|
||||||
|
public List<InvitationToken> getInvitationTokensForConference(Integer conferenceId);
|
||||||
|
public InvitationToken addInvitationToken(String email, RoleType role, Integer conferenceId) throws ConferenceDoesntExistException;
|
||||||
|
public void removeInvitationToken(InvitationToken tokenId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,21 @@
|
|||||||
package org.yacos.core.exceptions;
|
package org.yacos.core.exceptions;
|
||||||
|
|
||||||
public class ConferenceDoesntExistException extends Exception {
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class ConferenceDoesntExistException extends Exception implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
private Integer conferenceId;
|
||||||
|
|
||||||
|
public ConferenceDoesntExistException(Integer conferenceId) {
|
||||||
|
this.conferenceId = conferenceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getConferenceId() {
|
||||||
|
return conferenceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConferenceId(Integer conferenceId) {
|
||||||
|
this.conferenceId = conferenceId;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.yacos.core.system;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EnumType;
|
||||||
|
import javax.persistence.Enumerated;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.IdClass;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
|
import org.yacos.core.conferences.Conference;
|
||||||
|
import org.yacos.core.users.Role.RoleType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Token for an invitation.
|
||||||
|
* Gives the ability for a user to gain role for a conference at registration time.
|
||||||
|
* Allow a chairman or a PC member to gives a PC Member or Referee role to a person not yet registered.
|
||||||
|
* @author christiancorsano
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@IdClass(InvitationTokenPK.class)
|
||||||
|
public class InvitationToken implements Serializable {
|
||||||
|
private static final long serialVersionUID = -7383377207105284233L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Enumerated(EnumType.ORDINAL)
|
||||||
|
private RoleType role;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@ManyToOne(targetEntity=Conference.class,optional=false)
|
||||||
|
@JoinColumn(name="conference_id",nullable=false)
|
||||||
|
private Conference conference;
|
||||||
|
|
||||||
|
|
||||||
|
public String getEmail(){
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email){
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Enumerated(EnumType.ORDINAL)
|
||||||
|
public RoleType getRole(){
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Enumerated(EnumType.ORDINAL)
|
||||||
|
public void setRole(RoleType role){
|
||||||
|
this.role = role;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ManyToOne(targetEntity=Conference.class,optional=false)
|
||||||
|
@JoinColumn(name="conference_id",nullable=false)
|
||||||
|
public Conference getConference(){
|
||||||
|
return conference;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ManyToOne(targetEntity=Conference.class,optional=false)
|
||||||
|
@JoinColumn(name="conference_id",nullable=false)
|
||||||
|
public void setConference(Conference conf){
|
||||||
|
this.conference = conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InvitationTokenPK getId(){
|
||||||
|
return new InvitationTokenPK(email,role,conference);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package org.yacos.core.system;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
|
import org.yacos.core.conferences.Conference;
|
||||||
|
import org.yacos.core.users.Role.RoleType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Primary key class for the {@link InvitationToken} entity
|
||||||
|
* @author christiancorsano
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class InvitationTokenPK implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PK attribute : email
|
||||||
|
*/
|
||||||
|
public String email;
|
||||||
|
/**
|
||||||
|
* PK attribute : role
|
||||||
|
*/
|
||||||
|
public RoleType role;
|
||||||
|
/**
|
||||||
|
* PK attribute : conference
|
||||||
|
*/
|
||||||
|
@ManyToOne(targetEntity=Conference.class,optional=false)
|
||||||
|
@JoinColumn(name="conference_id",nullable=false)
|
||||||
|
public Conference conference;
|
||||||
|
|
||||||
|
public InvitationTokenPK(String email2, RoleType role2,
|
||||||
|
Conference conference2) {
|
||||||
|
this.email = email2;
|
||||||
|
this.role = role2;
|
||||||
|
this.conference = conference2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InvitationTokenPK() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if(obj instanceof InvitationTokenPK){
|
||||||
|
InvitationTokenPK objPK = (InvitationTokenPK) obj;
|
||||||
|
return this.email.equals(objPK.email)
|
||||||
|
&& this.role.equals(objPK.role)
|
||||||
|
&& this.conference.getId().equals(objPK.conference.getId());
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return this.email.hashCode() ^ this.role.hashCode() ^ conference.getId().hashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@ import javax.ejb.Remote;
|
|||||||
|
|
||||||
import org.yacos.core.conferences.Conference;
|
import org.yacos.core.conferences.Conference;
|
||||||
import org.yacos.core.exceptions.PKAlreadyUsedException;
|
import org.yacos.core.exceptions.PKAlreadyUsedException;
|
||||||
|
import org.yacos.core.system.InvitationToken;
|
||||||
|
import org.yacos.core.system.InvitationTokenPK;
|
||||||
import org.yacos.core.users.Role.RoleType;
|
import org.yacos.core.users.Role.RoleType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,7 +17,7 @@ import org.yacos.core.users.Role.RoleType;
|
|||||||
@Remote
|
@Remote
|
||||||
public interface IUserManager {
|
public interface IUserManager {
|
||||||
|
|
||||||
//crud methode
|
// crud methods
|
||||||
public User addUser(String login, String password, String firstName,
|
public User addUser(String login, String password, String firstName,
|
||||||
String lastName, String organization, String email) throws PKAlreadyUsedException;
|
String lastName, String organization, String email) throws PKAlreadyUsedException;
|
||||||
public void removeUser(String login);
|
public void removeUser(String login);
|
||||||
@@ -23,7 +25,7 @@ public interface IUserManager {
|
|||||||
public void UpdateUser(User user);
|
public void UpdateUser(User user);
|
||||||
public Boolean exists(String login);
|
public Boolean exists(String login);
|
||||||
|
|
||||||
// methodes lister
|
// Lists methods
|
||||||
public List<User> getUsers();
|
public List<User> getUsers();
|
||||||
public List<User> getUsers(Conference conf);
|
public List<User> getUsers(Conference conf);
|
||||||
public List<User> getUsers(int conf_id,Role.RoleType type);
|
public List<User> getUsers(int conf_id,Role.RoleType type);
|
||||||
@@ -41,4 +43,9 @@ public interface IUserManager {
|
|||||||
* @param conferenceId The id of the conference for which the Role is to be removed
|
* @param conferenceId The id of the conference for which the Role is to be removed
|
||||||
*/
|
*/
|
||||||
public void removeRole(String userLogin, RoleType roleType, int conferenceId);
|
public void removeRole(String userLogin, RoleType roleType, int conferenceId);
|
||||||
|
public boolean hasRoleForConference(String userLogin, RoleType roleType, Integer conferenceId);
|
||||||
|
|
||||||
|
// InvitationToken handling methods
|
||||||
|
public List<InvitationToken> getInvitationTokensForEmail(String email);
|
||||||
|
public void useInvitationTokenOnUser(String userLogin, InvitationTokenPK tokenId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,11 @@ package org.yacos.core.users;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
|
|
||||||
import org.yacos.core.article.Article;
|
import org.yacos.core.article.Article;
|
||||||
import org.yacos.core.conferences.Conference;
|
import org.yacos.core.conferences.Conference;
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import javax.persistence.Query;
|
|||||||
|
|
||||||
import org.yacos.core.conferences.Conference;
|
import org.yacos.core.conferences.Conference;
|
||||||
import org.yacos.core.exceptions.PKAlreadyUsedException;
|
import org.yacos.core.exceptions.PKAlreadyUsedException;
|
||||||
|
import org.yacos.core.system.InvitationToken;
|
||||||
|
import org.yacos.core.system.InvitationTokenPK;
|
||||||
import org.yacos.core.users.Role.RoleType;
|
import org.yacos.core.users.Role.RoleType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,6 +44,13 @@ public class UserManagerBean implements IUserManager{
|
|||||||
User user = new User(login, password, firstName, lastName, organization, email);
|
User user = new User(login, password, firstName, lastName, organization, email);
|
||||||
em.persist(user);
|
em.persist(user);
|
||||||
em.flush();
|
em.flush();
|
||||||
|
|
||||||
|
// Existing InvitationToken handling
|
||||||
|
List<InvitationToken> tokens = getInvitationTokensForEmail(user.getEmail());
|
||||||
|
for(InvitationToken token : tokens){
|
||||||
|
useInvitationTokenOnUser(login, token.getId());
|
||||||
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
else{ throw new PKAlreadyUsedException(); }
|
else{ throw new PKAlreadyUsedException(); }
|
||||||
@@ -108,4 +117,27 @@ public class UserManagerBean implements IUserManager{
|
|||||||
em.remove(role);
|
em.remove(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public List<InvitationToken> getInvitationTokensForEmail(String email) {
|
||||||
|
Query query = em.createQuery("from InvitationToken where email=?");
|
||||||
|
query.setParameter(1, email);
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void useInvitationTokenOnUser(String userLogin,
|
||||||
|
InvitationTokenPK tokenId) {
|
||||||
|
InvitationToken token = em.find(InvitationToken.class,tokenId);
|
||||||
|
addRoleForConference(userLogin, token.getRole(), token.getConference().getId());
|
||||||
|
em.remove(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasRoleForConference(String userLogin, RoleType roleType,
|
||||||
|
Integer conferenceId) {
|
||||||
|
User user = getUser(userLogin);
|
||||||
|
Conference conf = em.find(Conference.class, conferenceId);
|
||||||
|
RolePK pk = new RolePK(user,roleType,conf);
|
||||||
|
Role role = em.find(Role.class, pk);
|
||||||
|
return role != null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user