19 package org.turro.assistant;
21 import java.util.Date;
22 import java.util.HashSet;
23 import java.util.List;
25 import java.util.function.Consumer;
26 import org.turro.string.Strings;
27 import org.turro.auth.Authentication;
28 import org.turro.elephant.db.ElephantPU;
29 import org.turro.elephant.db.WhereClause;
30 import org.turro.elephant.entities.db.EntityParticipation;
31 import org.turro.elephant.entities.db.EntityParticipationPK;
32 import org.turro.entities.Entities;
33 import org.turro.entities.IElephantEntity;
34 import org.turro.i18n.I_;
35 import org.turro.jpa.Dao;
36 import org.turro.participation.IEntityParticipation;
37 import org.turro.participation.ParticipationReason;
38 import org.turro.plugin.contacts.ContactList;
39 import org.turro.plugin.contacts.IContact;
40 import org.turro.sql.SqlClause;
48 private final String entityPath;
49 private String participatorPath;
52 private Boolean checked;
60 if(!Strings.isBlank(entityPath)) {
61 if(contact !=
null && contact.
isValid()) {
62 participatorPath =
"/contact/" + contact.
getId();
69 this(entityPath, (String)
null, reason);
73 this.entityPath = entityPath;
74 this.participatorPath = participatorPath;
81 wc.
addClause(
"select count(ep) from EntityParticipation ep");
82 wc.
addClause(
"where ep.entityPath = :entityPath");
99 wc.
addClause(
"select ep from EntityParticipation ep");
100 wc.
addClause(
"where ep.entityPath = :entityPath");
107 wc.
addClause(
"and ep.participationDate >= :from");
110 return getDao().getResultList(wc);
119 wc.
addClause(
"select ep from EntityParticipation ep");
120 wc.
addClause(
"where ep.participatorPath = :entityPath");
127 wc.
addClause(
"and ep.participationDate >= :from");
130 return getDao().getResultList(wc);
135 wc.
addClause(
"select ep from EntityParticipation ep");
142 wc.
addClause(
"and ep.participationDate >= :from");
145 return getDao().getResultList(wc);
150 wc.
addClause(
"select ep from EntityParticipation ep");
157 wc.
addClause(
"and ep.participationDate >= :from");
164 if(checked ==
null) {
172 checked = ep !=
null;
179 return !Strings.isBlank(participatorPath);
183 return Strings.isBlank(entityPath) || Strings.isBlank(participatorPath) || reason ==
null;
187 boolean result =
false;
203 getDao().saveObject(ep);
224 getDao().saveObject(ep);
253 return I_.
byKey(reason.toString());
261 list.
add(ep.getContact());
266 private void reset() {
275 wc.
addClause(
"select count(ep) from EntityParticipation ep");
276 wc.
addClause(
"where ep.entityPath like concat('/', :rootPath, '/%')");
278 wc.
addClause(
"and ep.participatorPath = concat('/contact/', :participator)");
285 public static void cleanup(String entityPath) {
286 SqlClause.delete(
"EntityParticipation")
287 .where().equal(
"entityPath", entityPath)
288 .or().equal(
"participatorPath", entityPath)
296 return new HashSet<>(SqlClause.select(
"distinct ep.entityPath").from(
"EntityParticipation ep")
297 .where().startsWith(
"ep.entityPath",
"/" + root +
"/")
299 .resultList(String.class));
306 private Dao getDao() {
List< IEntityParticipation > getParticipations(Date from)
ParticipationInfo(String entityPath, ParticipationReason reason)
IElephantEntity getEntity()
List< IEntityParticipation > getAnyParticipations(Date from)
ContactList getParticipants()
List< IEntityParticipation > getParticipations()
static long getParticipationCount(String root, IContact contact, ParticipationReason reason)
ParticipationInfo(Object entity, ParticipationReason reason)
List< IEntityParticipation > getCrossParticipations(Date from)
void getAnyParticipations(Date from, Consumer< IEntityParticipation > action)
IElephantEntity getParticipator()
ParticipationInfo(Object entity, IContact contact, ParticipationReason reason)
ParticipationInfo(String entityPath, String participatorPath, ParticipationReason reason)
List< IEntityParticipation > getCrossParticipations()
static void cleanup(String entityPath)
static Set< String > getAllPaths(String root)
static IContact getIContact()
void addClause(String clause)
void addNamedValue(String name, Object value)
void setReason(ParticipationReason reason)
void setParticipatorPath(String participatorPath)
void setEntityPath(String entityPath)
void setParticipationDate(Date participationDate)
void setReason(ParticipationReason reason)
void setParticipatorPath(String participatorPath)
void setEntityPath(String entityPath)
static IElephantEntity getController(String path)
static String byKey(String key)
void deleteObject(Object obj)
Object getSingleResult(WhereClause wc)