From: Aron Roberts Date: Thu, 15 Jul 2010 22:19:23 +0000 (+0000) Subject: CSPACE-1637,CSPACE-2066: Authority references can now be returned from value instance... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=6f5ad239044a555bd6ff94d9a481aa94e1fbb298;p=tmp%2Fjakarta-migration.git CSPACE-1637,CSPACE-2066: Authority references can now be returned from value instances of repeatable fields, as well as - as was previously implemented - from non-repeatable fields. As prototyped in Acquisition records, specifying 'acquisitionSources' as an authRef field in tenant bindings will now return the authority references in each of its 'acquisitionSource' children. This has been tested to date only with simple repeatability: a parent and a set of 0-n immediate children. The current solution will need additional testing to verify that it works with arbitrary repeatability; and a slightly different approach using DocModel.getProperties(), as suggested by Richard and mentioned as well in code comments, may potentially be needed in that case. --- 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 index 69eca30e4..e0f84a604 100644 --- 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 @@ -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 acquisitionSourcesRefNames = new ArrayList(); + 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 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 sources = acquisitionSources.getAcquisitionSource(); + for (String refName : sources) { + Assert.assertTrue(acquisitionSourcesRefNames.contains(refName)); + } // Get the auth refs and check them ClientResponse res2 = @@ -321,12 +334,19 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest { private MultipartOutput createAcquisitionInstance( String accessionDate, String acquisitionAuthorizer, - String acquisitionFundingSource) { + String acquisitionFundingSource, + List acquisitionSources) { AcquisitionsCommon acquisition = new AcquisitionsCommon(); acquisition.setAccessionDate(accessionDate); acquisition.setAcquisitionAuthorizer(acquisitionAuthorizer); acquisition.setAcquisitionFundingSource(acquisitionFundingSource); + AcquisitionSourceList acqSourcesList = new AcquisitionSourceList(); + List 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); diff --git a/services/common/src/main/config/services/tenant-bindings.xml b/services/common/src/main/config/services/tenant-bindings.xml index cf07151c9..c5223b55e 100644 --- a/services/common/src/main/config/services/tenant-bindings.xml +++ b/services/common/src/main/config/services/tenant-bindings.xml @@ -659,7 +659,7 @@ authRefacquisitionAuthorizer authRefacquisitionFundingSource - + authRefacquisitionSources authRefacquisitionAuthorizer authRefacquisitionFundingSource - + authRefacquisitionSources public AuthorityRefList getAuthorityRefs( DocumentWrapper docWrapper, List 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 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 refNames = new ArrayList(); + Object val = docModel.getPropertyValue(field); + if (val instanceof String) + refNames.add((String) val); + else if (val instanceof List) { + refNames = (List) 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. "