BrightSide Workbench Full Report + Source Code
UserActivities.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.Set;
23 import java.util.concurrent.locks.ReentrantLock;
24 import org.amic.util.date.CheckDate;
25 import org.turro.plugin.contacts.IContact;
26 import org.turro.reflection.Instances;
27 
32 public class UserActivities {
33 
34  public static Set<Activity> getActivity(IContact contact) {
35  return getActivity(contact, ActivityType.values());
36  }
37 
38  public static Set<Activity> getActivity(IContact contact, ActivityType... type) {
39  Date from = new CheckDate().addYears(-5).getDate();
40  return getActivity(contact, from, type);
41  }
42 
43  public static Set<Activity> getActivity(IContact contact, Date from, ActivityType... type) {
44  LOCK.lock();
45  try {
46  ActivitySet set = new ActivitySet();
47  for(IUserActivity activity : Instances.cached().byAnnotation(UserActivity.class, IUserActivity.class)) {
48  activity.init();
49  set.addAll(activity.getActivity(contact, from, type));
50  activity.end();
51  }
52  return set;
53  } finally {
54  LOCK.unlock();
55  }
56  }
57 
58  private static final ReentrantLock LOCK = new ReentrantLock();
59 
60  private UserActivities() {}
61 
62 }
static Set< Activity > getActivity(IContact contact, Date from, ActivityType... type)
static Set< Activity > getActivity(IContact contact, ActivityType... type)
static Set< Activity > getActivity(IContact contact)