]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-590. Added support to get item list for a named OrgAuthority, based upon Perso...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Wed, 10 Mar 2010 00:33:25 +0000 (00:33 +0000)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Wed, 10 Mar 2010 00:33:25 +0000 (00:33 +0000)
services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java
services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java
services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java
services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityJAXBSchema.java
services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java
services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java

index e21dbfe3b53ff9f111dd9e38e5b98805f4a3a337..b4c071c7a03bd1d7038f0dff13d5d677d298e81d 100644 (file)
@@ -1,5 +1,6 @@
 package org.collectionspace.services.client;
 
+import javax.ws.rs.PathParam;
 import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.contact.ContactsCommonList;
@@ -90,6 +91,15 @@ public class OrgAuthorityClient extends AbstractServiceClientImpl {
         return orgAuthorityProxy.read(csid);
     }
 
+    /**
+     * @param name
+     * @return
+     * @see org.collectionspace.services.client.OrgAuthorityProxy#readByName(java.lang.String)
+     */
+    public ClientResponse<MultipartInput> readByName(String name) {
+        return orgAuthorityProxy.readByName(name);
+    }
+
     /**
      * @param orgAuthority
      * @return
@@ -127,6 +137,14 @@ public class OrgAuthorityClient extends AbstractServiceClientImpl {
         return orgAuthorityProxy.readItemList(vcsid);
     }
 
+    /**
+     * @return
+     * @see org.collectionspace.services.client.OrgAuthorityProxy#readItemListForNamedAuthority()
+     */
+    public ClientResponse<OrganizationsCommonList> readItemListForNamedAuthority(String specifier) {
+        return orgAuthorityProxy.readItemListForNamedAuthority(specifier);
+    }
+
     /**
      * @param csid
      * @return
index 97415e41b9139df9d55304bee874345a9729c717..74d88d01f1d52e71ad0d774e81236e3983bad492 100644 (file)
@@ -39,6 +39,11 @@ public interface OrgAuthorityProxy {
     @Path("/{csid}")
     ClientResponse<MultipartInput> read(@PathParam("csid") String csid);
 
+    //(R)ead by name
+    @GET
+    @Path("/urn:cspace:name({name})")
+    ClientResponse<MultipartInput> readByName(@PathParam("name") String name);
+
     //(U)pdate
     @PUT
     @Path("/{csid}")
@@ -55,6 +60,12 @@ public interface OrgAuthorityProxy {
     @Path("/{vcsid}/items/")
     ClientResponse<OrganizationsCommonList> readItemList(@PathParam("vcsid") String vcsid);
 
+    // List Items for a named authority
+    @GET
+    @Produces({"application/xml"})
+    @Path("/urn:cspace:name({specifier})/items/")
+    ClientResponse<OrganizationsCommonList> readItemListForNamedAuthority(@PathParam("specifier") String specifier);
+
     //(C)reate Item
     @POST
     @Path("/{vcsid}/items/")
index 2f3a2fceb4f3b8bd8f93542f703b9a56ccd64141..e749b73c41fcc3132861dc2cf354e05ba5ee9cbb 100644 (file)
@@ -72,6 +72,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
     private final String TEST_ORG_SHORTNAME = "Test Org";
     private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
     private String knownResourceId = null;
+    private String knownResourceDisplayName = null;
     private String knownResourceRefName = null;
     private String knownItemResourceId = null;
     private String knownContactResourceId = null;
@@ -128,6 +129,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
         // for additional tests below.
         if (knownResourceId == null){
             knownResourceId = newID;
+            knownResourceDisplayName = displayName;
             if (logger.isDebugEnabled()) {
                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
             }
@@ -393,6 +395,36 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
         }
     }
 
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+            groups = {"read"}, dependsOnGroups = {"create"})
+        public void readByName(String testName) throws Exception {
+
+            // Perform setup.
+            setupRead();
+            
+            // Submit the request to the service and store the response.
+            ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
+            int statusCode = res.getStatus();
+
+            // Check the status code of the response: does it match
+            // the expected response(s)?
+            if(logger.isDebugEnabled()){
+                logger.debug(testName + ": status = " + statusCode);
+            }
+            Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                    invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+            Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+            //FIXME: remove the following try catch once Aron fixes signatures
+            try {
+                MultipartInput input = (MultipartInput) res.getEntity();
+                OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
+                        client.getCommonPartName(), OrgauthoritiesCommon.class);
+                Assert.assertNotNull(orgAuthority);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+
 /*
     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
         groups = {"read"}, dependsOnMethods = {"read"})
@@ -752,7 +784,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
                         item.getDisplayName());
                 logger.debug(testName + ": list-item[" + i + "] URI=" +
                         item.getUri());
-                readItemList(csid);
+                readItemList(csid, null);
                 i++;
             }
         }
@@ -760,10 +792,15 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
 
     @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
     public void readItemList() {
-        readItemList(knownResourceId);
+        readItemList(knownResourceId, null);
     }
 
-    private void readItemList(String vcsid) {
+    @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
+    public void readItemListByAuthorityName() {
+        readItemList(null, knownResourceDisplayName);
+    }
+
+    private void readItemList(String vcsid, String name) {
 
         final String testName = "readItemList";
 
@@ -771,8 +808,17 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
         setupReadList(testName);
 
         // Submit the request to the service and store the response.
-        ClientResponse<OrganizationsCommonList> res =
-                client.readItemList(vcsid);
+        ClientResponse<OrganizationsCommonList> res = null;
+        
+        if(vcsid!= null) {
+               // Submit the request to the service and store the response.
+               res = client.readItemList(vcsid);
+        } else if(name!= null) {
+               // Submit the request to the service and store the response.
+               res = client.readItemListForNamedAuthority(name);
+        } else {
+               Assert.fail("readItemList passed null csid and name!");
+        }
         OrganizationsCommonList list = res.getEntity();
         int statusCode = res.getStatus();
 
@@ -888,7 +934,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
     // Success outcomes
     @Override
     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
-        groups = {"update"}, dependsOnGroups = {"create"})
+        groups = {"update"}, dependsOnGroups = {"read", "readList"})
     public void update(String testName) throws Exception {
 
         // Perform setup.
index ad674843b88e891cba3822a06e8e1c6757a45342..90798f9889d4478d5d463bfc4fd55cb1cc92dbc1 100644 (file)
@@ -8,6 +8,7 @@ package org.collectionspace.services;
  *\r
  */\r
 public interface OrgAuthorityJAXBSchema {\r
+       final static String ORGAUTHORITIES_COMMON = "orgauthorities_common";\r
        final static String DISPLAY_NAME = "displayName";\r
        final static String REF_NAME = "refName";\r
        final static String VOCAB_TYPE = "vocabType";\r
index f41add84e448c7cff9b97495b991953774e9b448..122867b2c753337f257293bb57aeb6391556f82b 100644 (file)
@@ -39,6 +39,7 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
+import org.collectionspace.services.OrgAuthorityJAXBSchema;
 import org.collectionspace.services.OrganizationJAXBSchema;
 import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
 import org.collectionspace.services.common.ClientType;
@@ -50,13 +51,13 @@ import org.collectionspace.services.common.document.BadRequestException;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
-import org.collectionspace.services.common.security.UnauthorizedException;
 import org.collectionspace.services.common.query.IQueryManager;
 import org.collectionspace.services.contact.ContactResource;
 import org.collectionspace.services.contact.ContactsCommon;
 import org.collectionspace.services.contact.ContactsCommonList;
 import org.collectionspace.services.contact.ContactJAXBSchema;
 import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler;
+import org.collectionspace.services.common.security.UnauthorizedException;
 import org.collectionspace.services.organization.nuxeo.OrganizationDocumentModelHandler;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
@@ -183,6 +184,65 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         }
     }
 
