]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
7213612d2964e0c58ca8ffa47c436856e893feef
[tmp/jakarta-migration.git] /
1 package org.collectionspace.services.common.vocabulary;
2
3 import javax.ws.rs.core.Response;
4
5 import org.collectionspace.services.client.AuthorityClient;
6 import org.collectionspace.services.client.PoxPayloadIn;
7 import org.collectionspace.services.common.context.MultipartServiceContextImpl;
8 import org.collectionspace.services.common.context.ServiceContext;
9 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthorityItemSpecifier;
10 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier;
11 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityIdentifierUtils;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14
15 public class AuthorityServiceUtils {
16     private static final Logger logger = LoggerFactory.getLogger(AuthorityIdentifierUtils.class);
17
18     public static final String SHOULD_UPDATE_REV_PROPERTY = "SHOULD_UPDATE_REV_PROPERTY";
19     public static final boolean DONT_UPDATE_REV = false;
20     public static final boolean UPDATE_REV = true;
21
22     static public PoxPayloadIn requestPayloadIn(ServiceContext ctx, Specifier specifier, Class responseType) throws Exception {
23         PoxPayloadIn result = null;
24         
25         AuthorityClient client = (AuthorityClient) ctx.getClient();
26         Response res = client.read(specifier.value);
27         try {
28                 int statusCode = res.getStatus();
29         
30                 // Check the status code of the response: does it match
31                 // the expected response(s)?
32                 if (logger.isDebugEnabled()) {
33                     logger.debug(client.getClass().getCanonicalName() + ": status = " + statusCode);
34                 }
35                 
36             result = new PoxPayloadIn((String)res.readEntity(responseType)); // Get the entire response!                
37         } finally {
38                 res.close();
39         }
40         
41         return result;
42     }
43     
44     static public PoxPayloadIn requestPayloadIn(AuthorityItemSpecifier specifier, String serviceName, Class responseType) throws Exception {
45         PoxPayloadIn result = null;
46         
47         ServiceContext parentCtx = new MultipartServiceContextImpl(serviceName);
48         AuthorityClient client = (AuthorityClient) parentCtx.getClient();
49         Response res = client.readItem(specifier.getParentSpecifier().value, specifier.getItemSpecifier().value);
50         try {
51                 int statusCode = res.getStatus();
52         
53                 // Check the status code of the response: does it match
54                 // the expected response(s)?
55                 if (logger.isDebugEnabled()) {
56                     logger.debug(client.getClass().getCanonicalName() + ": status = " + statusCode);
57                 }
58                 
59             result = new PoxPayloadIn((String)res.readEntity(responseType)); // Get the entire response!                
60         } finally {
61                 res.close();
62         }
63         
64         return result;
65     }
66 }