1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package eu.ehri.extension;
21
22 import eu.ehri.extension.base.AbstractResource;
23 import eu.ehri.extension.base.DeleteResource;
24 import eu.ehri.extension.base.GetResource;
25 import eu.ehri.project.core.Tx;
26 import eu.ehri.project.definitions.Entities;
27 import eu.ehri.project.exceptions.ItemNotFound;
28 import eu.ehri.project.exceptions.PermissionDenied;
29 import eu.ehri.project.models.EntityClass;
30 import eu.ehri.project.models.PermissionGrant;
31 import org.neo4j.graphdb.GraphDatabaseService;
32
33 import javax.ws.rs.DELETE;
34 import javax.ws.rs.GET;
35 import javax.ws.rs.Path;
36 import javax.ws.rs.PathParam;
37 import javax.ws.rs.Produces;
38 import javax.ws.rs.core.Context;
39 import javax.ws.rs.core.MediaType;
40 import javax.ws.rs.core.Response;
41
42
43
44
45 @Path(AbstractResource.RESOURCE_ENDPOINT_PREFIX + "/" + Entities.PERMISSION_GRANT)
46 public class PermissionGrantResource extends AbstractResource implements DeleteResource, GetResource {
47
48 public PermissionGrantResource(@Context GraphDatabaseService database) {
49 super(database);
50 }
51
52
53
54
55
56
57
58 @GET
59 @Produces(MediaType.APPLICATION_JSON)
60 @Path("{id:[^/]+}")
61 @Override
62 public Response get(@PathParam("id") String id) throws ItemNotFound {
63 try (final Tx tx = beginTx()) {
64 PermissionGrant grant = manager.getEntity(id,
65 EntityClass.PERMISSION_GRANT, PermissionGrant.class);
66 Response response = single(grant);
67 tx.success();
68 return response;
69 }
70 }
71
72
73
74
75
76
77 @DELETE
78 @Path("{id:[^/]+}")
79 @Override
80 public void delete(@PathParam("id") String id) throws ItemNotFound, PermissionDenied {
81 try (final Tx tx = beginTx()) {
82 api().acl().revokePermissionGrant(manager.getEntity(id,
83 EntityClass.PERMISSION_GRANT, PermissionGrant.class));
84 tx.success();
85 }
86 }
87 }