]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-725 - Refactored instance creation methods into a shared utility class.
authorPatrick Schmitz <pschmitz@berkeley.edu>
Wed, 13 Jan 2010 23:10:49 +0000 (23:10 +0000)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Wed, 13 Jan 2010 23:10:49 +0000 (23:10 +0000)
services/person/client/.classpath
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java [new file with mode: 0644]
services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java
services/person/import/.classpath
services/person/import/.project
services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonDocumentModelHandler.java

index cec251a4372bbde6e079c10e6c02204d8441af50..425cd1620f3d44a6c3d1d8c43488a67552f09765 100644 (file)
@@ -1,7 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
 <classpath>\r
        <classpathentry kind="src" output="target/classes" path="src/main/java"/>\r
+       <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>\r
        <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>\r
+       <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>\r
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>\r
        <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>\r
        <classpathentry kind="output" path="target/classes"/>\r
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
new file mode 100644 (file)
index 0000000..3f3a964
--- /dev/null
@@ -0,0 +1,236 @@
+package org.collectionspace.services.client;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.ws.rs.core.MediaType;\r
+import javax.ws.rs.core.MultivaluedMap;\r
+import javax.ws.rs.core.Response;\r
+\r
+import org.collectionspace.services.PersonJAXBSchema;\r
+import org.collectionspace.services.client.test.ServiceRequestType;\r
+import org.collectionspace.services.person.PersonsCommon;\r
+import org.collectionspace.services.person.PersonauthoritiesCommon;\r
+import org.jboss.resteasy.client.ClientResponse;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
+import org.jboss.resteasy.plugins.providers.multipart.OutputPart;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+public class PersonAuthorityClientUtils {\r
+    private static final Logger logger =\r
+        LoggerFactory.getLogger(PersonAuthorityClientUtils.class);\r
+\r
+    public static MultipartOutput createPersonAuthorityInstance(\r
+               String displayName, String refName, String headerLabel ) {\r
+        PersonauthoritiesCommon personAuthority = new PersonauthoritiesCommon();\r
+        personAuthority.setDisplayName(displayName);\r
+        personAuthority.setRefName(refName);\r
+        personAuthority.setVocabType("PersonAuthority");\r
+        MultipartOutput multipart = new MultipartOutput();\r
+        OutputPart commonPart = multipart.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);\r
+        commonPart.getHeaders().add("label", headerLabel);\r
+\r
+        if(logger.isDebugEnabled()){\r
+               logger.debug("to be created, personAuthority common ", \r
+                                       personAuthority, PersonauthoritiesCommon.class);\r
+        }\r
+\r
+        return multipart;\r
+    }\r
+\r
+    public static MultipartOutput createPersonInstance(String inAuthority, \r
+               String personRefName, Map<String, String> personInfo, String headerLabel){\r
+        PersonsCommon person = new PersonsCommon();\r
+        person.setInAuthority(inAuthority);\r
+               person.setRefName(personRefName);\r
+               String value = null;\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
+               person.setMiddleName(value);\r
+        if((value = (String)personInfo.get(PersonJAXBSchema.SUR_NAME))!=null)\r
+               person.setSurName(value);\r
+        if((value = (String)personInfo.get(PersonJAXBSchema.INITIALS))!=null)\r
+               person.setInitials(value);\r
+        if((value = (String)personInfo.get(PersonJAXBSchema.SALUTATIONS))!=null)\r
+               person.setSalutation(value);\r
+        if((value = (String)personInfo.get(PersonJAXBSchema.TITLE))!=null)\r
+               person.setTitle(value);\r
+        if((value = (String)personInfo.get(PersonJAXBSchema.NAME_ADDITIONS))!=null)\r
+               person.setNameAdditions(value);\r
+        if((value = (String)personInfo.get(PersonJAXBSchema.BIRTH_DATE))!=null)\r
+               person.setBirthDate(value);\r
+        if((value = (String)personInfo.get(PersonJAXBSchema.DEATH_DATE))!=null)\r
+               person.setDeathDate(value);\r
+        if((value = (String)personInfo.get(PersonJAXBSchema.BIRTH_PLACE))!=null)\r
+               person.setBirthPlace(value);\r
+        if((value = (String)personInfo.get(PersonJAXBSchema.DEATH_PLACE))!=null)\r
+               person.setDeathPlace(value);\r
+        if((value = (String)personInfo.get(PersonJAXBSchema.GROUP))!=null)\r
+               person.setGroup(value);\r
+        if((value = (String)personInfo.get(PersonJAXBSchema.NATIONALITY))!=null)\r
+               person.setNationality(value);\r
+        if((value = (String)personInfo.get(PersonJAXBSchema.GENDER))!=null)\r
+               person.setGender(value);\r
+        if((value = (String)personInfo.get(PersonJAXBSchema.OCCUPATION))!=null)\r
+               person.setOccupation(value);\r
+        if((value = (String)personInfo.get(PersonJAXBSchema.SCHOOL_OR_STYLE))!=null)\r
+               person.setSchoolOrStyle(value);\r
+        if((value = (String)personInfo.get(PersonJAXBSchema.BIO_NOTE))!=null)\r
+               person.setBioNote(value);\r
+        if((value = (String)personInfo.get(PersonJAXBSchema.NAME_NOTE))!=null)\r
+               person.setNameNote(value);\r
+        MultipartOutput multipart = new MultipartOutput();\r
+        OutputPart commonPart = multipart.addPart(person,\r
+            MediaType.APPLICATION_XML_TYPE);\r
+        commonPart.getHeaders().add("label", headerLabel);\r
+\r
+        if(logger.isDebugEnabled()){\r
+               logger.debug("to be created, person common ", person, PersonsCommon.class);\r
+        }\r
+\r
+        return multipart;\r
+    }\r
+    \r
+    public static String createItemInAuthority(String vcsid, \r
+               String personAuthorityRefName, Map<String,String> personMap,\r
+               PersonAuthorityClient client ) {\r
+       // Expected status code: 201 Created\r
+       int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();\r
+       // Type of service request being tested\r
+       ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;\r
+       String displayName = \r
+               prepareDefaultDisplayName(\r
+                       personMap.get(PersonJAXBSchema.FORE_NAME),\r
+                       personMap.get(PersonJAXBSchema.MIDDLE_NAME),\r
+                       personMap.get(PersonJAXBSchema.SUR_NAME),\r
+                       personMap.get(PersonJAXBSchema.BIRTH_DATE),\r
+                       personMap.get(PersonJAXBSchema.DEATH_DATE));\r
+       String refName = createPersonRefName(personAuthorityRefName, \r
+                       displayName);\r
+\r
+       if(logger.isDebugEnabled()){\r
+               logger.debug("Import: Create Item: \""+displayName\r
+                               +"\" in personAuthorityulary: \"" + personAuthorityRefName +"\"");\r
+       }\r
+       MultipartOutput multipart = \r
+               createPersonInstance( vcsid, refName,\r
+                       personMap, client.getItemCommonPartName() );\r
+       ClientResponse<Response> res = client.createItem(vcsid, multipart);\r
+\r
+       int statusCode = res.getStatus();\r
+\r
+       if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
+               throw new RuntimeException("Could not create Item: \""+refName\r
+                               +"\" in personAuthority: \"" + personAuthorityRefName\r
+                               +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+       }\r
+       if(statusCode != EXPECTED_STATUS_CODE) {\r
+               throw new RuntimeException("Unexpected Status when creating Item: \""+refName\r
+                               +"\" in personAuthority: \"" + personAuthorityRefName +"\", Status:"+ statusCode);\r
+       }\r
+\r
+       return extractId(res);\r
+    }\r
+\r
+    public static String createPersonAuthRefName(String personAuthorityName) {\r
+       return "urn:cspace:org.collectionspace.demo:personauthority:name("\r
+                       +personAuthorityName+")";\r
+    }\r
+\r
+    public static String createPersonRefName(\r
+                                               String personAuthRefName, String personName) {\r
+       return personAuthRefName+":person:name("+personName+")";\r
+    }\r
+\r
+    public static String extractId(ClientResponse<Response> res) {\r
+        MultivaluedMap<String, Object> mvm = res.getMetadata();\r
+        String uri = (String) ((ArrayList<Object>) mvm.get("Location")).get(0);\r
+        if(logger.isDebugEnabled()){\r
+               logger.debug("extractId:uri=" + uri);\r
+        }\r
+        String[] segments = uri.split("/");\r
+        String id = segments[segments.length - 1];\r
+        if(logger.isDebugEnabled()){\r
+               logger.debug("id=" + id);\r
+        }\r
+        return id;\r
+    }\r
+    \r
+    /**\r
+     * Returns an error message indicating that the status code returned by a\r
+     * specific call to a service does not fall within a set of valid status\r
+     * codes for that service.\r
+     *\r
+     * @param serviceRequestType  A type of service request (e.g. CREATE, DELETE).\r
+     *\r
+     * @param statusCode  The invalid status code that was returned in the response,\r
+     *                    from submitting that type of request to the service.\r
+     *\r
+     * @return An error message.\r
+     */\r
+    public static String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) {\r
+        return "Status code '" + statusCode + "' in response is NOT within the expected set: " +\r
+                requestType.validStatusCodesAsString();\r
+    }\r
+\r
+\r
+    \r
+    /**\r
+     * Produces a default displayName from the basic name and dates fields.\r
+     * @see PersonDocumentModelHandler.prepareDefaultDisplayName() which\r
+     * duplicates this logic, until we define a service-general utils package\r
+     * that is neither client nor service specific.\r
+     * @param foreName \r
+     * @param middleName\r
+     * @param surName\r
+     * @param birthDate\r
+     * @param deathDate\r
+     * @return\r
+     */\r
+    public static String prepareDefaultDisplayName(\r
+               String foreName, String middleName, String surName,\r
+               String birthDate, String deathDate ) {\r
+       StringBuilder newStr = new StringBuilder();\r
+               final String sep = " ";\r
+               final String dateSep = "-";\r
+               List<String> nameStrings = \r
+                       Arrays.asList(foreName, middleName, surName);\r
+               boolean firstAdded = false;\r
+       for(String partStr : nameStrings ){\r
+                       if(null != partStr ) {\r
+                               if(firstAdded) {\r
+                                       newStr.append(sep);\r
+                               }\r
+                               newStr.append(partStr);\r
+                               firstAdded = true;\r
+                       }\r
+       }\r
+       // Now we add the dates. In theory could have dates with no name, but that is their problem.\r
+       boolean foundBirth = false;\r
+               if(null != birthDate) {\r
+                       if(firstAdded) {\r
+                               newStr.append(sep);\r
+                       }\r
+                       newStr.append(birthDate);\r
+               newStr.append(dateSep);         // Put this in whether there is a death date or not\r
+                       foundBirth = true;\r
+               }\r
+               if(null != deathDate) {\r
+                       if(!foundBirth) {\r
+                               if(firstAdded) {\r
+                                       newStr.append(sep);\r
+                               }\r
+                       newStr.append(dateSep);\r
+                       }\r
+                       newStr.append(deathDate);\r
+               }\r
+               return newStr.toString();\r
+    }\r
+    \r
+\r
+\r
+}\r
index 79c43c77999043b82f11823e09e16c3b8d95495c..e449dfdcbe4e6df6fb0cfcc251cf315f56c275f6 100644 (file)
@@ -26,15 +26,17 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
+import org.collectionspace.services.PersonJAXBSchema;
 import org.collectionspace.services.client.PersonAuthorityClient;
