diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-07-23 18:29:36 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-23 18:29:36 +1200 |
commit | 4b2372336d0496c85befe099914434e5b68f05b3 (patch) | |
tree | 798de625a07c18287e829b3a037cacee179ebcff /src/org/traccar/api/resource/CalendarResource.java | |
parent | ba82047a492be54545961716814584d8880d28ae (diff) | |
parent | 5a65c0d6be8ffc2db0ffdb0c35ecedfb2b3750c7 (diff) | |
download | trackermap-server-4b2372336d0496c85befe099914434e5b68f05b3.tar.gz trackermap-server-4b2372336d0496c85befe099914434e5b68f05b3.tar.bz2 trackermap-server-4b2372336d0496c85befe099914434e5b68f05b3.zip |
Merge pull request #3373 from Abyss777/refactor_managers
Refactor managers, permissions etc
Diffstat (limited to 'src/org/traccar/api/resource/CalendarResource.java')
-rw-r--r-- | src/org/traccar/api/resource/CalendarResource.java | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/org/traccar/api/resource/CalendarResource.java b/src/org/traccar/api/resource/CalendarResource.java index 641d3b4b5..a0f8656af 100644 --- a/src/org/traccar/api/resource/CalendarResource.java +++ b/src/org/traccar/api/resource/CalendarResource.java @@ -33,7 +33,9 @@ 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; +import org.traccar.model.User; @Path("calendars") @Produces(MediaType.APPLICATION_JSON) @@ -44,28 +46,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.getDataManager().linkCalendar(getUserId(), entity.getId()); - Context.getCalendarManager().refreshUserCalendars(); + Context.getCalendarManager().addItem(entity); + Context.getDataManager().linkObject(User.class, getUserId(), entity.getClass(), entity.getId(), true); + Context.getCalendarManager().refreshUserItems(); return Response.ok(entity).build(); } @@ -73,8 +76,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.class, getUserId(), entity.getId()); + Context.getCalendarManager().updateItem(entity); return Response.ok(entity).build(); } @@ -82,8 +85,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.class, getUserId(), id); + Context.getCalendarManager().removeItem(id); return Response.noContent().build(); } } |