diff options
author | Abyss777 <abyss@fox5.ru> | 2017-07-19 15:24:55 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2017-07-19 15:24:55 +0500 |
commit | a9478ded48de140d47d17def1ee5329267fe6088 (patch) | |
tree | adc5a9177fd5adcf10a8b56ee4620780dfc13cd9 /src/org/traccar/api/resource/CalendarResource.java | |
parent | cb0d7cccaecfe049e04defd90884976ac1e982f9 (diff) | |
download | trackermap-server-a9478ded48de140d47d17def1ee5329267fe6088.tar.gz trackermap-server-a9478ded48de140d47d17def1ee5329267fe6088.tar.bz2 trackermap-server-a9478ded48de140d47d17def1ee5329267fe6088.zip |
Refactored four managers
Diffstat (limited to 'src/org/traccar/api/resource/CalendarResource.java')
-rw-r--r-- | src/org/traccar/api/resource/CalendarResource.java | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/org/traccar/api/resource/CalendarResource.java b/src/org/traccar/api/resource/CalendarResource.java index 641d3b4b5..be675fc79 100644 --- a/src/org/traccar/api/resource/CalendarResource.java +++ b/src/org/traccar/api/resource/CalendarResource.java @@ -33,6 +33,7 @@ import javax.ws.rs.core.Response; import org.traccar.Context; import org.traccar.api.BaseResource; +import org.traccar.database.CalendarManager; import org.traccar.model.Calendar; @Path("calendars") @@ -44,28 +45,29 @@ public class CalendarResource extends BaseResource { public Collection<Calendar> get( @QueryParam("all") boolean all, @QueryParam("userId") long userId) throws SQLException { + CalendarManager calendarManager = Context.getCalendarManager(); if (all) { if (Context.getPermissionsManager().isAdmin(getUserId())) { - return Context.getCalendarManager().getAllCalendars(); + return calendarManager.getItems(Calendar.class, calendarManager.getAllItems()); } else { Context.getPermissionsManager().checkManager(getUserId()); - return Context.getCalendarManager().getManagedCalendars(getUserId()); + return calendarManager.getItems(Calendar.class, calendarManager.getManagedItems(getUserId())); } } else { if (userId == 0) { userId = getUserId(); } Context.getPermissionsManager().checkUser(getUserId(), userId); - return Context.getCalendarManager().getUserCalendars(userId); + return calendarManager.getItems(Calendar.class, calendarManager.getUserItems(userId)); } } @POST public Response add(Calendar entity) throws SQLException { Context.getPermissionsManager().checkReadonly(getUserId()); - Context.getCalendarManager().addCalendar(entity); + Context.getCalendarManager().addItem(entity); Context.getDataManager().linkCalendar(getUserId(), entity.getId()); - Context.getCalendarManager().refreshUserCalendars(); + Context.getCalendarManager().refreshUserItems(); return Response.ok(entity).build(); } @@ -73,8 +75,8 @@ public class CalendarResource extends BaseResource { @PUT public Response update(Calendar entity) throws SQLException { Context.getPermissionsManager().checkReadonly(getUserId()); - Context.getPermissionsManager().checkCalendar(getUserId(), entity.getId()); - Context.getCalendarManager().updateCalendar(entity); + Context.getPermissionsManager().checkPermission("calendar", getUserId(), entity.getId()); + Context.getCalendarManager().updateItem(entity); return Response.ok(entity).build(); } @@ -82,8 +84,8 @@ public class CalendarResource extends BaseResource { @DELETE public Response remove(@PathParam("id") long id) throws SQLException { Context.getPermissionsManager().checkReadonly(getUserId()); - Context.getPermissionsManager().checkCalendar(getUserId(), id); - Context.getCalendarManager().removeCalendar(id); + Context.getPermissionsManager().checkPermission("calendar", getUserId(), id); + Context.getCalendarManager().removeItem(id); return Response.noContent().build(); } } |