import org.collectionspace.services.client.IClientQueryParams;
import org.collectionspace.services.client.IQueryManager;
+import org.collectionspace.services.client.PoxPayload;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.client.XmlTools;
* The Class AuthorityResource.
*/
+@SuppressWarnings({"rawtypes", "unchecked"})
@Consumes("application/xml")
@Produces("application/xml")
public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
extends NuxeoBasedResource {
- final static String SEARCH_TYPE_TERMSTATUS = "ts";
+ final Logger logger = LoggerFactory.getLogger(AuthorityResource.class);
+
+ final static String SEARCH_TYPE_TERMSTATUS = "ts";
public final static String hierarchy = "hierarchy";
protected Class<AuthCommon> authCommonClass;
final static String FETCH_SHORT_ID = "_fetch_";
public final static String PARENT_WILDCARD = "_ALL_";
+ protected static final boolean DONT_INCLUDE_ITEMS = false;
+ protected static final boolean INCLUDE_ITEMS = true;
- final Logger logger = LoggerFactory.getLogger(AuthorityResource.class);
-
/**
* Instantiates a new Authority resource.
*/
if (supportsReplicating(ctx.getTenantId(), ctx.getServiceName()) == false) {
throw new DocumentException(Response.Status.FORBIDDEN.getStatusCode());
}
- AuthorityDocumentModelHandler handler = (AuthorityDocumentModelHandler)createDocumentHandler(ctx);
+ AuthorityDocumentModelHandler handler = (AuthorityDocumentModelHandler)createDocumentHandler(ctx);
specifier = Specifier.getSpecifier(identifier, "getAuthority", "GET");
handler.setShouldUpdateRevNumber(AuthorityServiceUtils.DONT_UPDATE_REV); // Never update rev number on sync calls
neededSync = getRepositoryClient(ctx).synchronize(ctx, specifier, handler);
return result;
}
+
+ /*
+ * Builds a cached JAX-RS response.
+ */
+ protected Response buildResponse(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, PoxPayloadOut payloadOut) {
+ Response result = null;
+ ResponseBuilder responseBuilder = Response.ok(payloadOut.getBytes());
+ this.setCacheControl(ctx, responseBuilder);
+ result = responseBuilder.build();
+
+ return result;
+ }
+
/**
* Gets the authority.
*
@PathParam("csid") String specifier) {
Response result = null;
uriInfo = new UriInfoWrapper(uriInfo);
- PoxPayloadOut payloadout = null;
try {
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(request, uriInfo);
- DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createDocumentHandler(ctx);
-
- Specifier spec = Specifier.getSpecifier(specifier, "getAuthority", "GET");
- if (spec.form == SpecifierForm.CSID) {
- if (logger.isDebugEnabled()) {
- logger.debug("getAuthority with csid=" + spec.value);
- }
- getRepositoryClient(ctx).get(ctx, spec.value, handler);
- } else {
- String whereClause = RefNameServiceUtils.buildWhereForAuthByName(authorityCommonSchemaName, spec.value);
- DocumentFilter myFilter = new NuxeoDocumentFilter(whereClause, 0, 1);
- handler.setDocumentFilter(myFilter);
- getRepositoryClient(ctx).get(ctx, handler);
- }
-
- payloadout = ctx.getOutput();
- ResponseBuilder responseBuilder = Response.ok(payloadout.getBytes());
- this.setCacheControl(ctx, responseBuilder);
- result = responseBuilder.build();
+ PoxPayloadOut payloadout = getAuthority(ctx, request, uriInfo, specifier, DONT_INCLUDE_ITEMS);
+ result = buildResponse(ctx, payloadout);
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.GET_FAILED, specifier);
}
return result;
}
+
+ protected PoxPayloadOut getAuthority(
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
+ Request request,
+ UriInfo uriInfo,
+ String specifier,
+ boolean includeItems) throws Exception {
+ uriInfo = new UriInfoWrapper(uriInfo);
+ PoxPayloadOut payloadout = null;
+
+ DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> docHandler = createDocumentHandler(ctx);
+ Specifier spec = Specifier.getSpecifier(specifier, "getAuthority", "GET");
+ if (spec.form == SpecifierForm.CSID) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("getAuthority with csid=" + spec.value);
+ }
+ getRepositoryClient(ctx).get(ctx, spec.value, docHandler);
+ } else {
+ String whereClause = RefNameServiceUtils.buildWhereForAuthByName(authorityCommonSchemaName, spec.value);
+ DocumentFilter myFilter = new NuxeoDocumentFilter(whereClause, 0, 1);
+ docHandler.setDocumentFilter(myFilter);
+ getRepositoryClient(ctx).get(ctx, docHandler);
+ }
+
+ payloadout = ctx.getOutput();
+ if (includeItems == true) {
+ AbstractCommonList itemsList = this.getAuthorityItemList(ctx, specifier, uriInfo);
+ payloadout.addPart(PoxPayload.ABSTRACT_COMMON_LIST_ROOT_ELEMENT_LABEL, itemsList);
+ }
+
+ return payloadout;
+ }
/**
* Finds and populates the authority list.
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(uriInfo);
- DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createDocumentHandler(ctx);
+ DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createDocumentHandler(ctx);
DocumentFilter myFilter = handler.getDocumentFilter();
// Need to make the default sort order for authority items
// be on the displayName field
* @param itemIdentifier
* @throws Exception
*/
- @SuppressWarnings("rawtypes")
public boolean deleteAuthorityItem(ServiceContext<PoxPayloadIn, PoxPayloadOut> existingCtx,
String parentIdentifier,
String itemIdentifier,
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.client.VocabularyClient;
+import org.collectionspace.services.common.CSWebApplicationException;
+import org.collectionspace.services.common.ServiceMessages;
+import org.collectionspace.services.common.UriInfoWrapper;
+import org.collectionspace.services.common.api.Tools;
import org.collectionspace.services.common.context.ServiceBindingUtils;
import org.collectionspace.services.common.context.ServiceContext;
-//import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
import org.collectionspace.services.common.vocabulary.AuthorityResource;
-//import org.collectionspace.services.nuxeo.util.NuxeoUtils;
import org.collectionspace.services.vocabulary.nuxeo.VocabularyItemDocumentModelHandler;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.ws.rs.GET;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
@Path("/" + VocabularyClient.SERVICE_PATH_COMPONENT)
public class VocabularyResource extends
VOCABULARIES_COMMON, VOCABULARYITEMS_COMMON);
}
+ @GET
+ @Path("{csid}")
+ @Override
+ public Response get(
+ @Context Request request,
+ @Context UriInfo uriInfo,
+ @PathParam("csid") String specifier) {
+ Response result = null;
+ uriInfo = new UriInfoWrapper(uriInfo);
+
+ try {
+ MultivaluedMap<String,String> queryParams = uriInfo.getQueryParameters();
+ String showItemsValue = (String)queryParams.getFirst(VocabularyClient.SHOW_ITEMS_QP);
+ boolean showItems = Tools.isTrue(showItemsValue);
+
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(request, uriInfo);
+ PoxPayloadOut payloadout = getAuthority(ctx, request, uriInfo, specifier, showItems);
+ result = buildResponse(ctx, payloadout);
+ } catch (Exception e) {
+ throw bigReThrow(e, ServiceMessages.GET_FAILED, specifier);
+ }
+
+ if (result == null) {
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "GET request failed. The requested Authority specifier:" + specifier + ": was not found.").type(
+ "text/plain").build();
+ throw new CSWebApplicationException(response);
+ }
+
+ return result;
+ }
+
@Override
public String getServiceName() {
return vocabularyServiceName;