]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
14b346c19a765472f101c61dc76b7ab4fcdeed61
[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     // Used to keep track if an authority item's is deprecated
19     public static final String IS_DEPRECATED_PROPERTY = "IS_DEPRECATED_PROPERTY";
20     public static final Boolean DEPRECATED = true;
21     public static final Boolean NOT_DEPRECATED = !DEPRECATED;
22     
23     // Used to keep track if an authority item's rev number should be updated
24     public static final String SHOULD_UPDATE_REV_PROPERTY = "SHOULD_UPDATE_REV_PROPERTY";
25     public static final boolean UPDATE_REV = true;
26     public static final boolean DONT_UPDATE_REV = !UPDATE_REV;
27
28     // Used to keep track if an authority item is a locally proposed member of a SAS authority
29     public static final String IS_PROPOSED_PROPERTY = "IS_PROPOSED";
30     public static final Boolean PROPOSED = true;
31     public static final Boolean NOT_PROPOSED = !PROPOSED;
32     public static final Boolean NO_CHANGE = null;
33
34     static public PoxPayloadIn requestPayloadIn(ServiceContext ctx, Specifier specifier, Class responseType) throws Exception {
35         PoxPayloadIn result = null;
36         
37         AuthorityClient client = (AuthorityClient) ctx.getClient();
38         Response res = client.read(specifier.getURNValue());
39         try {
40                 int statusCode = res.getStatus();
41         
42                 // Check the status code of the response: does it match
43                 // the expected response(s)?
44                 if (logger.isDebugEnabled()) {
45                     logger.debug(client.getClass().getCanonicalName() + ": status = " + statusCode);
46                 }
47                 
48             result = new PoxPayloadIn((String)res.readEntity(responseType)); // Get the entire response!                
49         } finally {
50                 res.close();
51         }
52         
53         return result;
54     }
55     
56     //
57     // Makes a call to the SAS server for a authority item payload
58     //    
59     static public PoxPayloadIn requestPayloadIn(AuthorityItemSpecifier specifier, String serviceName, Class responseType) throws Exception {
60         PoxPayloadIn result = null;
61         
62         ServiceContext parentCtx = new MultipartServiceContextImpl(serviceName);
63         AuthorityClient client = (AuthorityClient) parentCtx.getClient();
64         Response res = client.readItem(specifier.getParentSpecifier().getURNValue(), specifier.getItemSpecifier().getURNValue());
65         try {
66                 int statusCode = res.getStatus();
67         
68                 // Check the status code of the response: does it match
69                 // the expected response(s)?
70                 if (logger.isDebugEnabled()) {
71                     logger.debug(client.getClass().getCanonicalName() + ": status = " + statusCode);
72                 }
73                 
74             result = new PoxPayloadIn((String)res.readEntity(responseType)); // Get the entire response!                
75         } finally {
76                 res.close();
77         }
78         
79         return result;
80     }
81 }