aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/CalendarManager.java
diff options
context:
space:
mode:
authorIvan Muratov <binakot@gmail.com>2017-10-24 14:52:48 +0300
committerGitHub <noreply@github.com>2017-10-24 14:52:48 +0300
commitdb02157dbb29539dda4b51a5e8b317293cfc536c (patch)
treeb974f082172406e16a92cb9da8136ef856f571a5 /src/org/traccar/database/CalendarManager.java
parent09d3cf2b5416327700ad22b652cf4a0dca09aaf2 (diff)
parent96e15853b9c28bd31295ca2c014e226e4a50aaa1 (diff)
downloadtrackermap-server-db02157dbb29539dda4b51a5e8b317293cfc536c.tar.gz
trackermap-server-db02157dbb29539dda4b51a5e8b317293cfc536c.tar.bz2
trackermap-server-db02157dbb29539dda4b51a5e8b317293cfc536c.zip
Merge branch 'master' into master
Diffstat (limited to 'src/org/traccar/database/CalendarManager.java')
-rw-r--r--src/org/traccar/database/CalendarManager.java99
1 files changed, 2 insertions, 97 deletions
diff --git a/src/org/traccar/database/CalendarManager.java b/src/org/traccar/database/CalendarManager.java
index 31d484327..44ced1082 100644
--- a/src/org/traccar/database/CalendarManager.java
+++ b/src/org/traccar/database/CalendarManager.java
@@ -16,107 +16,12 @@
*/
package org.traccar.database;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.traccar.Context;
-import org.traccar.helper.Log;
import org.traccar.model.Calendar;
-import org.traccar.model.CalendarPermission;
-
-public class CalendarManager {
-
- private final DataManager dataManager;
- private final Map<Long, Calendar> calendars = new ConcurrentHashMap<>();
- private final Map<Long, Set<Long>> userCalendars = new ConcurrentHashMap<>();
+public class CalendarManager extends SimpleObjectManager<Calendar> {
public CalendarManager(DataManager dataManager) {
- this.dataManager = dataManager;
- refreshCalendars();
- }
-
- public final void refreshCalendars() {
- if (dataManager != null) {
- try {
- calendars.clear();
- for (Calendar calendar : dataManager.getCalendars()) {
- calendars.put(calendar.getId(), calendar);
- }
- } catch (SQLException error) {
- Log.warning(error);
- }
- }
- refreshUserCalendars();
- }
-
- private Set<Long> getUserCalendarIds(long userId) {
- if (!userCalendars.containsKey(userId)) {
- userCalendars.put(userId, new HashSet<Long>());
- }
- return userCalendars.get(userId);
- }
-
- public Collection<Calendar> getUserCalendars(long userId) {
- ArrayList<Calendar> result = new ArrayList<>();
- for (long calendarId : getUserCalendarIds(userId)) {
- result.add(calendars.get(calendarId));
- }
- return result;
- }
-
- public Collection<Calendar> getManagedCalendars(long userId) {
- ArrayList<Calendar> result = new ArrayList<>();
- result.addAll(getUserCalendars(userId));
- for (long managedUserId : Context.getPermissionsManager().getUserPermissions(userId)) {
- result.addAll(getUserCalendars(managedUserId));
- }
- return result;
- }
-
- public final void refreshUserCalendars() {
- if (dataManager != null) {
- try {
- userCalendars.clear();
- for (CalendarPermission calendarsPermission : dataManager.getCalendarPermissions()) {
- getUserCalendarIds(calendarsPermission.getUserId()).add(calendarsPermission.getCalendarId());
- }
- } catch (SQLException error) {
- Log.warning(error);
- }
- }
- }
-
- public Calendar getCalendar(long calendarId) {
- return calendars.get(calendarId);
- }
-
- public final void addCalendar(Calendar calendar) throws SQLException {
- dataManager.addCalendar(calendar);
- calendars.put(calendar.getId(), calendar);
- }
-
- public final void updateCalendar(Calendar calendar) throws SQLException {
- dataManager.updateCalendar(calendar);
- calendars.put(calendar.getId(), calendar);
- }
-
- public final void removeCalendar(long calendarId) throws SQLException {
- dataManager.removeCalendar(calendarId);
- calendars.remove(calendarId);
- refreshUserCalendars();
+ super(dataManager, Calendar.class);
}
- public Collection<Calendar> getAllCalendars() {
- return calendars.values();
- }
-
- public boolean checkCalendar(long userId, long calendarId) {
- return getUserCalendarIds(userId).contains(calendarId);
- }
}