From 3138921a6a62eb74e6eac18dd9908fa428fde2a3 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Wed, 9 May 2012 12:34:50 -0700 Subject: [PATCH] CSPACE-5122: Updated Taxon authority item schema to reflect latest wiki schema. --- .../tenants/tenant-bindings-proto.xml | 17 +- .../main/resources/schemas/taxon_common.xsd | 28 +- .../client/TaxonomyAuthorityClientUtils.java | 78 +++-- .../test/TaxonomyAuthorityServiceTest.java | 314 +++++++++--------- .../jaxb/src/main/resources/taxon_common.xsd | 26 +- 5 files changed, 260 insertions(+), 203 deletions(-) diff --git a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml index c9ee8f2df..ebdc654e1 100644 --- a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml +++ b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml @@ -2404,10 +2404,14 @@ + + @@ -2452,6 +2456,13 @@ authRef taxonAuthorGroupList/*/taxonAuthor + + termRef @@ -2465,6 +2476,10 @@ termRef taxonAuthorGroupList/*/taxonAuthorType + + termRef + commonNameGroupList/*/commonNameLanguage + termRef taxonomicStatus diff --git a/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/schemas/taxon_common.xsd b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/schemas/taxon_common.xsd index 2f8e427f4..34ad97d0d 100644 --- a/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/schemas/taxon_common.xsd +++ b/services/taxonomy/3rdparty/nuxeo-platform-cs-taxonomy/src/main/resources/schemas/taxon_common.xsd @@ -28,22 +28,16 @@ - - - + - - - - - - + + @@ -64,6 +58,20 @@ + + + + + + + + + + + + + + @@ -85,7 +93,7 @@ - + diff --git a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClientUtils.java b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClientUtils.java index 71656e40c..886e79981 100644 --- a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClientUtils.java +++ b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClientUtils.java @@ -5,16 +5,20 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; - import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; - import org.apache.commons.io.FileUtils; import org.collectionspace.services.TaxonJAXBSchema; import org.collectionspace.services.client.test.ServiceRequestType; import org.collectionspace.services.common.api.Tools; -import org.collectionspace.services.taxonomy.*; +import org.collectionspace.services.taxonomy.CommonNameGroupList; +import org.collectionspace.services.taxonomy.TaxonAuthorGroupList; +import org.collectionspace.services.taxonomy.TaxonCitationList; +import org.collectionspace.services.taxonomy.TaxonCommon; +import org.collectionspace.services.taxonomy.TaxonTermGroup; +import org.collectionspace.services.taxonomy.TaxonTermGroupList; +import org.collectionspace.services.taxonomy.TaxonomyauthorityCommon; import org.dom4j.DocumentException; import org.jboss.resteasy.client.ClientResponse; import org.slf4j.Logger; @@ -27,8 +31,9 @@ public class TaxonomyAuthorityClientUtils { /** * Creates a new Taxonomy Authority + * * @param displayName The displayName used in UI, etc. - * @param refName The proper refName for this authority + * @param refName The proper refName for this authority * @param headerLabel The common part label * @return The PoxPayloadOut payload for the create call */ @@ -53,17 +58,20 @@ public class TaxonomyAuthorityClientUtils { } /** - * @param taxonomyAuthRefName The proper refName for this authority. - * @param taxonInfo the properties for the new instance of a term in this authority. - * @param taxonAuthorGroupList an author group list (values of a repeatable group in the term record). - * @param taxonCitationList a citation list (values of a repeatable scalar in the term record). + * @param taxonomyAuthRefName The proper refName for this authority. + * @param taxonInfo the properties for the new instance of a term in this + * authority. + * @param taxonAuthorGroupList an author group list (values of a repeatable + * group in the term record). + * @param taxonCitationList a citation list (values of a repeatable scalar + * in the term record). * @param headerLabel The common part label * @return The PoxPayloadOut payload for the create call */ public static PoxPayloadOut createTaxonInstance( - String taxonomyAuthRefName, Map taxonInfo, List terms, - TaxonAuthorGroupList taxonAuthorGroupList, TaxonCitationList taxonCitationList, - String headerLabel) { + String taxonomyAuthRefName, Map taxonInfo, + List terms, TaxonAuthorGroupList taxonAuthorGroupList, + TaxonCitationList taxonCitationList, CommonNameGroupList commonNameGroupList, String headerLabel) { TaxonCommon taxon = new TaxonCommon(); String shortId = taxonInfo.get(TaxonJAXBSchema.SHORT_IDENTIFIER); taxon.setShortIdentifier(shortId); @@ -78,15 +86,15 @@ public class TaxonomyAuthorityClientUtils { terms = getTermGroupInstance(getGeneratedIdentifier()); } } + terms.get(0).setTermDisplayName(taxonInfo.get(TaxonJAXBSchema.NAME)); + terms.get(0).setTermName(taxonInfo.get(TaxonJAXBSchema.NAME)); terms.get(0).setTermStatus(taxonInfo.get(TaxonJAXBSchema.TERM_STATUS)); - termList.getTaxonTermGroup().addAll(terms); - taxon.setTaxonTermGroupList(termList); - + terms.get(0).setTaxonomicStatus(taxonInfo.get(TaxonJAXBSchema.TAXONOMIC_STATUS)); + termList.getTaxonTermGroup().addAll(terms); + taxon.setTaxonTermGroupList(termList); + String value = null; // Fields specific to this authority record type. - if ((value = (String) taxonInfo.get(TaxonJAXBSchema.NAME)) != null) { - taxon.setTaxonFullName(value); - } if ((value = (String) taxonInfo.get(TaxonJAXBSchema.TAXON_RANK)) != null) { taxon.setTaxonRank(value); } @@ -96,21 +104,18 @@ public class TaxonomyAuthorityClientUtils { if ((value = (String) taxonInfo.get(TaxonJAXBSchema.TAXON_YEAR)) != null) { taxon.setTaxonYear(value); } - if ((value = (String) taxonInfo.get(TaxonJAXBSchema.TAXONOMIC_STATUS)) != null) { - taxon.setTaxonomicStatus(value); - } - if ((value = (String) taxonInfo.get(TaxonJAXBSchema.TAXON_IS_NAMED_HYBRID)) != null) { - taxon.setTaxonIsNamedHybrid(value); - } if (taxonCitationList != null) { taxon.setTaxonCitationList(taxonCitationList); } - if (taxonAuthorGroupList != null) { taxon.setTaxonAuthorGroupList(taxonAuthorGroupList); } + if (commonNameGroupList != null) { + taxon.setCommonNameGroupList(commonNameGroupList); + } - // FIXME: When the field isNamedHybrid becomes Boolean, add it as such to sample instances. + taxon.setTaxonIsNamedHybrid(Boolean.parseBoolean( + taxonInfo.get(TaxonJAXBSchema.TAXON_IS_NAMED_HYBRID))); PoxPayloadOut multipart = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); PayloadOutputPart commonPart = multipart.addPart(taxon, @@ -134,7 +139,8 @@ public class TaxonomyAuthorityClientUtils { public static String createItemInAuthority(String vcsid, String TaxonomyauthorityRefName, Map taxonMap, List terms, TaxonAuthorGroupList taxonAuthorGroupList, - TaxonCitationList taxonCitationList, TaxonomyAuthorityClient client) { + TaxonCitationList taxonCitationList, CommonNameGroupList commonNameGroupList, + TaxonomyAuthorityClient client) { // Expected status code: 201 Created int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); // Type of service request being tested @@ -159,7 +165,7 @@ public class TaxonomyAuthorityClientUtils { } PoxPayloadOut multipart = createTaxonInstance(TaxonomyauthorityRefName, - taxonMap, terms, taxonAuthorGroupList, taxonCitationList, client.getItemCommonPartName()); + taxonMap, terms, taxonAuthorGroupList, taxonCitationList, commonNameGroupList, client.getItemCommonPartName()); String newID = null; ClientResponse res = client.createItem(vcsid, multipart); try { @@ -296,10 +302,11 @@ public class TaxonomyAuthorityClientUtils { * specific call to a service does not fall within a set of valid status * codes for that service. * - * @param serviceRequestType A type of service request (e.g. CREATE, DELETE). + * @param serviceRequestType A type of service request (e.g. CREATE, + * DELETE). * - * @param statusCode The invalid status code that was returned in the response, - * from submitting that type of request to the service. + * @param statusCode The invalid status code that was returned in the + * response, from submitting that type of request to the service. * * @return An error message. */ @@ -310,10 +317,11 @@ public class TaxonomyAuthorityClientUtils { /** * Produces a default displayName from the basic name and dates fields. + * * @see TaxonomyDocumentModelHandler.prepareDefaultDisplayName() which * duplicates this logic, until we define a service-general utils package * that is neither client nor service specific. - * @param name + * @param name * @return */ public static String prepareDefaultDisplayName( @@ -322,7 +330,7 @@ public class TaxonomyAuthorityClientUtils { newStr.append(name); return newStr.toString(); } - + public static List getTermGroupInstance(String identifier) { if (Tools.isBlank(identifier)) { identifier = getGeneratedIdentifier(); @@ -334,8 +342,8 @@ public class TaxonomyAuthorityClientUtils { terms.add(term); return terms; } - + private static String getGeneratedIdentifier() { - return "id" + new Date().getTime(); - } + return "id" + new Date().getTime(); + } } 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 45fb4eac1..eda82f38f 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 @@ -1,24 +1,23 @@ /** - * 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: + * 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 + * http://www.collectionspace.org http://wiki.collectionspace.org * * Copyright (c)) 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. + * 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. + * 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; @@ -37,6 +36,7 @@ import org.collectionspace.services.client.TaxonomyAuthorityClient; import org.collectionspace.services.client.TaxonomyAuthorityClientUtils; import org.collectionspace.services.client.TaxonomyAuthorityProxy; import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.taxonomy.CommonNameGroupList; import org.collectionspace.services.taxonomy.TaxonAuthorGroup; import org.collectionspace.services.taxonomy.TaxonAuthorGroupList; import org.collectionspace.services.taxonomy.TaxonCitationList; @@ -55,18 +55,18 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.Test; /** - * TaxonomyAuthorityServiceTest, carries out tests against a - * deployed and running TaxonomyAuthority Service. + * TaxonomyAuthorityServiceTest, carries out tests against a deployed and + * running TaxonomyAuthority Service. * - * $LastChangedRevision$ - * $LastChangedDate$ + * $LastChangedRevision$ $LastChangedDate$ */ public class TaxonomyAuthorityServiceTest extends AbstractAuthorityServiceTest { - /** The logger. */ + /** + * The logger. + */ private final String CLASS_NAME = TaxonomyAuthorityServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(TaxonomyAuthorityServiceTest.class); - private final String TEST_SHORTID = "CentauruspleurexanthemusGreen1832"; private final String TEST_TERM_STATUS = "accepted"; private final String TEST_TAXON_FULL_NAME = "Centaurus pleurexanthemus Green 1832"; @@ -83,7 +83,8 @@ public class TaxonomyAuthorityServiceTest extends AbstractAuthorityServiceTest NULL_TAXON_TERMS_LIST = null; private final TaxonAuthorGroupList NULL_TAXON_AUTHOR_GROUP_LIST = null; private final TaxonCitationList NULL_TAXON_CITATION_LIST = null; - + private final CommonNameGroupList NULL_COMMON_NAME_GROUP_LIST = null; + private String knownResourceShortIdentifer = null; private String knownTaxonomyTypeRefName = null; @@ -100,9 +101,10 @@ public class TaxonomyAuthorityServiceTest extends AbstractAuthorityServiceTest getClientInstance() { @@ -150,6 +152,12 @@ public class TaxonomyAuthorityServiceTest extends AbstractAuthorityServiceTest commonNameGroups = commonNameGroupList.getCommonNameGroup(); + CommonNameGroup commonNameGroup = new CommonNameGroup(); + commonNameGroup.setCommonName(TEST_TAXON_FULL_NAME); + commonNameGroups.add(commonNameGroup); // FIXME: Add additional fields in the Taxon record here, // including at least one each of: @@ -157,7 +165,8 @@ public class TaxonomyAuthorityServiceTest extends AbstractAuthorityServiceTest res = client.readItem(knownResourceId, knownItemResourceId); @@ -199,7 +208,7 @@ public class TaxonomyAuthorityServiceTest extends AbstractAuthorityServiceTest 0); terms.get(0).setTermDisplayName(null); terms.get(0).setTermName(null); - + PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), taxon); setupUpdateWithInvalidBody(); // we expect a failure here res = client.updateItem(knownResourceId, knownItemResourceId, output); try { - assertStatusCode(res, testName); + assertStatusCode(res, testName); } finally { res.releaseConnection(); } @@ -229,7 +238,7 @@ public class TaxonomyAuthorityServiceTest extends AbstractAuthorityServiceTest terms = termList.getTaxonTermGroup(); - Assert.assertNotNull(terms); - Assert.assertTrue(terms.size() > 0); - terms.get(0).setTermDisplayName("updated-" + terms.get(0).getTermDisplayName()); - terms.get(0).setTermName("updated-" + terms.get(0).getTermName()); - result.setTaxonTermGroupList(termList); - return result; - } - - @Override - protected void compareUpdatedItemInstances(TaxonCommon original, - TaxonCommon updated) throws Exception { - - TaxonTermGroupList originalTermList = original.getTaxonTermGroupList(); - Assert.assertNotNull(originalTermList); - List originalTerms = originalTermList.getTaxonTermGroup(); - Assert.assertNotNull(originalTerms); - Assert.assertTrue(originalTerms.size() > 0); - - TaxonTermGroupList updatedTermList = updated.getTaxonTermGroupList(); - Assert.assertNotNull(updatedTermList); - List updatedTerms = updatedTermList.getTaxonTermGroup(); - Assert.assertNotNull(updatedTerms); - Assert.assertTrue(updatedTerms.size() > 0); - - Assert.assertEquals(updatedTerms.get(0).getTermDisplayName(), + } + + // + // Authority item specific overrides + // + @Override + protected String createItemInAuthority(String authorityId) { + return createItemInAuthority(authorityId, null /* + * refname + */); + } + + @Override + protected TaxonCommon updateItemInstance(TaxonCommon taxonCommon) { + TaxonCommon result = taxonCommon; + TaxonTermGroupList termList = taxonCommon.getTaxonTermGroupList(); + Assert.assertNotNull(termList); + List terms = termList.getTaxonTermGroup(); + Assert.assertNotNull(terms); + Assert.assertTrue(terms.size() > 0); + terms.get(0).setTermDisplayName("updated-" + terms.get(0).getTermDisplayName()); + terms.get(0).setTermName("updated-" + terms.get(0).getTermName()); + result.setTaxonTermGroupList(termList); + return result; + } + + @Override + protected void compareUpdatedItemInstances(TaxonCommon original, + TaxonCommon updated) throws Exception { + + TaxonTermGroupList originalTermList = original.getTaxonTermGroupList(); + Assert.assertNotNull(originalTermList); + List originalTerms = originalTermList.getTaxonTermGroup(); + Assert.assertNotNull(originalTerms); + Assert.assertTrue(originalTerms.size() > 0); + + TaxonTermGroupList updatedTermList = updated.getTaxonTermGroupList(); + Assert.assertNotNull(updatedTermList); + List updatedTerms = updatedTermList.getTaxonTermGroup(); + Assert.assertNotNull(updatedTerms); + Assert.assertTrue(updatedTerms.size() > 0); + + Assert.assertEquals(updatedTerms.get(0).getTermDisplayName(), originalTerms.get(0).getTermDisplayName(), "Value in updated record did not match submitted data."); - } + } - @Override - protected void verifyReadItemInstance(TaxonCommon item) throws Exception { - Assert.assertNotNull(item.getTaxonFullName(), "Field value is unexpectedly null."); - Assert.assertEquals(item.getTaxonFullName(), TEST_TAXON_FULL_NAME, - "Field value " + item.getTaxonFullName() + @Override + protected void verifyReadItemInstance(TaxonCommon item) throws Exception { + + TaxonTermGroupList termList = item.getTaxonTermGroupList(); + Assert.assertNotNull(termList); + List terms = termList.getTaxonTermGroup(); + Assert.assertNotNull(terms); + Assert.assertTrue(terms.size() > 0); + + String preferredTermName = terms.get(0).getTermName(); + Assert.assertNotNull(preferredTermName, "Field value is unexpectedly null."); + Assert.assertEquals(preferredTermName, TEST_TAXON_FULL_NAME, + "Field value " + preferredTermName + "does not match expected value " + TEST_TAXON_FULL_NAME); - } + } - @Override - protected PoxPayloadOut createNonExistenceItemInstance( - String commonPartName, String identifier) { + @Override + protected PoxPayloadOut createNonExistenceItemInstance( + String commonPartName, String identifier) { Map nonexMap = new HashMap(); nonexMap.put(TaxonJAXBSchema.NAME, TEST_TAXON_FULL_NAME); nonexMap.put(TaxonJAXBSchema.SHORT_IDENTIFIER, "nonEx"); @@ -528,7 +546,7 @@ public class TaxonomyAuthorityServiceTest extends AbstractAuthorityServiceTest - - - - - - - - + + @@ -67,6 +61,20 @@ + + + + + + + + + + + + + + @@ -88,7 +96,7 @@ - + -- 2.47.3