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.api.RefNameUtils.AuthorityTermInfo;
8 import org.collectionspace.services.common.context.MultipartServiceContextImpl;
9 import org.collectionspace.services.common.context.ServiceContext;
10 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthorityItemSpecifier;
11 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier;
12 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityIdentifierUtils;
13 import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface;
14 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
15 import org.nuxeo.ecm.core.api.DocumentModel;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public class AuthorityServiceUtils {
20 private static final Logger logger = LoggerFactory.getLogger(AuthorityIdentifierUtils.class);
22 // Used to keep track if an authority item's is deprecated
23 public static final String IS_DEPRECATED_PROPERTY = "IS_DEPRECATED_PROPERTY";
24 public static final Boolean DEPRECATED = true;
25 public static final Boolean NOT_DEPRECATED = !DEPRECATED;
27 // Used to keep track if an authority item's rev number should be updated
28 public static final String SHOULD_UPDATE_REV_PROPERTY = "SHOULD_UPDATE_REV_PROPERTY";
29 public static final boolean UPDATE_REV = true;
30 public static final boolean DONT_UPDATE_REV = !UPDATE_REV;
32 // Used to keep track if an authority item is a locally proposed member of a SAS authority
33 public static final String IS_PROPOSED_PROPERTY = "IS_PROPOSED";
34 public static final Boolean PROPOSED = true;
35 public static final Boolean NOT_PROPOSED = !PROPOSED;
36 public static final Boolean NO_CHANGE = null;
38 static public PoxPayloadIn requestPayloadIn(ServiceContext ctx, Specifier specifier, Class responseType) throws Exception {
39 PoxPayloadIn result = null;
41 AuthorityClient client = (AuthorityClient) ctx.getClient();
42 Response res = client.read(specifier.getURNValue());
44 int statusCode = res.getStatus();
46 // Check the status code of the response: does it match
47 // the expected response(s)?
48 if (logger.isDebugEnabled()) {
49 logger.debug(client.getClass().getCanonicalName() + ": status = " + statusCode);
52 result = new PoxPayloadIn((String)res.readEntity(responseType)); // Get the entire response!
61 // Makes a call to the SAS server for a authority item payload
63 static public PoxPayloadIn requestPayloadIn(AuthorityItemSpecifier specifier, String serviceName, Class responseType) throws Exception {
64 PoxPayloadIn result = null;
66 ServiceContext parentCtx = new MultipartServiceContextImpl(serviceName);
67 AuthorityClient client = (AuthorityClient) parentCtx.getClient();
68 Response res = client.readItem(specifier.getParentSpecifier().getURNValue(), specifier.getItemSpecifier().getURNValue());
70 int statusCode = res.getStatus();
72 // Check the status code of the response: does it match
73 // the expected response(s)?
74 if (logger.isDebugEnabled()) {
75 logger.debug(client.getClass().getCanonicalName() + ": status = " + statusCode);
78 result = new PoxPayloadIn((String)res.readEntity(responseType)); // Get the entire response!
86 static public boolean setAuthorityItemDeprecated(ServiceContext ctx,
87 DocumentModel docModel, String authorityItemCommonSchemaName, Boolean flag) throws Exception {
88 boolean result = false;
90 docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.DEPRECATED,
92 CoreSessionInterface repoSession = (CoreSessionInterface) ctx.getCurrentRepositorySession();
93 repoSession.saveDocument(docModel);
100 * Mark the authority item as deprecated.
106 static public boolean markAuthorityItemAsDeprecated(ServiceContext ctx, String authorityItemCommonSchemaName, String itemCsid) throws Exception {
107 boolean result = false;
110 DocumentModel docModel = NuxeoUtils.getDocFromCsid(ctx, (CoreSessionInterface)ctx.getCurrentRepositorySession(), itemCsid);
111 result = setAuthorityItemDeprecated(ctx, docModel, authorityItemCommonSchemaName, AuthorityServiceUtils.DEPRECATED);
112 } catch (Exception e) {
113 logger.warn(String.format("Could not mark item '%s' as deprecated.", itemCsid), e);