From c62d801096a81fd0bdf78618e3421d3fc6ada4b1 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Sat, 7 May 2011 14:36:55 +0000 Subject: [PATCH] CSPACE-3865: More naming tweaks. --- .../client/TaxonomyAuthorityClient.java | 3 +- .../client/TaxonomyAuthorityClientUtils.java | 30 ++-- .../test/TaxonomyAuthorityServiceTest.java | 22 ++- .../services/TaxonJAXBSchema.java | 13 ++ .../taxonomy/TaxonomyAuthorityResource.java | 23 ++-- .../nuxeo/TaxonDocumentModelHandler.java | 130 +++++++++--------- .../taxonomy/nuxeo/TaxonomyConstants.java | 6 +- 7 files changed, 114 insertions(+), 113 deletions(-) create mode 100644 services/taxonomy/jaxb/src/main/java/org/collectionspace/services/TaxonJAXBSchema.java diff --git a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java index 1b3efa953..5f6897b5b 100644 --- a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java +++ b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java @@ -31,7 +31,6 @@ import javax.ws.rs.core.Response; //import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.common.authorityref.AuthorityRefDocList; -import org.collectionspace.services.contact.ContactsCommonList; import org.collectionspace.services.taxonomy.TaxonomyauthorityCommonList; import org.collectionspace.services.taxonomy.TaxonCommonList; import org.collectionspace.services.client.TaxonomyAuthorityProxy; @@ -81,7 +80,7 @@ public class TaxonomyAuthorityClient extends AuthorityClientImpl taxonInfo, String headerLabel) { TaxonCommon taxon = new TaxonCommon(); - String shortId = taxonInfo.get(TaxonomyJAXBSchema.SHORT_IDENTIFIER); - String displayName = taxonInfo.get(TaxonomyJAXBSchema.DISPLAY_NAME); + String shortId = taxonInfo.get(TaxonJAXBSchema.SHORT_IDENTIFIER); + String displayName = taxonInfo.get(TaxonJAXBSchema.DISPLAY_NAME); taxon.setShortIdentifier(shortId); String taxonomyRefName = createTaxonomyRefName(taxonomyAuthRefName, shortId, displayName); taxon.setRefName(taxonomyRefName); String value = null; - value = taxonInfo.get(TaxonomyJAXBSchema.DISPLAY_NAME_COMPUTED); + value = taxonInfo.get(TaxonJAXBSchema.DISPLAY_NAME_COMPUTED); boolean displayNameComputed = (value == null) || value.equalsIgnoreCase("true"); taxon.setDisplayNameComputed(displayNameComputed); - if ((value = (String) taxonInfo.get(TaxonomyJAXBSchema.NAME)) != null) { + if ((value = (String) taxonInfo.get(TaxonJAXBSchema.NAME)) != null) { taxon.setTaxonFullName(value); } - if ((value = (String) taxonInfo.get(TaxonomyJAXBSchema.RANK)) != null) { + if ((value = (String) taxonInfo.get(TaxonJAXBSchema.RANK)) != null) { taxon.setTaxonRank(value); } - if ((value = (String) taxonInfo.get(TaxonomyJAXBSchema.TERM_STATUS)) != null) { + if ((value = (String) taxonInfo.get(TaxonJAXBSchema.TERM_STATUS)) != null) { taxon.setTermStatus(value); } // FIXME: Add additional fields in the Taxon record here. @@ -99,7 +99,7 @@ public class TaxonomyAuthorityClientUtils { /** * @param vcsid CSID of the authority to create a new taxon in * @param TaxonomyauthorityRefName The refName for the authority - * @param taxonMap the properties for the new Taxonomy + * @param taxonMap the properties for the new Taxon * @param client the service client * @return the CSID of the new item */ @@ -111,8 +111,8 @@ public class TaxonomyAuthorityClientUtils { // Type of service request being tested ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; - String displayName = taxonMap.get(TaxonomyJAXBSchema.DISPLAY_NAME); - String displayNameComputedStr = taxonMap.get(TaxonomyJAXBSchema.DISPLAY_NAME_COMPUTED); + String displayName = taxonMap.get(TaxonJAXBSchema.DISPLAY_NAME); + String displayNameComputedStr = taxonMap.get(TaxonJAXBSchema.DISPLAY_NAME_COMPUTED); boolean displayNameComputed = (displayNameComputedStr == null) || displayNameComputedStr.equalsIgnoreCase("true"); if (displayName == null) { if (!displayNameComputed) { @@ -121,7 +121,7 @@ public class TaxonomyAuthorityClientUtils { } displayName = prepareDefaultDisplayName( - taxonMap.get(TaxonomyJAXBSchema.NAME)); + taxonMap.get(TaxonJAXBSchema.NAME)); } if (logger.isDebugEnabled()) { @@ -138,13 +138,13 @@ public class TaxonomyAuthorityClientUtils { if (!REQUEST_TYPE.isValidStatusCode(statusCode)) { throw new RuntimeException("Could not create Item: \"" - + taxonMap.get(TaxonomyJAXBSchema.SHORT_IDENTIFIER) + + taxonMap.get(TaxonJAXBSchema.SHORT_IDENTIFIER) + "\" in Taxonomyauthority: \"" + TaxonomyauthorityRefName + "\" " + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); } if (statusCode != EXPECTED_STATUS_CODE) { throw new RuntimeException("Unexpected Status when creating Item: \"" - + taxonMap.get(TaxonomyJAXBSchema.SHORT_IDENTIFIER) + + taxonMap.get(TaxonJAXBSchema.SHORT_IDENTIFIER) + "\" in Taxonomyauthority: \"" + TaxonomyauthorityRefName + "\", Status:" + statusCode); } newID = extractId(res); @@ -155,7 +155,7 @@ public class TaxonomyAuthorityClientUtils { return newID; } - public static PoxPayloadOut createTaxonomyInstance( + public static PoxPayloadOut createTaxonInstance( String commonPartXML, String headerLabel) throws DocumentException { PoxPayloadOut multipart = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); PayloadOutputPart commonPart = multipart.addPart(commonPartXML, @@ -178,7 +178,7 @@ public class TaxonomyAuthorityClientUtils { ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; PoxPayloadOut multipart = - createTaxonomyInstance(commonPartXML, client.getItemCommonPartName()); + createTaxonInstance(commonPartXML, client.getItemCommonPartName()); String newID = null; ClientResponse res = client.createItem(vcsid, multipart); try { diff --git a/services/taxonomy/client/src/test/java/org/collectionspace/services/client/test/TaxonomyAuthorityServiceTest.java b/services/taxonomy/client/src/test/java/org/collectionspace/services/client/test/TaxonomyAuthorityServiceTest.java index 205f812b4..00ef63c12 100644 --- a/services/taxonomy/client/src/test/java/org/collectionspace/services/client/test/TaxonomyAuthorityServiceTest.java +++ b/services/taxonomy/client/src/test/java/org/collectionspace/services/client/test/TaxonomyAuthorityServiceTest.java @@ -27,16 +27,12 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.collectionspace.services.TaxonomyJAXBSchema; +import org.collectionspace.services.TaxonJAXBSchema; import org.collectionspace.services.client.AuthorityClient; import org.collectionspace.services.client.CollectionSpaceClient; -import org.collectionspace.services.client.ContactClient; -import org.collectionspace.services.client.ContactClientUtils; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.contact.ContactsCommon; -import org.collectionspace.services.contact.ContactsCommonList; import org.collectionspace.services.client.TaxonomyAuthorityClient; import org.collectionspace.services.client.TaxonomyAuthorityClientUtils; import org.collectionspace.services.jaxb.AbstractCommonList; @@ -244,10 +240,10 @@ public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FI TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); Map taxonMap = new HashMap(); // TODO Make loc type and status be controlled vocabs. - taxonMap.put(TaxonomyJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID); - taxonMap.put(TaxonomyJAXBSchema.NAME, TEST_NAME); - taxonMap.put(TaxonomyJAXBSchema.RANK, TEST_RANK); - taxonMap.put(TaxonomyJAXBSchema.TERM_STATUS, TEST_STATUS); + taxonMap.put(TaxonJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID); + taxonMap.put(TaxonJAXBSchema.NAME, TEST_NAME); + taxonMap.put(TaxonJAXBSchema.RANK, TEST_RANK); + taxonMap.put(TaxonJAXBSchema.TERM_STATUS, TEST_STATUS); // FIXME: Add additional fields in the Taxon record here. String newID = TaxonomyAuthorityClientUtils.createItemInAuthority(vcsid, @@ -258,7 +254,7 @@ public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FI if (knownItemResourceId == null) { setKnownItemResource(newID, TEST_SHORTID); if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownItemResourceId=" + newID); + logger.debug(testName + ": knownItemResourceId=" + newID + " inAuthority=" + vcsid); } } @@ -1112,9 +1108,9 @@ public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FI // The only relevant ID may be the one used in update(), below. TaxonomyAuthorityClient client = new TaxonomyAuthorityClient(); Map nonexMap = new HashMap(); - nonexMap.put(TaxonomyJAXBSchema.NAME, TEST_NAME); - nonexMap.put(TaxonomyJAXBSchema.SHORT_IDENTIFIER, "nonEx"); - nonexMap.put(TaxonomyJAXBSchema.TERM_STATUS, TEST_STATUS); + nonexMap.put(TaxonJAXBSchema.NAME, TEST_NAME); + nonexMap.put(TaxonJAXBSchema.SHORT_IDENTIFIER, "nonEx"); + nonexMap.put(TaxonJAXBSchema.TERM_STATUS, TEST_STATUS); PoxPayloadOut multipart = TaxonomyAuthorityClientUtils.createTaxonInstance( TaxonomyAuthorityClientUtils.createTaxonomyRefName(knownResourceRefName, "nonEx", "Non Existent"), diff --git a/services/taxonomy/jaxb/src/main/java/org/collectionspace/services/TaxonJAXBSchema.java b/services/taxonomy/jaxb/src/main/java/org/collectionspace/services/TaxonJAXBSchema.java new file mode 100644 index 000000000..4a7b5dab3 --- /dev/null +++ b/services/taxonomy/jaxb/src/main/java/org/collectionspace/services/TaxonJAXBSchema.java @@ -0,0 +1,13 @@ +/** + * + */ +package org.collectionspace.services; +import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; + +public interface TaxonJAXBSchema extends AuthorityItemJAXBSchema { + final static String TAXON_COMMON = "taxon_common"; + final static String NAME = "taxonFullName"; + final static String RANK = "taxonRank"; + +} + diff --git a/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/TaxonomyAuthorityResource.java b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/TaxonomyAuthorityResource.java index 52be61353..2dd0227ee 100644 --- a/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/TaxonomyAuthorityResource.java +++ b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/TaxonomyAuthorityResource.java @@ -43,7 +43,7 @@ import javax.ws.rs.core.UriInfo; import org.collectionspace.services.client.TaxonomyAuthorityClient; import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; -import org.collectionspace.services.TaxonomyJAXBSchema; +import org.collectionspace.services.TaxonJAXBSchema; import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl; import org.collectionspace.services.common.ClientType; import org.collectionspace.services.common.ServiceMain; @@ -78,30 +78,25 @@ import org.slf4j.LoggerFactory; @Path(TaxonomyAuthorityClient.SERVICE_PATH) @Consumes("application/xml") @Produces("application/xml") -public class TaxonomyAuthorityResource - extends AuthorityResource { +public class TaxonomyAuthorityResource + extends AuthorityResource { private final static String taxonomyAuthorityServiceName = "taxonomyauthorities"; - private final static String TAXONOMYAUTHORITY_COMMON = "taxonomyauthority_common"; - - // FIXME: May be desirable to change this to the plural form 'taxa', - // both here and in related config. + private final static String TAXONOMYAUTHORITY_COMMON = "taxonomyauthority_common"; private final static String taxonomyItemServiceName = "taxon"; - private final static String TAXON_COMMON = "taxon_common"; - + private final static String TAXONOMYITEM_COMMON = "taxon_common"; /** The logger. */ final Logger logger = LoggerFactory.getLogger(TaxonomyAuthorityResource.class); //FIXME retrieve client type from configuration /** The Constant CLIENT_TYPE. */ final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); - + /** * Instantiates a new taxonomy authority resource. */ public TaxonomyAuthorityResource() { - super(TaxonomyauthorityCommon.class, TaxonomyAuthorityResource.class, - TAXONOMYAUTHORITY_COMMON, TAXON_COMMON); + super(TaxonomyauthorityCommon.class, TaxonomyAuthorityResource.class, + TAXONOMYAUTHORITY_COMMON, TAXONOMYITEM_COMMON); } /* (non-Javadoc) @@ -124,6 +119,6 @@ public class TaxonomyAuthorityResource @Override public Class getCommonPartClass() { - return TaxonomyauthorityCommon.class; + return TaxonomyauthorityCommon.class; } } diff --git a/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonDocumentModelHandler.java b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonDocumentModelHandler.java index a75e40337..95f52bba1 100644 --- a/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonDocumentModelHandler.java +++ b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonDocumentModelHandler.java @@ -29,7 +29,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -import org.collectionspace.services.TaxonomyJAXBSchema; +import org.collectionspace.services.TaxonJAXBSchema; import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.service.ObjectPartType; @@ -65,28 +65,28 @@ public class TaxonDocumentModelHandler * Common part schema label */ private static final String COMMON_PART_LABEL = "taxon_common"; - + public TaxonDocumentModelHandler() { - super(COMMON_PART_LABEL); + super(COMMON_PART_LABEL); } - + /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper) */ @Override public void handleCreate(DocumentWrapper wrapDoc) throws Exception { - // first fill all the parts of the document - super.handleCreate(wrapDoc); - handleDisplayNames(wrapDoc.getWrappedObject()); + // first fill all the parts of the document + super.handleCreate(wrapDoc); + handleDisplayNames(wrapDoc.getWrappedObject()); } - + /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper) */ @Override public void handleUpdate(DocumentWrapper wrapDoc) throws Exception { - super.handleUpdate(wrapDoc); - handleDisplayNames(wrapDoc.getWrappedObject()); + super.handleUpdate(wrapDoc); + handleDisplayNames(wrapDoc.getWrappedObject()); } /** @@ -96,79 +96,77 @@ public class TaxonDocumentModelHandler * @throws Exception the exception */ private void handleDisplayNames(DocumentModel docModel) throws Exception { - String commonPartLabel = getServiceContext().getCommonPartLabel("taxon"); - Boolean displayNameComputed = (Boolean) docModel.getProperty(commonPartLabel, - TaxonomyJAXBSchema.DISPLAY_NAME_COMPUTED); - Boolean shortDisplayNameComputed = (Boolean) docModel.getProperty(commonPartLabel, - TaxonomyJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED); - if(displayNameComputed==null) - displayNameComputed = true; - if(shortDisplayNameComputed==null) - shortDisplayNameComputed = true; - if (displayNameComputed || shortDisplayNameComputed) { - String displayName = prepareDefaultDisplayName( - (String)docModel.getProperty(commonPartLabel, TaxonomyJAXBSchema.NAME )); - if (displayNameComputed) { - docModel.setProperty(commonPartLabel, TaxonomyJAXBSchema.DISPLAY_NAME, - displayName); - } - if (shortDisplayNameComputed) { - docModel.setProperty(commonPartLabel, TaxonomyJAXBSchema.SHORT_DISPLAY_NAME, - displayName); - } - } + String commonPartLabel = getServiceContext().getCommonPartLabel("taxon"); + Boolean displayNameComputed = (Boolean) docModel.getProperty(commonPartLabel, + TaxonJAXBSchema.DISPLAY_NAME_COMPUTED); + Boolean shortDisplayNameComputed = (Boolean) docModel.getProperty(commonPartLabel, + TaxonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED); + if (displayNameComputed == null) { + displayNameComputed = true; + } + if (shortDisplayNameComputed == null) { + shortDisplayNameComputed = true; + } + if (displayNameComputed || shortDisplayNameComputed) { + String displayName = prepareDefaultDisplayName( + (String) docModel.getProperty(commonPartLabel, TaxonJAXBSchema.NAME)); + if (displayNameComputed) { + docModel.setProperty(commonPartLabel, TaxonJAXBSchema.DISPLAY_NAME, + displayName); + } + if (shortDisplayNameComputed) { + docModel.setProperty(commonPartLabel, TaxonJAXBSchema.SHORT_DISPLAY_NAME, + displayName); + } + } } - + /** * Produces a default displayName from the basic name and dates fields. * @see TaxonomyAuthorityClientUtils.prepareDefaultDisplayName() which * duplicates this logic, until we define a service-general utils package * that is neither client nor service specific. - * @param foreName - * @param middleName - * @param surName - * @param birthDate - * @param deathDate + * @param name * @return * @throws Exception */ private static String prepareDefaultDisplayName( - String name ) throws Exception { - StringBuilder newStr = new StringBuilder(); - newStr.append(name); - return newStr.toString(); + String name) throws Exception { + StringBuilder newStr = new StringBuilder(); + newStr.append(name); + return newStr.toString(); } - + /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper) */ @Override - public TaxonCommonList extractCommonPartList( - DocumentWrapper wrapDoc) throws Exception { - TaxonCommonList coList = extractPagingInfo(new TaxonCommonList(), wrapDoc); + public TaxonCommonList extractCommonPartList( + DocumentWrapper wrapDoc) throws Exception { + TaxonCommonList coList = extractPagingInfo(new TaxonCommonList(), wrapDoc); AbstractCommonList commonList = (AbstractCommonList) coList; commonList.setFieldsReturned("displayName|refName|shortIdentifier|uri|csid"); - List list = coList.getTaxonListItem(); - Iterator iter = wrapDoc.getWrappedObject().iterator(); - String commonPartLabel = getServiceContext().getCommonPartLabel("taxon"); - while (iter.hasNext()) { - DocumentModel docModel = iter.next(); - TaxonListItem ilistItem = new TaxonListItem(); - ilistItem.setDisplayName((String) docModel.getProperty( - commonPartLabel, AuthorityItemJAXBSchema.DISPLAY_NAME)); - ilistItem.setShortIdentifier((String) docModel.getProperty(commonPartLabel, - AuthorityItemJAXBSchema.SHORT_IDENTIFIER)); - ilistItem.setRefName((String) docModel.getProperty(commonPartLabel, - AuthorityItemJAXBSchema.REF_NAME)); - String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString()); - ilistItem.setUri("/taxonomyauthorities/" + inAuthority + "/items/" - + id); - ilistItem.setCsid(id); - list.add(ilistItem); - } - - return coList; - } + List list = coList.getTaxonListItem(); + Iterator iter = wrapDoc.getWrappedObject().iterator(); + String commonPartLabel = getServiceContext().getCommonPartLabel("taxon"); + while (iter.hasNext()) { + DocumentModel docModel = iter.next(); + TaxonListItem ilistItem = new TaxonListItem(); + ilistItem.setDisplayName((String) docModel.getProperty( + commonPartLabel, AuthorityItemJAXBSchema.DISPLAY_NAME)); + ilistItem.setShortIdentifier((String) docModel.getProperty(commonPartLabel, + AuthorityItemJAXBSchema.SHORT_IDENTIFIER)); + ilistItem.setRefName((String) docModel.getProperty(commonPartLabel, + AuthorityItemJAXBSchema.REF_NAME)); + String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString()); + ilistItem.setUri("/taxonomyauthorities/" + inAuthority + "/items/" + + id); + ilistItem.setCsid(id); + list.add(ilistItem); + } + + return coList; + } /** * getQProperty converts the given property to qualified schema property diff --git a/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyConstants.java b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyConstants.java index 2274aa8e1..0133fcaac 100644 --- a/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyConstants.java +++ b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonomyConstants.java @@ -29,7 +29,7 @@ package org.collectionspace.services.taxonomy.nuxeo; */ public class TaxonomyConstants { - public final static String NUXEO_DOCTYPE = "Taxonomy"; - public final static String NUXEO_SCHEMA_NAME = "taxonomy"; - public final static String NUXEO_DC_TITLE = "CollectionSpace-Taxonomy"; + public final static String NUXEO_DOCTYPE = "Taxon"; + public final static String NUXEO_SCHEMA_NAME = "taxon"; + public final static String NUXEO_DC_TITLE = "CollectionSpace-Taxon"; } -- 2.47.3