YACOSCore : Correction pour faire fonctionner l'enregistrement des preferences
- Article
- IArticleManager : ajout d'une méthode pour ajouter une préference (ATTENTION : les objets modeles ne passent pas tous dans les tuyaux des managers Stateless, on va devoir revoir tout ça)
- Preference : Corrigé l'auto-generation de l'ID
***** REGENERATION DE LA TABLE PREFERENCE NECESSAIRE *****
This commit is contained in:
@@ -11,6 +11,8 @@ import javax.persistence.JoinColumn;
|
|||||||
import javax.persistence.JoinTable;
|
import javax.persistence.JoinTable;
|
||||||
import javax.persistence.ManyToMany;
|
import javax.persistence.ManyToMany;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
|
|
||||||
import org.yacos.core.conferences.Conference;
|
import org.yacos.core.conferences.Conference;
|
||||||
import org.yacos.core.users.User;
|
import org.yacos.core.users.User;
|
||||||
|
|
||||||
@@ -60,6 +62,9 @@ public class Article implements Serializable {
|
|||||||
)
|
)
|
||||||
private Collection<User> pcMembers;
|
private Collection<User> pcMembers;
|
||||||
|
|
||||||
|
@OneToMany(targetEntity=Preference.class,mappedBy="article")
|
||||||
|
private Collection<Preference> preferences;
|
||||||
|
|
||||||
private int state;
|
private int state;
|
||||||
|
|
||||||
public enum state {
|
public enum state {
|
||||||
@@ -214,7 +219,23 @@ public class Article implements Serializable {
|
|||||||
this.conference = conference;
|
this.conference = conference;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean asMember(){
|
/**
|
||||||
|
* @return the preferences
|
||||||
|
*/
|
||||||
|
@OneToMany(targetEntity=Preference.class,mappedBy="article")
|
||||||
|
public Collection<Preference> getPreferences() {
|
||||||
|
return preferences;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param preferences the preferences to set
|
||||||
|
*/
|
||||||
|
@OneToMany(targetEntity=Preference.class,mappedBy="article")
|
||||||
|
public void setPreferences(Collection<Preference> preferences) {
|
||||||
|
this.preferences = preferences;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasMember(){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.ejb.Stateless;
|
import javax.ejb.Stateless;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
import javax.persistence.PersistenceContext;
|
import javax.persistence.PersistenceContext;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
|
||||||
import org.yacos.core.users.User;
|
import org.yacos.core.users.User;
|
||||||
|
|
||||||
@@ -65,4 +67,37 @@ public class ArticleManagerBean implements IArticleManager, Serializable {
|
|||||||
public List<User> getArticleReferees(Article article) {
|
public List<User> getArticleReferees(Article article) {
|
||||||
return (List<User>) article.getReferees();
|
return (List<User>) article.getReferees();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Preference getArticlePreferenceForUser(Article article,
|
||||||
|
String pcMemberLogin) {
|
||||||
|
Query query = em.createQuery("SELECT p FROM Preference p WHERE p.article.id = :articleid AND p.pcMember.id = :pcmemberlogin");
|
||||||
|
query.setParameter("articleid",article.getId());
|
||||||
|
query.setParameter("pcmemberlogin", pcMemberLogin);
|
||||||
|
try {
|
||||||
|
return (Preference) query.getSingleResult();
|
||||||
|
} catch (NoResultException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArticlePreferences(Article article,
|
||||||
|
List<Preference> preferences) {
|
||||||
|
article.setPreferences(preferences);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addArticlePreference(Preference preference) {
|
||||||
|
if(! em.contains(preference)){
|
||||||
|
em.persist(preference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addArticlePreference(Integer article_id, String userLogin, String preferenceValue) {
|
||||||
|
Preference preference = new Preference();
|
||||||
|
Article article = getArticle(article_id);
|
||||||
|
preference.setArticle(article);
|
||||||
|
User pcMember = em.find(User.class, userLogin);
|
||||||
|
preference.setPcMember(pcMember);
|
||||||
|
preference.setPreference(preferenceValue);
|
||||||
|
em.persist(preference);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ public interface IArticleManager {
|
|||||||
|
|
||||||
public List<?> getArticlePCMembers(Article article);
|
public List<?> getArticlePCMembers(Article article);
|
||||||
public List<?> getArticleReferees(Article article);
|
public List<?> getArticleReferees(Article article);
|
||||||
|
public Preference getArticlePreferenceForUser(Article article, String pcMemberLogin);
|
||||||
|
public void setArticlePreferences(Article article, List<Preference> preferences);
|
||||||
|
public void addArticlePreference(Integer article_id, String userLogin, String preferenceValue);
|
||||||
|
|
||||||
public List<Article> getArticles();
|
public List<Article> getArticles();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.yacos.core.article;
|
package org.yacos.core.article;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import javax.persistence.GenerationType;
|
||||||
@@ -17,7 +19,11 @@ import org.yacos.core.users.User;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
public class Preference {
|
public class Preference implements Serializable {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
/**
|
/**
|
||||||
* Id mandatory in every entity.
|
* Id mandatory in every entity.
|
||||||
*/
|
*/
|
||||||
@@ -38,6 +44,7 @@ public class Preference {
|
|||||||
* @return the id
|
* @return the id
|
||||||
*/
|
*/
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.AUTO)
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -45,6 +52,7 @@ public class Preference {
|
|||||||
* @param id the id to set
|
* @param id the id to set
|
||||||
*/
|
*/
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.AUTO)
|
||||||
public void setId(Integer id) {
|
public void setId(Integer id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user