]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1273: CSID should be in the payload of term items for Person and Org services.
authorRichard Millet <richard.millet@berkeley.edu>
Wed, 24 Mar 2010 08:06:15 +0000 (08:06 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Wed, 24 Mar 2010 08:06:15 +0000 (08:06 +0000)
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java
services/jaxb/.classpath
services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java
services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.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 435e2ae1d2f02e5f848bc995d60090fce4e75b1a..45273740693997a59beb5fda0fbf4f617db8bc61 100644 (file)
@@ -80,24 +80,39 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
         for(InputPart part : inputParts){
             String partLabel = part.getHeaders().getFirst("label");
             ObjectPartType partMeta = partsMetaMap.get(partLabel);
-            extractPart(docModel, partLabel, partMeta);
+//            extractPart(docModel, partLabel, partMeta);
+                       Map<String, Object> unQObjectProperties = extractPart(docModel, partLabel, partMeta);
+                       addOutputPart(unQObjectProperties, partLabel, partMeta);
         }
     }
 
-    @Override
-    public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
-
-        DocumentModel docModel = wrapDoc.getWrappedObject();
-        String[] schemas = docModel.getDeclaredSchemas();
-        Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
-        for(String schema : schemas){
-            ObjectPartType partMeta = partsMetaMap.get(schema);
-            if(partMeta == null){
-                continue; //unknown part, ignore
-            }
-            extractPart(docModel, schema, partMeta);
-        }
+    private void addOutputPart(Map<String, Object> unQObjectProperties, String schema, ObjectPartType partMeta)
+               throws Exception {
+               Document doc = DocumentUtils.buildDocument(partMeta, schema,
+                               unQObjectProperties);
+               if (logger.isDebugEnabled()) {
+                       DocumentUtils.writeDocument(doc, System.out);
+               }
+               MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
+               ctx.addOutputPart(schema, doc, partMeta.getContent().getContentType());
     }
+    
+       @Override
+       public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
+                       throws Exception {
+
+               DocumentModel docModel = wrapDoc.getWrappedObject();
+               String[] schemas = docModel.getDeclaredSchemas();
+               Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
+               for (String schema : schemas) {
+                       ObjectPartType partMeta = partsMetaMap.get(schema);
+                       if (partMeta == null) {
+                               continue; // unknown part, ignore
+                       }
+                       Map<String, Object> unQObjectProperties = extractPart(docModel, schema, partMeta);
+                       addOutputPart(unQObjectProperties, schema, partMeta);
+               }
+       }
 
     @Override
     public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
@@ -167,10 +182,12 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
      * @param partMeta metadata for the object to extract
      * @throws Exception
      */
