Commit 4d3aef6b by Juho Juopperi

poll stuff

1 parent bd7bc9b5
package fi.insomnia.bortal.beans;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import fi.insomnia.bortal.facade.PollAnswerFacade;
import fi.insomnia.bortal.facade.PollFacade;
import fi.insomnia.bortal.model.Poll;
import fi.insomnia.bortal.model.PollAnswer;
import fi.insomnia.bortal.model.PollQuestion;
/**
* Session Bean implementation class PollBean
*/
@Stateless
public class PollBean implements PollBeanLocal {
@EJB
private PollFacade pollFacade;
@EJB
private PollAnswerFacade pollAnswerFacade;
@EJB
private EventBean eventBean;
@EJB
private UserBean userBean;
/**
* Default constructor.
*/
......@@ -22,14 +41,48 @@ public class PollBean implements PollBeanLocal {
@Override
public List<Poll> findPolls() {
// TODO Auto-generated method stub
return null;
List<Poll> list = new ArrayList<Poll>();
userBean.fatalNotLoggedIn();
for (Poll p : pollFacade.findAll(eventBean.getCurrentEvent()))
if (pollIsUsable(p))
list.add(p);
return list;
}
private boolean pollIsUsable(Poll poll) {
Calendar now = Calendar.getInstance();
// Already valid
if (poll.getBegin().before(now))
return false;
// Still valid
if (poll.getEnd().after(now))
return false;
// At least one question that is on a page
for (PollQuestion q : poll.getQuestions()) {
if (q.getPage() > 0)
return true;
}
// No usable questions
return false;
}
@Override
public boolean createAnswers(List<PollAnswer> answers) {
// TODO Auto-generated method stub
return false;
userBean.fatalNotLoggedIn();
for (PollAnswer answer : answers) {
answer.setUser(userBean.getCurrentUser());
if (answer.getId().getId() != null)
pollAnswerFacade.create(answer);
}
return false;
}
}
......@@ -7,6 +7,7 @@ import java.util.Calendar;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.Table;
......@@ -33,7 +34,7 @@ public class Poll extends GenericEventChild implements Serializable {
@Lob
private String description;
@OneToMany(mappedBy="poll")
@OneToMany(mappedBy = "poll", fetch = FetchType.EAGER)
private List<PollQuestion> questions;
public Poll() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!