BrightSide Workbench Full Report + Source Code
org.turro.voteit.VoteItUtil Class Reference

Static Public Member Functions

static void addVote (Object entity, int vote, IContact contact)
 
static void addVote (String path, int vote, IContact contact)
 
static void removeVote (Object entity, IContact contact)
 
static void removeVote (String path, IContact contact)
 
static void changeVote (Object entity, int newVote, IContact contact)
 
static void changeVote (String path, int newVote, IContact contact)
 
static VoteItInfo info (Object entity, IContact contact)
 
static VoteItInfo info (Object entity, String allowed, IContact contact)
 
static VoteItInfo info (String path, IContact contact)
 
static VoteItInfo info (String path, String allowed, IContact contact)
 
static MyVote myVote (String path, IContact contact)
 
static MyVote myVote (Dao dao, String path, IContact contact)
 
static List< VoteItallVotes (String path)
 
static String getAllowedString (String allowed)
 
static Collection< String > paths (String path, int fromDays)
 

Detailed Description

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

Definition at line 39 of file VoteItUtil.java.

Member Function Documentation

◆ addVote() [1/2]

static void org.turro.voteit.VoteItUtil.addVote ( Object  entity,
int  vote,
IContact  contact 
)
static

Definition at line 41 of file VoteItUtil.java.

41  {
42  String path = Entities.getController(entity).getPath();
43  if(path != null) {
44  addVote(path, vote, contact);
45  }
46  }
static void addVote(Object entity, int vote, IContact contact)
Definition: VoteItUtil.java:41
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addVote() [2/2]

static void org.turro.voteit.VoteItUtil.addVote ( String  path,
int  vote,
IContact  contact 
)
static

Definition at line 48 of file VoteItUtil.java.

48  {
49  if(!Strings.isBlank(path) && contact != null && contact.isValid()) {
50  Dao dao = new ContactsPU();
51  if(((Long) dao.getSingleResult(
52  " select count(*) from VoteIt " +
53  " where path = ? " +
54  " and creator = ?",
55  new Object[] { path, contact.getContact() }
56  )) == 0) {
57  VoteIt voteIt = new VoteIt();
58  voteIt.setCreator((Contact) contact.getContact());
59  voteIt.setDateCreation(new Date());
60  voteIt.setVote(vote);
61  voteIt.setPath(path);
62  dao.saveObject(voteIt);
63  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, contact, path, "vote-it", vote + "");
64  } else {
65  changeVote(path, vote, contact);
66  }
67  }
68  }
static void changeVote(Object entity, int newVote, IContact contact)
Definition: VoteItUtil.java:90
Here is the call graph for this function:

◆ allVotes()

static List<VoteIt> org.turro.voteit.VoteItUtil.allVotes ( String  path)
static

Definition at line 183 of file VoteItUtil.java.

183  {
184  Dao dao = new ContactsPU();
185  return dao.getResultList(
186  " select vi from VoteIt as vi " +
187  " where vi.path = ?",
188  new Object[] { path }
189  );
190  }
Here is the caller graph for this function:

◆ changeVote() [1/2]

static void org.turro.voteit.VoteItUtil.changeVote ( Object  entity,
int  newVote,
IContact  contact 
)
static

Definition at line 90 of file VoteItUtil.java.

90  {
91  String path = Entities.getController(entity).getPath();
92  if(path != null) {
93  changeVote(path, newVote, contact);
94  }
95  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ changeVote() [2/2]

static void org.turro.voteit.VoteItUtil.changeVote ( String  path,
int  newVote,
IContact  contact 
)
static

Definition at line 97 of file VoteItUtil.java.

97  {
98  if(!Strings.isBlank(path) && contact != null && contact.isValid()) {
99  Dao dao = new ContactsPU();
100  dao.executeUpdate(
101  " update VoteIt " +
102  " set vote = ? " +
103  " where path = ? " +
104  " and creator = ?",
105  new Object[] { newVote, path, contact.getContact() }
106  );
107  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, contact, path, "vote-it", newVote + "");
108  }
109  }
Here is the call graph for this function:

◆ getAllowedString()

static String org.turro.voteit.VoteItUtil.getAllowedString ( String  allowed)
static

Definition at line 192 of file VoteItUtil.java.

192  {
193  if(allowed == null) {
194  return "";
195  } else {
196  if(Strings.isBlank(allowed)) {
197  return " and 1 = 2 ";
198  } else {
199  return " and creator.id in (" + allowed + ")";
200  }
201  }
202  }
Here is the caller graph for this function:

◆ info() [1/4]

static VoteItInfo org.turro.voteit.VoteItUtil.info ( Object  entity,
IContact  contact 
)
static

Definition at line 111 of file VoteItUtil.java.

