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;
import javax.ejb.EJB;
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.PollFacade;
import fi.insomnia.bortal.facade.PollQuestionFacade;
import fi.insomnia.bortal.facade.PossibleAnswerFacade;
import fi.insomnia.bortal.model.Poll;
import fi.insomnia.bortal.model.PollAnswer;
......@@ -29,14 +34,19 @@ public class PollBean implements PollBeanLocal {
private PollAnswerFacade pollAnswerFacade;
@EJB
private EventBean eventBean;
private EventBeanLocal eventBean;
@EJB
private UserBean userBean;
private UserBeanLocal userBean;
@EJB
private PossibleAnswerFacade possibleAnswerFacade;
@EJB
private PollQuestionFacade pqfacade;
private static final Logger logger = LoggerFactory.getLogger(PollBean.class);
/**
* Default constructor.
*/
......@@ -50,10 +60,15 @@ public class PollBean implements PollBeanLocal {
userBean.fatalNotLoggedIn();
for (Poll p : pollFacade.findAll(eventBean.getCurrentEvent()))
if (pollIsUsable(p))
for (Poll p : pollFacade.findAll(eventBean.getCurrentEvent())) {
if (pollIsUsable(p)) {
list.add(p);
}
logger.debug("Checked poll {}. listsize {}", p, list.size());
}
logger.debug("Returning poll");
return list;
}
......@@ -61,18 +76,25 @@ public class PollBean implements PollBeanLocal {
Calendar now = Calendar.getInstance();
// Already valid
if (poll.getBegin().before(now))
if (poll.getBegin().after(now)) {
logger.debug("Poll {} not opened yet", poll);
return false;
}
// Still valid
if (poll.getEnd().after(now))
if (poll.getEnd().before(now)) {
logger.debug("Poll {} already closed", poll);
return false;
}
logger.debug("Poll has {} questions", poll.getQuestions());
// At least one question that is on a page
for (PollQuestion q : poll.getQuestions()) {
if (q.getPage() > 0)
logger.debug("Check question {} page {}", q, q.getPage());
if (q.getPage() > 0) {
return true;
}
}
// No usable questions
return false;
......@@ -84,7 +106,7 @@ public class PollBean implements PollBeanLocal {
for (PollAnswer answer : answers) {
answer.setUser(userBean.getCurrentUser());
if (answer.getId().getId() != null)
if (answer.getId().getId() == null)
pollAnswerFacade.create(answer);
}
......@@ -94,6 +116,18 @@ public class PollBean implements PollBeanLocal {
@Override
public PossibleAnswer findPossibleAnwerById(int id) {
PossibleAnswer ans = possibleAnswerFacade.find(eventBean.getCurrentEvent().getId(), new Integer(id));
logger.debug("Searching from facade {} found {}", id, ans.getId().getId());
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;
import fi.insomnia.bortal.model.Poll;
import fi.insomnia.bortal.model.PollAnswer;
import fi.insomnia.bortal.model.PollQuestion;
import fi.insomnia.bortal.model.PossibleAnswer;
@Local
......@@ -18,4 +19,10 @@ public interface PollBeanLocal {
PossibleAnswer findPossibleAnwerById(int id);
void createPoll(Poll poll);
void createAnswers(PollQuestion q1);
}
......@@ -23,7 +23,8 @@ public enum Permission {
ROLE_MANAGEMENT("User has right to view(r), modify(w) and assign(x) roles"),
PRODUCT("View(r), modify(w), and shop(x) products"),
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 static final Logger logger = LoggerFactory.getLogger(Permission.class);
......
......@@ -38,7 +38,7 @@ public abstract class GenericEventChild implements EventChildInterface {
}
@Override
public final boolean equals(Object object) {
public boolean equals(Object object) {
if (!this.getClass().equals(object.getClass())) {
logger.debug("Classes dont match {} {}", getClass(), object.getClass());
......
......@@ -51,8 +51,9 @@ public class Poll extends GenericEventChild implements Serializable {
super();
}
public Poll(LanEvent e) {
public Poll(LanEvent e, String name) {
super(e);
this.name = name;
}
public Calendar getBegin() {
......
......@@ -10,18 +10,21 @@ import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Entity
@Table(name = "poll_answer")
public class PollAnswer extends GenericEventChild implements Serializable {
private static final long serialVersionUID = 1L;
private static final Logger logger = LoggerFactory.getLogger(PollAnswer.class);
@Lob
@Column(name = "answer_text", nullable = true)
private String answerText;
private String answerText = "";
@Column(name = "answer_boolean", nullable = true)
private Boolean answerBoolean;
private Boolean answerBoolean = false;
@ManyToOne
@JoinColumns({
......@@ -33,19 +36,19 @@ public class PollAnswer extends GenericEventChild implements Serializable {
@JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false)
private User user;
public void setAnswerText(String answerText) {
this.answerText = answerText;
}
public PollAnswer() {
super();
}
public PollAnswer(PossibleAnswer a) {
super(new EventPk(a.getId().getId()));
super(a.getId());
this.choice = a;
}
public void setAnswerText(String answerText) {
this.answerText = answerText;
}
public String getAnswerText() {
return answerText;
}
......@@ -73,4 +76,23 @@ public class PollAnswer extends GenericEventChild implements Serializable {
public Boolean getAnswerBoolean() {
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 {
super();
}
public PollQuestion(Poll p) {
public PollQuestion(Poll p, String name) {
super(p.getId());
this.poll = p;
this.question = name;
}
/**
*
*/
private static final long serialVersionUID = 821112669474215823L;
@JoinColumns({
......@@ -41,6 +39,7 @@ public class PollQuestion extends GenericEventChild {
@OneToMany(mappedBy = "question", cascade = CascadeType.ALL)
private List<PossibleAnswer> answers = new ArrayList<PossibleAnswer>();
@Lob
private String question;
@Column(nullable = false)
......@@ -55,7 +54,7 @@ public class PollQuestion extends GenericEventChild {
}
public boolean isFreeText() {
return (answers.size() == 1 && answers.get(0).isText());
return (answers.size() == 1 && answers.get(0).getTextanswer());
}
public void setQuestion(String question) {
......
......@@ -11,11 +11,22 @@ import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Basic;
@Entity
@Table(name = "poll_question")
@Table(name = "possible_answer")
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 {
private String answer;
@Column(nullable = false)
private Integer sort = 100;
@Column(nullable = false)
private boolean text = false;
private boolean textanswer = false;
@Lob
private String description;
@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) })
@ManyToOne
private PollQuestion question;
......@@ -54,14 +67,6 @@ public class PossibleAnswer extends GenericEventChild {
this.sort = sort;
}
public boolean isText() {
return text;
}
public void setText(boolean text) {
this.text = text;
}
public String getDescription() {
return description;
}
......@@ -86,4 +91,12 @@ public class PossibleAnswer extends GenericEventChild {
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;
@ConversionValue(dataValue = "ROLE_MANAGEMENT", objectValue = "ROLE_MANAGEMENT"),
@ConversionValue(dataValue = "PRODUCT", objectValue = "PRODUCT"),
@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 {
......
......@@ -20,6 +20,7 @@ import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;
/**
* A vote for a compo entry
*/
......
......@@ -33,6 +33,8 @@
<br />
<h:commandButton value="Resize all images" action="#{TestDataView.convertImages()}" />
<br />
<h:commandButton value="Generate test poll data" action="#{TestDataView.generatePollData()}" />
<br />
</h:form>
</h:body>
</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 @@
<tools:isLoggedIn>
<div class="link#{i18n[util.concat(thispage,'.pagegroup')] == 'user'?'a':''}"><h:link outcome="/user/editself"
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>
-->
</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
outcome="/place/placemap" value="#{i18n['topmenu.placemap']}" /></div>
......@@ -49,8 +53,8 @@
outcome="/shop/showReaderEvents" value="#{i18n['topmenu.rfidshop']}" /></div>
</tools:canRead> <tools:canRead target="GAME">
<div class="link#{i18n[util.concat(thispage,'.pagegroup')] == 'game'?'a':''}"><h:link
outcome="/game/start" value="#{i18n['topmenu.game']}" /></div>
<div class="link#{i18n[util.concat(thispage,'.pagegroup')] == 'game'?'a':''}"><h:link outcome="/game/start"
value="#{i18n['topmenu.game']}" /></div>
</tools:canRead></div>
</div>
......
......@@ -6,26 +6,24 @@
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:param name="thispage" value="page.poll.start" />
<ui:define name="content">
<h:messages />
<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>
<f:facet name="header">
<h:outputText value="${i18n['poll.name']}" />
</f:facet>
<h:outputText value="#{question.question.question}" />
</h:column>
<h:column>
<h:inputTextarea cols="50" rows="7" value="#{question.textAnswer.answerText}" rendered="#{question.freeText}" />
<h:selectOneRadio converter="#{pollAnswerConverter}" rendered="#{!question.freeText and question.choices eq 1}"
value="#{question.oneSelected}">
<h:inputTextarea id="freecell" cols="50" rows="7" value="#{question.textAnswer.answerText}" rendered="#{question.freeText}" />
<h:selectOneRadio id="selectone" layout="pageDirection" converter="#{pollAnswerConverter}"
rendered="#{!question.freeText and question.question.choices eq 1}" value="#{question.oneSelected}">
<f:selectItems var="ans" itemLabel="#{ans.choice.answer}" value="#{question.answers}" />
</h:selectOneRadio>
</h:column>
</h:dataTable>
<h:commandButton action="#{pollView.savePoll()}" value="#{i18n['poll.save']}" />
</h:form>
</ui:define>
</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;
import javax.faces.bean.SessionScoped;
import javax.faces.model.ListDataModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beans.PollBeanLocal;
import fi.insomnia.bortal.model.Poll;
import fi.insomnia.bortal.model.PollAnswer;
......@@ -28,8 +31,12 @@ public class PollView extends GenericView {
private Integer thisPage = 1;
private static final Logger logger = LoggerFactory.getLogger(PollView.class);
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() {
......@@ -56,9 +63,13 @@ public class PollView extends GenericView {
public String savePoll() {
if (validate(this)) {
pollBean.createAnswers(createAnswers());
}
return "thankYou";
pages = null;
polls = null;
return "/poll/thankYou";
}
public void setPolls(ListDataModel<Poll> polls) {
......@@ -114,8 +125,8 @@ public class PollView extends GenericView {
return answers.get(0);
}
public void setOneSelected(PollAnswer ans) {
if (ans != null) {
for (PollAnswer possibleAns : answers) {
if (possibleAns.getChoice().equals(ans.getChoice())) {
possibleAns.setAnswerBoolean(true);
......@@ -124,6 +135,7 @@ public class PollView extends GenericView {
}
}
}
}
public PollAnswer getOneSelected() {
for (PollAnswer possibleAns : answers) {
......
......@@ -4,6 +4,8 @@
*/
package fi.insomnia.bortal.view;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.ejb.EJB;
......@@ -15,12 +17,18 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.TestDataBeanLocal;
import fi.insomnia.bortal.beans.UserBeanLocal;
import fi.insomnia.bortal.beans.UtilBeanLocal;
import fi.insomnia.bortal.handler.SessionHandler;
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.User;
......@@ -44,6 +52,10 @@ public class TestDataView {
private UtilBeanLocal utilbean;
@EJB
private CardTemplateBeanLocal ctbean;
@EJB
private EventBeanLocal eventbean;
@EJB
private PollBeanLocal pollbean;
public void generateData() {
......@@ -112,4 +124,32 @@ public class TestDataView {
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;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beans.PollBeanLocal;
import fi.insomnia.bortal.beans.ProductBeanLocal;
import fi.insomnia.bortal.model.PollAnswer;
import fi.insomnia.bortal.model.PossibleAnswer;
import fi.insomnia.bortal.model.Product;
@ManagedBean(name = "pollAnswerConverter")
@NoneScoped()
......@@ -19,6 +20,7 @@ public class PollAnswerConverter implements Converter {
@EJB
private PollBeanLocal pollbean;
private static final Logger logger = LoggerFactory.getLogger(PollAnswerConverter.class);
public PollAnswerConverter() {
}
......@@ -28,15 +30,20 @@ public class PollAnswerConverter implements Converter {
PossibleAnswer possibleAnswer = pollbean.findPossibleAnwerById(Integer.parseInt(value));
PollAnswer ret = new PollAnswer();
ret.setChoice(possibleAnswer);
logger.debug("Converting string {} to Poll Answer {}", value, possibleAnswer);
return ret;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
String ret = null;
if (value instanceof PollAnswer) {
ret = ((PollAnswer) value).getChoice().getId().getId().toString();
logger.debug("converting object {} to string {}", ((PollAnswer) value).getChoice().getId(), ret);
}
return ret;
......
......@@ -98,3 +98,7 @@ page.game.start.pagegroup=game
page.game.start.header=Insomnia Game
page.game.list.pagegroup=game
page.game.list.header=Insomnia Game
page.poll.start.pagegroup=poll
page.poll.start.header=Kysely
......@@ -69,6 +69,7 @@ role.edit.save=Tallenna
topmenu.game=Insomnia Game
topmenu.poll=Kysely
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!