+import org.collectionspace.services.client.PersonAuthorityClientUtils;
 import org.collectionspace.services.person.PersonauthoritiesCommon;
 import org.collectionspace.services.person.PersonauthoritiesCommonList;
 import org.collectionspace.services.person.PersonsCommon;
 import org.collectionspace.services.person.PersonsCommonList;
-
 import org.jboss.resteasy.client.ClientResponse;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
@@ -96,11 +98,11 @@ public class PersonAuthorityServiceTest extends AbstractServiceTest {
 
         // Submit the request to the service and store the response.
         String identifier = createIdentifier();
-        String displayName = "displayName-" + identifier;
+       String displayName = "displayName-" + identifier;
        String refName = createPersonAuthRefName(displayName);
-       String typeName = "vocabType-" + identifier;
        MultipartOutput multipart = 
-               createPersonAuthorityInstance(displayName, refName, typeName);
+               PersonAuthorityClientUtils.createPersonAuthorityInstance(
+                               displayName, refName, client.getCommonPartName());
         ClientResponse<Response> res = client.create(multipart);
         int statusCode = res.getStatus();
 
@@ -121,7 +123,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTest {
         // for additional tests below.
         knownResourceRefName = refName;
 
-        lastPersonAuthId = extractId(res);
+        lastPersonAuthId = PersonAuthorityClientUtils.extractId(res);
         // Store the ID returned from the first resource created
         // for additional tests below.
         if (knownResourceId == null){
@@ -132,7 +134,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTest {
         }
         // Store the IDs from every resource created by tests,
         // so they can be deleted after tests have been run.
-        allResourceIdsCreated.add(extractId(res));
+        allResourceIdsCreated.add(lastPersonAuthId);
 
     }
 
@@ -156,13 +158,26 @@ public class PersonAuthorityServiceTest extends AbstractServiceTest {
 
         // Submit the request to the service and store the response.
         String identifier = createIdentifier();
-        String refName = createPersonRefName(authRefName, "Patrick Schmitz");
-        MultipartOutput multipart = createPersonInstance(vcsid, refName,
-                       "Patrick","Lee","Schmitz","pls", null, null, null,
-                               "1960", null, "Detroit, MI", null, "Coders", "American", "male",
-                               null, null, null, null );
+        Map<String, String> johnWayneMap = new HashMap<String,String>();
+        johnWayneMap.put(PersonJAXBSchema.FORE_NAME, "John");
+        johnWayneMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
+        johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
+        johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, "May 26, 1907");
+        johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
+        johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, "June 11, 1979");
+        johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" +
+                       "known by his stage name John Wayne, was an American film actor, director " +
+                       "and producer. He epitomized rugged masculinity and has become an enduring " +
+                       "American icon. He is famous for his distinctive voice, walk and height. " +
+                       "He was also known for his conservative political views and his support in " +
+                       "the 1950s for anti-communist positions.");
+        String refName = createPersonRefName(authRefName, "John Wayne");
+        MultipartOutput multipart = 
+               PersonAuthorityClientUtils.createPersonInstance(vcsid, refName, johnWayneMap,
+                               client.getItemCommonPartName() );
         ClientResponse<Response> res = client.createItem(vcsid, multipart);
         int statusCode = res.getStatus();
