]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1895 Working on the repeating sections of Location, and general support for...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Tue, 25 May 2010 06:56:21 +0000 (06:56 +0000)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Tue, 25 May 2010 06:56:21 +0000 (06:56 +0000)
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteSubItemDocumentModelHandlerImpl.java
services/note/client/src/test/java/org/collectionspace/services/client/test/NoteServiceTest.java
services/note/service/src/main/java/org/collectionspace/services/note/nuxeo/NoteDocumentModelHandler.java

index 61ba6c808b7de5da62eb9e40df0816b759ad861d..05ded5bb0bad6e80d9085cc6b3aa686c54c63e20 100644 (file)
@@ -94,7 +94,7 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
         }
     }
 
-    private void addOutputPart(Map<String, Object> unQObjectProperties, String schema, ObjectPartType partMeta)
+    protected void addOutputPart(Map<String, Object> unQObjectProperties, String schema, ObjectPartType partMeta)
                throws Exception {
                Document doc = DocumentUtils.buildDocument(partMeta, schema,
                                unQObjectProperties);
@@ -220,6 +220,20 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
      */
     protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
             throws Exception {
+       return extractPart( docModel, schema, partMeta, null );
+    }
+    
+    /**
+     * extractPart extracts an XML object from given DocumentModel
+     * @param docModel
+     * @param schema of the object to extract
+     * @param partMeta metadata for the object to extract
+     * @throws Exception
+     */
+    protected Map<String, Object> extractPart(
+               DocumentModel docModel, String schema, ObjectPartType partMeta,
+               Map<String, Object> addToMap)
+            throws Exception {
        Map<String, Object> result = null;
        
         MediaType mt = MediaType.valueOf(partMeta.getContent().getContentType());
@@ -227,7 +241,8 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
             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?
-            Map<String, Object> unQObjectProperties = new HashMap<String, Object>();
+            Map<String, Object> unQObjectProperties = 
+               (addToMap!=null)? addToMap:(new HashMap<String, Object>());
             Set<Entry<String, Object>> qualifiedEntries = objectProps.entrySet();
             for(Entry<String, Object> entry : qualifiedEntries){
                 String unqProp = getUnQProperty(entry.getKey());
index 0947ae0734db8219aa9eb5410dc4786e47681a3f..f5adcea72afde26e93a6d6a931177ac505c747a1 100644 (file)
@@ -70,6 +70,7 @@ public abstract class RemoteSubItemDocumentModelHandlerImpl<T, TL> extends
      * @param partMeta metadata for the object to fill\r
      * @throws Exception\r
      */\r
+       @Override\r
     protected void fillPart(InputPart part, DocumentModel docModel, ObjectPartType partMeta)\r
             throws Exception {\r
         InputStream payload = part.getBody(InputStream.class, null);\r
@@ -104,5 +105,26 @@ public abstract class RemoteSubItemDocumentModelHandlerImpl<T, TL> extends
         }\r
     }\r
     \r
+    /**\r
+     * extractPart extracts an XML object from given DocumentModel\r
+     * This overridden form checks for schemas that extend subitem, and merges\r
+     * in the subitem properties for that part.\r
+     * @param docModel\r
+     * @param schema of the object to extract\r
+     * @param partMeta metadata for the object to extract\r
+     * @throws Exception\r
+     */\r
+       @Override\r
+    protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)\r
+            throws Exception {\r
+       Map<String, Object> map = extractPart( docModel, schema, partMeta, null ); \r
+               if(schemaHasSubItem(schema)) {\r
+                       extractPart(docModel, SI_LABEL, partMeta, map);\r
+               }\r
+       return map;\r
+    }\r
+       \r
+       // TODO HACK - should make this info be configured in the part metadata.\r
+       public abstract boolean schemaHasSubItem(String schema);\r
 \r
 }\r
index c325bae75737c7072c4f014118bf0e4e72db620b..e610d00dbfed250b106ec3425848054103872242 100644 (file)
@@ -290,9 +290,9 @@ public class NoteServiceTest extends AbstractServiceTestImpl {
                 client.getCommonPartName(), NotesCommon.class);\r
         Assert.assertNotNull(note);\r
 \r
-        // Update the content of this resource.\r
+        // Update the content of this resource, both the subitem, and the content\r
         note.setContent("updated-" + note.getContent());\r
-        note.setAuthor("updated-" + note.getAuthor());\r
+        note.setOrder(note.getOrder()+10);\r
         if(logger.isDebugEnabled()){\r
             logger.debug("to be updated object");\r
             logger.debug(objectAsXmlString(note, NotesCommon.class));\r
@@ -319,10 +319,10 @@ public class NoteServiceTest extends AbstractServiceTestImpl {
                         client.getCommonPartName(), NotesCommon.class);\r
         Assert.assertNotNull(updatedNote);\r
 \r
-        Assert.assertEquals(updatedNote.getContent(),\r
-                note.getContent(),\r
+        Assert.assertEquals(updatedNote.getContent(), note.getContent(),\r
                 "Data in updated object did not match submitted data.");\r
-\r
+        Assert.assertEquals(updatedNote.getOrder(), note.getOrder(),\r
+                "Data in updated object (subitem) did not match submitted data.");\r
     }\r
 \r
     // Failure outcomes\r
index 8a6a12d4be4898ff0d36e6eda215c3d98b2e4809..53043b598a722ab606120567a8ae1e11d05c1ed3 100644 (file)
@@ -58,6 +58,13 @@ public class NoteDocumentModelHandler
 \r
     /** The owner. */\r
     private String owner;\r
+    \r
+    private final String commonSchemaName = "notes_common";\r
+    \r
+       public boolean schemaHasSubItem(String schema) {\r
+               return commonSchemaName.equals(schema);\r
+       }\r
+\r
 \r
     /**\r
      * Gets the owner.\r