+
+    @GET
+    @Path("urn:cspace:name({specifier})")
+    public MultipartOutput getOrgAuthorityByName(@PathParam("specifier") String specifier) {
+        String idValue = null;
+        if (specifier == null) {
+            logger.error("getOrgAuthority: missing name!");
+            Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+                    "get failed on OrgAuthority (missing specifier)").type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        String whereClause =
+               OrgAuthorityJAXBSchema.ORGAUTHORITIES_COMMON+
+               ":"+OrgAuthorityJAXBSchema.DISPLAY_NAME+
+               "='"+specifier+"'";
+        // We only get a single doc - if there are multiple,
+        // it is an error in use.
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("getOrgAuthority with name=" + specifier);
+        } 
+        MultipartOutput result = null;
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            DocumentHandler handler = createDocumentHandler(ctx);
+            DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1);
+            handler.setDocumentFilter(myFilter);
+            getRepositoryClient(ctx).get(ctx, handler);
+            result = (MultipartOutput) ctx.getOutput();
+        } catch (UnauthorizedException ue) {
+            Response response = Response.status(
+                    Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
+            throw new WebApplicationException(response);
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("getOrgAuthority", dnfe);
+            }
+            Response response = Response.status(Response.Status.NOT_FOUND).entity(
+                    "Get failed on OrgAuthority spec=" + specifier).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("getOrgAuthority", e);
+            }
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        if (result == null) {
+            Response response = Response.status(Response.Status.NOT_FOUND).entity(
+                    "Get failed, the requested OrgAuthority spec:" + specifier + ": was not found.").type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        return result;
+    }
+
     @GET
     @Path("{csid}")
     public MultipartOutput getOrgAuthority(@PathParam("csid") String csid) {
@@ -482,6 +542,62 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         return organizationObjectList;
     }
 