+        String extractedID = PersonAuthorityClientUtils.extractId(res);
 
         // Check the status code of the response: does it match
         // the expected response(s)?
@@ -173,10 +188,11 @@ public class PersonAuthorityServiceTest extends AbstractServiceTest {
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
 
+        
         // Store the ID returned from the first item resource created
         // for additional tests below.
         if (knownItemResourceId == null){
-            knownItemResourceId = extractId(res);
+            knownItemResourceId = extractedID;
             if (logger.isDebugEnabled()) {
                 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
             }
@@ -188,9 +204,9 @@ public class PersonAuthorityServiceTest extends AbstractServiceTest {
         //
         // Item resource IDs are unique, so these are used as keys;
         // the non-unique IDs of their parents are stored as associated values.
-        allResourceItemIdsCreated.put(extractId(res), vcsid);
+        allResourceItemIdsCreated.put(extractedID, vcsid);
 
-        return extractId(res);
+        return extractedID;
     }
 
     @Override
@@ -397,6 +413,12 @@ public class PersonAuthorityServiceTest extends AbstractServiceTest {
         PersonsCommon person = (PersonsCommon) extractPart(input,
                 client.getItemCommonPartName(), PersonsCommon.class);
         Assert.assertNotNull(person);
+        boolean showFull = true;
+        if(showFull && logger.isDebugEnabled()){
+            logger.debug(testName + ": returned payload:");
+            logger.debug(objectAsXmlString(person, PersonsCommon.class));
+        }
+        Assert.assertEquals(person.getInAuthority(), knownResourceId);
 
     }
 
@@ -526,19 +548,21 @@ public class PersonAuthorityServiceTest extends AbstractServiceTest {
         }
         Assert.assertEquals( nItemsReturned, nItemsToCreateInList);
 
-        // Optionally output additional data about list members for debugging.
-        boolean iterateThroughList = false;
-        if (iterateThroughList && logger.isDebugEnabled()) {
-            int i = 0;
-            for (PersonsCommonList.PersonListItem item : items) {
+        int i = 0;
+        for (PersonsCommonList.PersonListItem item : items) {
+               Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
+               Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
+               // Optionally output additional data about list members for debugging.
+               boolean showDetails = true;
+               if (showDetails && logger.isDebugEnabled()) {
                 logger.debug("  " + testName + ": list-item[" + i + "] csid=" +
                         item.getCsid());
                 logger.debug("  " + testName + ": list-item[" + i + "] displayName=" +
                         item.getDisplayName());
                 logger.debug("  " + testName + ": list-item[" + i + "] URI=" +
                         item.getUri());
-                i++;
             }
+            i++;
         }
     }
 
@@ -804,11 +828,14 @@ public class PersonAuthorityServiceTest extends AbstractServiceTest {
         // The only relevant ID may be the one used in update(), below.
 
         // The only relevant ID may be the one used in update(), below.
-        MultipartOutput multipart = createPersonInstance(NON_EXISTENT_ID, 
-                       createPersonRefName(NON_EXISTENT_ID, NON_EXISTENT_ID),  
-                       "Patrick","Lee","Schmitz","pls", null, null, null,
-                               "1960", null, "Detroit, MI", null, "Coders", "American", "male",
-                               null, null, null, null );
+        Map<String, String> nonexMap = new HashMap<String,String>();
+        nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
+        nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
+        nonexMap.put(PersonJAXBSchema.GENDER, "male");
+        MultipartOutput multipart = 
+       PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID, 
+                       createPersonRefName(NON_EXISTENT_ID, NON_EXISTENT_ID), nonexMap,
+                       client.getItemCommonPartName() );
         ClientResponse<MultipartInput> res =
                 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
         int statusCode = res.getStatus();
@@ -1038,85 +1065,9 @@ public class PersonAuthorityServiceTest extends AbstractServiceTest {
     private MultipartOutput createPersonAuthorityInstance(String identifier) {
        String displayName = "displayName-" + identifier;
        String refName = createPersonAuthRefName(displayName);
-       String typeName = "vocabType-" + identifier;
-        return createPersonAuthorityInstance(
-                displayName, refName,typeName );
+       return 
+               PersonAuthorityClientUtils.createPersonAuthorityInstance(
+                               displayName, refName, client.getCommonPartName());
     }
 
-    private MultipartOutput createPersonAuthorityInstance(
-               String displayName, String refName, String vocabType) {
-        PersonauthoritiesCommon personAuthority = new PersonauthoritiesCommon();
-        personAuthority.setDisplayName(displayName);
-        if(refName!=null)
-            personAuthority.setRefName(refName);
-        personAuthority.setVocabType(vocabType);
-        MultipartOutput multipart = new MultipartOutput();
-        OutputPart commonPart = multipart.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
-        commonPart.getHeaders().add("label", client.getCommonPartName());
-
-        if(logger.isDebugEnabled()) {
-            logger.debug("to be created, personAuthority common");
-            logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
-        }
-        return multipart;
-    }
-
-    private MultipartOutput createPersonInstance(String inAuthority, String refName,
-        String foreName, String middleName, String surName, 
-        String initials, String salutation, String title, String nameAdditions,  
-        String birthDate, String deathDate, String birthPlace, String deathPlace, 
-        String group, String nationality, String gender, String occupation, 
-        String schoolOrStyle, String bioNote, String nameNote ) {
-        PersonsCommon person = new PersonsCommon();
-        person.setInAuthority(inAuthority);
-               person.setRefName(refName);
-        if(foreName!=null)
-               person.setForeName(foreName);
-        if(middleName!=null)
-               person.setMiddleName(middleName);
-        if(surName!=null)
-               person.setSurName(surName);
-        if(initials!=null)
-               person.setInitials(initials);
-        if(salutation!=null)
-               person.setSalutation(salutation);
-        if(title!=null)
-               person.setTitle(title);
-        if(nameAdditions!=null)
-               person.setNameAdditions(nameAdditions);
-        if(birthDate!=null)
-               person.setBirthDate(birthDate);
-        if(deathDate!=null)
-               person.setDeathDate(deathDate);
-        if(birthPlace!=null)
-               person.setBirthPlace(birthPlace);
-        if(deathPlace!=null)
-               person.setDeathPlace(deathPlace);
-        if(group!=null)
-               person.setGroup(group);
-        if(nationality!=null)
-               person.setNationality(nationality);
-        if(gender!=null)
-               person.setGender(gender);
-        if(occupation!=null)
-               person.setOccupation(occupation);
-        if(schoolOrStyle!=null)
-               person.setSchoolOrStyle(schoolOrStyle);
-        if(bioNote!=null)
-               person.setBioNote(bioNote);
-        if(nameNote!=null)
-               person.setNameNote(nameNote);
-        MultipartOutput multipart = new MultipartOutput();
-        OutputPart commonPart = multipart.addPart(person,
-            MediaType.APPLICATION_XML_TYPE);
-        commonPart.getHeaders().add("label", client.getItemCommonPartName());
-
-        if(logger.isDebugEnabled()){
-            logger.debug("to be created, person common");
-            logger.debug(objectAsXmlString(person,
-                PersonsCommon.class));
-        }
-
-        return multipart;
-    }
 }
index 83343792eb746e9b6b3f9efc144be2bff14a8921..199bbbbdbabba5e7cbae0d055b2ea2d981077cfc 100644 (file)
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
 <classpath>\r
        <classpathentry kind="src" output="target/classes" path="src/main/java"/>\r
+       <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>\r
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>\r
        <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>\r
        <classpathentry kind="output" path="target/classes"/>\r
index 6d98bdb53dcab6b894a7ca60d7547df96a30687d..ae21be519f0b149844966c76ad6aa2c0ec31b235 100644 (file)
@@ -3,6 +3,9 @@
        <name>org.collectionspace.services.person.importer</name>\r
        <comment></comment>\r
        <projects>\r
+               <project>org.collectionspace.services.client</project>\r
+               <project>org.collectionspace.services.common</project>\r
+               <project>org.collectionspace.services.person.jaxb</project>\r
        </projects>\r
        <buildSpec>\r
                <buildCommand>\r
index e02b5b0553f31b3759e1f1cee1d97b4f427805bb..6db5909e7a6d55a04328e208bde7854c0e43d6a6 100644 (file)
@@ -46,6 +46,10 @@ import org.slf4j.LoggerFactory;
  * $LastChangedRevision: $
  * $LastChangedDate: $
  */
+/**
+ * @author pschmitz
+ *
+ */
 public class PersonDocumentModelHandler
         extends RemoteDocumentModelHandler<PersonsCommon, PersonsCommonList> {
 
@@ -95,50 +99,70 @@ public class PersonDocumentModelHandler
     }
     
     private String prepareDefaultDisplayName(DocumentModel docModel) throws Exception {
+       String commonPartLabel = getServiceContext().getCommonPartLabel("persons");
+       return 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 )                     
+                       );
+    }
+
+    
+    /**
+     * Produces a default displayName from the basic name and dates fields.
+     * @see PersonAuthorityClientUtils.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
+     * @return
+     * @throws Exception
+     */
+    private static String prepareDefaultDisplayName(
+               String foreName, String middleName, String surName,
+               String birthDate, String deathDate ) throws Exception {
        StringBuilder newStr = new StringBuilder();
-               String part = null;
                final String sep = " ";
                final String dateSep = "-";
                List<String> nameStrings = 
-                       Arrays.asList(PersonJAXBSchema.FORE_NAME, PersonJAXBSchema.MIDDLE_NAME, 
-                                       PersonJAXBSchema.SUR_NAME);
+                       Arrays.asList(foreName, middleName, surName);
                boolean firstAdded = false;
        for(String partStr : nameStrings ){
-                       if(null != (part = (String) 
-                                       docModel.getProperty(getServiceContext().getCommonPartLabel("persons"), partStr ))) {
+                       if(null != partStr ) {
                                if(firstAdded) {
                                        newStr.append(sep);
                                }
-                               newStr.append(part);
+                               newStr.append(partStr);
                                firstAdded = true;
                        }
        }
        // Now we add the dates. In theory could have dates with no name, but that is their problem.
        boolean foundBirth = false;
-               if(null != (part = (String) 
-                               docModel.getProperty(getServiceContext().getCommonPartLabel("persons"), 
-                                               PersonJAXBSchema.BIRTH_DATE ))) {
+               if(null != birthDate) {
                        if(firstAdded) {
                                newStr.append(sep);
                        }
-                       newStr.append(part);
+                       newStr.append(birthDate);
                newStr.append(dateSep);         // Put this in whether there is a death date or not
                        foundBirth = true;
                }
-               if(null != (part = (String) 
-                               docModel.getProperty(getServiceContext().getCommonPartLabel("persons"), 
-                                               PersonJAXBSchema.DEATH_DATE ))) {
+               if(null != deathDate) {
                        if(!foundBirth) {
                                if(firstAdded) {
                                        newStr.append(sep);
                                }
                        newStr.append(dateSep);
                        }
-                       newStr.append(part);
+                       newStr.append(deathDate);
                }
                return newStr.toString();
     }
-
+    
     /**
      * getCommonPart get associated person
      * @return