]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5119,CSPACE-5135,CSPACE-5138: All Person tests now pass. Validation that each...
authorAron Roberts <aron@socrates.berkeley.edu>
Thu, 3 May 2012 00:33:14 +0000 (17:33 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Thu, 3 May 2012 00:33:14 +0000 (17:33 -0700)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java
services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java

index 38031921f67f4f68bb0b67261d7a8151d6701123..8f60e0359e68eb8d661f7eae31ce678ebe39e034 100644 (file)
@@ -675,11 +675,6 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             String qualifiedDisplayNameField =
                     NuxeoUtils.getPrimaryElPathPropertyName(authorityItemCommonSchemaName,
                         getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
-                    // authorityItemCommonSchemaName + ":" + getItemTermInfoGroupXPathBase()
-                    //    + "/0/" + AuthorityItemJAXBSchema.TERM_DISPLAY_NAME;
-
-                    // NuxeoUtils.getPrimaryXPathPropertyName(authorityItemCommonSchemaName, 
-                    //     getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
 
             // Note that docType defaults to the ServiceName, so we're fine with that.
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = null;
index ad85f2a2e5edf9768b19e0d867eb5b63308cd721..c440b5a096aeb78387676b670f2613dc2d89c6e8 100644 (file)
@@ -170,7 +170,6 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
             field.setElement(AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
             field.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(
                     authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME));
-            // field.setXpath(AuthorityItemJAXBSchema.DISPLAY_NAME);
             list.add(field);
         }
         if (!hasShortId) {
@@ -190,7 +189,6 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
             field.setElement(AuthorityItemJAXBSchema.TERM_STATUS);
             field.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(
                     authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_STATUS));
-            // field.setXpath(AuthorityItemJAXBSchema.TERM_STATUS);
             list.add(field);
         }
         return list;
@@ -217,7 +215,8 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
             logger.warn("Creating Authority Item with no displayName!");
         }
         *
-        */
+        */        
+        
         // CSPACE-3178:
         // handleDisplayNameAsShortIdentifier(wrapDoc.getWrappedObject(), authorityItemCommonSchemaName);
         // refName includes displayName, so we force a correct value here.
index 392721e8e1fc1f4aa0bce77aad0f06953396f9f9..a85a861602508eee41f6cec067598519b3400427 100644 (file)
@@ -72,11 +72,6 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
     /** The logger. */
     private final String CLASS_NAME = PersonAuthorityServiceTest.class.getName();
     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
