BrightSide Workbench Full Report + Source Code
DossierUserActivity.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.user.activity;
20 
21 import java.util.Date;
22 import java.util.EnumSet;
23 import java.util.HashSet;
24 import java.util.Set;
25 import org.turro.dossier.db.DossierPU;
26 import org.turro.dossier.entity.Participant;
27 import org.turro.elephant.db.WhereClause;
28 import org.turro.jpa.Dao;
29 import org.turro.plugin.contacts.IContact;
30 
35 @UserActivity
37 
38  @Override
39  protected Dao createDao() {
40  return new DossierPU();
41  }
42 
43  @Override
44  protected Set<ActivityType> getAllowed() {
46  }
47 
48  @Override
49  protected Set<Activity> getActivity(IContact contact, Date from, Set<ActivityType> types) {
50  Set<Activity> set = new HashSet<>();
51  if(types.contains(ActivityType.ACTIVITY_PARTICIPATE)) {
52  set.addAll(getParticipations(contact, from, types));
53  }
54  return set;
55  }
56 
57  private Set<Activity> getParticipations(IContact contact, Date from, Set<ActivityType> types) {
58  WhereClause wc = new WhereClause();
59  wc.addClause("select p from Participant p");
60  wc.addClause("where 1=1");
61  if(from != null) {
62  wc.addClause("and p.creation >= :date");
63  wc.addNamedValue("date", from);
64  }
65  if(contact != null) {
66  wc.addClause("and p.idContact = :participator");
67  wc.addNamedValue("participator", contact.getId());
68  }
69  wc.addClause("order by p.creation desc");
70  Set<Activity> set = new HashSet<>();
71  for(Participant p : getDao().getResultList(Participant.class, wc, 100)) {
72  Activity activity = convertToActivity(types, p);
73  if(activity != null) set.add(activity);
74  }
75  return set;
76  }
77 
78  private Activity convertToActivity(Set<ActivityType> types, Participant p) {
79  return new Activity(p.getCreation(), ActivityType.ACTIVITY_PARTICIPATE, p.getIdContact(),
80  DossierPU.getObjectPath(p.getDossier()), p);
81  }
82 
83 }
void addNamedValue(String name, Object value)
Set< Activity > getActivity(IContact contact, Date from, Set< ActivityType > types)