Commit d8052db3 by Tuomas Riihimäki

Kyselyhässäkkä periaatteessa valmis. No deployataan, eli on..

1 parent ec613581
...@@ -7,8 +7,13 @@ import java.util.List; ...@@ -7,8 +7,13 @@ import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.facade.EventChildGenericFacade;
import fi.insomnia.bortal.facade.PollAnswerFacade; import fi.insomnia.bortal.facade.PollAnswerFacade;
import fi.insomnia.bortal.facade.PollFacade; import fi.insomnia.bortal.facade.PollFacade;
import fi.insomnia.bortal.facade.PollQuestionFacade;
import fi.insomnia.bortal.facade.PossibleAnswerFacade; import fi.insomnia.bortal.facade.PossibleAnswerFacade;
import fi.insomnia.bortal.model.Poll; import fi.insomnia.bortal.model.Poll;
import fi.insomnia.bortal.model.PollAnswer; import fi.insomnia.bortal.model.PollAnswer;
...@@ -29,14 +34,19 @@ public class PollBean implements PollBeanLocal { ...@@ -29,14 +34,19 @@ public class PollBean implements PollBeanLocal {
private PollAnswerFacade pollAnswerFacade; private PollAnswerFacade pollAnswerFacade;
@EJB @EJB
private EventBean eventBean; private EventBeanLocal eventBean;
@EJB @EJB
private UserBean userBean; private UserBeanLocal userBean;
@EJB @EJB
private PossibleAnswerFacade possibleAnswerFacade; private PossibleAnswerFacade possibleAnswerFacade;
@EJB
private PollQuestionFacade pqfacade;
private static final Logger logger = LoggerFactory.getLogger(PollBean.class);
/** /**
* Default constructor. * Default constructor.
*/ */
...@@ -50,10 +60,15 @@ public class PollBean implements PollBeanLocal { ...@@ -50,10 +60,15 @@ public class PollBean implements PollBeanLocal {
userBean.fatalNotLoggedIn(); userBean.fatalNotLoggedIn();
for (Poll p : pollFacade.findAll(eventBean.getCurrentEvent())) for (Poll p : pollFacade.findAll(eventBean.getCurrentEvent())) {
if (pollIsUsable(p)) if (pollIsUsable(p)) {
list.add(p); list.add(p);
}
logger.debug("Checked poll {}. listsize {}", p, list.size());
}
logger.debug("Returning poll");
return list; return list;
} }
...@@ -61,17 +76,24 @@ public class PollBean implements PollBeanLocal { ...@@ -61,17 +76,24 @@ public class PollBean implements PollBeanLocal {
Calendar now = Calendar.getInstance(); Calendar now = Calendar.getInstance();
// Already valid // Already valid
if (poll.getBegin().before(now)) if (poll.getBegin().after(now)) {
logger.debug("Poll {} not opened yet", poll);
return false; return false;
}
// Still valid // Still valid
if (poll.getEnd().after(now)) if (poll.getEnd().before(now)) {
logger.debug("Poll {} already closed", poll);
return false; return false;
}
logger.debug("Poll has {} questions", poll.getQuestions());
// At least one question that is on a page // At least one question that is on a page
for (PollQuestion q : poll.getQuestions()) { for (PollQuestion q : poll.getQuestions()) {
if (q.getPage() > 0) logger.debug("Check question {} page {}", q, q.getPage());
if (q.getPage() > 0) {
return true; return true;
}
} }
// No usable questions // No usable questions
...@@ -84,7 +106,7 @@ public class PollBean implements PollBeanLocal { ...@@ -84,7 +106,7 @@ public class PollBean implements PollBeanLocal {
for (PollAnswer answer : answers) { for (PollAnswer answer : answers) {
answer.setUser(userBean.getCurrentUser()); answer.setUser(userBean.getCurrentUser());
if (answer.getId().getId() != null) if (answer.getId().getId() == null)
pollAnswerFacade.create(answer); pollAnswerFacade.create(answer);
} }
...@@ -94,6 +116,18 @@ public class PollBean implements PollBeanLocal { ...@@ -94,6 +116,18 @@ public class PollBean implements PollBeanLocal {
@Override @Override
public PossibleAnswer findPossibleAnwerById(int id) { public PossibleAnswer findPossibleAnwerById(int id) {
PossibleAnswer ans = possibleAnswerFacade.find(eventBean.getCurrentEvent().getId(), new Integer(id)); PossibleAnswer ans = possibleAnswerFacade.find(eventBean.getCurrentEvent().getId(), new Integer(id));
logger.debug("Searching from facade {} found {}", id, ans.getId().getId());
return ans; return ans;
} }
@Override
public void createPoll(Poll poll) {
pollFacade.create(poll);
}
@Override
public void createAnswers(PollQuestion q) {
pqfacade.create(q);
}
} }
...@@ -5,6 +5,7 @@ import javax.ejb.Local; ...@@ -5,6 +5,7 @@ import javax.ejb.Local;
import fi.insomnia.bortal.model.Poll; import fi.insomnia.bortal.model.Poll;
import fi.insomnia.bortal.model.PollAnswer; import fi.insomnia.bortal.model.PollAnswer;
import fi.insomnia.bortal.model.PollQuestion;
import fi.insomnia.bortal.model.PossibleAnswer; import fi.insomnia.bortal.model.PossibleAnswer;
@Local @Local
...@@ -18,4 +19,10 @@ public interface PollBeanLocal { ...@@ -18,4 +19,10 @@ public interface PollBeanLocal {
PossibleAnswer findPossibleAnwerById(int id); PossibleAnswer findPossibleAnwerById(int id);
void createPoll(Poll poll);
void createAnswers(PollQuestion q1);
} }
...@@ -23,7 +23,8 @@ public enum Permission { ...@@ -23,7 +23,8 @@ public enum Permission {
ROLE_MANAGEMENT("User has right to view(r), modify(w) and assign(x) roles"), ROLE_MANAGEMENT("User has right to view(r), modify(w) and assign(x) roles"),
PRODUCT("View(r), modify(w), and shop(x) products"), PRODUCT("View(r), modify(w), and shop(x) products"),
SHOP("View shopped events(r), Modify AccountEvents() and Shop(x)"), SHOP("View shopped events(r), Modify AccountEvents() and Shop(x)"),
GAME("View(r) own, write(w) modify, view all(X)"); GAME("View(r) own, write(w) modify, view all(X)"),
POLL("View answers(r), create (w) and answer(x) to polls");
private String description; private String description;
private static final Logger logger = LoggerFactory.getLogger(Permission.class); private static final Logger logger = LoggerFactory.getLogger(Permission.class);
......
...@@ -38,7 +38,7 @@ public abstract class GenericEventChild implements EventChildInterface { ...@@ -38,7 +38,7 @@ public abstract class GenericEventChild implements EventChildInterface {
} }
@Override @Override
public final boolean equals(Object object) { public boolean equals(Object object) {
if (!this.getClass().equals(object.getClass())) { if (!this.getClass().equals(object.getClass())) {
logger.debug("Classes dont match {} {}", getClass(), object.getClass()); logger.debug("Classes dont match {} {}", getClass(), object.getClass());
......
...@@ -51,8 +51,9 @@ public class Poll extends GenericEventChild implements Serializable { ...@@ -51,8 +51,9 @@ public class Poll extends GenericEventChild implements Serializable {
super(); super();
} }
public Poll(LanEvent e) { public Poll(LanEvent e, String name) {
super(e); super(e);
this.name = name;
} }
public Calendar getBegin() { public Calendar getBegin() {
......
...@@ -10,18 +10,21 @@ import javax.persistence.Lob; ...@@ -10,18 +10,21 @@ import javax.persistence.Lob;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Entity @Entity
@Table(name = "poll_answer") @Table(name = "poll_answer")
public class PollAnswer extends GenericEventChild implements Serializable { public class PollAnswer extends GenericEventChild implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Logger logger = LoggerFactory.getLogger(PollAnswer.class);
@Lob @Lob
@Column(name = "answer_text", nullable = true) @Column(name = "answer_text", nullable = true)
private String answerText; private String answerText = "";
@Column(name = "answer_boolean", nullable = true) @Column(name = "answer_boolean", nullable = true)
private Boolean answerBoolean; private Boolean answerBoolean = false;
@ManyToOne @ManyToOne
@JoinColumns({ @JoinColumns({
...@@ -33,19 +36,19 @@ public class PollAnswer extends GenericEventChild implements Serializable { ...@@ -33,19 +36,19 @@ public class PollAnswer extends GenericEventChild implements Serializable {
@JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false) @JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false)
private User user; private User user;
public void setAnswerText(String answerText) {
this.answerText = answerText;
}
public PollAnswer() { public PollAnswer() {
super(); super();
} }
public PollAnswer(PossibleAnswer a) { public PollAnswer(PossibleAnswer a) {
super(new EventPk(a.getId().getId())); super(a.getId());
this.choice = a; this.choice = a;
} }
public void setAnswerText(String answerText) {
this.answerText = answerText;
}
public String getAnswerText() { public String getAnswerText() {
return answerText; return answerText;
} }
...@@ -73,4 +76,23 @@ public class PollAnswer extends GenericEventChild implements Serializable { ...@@ -73,4 +76,23 @@ public class PollAnswer extends GenericEventChild implements Serializable {
public Boolean getAnswerBoolean() { public Boolean getAnswerBoolean() {
return answerBoolean; return answerBoolean;
} }
@Override
public boolean equals(Object p) {
boolean ret = false;
if (p != null && p instanceof PollAnswer) {
PollAnswer ans = (PollAnswer) p;
if (this.getId() != null && ans.getId() != null) {
ret = super.equals(p);
} else {
if (this.getChoice() != null && this.getChoice().equals(ans.getChoice())) {
ret = true;
}
}
}
logger.debug("Equalling {} {}, ret: {}", new Object[] { this, p, ret });
return ret;
}
} }
...@@ -21,15 +21,13 @@ public class PollQuestion extends GenericEventChild { ...@@ -21,15 +21,13 @@ public class PollQuestion extends GenericEventChild {
super(); super();
} }
public PollQuestion(Poll p) { public PollQuestion(Poll p, String name) {
super(p.getId()); super(p.getId());
this.poll = p; this.poll = p;
this.question = name;
} }
/**
*
*/
private static final long serialVersionUID = 821112669474215823L; private static final long serialVersionUID = 821112669474215823L;
@JoinColumns({ @JoinColumns({
...@@ -41,6 +39,7 @@ public class PollQuestion extends GenericEventChild { ...@@ -41,6 +39,7 @@ public class PollQuestion extends GenericEventChild {
@OneToMany(mappedBy = "question", cascade = CascadeType.ALL) @OneToMany(mappedBy = "question", cascade = CascadeType.ALL)
private List<PossibleAnswer> answers = new ArrayList<PossibleAnswer>(); private List<PossibleAnswer> answers = new ArrayList<PossibleAnswer>();
@Lob @Lob
private String question; private String question;
@Column(nullable = false) @Column(nullable = false)
...@@ -55,7 +54,7 @@ public class PollQuestion extends GenericEventChild { ...@@ -55,7 +54,7 @@ public class PollQuestion extends GenericEventChild {
} }
public boolean isFreeText() { public boolean isFreeText() {
return (answers.size() == 1 && answers.get(0).isText()); return (answers.size() == 1 && answers.get(0).getTextanswer());
} }
public void setQuestion(String question) { public void setQuestion(String question) {
......
...@@ -11,11 +11,22 @@ import javax.persistence.Lob; ...@@ -11,11 +11,22 @@ import javax.persistence.Lob;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Basic;
@Entity @Entity
@Table(name = "poll_question") @Table(name = "possible_answer")
public class PossibleAnswer extends GenericEventChild { public class PossibleAnswer extends GenericEventChild {
public PossibleAnswer() {
super();
}
public PossibleAnswer(PollQuestion pq, String answer) {
super(pq.getId());
this.answer = answer;
this.question = pq;
}
/** /**
* *
*/ */
...@@ -24,13 +35,15 @@ public class PossibleAnswer extends GenericEventChild { ...@@ -24,13 +35,15 @@ public class PossibleAnswer extends GenericEventChild {
private String answer; private String answer;
@Column(nullable = false) @Column(nullable = false)
private Integer sort = 100; private Integer sort = 100;
@Column(nullable = false) @Column(nullable = false)
private boolean text = false; private boolean textanswer = false;
@Lob @Lob
private String description; private String description;
@JoinColumns({ @JoinColumns({
@JoinColumn(name = "question_id", referencedColumnName = "id"), @JoinColumn(name = "question_id", referencedColumnName = "id" , nullable=false),
@JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) }) @JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) })
@ManyToOne @ManyToOne
private PollQuestion question; private PollQuestion question;
...@@ -54,14 +67,6 @@ public class PossibleAnswer extends GenericEventChild { ...@@ -54,14 +67,6 @@ public class PossibleAnswer extends GenericEventChild {
this.sort = sort; this.sort = sort;
} }
public boolean isText() {
return text;
}
public void setText(boolean text) {
this.text = text;
}
public String getDescription() { public String getDescription() {
return description; return description;
} }
...@@ -86,4 +91,12 @@ public class PossibleAnswer extends GenericEventChild { ...@@ -86,4 +91,12 @@ public class PossibleAnswer extends GenericEventChild {
this.answers = answers; this.answers = answers;
} }
public void setTextanswer(Boolean textanswer) {
this.textanswer = textanswer;
}
public Boolean getTextanswer() {
return textanswer;
}
} }
...@@ -40,7 +40,9 @@ import fi.insomnia.bortal.enums.Permission; ...@@ -40,7 +40,9 @@ import fi.insomnia.bortal.enums.Permission;
@ConversionValue(dataValue = "ROLE_MANAGEMENT", objectValue = "ROLE_MANAGEMENT"), @ConversionValue(dataValue = "ROLE_MANAGEMENT", objectValue = "ROLE_MANAGEMENT"),
@ConversionValue(dataValue = "PRODUCT", objectValue = "PRODUCT"), @ConversionValue(dataValue = "PRODUCT", objectValue = "PRODUCT"),
@ConversionValue(dataValue = "SHOP", objectValue = "SHOP"), @ConversionValue(dataValue = "SHOP", objectValue = "SHOP"),
@ConversionValue(dataValue = "GAME", objectValue = "GAME") @ConversionValue(dataValue = "GAME", objectValue = "GAME"),
@ConversionValue(dataValue = "POLL", objectValue = "POLL")
}) })
public class RoleRight implements EventChildInterface { public class RoleRight implements EventChildInterface {
......
...@@ -20,6 +20,7 @@ import javax.persistence.TemporalType; ...@@ -20,6 +20,7 @@ import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import javax.persistence.Version; import javax.persistence.Version;
/** /**
* A vote for a compo entry * A vote for a compo entry
*/ */
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
<br /> <br />
<h:commandButton value="Resize all images" action="#{TestDataView.convertImages()}" /> <h:commandButton value="Resize all images" action="#{TestDataView.convertImages()}" />
<br /> <br />
<h:commandButton value="Generate test poll data" action="#{TestDataView.generatePollData()}" />
<br />
</h:form> </h:form>
</h:body> </h:body>
</html> </html>
......
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<ui:composition template="/layout/insomnia1/sidebartemplate.xhtml">
<ui:param name="rendered" value="#{sessionHandler.isLoggedIn()}" />
<ui:define name="sidebarcontent">
<ul>
<li><h:link outcome="/user/sendPicture" value="#{i18n['user.sendPicture']}"/></li>
<li><h:link outcome="/user/changePassword" value="#{i18n['user.changePassword']}"/></li>
<li><h:link outcome="/user/accountEvents" value="#{i18n['user.accountEvents']}"/></li>
<li><h:link outcome="/place/myGroups" value="#{i18n['user.myGroups']}"/></li>
<li><h:link outcome="/place/insertToken" value="#{i18n['user.insertToken']}"/></li>
</ul>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
...@@ -34,10 +34,14 @@ ...@@ -34,10 +34,14 @@
<tools:isLoggedIn> <tools:isLoggedIn>
<div class="link#{i18n[util.concat(thispage,'.pagegroup')] == 'user'?'a':''}"><h:link outcome="/user/editself" <div class="link#{i18n[util.concat(thispage,'.pagegroup')] == 'user'?'a':''}"><h:link outcome="/user/editself"
value="#{i18n['topmenu.usersPreferences']}" /></div> value="#{i18n['topmenu.usersPreferences']}" /></div>
<div class="link#{i18n[util.concat(thispage,'.pagegroup')] == 'shop'?'a': ''}"><h:link <!-- <div class="link#{i18n[util.concat(thispage,'.pagegroup')] == 'shop'?'a': ''}"><h:link
outcome="/product/createBill" value="#{i18n['topmenu.shoppings']}" /></div> outcome="/product/createBill" value="#{i18n['topmenu.shoppings']}" /></div>
-->
</tools:isLoggedIn> </tools:isLoggedIn> <tools:canRead target="POLL">
<div class="link#{i18n[util.concat(thispage,'.pagegroup')] == 'poll'?'a': ''}"><h:link
outcome="/poll/start" value="#{i18n['topmenu.poll']}" /></div>
</tools:canRead>
<div class="link#{i18n[util.concat(thispage,'.pagegroup')] == 'placemap'?'a':''}"><h:link <div class="link#{i18n[util.concat(thispage,'.pagegroup')] == 'placemap'?'a':''}"><h:link
outcome="/place/placemap" value="#{i18n['topmenu.placemap']}" /></div> outcome="/place/placemap" value="#{i18n['topmenu.placemap']}" /></div>
...@@ -49,8 +53,8 @@ ...@@ -49,8 +53,8 @@
outcome="/shop/showReaderEvents" value="#{i18n['topmenu.rfidshop']}" /></div> outcome="/shop/showReaderEvents" value="#{i18n['topmenu.rfidshop']}" /></div>
</tools:canRead> <tools:canRead target="GAME"> </tools:canRead> <tools:canRead target="GAME">
<div class="link#{i18n[util.concat(thispage,'.pagegroup')] == 'game'?'a':''}"><h:link <div class="link#{i18n[util.concat(thispage,'.pagegroup')] == 'game'?'a':''}"><h:link outcome="/game/start"
outcome="/game/start" value="#{i18n['topmenu.game']}" /></div> value="#{i18n['topmenu.game']}" /></div>
</tools:canRead></div> </tools:canRead></div>
</div> </div>
......
...@@ -6,26 +6,24 @@ ...@@ -6,26 +6,24 @@
xmlns:users="http://java.sun.com/jsf/composite/tools/user" xmlns:c="http://java.sun.com/jsp/jstl/core"> xmlns:users="http://java.sun.com/jsf/composite/tools/user" xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body> <h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml"> <ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.eventorg.list" /> <ui:param name="thispage" value="page.poll.start" />
<ui:define name="content"> <ui:define name="content">
<h:messages />
<h:form id="answerForm"> <h:form id="answerForm">
<h:dataTable border="1" id="questions" value="#{pollView.currentPage}" var="question"> <h:dataTable border="0" id="questions" value="#{pollView.currentPage}" var="question">
<h:column> <h:column>
<f:facet name="header">
<h:outputText value="${i18n['poll.name']}" />
</f:facet>
<h:outputText value="#{question.question.question}" /> <h:outputText value="#{question.question.question}" />
</h:column> </h:column>
<h:column> <h:column>
<h:inputTextarea cols="50" rows="7" value="#{question.textAnswer.answerText}" rendered="#{question.freeText}" /> <h:inputTextarea id="freecell" cols="50" rows="7" value="#{question.textAnswer.answerText}" rendered="#{question.freeText}" />
<h:selectOneRadio converter="#{pollAnswerConverter}" rendered="#{!question.freeText and question.choices eq 1}" <h:selectOneRadio id="selectone" layout="pageDirection" converter="#{pollAnswerConverter}"
value="#{question.oneSelected}"> rendered="#{!question.freeText and question.question.choices eq 1}" value="#{question.oneSelected}">
<f:selectItems var="ans" itemLabel="#{ans.choice.answer}" value="#{question.answers}" /> <f:selectItems var="ans" itemLabel="#{ans.choice.answer}" value="#{question.answers}" />
</h:selectOneRadio> </h:selectOneRadio>
</h:column> </h:column>
</h:dataTable> </h:dataTable>
<h:commandButton action="#{pollView.savePoll()}" value="#{i18n['poll.save']}" />
</h:form> </h:form>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
......
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:users="http://java.sun.com/jsf/composite/tools/user" xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.eventorg.list" />
<ui:define name="content">
<h1>Kiitoksia vastauksistasi</h1>
<p>Nähdään ensi vuonna uudestaan.</p>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
...@@ -10,6 +10,9 @@ import javax.faces.bean.ManagedBean; ...@@ -10,6 +10,9 @@ import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped; import javax.faces.bean.SessionScoped;
import javax.faces.model.ListDataModel; import javax.faces.model.ListDataModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beans.PollBeanLocal; import fi.insomnia.bortal.beans.PollBeanLocal;
import fi.insomnia.bortal.model.Poll; import fi.insomnia.bortal.model.Poll;
import fi.insomnia.bortal.model.PollAnswer; import fi.insomnia.bortal.model.PollAnswer;
...@@ -28,8 +31,12 @@ public class PollView extends GenericView { ...@@ -28,8 +31,12 @@ public class PollView extends GenericView {
private Integer thisPage = 1; private Integer thisPage = 1;
private static final Logger logger = LoggerFactory.getLogger(PollView.class);
public void initPollList() { public void initPollList() {
setPolls(new ListDataModel<Poll>(pollBean.findPolls())); List<Poll> pollList = pollBean.findPolls();
setPolls(new ListDataModel<Poll>(pollList));
logger.debug("Found {} polls from bean", pollList.size());
} }
public String nextPage() { public String nextPage() {
...@@ -56,9 +63,13 @@ public class PollView extends GenericView { ...@@ -56,9 +63,13 @@ public class PollView extends GenericView {
public String savePoll() { public String savePoll() {
if (validate(this)) { if (validate(this)) {
pollBean.createAnswers(createAnswers()); pollBean.createAnswers(createAnswers());
} }
return "thankYou"; pages = null;
polls = null;
return "/poll/thankYou";
} }
public void setPolls(ListDataModel<Poll> polls) { public void setPolls(ListDataModel<Poll> polls) {
...@@ -114,13 +125,14 @@ public class PollView extends GenericView { ...@@ -114,13 +125,14 @@ public class PollView extends GenericView {
return answers.get(0); return answers.get(0);
} }
public void setOneSelected(PollAnswer ans) { public void setOneSelected(PollAnswer ans) {
for (PollAnswer possibleAns : answers) { if (ans != null) {
if (possibleAns.getChoice().equals(ans.getChoice())) { for (PollAnswer possibleAns : answers) {
possibleAns.setAnswerBoolean(true); if (possibleAns.getChoice().equals(ans.getChoice())) {
} else { possibleAns.setAnswerBoolean(true);
possibleAns.setAnswerBoolean(false); } else {
possibleAns.setAnswerBoolean(false);
}
} }
} }
} }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
*/ */
package fi.insomnia.bortal.view; package fi.insomnia.bortal.view;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List; import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
...@@ -15,12 +17,18 @@ import org.slf4j.Logger; ...@@ -15,12 +17,18 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beans.CardTemplateBeanLocal; import fi.insomnia.bortal.beans.CardTemplateBeanLocal;
import fi.insomnia.bortal.beans.EventBeanLocal;
import fi.insomnia.bortal.beans.PollBeanLocal;
import fi.insomnia.bortal.beans.RoleBeanLocal; import fi.insomnia.bortal.beans.RoleBeanLocal;
import fi.insomnia.bortal.beans.TestDataBeanLocal; import fi.insomnia.bortal.beans.TestDataBeanLocal;
import fi.insomnia.bortal.beans.UserBeanLocal; import fi.insomnia.bortal.beans.UserBeanLocal;
import fi.insomnia.bortal.beans.UtilBeanLocal; import fi.insomnia.bortal.beans.UtilBeanLocal;
import fi.insomnia.bortal.handler.SessionHandler; import fi.insomnia.bortal.handler.SessionHandler;
import fi.insomnia.bortal.model.EventMap; import fi.insomnia.bortal.model.EventMap;
import fi.insomnia.bortal.model.LanEvent;
import fi.insomnia.bortal.model.Poll;
import fi.insomnia.bortal.model.PollQuestion;
import fi.insomnia.bortal.model.PossibleAnswer;
import fi.insomnia.bortal.model.Role; import fi.insomnia.bortal.model.Role;
import fi.insomnia.bortal.model.User; import fi.insomnia.bortal.model.User;
...@@ -44,6 +52,10 @@ public class TestDataView { ...@@ -44,6 +52,10 @@ public class TestDataView {
private UtilBeanLocal utilbean; private UtilBeanLocal utilbean;
@EJB @EJB
private CardTemplateBeanLocal ctbean; private CardTemplateBeanLocal ctbean;
@EJB
private EventBeanLocal eventbean;
@EJB
private PollBeanLocal pollbean;
public void generateData() { public void generateData() {
...@@ -112,4 +124,32 @@ public class TestDataView { ...@@ -112,4 +124,32 @@ public class TestDataView {
return null; return null;
} }
public String generatePollData() {
LanEvent ev = eventbean.getCurrentEvent();
Poll poll = new Poll(ev, "Tapahtumakysely");
Calendar end = Calendar.getInstance();
end.add(Calendar.MONTH, 1);
poll.setEnd(end);
createTextQuestion(poll, "Palautetta järjestäjille");
createTextQuestion(poll, "Mikä InsomniaGamessa oli parasta?");
createTextQuestion(poll, "Mikä InsomniaGamessa oli huonointa?");
createTextQuestion(poll, "Miten olisit halunnut saada tietoa InsomniaGameen liittyvistä tehtävistä?");
createTextQuestion(poll, "Palautteesi InsomniaGamen järjestäjille:");
pollbean.createPoll(poll);
return null;
}
private void createTextQuestion(Poll poll, String question) {
PollQuestion q1 = new PollQuestion(poll, question);
poll.getQuestions().add(q1);
PossibleAnswer vapaa = new PossibleAnswer(q1, "");
vapaa.setTextanswer(true);
q1.getAnswers().add(vapaa);
}
} }
...@@ -7,11 +7,12 @@ import javax.faces.component.UIComponent; ...@@ -7,11 +7,12 @@ import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import javax.faces.convert.Converter; import javax.faces.convert.Converter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beans.PollBeanLocal; import fi.insomnia.bortal.beans.PollBeanLocal;
import fi.insomnia.bortal.beans.ProductBeanLocal;
import fi.insomnia.bortal.model.PollAnswer; import fi.insomnia.bortal.model.PollAnswer;
import fi.insomnia.bortal.model.PossibleAnswer; import fi.insomnia.bortal.model.PossibleAnswer;
import fi.insomnia.bortal.model.Product;
@ManagedBean(name = "pollAnswerConverter") @ManagedBean(name = "pollAnswerConverter")
@NoneScoped() @NoneScoped()
...@@ -19,6 +20,7 @@ public class PollAnswerConverter implements Converter { ...@@ -19,6 +20,7 @@ public class PollAnswerConverter implements Converter {
@EJB @EJB
private PollBeanLocal pollbean; private PollBeanLocal pollbean;
private static final Logger logger = LoggerFactory.getLogger(PollAnswerConverter.class);
public PollAnswerConverter() { public PollAnswerConverter() {
} }
...@@ -28,15 +30,20 @@ public class PollAnswerConverter implements Converter { ...@@ -28,15 +30,20 @@ public class PollAnswerConverter implements Converter {
PossibleAnswer possibleAnswer = pollbean.findPossibleAnwerById(Integer.parseInt(value)); PossibleAnswer possibleAnswer = pollbean.findPossibleAnwerById(Integer.parseInt(value));
PollAnswer ret = new PollAnswer(); PollAnswer ret = new PollAnswer();
ret.setChoice(possibleAnswer); ret.setChoice(possibleAnswer);
logger.debug("Converting string {} to Poll Answer {}", value, possibleAnswer);
return ret; return ret;
} }
@Override @Override
public String getAsString(FacesContext context, UIComponent component, Object value) { public String getAsString(FacesContext context, UIComponent component, Object value) {
String ret = null; String ret = null;
if (value instanceof PollAnswer) { if (value instanceof PollAnswer) {
ret = ((PollAnswer) value).getChoice().getId().getId().toString(); ret = ((PollAnswer) value).getChoice().getId().getId().toString();
logger.debug("converting object {} to string {}", ((PollAnswer) value).getChoice().getId(), ret);
} }
return ret; return ret;
......
...@@ -97,4 +97,8 @@ page.shop.readerevents.header=RFID kauppa ...@@ -97,4 +97,8 @@ page.shop.readerevents.header=RFID kauppa
page.game.start.pagegroup=game page.game.start.pagegroup=game
page.game.start.header=Insomnia Game page.game.start.header=Insomnia Game
page.game.list.pagegroup=game page.game.list.pagegroup=game
page.game.list.header=Insomnia Game page.game.list.header=Insomnia Game
\ No newline at end of file
page.poll.start.pagegroup=poll
page.poll.start.header=Kysely
...@@ -69,6 +69,7 @@ role.edit.save=Tallenna ...@@ -69,6 +69,7 @@ role.edit.save=Tallenna
topmenu.game=Insomnia Game topmenu.game=Insomnia Game
topmenu.poll=Kysely
game.gamepoints=Insomnia Game pisteet: game.gamepoints=Insomnia Game pisteet:
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!