BrightSide Workbench Full Report + Source Code
org.turro.polls.PollsUtil Class Reference

Public Member Functions

 PollsUtil (IContact contact)
 
 PollsUtil (String idContact)
 
IContact getContact ()
 
boolean vote (Long pollId, String pollData, Integer vote)
 
synchronized boolean vote (PollOption pollOption, Integer vote)
 
boolean isAllowedToVote (PollOption pollOption)
 
PollOption getPollOption (Long pollId, String pollData)
 
PollVote getPollVote (PollOption pollOption)
 
PollVote getPollVote (PollOption pollOption, IContact contact)
 
long getPollOptionCount (PollOption pollOption, int vote)
 

Static Public Member Functions

static List< PollgetPolls (String entityPath)
 
static Poll savePoll (Poll poll, List< PollOption > pos)
 
static void removePoll (Poll poll)
 
static void removeOption (PollOption po)
 
static Set< PollgetMyPolls (IContact contact)
 
static Set< PollgetPolls (IContact contact, boolean active, boolean restricted, int maxResults)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 40 of file PollsUtil.java.

Constructor & Destructor Documentation

◆ PollsUtil() [1/2]

org.turro.polls.PollsUtil.PollsUtil ( IContact  contact)

Definition at line 44 of file PollsUtil.java.

44  {
45  this.contact = contact;
46  }

◆ PollsUtil() [2/2]

org.turro.polls.PollsUtil.PollsUtil ( String  idContact)

Definition at line 48 of file PollsUtil.java.

48  {
49  this.contact = Contacts.getContactById(idContact);
50  }
Here is the call graph for this function:

Member Function Documentation

◆ getContact()

IContact org.turro.polls.PollsUtil.getContact ( )

Definition at line 52 of file PollsUtil.java.

52  {
53  return contact;
54  }

◆ getMyPolls()

static Set<Poll> org.turro.polls.PollsUtil.getMyPolls ( IContact  contact)
static

Definition at line 211 of file PollsUtil.java.

211  {
212  return getPolls(contact, false, true, 0);
213  }
static List< Poll > getPolls(String entityPath)
Definition: PollsUtil.java:148
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPollOption()

PollOption org.turro.polls.PollsUtil.getPollOption ( Long  pollId,
String  pollData 
)

Definition at line 117 of file PollsUtil.java.