-    protected void extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
+    protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
             throws Exception {
+       Map<String, Object> result = null;
+       
         MediaType mt = MediaType.valueOf(partMeta.getContent().getContentType());
-        if(mt.equals(MediaType.APPLICATION_XML_TYPE)){
+        if (mt.equals(MediaType.APPLICATION_XML_TYPE)){
             Map<String, Object> objectProps = docModel.getProperties(schema);
             //unqualify properties before sending the doc over the wire (to save bandwidh)
             //FIXME: is there a better way to avoid duplication of a collection?
@@ -180,13 +197,10 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
                 String unqProp = getUnQProperty(entry.getKey());
                 unQObjectProperties.put(unqProp, entry.getValue());
             }
-            Document doc = DocumentUtils.buildDocument(partMeta, schema, unQObjectProperties);
-            if(logger.isDebugEnabled()){
-                DocumentUtils.writeDocument(doc, System.out);
-            }
-            MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
-            ctx.addOutputPart(schema, doc, partMeta.getContent().getContentType());
+            result = unQObjectProperties;
         } //TODO: handle other media types
+        
+        return result;
     }
     
     public AuthorityRefList getAuthorityRefs(
index bd6bf38ebfeec17a6798d10f9136f483e0b76962..65161d26bac1f803129495951c07d50cddba68ef 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 kind="src" path="target/generated-sources/xjc"/>\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 kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>\r
index e749b73c41fcc3132861dc2cf354e05ba5ee9cbb..32d6d6a381d48974946108fdd1a06decdc8f2155 100644 (file)
@@ -524,6 +524,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
         Assert.assertNotNull(displayName, expectedDisplayName);
         
         // Update the shortName and verify the computed name is updated.
+        organization.setCsid(null);
         organization.setDisplayNameComputed(true);
         organization.setShortName("updated-" + TEST_ORG_SHORTNAME);
         expectedDisplayName = 
@@ -1017,6 +1018,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
         Assert.assertNotNull(organization);
 
         // Update the contents of this resource.
+        organization.setCsid(null);
         organization.setShortName("updated-" + organization.getShortName());
         if(logger.isDebugEnabled()){
             logger.debug("to be updated Organization");
index c5c399b3cdc21b81ce7d5a61c2e40ac74c30305d..0465abe3e9319209622eb9cdede6300341d447c8 100644 (file)
@@ -25,11 +25,13 @@ package org.collectionspace.services.organization.nuxeo;
 
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import org.collectionspace.services.OrganizationJAXBSchema;
 import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentWrapper;
+import org.collectionspace.services.common.service.ObjectPartType;
 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.organization.OrganizationsCommon;
@@ -50,6 +52,10 @@ public class OrganizationDocumentModelHandler
         extends RemoteDocumentModelHandlerImpl<OrganizationsCommon, OrganizationsCommonList> {
 
     private final Logger logger = LoggerFactory.getLogger(OrganizationDocumentModelHandler.class);
+    /**
+     * Common part schema label
+     */
+    private static final String COMMON_PART_LABEL = "organizations_common";    
     /**
      * organization is used to stash JAXB object to use when handle is called
      * for Action.CREATE, Action.UPDATE or Action.GET
@@ -169,6 +175,20 @@ public class OrganizationDocumentModelHandler
         this.organizationList = organizationList;
     }
 
+    @Override
+    protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
+            throws Exception {
+       Map<String, Object> unQObjectProperties = super.extractPart(docModel, schema, partMeta);
+       
+       // Add the CSID to the common part
+       if (partMeta.getLabel().equalsIgnoreCase(COMMON_PART_LABEL)) {
+               String csid = NuxeoUtils.extractId(docModel.getPathAsString());
+               unQObjectProperties.put("csid", csid);
+       }
+       
+       return unQObjectProperties;
+    }
+    
     @Override
     public OrganizationsCommon extractCommonPart(DocumentWrapper wrapDoc)
             throws Exception {
index 1fce517d49a0bc6b7ae1daf812695864520e05da..828d5683ae64e8ee4e6a46c8c851ce99e22c6ac1 100644 (file)
@@ -549,6 +549,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
         Assert.assertNotNull(displayName, expectedDisplayName);
         
         // Update the shortName and verify the computed name is updated.
+        person.setCsid(null);
         person.setDisplayNameComputed(true);
         person.setForeName("updated-" + TEST_FORE_NAME);
         expectedDisplayName = 
@@ -1041,12 +1042,13 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
         Assert.assertNotNull(person);
 
         // Update the contents of this resource.
+        person.setCsid(null);
         person.setForeName("updated-" + person.getForeName());
         if(logger.isDebugEnabled()){
             logger.debug("to be updated Person");
             logger.debug(objectAsXmlString(person,
                 PersonsCommon.class));
-        }
+        }        
 
         // Submit the updated resource to the service and store the response.
         MultipartOutput output = new MultipartOutput();
index 2bf96742d2c4de8daa70448448c6a45833de4129..e77d5de3f0138211466ab70c0c74b85cfce4850b 100644 (file)
@@ -27,10 +27,12 @@ import java.util.Iterator;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 
 import org.collectionspace.services.PersonJAXBSchema;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentWrapper;
+import org.collectionspace.services.common.service.ObjectPartType;
 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.person.PersonsCommon;
@@ -55,6 +57,11 @@ public class PersonDocumentModelHandler
         extends RemoteDocumentModelHandlerImpl<PersonsCommon, PersonsCommonList> {
 
     private final Logger logger = LoggerFactory.getLogger(PersonDocumentModelHandler.class);
+    /**
+     * Common part schema label
+     */
+    private static final String COMMON_PART_LABEL = "persons_common";
+    
     /**
      * person is used to stash JAXB object to use when handle is called
      * for Action.CREATE, Action.UPDATE or Action.GET
@@ -195,6 +202,20 @@ public class PersonDocumentModelHandler
         this.personList = personList;
     }
 
+    @Override
+    protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
+            throws Exception {
+       Map<String, Object> unQObjectProperties = super.extractPart(docModel, schema, partMeta);
+       
+       // Add the CSID to the common part
+       if (partMeta.getLabel().equalsIgnoreCase(COMMON_PART_LABEL)) {
+               String csid = NuxeoUtils.extractId(docModel.getPathAsString());
+               unQObjectProperties.put("csid", csid);
+       }
+       
+       return unQObjectProperties;
+    }
+    
     @Override
     public PersonsCommon extractCommonPart(DocumentWrapper wrapDoc)
             throws Exception {