]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-202: Added 'showItems' query param to GET requests on vocabularies that will...
authorremillet <remillet@yahoo.com>
Tue, 16 Jan 2018 19:41:52 +0000 (11:41 -0800)
committerremillet <remillet@yahoo.com>
Tue, 16 Jan 2018 19:41:52 +0000 (11:41 -0800)
.gitignore
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/client/src/main/java/org/collectionspace/services/client/PoxPayload.java
services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java
services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java
services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java

index b7d897e979664c7a060fd377b02b8d30e52253d4..31642b6ffbf28eb8f6b885b47168bfeec1053b2b 100644 (file)
@@ -1,3 +1,4 @@
+*.out*
 *.iml
 *.org.*.bindings.xml
 *org.eclipse.wst*
index f1d81fab4385c14cc884e776b35f8c045e25ca00..7277ca066d1434137c47197781ca6287201ed446 100644 (file)
@@ -44,6 +44,7 @@ import javax.ws.rs.core.Response.ResponseBuilder;
 
 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;
@@ -102,12 +103,15 @@ import org.slf4j.LoggerFactory;
  * 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;
@@ -118,9 +122,9 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
         
     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.
      */
@@ -383,7 +387,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
                    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);
@@ -407,7 +411,20 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
                
        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.
      * 
@@ -424,29 +441,11 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             @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);
         }
@@ -460,6 +459,38 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
 
         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.
@@ -478,7 +509,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             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
@@ -1332,7 +1363,6 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
      * @param itemIdentifier
      * @throws Exception
      */
-    @SuppressWarnings("rawtypes")
        public boolean deleteAuthorityItem(ServiceContext<PoxPayloadIn, PoxPayloadOut> existingCtx,
             String parentIdentifier,
             String itemIdentifier,
index b495d1848708d6963b87929372d8a94311ea18c0..52508e5530f5eb42be6c2d3ce0aafdf537ca805e 100644 (file)
@@ -40,6 +40,10 @@ public abstract class PoxPayload<PT extends PayloadPart> {
        /** The Constant logger. */
        protected static final Logger logger = LoggerFactory.getLogger(PayloadPart.class);      
        
+       /** String constant for JAX-B root element labels */
+       public static final String DOCUMENT_ROOT_ELEMENT_LABEL = "document";
+       public static final String ABSTRACT_COMMON_LIST_ROOT_ELEMENT_LABEL = "abstract-common-list";
+       
        /** The xml text. */
        private String xmlPayload;
        
@@ -53,7 +57,8 @@ public abstract class PoxPayload<PT extends PayloadPart> {
        private List<PT> parts = new ArrayList<PT>();
        
        // Valid root element labels
-       private static Set<String> validRootElementLabels = new HashSet<String>(Arrays.asList("document", "abstract-common-list"));
+       private static Set<String> validRootElementLabels = new HashSet<String>(Arrays.asList(DOCUMENT_ROOT_ELEMENT_LABEL, 
+                       ABSTRACT_COMMON_LIST_ROOT_ELEMENT_LABEL));
        
        /**
         * Instantiates a new pox payload.
index 57dc5c4e90c26177f91f096c23fe097ae689bc48..6f668f619c2993066dbd029e541e5d0a3f4ca583 100644 (file)
@@ -708,6 +708,13 @@ public abstract class AbstractCollectionSpaceResourceImpl<IT, OT>
        return getCacheControl(ctx, "default"); // Look for a default one if we couldn't find based on the resource request
     }
     
+    /**
+     * FIXME: This code around cache control needs some documentation.
+     * 
+     * @param ctx
+     * @param cacheKey
+     * @return
+     */
     protected CacheControl getCacheControl(ServiceContext<IT, OT> ctx, String cacheKey) {
        CacheControl result = null;
        
index 91a1888feb3e0613e6549416144fdce0be421de2..3159c1b6d6bc5cd7f122c4aba90cb3f79d21c921 100644 (file)
@@ -38,6 +38,7 @@ public class VocabularyClient extends AuthorityClientImpl<VocabulariesCommon, Vo
        public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
        public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME;
     public static final String TERM_INFO_GROUP_XPATH_BASE = "vocabularyTermGroup";
+       public static String SHOW_ITEMS_QP = "showItems"; // query param on GET of vocabulary to get list of items included in the result payload
        //
        // Subitem constants
        //
index 3f454e793e62c12625e43af3253244a8e6370667..30a48c913583717cd451763abc00fc5da535ede1 100644 (file)
@@ -26,16 +26,26 @@ package org.collectionspace.services.vocabulary;
 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 
@@ -55,6 +65,38 @@ 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;