This commit is contained in:
Maxime Dagnicourt
2008-02-04 16:39:19 +00:00
parent c5bd76a8f5
commit cd5112abfa
5 changed files with 118 additions and 37 deletions

View File

@@ -28,6 +28,7 @@ public class Criterion implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private String name;
private Integer min_rating;
private Integer max_rating;

View File

@@ -3,7 +3,7 @@
*/
package org.yacos.core.evaluation;
import java.util.Collection;
import java.util.List;
import javax.ejb.Stateless;
@@ -16,9 +16,9 @@ import javax.persistence.Query;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.yacos.core.article.Article;
import org.yacos.core.article.IArticleManager;
import org.yacos.core.conferences.IConferenceManager;
import org.yacos.core.users.User;
import org.yacos.core.users.IUserManager;
/**
* @author christiancorsano
@@ -32,16 +32,38 @@ public class EvaluationManagerBean implements IEvaluationManager {
protected final Log logger = LogFactory.getLog(getClass());
private IConferenceManager cm;
private IArticleManager am;
private IUserManager um;
private IConferenceManager getConferenceManager(){
Context context;
try {
context = new InitialContext();
cm = (IConferenceManager)context.lookup("ConferenceManagerBean/remote");
} catch (NamingException e) {
logger.error(e.getMessage());
}
return cm;
}
private IArticleManager getArticleManager(){
Context context;
try {
context = new InitialContext();
am = (IArticleManager)context.lookup("ArticleManagerBean/remote");
} catch (NamingException e) {
logger.error(e.getMessage());
}
return am;
}
private IUserManager getUserManager(){
Context context;
try {
context = new InitialContext();
cm = (IConferenceManager)context.lookup("ConferenceManagerBean/remote");
um = (IUserManager)context.lookup("UserManagerBean/remote");
} catch (NamingException e) {
logger.error(e.getMessage());
}
return cm;
return um;
}
@@ -54,11 +76,7 @@ public class EvaluationManagerBean implements IEvaluationManager {
//return q.getResultList();
}
@SuppressWarnings("unchecked")
public List<Report> getReportsForArticle(Article article) {
Query q = em.createNativeQuery("from Report where article_id="+article.getId(), Report.class);
return q.getResultList();
}
public Criterion addCriterion(String name, Integer min_rating,
Integer max_rating, int confId) {
@@ -67,7 +85,6 @@ public class EvaluationManagerBean implements IEvaluationManager {
crit.setName(name);
crit.setMin(min_rating);
crit.setMax(max_rating);
System.out.println();
crit.setConference(cm.getConference(confId));
em.persist(crit);
em.flush();
@@ -93,21 +110,59 @@ public class EvaluationManagerBean implements IEvaluationManager {
* methodes du Report
*/
public Report addReport(Article article, String commentPCMember, String commentAuthor, List<Rating> ratings,
User referee) {
Report report = new Report(commentPCMember, commentAuthor,ratings, referee, article);
public Report addReport(int articleId, String commentPCMember, String commentAuthor, List<Rating> ratings,
String refereeLogin) {
um = getUserManager();
am = getArticleManager();
Report report = new Report();
report.setReferee(um.getUser(refereeLogin));
report.setArticle(am.getArticle(articleId));
report.setCommentPCMember(commentPCMember);
report.setCommentAuthor(commentAuthor);
report.setRatings(ratings);
//Report report = new Report("dsd",commentAuthor,ratings,um.getUser(refereeLogin),am.getArticle(articleId));
em.persist(report);
em.flush();
return report;
}
public List<Report> getReportsForUser(User user) {
// TODO Auto-generated method stub
return null;
}
public void updateReport(Report report) {
// TODO Auto-generated method stub
em.merge(report);
em.flush();
}
public void removeReport(int reportId) {
Report report = this.getReport(reportId);
em.remove(report);
}
public Report getReport(int reportId){
Report report = em.find(Report.class, reportId);
return report;
}
public Report getReportforArticleAndReferee(int articleId, String refereeLogin) {
Query q = em.createQuery("from Report r where article_id= ? and referee_id= ?");
q.setParameter(1, articleId);
q.setParameter(2, refereeLogin);
return (Report) q.getSingleResult();
}
@SuppressWarnings("unchecked")
public List<Report> getReportsForArticle(int articleId) {
Query q = em.createQuery("from Report r where article_id= ?");
q.setParameter(1, articleId);
return q.getResultList();
}
@SuppressWarnings("unchecked")
public List<Report> getReportsForReferee(String refereeLogin) {
Query q = em.createQuery("from Report r where referee_id= ?");
q.setParameter(1, refereeLogin);
return q.getResultList();
}
}

