From 2943582f99fbe7293793d731917de5fc7a63e069 Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Tue, 25 May 2010 06:56:21 +0000 Subject: [PATCH] CSPACE-1895 Working on the repeating sections of Location, and general support for this. Fixed a bug with update. --- .../java/RemoteDocumentModelHandlerImpl.java | 19 ++++++++++++++-- ...RemoteSubItemDocumentModelHandlerImpl.java | 22 +++++++++++++++++++ .../services/client/test/NoteServiceTest.java | 10 ++++----- .../note/nuxeo/NoteDocumentModelHandler.java | 7 ++++++ 4 files changed, 51 insertions(+), 7 deletions(-) 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 61ba6c808..05ded5bb0 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 @@ -94,7 +94,7 @@ public abstract class RemoteDocumentModelHandlerImpl } } - private void addOutputPart(Map unQObjectProperties, String schema, ObjectPartType partMeta) + protected void addOutputPart(Map unQObjectProperties, String schema, ObjectPartType partMeta) throws Exception { Document doc = DocumentUtils.buildDocument(partMeta, schema, unQObjectProperties); @@ -220,6 +220,20 @@ public abstract class RemoteDocumentModelHandlerImpl */ protected Map 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 extractPart( + DocumentModel docModel, String schema, ObjectPartType partMeta, + Map addToMap) + throws Exception { Map result = null; MediaType mt = MediaType.valueOf(partMeta.getContent().getContentType()); @@ -227,7 +241,8 @@ public abstract class RemoteDocumentModelHandlerImpl Map 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 unQObjectProperties = new HashMap(); + Map unQObjectProperties = + (addToMap!=null)? addToMap:(new HashMap()); Set> qualifiedEntries = objectProps.entrySet(); for(Entry entry : qualifiedEntries){ String unqProp = getUnQProperty(entry.getKey()); diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteSubItemDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteSubItemDocumentModelHandlerImpl.java index 0947ae073..f5adcea72 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteSubItemDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteSubItemDocumentModelHandlerImpl.java @@ -70,6 +70,7 @@ public abstract class RemoteSubItemDocumentModelHandlerImpl extends * @param partMeta metadata for the object to fill * @throws Exception */ + @Override protected void fillPart(InputPart part, DocumentModel docModel, ObjectPartType partMeta) throws Exception { InputStream payload = part.getBody(InputStream.class, null); @@ -104,5 +105,26 @@ public abstract class RemoteSubItemDocumentModelHandlerImpl extends } } + /** + * extractPart extracts an XML object from given DocumentModel + * This overridden form checks for schemas that extend subitem, and merges + * in the subitem properties for that part. + * @param docModel + * @param schema of the object to extract + * @param partMeta metadata for the object to extract + * @throws Exception + */ + @Override + protected Map extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta) + throws Exception { + Map map = extractPart( docModel, schema, partMeta, null ); + if(schemaHasSubItem(schema)) { + extractPart(docModel, SI_LABEL, partMeta, map); + } + return map; + } + + // TODO HACK - should make this info be configured in the part metadata. + public abstract boolean schemaHasSubItem(String schema); } diff --git a/services/note/client/src/test/java/org/collectionspace/services/client/test/NoteServiceTest.java b/services/note/client/src/test/java/org/collectionspace/services/client/test/NoteServiceTest.java index c325bae75..e610d00db 100644 --- a/services/note/client/src/test/java/org/collectionspace/services/client/test/NoteServiceTest.java +++ b/services/note/client/src/test/java/org/collectionspace/services/client/test/NoteServiceTest.java @@ -290,9 +290,9 @@ public class NoteServiceTest extends AbstractServiceTestImpl { client.getCommonPartName(), NotesCommon.class); Assert.assertNotNull(note); - // Update the content of this resource. + // Update the content of this resource, both the subitem, and the content note.setContent("updated-" + note.getContent()); - note.setAuthor("updated-" + note.getAuthor()); + note.setOrder(note.getOrder()+10); if(logger.isDebugEnabled()){ logger.debug("to be updated object"); logger.debug(objectAsXmlString(note, NotesCommon.class)); @@ -319,10 +319,10 @@ public class NoteServiceTest extends AbstractServiceTestImpl { client.getCommonPartName(), NotesCommon.class); Assert.assertNotNull(updatedNote); - Assert.assertEquals(updatedNote.getContent(), - note.getContent(), + Assert.assertEquals(updatedNote.getContent(), note.getContent(), "Data in updated object did not match submitted data."); - + Assert.assertEquals(updatedNote.getOrder(), note.getOrder(), + "Data in updated object (subitem) did not match submitted data."); } // Failure outcomes diff --git a/services/note/service/src/main/java/org/collectionspace/services/note/nuxeo/NoteDocumentModelHandler.java b/services/note/service/src/main/java/org/collectionspace/services/note/nuxeo/NoteDocumentModelHandler.java index 8a6a12d4b..53043b598 100644 --- a/services/note/service/src/main/java/org/collectionspace/services/note/nuxeo/NoteDocumentModelHandler.java +++ b/services/note/service/src/main/java/org/collectionspace/services/note/nuxeo/NoteDocumentModelHandler.java @@ -58,6 +58,13 @@ public class NoteDocumentModelHandler /** The owner. */ private String owner; + + private final String commonSchemaName = "notes_common"; + + public boolean schemaHasSubItem(String schema) { + return commonSchemaName.equals(schema); + } + /** * Gets the owner. -- 2.47.3