111  {
112  return info(entity, null, contact);
113  }
static VoteItInfo info(Object entity, IContact contact)
Here is the caller graph for this function:

◆ info() [2/4]

static VoteItInfo org.turro.voteit.VoteItUtil.info ( Object  entity,
String  allowed,
IContact  contact 
)
static

Definition at line 115 of file VoteItUtil.java.

115  {
116  String path = Entities.getController(entity).getPath();
117  if(path != null) {
118  return info(path, allowed, contact);
119  }
120  return null;
121  }
Here is the call graph for this function:

◆ info() [3/4]

static VoteItInfo org.turro.voteit.VoteItUtil.info ( String  path,
IContact  contact 
)
static

Definition at line 123 of file VoteItUtil.java.

123  {
124  return info(path, null, contact);
125  }
Here is the call graph for this function:

◆ info() [4/4]

static VoteItInfo org.turro.voteit.VoteItUtil.info ( String  path,
String  allowed,
IContact  contact 
)
static

Definition at line 127 of file VoteItUtil.java.

127  {
128  VoteItInfo vi = new VoteItInfo();
129  Dao dao = new ContactsPU();
130  vi.setPositive((Long) dao.getSingleResult(
131  " select count(vote) from VoteIt " +
132  " where path = ? and vote > 0 " +
133  getAllowedString(allowed),
134  new Object[] { path }
135  ));
136  vi.setNocare((Long) dao.getSingleResult(
137  " select count(vote) from VoteIt " +
138  " where path = ? and vote = 0 " +
139  getAllowedString(allowed),
140  new Object[] { path }
141  ));
142  vi.setNegative((Long) dao.getSingleResult(
143  " select count(vote) from VoteIt " +
144  " where path = ? and vote < 0 " +
145  getAllowedString(allowed),
146  new Object[] { path }
147  ));
148  if(contact != null) {
149  vi.setMyVote(myVote(dao, path, contact));
150  }
151  return vi;
152  }
static String getAllowedString(String allowed)
static MyVote myVote(String path, IContact contact)
Here is the call graph for this function:

◆ myVote() [1/2]

static MyVote org.turro.voteit.VoteItUtil.myVote ( Dao  dao,
String  path,
IContact  contact 
)
static

Definition at line 169 of file VoteItUtil.java.

169  {
170  if(!Strings.isBlank(path) && contact != null && contact.isValid()) {
171  VoteIt vi = (VoteIt) dao.getSingleResultOrNull(
172  " select vi from VoteIt as vi " +
173  " where path = ? and creator = ?",
174  new Object[] { path, contact.getContact() }
175  );
176  if(vi != null) {
177  return new MyVote(contact, vi.getVote());
178  }
179  }
180  return null;
181  }
Here is the call graph for this function:

◆ myVote() [2/2]

static MyVote org.turro.voteit.VoteItUtil.myVote ( String  path,
IContact  contact 
)
static

Definition at line 154 of file VoteItUtil.java.

154  {
155  Dao dao = new ContactsPU();
156  if(!Strings.isBlank(path) && contact != null && contact.isValid()) {
157  VoteIt vi = (VoteIt) dao.getSingleResultOrNull(
158  " select vi from VoteIt as vi " +
159  " where path = ? and creator = ?",
160  new Object[] { path, contact.getContact() }
161  );
162  if(vi != null) {
163  return new MyVote(contact, vi.getVote());
164  }
165  }
166  return null;
167  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ paths()

static Collection<String> org.turro.voteit.VoteItUtil.paths ( String  path,
int  fromDays 
)
static

Definition at line 204 of file VoteItUtil.java.

204  {
205  Dao dao = new ContactsPU();
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() }
211  );
212  }

◆ removeVote() [1/2]

static void org.turro.voteit.VoteItUtil.removeVote ( Object  entity,
IContact  contact 
)
static

Definition at line 70 of file VoteItUtil.java.

70  {
71  String path = Entities.getController(entity).getPath();
72  if(path != null) {
73  removeVote(path, contact);
74  }
75  }
static void removeVote(Object entity, IContact contact)
Definition: VoteItUtil.java:70
Here is the call graph for this function:

◆ removeVote() [2/2]

static void org.turro.voteit.VoteItUtil.removeVote ( String  path,
IContact  contact 
)
static

Definition at line 77 of file VoteItUtil.java.

77  {
78  if(!Strings.isBlank(path) && contact != null && contact.isValid()) {
79  Dao dao = new ContactsPU();
80  dao.executeUpdate(
81  " delete from VoteIt " +
82  " where path = ? " +
83  " and creator = ?",
84  new Object[] { path, contact.getContact() }
85  );
86  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, contact, path, "vote-it", "deleted");
87  }
88  }
Here is the call graph for this function:

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