19 package org.turro.voteit;
21 import java.util.Collection;
22 import java.util.Date;
23 import java.util.List;
24 import org.amic.util.date.CheckDate;
25 import org.turro.string.Strings;
26 import org.turro.contacts.Contact;
27 import org.turro.contacts.VoteIt;
28 import org.turro.contacts.db.ContactsPU;
29 import org.turro.entities.Entities;
30 import org.turro.jpa.Dao;
31 import org.turro.log.SystemLogType;
32 import org.turro.log.SystemLogger;
33 import org.turro.plugin.contacts.IContact;
49 if(!Strings.isBlank(path) && contact !=
null && contact.
isValid()) {
52 " select count(*) from VoteIt " +
55 new Object[] { path, contact.getContact() }
62 dao.saveObject(voteIt);
78 if(!Strings.isBlank(path) && contact !=
null && contact.
isValid()) {
81 " delete from VoteIt " +
98 if(!Strings.isBlank(path) && contact !=
null && contact.
isValid()) {
105 new Object[] { newVote, path, contact.
getContact() }
112 return info(entity,
null, contact);
118 return info(path, allowed, contact);
124 return info(path,
null, contact);
131 " select count(vote) from VoteIt " +
132 " where path = ? and vote > 0 " +
134 new Object[] { path }
137 " select count(vote) from VoteIt " +
138 " where path = ? and vote = 0 " +
140 new Object[] { path }
143 " select count(vote) from VoteIt " +
144 " where path = ? and vote < 0 " +
146 new Object[] { path }
148 if(contact !=
null) {
156 if(!Strings.isBlank(path) && contact !=
null && contact.
isValid()) {
158 " select vi from VoteIt as vi " +
159 " where path = ? and creator = ?",
163 return new MyVote(contact, vi.getVote());
170 if(!Strings.isBlank(path) && contact !=
null && contact.
isValid()) {
172 " select vi from VoteIt as vi " +
173 " where path = ? and creator = ?",
177 return new MyVote(contact, vi.getVote());
185 return dao.getResultList(
186 " select vi from VoteIt as vi " +
187 " where vi.path = ?",
188 new Object[] { path }
193 if(allowed ==
null) {
196 if(Strings.isBlank(allowed)) {
197 return " and 1 = 2 ";
199 return " and creator.id in (" + allowed +
")";
204 public static Collection<String>
paths(String path,
int fromDays) {
206 return dao.getResultList(
207 " select g.path from VoteIt g " +
208 " where g.path like ? " +
209 " and g.dateCreation >= ?",
210 new Object[] { path +
"/%",
new CheckDate().addDays(-fromDays).getDate() }
static IElephantEntity getController(String path)
int executeUpdate(String query)
Object getSingleResult(WhereClause wc)
Object getSingleResultOrNull(SqlClause sc)
static ISystemLogger getInstance()
void setNocare(long nocare)
void setMyVote(MyVote myVote)
void setNegative(long negative)
void setPositive(long positive)
static List< VoteIt > allVotes(String path)
static String getAllowedString(String allowed)
static void removeVote(String path, IContact contact)
static void addVote(String path, int vote, IContact contact)
static VoteItInfo info(String path, String allowed, IContact contact)
static MyVote myVote(Dao dao, String path, IContact contact)
static VoteItInfo info(String path, IContact contact)
static Collection< String > paths(String path, int fromDays)
static void changeVote(String path, int newVote, IContact contact)
static MyVote myVote(String path, IContact contact)
static void changeVote(Object entity, int newVote, IContact contact)
static VoteItInfo info(Object entity, String allowed, IContact contact)
static VoteItInfo info(Object entity, IContact contact)
static void removeVote(Object entity, IContact contact)
static void addVote(Object entity, int vote, IContact contact)
void doLog(SystemLogType type, Object entity, String comment, Serializable data)