}
}
- @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);
- }
- }
+ @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);
+ 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 fillAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
* @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?
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(
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;
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
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 {