]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1637,CSPACE-2066: Authority references can now be returned from value instance...
authorAron Roberts <aron@socrates.berkeley.edu>
Thu, 15 Jul 2010 22:19:23 +0000 (22:19 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Thu, 15 Jul 2010 22:19:23 +0000 (22:19 +0000)
services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java
services/common/src/main/config/services/tenant-bindings.xml
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java

index 69eca30e41c6f4917e8fdd60b3a41e426afa5769..e0f84a604d6f20ce3d494cf9d70aa23abf14b824 100644 (file)
@@ -38,7 +38,7 @@ import org.collectionspace.services.client.PersonAuthorityClientUtils;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.collectionspace.services.acquisition.AcquisitionsCommon;
-//import org.collectionspace.services.acquisition.AcquisitionsCommonList;
+import org.collectionspace.services.acquisition.AcquisitionSourceList;
 
 import org.jboss.resteasy.client.ClientResponse;
 
@@ -73,9 +73,8 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest {
     private String personAuthCSID = null; 
     private String acquisitionAuthorizerRefName = null;
     private String acquisitionFundingSourceRefName = null;
-    // Not ready for multiples, yet
-    //private String acquisitionSourcesRefName = null;
-    private final int NUM_AUTH_REFS_EXPECTED = 2;
+    private List<String> acquisitionSourcesRefNames = new ArrayList<String>();
+    private final int NUM_AUTH_REFS_EXPECTED = 4;
 
     /* (non-Javadoc)
      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
@@ -117,7 +116,8 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest {
         MultipartOutput multipart = createAcquisitionInstance(
             "April 1, 2010",
            acquisitionAuthorizerRefName,
-           acquisitionFundingSourceRefName);
+           acquisitionFundingSourceRefName,
+            acquisitionSourcesRefNames);
 
         AcquisitionClient acquisitionClient = new AcquisitionClient();
         ClientResponse<Response> res = acquisitionClient.create(multipart);
@@ -169,9 +169,17 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest {
         acquisitionAuthorizerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
         personIdsCreated.add(csid);
         
-        csid = createPerson("Sammy", "Source", "sammySource", authRefName);
+        csid = createPerson("Fran", "Funding-Source", "franFundingSource", authRefName);
         acquisitionFundingSourceRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
         personIdsCreated.add(csid);
+
+        csid = createPerson("Sammy", "SourceOne", "sammySourceOne", authRefName);
+        acquisitionSourcesRefNames.add(PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null));
+        personIdsCreated.add(csid);
+
+        csid = createPerson("Serena", "SourceTwo", "serenaSourceTwo", authRefName);
+        acquisitionSourcesRefNames.add(PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null));
+        personIdsCreated.add(csid);
     }
     
     protected String createPerson(String firstName, String surName, String shortId, String authRefName ) {
@@ -225,6 +233,11 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest {
         // Check a couple of fields
         Assert.assertEquals(acquisition.getAcquisitionAuthorizer(), acquisitionAuthorizerRefName);
         Assert.assertEquals(acquisition.getAcquisitionFundingSource(), acquisitionFundingSourceRefName);
+        AcquisitionSourceList acquisitionSources = acquisition.getAcquisitionSources();
+        List<String> sources = acquisitionSources.getAcquisitionSource();
+        for (String refName : sources) {
+          Assert.assertTrue(acquisitionSourcesRefNames.contains(refName));
+        }
         
         // Get the auth refs and check them
         ClientResponse<AuthorityRefList> res2 =
@@ -321,12 +334,19 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest {
    private MultipartOutput createAcquisitionInstance(
        String accessionDate,
        String acquisitionAuthorizer,
-       String acquisitionFundingSource) {
+       String acquisitionFundingSource,
+        List<String> acquisitionSources) {
        
         AcquisitionsCommon acquisition = new AcquisitionsCommon();
         acquisition.setAccessionDate(accessionDate);
         acquisition.setAcquisitionAuthorizer(acquisitionAuthorizer);
         acquisition.setAcquisitionFundingSource(acquisitionFundingSource);
+        AcquisitionSourceList acqSourcesList = new AcquisitionSourceList();
+        List<String> sources = acqSourcesList.getAcquisitionSource();
+        for (String source: acquisitionSources) {
+          sources.add(source);
+        }
+        acquisition.setAcquisitionSources(acqSourcesList);
         MultipartOutput multipart = new MultipartOutput();
         OutputPart commonPart =
             multipart.addPart(acquisition, MediaType.APPLICATION_XML_TYPE);
index cf07151c9148aa77253e1a97529d78e0ba2f8d4f..c5223b55e4d3304e668d3e78fc6d8456f6063846 100644 (file)
                     <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>acquisitionSources</types:value></types:item>
                     </service:properties>
                     <service:content contentType="application/xml">
                         <service:xmlContent
                     <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>acquisitionSources</types:value></types:item>
                     </service:properties>
                     <service:content contentType="application/xml">
                         <service:xmlContent
index 25efd1c35bd9f740abce1aff4c44989de223bbfb..8785252d83ea728c8808bcd38b61130d6828835f 100644 (file)
@@ -24,6 +24,7 @@
 package org.collectionspace.services.nuxeo.client.java;
 
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -299,31 +300,63 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
     public AuthorityRefList getAuthorityRefs(
                DocumentWrapper<DocumentModel> docWrapper,
                List<String> authRefFields) throws PropertyException {
+        final String FIELD_REFNAME_DELIMITER = "|";
+        final String FIELD_REFNAME_DELIMITER_REGEX = "\\" + FIELD_REFNAME_DELIMITER;
        AuthorityRefList authRefList = new AuthorityRefList();
        try {
                DocumentModel docModel = docWrapper.getWrappedObject();
                List<AuthorityRefList.AuthorityRefItem> list = authRefList.getAuthorityRefItem();
 
                for (String field : authRefFields) {
-                       String refName = (String) docModel.getPropertyValue(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) {
-                               // FIXME: Do we need to throw this Exception here?
-                               if (logger.isDebugEnabled()) {
-                                       logger.debug("Caught exception in getAuthorityRefs", e);
-                               }
-                       }
+                        // FIXME If the code used below doesn't support
+                        // arbitrary levels of nesting; e.g. "get all authrefs
+                        // in any children of a parent," then we might use
+                        // docModel.getProperties() instead,
+                        List<String> refNames = new ArrayList<String>();
+                        Object val = docModel.getPropertyValue(field);
+                        if (val instanceof String)
+                         refNames.add((String) val);
+                        else if (val instanceof List) {
+                          refNames = (List<String>) val;
+                        }
+                        for (String refName : refNames) {
+                            if (refName == null || refName.trim().isEmpty())
+                                    continue;
+                            try {
+                                    // If the refName is prefixed by a field name
+                                    // and a delimiter, this means that it was
+                                    // found in a child of the specified authref field.
+                                    //
+                                    // Store the child field's name as the field name.
+                                    // Then strip off the child's name and the delimiter
+                                    // from the refName.
+                                    //
+                                    // FIXME: Move this 'split' code to its own utility method.
+                                    // FIXME: Verify that the behavior description above
+                                    // is accurate for arbitrary levels of nesting.
+                                    if (refName.indexOf(FIELD_REFNAME_DELIMITER) > 0) {
+                                        String[] refNameParts =
+                                            refName.split(FIELD_REFNAME_DELIMITER_REGEX);
+                                        field = refNameParts[0];
+                                        refName = refNameParts[1];
+                                    }
+                                    
+                                    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) {
+                                    // FIXME: Do we need to throw this Exception here?
+                                    if (logger.isDebugEnabled()) {
+                                            logger.debug("Caught exception in getAuthorityRefs", e);
+                                    }
+                            }
+                        }
                }
        } catch (PropertyException pe) {
                String msg = "Attempted to retrieve value for invalid or missing authority field. "