1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package eu.ehri.extension.providers;
21
22 import eu.ehri.extension.PermissionsResource;
23 import eu.ehri.project.acl.InheritedItemPermissionSet;
24
25 import javax.ws.rs.Produces;
26 import javax.ws.rs.WebApplicationException;
27 import javax.ws.rs.core.HttpHeaders;
28 import javax.ws.rs.core.MediaType;
29 import javax.ws.rs.core.MultivaluedMap;
30 import javax.ws.rs.ext.MessageBodyWriter;
31 import javax.ws.rs.ext.Provider;
32 import java.io.IOException;
33 import java.io.OutputStream;
34 import java.lang.annotation.Annotation;
35 import java.lang.reflect.Type;
36
37 @Provider
38 @Produces(MediaType.APPLICATION_JSON)
39 public class InheritedItemPermissionSetProvider
40 implements MessageBodyWriter<InheritedItemPermissionSet>, JsonMessageBodyHandler {
41
42 @Override
43 public boolean isWriteable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
44 return InheritedItemPermissionSet.class.equals(aClass);
45 }
46
47 @Override
48 public long getSize(InheritedItemPermissionSet permissionSet, Class<?> aClass, Type type, Annotation[] annotations,
49 MediaType mediaType) {
50 return -1L;
51 }
52
53 @Override
54 public void writeTo(InheritedItemPermissionSet itemPermissionSet,
55 Class<?> aClass, Type type, Annotation[] annotations,
56 MediaType mediaType, MultivaluedMap<String, Object> headers,
57 OutputStream outputStream) throws IOException, WebApplicationException {
58 headers.putSingle(HttpHeaders.CACHE_CONTROL,
59 PermissionsResource.getCacheControl().toString());
60 mapper.writeValue(outputStream, itemPermissionSet.serialize());
61 }
62 }