19 package org.turro.activity;
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.HashSet;
24 import java.util.List;
26 import java.util.stream.Collectors;
27 import org.turro.assistant.AssistantConstants;
28 import org.turro.assistant.AssistantSet;
29 import org.turro.assistant.Assistants;
30 import org.turro.elephant.db.ElephantPU;
31 import org.turro.elephant.entities.db.Activity;
32 import org.turro.elephant.entities.db.ActivityAssistant;
33 import org.turro.jpa.Dao;
34 import org.turro.reflection.Instances;
35 import org.turro.sql.SqlClause;
36 import org.turro.string.Strings;
37 import org.turro.util.Cached;
45 public Activity add(Date activityDate, String activityPath, String entityPath, String sortPath) {
46 if(Strings.anyBlank(entityPath, activityPath, sortPath))
return null;
53 entityPaths.add(entityPath);
54 return dao.get().saveObject(activity);
58 return SqlClause.select(
"max(a.activityDate)").from(
"Activity a")
59 .where().equal(
"reason", reason)
61 .singleResult(Date.class, defaultDate);
76 private static final Set<String> entityPaths =
new HashSet<>();
84 for(String entityPath : entityPaths) {
85 updateEntityPath(dao, entityPath);
90 private static void updateEntityPath(
Dao dao, String entityPath) {
91 SqlClause.delete(
"ActivityAssistant")
92 .where().equal(
"entityPath", entityPath)
95 List<ActivityAssistant> assistants =
new ArrayList<>();
108 return participants.stream().map(a -> a.contact.getId()).collect(Collectors.toSet());
113 private final Cached<Dao> dao = Cached.instance(() ->
new ElephantPU());
121 private final String reason;
122 private static final Date defaultDate =
new Date(0L);
125 this.reason = reason;
static void resetEntityPaths()
static Set< String > getParticipants(String entityPath)
static Activities of(String reason)
Activity add(Date activityDate, String activityPath, String entityPath, String sortPath)
static void addParticipants()
Activities(String reason)
static void addAssistants(String role, AssistantSet list, Object data)
void setEntityPath(String entityPath)
void setContactId(String contactId)
void setReason(String reason)
void setActivityDate(Date activityDate)
void setSortPath(String sortPath)
void setActivityPath(String activityPath)
void setEntityPath(String entityPath)
void saveCollection(Collection objs)