Commit des modifications du modele pour faire passer les tests

This commit is contained in:
2008-01-21 16:52:03 +00:00
parent 0efcb90988
commit 3beb363650
12 changed files with 154 additions and 67 deletions

View File

@@ -4,6 +4,7 @@
<properties>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.jdbc.batch_size" value="0"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
</properties>
</persistence-unit>
</persistence>

View File

@@ -71,11 +71,11 @@ public class Article implements Serializable {
@OneToMany(targetEntity=Preference.class,mappedBy="article")
private Collection<Preference> preferences;
private int state;
public enum state {
public enum State {
SUMMARY, FINAL
};
private State state;
public Article() {
secondaryAuthors = new ArrayList<String>();
@@ -83,7 +83,7 @@ public class Article implements Serializable {
public Article(String title, String topic,
String url_article, User mainAuthor,
List<String> secondaryAuthor, int state, Conference conference) {
List<String> secondaryAuthor, State state, Conference conference) {
//this.id = reference;
this.title = title;
this.topic = topic;
@@ -150,15 +150,15 @@ public class Article implements Serializable {
return secondaryAuthors;
}
public void setSecondaryAuthors(ArrayList<String> secondaryAuthors) {
this.secondaryAuthors = secondaryAuthors;
public void setSecondaryAuthors(List<String> secondaryAuthors) {
this.secondaryAuthors = new ArrayList<String>(secondaryAuthors);
}
public int getState() {
public State getState() {
return state;
}
public void setState(int state) {
public void setState(State state) {
this.state = state;
}

View File

@@ -9,7 +9,9 @@ import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.yacos.core.article.Article.State;
import org.yacos.core.conferences.Conference;
import org.yacos.core.conferences.ConferenceDoesntExistException;
import org.yacos.core.users.User;
@Stateless
@@ -21,15 +23,25 @@ public class ArticleManagerBean implements IArticleManager, Serializable {
private static final long serialVersionUID = 1L;
@PersistenceContext
EntityManager em;
private EntityManager em;
public ArticleManagerBean() {
}
public Article addArticle(String title, String topic,String url_article,
User mainAuthor, List<String> secondaryAuthor, int state,Conference conference) {
Article a = new Article(title, topic, url_article, mainAuthor, secondaryAuthor, state, conference);
String mainAuthorLogin, List<String> secondaryAuthors, State state,Integer conferenceId) {
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);
return a;
}
@@ -39,8 +51,9 @@ public class ArticleManagerBean implements IArticleManager, Serializable {
}
public void removeArticle(Article a) {
em.remove(a);
public void removeArticle(Integer articleId) {
Article article = this.getArticle(articleId);
em.remove(article);
em.flush();
}
@@ -49,7 +62,11 @@ public class ArticleManagerBean implements IArticleManager, Serializable {
}
@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.setParameter(1, conf);
return query.getResultList();
@@ -139,8 +156,8 @@ public class ArticleManagerBean implements IArticleManager, Serializable {
em.merge(preference);
}
public boolean existsArticle(Article article) {
return em.find(Article.class, article.getId())!=null;
public boolean existsArticle(Integer articleId) {
return em.find(Article.class, articleId)!=null;
}
public boolean existsPreference(Preference preference) {

View File

@@ -4,7 +4,9 @@ import java.util.List;
import javax.ejb.Remote;
import org.yacos.core.article.Article.State;
import org.yacos.core.conferences.Conference;
import org.yacos.core.conferences.ConferenceDoesntExistException;
import org.yacos.core.users.User;
@@ -12,8 +14,8 @@ import org.yacos.core.users.User;
public interface IArticleManager {
public Article getArticle(Integer id);
public Article addArticle(String title, String topic,String url_article,
User mainAuthor, List<String> secondaryAuthor, int state,Conference conference);
public void removeArticle(Article a);
String mainauthor, List<String> secondaryAuthor, State state,Integer integer);
public void removeArticle(Integer articleId);
public void updateArticle(Article article);
@@ -21,7 +23,7 @@ public interface IArticleManager {
//liste d'articles
//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> getArticlesOfMember(Conference conf, User member);
@@ -36,7 +38,7 @@ public interface IArticleManager {
public void addOrUpdatePreference(Integer article_id, String userLogin, String preferenceValue);
//FIXME interet ?
public boolean existsArticle(Article article);
public boolean existsArticle(Integer articleId);
public boolean existsPreference(Preference preference);
}

View File

@@ -0,0 +1,5 @@
package org.yacos.core.conferences;
public class ConferenceDoesntExistException extends Exception {
}

View File

@@ -28,8 +28,8 @@ public class ConferenceManagerBean implements IConferenceManager {
return em.find(Conference.class, id);
}
public void remove(Conference conf) {
Conference persistedConf = em.find(Conference.class, conf.getId());
public void remove(Integer conferenceId) {
Conference persistedConf = em.find(Conference.class, conferenceId);
em.remove(persistedConf);
}
@@ -61,7 +61,9 @@ public class ConferenceManagerBean implements IConferenceManager {
* 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);
em.persist(role);
}
@@ -96,8 +98,8 @@ public class ConferenceManagerBean implements IConferenceManager {
return query.getResultList();
}
public boolean exists(Integer conferenceId) {
return (this.getConference(conferenceId)!=null);
}
}

View File

@@ -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 getConference(Integer id);
public void remove(Conference conf);
public void remove(Integer conferenceId);
public void update(Conference conf);
//article methodes
@@ -30,9 +30,10 @@ public interface IConferenceManager {
//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 List<Role> getRoles(Conference conf);
public List<Role> getRoles(User user, Conference conf);
public void updateRole(Role role);
public boolean exists(Integer conferenceId);
}

View File

@@ -6,15 +6,19 @@ import javax.ejb.Remote;
import org.yacos.core.conferences.Conference;
import org.yacos.core.exceptions.PKAlreadyUsedException;
import org.yacos.core.users.Role.RoleType;
/**
* @author christiancorsano
*
*/
@Remote
public interface IUserManager {
//crud methode
public User addUser(String login, String password, String firstName,
String lastName, String organization, String email) throws PKAlreadyUsedException;
public void removeUser(User user);
public void removeUser(String login);
public User getUser(String login);
public void UpdateUser(User user);
public Boolean exists(String login);
@@ -23,6 +27,18 @@ public interface IUserManager {
public List<User> getUsers();
public List<User> getUsers(Conference conf);
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);
}

View File

@@ -2,6 +2,7 @@ package org.yacos.core.users;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
@@ -28,19 +29,29 @@ public class Role implements Serializable {
*/
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
* Primary Key
*/
@Id
@ManyToOne(targetEntity=User.class,optional=false)
@JoinColumn(name="user_id",nullable=false)
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
* Primary Key
*/
@Id
@ManyToOne(targetEntity=Conference.class,optional=false)
@JoinColumn(name="conference_id",nullable=false)
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() {
return user;
}
@ManyToOne(targetEntity=User.class,optional=false)
@JoinColumn(name="user_id",nullable=false)
public void setUser(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() {
return conference;
}
@ManyToOne(targetEntity=Conference.class,optional=false)
@JoinColumn(name="conference_id",nullable=false)
public void setConference(Conference conference) {
this.conference = conference;
this.conference_id = conference.getId();
}
/**
* @return the type of this role
*/
@Enumerated(EnumType.ORDINAL)
public RoleType getType() {
return type;
}
/**
* @param type the type of this role
*/
@Enumerated(EnumType.ORDINAL)
public void setType(RoleType type) {
this.type = type;
}

View File

@@ -1,11 +1,6 @@
package org.yacos.core.users;
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.users.Role.RoleType;
@@ -16,24 +11,28 @@ public class RolePK implements Serializable{
*/
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 RoleType type;
/**
* Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html
*/
@Id
@ManyToOne(targetEntity=User.class,optional=false)
@JoinColumn(name="user_id",nullable=false)
public User user;
/**
* Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html
*/
@Id
@ManyToOne(targetEntity=Conference.class,optional=false)
@JoinColumn(name="conference_id",nullable=false)
public Conference conference;
public RolePK() {
}
public RolePK(User user, RoleType type, Conference conference) {
super();
this.user_id = user.getLogin();
this.type = type;
this.conference_id = conference.getId();
}
@Override
public boolean equals(Object obj) {
@@ -42,13 +41,13 @@ public class RolePK implements Serializable{
}
RolePK otherPK = (RolePK) obj;
return type.equals(otherPK.type)&&
user.getLogin().equals(otherPK.user.getLogin())&&
conference.getId() == otherPK.conference.getId();
user_id.equals(otherPK.user_id)&&
conference_id == otherPK.conference_id;
}
@Override
public int hashCode() {
return type.hashCode() ^ user.hashCode() ^ conference.hashCode();
return type.hashCode() ^ user_id.hashCode() ^ conference_id.hashCode();
}
}

View File

@@ -4,8 +4,10 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@@ -57,7 +59,7 @@ public class User implements Serializable{
/**
* 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;
@OneToMany(targetEntity=Article.class,mappedBy="mainAuthor")
@@ -137,7 +139,7 @@ public class User implements Serializable{
return false;
}
@OneToMany(targetEntity=Role.class,mappedBy="user")
@OneToMany(targetEntity=Role.class,mappedBy="user",fetch=FetchType.EAGER)
public List<Role> getRoles(){
return roles;
}
@@ -160,7 +162,7 @@ public class User implements Serializable{
/**
* @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) {
this.roles = roles;
}

View File

@@ -51,8 +51,8 @@ public class UserManagerBean implements IUserManager{
* Removes a user from the system
* @param user
*/
public void removeUser(User user){
User persistedUser = em.find(User.class, user.getLogin());
public void removeUser(String login){
User persistedUser = em.find(User.class, login);
em.remove(persistedUser);
}
@@ -83,4 +83,25 @@ public class UserManagerBean implements IUserManager{
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);
}
}