From 92919d8c1d96b5740d8dfcae04addf0be8f1e0a1 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Thu, 20 May 2010 05:29:46 +0000 Subject: [PATCH] CSPACE-1153: Setting Person's displayNameComputed flag to false generates Exception on create. Also fixed an edge-case bug in pagination. --- .../client/test/AbstractServiceTestImpl.java | 2 +- .../document/InvalidDocumentException.java | 6 +++ .../java/RemoteDocumentModelHandlerImpl.java | 4 +- .../client/PersonAuthorityClientUtils.java | 22 ++++++-- .../test/PersonAuthorityServiceTest.java | 6 +++ .../nuxeo/PersonDocumentModelHandler.java | 54 ++++++++++--------- 6 files changed, 63 insertions(+), 31 deletions(-) diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java index 7f2e8860a..1c509d05b 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java @@ -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, diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/InvalidDocumentException.java b/services/common/src/main/java/org/collectionspace/services/common/document/InvalidDocumentException.java index 0abded31b..c1000e963 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/InvalidDocumentException.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/InvalidDocumentException.java @@ -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 InvalidDocumentException without detail message. */ public InvalidDocumentException() { + //empty constructor } /** diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index 269f7cd82..61ba6c808 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -119,8 +119,8 @@ public abstract class RemoteDocumentModelHandlerImpl 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(); diff --git a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java index a62708048..f8053164c 100644 --- a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java +++ b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java @@ -94,10 +94,26 @@ public class PersonAuthorityClientUtils { PersonsCommon person = new PersonsCommon(); person.setInAuthority(inAuthority); person.setRefName(personRefName); - String value = null; - value = personInfo.get(PersonJAXBSchema.DISPLAY_NAME_COMPUTED); - boolean displayNameComputed = (value==null) || value.equalsIgnoreCase("true"); + + // + // If the 'DISPLAY_NAME_COMPUTED' property is null or empty then + // we'll assume that the service consumer wants us to compute the + // display name. Otherwise, we'll parse the value with the Boolean class. + // + String booleanStr = personInfo.get(PersonJAXBSchema.DISPLAY_NAME_COMPUTED); + boolean displayNameComputed = true; + if (booleanStr != null && booleanStr.length() > 0) { + displayNameComputed = Boolean.parseBoolean(booleanStr); + } person.setDisplayNameComputed(displayNameComputed); + + String displayName = personInfo.get(PersonJAXBSchema.DISPLAY_NAME); + person.setDisplayName(displayName); + if (displayNameComputed == false && displayName == null) { + throw new IllegalArgumentException("displayName cannot be null when displayComputed is 'false'"); + } + + String value; if((value = (String)personInfo.get(PersonJAXBSchema.FORE_NAME))!=null) person.setForeName(value); if((value = (String)personInfo.get(PersonJAXBSchema.MIDDLE_NAME))!=null) diff --git a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java index ad22c3e71..8916880b0 100644 --- a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java +++ b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java @@ -229,6 +229,12 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { String identifier = createIdentifier(); String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName, "John Wayne", true); Map johnWayneMap = new HashMap(); + // + // 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"); diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonDocumentModelHandler.java b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonDocumentModelHandler.java index 67b1f3b98..1e1ef6d81 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonDocumentModelHandler.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonDocumentModelHandler.java @@ -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 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(); } -- 2.47.3