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;
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()
MultipartOutput multipart = createAcquisitionInstance(
"April 1, 2010",
acquisitionAuthorizerRefName,
- acquisitionFundingSourceRefName);
+ acquisitionFundingSourceRefName,
+ acquisitionSourcesRefNames);
AcquisitionClient acquisitionClient = new AcquisitionClient();
ClientResponse<Response> res = acquisitionClient.create(multipart);
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 ) {
// 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 =
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);
<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
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;
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. "