]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1079: Added getReferencingObjects() support to Organization service.
authorRichard Millet <richard.millet@berkeley.edu>
Tue, 11 May 2010 21:08:05 +0000 (21:08 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Tue, 11 May 2010 21:08:05 +0000 (21:08 +0000)
services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java
services/intake/client/pom.xml
services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java [new file with mode: 0644]
services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java
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/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java
services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java

index 3e01d21e2d5e342bc4385274416f39fe75af11a1..0706ccc6dfbbdbbcac078ac6d53818797847ce4c 100644 (file)
@@ -65,7 +65,7 @@ public class PerformanceTest extends CollectionSpacePerformanceTest {
        // Get clients for the CollectionSpace services
        //
        /** The MA x_ records. */
-       private static int MAX_RECORDS = 100;
+       private static int MAX_RECORDS = 1000;
 
        /**
         * Performance test.
index 09b15d019611027817feca77c06fd8ebaf2b4c9a..04b698a1ce4ff416b55a0bfdaa0c481e3bb7a596 100644 (file)
             <artifactId>org.collectionspace.services.person.client</artifactId>\r
             <version>${project.version}</version>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>org.collectionspace.services</groupId>\r
+            <artifactId>org.collectionspace.services.organization.client</artifactId>\r
+            <version>${project.version}</version>\r
+        </dependency>\r
 <!-- External dependencies -->        \r
         <dependency>\r
             <groupId>org.testng</groupId>\r
diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java
new file mode 100644 (file)
index 0000000..4c7be74
--- /dev/null
@@ -0,0 +1,350 @@
+/**\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright © 2009 Regents of the University of California\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.collectionspace.services.client.test;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.ws.rs.core.MediaType;\r
+import javax.ws.rs.core.Response;\r
+\r
+import org.collectionspace.services.OrganizationJAXBSchema;\r
+import org.collectionspace.services.client.CollectionSpaceClient;\r
+import org.collectionspace.services.client.IntakeClient;\r
+import org.collectionspace.services.client.OrgAuthorityClient;\r
+import org.collectionspace.services.client.OrgAuthorityClientUtils;\r
+import org.collectionspace.services.common.authorityref.AuthorityRefDocList;\r
+import org.collectionspace.services.intake.IntakesCommon;\r
+//import org.collectionspace.services.intake.IntakesCommonList;\r
+import org.collectionspace.services.jaxb.AbstractCommonList;\r
+\r
+import org.jboss.resteasy.client.ClientResponse;\r
+\r
+//import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
+import org.jboss.resteasy.plugins.providers.multipart.OutputPart;\r
+import org.testng.Assert;\r
+import org.testng.annotations.AfterClass;\r
+import org.testng.annotations.Test;\r
+\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+/**\r
+ * OrganizationAuthRefDocsTest, carries out tests against a\r
+ * deployed and running Organization Service.\r
+ *\r
+ * $LastChangedRevision: 1327 $\r
+ * $LastChangedDate: 2010-02-12 10:35:11 -0800 (Fri, 12 Feb 2010) $\r
+ */\r
+public class OrganizationAuthRefDocsTest extends BaseServiceTest {\r
+\r
+   private final Logger logger =\r
+       LoggerFactory.getLogger(OrganizationAuthRefDocsTest.class);\r
+\r
+    // Instance variables specific to this test.\r
+    final String SERVICE_PATH_COMPONENT = "intakes";\r
+    final String ORGANIZATION_AUTHORITY_NAME = "TestOrganizationAuth";\r
+    private String knownIntakeId = null;\r
+    private List<String> intakeIdsCreated = new ArrayList<String>();\r
+    private List<String> orgIdsCreated = new ArrayList<String>();\r
+    private int CREATED_STATUS = Response.Status.CREATED.getStatusCode();\r
+    private int OK_STATUS = Response.Status.OK.getStatusCode();\r
+    private String orgAuthCSID = null; \r
+    private String currentOwnerOrgCSID = null; \r
+    private String currentOwnerRefName = null;\r
+    private String depositorRefName = null;\r
+    private String conditionCheckAssesorRefName = null;\r
+    private String insurerRefName = null;\r
+    private String fieldCollectorRefName = null;\r
+    private String valuerRefName = null;\r
+    private final int NUM_AUTH_REF_DOCS_EXPECTED = 1;\r
+\r
+    /* (non-Javadoc)\r
+     * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()\r
+     */\r
+    @Override\r
+    protected CollectionSpaceClient getClientInstance() {\r
+       throw new UnsupportedOperationException(); //method not supported (or needed) in this test class\r
+    }\r
+    \r
+    /* (non-Javadoc)\r
+     * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)\r
+     */\r
+    @Override\r
+       protected AbstractCommonList getAbstractCommonList(\r
+                       ClientResponse<AbstractCommonList> response) {\r
+       throw new UnsupportedOperationException(); //method not supported (or needed) in this test class\r
+    }\r
+\r
+    // ---------------------------------------------------------------\r
+    // CRUD tests : CREATE tests\r
+    // ---------------------------------------------------------------\r
+    // Success outcomes\r
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)\r
+    public void createIntakeWithAuthRefs(String testName) throws Exception {\r
+\r
+        testSetup(CREATED_STATUS, ServiceRequestType.CREATE,testName);\r
+\r
+        // Submit the request to the service and store the response.\r
+        String identifier = createIdentifier();\r
+        \r
+        // Create all the organization refs and entities\r
+        createOrgRefs();\r
+\r
+        IntakeClient intakeClient = new IntakeClient();\r
+        MultipartOutput multipart = createIntakeInstance(\r
+                "entryNumber-" + identifier,\r
+                "entryDate-" + identifier,\r
+                                                               currentOwnerRefName,\r
+                                                               depositorRefName,\r
+                                                               conditionCheckAssesorRefName,\r
+                                                               insurerRefName,\r
+                                                               fieldCollectorRefName,\r
+                                                               valuerRefName );\r
+\r
+        ClientResponse<Response> res = intakeClient.create(multipart);\r
+        try {\r
+               int statusCode = res.getStatus();\r
+       \r
+               // Check the status code of the response: does it match\r
+               // the expected response(s)?\r
+               //\r
+               // Specifically:\r
+               // Does it fall within the set of valid status codes?\r
+               // Does it exactly match the expected status code?\r
+               if(logger.isDebugEnabled()){\r
+                   logger.debug(testName + ": status = " + statusCode);\r
+               }\r
+               Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),\r
+                       invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+               Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);\r
+        } finally {\r
+               res.releaseConnection();\r
+        }\r
+\r
+        // Store the ID returned from the first resource created\r
+        // for additional tests below.\r
+        if (knownIntakeId == null){\r
+            knownIntakeId = extractId(res);\r
+            if (logger.isDebugEnabled()) {\r
+                logger.debug(testName + ": knownIntakeId=" + knownIntakeId);\r
+            }\r
+        }\r
+        \r
+        // Store the IDs from every resource created by tests,\r
+        // so they can be deleted after tests have been run.\r
+        intakeIdsCreated.add(extractId(res));\r
+    }\r
+    \r
+    /**\r
+     * Creates the organization refs.\r
+     */\r
+    protected void createOrgRefs(){\r
+        OrgAuthorityClient orgAuthClient = new OrgAuthorityClient();\r
+       String authRefName = \r
+               OrgAuthorityClientUtils.createOrgAuthRefName(ORGANIZATION_AUTHORITY_NAME, false);\r
+       MultipartOutput multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(\r
+                       ORGANIZATION_AUTHORITY_NAME, authRefName, orgAuthClient.getCommonPartName());\r
+        ClientResponse<Response> res = orgAuthClient.create(multipart);\r
+        int statusCode = res.getStatus();\r
+\r
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),\r
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+        Assert.assertEquals(statusCode, CREATED_STATUS);\r
+        orgAuthCSID = extractId(res);\r
+        \r
+        currentOwnerRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
+                                                               authRefName, "Olivier Owner", true);\r
+                               currentOwnerOrgCSID = createOrganization("Olivier", "Owner", currentOwnerRefName);\r
+        orgIdsCreated.add(currentOwnerOrgCSID);\r
+        \r
+        depositorRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
+                                                                       authRefName, "Debbie Depositor", true);\r
+        orgIdsCreated.add(createOrganization("Debbie", "Depositor", depositorRefName));\r
+        \r
+        conditionCheckAssesorRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
+                                                                       authRefName, "Andrew Assessor", true);\r
+        orgIdsCreated.add(createOrganization("Andrew", "Assessor", conditionCheckAssesorRefName));\r
+        \r
+        insurerRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
+                                                                       authRefName, "Ingrid Insurer", true);\r
+        orgIdsCreated.add(createOrganization("Ingrid", "Insurer", insurerRefName));\r
+        \r
+        fieldCollectorRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
+                                                                       authRefName, "Connie Collector", true);\r
+        orgIdsCreated.add(createOrganization("Connie", "Collector", fieldCollectorRefName));\r
+        \r
+        valuerRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
+                                                                       authRefName, "Vince Valuer", true);\r
+        orgIdsCreated.add(createOrganization("Vince", "Valuer", valuerRefName));\r
+        \r
+\r
+    }\r
+    \r
+    protected String createOrganization(String shortName, String longName, String refName ) {\r
+        OrgAuthorityClient orgAuthClient = new OrgAuthorityClient();\r
+        Map<String, String> orgInfo = new HashMap<String,String>();\r
+        orgInfo.put(OrganizationJAXBSchema.SHORT_NAME, shortName);\r
+        orgInfo.put(OrganizationJAXBSchema.LONG_NAME, longName);\r
+       MultipartOutput multipart = \r
+               OrgAuthorityClientUtils.createOrganizationInstance(orgAuthCSID, \r
+                               refName, orgInfo, orgAuthClient.getItemCommonPartName());\r
+        ClientResponse<Response> res = orgAuthClient.createItem(orgAuthCSID, multipart);\r
+        int statusCode = res.getStatus();\r
+\r
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),\r
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+        Assert.assertEquals(statusCode, CREATED_STATUS);\r
+       return extractId(res);\r
+    }\r
+\r
+    // Success outcomes\r
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,\r
+        dependsOnMethods = {"createIntakeWithAuthRefs"})\r
+    public void readAndCheckAuthRefDocs(String testName) throws Exception {\r
+\r
+        // Perform setup.\r
+        testSetup(OK_STATUS, ServiceRequestType.READ,testName);\r
+        \r
+        // Get the auth ref docs and check them\r
+       OrgAuthorityClient orgAuthClient = new OrgAuthorityClient();\r
+       ClientResponse<AuthorityRefDocList> refDocListResp =\r
+               orgAuthClient.getReferencingObjects(orgAuthCSID, currentOwnerOrgCSID);\r
+\r
+        int statusCode = refDocListResp.getStatus();\r
+\r
+        if(logger.isDebugEnabled()){\r
+            logger.debug(testName + ".getReferencingObjects: status = " + statusCode);\r
+        }\r
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),\r
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);\r
+        AuthorityRefDocList list = refDocListResp.getEntity();\r
+\r
+        // Optionally output additional data about list members for debugging.\r
+        boolean iterateThroughList = true;\r
+        boolean fFoundIntake = false;\r
+        if(iterateThroughList && logger.isDebugEnabled()){\r
+            List<AuthorityRefDocList.AuthorityRefDocItem> items =\r
+                    list.getAuthorityRefDocItem();\r
+            int i = 0;\r
+            logger.debug(testName + ": Docs that use: " + currentOwnerRefName);\r
+            for(AuthorityRefDocList.AuthorityRefDocItem item : items){\r
+                logger.debug(testName + ": list-item[" + i + "] " +\r
+                               item.getDocType() + "(" +\r
+                               item.getDocId() + ") Name:[" +\r
+                               item.getDocName() + "] Number:[" +\r
+                               item.getDocNumber() + "] in field:[" +\r
+                               item.getSourceField() + "]");\r
+                if(!fFoundIntake && knownIntakeId.equalsIgnoreCase(item.getDocId())) {\r
+                               fFoundIntake = true;\r
+                }\r
+                i++;\r
+            }\r
+            Assert.assertTrue(fFoundIntake, "Did not find Intake with authref!");\r
+        }\r
+    }\r
+\r
+\r
+    // ---------------------------------------------------------------\r
+    // Cleanup of resources created during testing\r
+    // ---------------------------------------------------------------\r
+\r
+    /**\r
+     * Deletes all resources created by tests, after all tests have been run.\r
+     *\r
+     * This cleanup method will always be run, even if one or more tests fail.\r
+     * For this reason, it attempts to remove all resources created\r
+     * at any point during testing, even if some of those resources\r
+     * may be expected to be deleted by certain tests.\r
+     */\r
+    @AfterClass(alwaysRun=true)\r
+    public void cleanUp() {\r
+        String noTest = System.getProperty("noTestCleanup");\r
+       if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {\r
+            if (logger.isDebugEnabled()) {\r
+                logger.debug("Skipping Cleanup phase ...");\r
+            }\r
+            return;\r
+       }\r
+        if (logger.isDebugEnabled()) {\r
+            logger.debug("Cleaning up temporary resources created for testing ...");\r
+        }\r
+        IntakeClient intakeClient = new IntakeClient();\r
+        // Note: Any non-success responses are ignored and not reported.\r
+        for (String resourceId : intakeIdsCreated) {\r
+            ClientResponse<Response> res = intakeClient.delete(resourceId);\r
+            res.releaseConnection();\r
+        }\r
+        // Delete persons before PersonAuth\r
+        OrgAuthorityClient personAuthClient = new OrgAuthorityClient();\r
+        for (String resourceId : orgIdsCreated) {\r
+            ClientResponse<Response> res = personAuthClient.deleteItem(orgAuthCSID, resourceId);\r
+            res.releaseConnection();\r
+        }\r
+        if (orgAuthCSID != null) {\r
+               personAuthClient.delete(orgAuthCSID).releaseConnection();\r
+        }\r
+    }\r
+\r
+    // ---------------------------------------------------------------\r
+    // Utility methods used by tests above\r
+    // ---------------------------------------------------------------\r
+    @Override\r
+    public String getServicePathComponent() {\r
+        return SERVICE_PATH_COMPONENT;\r
+    }\r
+\r
+   private MultipartOutput createIntakeInstance(String entryNumber,\r
+               String entryDate,\r
+                               String currentOwner,\r
+                               String depositor,\r
+                               String conditionCheckAssesor,\r
+                               String insurer,\r
+                               String fieldCollector,\r
+                               String Valuer ) {\r
+        IntakesCommon intake = new IntakesCommon();\r
+        intake.setEntryNumber(entryNumber);\r
+        intake.setEntryDate(entryDate);\r
+        intake.setCurrentOwner(currentOwner);\r
+        intake.setDepositor(depositor);\r
+        intake.setConditionCheckAssesor(conditionCheckAssesor);\r
+        intake.setInsurer(insurer);\r
+        intake.setFieldCollector(fieldCollector);\r
+        intake.setValuer(Valuer);\r
+        MultipartOutput multipart = new MultipartOutput();\r
+        OutputPart commonPart =\r
+            multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);\r
+        commonPart.getHeaders().add("label", new IntakeClient().getCommonPartName());\r
+\r
+        if(logger.isDebugEnabled()){\r
+            logger.debug("to be created, intake common");\r
+            logger.debug(objectAsXmlString(intake, IntakesCommon.class));\r
+        }\r
+\r
+        return multipart;\r
+    }\r
+}\r
index 22bc8372856860f0e8d2c5b8319aac4155cb450a..d327824e25d60c3e8eeda27955a1952733d2366d 100644 (file)
@@ -37,12 +37,12 @@ import org.collectionspace.services.client.PersonAuthorityClient;
 import org.collectionspace.services.client.PersonAuthorityClientUtils;
 import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
 import org.collectionspace.services.intake.IntakesCommon;
-import org.collectionspace.services.intake.IntakesCommonList;
+//import org.collectionspace.services.intake.IntakesCommonList;
 import org.collectionspace.services.jaxb.AbstractCommonList;
 
 import org.jboss.resteasy.client.ClientResponse;
 
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+//import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
 import org.testng.Assert;
@@ -68,8 +68,8 @@ public class PersonAuthRefDocsTest extends BaseServiceTest {
     final String SERVICE_PATH_COMPONENT = "intakes";
     final String PERSON_AUTHORITY_NAME = "TestPersonAuth";
     private String knownIntakeId = null;
-    private List<String> intakeIdsCreated = new ArrayList();
-    private List<String> personIdsCreated = new ArrayList();
+    private List<String> intakeIdsCreated = new ArrayList<String>();
+    private List<String> personIdsCreated = new ArrayList<String>();
     private int CREATED_STATUS = Response.Status.CREATED.getStatusCode();
     private int OK_STATUS = Response.Status.OK.getStatusCode();
     private String personAuthCSID = null; 
@@ -126,21 +126,24 @@ public class PersonAuthRefDocsTest extends BaseServiceTest {
                                                                valuerRefName );
 
         ClientResponse<Response> res = intakeClient.create(multipart);
-
-        int statusCode = res.getStatus();
-
-        // Check the status code of the response: does it match
-        // the expected response(s)?
-        //
-        // Specifically:
-        // Does it fall within the set of valid status codes?
-        // Does it exactly match the expected status code?
-        if(logger.isDebugEnabled()){
-            logger.debug(testName + ": status = " + statusCode);
+        try {
+               int statusCode = res.getStatus();
+       
+               // Check the status code of the response: does it match
+               // the expected response(s)?
+               //
+               // Specifically:
+               // Does it fall within the set of valid status codes?
+               // Does it exactly match the expected status code?
+               if(logger.isDebugEnabled()){
+                   logger.debug(testName + ": status = " + statusCode);
+               }
+               Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                       invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+               Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        } finally {
+               res.releaseConnection();
         }
-        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
 
         // Store the ID returned from the first resource created
         // for additional tests below.
@@ -156,6 +159,9 @@ public class PersonAuthRefDocsTest extends BaseServiceTest {
         intakeIdsCreated.add(extractId(res));
     }
     
+    /**
+     * Creates the person refs.
+     */
     protected void createPersonRefs(){
         PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
        String authRefName = 
@@ -291,14 +297,16 @@ public class PersonAuthRefDocsTest extends BaseServiceTest {
         // Note: Any non-success responses are ignored and not reported.
         for (String resourceId : intakeIdsCreated) {
             ClientResponse<Response> res = intakeClient.delete(resourceId);
+            res.releaseConnection();
         }
         // Delete persons before PersonAuth
         PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
         for (String resourceId : personIdsCreated) {
             ClientResponse<Response> res = personAuthClient.deleteItem(personAuthCSID, resourceId);
+            res.releaseConnection();
         }
         if (personAuthCSID != null) {
-               personAuthClient.delete(personAuthCSID);
+               personAuthClient.delete(personAuthCSID).releaseConnection();
         }
     }
 
index 5894be657a1110a31513fd548a3c85111cfeb7c9..b6b954d33f432ef0f79b27f8ff60f3b62b034203 100644 (file)
@@ -29,6 +29,7 @@ package org.collectionspace.services.client;
 //import javax.ws.rs.PathParam;
 import javax.ws.rs.core.Response;
 
+import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.contact.ContactsCommonList;
 import org.collectionspace.services.organization.OrgauthoritiesCommonList;
@@ -165,6 +166,7 @@ public class OrgAuthorityClient extends AbstractServiceClientImpl {
      * @param csid the csid
      * @return the client response
      */
+    @Override
     public ClientResponse<Response> delete(String csid) {
         return orgAuthorityProxy.delete(csid);
     }
@@ -178,6 +180,18 @@ public class OrgAuthorityClient extends AbstractServiceClientImpl {
     public ClientResponse<OrganizationsCommonList> readItemList(String vcsid) {
         return orgAuthorityProxy.readItemList(vcsid);
     }
+    
+    /**
+     * Gets the referencing objects.
+     *
+     * @param parentcsid the parentcsid
+     * @param csid the csid
+     * @return the referencing objects
+     */
+    public ClientResponse<AuthorityRefDocList> getReferencingObjects(String parentcsid, String csid) {
+        return orgAuthorityProxy.getReferencingObjects(parentcsid, csid);
+    }
+    
 
     /**
      * Read item list for named authority.
index 600e0a6d89413305963056130f77cd78a62687a1..54f2091cef632c1d014126a534f6aabff280f88d 100644 (file)
@@ -10,6 +10,7 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Response;
 
+import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.contact.ContactsCommonList;
 import org.collectionspace.services.organization.OrgauthoritiesCommonList;
@@ -60,6 +61,20 @@ public interface OrgAuthorityProxy extends CollectionSpaceProxy {
     @Produces({"application/xml"})
     @Path("/{vcsid}/items/")
     ClientResponse<OrganizationsCommonList> readItemList(@PathParam("vcsid") String vcsid);
+    
+    /**
+     * @param parentcsid 
+     * @param itemcsid 
+     * @param csid
+     * @return
+     * @see org.collectionspace.services.client.IntakeProxy#getAuthorityRefs(java.lang.String)
+     */
+    @GET
+    @Path("{csid}/items/{itemcsid}/refObjs")
+    @Produces("application/xml")
+    ClientResponse<AuthorityRefDocList> getReferencingObjects(
+            @PathParam("csid") String parentcsid,
+            @PathParam("itemcsid") String itemcsid);    
 
     // List Items for a named authority
     @GET
index 8edf382108519b4e85903beefb4ffa5d48ce592a..56af0dd392d51ff3c7f229625cc28adfacc8fae3 100644 (file)
@@ -46,8 +46,10 @@ import org.collectionspace.services.OrganizationJAXBSchema;
 import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
+import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
-import org.collectionspace.services.common.context.MultipartServiceContext;
+//import org.collectionspace.services.common.context.MultipartServiceContext;
+//import org.collectionspace.services.common.context.MultipartServiceContextFactory;
 import org.collectionspace.services.common.context.MultipartServiceContextImpl;
 //import org.collectionspace.services.common.context.MultipartServiceContextFactory;
 import org.collectionspace.services.common.context.ServiceBindingUtils;
@@ -58,12 +60,14 @@ import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.query.IQueryManager;
+import org.collectionspace.services.common.repository.RepositoryClient;
 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.common.vocabulary.RefNameServiceUtils;
 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
 import org.collectionspace.services.organization.nuxeo.OrganizationDocumentModelHandler;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
@@ -342,6 +346,90 @@ public class OrgAuthorityResource extends
         return result;
     }
 
+    /**
+     * Gets the entities referencing this Organization instance. The service type
+     * can be passed as a query param "type", and must match a configured type
+     * for the service bindings. If not set, the type defaults to
+     * ServiceBindingUtils.SERVICE_TYPE_PROCEDURE.
+     * @param parentcsid 
+     * 
+     * @param csid the parent csid
+     * @param itemcsid the person csid
+     * @param ui the ui
+     * 
+     * @return the info for the referencing objects
+     */
+    @GET
+    @Path("{csid}/items/{itemcsid}/refObjs")
+    @Produces("application/xml")
+    public AuthorityRefDocList getReferencingObjects(
+               @PathParam("csid") String parentcsid,
+               @PathParam("itemcsid") String itemcsid,
+               @Context UriInfo ui) {
+       AuthorityRefDocList authRefDocList = null;
+       if (logger.isDebugEnabled()) {
+               logger.debug("getReferencingObjects with parentcsid=" 
+                               + parentcsid + " and itemcsid=" + itemcsid);
+       }
+       if (parentcsid == null || "".equals(parentcsid)
+                       || itemcsid == null || "".equals(itemcsid)) {
+               logger.error("getPerson: missing parentcsid or itemcsid!");
+               Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+                               "get failed on Person with parentcsid=" 
+                               + parentcsid + " and itemcsid=" + itemcsid).type(
+                               "text/plain").build();
+               throw new WebApplicationException(response);
+       }
+       try {
+               // Note that we have to create the service context for the Items, not the main service
+               MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(), queryParams);
+               DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+               RepositoryClient repoClient = getRepositoryClient(ctx); 
+               DocumentFilter myFilter = handler.getDocumentFilter();
+               String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE;
+               List<String> list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP);
+               if (list != null) {
+                       serviceType = list.get(0);
+               }
+               DocumentWrapper<DocumentModel> docWrapper = repoClient.getDoc(ctx, itemcsid);
+               DocumentModel docModel = docWrapper.getWrappedObject();
+               String refName = (String)docModel.getPropertyValue(OrganizationJAXBSchema.REF_NAME);
+
+               authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(repoClient, 
+                               ctx.getTenantId(), serviceType, refName,
+                               myFilter.getPageSize(), myFilter.getStartPage(), true );
+       } 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("getReferencingObjects", dnfe);
+               }
+               Response response = Response.status(Response.Status.NOT_FOUND).entity(
+                               "GetReferencingObjects failed with parentcsid=" 
+                               + parentcsid + " and itemcsid=" + itemcsid).type(
+                               "text/plain").build();
+               throw new WebApplicationException(response);
+       } catch (Exception e) { // Includes DocumentException
+               if (logger.isDebugEnabled()) {
+                       logger.debug("GetReferencingObjects", e);
+               }
+               Response response = Response.status(
+                               Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
+               throw new WebApplicationException(response);
+       }
+       if (authRefDocList == null) {
+               Response response = Response.status(Response.Status.NOT_FOUND).entity(
+                               "Get failed, the requested Person CSID:" + itemcsid + ": was not found.").type(
+                               "text/plain").build();
+               throw new WebApplicationException(response);
+       }
+       return authRefDocList;
+    }
+
+    
     /**
      * Gets the org authority.
      * 
@@ -410,16 +498,14 @@ public class OrgAuthorityResource extends
     public OrgauthoritiesCommonList getOrgAuthorityList(@Context UriInfo ui) {
         OrgauthoritiesCommonList orgAuthorityObjectList = new OrgauthoritiesCommonList();
         try {
-               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             DocumentHandler handler = createDocumentHandler(ctx);
-            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
-            myFilter.setPagination(queryParams);
+            DocumentFilter myFilter = handler.getDocumentFilter();
             String nameQ = queryParams.getFirst("refName");
             if (nameQ != null) {
                 myFilter.setWhereClause("orgauthorities_common:refName='" + nameQ + "'");
             }
-            handler.setDocumentFilter(myFilter);
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             orgAuthorityObjectList = (OrgauthoritiesCommonList) handler.getCommonPartList();
         } catch (UnauthorizedException ue) {
@@ -701,8 +787,7 @@ public class OrgAuthorityResource extends
                ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
                                queryParams);
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
-            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
-            myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
+            DocumentFilter myFilter = handler.getDocumentFilter(); //new DocumentFilter();
             myFilter.setWhereClause(OrganizationJAXBSchema.ORGANIZATIONS_COMMON +
                        ":" + OrganizationJAXBSchema.IN_AUTHORITY + "=" +
                        "'" + parentcsid + "'");
@@ -714,7 +799,6 @@ public class OrgAuthorityResource extends
                        " LIKE " + "'%" + partialTerm + "%'";
                myFilter.appendWhereClause(ptClause);
             }            
-            handler.setDocumentFilter(myFilter);
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             organizationObjectList = (OrganizationsCommonList) handler.getCommonPartList();
         } catch (UnauthorizedException ue) {
@@ -753,16 +837,15 @@ public class OrgAuthorityResource extends
             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
             String whereClause =
                OrgAuthorityJAXBSchema.ORGAUTHORITIES_COMMON+
-               ":"+OrgAuthorityJAXBSchema.DISPLAY_NAME+
-               "='"+parentSpecifier+"'";
+               ":" + OrgAuthorityJAXBSchema.DISPLAY_NAME+
+               "='" + parentSpecifier+"'";
             // Need to get an Authority by name
             ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             String parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
 
             ctx = createServiceContext(getItemServiceName(), queryParams);
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
-            DocumentFilter myFilter = handler.createDocumentFilter();// new DocumentFilter();
-            myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
+            DocumentFilter myFilter = handler.getDocumentFilter();// new DocumentFilter();
 
             // Add the where clause "organizations_common:inAuthority='" + parentcsid + "'"
             myFilter.setWhereClause(OrganizationJAXBSchema.ORGANIZATIONS_COMMON + ":" +
@@ -776,9 +859,7 @@ public class OrgAuthorityResource extends
                        " LIKE " +
                        "'%" + partialTerm + "%'";
                myFilter.appendWhereClause(ptClause);
-            }
-            
-            handler.setDocumentFilter(myFilter);
+            }            
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             personObjectList = (OrganizationsCommonList) handler.getCommonPartList();
         } catch (UnauthorizedException ue) {
@@ -977,8 +1058,7 @@ public class OrgAuthorityResource extends
                ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName(),
                                queryParams);
             DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
-            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
-            myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
+            DocumentFilter myFilter = handler.getDocumentFilter(); //new DocumentFilter();
             myFilter.setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" +
                 ContactJAXBSchema.IN_AUTHORITY +
                 "='" + parentcsid + "'" +
@@ -987,7 +1067,6 @@ public class OrgAuthorityResource extends
                 ContactJAXBSchema.IN_ITEM +
                 "='" + itemcsid + "'" +
                 " AND ecm:isProxy = 0");
-            handler.setDocumentFilter(myFilter);
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             contactObjectList = (ContactsCommonList) handler.getCommonPartList();
         } catch (UnauthorizedException ue) {
index c34e5ca9adb73722d4060e425722e2f88b961d4b..6145dc9fa3d9e937e0f8009dda4aac3315324ac2 100644 (file)
@@ -26,7 +26,7 @@
  */
 package org.collectionspace.services.client;
 
-import javax.ws.rs.PathParam;
+//import javax.ws.rs.PathParam;
 import javax.ws.rs.core.Response;
 
 //import org.collectionspace.services.common.authorityref.AuthorityRefList;
index a02ee7ab2cb376af4baafb635e7d5d47e1b3aaf2..a1d8a708e761af078ddeccbf1d7a5c0d1033b6f9 100644 (file)
@@ -355,13 +355,13 @@ public class PersonAuthorityResource extends
             throw new WebApplicationException(response);
         }
     try {
+        MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
         // Note that we have to create the service context for the Items, not the main service
-        ServiceContext<MultipartInput, MultipartOutput> ctx = MultipartServiceContextFactory.get().createServiceContext(getItemServiceName());
+        ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
+                       queryParams);
         DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
         RepositoryClient repoClient = getRepositoryClient(ctx); 
-        DocumentFilter myFilter = handler.createDocumentFilter();
-        MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-        myFilter.setPagination(queryParams);
+        DocumentFilter myFilter = handler.getDocumentFilter();
        String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE;
         List<String> list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP);
         if (list != null) {
@@ -467,13 +467,10 @@ public class PersonAuthorityResource extends
             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
                ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             DocumentHandler handler = createDocumentHandler(ctx);
-//REM:            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
-//REM:            myFilter.setPagination(queryParams); //FIXME
             String nameQ = queryParams.getFirst("refName");
             if (nameQ != null) {
                 handler.getDocumentFilter().setWhereClause("personauthorities_common:refName='" + nameQ + "'");
             }
-//REM:            handler.setDocumentFilter(myFilter);
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             personAuthorityObjectList = (PersonauthoritiesCommonList) handler.getCommonPartList();
         } catch (UnauthorizedException ue) {
@@ -712,9 +709,6 @@ public class PersonAuthorityResource extends
                ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
                                queryParams);
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
-//REM:            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
-//REM:            myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
-
             // Add the where clause "persons_common:inAuthority='" + parentcsid + "'"
             handler.getDocumentFilter().setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" +
                        PersonJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'");
