]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-590 Added support to get list of items for a vocab using the vocab shortId.
authorPatrick Schmitz <pschmitz@berkeley.edu>
Tue, 15 Jun 2010 06:28:51 +0000 (06:28 +0000)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Tue, 15 Jun 2010 06:28:51 +0000 (06:28 +0000)
services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java
services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyProxy.java
services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java
services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java

index 999b741d95c6f5c99e9e00000a4e4f2438d4d153..9b031f4d1c87f32a78b4831588342f48e6fbb89e 100644 (file)
@@ -175,6 +175,16 @@ public class VocabularyClient extends AbstractServiceClientImpl {
         return vocabularyProxy.readItemList(vcsid);
     }
 
+    /**
+     * Read item list for named vocabulary.
+     *
+     * @param specifier the specifier
+     * @return the client response
+     */
+    public ClientResponse<VocabularyitemsCommonList> readItemListForNamedVocabulary(String specifier) {
+        return vocabularyProxy.readItemListForNamedVocabulary(specifier);
+    }
+
     /**
      * Read item.
      *
index 7440be3407fcaa5bd30b8da8708c9969ad6a4bef..a9ff1eab2db095adb70575f17fa795485d3af710 100644 (file)
@@ -8,7 +8,10 @@ import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.vocabulary.VocabulariesCommonList;
 import org.collectionspace.services.vocabulary.VocabularyitemsCommonList;
@@ -58,6 +61,12 @@ public interface VocabularyProxy extends CollectionSpaceProxy {
     @Produces({"application/xml"})
     @Path("/{vcsid}/items/")
     ClientResponse<VocabularyitemsCommonList> readItemList(@PathParam("vcsid") String vcsid);
+    
+    // List Items using the name of the Vocab
+    @GET
+    @Produces({"application/xml"})
+    @Path("/urn:cspace:name({specifier})/items")
+    ClientResponse<VocabularyitemsCommonList> readItemListForNamedVocabulary(@PathParam("specifier") String specifier);
 
     //(C)reate Item
     @POST
index ea5deea28f3e307c077a3e578f720e0b9e4f81ff..01c402e22e90c146158b57c8eb2dac18fe9c5ae3 100644 (file)
@@ -187,7 +187,7 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl {
 
     @Override
     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
-            dependsOnMethods = {"create", "createItem"})
+            dependsOnMethods = {"create", "createItem", "readItem"})
     public void createList(String testName) throws Exception {
         for (int i = 0; i < 3; i++) {
                // Force create to reset the known resource info
@@ -682,28 +682,39 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl {
                         item.getDisplayName());
                 logger.debug(testName + ": list-item[" + i + "] URI=" +
                         item.getUri());
-                readItemList(csid);
+                readItemListInt(csid, null, "readList");
                 i++;
             }
         }
     }
 
-    @Test(dependsOnMethods = {"createList", "readItem"})
-    public void readItemList() {
-        readItemList(knownResourceId);
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+            dependsOnMethods = {"createList", "readItem"})
+    public void readItemList(String testName) {
+       readItemListInt(knownResourceId, null, testName);
     }
 
-    private void readItemList(String vcsid) {
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+            dependsOnMethods = {"createList", "readItem"})
+    public void readItemListByName(String testName) {
+       readItemListInt(null, knownResourceShortIdentifer, testName);
+    }
 
-        final String testName = "readItemList";
+    private void readItemListInt(String vcsid, String shortId, String testName) {
 
         // Perform setup.
         setupReadList();
 
         // Submit the request to the service and store the response.
         VocabularyClient client = new VocabularyClient();
-        ClientResponse<VocabularyitemsCommonList> res =
-                client.readItemList(vcsid);
+        ClientResponse<VocabularyitemsCommonList> res = null;
+        if(vcsid!=null) {
+            res = client.readItemList(vcsid);
+        } else if(shortId!=null) {
+            res = client.readItemListForNamedVocabulary(shortId);
+        } else {
+               Assert.fail("Internal Error: readItemList both vcsid and shortId are null!");
+        }
         VocabularyitemsCommonList list = res.getEntity();
         int statusCode = res.getStatus();
 
index d5cc5391a85452fd0b8384e628e0750f548d1695..522b3aca3cd952de8b62b82f60806bc94c0dddbd 100644 (file)
@@ -595,6 +595,50 @@ public class VocabularyResource extends
         return vocabularyItemObjectList;
     }
 
+    
+    /**
+     * Gets the vocabulary item list.
+     * 
+     * @param parentcsid the parentcsid
+     * @param partialTerm the partial term
+     * @param ui the ui
+     * 
+     * @return the vocabulary item list
+     */
+    @GET
+    @Path("urn:cspace:name({specifier})/items")
+    @Produces("application/xml")
+    public VocabularyitemsCommonList getVocabularyItemListByVocabName(
+            @PathParam("specifier") String specifier,
+            @QueryParam(IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,
+            @Context UriInfo ui) {
+        try {
+               MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+               String whereClause =
+                       VocabularyJAXBSchema.VOCABULARIES_COMMON+
+                       ":"+VocabularyJAXBSchema.SHORT_IDENTIFIER+
+                       "='"+specifier+"'";
+               // Need to get an Authority by name
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
+               String parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
+               return getVocabularyItemList(parentcsid, partialTerm, ui);
+        } catch (UnauthorizedException ue) {
+            Response response = Response.status(
+                    Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
+            throw new WebApplicationException(response);
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Caught exception in getVocabularyItemListByVocabName", e);
+            }
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
+       
+    }
+    
+    
+
     /**
      * Update vocabulary item.
      *