117  {
118  PollOptionPK pk = new PollOptionPK();
119  pk.setIdPoll(pollId);
120  pk.setPollData(pollData);
121  return getDao().find(PollOption.class, pk);
122  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPollOptionCount()

long org.turro.polls.PollsUtil.getPollOptionCount ( PollOption  pollOption,
int  vote 
)

Definition at line 136 of file PollsUtil.java.

136  {
137  WhereClause wc = new WhereClause();
138  wc.addClause("select count(vote) from PollVote vote");
139  wc.addClause("where vote.idPoll = :idPoll");
140  wc.addNamedValue("idPoll", pollOption.getIdPoll());
141  wc.addClause("and vote.pollData = :pollData");
142  wc.addNamedValue("pollData", pollOption.getPollData());
143  wc.addClause("and vote.vote = :vote");
144  wc.addNamedValue("vote", vote);
145  return (long) getDao().getSingleResultOrNull(wc);
146  }
Object getSingleResultOrNull(SqlClause sc)
Definition: Dao.java:419
boolean vote(Long pollId, String pollData, Integer vote)
Definition: PollsUtil.java:56
Here is the call graph for this function:

◆ getPolls() [1/2]

static Set<Poll> org.turro.polls.PollsUtil.getPolls ( IContact  contact,
boolean  active,
boolean  restricted,
int  maxResults 
)
static

Definition at line 215 of file PollsUtil.java.

215  {
216  Dao dao = new ElephantPU();
217  TreeSet<Poll> polls = new TreeSet<>();
218  if(!active) {
219  WhereClause wc = new WhereClause();
220  wc.addClause("select distinct poll from Poll poll");
221  if(restricted) {
222  wc.addClause("join PollVote vote on vote.idPoll = poll.id");
223  wc.addClause("where vote.idContact = :contact");
224  wc.addNamedValue("contact", contact.getId());
225  }
226  wc.addClause("order by poll.deadline desc");
227  polls.addAll(dao.getResultList(wc, maxResults));
228  }
229  WhereClause wc = new WhereClause();
230  wc.addClause("select poll from Poll poll");
231  wc.addClause("where poll.deadline >= current_date");
232  if(restricted) {
233  for(Poll poll : (List<Poll>) dao.getResultList(wc)) {
234  if(poll.isParticipant(contact)) {
235  polls.add(poll);
236  }
237  }
238  }
239  return polls;
240  }
Here is the call graph for this function:

◆ getPolls() [2/2]

static List<Poll> org.turro.polls.PollsUtil.getPolls ( String  entityPath)
static

Definition at line 148 of file PollsUtil.java.

148  {
149  Dao dao = new ElephantPU();
150  WhereClause wc = new WhereClause();
151  wc.addClause("select poll from Poll as poll");
152  wc.addClause("where poll.entityPath = :path");
153  wc.addNamedValue("path", entityPath);
154  return dao.getResultList(wc);
155  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPollVote() [1/2]

PollVote org.turro.polls.PollsUtil.getPollVote ( PollOption  pollOption)

Definition at line 124 of file PollsUtil.java.

124  {
125  return getPollVote(pollOption, contact);
126  }
PollVote getPollVote(PollOption pollOption)
Definition: PollsUtil.java:124
Here is the caller graph for this function:

◆ getPollVote() [2/2]

PollVote org.turro.polls.PollsUtil.getPollVote ( PollOption  pollOption,
IContact  contact 
)

Definition at line 128 of file PollsUtil.java.

128  {
129  PollVotePK pk = new PollVotePK();
130  pk.setIdPoll(pollOption.getIdPoll());
131  pk.setPollData(pollOption.getPollData());
132  pk.setIdContact(contact.getId());
133  return getDao().find(PollVote.class, pk, null);
134  }
Here is the call graph for this function:

◆ isAllowedToVote()

boolean org.turro.polls.PollsUtil.isAllowedToVote ( PollOption  pollOption)

Definition at line 86 of file PollsUtil.java.

86  {
87  if(pollOption != null) {
88  return getPollVote(pollOption) != null || canVote(pollOption);
89  }
90  return false;
91  }
Here is the call graph for this function:

◆ removeOption()

static void org.turro.polls.PollsUtil.removeOption ( PollOption  po)
static

Definition at line 190 of file PollsUtil.java.

190  {
191  if(po == null) return;
192  Dao dao = new ElephantPU();
193  WhereClause wc = new WhereClause();
194  wc.addClause("delete from PollOption");
195  wc.addClause("where idPoll = :idPoll");
196  wc.addNamedValue("idPoll", po.getIdPoll());
197  wc.addClause("and pollData = :pollData");
198  wc.addNamedValue("pollData", po.getPollData());
199  dao.executeUpdate(wc);
200  wc = new WhereClause();
201  wc.addClause("delete from PollVote");
202  wc.addClause("where idPoll = :idPoll");
203  wc.addNamedValue("idPoll", po.getIdPoll());
204  wc.addClause("and pollData = :pollData");
205  wc.addNamedValue("pollData", po.getPollData());
206  dao.executeUpdate(wc);
207  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ removePoll()

static void org.turro.polls.PollsUtil.removePoll ( Poll  poll)
static

Definition at line 170 of file PollsUtil.java.

170  {
171  if(poll == null) return;
172  Dao dao = new ElephantPU();
173  WhereClause wc = new WhereClause();
174  wc.addClause("delete from Poll");
175  wc.addClause("where id = :idPoll");
176  wc.addNamedValue("idPoll", poll.getId());
177  dao.executeUpdate(wc);
178  wc = new WhereClause();
179  wc.addClause("delete from PollOption");
180  wc.addClause("where idPoll = :idPoll");
181  wc.addNamedValue("idPoll", poll.getId());
182  dao.executeUpdate(wc);
183  wc = new WhereClause();
184  wc.addClause("delete from PollVote");
185  wc.addClause("where idPoll = :idPoll");
186  wc.addNamedValue("idPoll", poll.getId());
187  dao.executeUpdate(wc);
188  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ savePoll()

static Poll org.turro.polls.PollsUtil.savePoll ( Poll  poll,
List< PollOption pos 
)
static

Definition at line 157 of file PollsUtil.java.

157  {
158  Dao dao = new ElephantPU();
159  if(!poll.isEmpty()) {
160  poll = dao.saveObject(poll);
161  for(PollOption po : pos) {
162  if(!po.isEmpty()) {
163  dao.saveObject(po);
164  }
165  }
166  }
167  return poll;
168  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vote() [1/2]

boolean org.turro.polls.PollsUtil.vote ( Long  pollId,
String  pollData,
Integer  vote 
)

Definition at line 56 of file PollsUtil.java.

56  {
57  return vote(getPollOption(pollId, pollData), vote);
58  }
PollOption getPollOption(Long pollId, String pollData)
Definition: PollsUtil.java:117
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vote() [2/2]

synchronized boolean org.turro.polls.PollsUtil.vote ( PollOption  pollOption,
Integer  vote 
)

Definition at line 60 of file PollsUtil.java.

60  {
61  if(pollOption != null) {
62  PollVote pollVote = getPollVote(pollOption);
63  if(pollVote != null && pollVote.getVote() == vote) {
64  // Only 0/1, delete 0
65  getDao().deleteObject(pollVote);
66  return true;
67  }
68  if(pollVote == null) {
69  if(canVote(pollOption)) {
70  pollVote = new PollVote();
71  pollVote.setIdContact(contact.getId());
72  pollVote.setIdPoll(pollOption.getIdPoll());
73  pollVote.setPollData(pollOption.getPollData());
74  }
75  }
76  if(pollVote != null) {
77  pollVote.setVoteDate(new Date());
78  pollVote.setVote(vote);
79  getDao().saveObject(pollVote);
80  return true;
81  }
82  }
83  return false;
84  }
void deleteObject(Object obj)
Definition: Dao.java:162
Here is the call graph for this function:

The documentation for this class was generated from the following file: