]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-852. Added support in tenant-bindings.xml for authority reference fields in...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Tue, 2 Mar 2010 08:42:28 +0000 (08:42 +0000)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Tue, 2 Mar 2010 08:42:28 +0000 (08:42 +0000)
Refactored the code that was in IntakeDocumentModelHandler (getAuthorityRefs) into RemoteDocumentModelHandlerImpl.
Added tests for both services.

14 files changed:
services/acquisition/client/pom.xml
services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionClient.java
services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionProxy.java
services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java [new file with mode: 0644]
services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java
services/collectionobject/client/pom.xml
services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java
services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectProxy.java
services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java [new file with mode: 0644]
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java
services/common/src/main/config/tenant-bindings.xml
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java
services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java
services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeDocumentModelHandler.java

index 5ad5546105cbadede7a8c3d8418a9a1db24b8c7d..7cfe4b51faba38c5d0b8399d16ab04440f455964 100644 (file)
             <artifactId>org.collectionspace.services.client</artifactId>\r
             <version>${cspace.services.client.version}</version>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>org.collectionspace.services</groupId>\r
+            <artifactId>org.collectionspace.services.person.client</artifactId>\r
+            <version>${cspace.services.client.version}</version>\r
+        </dependency>\r
         \r
         <dependency>\r
             <groupId>org.testng</groupId>\r
index 954d0eedb0633a49312ff5a532a4d217f97c7726..2051c24e1e14460db85199ab2a4f31f7903ca378 100644 (file)
@@ -3,6 +3,7 @@ package org.collectionspace.services.client;
 import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.acquisition.AcquisitionsCommonList;
+import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.jboss.resteasy.client.ProxyFactory;
 import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
@@ -84,6 +85,15 @@ public class AcquisitionClient extends AbstractServiceClientImpl {
         return acquisitionProxy.read(csid);
     }
 
+    /**
+     * @param csid
+     * @return
+     * @see org.collectionspace.services.client.CollectionObjectProxy#getAuthorityRefs(java.lang.String)
+     */
+    public ClientResponse<AuthorityRefList> getAuthorityRefs(String csid) {
+        return acquisitionProxy.getAuthorityRefs(csid);
+    }
+
     /**
      * @param intake
      * @return
index 0a7c02e45aabb2f03b5ed3cb3373cfb01b020b56..233ccad27fce67c83eb9fbd55bec3df990f8f6ca 100644 (file)
@@ -11,6 +11,7 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.acquisition.AcquisitionsCommonList;
+import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.jboss.resteasy.client.ClientResponse;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
@@ -36,6 +37,12 @@ public interface AcquisitionProxy {
     @Path("/{csid}")
     ClientResponse<MultipartInput> read(@PathParam("csid") String csid);
 
+    // List Authority references
+    @GET
+    @Produces({"application/xml"})
+    @Path("/{csid}/authorityrefs/")
+    ClientResponse<AuthorityRefList> getAuthorityRefs(@PathParam("csid") String csid);
+    
     //(U)pdate
     @PUT
     @Path("/{csid}")
diff --git a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java
new file mode 100644 (file)
index 0000000..43aabc6
--- /dev/null
@@ -0,0 +1,299 @@
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+ *
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+ *
+ * Copyright © 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.collectionspace.services.client.test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.collectionspace.services.PersonJAXBSchema;
+import org.collectionspace.services.client.AcquisitionClient;
+import org.collectionspace.services.client.PersonAuthorityClient;
+import org.collectionspace.services.client.PersonAuthorityClientUtils;
+import org.collectionspace.services.common.authorityref.AuthorityRefList;
+import org.collectionspace.services.acquisition.AcquisitionsCommon;
+import org.collectionspace.services.acquisition.AcquisitionsCommonList;
+
+import org.jboss.resteasy.client.ClientResponse;
+
+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;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.Test;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * AcquisitionAuthRefsTest, carries out tests against a
+ * deployed and running Acquisition Service.
+ *
+ * $LastChangedRevision: 1327 $
+ * $LastChangedDate: 2010-02-12 10:35:11 -0800 (Fri, 12 Feb 2010) $
+ */
+public class AcquisitionAuthRefsTest extends BaseServiceTest {
+
+   private final Logger logger =
+       LoggerFactory.getLogger(AcquisitionAuthRefsTest.class);
+
+    // Instance variables specific to this test.
+    private AcquisitionClient acquisitionClient = new AcquisitionClient();
+    private PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
+    final String SERVICE_PATH_COMPONENT = "acquisitions";
+    final String PERSON_AUTHORITY_NAME = "TestPersonAuth";
+    private String knownResourceId = null;
+    private List<String> acquisitionIdsCreated = new ArrayList();
+    private List<String> personIdsCreated = new ArrayList();
+    private int CREATED_STATUS = Response.Status.CREATED.getStatusCode();
+    private int OK_STATUS = Response.Status.OK.getStatusCode();
+    private String personAuthCSID = null; 
+    private String acquisitionAuthorizerRefName = null;
+    private String acquisitionFundingSourceRefName = null;
+    // Not ready for multiples, yet
+    //private String acquisitionSourcesRefName = null;
+    private String fieldCollectorRefName = null;
+    private final int NUM_AUTH_REFS_EXPECTED = 3;
+
+    // ---------------------------------------------------------------
+    // CRUD tests : CREATE tests
+    // ---------------------------------------------------------------
+    // Success outcomes
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
+    public void createWithAuthRefs(String testName) throws Exception {
+
+        testSetup(CREATED_STATUS, ServiceRequestType.CREATE,testName);
+
+        // Submit the request to the service and store the response.
+        String identifier = createIdentifier();
+        
+        // Create all the person refs and entities
+        createPersonRefs();
+        
+        MultipartOutput multipart = createAcquisitionInstance(
+                                               "April 1, 2010",
+                                                               acquisitionAuthorizerRefName,
+                                                               acquisitionFundingSourceRefName,
+                                                               fieldCollectorRefName );
+
+        ClientResponse<Response> res = acquisitionClient.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);
+        }
+        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.
+        if (knownResourceId == null){
+            knownResourceId = extractId(res);
+            if (logger.isDebugEnabled()) {
+                logger.debug(testName + ": knownResourceId=" + knownResourceId);
+            }
+        }
+        
+        // Store the IDs from every resource created by tests,
+        // so they can be deleted after tests have been run.
+        acquisitionIdsCreated.add(extractId(res));
+    }
+    
+    protected void createPersonRefs(){
+       String authRefName = 
+               PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false);
+       MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
+                       PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName());
+        ClientResponse<Response> res = personAuthClient.create(multipart);
+        int statusCode = res.getStatus();
+
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, CREATED_STATUS);
+        personAuthCSID = extractId(res);
+        
+        acquisitionAuthorizerRefName = PersonAuthorityClientUtils.createPersonRefName(
+                                                               authRefName, "Annie Authorizer", true);
+        personIdsCreated.add(createPerson("Annie", "Authorizer", acquisitionAuthorizerRefName));
+        
+        acquisitionFundingSourceRefName = PersonAuthorityClientUtils.createPersonRefName(
+                                                                       authRefName, "Sammy Source", true);
+        personIdsCreated.add(createPerson("Sammy", "Source", acquisitionFundingSourceRefName));
+        
+        
+        fieldCollectorRefName = PersonAuthorityClientUtils.createPersonRefName(
+                                                                       authRefName, "Connie Collector", true);
+        personIdsCreated.add(createPerson("Connie", "Collector", fieldCollectorRefName));
+    }
+    
+    protected String createPerson(String firstName, String surName, String refName ) {
+        Map<String, String> personInfo = new HashMap<String,String>();
+        personInfo.put(PersonJAXBSchema.FORE_NAME, firstName);
+        personInfo.put(PersonJAXBSchema.SUR_NAME, surName);
+       MultipartOutput multipart = 
+               PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, 
+                               refName, personInfo, personAuthClient.getItemCommonPartName());
+        ClientResponse<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
+        int statusCode = res.getStatus();
+
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, CREATED_STATUS);
+       return extractId(res);
+    }
+
+    // Success outcomes
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+        dependsOnMethods = {"createWithAuthRefs"})
+    public void readAndCheckAuthRefs(String testName) throws Exception {
+
+        // Perform setup.
+        testSetup(OK_STATUS, ServiceRequestType.READ,testName);
+
+        // Submit the request to the service and store the response.
+        ClientResponse<MultipartInput> res = acquisitionClient.read(knownResourceId);
+        int statusCode = res.getStatus();
+
+        // Check the status code of the response: does it match
+        // the expected response(s)?
+        if(logger.isDebugEnabled()){
+            logger.debug(testName + ".read: status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+        MultipartInput input = (MultipartInput) res.getEntity();
+        AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input,
+                       acquisitionClient.getCommonPartName(), AcquisitionsCommon.class);
+        Assert.assertNotNull(acquisition);
+        // Check a couple of fields
+        Assert.assertEquals(acquisition.getAcquisitionAuthorizer(), acquisitionAuthorizerRefName);
+        Assert.assertEquals(acquisition.getFieldCollector(), fieldCollectorRefName);
+        
+        // Get the auth refs and check them
+        ClientResponse<AuthorityRefList> res2 = acquisitionClient.getAuthorityRefs(knownResourceId);
+        statusCode = res2.getStatus();
+
+        if(logger.isDebugEnabled()){
+            logger.debug(testName + ".getAuthorityRefs: status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        AuthorityRefList list = res2.getEntity();
+
+        // Optionally output additional data about list members for debugging.
+        boolean iterateThroughList = true;
+        if(iterateThroughList && logger.isDebugEnabled()){
+            List<AuthorityRefList.AuthorityRefItem> items =
+                    list.getAuthorityRefItem();
+            int i = 0;
+            for(AuthorityRefList.AuthorityRefItem item : items){
+                logger.debug(testName + ": list-item[" + i + "] Field:" +
+                               item.getSourceField() + "= " +
+                        item.getAuthDisplayName() +
+                        item.getItemDisplayName());
+                logger.debug(testName + ": list-item[" + i + "] refName=" +
+                        item.getRefName());
+                logger.debug(testName + ": list-item[" + i + "] URI=" +
+                        item.getUri());
+                i++;
+            }
+            Assert.assertEquals(i, NUM_AUTH_REFS_EXPECTED, "Did not find all authrefs!");
+        }
+    }
+
+
+    // ---------------------------------------------------------------
+    // Cleanup of resources created during testing
+    // ---------------------------------------------------------------
+
+    /**
+     * Deletes all resources created by tests, after all tests have been run.
+     *
+     * This cleanup method will always be run, even if one or more tests fail.
+     * For this reason, it attempts to remove all resources created
+     * at any point during testing, even if some of those resources
+     * may be expected to be deleted by certain tests.
+     */
+    // @AfterClass(alwaysRun=true)
+    public void cleanUp() {
+        if (logger.isDebugEnabled()) {
+            logger.debug("Cleaning up temporary resources created for testing ...");
+        }
+        // Note: Any non-success responses are ignored and not reported.
+        for (String resourceId : acquisitionIdsCreated) {
+            ClientResponse<Response> res = acquisitionClient.delete(resourceId);
+        }
+        // Delete persons before PersonAuth
+        for (String resourceId : personIdsCreated) {
+            ClientResponse<Response> res = personAuthClient.deleteItem(personAuthCSID, resourceId);
+        }
+        ClientResponse<Response> res = personAuthClient.delete(personAuthCSID);
+    }
+
+    // ---------------------------------------------------------------
+    // Utility methods used by tests above
+    // ---------------------------------------------------------------
+    @Override
+    public String getServicePathComponent() {
+        return SERVICE_PATH_COMPONENT;
+    }
+
+   private MultipartOutput createAcquisitionInstance(
+                       String accessionDate,
+                               String acquisitionAuthorizer,
+                               String acquisitionFundingSource,
+                               String fieldCollector ) {
+        AcquisitionsCommon acquisition = new AcquisitionsCommon();
+        acquisition.setAccessionDate(accessionDate);
+        acquisition.setAcquisitionAuthorizer(acquisitionAuthorizer);
+        acquisition.setAcquisitionFundingSource(acquisitionFundingSource);
+        acquisition.setFieldCollector(fieldCollector);
+        MultipartOutput multipart = new MultipartOutput();
+        OutputPart commonPart =
+            multipart.addPart(acquisition, MediaType.APPLICATION_XML_TYPE);
+        commonPart.getHeaders().add("label", acquisitionClient.getCommonPartName());
+
+        if(logger.isDebugEnabled()){
+            logger.debug("to be created, acquisition common");
+            logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
+        }
+
+        return multipart;
+    }
+}
index 1db3cfadf9b9831992c4fed01fe580f53e2d7810..910b733f29fd553d24fe4e57f97c9137208b463c 100644 (file)
@@ -23,6 +23,8 @@
  */
 package org.collectionspace.services.acquisition;
 
+import java.util.List;
+
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
@@ -39,18 +41,23 @@ import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
+import org.collectionspace.services.common.authorityref.AuthorityRefList;
 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.ServiceContext;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
 import org.collectionspace.services.common.document.DocumentHandler;
+import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.query.IQueryManager;
 import org.collectionspace.services.common.query.QueryManager;
 import org.collectionspace.services.common.security.UnauthorizedException;
+import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 import org.jboss.resteasy.util.HttpResponseCodes;
+import org.nuxeo.ecm.core.api.DocumentModel;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -308,6 +315,38 @@ public class AcquisitionResource
             throw new WebApplicationException(response);
         }
         return acquisitionObjectList;
-    }    
+    }   
+    
+    @GET
+    @Path("{csid}/authorityrefs")
+    @Produces("application/xml")
+    public AuthorityRefList getAuthorityRefs(
+               @PathParam("csid") String csid, 
+               @Context UriInfo ui) {
+       AuthorityRefList authRefList = null;
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            DocumentWrapper<DocumentModel> docWrapper = 
+               getRepositoryClient(ctx).getDoc(ctx, csid);
+            RemoteDocumentModelHandlerImpl handler 
+               = (RemoteDocumentModelHandlerImpl)createDocumentHandler(ctx);
+            List<String> authRefFields = ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues("authRef");
+            String prefix = ctx.getCommonPartLabel()+":";
+            authRefList = handler.getAuthorityRefs(docWrapper, prefix, authRefFields);
+        } 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 getAuthorityRefs", e);
+            }
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        return authRefList;
+    }
+    
     
 }
