Replacing Multipart Service Requests

Using Nuxeo's Import/Export format as inspiration, the CollectionSpace services team will be replacing our existing Multipart payloads with pure XML payloads.

For example, the following XML payload would be the result of a GET request on the Vocabulary service:

<?xml version="1.0" encoding="UTF-8"?>
<document name="vocabularies">
    <ns2:vocabularies_common
        xmlns:ns2="http://collectionspace.org/services/vocabulary"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <shortIdentifier>1296500910627</shortIdentifier>
        <refName>urn:cspace:org.collectionspace.demo:vocabulary:name(1296500910627)'displayName-1296500910627'</refName>
        <csid>31af11b0-09b3-4774-8791</csid>
        <displayName>displayName-1296500910627</displayName>
        <vocabType>enum</vocabType>
    </ns2:vocabularies_common>
    <ns2:collectionspace_core
        xmlns:ns2="http://collectionspace.org/collectionspace_core/"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <tenantId>1</tenantId>
        <updatedAt>2011-01-31T19:08:35Z</updatedAt>
        <createdAt>2011-01-31T19:08:35Z</createdAt>
    </ns2:collectionspace_core>
</document>

For each schema defined by the document type there is a schema entry which contains the document properties belonging to that schema. The XSD schema that correspond to that schema can be used to validate the content of the schema section

Nuxeo Export of an Intake Instance

<?xml version="1.0" encoding="UTF-8"?>

