From: Richard Millet Date: Tue, 28 May 2019 19:22:04 +0000 (-0700) Subject: DRYD-658: Add API endpoint to vocab/authorities to request a term record using a... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=d4c1d3ca9aa0f2b03f2f74ab5bc01acef88fff04;p=tmp%2Fjakarta-migration.git DRYD-658: Add API endpoint to vocab/authorities to request a term record using a fully qualified refname. --- diff --git a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CSpaceResteasyBootstrap.java b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CSpaceResteasyBootstrap.java index 0a8cbc797..c60dc923a 100644 --- a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CSpaceResteasyBootstrap.java +++ b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CSpaceResteasyBootstrap.java @@ -216,7 +216,7 @@ public class CSpaceResteasyBootstrap extends ResteasyBootstrap { // AuthorityResource authorityResource = (AuthorityResource) resourceMap.get(serviceName.toLowerCase()); try { - response = authorityResource.get(null, null, authoritySpecifier); + response = authorityResource.get(null, null, null, authoritySpecifier); } catch (CSWebApplicationException e) { response = e.getResponse(); // If the authority doesn't exist, we expect a 404 error } diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index c6736e332..3c52763d9 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -60,6 +60,8 @@ import org.collectionspace.services.common.UriInfoWrapper; import org.collectionspace.services.common.UriTemplateFactory; import org.collectionspace.services.common.UriTemplateRegistryKey; import org.collectionspace.services.common.api.RefName; +import org.collectionspace.services.common.api.RefNameUtils; +import org.collectionspace.services.common.api.RefNameUtils.AuthorityTermInfo; import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.authorityref.AuthorityRefDocList; import org.collectionspace.services.common.authorityref.AuthorityRefList; @@ -448,15 +450,27 @@ public abstract class AuthorityResource @Override public Response get( @Context Request request, + @Context ResourceMap resourceMap, @Context UriInfo uriInfo, @PathParam("csid") String specifier) { Response result = null; uriInfo = new UriInfoWrapper(uriInfo); - - try { - ServiceContext ctx = createServiceContext(request, uriInfo); - PoxPayloadOut payloadout = getAuthority(ctx, request, uriInfo, specifier, DONT_INCLUDE_ITEMS); - result = buildResponse(ctx, payloadout); + PoxPayloadOut payloadout = null; + + try { + // + // If the specifier is a fully qualified authority term refname, then return the term payload in the response + // + if (RefNameUtils.isTermRefname(specifier)) { + AuthorityTermInfo authorityTermInfo = RefNameUtils.parseAuthorityTermInfo(specifier); + String parentIdentifier = Specifier.createShortIdURNValue(authorityTermInfo.inAuthority.name); + String itemIdentifier = Specifier.createShortIdURNValue(authorityTermInfo.name); + result = this.getAuthorityItemResponse(request, uriInfo, resourceMap, parentIdentifier, itemIdentifier); + } else { + ServiceContext ctx = createServiceContext(request, uriInfo); + payloadout = getAuthority(ctx, request, uriInfo, specifier, DONT_INCLUDE_ITEMS); + result = buildResponse(ctx, payloadout); + } } catch (Exception e) { throw bigReThrow(e, ServiceMessages.GET_FAILED, specifier); } @@ -1051,6 +1065,21 @@ public abstract class AuthorityResource @PathParam("itemcsid") String itemIdentifier) { uriInfo = new UriInfoWrapper(uriInfo); PoxPayloadOut result = null; + + result = this.getAuthorityItemPayload(request, uriInfo, resourceMap, parentIdentifier, itemIdentifier); + + return result.getBytes(); + } + + + public PoxPayloadOut getAuthorityItemPayload( + @Context Request request, + @Context UriInfo uriInfo, + @Context ResourceMap resourceMap, + @PathParam("csid") String parentIdentifier, + @PathParam("itemcsid") String itemIdentifier) { + uriInfo = new UriInfoWrapper(uriInfo); + PoxPayloadOut result = null; try { RemoteServiceContext ctx = (RemoteServiceContext) createServiceContext(getItemServiceName(), resourceMap, uriInfo); @@ -1065,8 +1094,35 @@ public abstract class AuthorityResource throw bigReThrow(e, ServiceMessages.GET_FAILED); } - return result.getBytes(); + return result; } + + public Response getAuthorityItemResponse( + @Context Request request, + @Context UriInfo uriInfo, + @Context ResourceMap resourceMap, + @PathParam("csid") String parentIdentifier, + @PathParam("itemcsid") String itemIdentifier) { + uriInfo = new UriInfoWrapper(uriInfo); + PoxPayloadOut payloadout = null; + RemoteServiceContext ctx = null; + + try { + ctx = (RemoteServiceContext) createServiceContext(getItemServiceName(), resourceMap, uriInfo); + + JaxRsContext jaxRsContext = new JaxRsContext(request, uriInfo); // Needed for getting account permissions part of the resource + ctx.setJaxRsContext(jaxRsContext); + + payloadout = getAuthorityItem(ctx, parentIdentifier, itemIdentifier); + } catch (DocumentNotFoundException dnf) { + throw bigReThrow(dnf, ServiceMessages.resourceNotFoundMsg(itemIdentifier)); + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.GET_FAILED); + } + + return buildResponse(ctx, payloadout); + } + /* * Most of the authority child classes will/should use this implementation. However, the Vocabulary service's item schema is diff --git a/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/AbstractBatchJob.java b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/AbstractBatchJob.java index b2e0e1434..a9b9af5f4 100644 --- a/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/AbstractBatchJob.java +++ b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/AbstractBatchJob.java @@ -220,7 +220,7 @@ public abstract class AbstractBatchJob extends AbstractBatchInvocable { protected PoxPayloadOut findByCsid(String serviceName, String csid) throws URISyntaxException, DocumentException { NuxeoBasedResource resource = (NuxeoBasedResource) getResourceMap().get(serviceName); - byte[] outputBytes = (byte[]) resource.get(null, createUriInfo(), csid).getEntity(); + byte[] outputBytes = (byte[]) resource.get(null, null, createUriInfo(), csid).getEntity(); PoxPayloadOut payload = new PoxPayloadOut(outputBytes); diff --git a/services/common-api/src/main/java/org/collectionspace/services/common/api/RefNameUtils.java b/services/common-api/src/main/java/org/collectionspace/services/common/api/RefNameUtils.java index e117600b0..13802afe5 100644 --- a/services/common-api/src/main/java/org/collectionspace/services/common/api/RefNameUtils.java +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/RefNameUtils.java @@ -234,6 +234,18 @@ public class RefNameUtils { return sb.toString(); } } + + public static boolean isTermRefname(String specifier) { + boolean result = true; + + try { + AuthorityTermInfo authorityTermInfo = RefNameUtils.parseAuthorityTermInfo(specifier); + } catch (Exception e) { + result = false; + } + + return result; + } /* * Returns the name / shortIdentifier value of an authority item in a refName diff --git a/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java b/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java index ae2f1f355..6391eb98a 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java +++ b/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java @@ -333,6 +333,7 @@ public abstract class NuxeoBasedResource @Path("{csid}") public Response get( @Context Request request, + @Context ResourceMap resourceMap, @Context UriInfo uriInfo, @PathParam("csid") String csid) { uriInfo = new UriInfoWrapper(uriInfo); diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java index 72c4c89aa..62b956147 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java @@ -34,6 +34,8 @@ import org.collectionspace.services.common.CSWebApplicationException; import org.collectionspace.services.common.ResourceMap; import org.collectionspace.services.common.ServiceMessages; import org.collectionspace.services.common.UriInfoWrapper; +import org.collectionspace.services.common.api.RefNameUtils; +import org.collectionspace.services.common.api.RefNameUtils.AuthorityTermInfo; import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.context.ServiceBindingUtils; import org.collectionspace.services.common.context.ServiceContext; @@ -570,6 +572,7 @@ public class VocabularyResource extends @Override public Response get( @Context Request request, + @Context ResourceMap resourceMap, @Context UriInfo uriInfo, @PathParam("csid") String specifier) { Response result = null; @@ -587,10 +590,16 @@ public class VocabularyResource extends queryParams.add(IClientQueryParams.PAGE_SIZE_PARAM, "0"); } } - - ServiceContext ctx = createServiceContext(request, uriInfo); - PoxPayloadOut payloadout = getAuthority(ctx, request, uriInfo, specifier, showItems); - result = buildResponse(ctx, payloadout); + if (RefNameUtils.isTermRefname(specifier)) { + AuthorityTermInfo authorityTermInfo = RefNameUtils.parseAuthorityTermInfo(specifier); + String parentIdentifier = Specifier.createShortIdURNValue(authorityTermInfo.inAuthority.name); + String itemIdentifier = Specifier.createShortIdURNValue(authorityTermInfo.name); + result = this.getAuthorityItemResponse(request, uriInfo, resourceMap, parentIdentifier, itemIdentifier); + } else { + ServiceContext 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); }