aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/api/resource/UserResource.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-12-01 14:37:26 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-12-01 14:37:26 +1300
commita4fb24732188e4e0b7cc44079eea02c85e142028 (patch)
treea2fdc0e6f92d7bfafe2f4e39b01133c2a09fc748 /src/org/traccar/api/resource/UserResource.java
parent40a607faa34d3c21d7b6d8275279fc8ce3c96980 (diff)
downloadtrackermap-server-a4fb24732188e4e0b7cc44079eea02c85e142028.tar.gz
trackermap-server-a4fb24732188e4e0b7cc44079eea02c85e142028.tar.bz2
trackermap-server-a4fb24732188e4e0b7cc44079eea02c85e142028.zip
Refactor base and other resource classes
Diffstat (limited to 'src/org/traccar/api/resource/UserResource.java')
-rw-r--r--src/org/traccar/api/resource/UserResource.java63
1 files changed, 35 insertions, 28 deletions
diff --git a/src/org/traccar/api/resource/UserResource.java b/src/org/traccar/api/resource/UserResource.java
index 8e17787c2..43bef891f 100644
--- a/src/org/traccar/api/resource/UserResource.java
+++ b/src/org/traccar/api/resource/UserResource.java
@@ -15,8 +15,8 @@
*/
package org.traccar.api.resource;
+import java.sql.SQLException;
import java.util.Collection;
-import javax.annotation.security.RolesAllowed;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -25,52 +25,59 @@ import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+
+import org.traccar.Context;
import org.traccar.api.BaseResource;
import org.traccar.model.User;
@Path("users")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
-public class UserResource extends BaseResource<User> {
+public class UserResource extends BaseResource {
@GET
- @RolesAllowed(User.ROLE_ADMIN)
- @Override
- public Collection<User> getEntities() {
- return super.getEntities();
- }
-
- @GET
- @Path("{id}")
- @RolesAllowed(User.ROLE_USER)
- @Override
- public User getEntity(@PathParam("id") long id) {
- return super.getEntity(id);
+ public Collection<User> get() {
+ try {
+ return Context.getDataManager().getUsers();
+ } catch (SQLException e) {
+ throw new WebApplicationException(e);
+ }
}
@POST
- @RolesAllowed(User.ROLE_USER)
- @Override
- public Response postEntity(User entity) {
- return super.postEntity(entity);
+ public Response add(User entity) {
+ try {
+ Context.getDataManager().addUser(entity);
+ return Response.ok(entity).build();
+ } catch (SQLException e) {
+ throw new WebApplicationException(e);
+ }
}
- @PUT
@Path("{id}")
- @RolesAllowed(User.ROLE_USER)
- @Override
- public Response putEntity(@PathParam("id") long id, User entity) {
- return super.putEntity(id, entity);
+ @PUT
+ public Response update(@PathParam("id") long id, User entity) {
+ try {
+ entity.setId(id);
+ Context.getDataManager().updateUser(entity);
+ return Response.ok(entity).build();
+ } catch (SQLException e) {
+ throw new WebApplicationException(e);
+ }
}
- @DELETE
@Path("{id}")
- @RolesAllowed(User.ROLE_USER)
- @Override
- public Response deleteEntity(@PathParam("id") long id) {
- return super.deleteEntity(id);
+ @DELETE
+ public Response remove(@PathParam("id") long id) {
+ try {
+ Context.getDataManager().removeUser(id);
+ return Response.noContent().build();
+ } catch (SQLException e) {
+ throw new WebApplicationException(e);
+ }
}
}