From: Patrick Schmitz Date: Tue, 15 Jun 2010 06:28:51 +0000 (+0000) Subject: CSPACE-590 Added support to get list of items for a vocab using the vocab shortId. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=f560207227cee200ab37a44fe3bc10947b4f07a0;p=tmp%2Fjakarta-migration.git CSPACE-590 Added support to get list of items for a vocab using the vocab shortId. --- diff --git a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java index 999b741d9..9b031f4d1 100644 --- a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java +++ b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java @@ -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 readItemListForNamedVocabulary(String specifier) { + return vocabularyProxy.readItemListForNamedVocabulary(specifier); + } + /** * Read item. * diff --git a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyProxy.java b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyProxy.java index 7440be340..a9ff1eab2 100644 --- a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyProxy.java +++ b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyProxy.java @@ -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 readItemList(@PathParam("vcsid") String vcsid); + + // List Items using the name of the Vocab + @GET + @Produces({"application/xml"}) + @Path("/urn:cspace:name({specifier})/items") + ClientResponse readItemListForNamedVocabulary(@PathParam("specifier") String specifier); //(C)reate Item @POST diff --git a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java index ea5deea28..01c402e22 100644 --- a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java +++ b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java @@ -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 res = - client.readItemList(vcsid); + ClientResponse 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(); 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 d5cc5391a..522b3aca3 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 @@ -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 queryParams = ui.getQueryParameters(); + String whereClause = + VocabularyJAXBSchema.VOCABULARIES_COMMON+ + ":"+VocabularyJAXBSchema.SHORT_IDENTIFIER+ + "='"+specifier+"'"; + // Need to get an Authority by name + ServiceContext 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. *