]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1153: Setting Person's displayNameComputed flag to false generates Exception...
authorRichard Millet <richard.millet@berkeley.edu>
Thu, 20 May 2010 05:29:46 +0000 (05:29 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Thu, 20 May 2010 05:29:46 +0000 (05:29 +0000)
services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java
services/common/src/main/java/org/collectionspace/services/common/document/InvalidDocumentException.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.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/PersonDocumentModelHandler.java

index 7f2e8860a5c56a7a31d27efec92a924ba0da21dc..1c509d05b83853fffcbfecfee5a5172c73eee893 100644 (file)
@@ -365,7 +365,7 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements
         }
         
         // if there are any remainders be sure to paginate them as well
-        long mod = totalItems % pageSize;
+        long mod = pageSize != 0 ? totalItems % pageSize : totalItems;
         if (mod != 0) {
                list = (AbstractCommonList) this.readList(testName, client, pageSize, pagesTotal);
                assertPaginationInfo(testName,
index 0abded31b2b3020ecab62f77e5dd087e711348f0..c1000e963a1067a2c2394e6f5be0dca1da464b71 100644 (file)
@@ -35,9 +35,15 @@ package org.collectionspace.services.common.document;
 public class InvalidDocumentException extends BadRequestException {
 
     /**
+        * Default UID for serialization
+        */
+       private static final long serialVersionUID = 1L;
+
+       /**
      * Creates a new instance of <code>InvalidDocumentException</code> without detail message.
      */
     public InvalidDocumentException() {
+       //empty constructor
     }
 
     /**
index 269f7cd82a1bc5c8e8f05db73a970c2004f8ef22..61ba6c808b7de5da62eb9e40df0816b759ad861d 100644 (file)
@@ -119,8 +119,8 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
        
        DocumentFilter docFilter = this.getDocumentFilter();
        long pageSize = docFilter.getPageSize();
-       long pageNum = docFilter.getOffset() / pageSize;
-       // set the page size and page numer
+       long pageNum = pageSize != 0 ? docFilter.getOffset() / pageSize : pageSize;
+       // set the page size and page number
        commonList.setPageNum(pageNum);
        commonList.setPageSize(pageSize);
        DocumentModelList docList = wrapDoc.getWrappedObject();
index a627080480626fd405c7e199daad054088e06625..f8053164caa34ab7cb75cf82a27f05eb2c5fd6b2 100644 (file)
@@ -94,10 +94,26 @@ public class PersonAuthorityClientUtils {
         PersonsCommon person = new PersonsCommon();\r
         person.setInAuthority(inAuthority);\r
                person.setRefName(personRefName);\r
-               String value = null;\r
-       value = personInfo.get(PersonJAXBSchema.DISPLAY_NAME_COMPUTED);\r
-       boolean displayNameComputed = (value==null) || value.equalsIgnoreCase("true"); \r
+               \r
+               //\r
+               // If the 'DISPLAY_NAME_COMPUTED' property is null or empty then\r
+               // we'll assume that the service consumer wants us to compute the\r
+               // display name.  Otherwise, we'll parse the value with the Boolean class.\r
+               //\r
+       String booleanStr = personInfo.get(PersonJAXBSchema.DISPLAY_NAME_COMPUTED);\r
+       boolean displayNameComputed = true;\r
+       if (booleanStr != null && booleanStr.length() > 0) {\r
+               displayNameComputed = Boolean.parseBoolean(booleanStr);\r
+       }\r
        person.setDisplayNameComputed(displayNameComputed);\r
+\r
+               String displayName = personInfo.get(PersonJAXBSchema.DISPLAY_NAME);\r
+               person.setDisplayName(displayName);\r
+       if (displayNameComputed == false && displayName == null) {\r
+               throw new IllegalArgumentException("displayName cannot be null when displayComputed is 'false'");\r
+       }       \r
+       \r
+       String value;\r
         if((value = (String)personInfo.get(PersonJAXBSchema.FORE_NAME))!=null)\r
                person.setForeName(value);\r
         if((value = (String)personInfo.get(PersonJAXBSchema.MIDDLE_NAME))!=null)\r
index ad22c3e71948272dcc710e1bdee716773f824f55..8916880b05657cadccbabae13c417dea414b0b7c 100644 (file)
@@ -229,6 +229,12 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
         String identifier = createIdentifier();
         String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName, "John Wayne", true);
         Map<String, String> johnWayneMap = new HashMap<String,String>();
+        //
+        // Fill the property map
+        //
+        johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
+        johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME, "John Wayne");
+        
         johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME);
         johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME);
         johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
index 67b1f3b9831f78ae56c4f6730eceb1d445a827b2..1e1ef6d812c204bac4e64f3a992c73e6408620a4 100644 (file)
@@ -30,6 +30,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.collectionspace.services.PersonJAXBSchema;
+import org.collectionspace.services.common.document.InvalidDocumentException;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.service.ObjectPartType;
@@ -38,8 +39,10 @@ import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.person.PersonsCommon;
 import org.collectionspace.services.person.PersonsCommonList;
 import org.collectionspace.services.person.PersonsCommonList.PersonListItem;
+
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -127,16 +130,15 @@ public class PersonDocumentModelHandler
        String commonPartLabel = getServiceContext().getCommonPartLabel("persons");
        Boolean displayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
                        PersonJAXBSchema.DISPLAY_NAME_COMPUTED);
-       if (displayNameComputed) {
+       if (displayNameComputed == true) {
                String displayName = prepareDefaultDisplayName(
-                       (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.FORE_NAME ),                     
-                       (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.MIDDLE_NAME ),                           
-                       (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.SUR_NAME ),                      
-                       (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.BIRTH_DATE ),                            
-                       (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.DEATH_DATE )                     
-                       );
-                       docModel.setProperty(commonPartLabel, PersonJAXBSchema.DISPLAY_NAME,
-                                       displayName);
+                               (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.FORE_NAME),                      
+                               (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.MIDDLE_NAME),                            
+                               (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.SUR_NAME),                       
+                               (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.BIRTH_DATE),                     
+                               (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.DEATH_DATE));
+               docModel.setProperty(commonPartLabel, PersonJAXBSchema.DISPLAY_NAME,
+                               displayName);
        }
     }
        
@@ -156,16 +158,17 @@ public class PersonDocumentModelHandler
     private static String prepareDefaultDisplayName(
                String foreName, String middleName, String surName,
                String birthDate, String deathDate ) throws Exception {
-       StringBuilder newStr = new StringBuilder();
-               final String sep = " ";
-               final String dateSep = "-";
+               final String SEP = " ";
+               final String DATE_SEP = "-";
+
+               StringBuilder newStr = new StringBuilder();
                List<String> nameStrings = 
                        Arrays.asList(foreName, middleName, surName);
                boolean firstAdded = false;
-       for(String partStr : nameStrings ){
-                       if(null != partStr ) {
-                               if(firstAdded) {
-                                       newStr.append(sep);
+       for (String partStr : nameStrings ){
+                       if (partStr != null) {
+                               if (firstAdded == true) {
+                                       newStr.append(SEP);
                                }
                                newStr.append(partStr);
                                firstAdded = true;
@@ -173,23 +176,24 @@ public class PersonDocumentModelHandler
        }
        // Now we add the dates. In theory could have dates with no name, but that is their problem.
        boolean foundBirth = false;
-               if(null != birthDate) {
-                       if(firstAdded) {
-                               newStr.append(sep);
+               if (birthDate != null) {
+                       if (firstAdded) {
+                               newStr.append(SEP);
                        }
                        newStr.append(birthDate);
-               newStr.append(dateSep);         // Put this in whether there is a death date or not
+               newStr.append(DATE_SEP);                // Put this in whether there is a death date or not
                        foundBirth = true;
                }
-               if(null != deathDate) {
-                       if(!foundBirth) {
-                               if(firstAdded) {
-                                       newStr.append(sep);
+               if (deathDate != null) {
+                       if (!foundBirth) {
+                               if (firstAdded == true) {
+                                       newStr.append(SEP);
                                }
-                       newStr.append(dateSep);
+                       newStr.append(DATE_SEP);
                        }
                        newStr.append(deathDate);
                }
+               
                return newStr.toString();
     }