View File

@@ -3,14 +3,11 @@
*/
package org.yacos.core.evaluation;
import java.util.Collection;
import java.util.List;
import javax.ejb.Remote;
import org.yacos.core.article.Article;
import org.yacos.core.users.User;
/**
* @author christiancorsano
*
@@ -25,9 +22,12 @@ public interface IEvaluationManager {
public void removeCriterion(int criterionId);
public List<Criterion> getCriterions(int confId);
public Report addReport(Article article, String commentPCMember, String commentAuthor,
List<Rating> ratings, User referee);
public Report addReport(int articleId, String commentPCMember, String commentAuthor,
List<Rating> ratings, String userLogin);
public void updateReport(Report report);
public List<Report> getReportsForArticle(Article article);
public List<Report> getReportsForUser(User user);
public void removeReport(int reportId);
public Report getReport(int reportId);
public Report getReportforArticleAndReferee(int articleId, String refereeLogin);
public List<Report> getReportsForArticle(int articleId);
public List<Report> getReportsForReferee(String refereeLogin);
}

View File

@@ -3,6 +3,8 @@
*/
package org.yacos.core.evaluation;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
@@ -16,28 +18,34 @@ import javax.persistence.ManyToOne;
*
*/
@Entity
public class Rating {
public class Rating implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private Integer value;
@ManyToOne(targetEntity=Criterion.class,fetch=FetchType.EAGER)
@JoinColumn(name="criterion_id",nullable=false)
private Criterion criterion;
@ManyToOne(targetEntity=Report.class)
@JoinColumn(name="report_id",nullable=false)
private Report report;
/**
* @return the id
*/
@Id
public Integer getId() {
return id;
}
/**
* @param id the id to set
*/
@Id
public void setId(Integer id) {
this.id = id;
}

View File

@@ -3,8 +3,9 @@
*/
package org.yacos.core.evaluation;
import java.util.ArrayList;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@@ -23,25 +24,39 @@ import org.yacos.core.users.User;
*
*/
@Entity
public class Report {
public class Report implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private String commentPCMember;
private String commentAuthor;
@OneToMany(targetEntity=Rating.class,mappedBy="report",fetch=FetchType.EAGER)
private Collection<Rating> ratings;
@ManyToOne(targetEntity=User.class)
@JoinColumn(name="referee_id",nullable=false)
private User referee;
@ManyToOne(targetEntity=Article.class)
@JoinColumn(name="article_id",nullable=false)
@JoinColumn(name="article_id",nullable=false )
private Article article;
/**
* @constructor
*/
public Report(){
super();
}
public Report(String commentPCMember, String commentAuthor,
Collection<Rating> ratings, User referee, Article article) {
super();
@@ -56,6 +71,7 @@ public class Report {
* @return the id
*/
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public Integer getId() {
return id;
}
@@ -63,6 +79,7 @@ public class Report {
* @param id the id to set
*/
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public void setId(Integer id) {
this.id = id;
}
@@ -138,7 +155,7 @@ public class Report {
* @param ratings the ratings to set
*/
@OneToMany(targetEntity=Rating.class,mappedBy="report")
public void setRatings(ArrayList<Rating> ratings) {
public void setRatings(List<Rating> ratings) {
this.ratings = ratings;
}
}