]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-658: Add API endpoint to vocab/authorities to request a term record using a...
authorRichard Millet <remillet@gmail.com>
Tue, 28 May 2019 19:22:04 +0000 (12:22 -0700)
committerRichard Millet <remillet@gmail.com>
Tue, 28 May 2019 19:22:04 +0000 (12:22 -0700)
services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CSpaceResteasyBootstrap.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/AbstractBatchJob.java
services/common-api/src/main/java/org/collectionspace/services/common/api/RefNameUtils.java
services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java
services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java

index 0a8cbc79734cbb33bebedd094487b461c3ce6fe2..c60dc923a071c4f5d5f39962e785efa592bcd938 100644 (file)
@@ -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
                }
index c6736e33298d614556e6aec3f73ec82de0315f09..3c52763d9c9e85d1a1039e82aeb515df004763e5 100644 (file)
@@ -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<AuthCommon, AuthItemHandler>
     @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<PoxPayloadIn, PoxPayloadOut> 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<PoxPayloadIn, PoxPayloadOut> 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<AuthCommon, AuthItemHandler>
             @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<PoxPayloadIn, PoxPayloadOut> ctx = 
                     (RemoteServiceContext<PoxPayloadIn, PoxPayloadOut>) createServiceContext(getItemServiceName(), resourceMap, uriInfo);
@@ -1065,8 +1094,35 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             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<PoxPayloadIn, PoxPayloadOut> ctx = null;
+        
+        try {
+            ctx = (RemoteServiceContext<PoxPayloadIn, PoxPayloadOut>) 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
index b2e0e14343628d44f60568cf7d45eee078219924..a9b9af5f463cb1494a2a9f6aba28d82d10737410 100644 (file)
@@ -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);
 
index e117600b087e17e6fc118c7b790b84cc224ace38..13802afe5216141469f45eb106865b496a7e29fd 100644 (file)
@@ -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
index ae2f1f355db579aa607969c4cdeeecd9bca246c4..6391eb98a85c9482ecc7724670b58aac354f6e0d 100644 (file)
@@ -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);
index 72c4c89aa0c63d5de4110397f62d586b6597dc76..62b9561474897649d0c1f4bd2b0b27d8cfd3fcaa 100644 (file)
@@ -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<PoxPayloadIn, PoxPayloadOut> 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<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);
         }