+    @GET
+    @Path("urn:cspace:name({specifier})/items")
+    @Produces("application/xml")
+    public OrganizationsCommonList getOrganizationListByAuthName(
+               @PathParam("specifier") String parentSpecifier,
+            @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,            
+            @Context UriInfo ui) {
+       OrganizationsCommonList personObjectList = new OrganizationsCommonList();
+        try {
+            String whereClause =
+               OrgAuthorityJAXBSchema.ORGAUTHORITIES_COMMON+
+               ":"+OrgAuthorityJAXBSchema.DISPLAY_NAME+
+               "='"+parentSpecifier+"'";
+            // Need to get an Authority by name
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            String parentcsid = 
+               getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
+
+            ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
+            DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+            MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+            DocumentFilter myFilter = new DocumentFilter();
+            myFilter.setPagination(queryParams);
+
+            // Add the where clause "organizations_common:inAuthority='" + parentcsid + "'"
+            myFilter.setWhereClause(OrganizationJAXBSchema.ORGANIZATIONS_COMMON + ":" +
+                       OrganizationJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'");
+            
+            // AND organizations_common:displayName LIKE '%partialTerm%'
+            if (partialTerm != null && !partialTerm.isEmpty()) {
+               String ptClause = "AND " +
+               OrganizationJAXBSchema.ORGANIZATIONS_COMMON + ":" +
+               OrganizationJAXBSchema.DISPLAY_NAME +
+                       " LIKE " +
+                       "'%" + partialTerm + "%'";
+               myFilter.appendWhereClause(ptClause);
+            }
+            
+            handler.setDocumentFilter(myFilter);
+            getRepositoryClient(ctx).getFiltered(ctx, handler);
+            personObjectList = (OrganizationsCommonList) handler.getCommonPartList();
+        } 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 getOrganizationListByAuthName", e);
+            }
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        return personObjectList;
+    }
+
     @PUT
     @Path("{csid}/items/{itemcsid}")
     public MultipartOutput updateOrganization(
index 772c3174f4903ee81a4c885b7e61e75d442ff46d..cfb962a7f18fdf6d910a04641627e56339b11c79 100644 (file)
@@ -557,7 +557,7 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
                PersonAuthorityJAXBSchema.PERSONAUTHORITIES_COMMON+
                ":"+PersonAuthorityJAXBSchema.DISPLAY_NAME+
                "='"+parentSpecifier+"'";
-            // Need to get an Authoirty by name
+            // Need to get an Authority by name
             ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             String parentcsid = 
                getRepositoryClient(ctx).findDocCSID(ctx, whereClause);