BrightSide Workbench Full Report + Source Code
PollOption.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.elephant.entities.db;
20 
21 import java.util.List;
22 import javax.persistence.Entity;
23 import javax.persistence.Id;
24 import javax.persistence.IdClass;
25 import org.turro.string.Strings;
26 import org.turro.elephant.db.ElephantPU;
27 import org.turro.elephant.db.WhereClause;
28 import org.turro.plugin.contacts.IContact;
29 
34 @Entity
35 @IdClass(PollOptionPK.class)
36 public class PollOption implements java.io.Serializable {
37 
38  @Id
39  private Long idPoll;
40 
41  @Id
42  private String pollData;
43 
44  private String description;
45 
46  private int ordering;
47 
48  private boolean actionButton;
49 
50  public Long getIdPoll() {
51  return idPoll;
52  }
53 
54  public void setIdPoll(Long idPoll) {
55  this.idPoll = idPoll;
56  }
57 
58  public String getPollData() {
59  return pollData;
60  }
61 
62  public void setPollData(String pollData) {
63  this.pollData = pollData;
64  }
65 
66  public String getDescription() {
67  return description;
68  }
69 
70  public void setDescription(String description) {
71  this.description = description;
72  }
73 
74  public int getOrdering() {
75  return ordering;
76  }
77 
78  public void setOrdering(int ordering) {
79  this.ordering = ordering;
80  }
81 
82  public boolean isActionButton() {
83  return actionButton;
84  }
85 
86  public void setActionButton(boolean actionButton) {
87  this.actionButton = actionButton;
88  }
89 
90  /* Helpers */
91 
92  public boolean isEmpty() {
93  return Strings.isBlank(pollData);
94  }
95 
96  public Poll getPoll() {
97  return new ElephantPU().find(Poll.class, this.getIdPoll());
98  }
99 
100  public List<PollVote> getVotes() {
101  WhereClause wc = new WhereClause();
102  wc.addClause("select vote from PollVote vote");
103  wc.addClause("where vote.idPoll = :idPoll");
104  wc.addNamedValue("idPoll", this.getIdPoll());
105  wc.addClause("and vote.pollData = :pollData");
106  wc.addNamedValue("pollData", this.getPollData());
107  return new ElephantPU().getResultList(wc);
108  }
109 
110  /* Participants */
111 
112  public PollVote getPollVote(IContact contact) {
113  PollVotePK pv = new PollVotePK();
114  pv.setIdPoll(getIdPoll());
115  pv.setPollData(getPollData());
116  pv.setIdContact(contact.getId());
117  return new ElephantPU().find(PollVote.class, pv);
118  }
119 
120 }
void addNamedValue(String name, Object value)
void setActionButton(boolean actionButton)
Definition: PollOption.java:86
void setDescription(String description)
Definition: PollOption.java:70
PollVote getPollVote(IContact contact)