1 package org.collectionspace.services.common.vocabulary;
3 import javax.ws.rs.core.Response;
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;
15 public class AuthorityServiceUtils {
16 private static final Logger logger = LoggerFactory.getLogger(AuthorityIdentifierUtils.class);
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;
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;
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;
34 static public PoxPayloadIn requestPayloadIn(ServiceContext ctx, Specifier specifier, Class responseType) throws Exception {
35 PoxPayloadIn result = null;
37 AuthorityClient client = (AuthorityClient) ctx.getClient();
38 Response res = client.read(specifier.getURNValue());
40 int statusCode = res.getStatus();
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);
48 result = new PoxPayloadIn((String)res.readEntity(responseType)); // Get the entire response!
57 // Makes a call to the SAS server for a authority item payload
59 static public PoxPayloadIn requestPayloadIn(AuthorityItemSpecifier specifier, String serviceName, Class responseType) throws Exception {
60 PoxPayloadIn result = null;
62 ServiceContext parentCtx = new MultipartServiceContextImpl(serviceName);
63 AuthorityClient client = (AuthorityClient) parentCtx.getClient();
64 Response res = client.readItem(specifier.getParentSpecifier().getURNValue(), specifier.getItemSpecifier().getURNValue());
66 int statusCode = res.getStatus();
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);
74 result = new PoxPayloadIn((String)res.readEntity(responseType)); // Get the entire response!