19 package org.turro.elephant.entities.db;
21 import java.util.Date;
22 import java.util.List;
23 import java.util.Objects;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.GenerationType;
28 import javax.persistence.Id;
29 import javax.persistence.Lob;
30 import javax.persistence.Temporal;
31 import org.turro.string.Strings;
32 import org.turro.assistant.AssistantConstants;
33 import org.turro.assistant.AssistantSet;
34 import org.turro.assistant.Assistants;
35 import org.turro.auth.Authentication;
36 import org.turro.elephant.context.Application;
37 import org.turro.elephant.context.ElephantContext;
38 import org.turro.elephant.db.ElephantPU;
39 import org.turro.elephant.db.WhereClause;
40 import org.turro.elephant.impl.util.Parser;
41 import org.turro.entities.Entities;
42 import org.turro.entities.IElephantEntity;
43 import org.turro.jpa.entity.IDaoEntity;
44 import org.turro.parser.wiki.WikiCompiler;
45 import org.turro.plugin.contacts.IContact;
46 import org.turro.util.CompareUtil;
53 public class Poll implements java.io.Serializable,
IDaoEntity, Comparable<Poll> {
56 @GeneratedValue(strategy=GenerationType.IDENTITY)
57 @Column(name=
"IDENTIFIER")
60 private String title, location, entityPath;
62 @Temporal(javax.persistence.TemporalType.TIMESTAMP)
63 private Date deadline;
67 private String wiki, text;
69 private int maxPerOption, maxVotedOptions;
71 private boolean showParticipants, showVotes, allowInsertions, allowNegatives;
73 private String optionClass, optionStart, optionEnd;
96 this.location = location;
104 this.entityPath = entityPath;
112 this.deadline = deadline;
137 this.maxPerOption = maxPerOption;
141 return maxVotedOptions;
145 this.maxVotedOptions = maxVotedOptions;
149 return showParticipants;
153 this.showParticipants = showParticipants;
161 this.showVotes = showVotes;
165 return allowInsertions;
169 this.allowInsertions = allowInsertions;
173 return allowNegatives;
177 this.allowNegatives = allowNegatives;
185 this.optionClass = optionClass;
193 this.optionStart = optionStart;
201 this.optionEnd = optionEnd;
213 return Strings.isBlank(title) || deadline ==
null;
219 return !
isEmpty() && deadline.after(
new Date());
228 wc.
addClause(
"select opt from PollOption opt");
229 wc.
addClause(
"where opt.idPoll = :idPoll");
231 wc.
addClause(
"order by opt.ordering, opt.pollData");
237 wc.
addClause(
"select vote from PollVote vote");
238 wc.
addClause(
"where vote.idPoll = :idPoll");
240 wc.
addClause(
"order by vote.idPoll, vote.pollData");
246 wc.
addClause(
"select vote from PollVote vote");
247 wc.
addClause(
"where vote.idPoll = :idPoll");
249 wc.
addClause(
"and vote.idContact = :contact");
251 wc.
addClause(
"order by vote.idPoll, vote.pollData");
260 if(assistantSet ==
null) {
281 if(po.getPollVote(contact) ==
null) {
293 hash = 17 * hash + Objects.hashCode(this.
id);
305 if (getClass() != obj.getClass()) {
309 if (!Objects.equals(
this.id, other.id)) {
317 int result = CompareUtil.compare(o.deadline, deadline);
319 CompareUtil.compare(o.id,
id);
boolean exists(IContact contact)
static void addAssistants(String role, AssistantSet list, Object data)
static IContact getIContact()
static String getSiteName()
void addClause(String clause)
void addNamedValue(String name, Object value)
boolean isAllowNegatives()
void setText(String text)
AssistantSet getParticipants()
void setTitle(String title)
IElephantEntity getEntity()
void setMaxPerOption(int maxPerOption)
boolean equals(Object obj)
boolean isFullyVoted(IContact contact)
void setOptionStart(String optionStart)
List< PollVote > getVotes(IContact contact)
void setAllowNegatives(boolean allowNegatives)
void setMaxVotedOptions(int maxVotedOptions)
boolean isAllowInsertions()
List< PollOption > getOptions()
void setShowParticipants(boolean showParticipants)
boolean isShowParticipants()
void setEntityPath(String entityPath)
void setWiki(String wiki)
void setLocation(String location)
void setShowVotes(boolean showVotes)
void setOptionClass(String optionClass)
List< PollVote > getVotes()
void setOptionEnd(String optionEnd)
void setDeadline(Date deadline)
boolean isParticipant(IContact contact)
void setAllowInsertions(boolean allowInsertions)
static IElephantEntity getController(String path)