-    private final String REFNAME = "refName";
-    private final String TERM_DISPLAY_NAME = "termDisplayName";
-    // private final String TERM_DISPLAY_NAME_ELPATH =
-    //        NuxeoUtils.getPrimaryElPathPropertyName(null,
-    //            new PersonAuthorityClient().getTermInfoGroupXpathBase(), TERM_DISPLAY_NAME);
 
     @Override
     public String getServicePathComponent() {
@@ -679,6 +674,7 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
         List<PersonTermGroup> terms = termList.getPersonTermGroup();
         Assert.assertNotNull(terms);
         terms.get(0).setTermDisplayName(null);
+        terms.get(0).setTermName(null);
 
         // Submit the updated resource to the service and store the response.
         PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
@@ -825,11 +821,11 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
 
         for (AbstractCommonList.ListItem item : items) {
             String value =
-                    AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME);
+                    AbstractCommonListUtils.ListItemGetElementValue(item, AuthorityItemJAXBSchema.REF_NAME);
             Assert.assertTrue((null != value), "Item refName is null!");
             
             value =
-                    AbstractCommonListUtils.ListItemGetElementValue(item, TERM_DISPLAY_NAME);
+                    AbstractCommonListUtils.ListItemGetElementValue(item, AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
             Assert.assertTrue((null != value), "Item displayName is null!");
         }
         if (logger.isTraceEnabled()) {
@@ -1430,6 +1426,8 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
         
         List<PersonTermGroup> terms = new ArrayList<PersonTermGroup>();
         PersonTermGroup term = new PersonTermGroup();
+        term.setTermDisplayName("John Wayne");
+        term.setTermName("John Wayne");
         term.setForeName("John");
         term.setSurName("Wayne");
         terms.add(term);
index fe36ecd5f4daa9edf9ac352c2ef5750e1b38af69..0bfb7897b50701e52696cad8602b8f4dacc62c7b 100644 (file)
@@ -1,45 +1,48 @@
 /**
- *  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
-
- *  Copyright 2009 University of California at Berkeley
-
- *  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.
+ * 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
+ *
+ * Copyright 2009 University of California at Berkeley
+ *
+ * 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.
  */
 package org.collectionspace.services.person.nuxeo;
 
+import java.util.List;
 import java.util.regex.Pattern;
+import org.collectionspace.services.common.api.Tools;
 import org.collectionspace.services.person.PersonsCommon;
 import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentHandler.Action;
 import org.collectionspace.services.common.document.InvalidDocumentException;
 import org.collectionspace.services.common.document.ValidatorHandler;
+import org.collectionspace.services.person.PersonTermGroup;
+import org.collectionspace.services.person.PersonTermGroupList;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * PersonValidatorHandler
- * 
- * Validates data supplied when attempting to create and/or update Person records.
- * 
- * $LastChangedRevision: $
- * $LastChangedDate: $
+ *
+ * Validates data supplied when attempting to create and/or update Person
+ * records.
+ *
+ * $LastChangedRevision: $ $LastChangedDate: $
  */
 public class PersonValidatorHandler implements ValidatorHandler {
 
@@ -52,49 +55,61 @@ public class PersonValidatorHandler implements ValidatorHandler {
         if (logger.isDebugEnabled()) {
             logger.debug("validate() action=" + action.name());
         }
-        
+
         // Bail out if the validation action is for delete.
         if (action.equals(Action.DELETE)) {
-               return;
+            return;
         }
-        
+
         try {
             MultipartServiceContext mctx = (MultipartServiceContext) ctx;
             PersonsCommon person = (PersonsCommon) mctx.getInputPart(mctx.getCommonPartLabel(),
                     PersonsCommon.class);
             String msg = "";
             boolean invalid = false;
-            
-            if(person != null) {       // No guarantee that there is a common part in every post/update.
-                
-                   // Validation occurring on both creates and updates
-                
-                    // FIXME Add validation logic here to ensure that every term info group must contain
-                    // any required data elements.  (Potential example: every term info group must contain
-                    // a non-null, non-whitespace-only value in either of the term or displayName fields.)
-                
-                    /*
-                   String displayName = person.getDisplayName();
-                   if (!person.isDisplayNameComputed() && ((displayName == null) || displayName.trim().isEmpty())) {
-                       invalid = true;
-                       msg += "displayName must be non-null and non-blank if displayNameComputed is false!";
-                   }
-                    * 
-                    */
-                   
-                   // Validation specific to creates or updates
-                   if (action.equals(Action.CREATE)) {
-                       String shortId = person.getShortIdentifier();
-                       // Per CSPACE-2215, shortIdentifier values that are null (missing)
-                       // oe the empty string are now legally accepted in create payloads.
-                       // In either of those cases, a short identifier will be synthesized from
-                       // a display name or supplied in another manner.
-                       if ((shortId != null) && (shortIdBadPattern.matcher(shortId).find())) {
-                           invalid = true;
-                           msg += "shortIdentifier must only contain standard word characters";
-                       }
-                   } else if (action.equals(Action.UPDATE)) {
-                   }
+
+            if (person != null) {      // No guarantee that there is a common part in every post/update.
+
+                // Validation occurring on both creates and updates
+
+                /*
+                 * String displayName = person.getDisplayName(); if
+                 * (!person.isDisplayNameComputed() && ((displayName == null) ||
+                 * displayName.trim().isEmpty())) { invalid = true; msg +=
+                 * "displayName must be non-null and non-blank if
+                 * displayNameComputed is false!"; }
+                 *
+                 */
+
+                if (!containsAtLeastOneTerm(person)) {
+                    invalid = true;
+                    msg += "Authority items must contain at least one term.";
+                }
+
+                if (!allTermsContainNameOrDisplayName(person)) {
+                    invalid = true;
+                    msg += "Each term group in an authority item must contain "
+                            + "a non-empty term name or "
+                            + "a non-empty term display name.";
+                }
+
+                // Validation specific to creates or updates
+                if (action.equals(Action.CREATE)) {
+
+                    // shortIdentifier value must contain only word characters
+                    String shortId = person.getShortIdentifier();
+                    if ((shortId != null) && (shortIdBadPattern.matcher(shortId).find())) {
+                        invalid = true;
+                        msg += "shortIdentifier must only contain standard word characters";
+                    }
+
+                    // Note: Per CSPACE-2215, shortIdentifier values that are null (missing)
+                    // or the empty string are now legally accepted in create payloads.
+                    // In either of those cases, a short identifier will be synthesized from
+                    // a display name or supplied in another manner.
+
+                } else if (action.equals(Action.UPDATE)) {
+                }
             }
 
             if (invalid) {
@@ -107,4 +122,28 @@ public class PersonValidatorHandler implements ValidatorHandler {
             throw new InvalidDocumentException(e);
         }
     }
+
+    private boolean containsAtLeastOneTerm(PersonsCommon person) {
+        PersonTermGroupList termGroupList = person.getPersonTermGroupList();
+        if (termGroupList == null) {
+            return false;
+        }
+        List<PersonTermGroup> termGroups = termGroupList.getPersonTermGroup();
+        if ((termGroups == null) || (termGroups.size() == 0)) {
+            return false;
+        }
+        return true;
+    }
+
+    private boolean allTermsContainNameOrDisplayName(PersonsCommon person) {
+        PersonTermGroupList termGroupList = person.getPersonTermGroupList();
+        List<PersonTermGroup> termGroups = termGroupList.getPersonTermGroup();
+        for (PersonTermGroup termGroup : termGroups) {
+            if (Tools.isBlank(termGroup.getTermName()) || Tools.isBlank(termGroup.getTermDisplayName()) ){
+                return false;
+            }
+        }
+        return true;
+    }
+    
 }