Commit des modifications du modele pour faire passer les tests
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<property name="hibernate.hbm2ddl.auto" value="update"/>
|
<property name="hibernate.hbm2ddl.auto" value="update"/>
|
||||||
<property name="hibernate.jdbc.batch_size" value="0"/>
|
<property name="hibernate.jdbc.batch_size" value="0"/>
|
||||||
|
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
</persistence>
|
</persistence>
|
||||||
@@ -71,11 +71,11 @@ public class Article implements Serializable {
|
|||||||
@OneToMany(targetEntity=Preference.class,mappedBy="article")
|
@OneToMany(targetEntity=Preference.class,mappedBy="article")
|
||||||
private Collection<Preference> preferences;
|
private Collection<Preference> preferences;
|
||||||
|
|
||||||
private int state;
|
public enum State {
|
||||||
|
|
||||||
public enum state {
|
|
||||||
SUMMARY, FINAL
|
SUMMARY, FINAL
|
||||||
};
|
};
|
||||||
|
private State state;
|
||||||
|
|
||||||
|
|
||||||
public Article() {
|
public Article() {
|
||||||
secondaryAuthors = new ArrayList<String>();
|
secondaryAuthors = new ArrayList<String>();
|
||||||
@@ -83,7 +83,7 @@ public class Article implements Serializable {
|
|||||||
|
|
||||||
public Article(String title, String topic,
|
public Article(String title, String topic,
|
||||||
String url_article, User mainAuthor,
|
String url_article, User mainAuthor,
|
||||||
List<String> secondaryAuthor, int state, Conference conference) {
|
List<String> secondaryAuthor, State state, Conference conference) {
|
||||||
//this.id = reference;
|
//this.id = reference;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.topic = topic;
|
this.topic = topic;
|
||||||
@@ -150,15 +150,15 @@ public class Article implements Serializable {
|
|||||||
return secondaryAuthors;
|
return secondaryAuthors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSecondaryAuthors(ArrayList<String> secondaryAuthors) {
|
public void setSecondaryAuthors(List<String> secondaryAuthors) {
|
||||||
this.secondaryAuthors = secondaryAuthors;
|
this.secondaryAuthors = new ArrayList<String>(secondaryAuthors);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getState() {
|
public State getState() {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setState(int state) {
|
public void setState(State state) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ import javax.persistence.NoResultException;
|
|||||||
import javax.persistence.PersistenceContext;
|
import javax.persistence.PersistenceContext;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
|
|
||||||
|
import org.yacos.core.article.Article.State;
|
||||||
import org.yacos.core.conferences.Conference;
|
import org.yacos.core.conferences.Conference;
|
||||||
|
import org.yacos.core.conferences.ConferenceDoesntExistException;
|
||||||
import org.yacos.core.users.User;
|
import org.yacos.core.users.User;
|
||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
@@ -21,15 +23,25 @@ public class ArticleManagerBean implements IArticleManager, Serializable {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
EntityManager em;
|
private EntityManager em;
|
||||||
|
|
||||||
public ArticleManagerBean() {
|
public ArticleManagerBean() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Article addArticle(String title, String topic,String url_article,
|
public Article addArticle(String title, String topic,String url_article,
|
||||||
User mainAuthor, List<String> secondaryAuthor, int state,Conference conference) {
|
String mainAuthorLogin, List<String> secondaryAuthors, State state,Integer conferenceId) {
|
||||||
Article a = new Article(title, topic, url_article, mainAuthor, secondaryAuthor, state, conference);
|
Article a = new Article();
|
||||||
|
a.setTitle(title);
|
||||||
|
a.setTopic(topic);
|
||||||
|
a.setURL_article(url_article);
|
||||||
|
User mainAuthor = em.find(User.class,mainAuthorLogin);
|
||||||
|
a.setMainAuthor(mainAuthor);
|
||||||
|
a.setSecondaryAuthors(secondaryAuthors);
|
||||||
|
a.setState(state);
|
||||||
|
Conference conference = em.find(Conference.class, conferenceId);
|
||||||
|
a.setConference(conference);
|
||||||
|
|
||||||
em.persist(a);
|
em.persist(a);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
@@ -39,8 +51,9 @@ public class ArticleManagerBean implements IArticleManager, Serializable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeArticle(Article a) {
|
public void removeArticle(Integer articleId) {
|
||||||
em.remove(a);
|
Article article = this.getArticle(articleId);
|
||||||
|
em.remove(article);
|
||||||
em.flush();
|
em.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +62,11 @@ public class ArticleManagerBean implements IArticleManager, Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public List<Article> getArticles(Conference conf) {
|
public List<Article> getArticles(Integer confId) throws ConferenceDoesntExistException {
|
||||||
|
Conference conf = em.find(Conference.class, confId);
|
||||||
|
if(conf == null){
|
||||||
|
throw new ConferenceDoesntExistException();
|
||||||
|
}
|
||||||
Query query = em.createQuery("from Article a WHERE conference = ? ORDER BY a.title");
|
Query query = em.createQuery("from Article a WHERE conference = ? ORDER BY a.title");
|
||||||
query.setParameter(1, conf);
|
query.setParameter(1, conf);
|
||||||
return query.getResultList();
|
return query.getResultList();
|
||||||
@@ -139,8 +156,8 @@ public class ArticleManagerBean implements IArticleManager, Serializable {
|
|||||||
em.merge(preference);
|
em.merge(preference);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean existsArticle(Article article) {
|
public boolean existsArticle(Integer articleId) {
|
||||||
return em.find(Article.class, article.getId())!=null;
|
return em.find(Article.class, articleId)!=null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean existsPreference(Preference preference) {
|
public boolean existsPreference(Preference preference) {
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.ejb.Remote;
|
import javax.ejb.Remote;
|
||||||
|
|
||||||
|
import org.yacos.core.article.Article.State;
|
||||||
import org.yacos.core.conferences.Conference;
|
import org.yacos.core.conferences.Conference;
|
||||||
|
import org.yacos.core.conferences.ConferenceDoesntExistException;
|
||||||
import org.yacos.core.users.User;
|
import org.yacos.core.users.User;
|
||||||
|
|
||||||
|
|
||||||
@@ -12,8 +14,8 @@ import org.yacos.core.users.User;
|
|||||||
public interface IArticleManager {
|
public interface IArticleManager {
|
||||||
public Article getArticle(Integer id);
|
public Article getArticle(Integer id);
|
||||||
public Article addArticle(String title, String topic,String url_article,
|
public Article addArticle(String title, String topic,String url_article,
|
||||||
User mainAuthor, List<String> secondaryAuthor, int state,Conference conference);
|
String mainauthor, List<String> secondaryAuthor, State state,Integer integer);
|
||||||
public void removeArticle(Article a);
|
public void removeArticle(Integer articleId);
|
||||||
public void updateArticle(Article article);
|
public void updateArticle(Article article);
|
||||||
|
|
||||||
|
|
||||||
@@ -21,7 +23,7 @@ public interface IArticleManager {
|
|||||||
//liste d'articles
|
//liste d'articles
|
||||||
|
|
||||||
//public List<Article> getArticles();
|
//public List<Article> getArticles();
|
||||||
public List<Article> getArticles(Conference conf);
|
public List<Article> getArticles(Integer confId) throws ConferenceDoesntExistException;
|
||||||
public List<Article> getArticleOfAuthor(Conference conf, User Author);
|
public List<Article> getArticleOfAuthor(Conference conf, User Author);
|
||||||
public List<Article> getArticlesOfMember(Conference conf, User member);
|
public List<Article> getArticlesOfMember(Conference conf, User member);
|
||||||
|
|
||||||
@@ -36,7 +38,7 @@ public interface IArticleManager {
|
|||||||
public void addOrUpdatePreference(Integer article_id, String userLogin, String preferenceValue);
|
public void addOrUpdatePreference(Integer article_id, String userLogin, String preferenceValue);
|
||||||
|
|
||||||
//FIXME interet ?
|
//FIXME interet ?
|
||||||
public boolean existsArticle(Article article);
|
public boolean existsArticle(Integer articleId);
|
||||||
public boolean existsPreference(Preference preference);
|
public boolean existsPreference(Preference preference);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package org.yacos.core.conferences;
|
||||||
|
|
||||||
|
public class ConferenceDoesntExistException extends Exception {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -28,8 +28,8 @@ public class ConferenceManagerBean implements IConferenceManager {
|
|||||||
return em.find(Conference.class, id);
|
return em.find(Conference.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Conference conf) {
|
public void remove(Integer conferenceId) {
|
||||||
Conference persistedConf = em.find(Conference.class, conf.getId());
|
Conference persistedConf = em.find(Conference.class, conferenceId);
|
||||||
em.remove(persistedConf);
|
em.remove(persistedConf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,9 @@ public class ConferenceManagerBean implements IConferenceManager {
|
|||||||
* m<>thodes relatives aux roles
|
* m<>thodes relatives aux roles
|
||||||
* */
|
* */
|
||||||
|
|
||||||
public void addRole(Role.RoleType roleType, User user, Conference conf) {
|
public void addRole(Role.RoleType roleType, String login, Integer confId) {
|
||||||
|
User user = em.find(User.class, login);
|
||||||
|
Conference conf = em.find(Conference.class, confId);
|
||||||
Role role = new Role(roleType, user, conf);
|
Role role = new Role(roleType, user, conf);
|
||||||
em.persist(role);
|
em.persist(role);
|
||||||
}
|
}
|
||||||
@@ -96,8 +98,8 @@ public class ConferenceManagerBean implements IConferenceManager {
|
|||||||
return query.getResultList();
|
return query.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean exists(Integer conferenceId) {
|
||||||
|
return (this.getConference(conferenceId)!=null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public interface IConferenceManager {
|
|||||||
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);
|
||||||
|
|
||||||
public void remove(Conference conf);
|
public void remove(Integer conferenceId);
|
||||||
public void update(Conference conf);
|
public void update(Conference conf);
|
||||||
|
|
||||||
//article methodes
|
//article methodes
|
||||||
@@ -30,9 +30,10 @@ public interface IConferenceManager {
|
|||||||
|
|
||||||
|
|
||||||
//role et user methode
|
//role et user methode
|
||||||
public void addRole(Role.RoleType roleType, User user, Conference conf);
|
public void 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(User user, Conference conf);
|
public List<Role> getRoles(User user, Conference conf);
|
||||||
public void updateRole(Role role);
|
public void updateRole(Role role);
|
||||||
|
public boolean exists(Integer conferenceId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,19 @@ 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.users.Role.RoleType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author christiancorsano
|
||||||
|
*
|
||||||
|
*/
|
||||||
@Remote
|
@Remote
|
||||||
public interface IUserManager {
|
public interface IUserManager {
|
||||||
|
|
||||||
//crud methode
|
//crud methode
|
||||||
|
|
||||||
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(User user);
|
public void removeUser(String login);
|
||||||
public User getUser(String login);
|
public User getUser(String login);
|
||||||
public void UpdateUser(User user);
|
public void UpdateUser(User user);
|
||||||
public Boolean exists(String login);
|
public Boolean exists(String login);
|
||||||
@@ -23,6 +27,18 @@ public interface IUserManager {
|
|||||||
public List<User> getUsers();
|
public List<User> getUsers();
|
||||||
public List<User> getUsers(Conference conf);
|
public List<User> getUsers(Conference conf);
|
||||||
public List<User> getUsers(Role.RoleType type);
|
public List<User> getUsers(Role.RoleType type);
|
||||||
|
/**
|
||||||
|
* Create and adds a role to a user
|
||||||
|
* @param login The login of the user
|
||||||
|
* @param role The role to grant to the user
|
||||||
|
* @param conferenceId The id of the conference for which the Role is to be granted
|
||||||
|
*/
|
||||||
|
public void addRoleForConference(String login, RoleType role, Integer conferenceId);
|
||||||
|
/**
|
||||||
|
* Remove a role from a user
|
||||||
|
* @param login The login of the user
|
||||||
|
* @param role The role to remove from the user
|
||||||
|
* @param conferenceId The id of the conference for which the Role is to be removed
|
||||||
|
*/
|
||||||
|
public void removeRole(String userLogin, RoleType roleType, int conferenceId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.yacos.core.users;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.EnumType;
|
import javax.persistence.EnumType;
|
||||||
import javax.persistence.Enumerated;
|
import javax.persistence.Enumerated;
|
||||||
@@ -28,19 +29,29 @@ public class Role implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dummy field to make the composite PK work despite the ManyToOne relationship
|
||||||
|
*/
|
||||||
|
@Id
|
||||||
|
@Column(name="user_id",insertable=false,updatable=false)
|
||||||
|
private String user_id;
|
||||||
/**
|
/**
|
||||||
* User for which this role is defined
|
* User for which this role is defined
|
||||||
* Primary Key
|
* Primary Key
|
||||||
*/
|
*/
|
||||||
@Id
|
|
||||||
@ManyToOne(targetEntity=User.class,optional=false)
|
@ManyToOne(targetEntity=User.class,optional=false)
|
||||||
@JoinColumn(name="user_id",nullable=false)
|
@JoinColumn(name="user_id",nullable=false)
|
||||||
private User user;
|
private User user;
|
||||||
|
/**
|
||||||
|
* Dummy field to make the composite PK work despite the ManyToOne relationship
|
||||||
|
*/
|
||||||
|
@Id
|
||||||
|
@Column(name="conference_id",insertable=false,updatable=false)
|
||||||
|
private Integer conference_id;
|
||||||
/**
|
/**
|
||||||
* Conference for which this role is defined
|
* Conference for which this role is defined
|
||||||
* Primary Key
|
* Primary Key
|
||||||
*/
|
*/
|
||||||
@Id
|
|
||||||
@ManyToOne(targetEntity=Conference.class,optional=false)
|
@ManyToOne(targetEntity=Conference.class,optional=false)
|
||||||
@JoinColumn(name="conference_id",nullable=false)
|
@JoinColumn(name="conference_id",nullable=false)
|
||||||
private Conference conference;
|
private Conference conference;
|
||||||
@@ -66,35 +77,45 @@ public class Role implements Serializable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ManyToOne(targetEntity=User.class,optional=false)
|
||||||
|
@JoinColumn(name="user_id",nullable=false)
|
||||||
public User getUser() {
|
public User getUser() {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ManyToOne(targetEntity=User.class,optional=false)
|
||||||
|
@JoinColumn(name="user_id",nullable=false)
|
||||||
public void setUser(User user) {
|
public void setUser(User user) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
this.user_id = user.getLogin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ManyToOne(targetEntity=Conference.class,optional=false)
|
||||||
|
@JoinColumn(name="conference_id",nullable=false)
|
||||||
public Conference getConference() {
|
public Conference getConference() {
|
||||||
return conference;
|
return conference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ManyToOne(targetEntity=Conference.class,optional=false)
|
||||||
|
@JoinColumn(name="conference_id",nullable=false)
|
||||||
public void setConference(Conference conference) {
|
public void setConference(Conference conference) {
|
||||||
this.conference = conference;
|
this.conference = conference;
|
||||||
|
this.conference_id = conference.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the type of this role
|
* @return the type of this role
|
||||||
*/
|
*/
|
||||||
|
@Enumerated(EnumType.ORDINAL)
|
||||||
public RoleType getType() {
|
public RoleType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param type the type of this role
|
* @param type the type of this role
|
||||||
*/
|
*/
|
||||||
|
@Enumerated(EnumType.ORDINAL)
|
||||||
public void setType(RoleType type) {
|
public void setType(RoleType type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
package org.yacos.core.users;
|
package org.yacos.core.users;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
|
|
||||||
import org.yacos.core.conferences.Conference;
|
import org.yacos.core.conferences.Conference;
|
||||||
import org.yacos.core.users.Role.RoleType;
|
import org.yacos.core.users.Role.RoleType;
|
||||||
|
|
||||||
@@ -16,24 +11,28 @@ public class RolePK implements Serializable{
|
|||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html
|
||||||
|
*/
|
||||||
|
public String user_id;
|
||||||
|
/**
|
||||||
|
* Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html
|
||||||
|
*/
|
||||||
|
public Integer conference_id;
|
||||||
/**
|
/**
|
||||||
* Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html
|
* Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html
|
||||||
*/
|
*/
|
||||||
public RoleType type;
|
public RoleType type;
|
||||||
/**
|
|
||||||
* Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html
|
public RolePK() {
|
||||||
*/
|
}
|
||||||
@Id
|
|
||||||
@ManyToOne(targetEntity=User.class,optional=false)
|
public RolePK(User user, RoleType type, Conference conference) {
|
||||||
@JoinColumn(name="user_id",nullable=false)
|
super();
|
||||||
public User user;
|
this.user_id = user.getLogin();
|
||||||
/**
|
this.type = type;
|
||||||
* Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html
|
this.conference_id = conference.getId();
|
||||||
*/
|
}
|
||||||
@Id
|
|
||||||
@ManyToOne(targetEntity=Conference.class,optional=false)
|
|
||||||
@JoinColumn(name="conference_id",nullable=false)
|
|
||||||
public Conference conference;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
@@ -42,13 +41,13 @@ public class RolePK implements Serializable{
|
|||||||
}
|
}
|
||||||
RolePK otherPK = (RolePK) obj;
|
RolePK otherPK = (RolePK) obj;
|
||||||
return type.equals(otherPK.type)&&
|
return type.equals(otherPK.type)&&
|
||||||
user.getLogin().equals(otherPK.user.getLogin())&&
|
user_id.equals(otherPK.user_id)&&
|
||||||
conference.getId() == otherPK.conference.getId();
|
conference_id == otherPK.conference_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return type.hashCode() ^ user.hashCode() ^ conference.hashCode();
|
return type.hashCode() ^ user_id.hashCode() ^ conference_id.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ 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.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.FetchType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
|
|
||||||
@@ -57,7 +59,7 @@ public class User implements Serializable{
|
|||||||
/**
|
/**
|
||||||
* Roles for this user
|
* Roles for this user
|
||||||
*/
|
*/
|
||||||
@OneToMany(targetEntity=Role.class,mappedBy="user")
|
@OneToMany(targetEntity=Role.class,mappedBy="user",fetch=FetchType.EAGER,cascade=CascadeType.ALL)
|
||||||
private List<Role> roles;
|
private List<Role> roles;
|
||||||
|
|
||||||
@OneToMany(targetEntity=Article.class,mappedBy="mainAuthor")
|
@OneToMany(targetEntity=Article.class,mappedBy="mainAuthor")
|
||||||
@@ -137,7 +139,7 @@ public class User implements Serializable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@OneToMany(targetEntity=Role.class,mappedBy="user")
|
@OneToMany(targetEntity=Role.class,mappedBy="user",fetch=FetchType.EAGER)
|
||||||
public List<Role> getRoles(){
|
public List<Role> getRoles(){
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
@@ -160,7 +162,7 @@ public class User implements Serializable{
|
|||||||
/**
|
/**
|
||||||
* @param roles the roles to set
|
* @param roles the roles to set
|
||||||
*/
|
*/
|
||||||
@OneToMany(targetEntity=Role.class,mappedBy="user")
|
@OneToMany(targetEntity=Role.class,mappedBy="user",fetch=FetchType.EAGER)
|
||||||
public void setRoles(List<Role> roles) {
|
public void setRoles(List<Role> roles) {
|
||||||
this.roles = roles;
|
this.roles = roles;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ public class UserManagerBean implements IUserManager{
|
|||||||
* Removes a user from the system
|
* Removes a user from the system
|
||||||
* @param user
|
* @param user
|
||||||
*/
|
*/
|
||||||
public void removeUser(User user){
|
public void removeUser(String login){
|
||||||
User persistedUser = em.find(User.class, user.getLogin());
|
User persistedUser = em.find(User.class, login);
|
||||||
em.remove(persistedUser);
|
em.remove(persistedUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,4 +83,25 @@ public class UserManagerBean implements IUserManager{
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addRoleForConference(String login, RoleType role, Integer conferenceId) {
|
||||||
|
User user = em.find(User.class, login);
|
||||||
|
Conference conference = em.find(Conference.class, conferenceId);
|
||||||
|
//if(user.hasRoleForConference(role, conference)){
|
||||||
|
// return;
|
||||||
|
//}
|
||||||
|
|
||||||
|
Role newRole = new Role();
|
||||||
|
newRole.setUser(user);
|
||||||
|
newRole.setConference(conference);
|
||||||
|
newRole.setType(role);
|
||||||
|
em.persist(newRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeRole(String userLogin, RoleType roleType, int conferenceId) {
|
||||||
|
User user = em.find(User.class, userLogin);
|
||||||
|
Conference conference = em.find(Conference.class, conferenceId);
|
||||||
|
Role role = em.find(Role.class, new RolePK(user,roleType,conference));
|
||||||
|
em.remove(role);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user