index 95f3cc5ce51fe32fc3292a19239249a58582126e..c71cab02838d2328946fbe445df915d177d26e7e 100644 (file)
             <artifactId>org.collectionspace.services.client</artifactId>\r
             <version>${cspace.services.client.version}</version>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>org.collectionspace.services</groupId>\r
+            <artifactId>org.collectionspace.services.person.client</artifactId>\r
+            <version>${cspace.services.client.version}</version>\r
+        </dependency>\r
         \r
         <dependency>\r
             <groupId>org.testng</groupId>\r
index a342a9580d7b81565fa1d55ab915ab30a62791c2..1f1e02019f9e174d0a7f64da96e224d2fe0b1080 100644 (file)
@@ -35,6 +35,7 @@ import javax.ws.rs.core.UriInfo;
 
 
 import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
+import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.query.IQueryManager;
 import org.jboss.resteasy.client.ProxyFactory;
@@ -84,6 +85,7 @@ public class CollectionObjectClient extends AbstractServiceClientImpl {
     /**
      * Read list.
      * 
+     * @see org.collectionspace.services.client.CollectionObjectProxy#readList()
      * @return the client response< collectionobjects common list>
      */
     public ClientResponse<CollectionobjectsCommonList> readList() {
@@ -97,6 +99,7 @@ public class CollectionObjectClient extends AbstractServiceClientImpl {
      * This is an intentionally empty method that is used for performance test 
      * to get a rough time estimate of the client to server response-request overhead.
      * 
+     * @see org.collectionspace.services.client.CollectionObjectProxy#roundtrip()
      * @return the client response< response>
      */
     public ClientResponse<Response> roundtrip() {
@@ -108,6 +111,7 @@ public class CollectionObjectClient extends AbstractServiceClientImpl {
      * 
      * @param keywords the keywords
      * 
+     * @see org.collectionspace.services.client.CollectionObjectProxy#keywordSearch()
      * @return the client response< collectionobjects common list>
      */
     public ClientResponse<CollectionobjectsCommonList> keywordSearch(String keywords) {
@@ -120,17 +124,29 @@ public class CollectionObjectClient extends AbstractServiceClientImpl {
      * 
      * @param csid the csid
      * 
+     * @see org.collectionspace.services.client.CollectionObjectProxy#keywordSearch()
      * @return the client response< multipart input>
      */
     public ClientResponse<MultipartInput> read(String csid) {
         return collectionObjectProxy.read(csid);
     }
 
+    /**
+     * @param csid
+     * @return
+     * @see org.collectionspace.services.client.CollectionObjectProxy#getAuthorityRefs(java.lang.String)
+     */
+    public ClientResponse<AuthorityRefList> getAuthorityRefs(String csid) {
+        return collectionObjectProxy.getAuthorityRefs(csid);
+    }
+
+
     /**
      * Creates the.
      * 
      * @param multipart the multipart
      * 
+     * @see org.collectionspace.services.client.CollectionObjectProxy#create()
      * @return the client response< response>
      */
     public ClientResponse<Response> create(MultipartOutput multipart) {
@@ -143,6 +159,7 @@ public class CollectionObjectClient extends AbstractServiceClientImpl {
      * @param csid the csid
      * @param multipart the multipart
      * 
+     * @see org.collectionspace.services.client.CollectionObjectProxy#update()
      * @return the client response< multipart input>
      */
     public ClientResponse<MultipartInput> update(String csid, MultipartOutput multipart) {
@@ -154,6 +171,7 @@ public class CollectionObjectClient extends AbstractServiceClientImpl {
      * 
      * @param csid the csid
      * 
+     * @see org.collectionspace.services.client.CollectionObjectProxy#delete()
      * @return the client response< response>
      */
     public ClientResponse<Response> delete(String csid) {
index 9928ef42c864763dedd40fba38cf7ff22b7bc215..d0e0a4dcfb22060007c6f9b0ad76e2e517d3a72e 100644 (file)
@@ -13,6 +13,7 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
+import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.common.query.IQueryManager;
 import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
 import org.jboss.resteasy.client.ClientResponse;
@@ -51,6 +52,13 @@ public interface CollectionObjectProxy {
     @GET
     @Path("/{csid}")
     ClientResponse<MultipartInput> read(@PathParam("csid") String csid);
+    
+    // List Authority references
+    @GET
+    @Produces({"application/xml"})
+    @Path("/{csid}/authorityrefs/")
+    ClientResponse<AuthorityRefList> getAuthorityRefs(@PathParam("csid") String csid);
+    
 
     //(U)pdate
     @PUT
diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java
new file mode 100644 (file)
index 0000000..970bbbe
--- /dev/null
@@ -0,0 +1,307 @@
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+ *
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+ *
+ * Copyright © 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.collectionspace.services.client.test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.collectionspace.services.PersonJAXBSchema;
+import org.collectionspace.services.client.CollectionObjectClient;
+import org.collectionspace.services.client.PersonAuthorityClient;
+import org.collectionspace.services.client.PersonAuthorityClientUtils;
+import org.collectionspace.services.common.authorityref.AuthorityRefList;
+import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
+import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
+
+import org.jboss.resteasy.client.ClientResponse;
+
+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;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.Test;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * CollectionObjectAuthRefsTest, carries out tests against a
+ * deployed and running CollectionObject Service.
+ *
+ * $LastChangedRevision: 1327 $
+ * $LastChangedDate: 2010-02-12 10:35:11 -0800 (Fri, 12 Feb 2010) $
+ */
+public class CollectionObjectAuthRefsTest extends BaseServiceTest {
+
+   private final Logger logger =
+       LoggerFactory.getLogger(CollectionObjectAuthRefsTest.class);
+
+    // Instance variables specific to this test.
+    private CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+    private PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
+    final String SERVICE_PATH_COMPONENT = "collectionobjects";
+    final String PERSON_AUTHORITY_NAME = "TestPersonAuth";
+    private String knownResourceId = null;
+    private List<String> collectionObjectIdsCreated = new ArrayList();
+    private List<String> personIdsCreated = new ArrayList();
+    private int CREATED_STATUS = Response.Status.CREATED.getStatusCode();
+    private int OK_STATUS = Response.Status.OK.getStatusCode();
+    private String personAuthCSID = null; 
+    private String contentOrganizationRefName = null;
+    private String contentPeopleRefName = null;
+    private String contentPersonRefName = null;
+    private String inscriberRefName = null;
+    private final int NUM_AUTH_REFS_EXPECTED = 4;
+
+    // ---------------------------------------------------------------
+    // CRUD tests : CREATE tests
+    // ---------------------------------------------------------------
+    // Success outcomes
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
+    public void createWithAuthRefs(String testName) throws Exception {
+
+        testSetup(CREATED_STATUS, ServiceRequestType.CREATE,testName);
+
+        // Submit the request to the service and store the response.
+        String identifier = createIdentifier();
+        
+        // Create all the person refs and entities
+        createPersonRefs();
+        
+        MultipartOutput multipart = createCollectionObjectInstance(
+                                                       "Obj Title",
+                                                       "ObjNum-1234",
+                                                               contentOrganizationRefName,
+                                                               contentPeopleRefName,
+                                                               contentPersonRefName,
+                                                               inscriberRefName );
+
+        ClientResponse<Response> res = collectionObjectClient.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);
+        }
+        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.
+        if (knownResourceId == null){
+            knownResourceId = extractId(res);
+            if (logger.isDebugEnabled()) {
+                logger.debug(testName + ": knownResourceId=" + knownResourceId);
+            }
+        }
+        
+        // Store the IDs from every resource created by tests,
+        // so they can be deleted after tests have been run.
+        collectionObjectIdsCreated.add(extractId(res));
+    }
+    
+    protected void createPersonRefs(){
+       String authRefName = 
+               PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false);
+       MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
+                       PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName());
+        ClientResponse<Response> res = personAuthClient.create(multipart);
+        int statusCode = res.getStatus();
+
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, CREATED_STATUS);
+        personAuthCSID = extractId(res);
+        
+        contentOrganizationRefName = PersonAuthorityClientUtils.createPersonRefName(
+                                                               authRefName, "Omni Org", true);
+        personIdsCreated.add(createPerson("Omni", "Org", contentOrganizationRefName));
+        
+        contentPeopleRefName = PersonAuthorityClientUtils.createPersonRefName(
+                                                                       authRefName, "Pushy People", true);
+        personIdsCreated.add(createPerson("Pushy", "People", contentPeopleRefName));
+        
+        contentPersonRefName = PersonAuthorityClientUtils.createPersonRefName(
+                                                                       authRefName, "Connie ContactPerson", true);
+        personIdsCreated.add(createPerson("Connie", "ContactPerson", contentPersonRefName));
+        
+        inscriberRefName = PersonAuthorityClientUtils.createPersonRefName(
+                                                                       authRefName, "Ingrid Inscriber", true);
+        personIdsCreated.add(createPerson("Ingrid", "Inscriber", inscriberRefName));
+    }
+    
+    protected String createPerson(String firstName, String surName, String refName ) {
+        Map<String, String> personInfo = new HashMap<String,String>();
+        personInfo.put(PersonJAXBSchema.FORE_NAME, firstName);
+        personInfo.put(PersonJAXBSchema.SUR_NAME, surName);
+       MultipartOutput multipart = 
+               PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, 
+                               refName, personInfo, personAuthClient.getItemCommonPartName());
+        ClientResponse<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
+        int statusCode = res.getStatus();
+
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, CREATED_STATUS);
+       return extractId(res);
+    }
+
+    // Success outcomes
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+        dependsOnMethods = {"createWithAuthRefs"})
+    public void readAndCheckAuthRefs(String testName) throws Exception {
+
+        // Perform setup.
+        testSetup(OK_STATUS, ServiceRequestType.READ,testName);
+
+        // Submit the request to the service and store the response.
+        ClientResponse<MultipartInput> res = collectionObjectClient.read(knownResourceId);
+        int statusCode = res.getStatus();
+
+        // Check the status code of the response: does it match
+        // the expected response(s)?
+        if(logger.isDebugEnabled()){
+            logger.debug(testName + ".read: status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+        MultipartInput input = (MultipartInput) res.getEntity();
+        CollectionobjectsCommon collectionObject = (CollectionobjectsCommon) extractPart(input,
+                       collectionObjectClient.getCommonPartName(), CollectionobjectsCommon.class);
+        Assert.assertNotNull(collectionObject);
+        // Check a couple of fields
+        Assert.assertEquals(collectionObject.getContentOrganization(), contentOrganizationRefName);
+        Assert.assertEquals(collectionObject.getInscriber(), inscriberRefName);
+        
+        // Get the auth refs and check them
+        ClientResponse<AuthorityRefList> res2 = collectionObjectClient.getAuthorityRefs(knownResourceId);
+        statusCode = res2.getStatus();
+
+        if(logger.isDebugEnabled()){
+            logger.debug(testName + ".getAuthorityRefs: status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        AuthorityRefList list = res2.getEntity();
+
+        // Optionally output additional data about list members for debugging.
+        boolean iterateThroughList = true;
+        if(iterateThroughList && logger.isDebugEnabled()){
+            List<AuthorityRefList.AuthorityRefItem> items =
+                    list.getAuthorityRefItem();
+            int i = 0;
+            for(AuthorityRefList.AuthorityRefItem item : items){
+                logger.debug(testName + ": list-item[" + i + "] Field:" +
+                               item.getSourceField() + "= " +
+                        item.getAuthDisplayName() +
+                        item.getItemDisplayName());
+                logger.debug(testName + ": list-item[" + i + "] refName=" +
+                        item.getRefName());
+                logger.debug(testName + ": list-item[" + i + "] URI=" +
+                        item.getUri());
+                i++;
+            }
+            Assert.assertEquals(i, NUM_AUTH_REFS_EXPECTED, "Did not find all authrefs!");
+        }
+    }
+
+
+    // ---------------------------------------------------------------
+    // Cleanup of resources created during testing
+    // ---------------------------------------------------------------
+
+    /**
+     * Deletes all resources created by tests, after all tests have been run.
+     *
+     * This cleanup method will always be run, even if one or more tests fail.
+     * For this reason, it attempts to remove all resources created
+     * at any point during testing, even if some of those resources
+     * may be expected to be deleted by certain tests.
+     */
+    // @AfterClass(alwaysRun=true)
+    public void cleanUp() {
+        if (logger.isDebugEnabled()) {
+            logger.debug("Cleaning up temporary resources created for testing ...");
+        }
+        // Note: Any non-success responses are ignored and not reported.
+        for (String resourceId : collectionObjectIdsCreated) {
+            ClientResponse<Response> res = collectionObjectClient.delete(resourceId);
+        }
+        // Delete persons before PersonAuth
+        for (String resourceId : personIdsCreated) {
+            ClientResponse<Response> res = personAuthClient.deleteItem(personAuthCSID, resourceId);
+        }
+        ClientResponse<Response> res = personAuthClient.delete(personAuthCSID);
+    }
+
+    // ---------------------------------------------------------------
+    // Utility methods used by tests above
+    // ---------------------------------------------------------------
+    @Override
+    public String getServicePathComponent() {
+        return SERVICE_PATH_COMPONENT;
+    }
+
+   private MultipartOutput createCollectionObjectInstance(
+                               String title,
+                               String objNum,
+                               String contentOrganization,
+                               String contentPeople,
+                               String contentPerson,
+                               String inscriber ) {
+        CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
+        collectionObject.setTitle(title);
+        collectionObject.setObjectNumber(objNum);
+        collectionObject.setContentOrganization(contentOrganization);
+        collectionObject.setContentPeople(contentPeople);
+        collectionObject.setContentPerson(contentPerson);
+        collectionObject.setInscriber(inscriber);
+        MultipartOutput multipart = new MultipartOutput();
+        OutputPart commonPart =
+            multipart.addPart(collectionObject, MediaType.APPLICATION_XML_TYPE);
+        commonPart.getHeaders().add("label", collectionObjectClient.getCommonPartName());
+
+        if(logger.isDebugEnabled()){
+            logger.debug("to be created, collectionObject common");
+            logger.debug(objectAsXmlString(collectionObject, CollectionobjectsCommon.class));
+        }
+
+        return multipart;
+    }
+}
index 6785a488e51eb6bbc681f5db81a707e8fe56c31e..ac027467a5099561b08cce6734363b158634f8a6 100644 (file)
  */
 package org.collectionspace.services.collectionobject;
 
-import java.util.List;
 import java.util.ArrayList;
-import java.util.Iterator;
-import java.lang.reflect.Type;
+import java.util.List;
 
 import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
 import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 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.WebApplicationException;
 import javax.ws.rs.core.Context;
@@ -45,33 +43,33 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
-import org.collectionspace.services.common.query.QueryManager;
-import org.collectionspace.services.common.query.IQueryManager;
 import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
+import org.collectionspace.services.common.authorityref.AuthorityRefList;
 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.ServiceContext;
 import org.collectionspace.services.common.document.BadRequestException;
-import org.collectionspace.services.common.document.DocumentNotFoundException;
-import org.collectionspace.services.common.document.DocumentHandler;
 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.document.DocumentWrapper;
+import org.collectionspace.services.common.query.IQueryManager;
+import org.collectionspace.services.common.query.QueryManager;
 import org.collectionspace.services.common.security.UnauthorizedException;
-import org.jboss.resteasy.plugins.providers.multipart.InputPart;
+import org.collectionspace.services.intake.IntakeResource;
+import org.collectionspace.services.intake.IntakesCommonList;
+import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
+import org.collectionspace.services.relation.NewRelationResource;
+import org.collectionspace.services.relation.RelationsCommonList;
+import org.collectionspace.services.relation.RelationshipType;
 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.jboss.resteasy.util.HttpResponseCodes;
+import org.nuxeo.ecm.core.api.DocumentModel;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.collectionspace.services.intake.IntakesCommonList;
-import org.collectionspace.services.intake.IntakeResource;
-
-import org.collectionspace.services.relation.NewRelationResource;
-import org.collectionspace.services.relation.RelationshipType;
-import org.collectionspace.services.relation.RelationsCommonList;
-import org.collectionspace.services.relation.RelationsCommon;
-
 
 /**
  * The Class CollectionObjectResource.
@@ -393,6 +391,37 @@ public class CollectionObjectResource
         
         return result;
     }
+
+    @GET
+    @Path("{csid}/authorityrefs")
+    @Produces("application/xml")
+    public AuthorityRefList getAuthorityRefs(
+               @PathParam("csid") String csid, 
+               @Context UriInfo ui) {
+       AuthorityRefList authRefList = null;
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            DocumentWrapper<DocumentModel> docWrapper = 
+               getRepositoryClient(ctx).getDoc(ctx, csid);
+            RemoteDocumentModelHandlerImpl handler 
+               = (RemoteDocumentModelHandlerImpl)createDocumentHandler(ctx);
+            List<String> authRefFields = ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues("authRef");
+            String prefix = ctx.getCommonPartLabel()+":";
+            authRefList = handler.getAuthorityRefs(docWrapper, prefix, authRefFields);
+        } 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 getAuthorityRefs", e);
+            }
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        return authRefList;
+    }
     
     /**
      * Roundtrip.
index 8345e9b068132887d8a601cb967fc7fb0b830e2f..fd6177686be349f7cd5ecc169c40a330c286f856 100644 (file)
                 <service:part id="1" control_group="Managed"
                               versionable="true" auditable="false"
                               label="collectionobjects_common" updated="" order="1">
+                    <service:properties>
+                                                                                       <types:item><types:key>authRef</types:key><types:value>contentOrganization</types:value></types:item>
+                                                                                       <types:item><types:key>authRef</types:key><types:value>contentPeople</types:value></types:item>
+                                                                                       <types:item><types:key>authRef</types:key><types:value>contentPerson</types:value></types:item>
+                                                                                       <types:item><types:key>authRef</types:key><types:value>inscriber</types:value></types:item>
+                                                                               </service:properties>                                                                                                                   
                     <service:content contentType="application/xml">
                         <service:xmlContent
                             namespaceURI="http://collectionspace.org/services/collectionobject"
                 <service:part id="1" control_group="Managed"
                               versionable="true" auditable="false"
                               label="acquisitions_common" updated="" order="1">
-                    <service:content contentType="application/xml">
+                    <service:properties>
+                                                                                       <types:item><types:key>authRef</types:key><types:value>acquisitionAuthorizer</types:value></types:item>
+                                                                                       <types:item><types:key>authRef</types:key><types:value>acquisitionFundingSource</types:value></types:item>
+                                                                                       <!-- Need to handle repeating ref fields, like "acquisitionSources" -->
+                                                                                       <types:item><types:key>authRef</types:key><types:value>fieldCollector</types:value></types:item>
+                                                                               </service:properties>
+                                                                               <service:content contentType="application/xml">
                         <service:xmlContent
                             namespaceURI="http://collectionspace.org/services/acquisition"
                             schemaLocation="http://collectionspace.org/services/acquisition http://services.collectionspace.org/acquisition/acquisitions_common.xsd">
index 3e86596f8710a3e7bc85c728fa64bea558d139c7..6efb988a71f3add81493c72a1332235b478d1cef 100644 (file)
@@ -29,13 +29,19 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
+
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.BadRequestException;
 import org.collectionspace.services.common.document.DocumentUtils;
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.service.ObjectPartType;
+import org.collectionspace.services.common.vocabulary.RefNameUtils;
 import org.jboss.resteasy.plugins.providers.multipart.InputPart;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.nuxeo.ecm.core.api.DocumentModel;
@@ -182,4 +188,48 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
             ctx.addOutputPart(schema, doc, partMeta.getContent().getContentType());
         } //TODO: handle other media types
     }
+    
+    public AuthorityRefList getAuthorityRefs(
+               DocumentWrapper<DocumentModel> docWrapper,
+               String pathPrefix,
+               List<String> authRefFields) {
+       AuthorityRefList authRefList = new AuthorityRefList();
+        try {
+            DocumentModel docModel = docWrapper.getWrappedObject();
+            List<AuthorityRefList.AuthorityRefItem> list = 
+               authRefList.getAuthorityRefItem();
+
+            for(String field:authRefFields){
+                       String refName = (String)docModel.getPropertyValue(pathPrefix+field);
+                       if(refName==null)
+                               continue;
+               try{
+                       RefNameUtils.AuthorityTermInfo termInfo =
+                               RefNameUtils.parseAuthorityTermInfo(refName);
+                       AuthorityRefList.AuthorityRefItem ilistItem = 
+                               new AuthorityRefList.AuthorityRefItem();
+                       ilistItem.setRefName(refName);
+                       ilistItem.setAuthDisplayName(termInfo.inAuthority.displayName);
+                       ilistItem.setItemDisplayName(termInfo.displayName);
+                       ilistItem.setSourceField(field);
+                       ilistItem.setUri(termInfo.getRelativeUri());
+                    list.add(ilistItem);
+               } catch( Exception e ) {
+                    if (logger.isDebugEnabled()) {
+                        logger.debug("Caught exception in getAuthorityRefs", e);
+                    }
+               }
+            }
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Caught exception in getAuthorityRefs", e);
+            }
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        return authRefList;
+    }
+
+
 }
index e6bd2f7868287675ec931063c07e6b67922754d9..159d79696f964d7980de0ebe1642ef221e743340 100644 (file)
  */
 package org.collectionspace.services.intake;
 
-import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
 import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
 import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 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.WebApplicationException;
 import javax.ws.rs.core.Context;
@@ -42,28 +40,22 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
-import org.collectionspace.services.IntakeJAXBSchema;
 import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
-
-import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
+import org.collectionspace.services.common.authorityref.AuthorityRefList;
 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.ServiceContext;
 import org.collectionspace.services.common.document.DocumentFilter;
-import org.collectionspace.services.common.document.DocumentNotFoundException;
 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.query.QueryManager;
 import org.collectionspace.services.common.security.UnauthorizedException;
-import org.collectionspace.services.common.service.ObjectPartType;
-import org.collectionspace.services.common.vocabulary.RefNameUtils;
-import org.collectionspace.services.intake.IntakesCommonList.IntakeListItem;
-import org.collectionspace.services.intake.nuxeo.IntakeDocumentModelHandler;
-import org.collectionspace.services.nuxeo.util.NuxeoUtils;
+import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 import org.jboss.resteasy.util.HttpResponseCodes;
@@ -218,7 +210,8 @@ public class IntakeResource extends AbstractCollectionSpaceResourceImpl {
             ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             DocumentWrapper<DocumentModel> docWrapper = 
                getRepositoryClient(ctx).getDoc(ctx, csid);
-            IntakeDocumentModelHandler handler = (IntakeDocumentModelHandler)createDocumentHandler(ctx);
+            RemoteDocumentModelHandlerImpl handler 
+               = (RemoteDocumentModelHandlerImpl)createDocumentHandler(ctx);
             List<String> authRefFields = ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues("authRef");
             String prefix = ctx.getCommonPartLabel()+":";
             authRefList = handler.getAuthorityRefs(docWrapper, prefix, authRefFields);
index 15b7c873cd73038afb61e33e486cf1fc02c3bf46..30107afa31e52a503f839767a37e4303b6c1ccb1 100644 (file)
@@ -26,25 +26,11 @@ package org.collectionspace.services.intake.nuxeo;
 import java.util.Iterator;
 import java.util.List;
 
-import javax.ws.rs.PathParam;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-
 import org.collectionspace.services.IntakeJAXBSchema;
-import org.collectionspace.services.common.authorityref.AuthorityRefList;
-import org.collectionspace.services.common.context.MultipartServiceContextFactory;
-import org.collectionspace.services.common.context.MultipartServiceContextImpl;
-import org.collectionspace.services.common.context.ServiceContext;
-import org.collectionspace.services.common.document.DocumentHandler.Action;
 import org.collectionspace.services.common.document.DocumentWrapper;
-import org.collectionspace.services.common.security.UnauthorizedException;
-import org.collectionspace.services.common.vocabulary.RefNameUtils;
 import org.collectionspace.services.intake.IntakesCommon;
 import org.collectionspace.services.intake.IntakesCommonList;
 import org.collectionspace.services.intake.IntakesCommonList.IntakeListItem;
-
 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.nuxeo.ecm.core.api.DocumentModel;
@@ -152,48 +138,6 @@ public class IntakeDocumentModelHandler
     public String getQProperty(String prop) {
         return IntakeConstants.NUXEO_SCHEMA_NAME + ":" + prop;
     }
-    
-    public AuthorityRefList getAuthorityRefs(
-               DocumentWrapper<DocumentModel> docWrapper,
-               String pathPrefix,
-               List<String> authRefFields) {
-       AuthorityRefList authRefList = new AuthorityRefList();
-        try {
-            DocumentModel docModel = docWrapper.getWrappedObject();
-            List<AuthorityRefList.AuthorityRefItem> list = 
-               authRefList.getAuthorityRefItem();
-
-            for(String field:authRefFields){
-                       String refName = (String)docModel.getPropertyValue(pathPrefix+field);
-                       if(refName==null)
-                               continue;
-               try{
-                       RefNameUtils.AuthorityTermInfo termInfo =
-                               RefNameUtils.parseAuthorityTermInfo(refName);
-                       AuthorityRefList.AuthorityRefItem ilistItem = 
-                               new AuthorityRefList.AuthorityRefItem();
-                       ilistItem.setRefName(refName);
-                       ilistItem.setAuthDisplayName(termInfo.inAuthority.displayName);
-                       ilistItem.setItemDisplayName(termInfo.displayName);
-                       ilistItem.setSourceField(field);
-                       ilistItem.setUri(termInfo.getRelativeUri());
-                    list.add(ilistItem);
-               } catch( Exception e ) {
-                    if (logger.isDebugEnabled()) {
-                        logger.debug("Caught exception in getAuthorityRefs", e);
-                    }
-               }
-            }
-        } catch (Exception e) {
-            if (logger.isDebugEnabled()) {
-                logger.debug("Caught exception in getIntakeList", e);
-            }
-            Response response = Response.status(
-                    Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
-            throw new WebApplicationException(response);
-        }
-        return authRefList;
-    }
-
 }