<document repository="default" id="063c31f1-fea5-4b5f-b966-78e803bb6623">
  <system>
    <type>Intake</type>
    <path>default-domain/workspaces/Intakes/a10d80d8-1e9c-4ca7-96d4</path>
    <lifecycle-state>undefined</lifecycle-state>
    <lifecycle-policy>undefined</lifecycle-policy>
    <access-control>
      <acl name="inherited">
        <entry principal="Administrator" permission="Everything" grant="true"/>
        <entry principal="members" permission="Read" grant="true"/>
      </acl>
    </access-control>
  </system>
  <schema xmlns:dc="http://www.nuxeo.org/ecm/schemas/dublincore/" name="dublincore">
    <dc:creator>Administrator</dc:creator>
    <dc:source/>
    <dc:contributors>
      <item>Administrator</item>
    </dc:contributors>
    <dc:created>2011-01-15T00:22:42Z</dc:created>
    <dc:description/>
    <dc:rights/>
    <dc:subjects/>
    <dc:format/>
    <dc:valid/>
    <dc:issued/>
    <dc:modified>2011-01-15T00:22:42Z</dc:modified>
    <dc:coverage/>
    <dc:expired/>
    <dc:language/>
    <dc:title/>
  </schema>
  <schema xmlns:intakes_common="http://collectionspace.org/intake/" name="intakes_common">
    <intakes_common:conditionCheckReasons>
      <conditionCheckReason></conditionCheckReason>
    </intakes_common:conditionCheckReasons>
    <intakes_common:valuationReferenceNumber></intakes_common:valuationReferenceNumber>
    <intakes_common:entryReason>consideration</intakes_common:entryReason>
    <intakes_common:currentOwner></intakes_common:currentOwner>
    <intakes_common:depositor></intakes_common:depositor>
    <intakes_common:insuranceNote></intakes_common:insuranceNote>
    <intakes_common:depositorsRequirements></intakes_common:depositorsRequirements>
    <intakes_common:valuer></intakes_common:valuer>
    <intakes_common:entryDate>2011-01-04</intakes_common:entryDate>
    <intakes_common:fieldCollectionMethods>
      <fieldCollectionMethod></fieldCollectionMethod>
    </intakes_common:fieldCollectionMethods>
    <intakes_common:conditionCheckersOrAssessors>
      <conditionCheckerOrAssessor></conditionCheckerOrAssessor>
    </intakes_common:conditionCheckersOrAssessors>
    <intakes_common:entryNumber>IN2011.1</intakes_common:entryNumber>
    <intakes_common:conditionCheckMethods>
      <conditionCheckMethod></conditionCheckMethod>
    </intakes_common:conditionCheckMethods>
    <intakes_common:fieldCollectors>
      <fieldCollector></fieldCollector>
    </intakes_common:fieldCollectors>
    <intakes_common:packingNote>No packing note.</intakes_common:packingNote>
    <intakes_common:returnDate>2011-01-04</intakes_common:returnDate>
    <intakes_common:currentLocationGroupList>
      <currentLocationGroup>
        <currentLocationFitness></currentLocationFitness>
        <currentLocationNote></currentLocationNote>
        <currentLocation></currentLocation>
      </currentLocationGroup>
    </intakes_common:currentLocationGroupList>
    <intakes_common:entryMethods>
      <entryMethod></entryMethod>
    </intakes_common:entryMethods>
    <intakes_common:insurers>
      <insurer></insurer>
    </intakes_common:insurers>
    <intakes_common:locationDate></intakes_common:locationDate>
    <intakes_common:conditionCheckDate></intakes_common:conditionCheckDate>
    <intakes_common:entryNote>No note</intakes_common:entryNote>
    <intakes_common:conditionCheckNote></intakes_common:conditionCheckNote>
    <intakes_common:fieldCollectionSources>
      <fieldCollectionSource></fieldCollectionSource>
    </intakes_common:fieldCollectionSources>
    <intakes_common:fieldCollectionPlace></intakes_common:fieldCollectionPlace>
    <intakes_common:fieldCollectionDate></intakes_common:fieldCollectionDate>
    <intakes_common:fieldCollectionNote></intakes_common:fieldCollectionNote>
    <intakes_common:insuranceReferenceNumber></intakes_common:insuranceReferenceNumber>
    <intakes_common:fieldCollectionEventNames>
      <fieldCollectionEventName></fieldCollectionEventName>
    </intakes_common:fieldCollectionEventNames>
    <intakes_common:insurancePolicyNumber></intakes_common:insurancePolicyNumber>
    <intakes_common:normalLocation></intakes_common:normalLocation>
    <intakes_common:conditionCheckReferenceNumber></intakes_common:conditionCheckReferenceNumber>
    <intakes_common:fieldCollectionNumber></intakes_common:fieldCollectionNumber>
    <intakes_common:insuranceRenewalDate></intakes_common:insuranceRenewalDate>
  </schema>
  <schema xmlns="http://www.nuxeo.org/ecm/schemas/common/" name="common">
    <icon/>
    <icon-expanded/>
    <size/>
  </schema>
  <schema xmlns:collectionspace_core="http://collectionspace.org/collectionspace_core/" name="collectionspace_core">
    <collectionspace_core:updatedAt>2011-01-15T00:22:42Z</collectionspace_core:updatedAt>
    <collectionspace_core:createdAt>2011-01-15T00:22:42Z</collectionspace_core:createdAt>
    <collectionspace_core:tenantId>1</collectionspace_core:tenantId>
  </schema>
</document>

Using JAXB to Marshal XML

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import org.collectionspace.services.dimension.DimensionsCommon;

public class DimensionOut {
    public static void main( String[] args ) {
    	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    	try {
	    	JAXBContext jc = JAXBContext.newInstance("org.collectionspace.services.dimension");
	    	//Create marshaller
	    	Marshaller m = jc.createMarshaller();
	    	DimensionsCommon dc = new DimensionsCommon();
	    	dc.setCsid("1234");
	    	//Marshal object into file.
	    	m.marshal(dc, outputStream);
	    	System.out.println(outputStream.toString());
	    	
	    	//
	    	// Now XML to JAXB class instance
	    	//
	    	//Create unmarshaller
	    	Unmarshaller um = jc.createUnmarshaller();
	    	DimensionsCommon dc2 = (DimensionsCommon) um.unmarshal(
	    			new ByteArrayInputStream(outputStream.toString().getBytes()));
	    	System.out.println("The 'csid' field value is: " + dc2.getCsid());
	    	} catch (Exception x) {
	    		x.printStackTrace();
	    }
    }
}

The code above marshalls the following XML fragment:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:dimensions_common xmlns:ns2="http://collectionspace.org/services/dimension">
<csid>1234</csid>
</ns2:dimensions_common>