@@ -728,7 +722,6 @@ public class PersonAuthorityResource extends
                        "'%" + partialTerm + "%'";
                handler.getDocumentFilter().appendWhereClause(ptClause);
             }            
-//REM:            handler.setDocumentFilter(myFilter);
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             personObjectList = (PersonsCommonList) handler.getCommonPartList();
         } catch (UnauthorizedException ue) {
@@ -765,23 +758,20 @@ public class PersonAuthorityResource extends
             @Context UriInfo ui) {
         PersonsCommonList personObjectList = new PersonsCommonList();
         try {
-            MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
             String whereClause =
                PersonAuthorityJAXBSchema.PERSONAUTHORITIES_COMMON+
-               ":"+PersonAuthorityJAXBSchema.DISPLAY_NAME+
-               "='"+parentSpecifier+"'";
+               ":" + PersonAuthorityJAXBSchema.DISPLAY_NAME+
+               "='" + parentSpecifier+"'";
             // Need to get an Authority by name
+            MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
             ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             String parentcsid = 
                getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
-
             ctx = createServiceContext(getItemServiceName(), queryParams);
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
-//REM:            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
-//REM:            myFilter.setPagination(queryParams); //FIXME
 
             // Add the where clause "persons_common:inAuthority='" + parentcsid + "'"
-            handler.createDocumentFilter().setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" +
+            handler.getDocumentFilter().setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" +
                        PersonJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'");
             
             // AND persons_common:displayName LIKE '%partialTerm%'
@@ -791,10 +781,8 @@ public class PersonAuthorityResource extends
                        PersonJAXBSchema.DISPLAY_NAME +
                        " LIKE " +
                        "'%" + partialTerm + "%'";
-               handler.createDocumentFilter().appendWhereClause(ptClause);
-            }
-            
-//REM:            handler.setDocumentFilter(myFilter);
+               handler.getDocumentFilter().appendWhereClause(ptClause);
+            }            
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             personObjectList = (PersonsCommonList) handler.getCommonPartList();
         } catch (UnauthorizedException ue) {
@@ -1000,9 +988,7 @@ public class PersonAuthorityResource extends
                ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName(),
                                queryParams);
             DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
-//REM:            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
-//REM:            myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
-            handler.createDocumentFilter().setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" +
+            handler.getDocumentFilter().setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" +
                 ContactJAXBSchema.IN_AUTHORITY +
                 "='" + parentcsid + "'" +
                 " AND " +
@@ -1010,7 +996,6 @@ public class PersonAuthorityResource extends
                 ContactJAXBSchema.IN_ITEM +
                 "='" + itemcsid + "'" +
                 " AND ecm:isProxy = 0");
-//REM:            handler.setDocumentFilter(myFilter);
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             contactObjectList = (ContactsCommonList) handler.getCommonPartList();
         } catch (UnauthorizedException ue) {