BrightSide Workbench Full Report + Source Code
ContactUserActivity.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.contacts.JobBoard;
26 import org.turro.contacts.db.ContactsPU;
27 import org.turro.elephant.db.WhereClause;
28 import org.turro.jpa.Dao;
29 import org.turro.plugin.contacts.IContact;
30 
37 
38  @Override
39  protected Dao createDao() {
40  return new ContactsPU();
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 j from JobBoard j");
60  wc.addClause("where 1=1");
61  if(from != null) {
62  wc.addClause("and j.updateDate >= :date");
63  wc.addNamedValue("date", from);
64  }
65  if(contact != null) {
66  wc.addClause("and j.contact = :contact");
67  wc.addNamedValue("contact", contact.getContact());
68  }
69  wc.addClause("order by j.updateDate desc");
70  Set<Activity> set = new HashSet<>();
71  for(JobBoard j : getDao().getResultList(JobBoard.class, wc, 100)) {
72  Activity activity = convertToActivity(types, j);
73  if(activity != null) set.add(activity);
74  }
75  return set;
76  }
77 
78  private Activity convertToActivity(Set<ActivityType> types, JobBoard j) {
79  return new Activity(j.getUpdateDate(), ActivityType.ACTIVITY_CHANGE, j.getContact().getId(),
80  ContactsPU.getObjectPath(j.getContact()), j);
81  }
82 
83 }
void addNamedValue(String name, Object value)
Set< Activity > getActivity(IContact contact, Date from, Set< ActivityType > types)