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 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;
22 static public PoxPayloadIn requestPayloadIn(ServiceContext ctx, Specifier specifier, Class responseType) throws Exception {
23 PoxPayloadIn result = null;
25 AuthorityClient client = (AuthorityClient) ctx.getClient();
26 Response res = client.read(specifier.value);
28 int statusCode = res.getStatus();
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);
36 result = new PoxPayloadIn((String)res.readEntity(responseType)); // Get the entire response!
44 static public PoxPayloadIn requestPayloadIn(AuthorityItemSpecifier specifier, String serviceName, Class responseType) throws Exception {
45 PoxPayloadIn result = null;
47 ServiceContext parentCtx = new MultipartServiceContextImpl(serviceName);
48 AuthorityClient client = (AuthorityClient) parentCtx.getClient();
49 Response res = client.readItem(specifier.getParentSpecifier().value, specifier.getItemSpecifier().value);
51 int statusCode = res.getStatus();
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);
59 result = new PoxPayloadIn((String)res.readEntity(responseType)); // Get the entire response!