19 package org.turro.user.activity;
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.EnumSet;
24 import java.util.HashSet;
26 import org.turro.string.Strings;
27 import org.turro.elephant.db.ElephantPU;
28 import org.turro.elephant.db.WhereClause;
29 import org.turro.elephant.entities.db.EntityParticipation;
30 import org.turro.jpa.Dao;
31 import org.turro.participation.ParticipationReason;
32 import org.turro.path.Path;
33 import org.turro.plugin.contacts.IContact;
55 Set<Activity>
set =
new HashSet<>();
56 set.addAll(getParticipations(contact, from, types));
60 private Set<Activity> getParticipations(
IContact contact, Date from, Set<ActivityType> types) {
68 if(types.contains(ActivityType.ACTIVITY_SEEN)) reasons.add(ParticipationReason.REASON_SEEN);
69 if(types.contains(ActivityType.ACTIVITY_SPAM)) reasons.add(ParticipationReason.REASON_SPAM);
70 if(types.contains(ActivityType.ACTIVITY_LIKE)) reasons.add(ParticipationReason.REASON_LIKE);
71 WhereClause wc =
new WhereClause();
72 wc.addClause(
"select ep from EntityParticipation ep");
73 wc.addIn(
"where",
"ep.reason",
new ArrayList(reasons));
75 wc.addClause(
"and ep.participationDate >= :date");
76 wc.addNamedValue(
"date", from);
79 wc.addClause(
"and (");
80 wc.addClause(
"ep.participatorPath = :participator");
83 wc.addNamedValue(
"participator",
"/contact/" + contact.
getId());
86 wc.addClause(
"order by ep.participationDate desc");
87 Set<Activity>
set =
new HashSet<>();
88 for(EntityParticipation ep :
getDao().getResultList(EntityParticipation.class, wc, 100)) {
89 if(!Strings.isBlank(ep.getEntity().getName()) && !Strings.isBlank(ep.getEntity().getImage())) {
90 Activity activity = convertToActivity(types, ep);
91 if(activity !=
null && !Strings.isBlank(activity.getEntity().getName()))
set.add(activity);
97 private Activity convertToActivity(Set<ActivityType> types, EntityParticipation ep) {
98 switch (ep.getReason()) {
100 return new Activity(ep.getParticipationDate(), ActivityType.ACTIVITY_FOLLOW, Path.getIdentifier(ep.getParticipatorPath()), ep.getEntityPath(), ep);
101 case REASON_PARTICIPATE:
102 return new Activity(ep.getParticipationDate(), ActivityType.ACTIVITY_PARTICIPATE, Path.getIdentifier(ep.getParticipatorPath()), ep.getEntityPath(), ep);
104 return new Activity(ep.getParticipationDate(), ActivityType.ACTIVITY_SEEN, Path.getIdentifier(ep.getParticipatorPath()), ep.getEntityPath(), ep);
106 return new Activity(ep.getParticipationDate(), ActivityType.ACTIVITY_SPAM, Path.getIdentifier(ep.getParticipatorPath()), ep.getEntityPath(), ep);
108 return new Activity(ep.getParticipationDate(), ActivityType.ACTIVITY_LIKE, Path.getIdentifier(ep.getParticipatorPath()), ep.getEntityPath(), ep);
Set< Activity > getActivity(IContact contact, Date from, Set< ActivityType > types)
Set< ActivityType > getAllowed()