<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Session.saveDocument doesn&amp;apos;t seem to store? in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/session-savedocument-doesn-apos-t-seem-to-store/m-p/318507#M5508</link>
    <description>&lt;P&gt;hi all, i'm creating a custom operation that aims to take a blob (xml-file) and create a document with the blob attached and some of the metadata filled from the xml-file. I'm using this operation via the Automation API to upload a xml-file and have the document auto-created. It all seems to work fine, except that the document doesn't appear in the webUI and when i try to access it via the Automation interface (for a subsequent Blob.Attach) I get a 404 Not Found response. So I must be doing something wrong here. The java code i have is below, it's roughly based on Document.Create and Blob.Attach:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;@Operation(id=APAS_CreatePlate.ID, category=Constants.CAT_SERVICES, label="APAS_CreatePlate", description="")
public class APAS_CreatePlate {

    public static final String ID = "APAS_CreatePlate";
    
    @Context
    protected CoreSession session;
    
    @Param(name = "folder", required = true)
    protected DocumentModel m_parent;

    @OperationMethod
    public DocumentModel run(Blob input) throws ClientException {
    	// first create the document model for type Plate
    	DocumentModel newPlate = session.createDocumentModel(m_parent.getPathAsString(), "Plate", "Plate");
    	try {
	    	&amp;lt;&amp;lt;-- snipped away some JAXB init code --&amp;gt;&amp;gt;
	    	// create xml reader
	    	XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(input.getString()));
	        Plate xmlPlate = (Plate)jaxbUnmarshaller.unmarshal(xsr, Plate.class).getValue();
			
	        Properties props = new Properties();
	    	props.put("plate:sample_type", xmlPlate.getSampleType());
	    	// TODO the other relevant properties
	    	DocumentHelper.setProperties(session, newPlate, props);
	    	DocumentHelper.addBlob(newPlate.getProperty("file:content"), input);
	    	DocumentModel doc = session.createDocument(newPlate);
	    	return session.saveDocument(doc);
    	} &amp;lt;&amp;lt;-- snipped exception handling --&amp;gt;&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now when using this code via the URL and JSON payload (and the attached blob of course):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&lt;A href="http://localhost:8080/nuxeo/site/automation/APAS_CreatePlate" target="test_blank"&gt;http://localhost:8080/nuxeo/site/automation/APAS_CreatePlate&lt;/A&gt;
{"params":{"folder": "c5667b68-f712-42ec-a814-fa211e8c89dd"}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I get a JSON response:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;{
    "versionLabel": "0.0", 
    "changeToken": "1385697404589", 
    "uid": "33a41d27-528a-46f2-9e89-8fd60e430930", 
    "repository": "default", 
    "title": "Plate", 
    "lastModified": "2013-11-29T03:56:44.58Z", 
    "facets": [
        "Downloadable", 
        "Commentable", 
        "Asset", 
        "SuperSpace", 
        "Versionable", 
        "Publishable", 
        "HasRelatedText"
    ], 
    "entity-type": "document", 
    "state": "project", 
    "isCheckedOut": true, 
    "contextParameters": {}, 
    "path": "/default-domain/workspaces/amp/plates/Plate", 
    "type": "Plate"
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which seems to indicate to me the document has been created just fine. However, it is apparently not stored, because the next invocation gives the 404:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&lt;A href="http://localhost:8080/nuxeo/site/automation/Blob.Attach" target="test_blank"&gt;http://localhost:8080/nuxeo/site/automation/Blob.Attach&lt;/A&gt;
{"params":{"document": "33a41d27-528a-46f2-9e89-8fd60e430930","xpath": "plate:top_image"}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can anyone suggest a way forward for me?&lt;/P&gt;
&lt;P&gt;Cheers!
Chris&lt;/P&gt;</description>
    <pubDate>Fri, 29 Nov 2013 05:15:33 GMT</pubDate>
    <dc:creator>chrisd_</dc:creator>
    <dc:date>2013-11-29T05:15:33Z</dc:date>
    <item>
      <title>Session.saveDocument doesn&amp;apos;t seem to store?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/session-savedocument-doesn-apos-t-seem-to-store/m-p/318507#M5508</link>
      <description>&lt;P&gt;hi all, i'm creating a custom operation that aims to take a blob (xml-file) and create a document with the blob attached and some of the metadata filled from the xml-file. I'm using this operation via the Automation API to upload a xml-file and have the document auto-created. It all seems to work fine, except that the document doesn't appear in the webUI and when i try to access it via the Automation interface (for a subsequent Blob.Attach) I get a 404 Not Found response. So I must be doing something wrong here. The java code i have is below, it's roughly based on Document.Create and Blob.Attach:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;@Operation(id=APAS_CreatePlate.ID, category=Constants.CAT_SERVICES, label="APAS_CreatePlate", description="")
public class APAS_CreatePlate {

    public static final String ID = "APAS_CreatePlate";
    
    @Context
    protected CoreSession session;
    
    @Param(name = "folder", required = true)
    protected DocumentModel m_parent;

    @OperationMethod
    public DocumentModel run(Blob input) throws ClientException {
    	// first create the document model for type Plate
    	DocumentModel newPlate = session.createDocumentModel(m_parent.getPathAsString(), "Plate", "Plate");
    	try {
	    	&amp;lt;&amp;lt;-- snipped away some JAXB init code --&amp;gt;&amp;gt;
	    	// create xml reader
	    	XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(input.getString()));
	        Plate xmlPlate = (Plate)jaxbUnmarshaller.unmarshal(xsr, Plate.class).getValue();
			
	        Properties props = new Properties();
	    	props.put("plate:sample_type", xmlPlate.getSampleType());
	    	// TODO the other relevant properties
	    	DocumentHelper.setProperties(session, newPlate, props);
	    	DocumentHelper.addBlob(newPlate.getProperty("file:content"), input);
	    	DocumentModel doc = session.createDocument(newPlate);
	    	return session.saveDocument(doc);
    	} &amp;lt;&amp;lt;-- snipped exception handling --&amp;gt;&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now when using this code via the URL and JSON payload (and the attached blob of course):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&lt;A href="http://localhost:8080/nuxeo/site/automation/APAS_CreatePlate" target="test_blank"&gt;http://localhost:8080/nuxeo/site/automation/APAS_CreatePlate&lt;/A&gt;
{"params":{"folder": "c5667b68-f712-42ec-a814-fa211e8c89dd"}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I get a JSON response:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;{
    "versionLabel": "0.0", 
    "changeToken": "1385697404589", 
    "uid": "33a41d27-528a-46f2-9e89-8fd60e430930", 
    "repository": "default", 
    "title": "Plate", 
    "lastModified": "2013-11-29T03:56:44.58Z", 
    "facets": [
        "Downloadable", 
        "Commentable", 
        "Asset", 
        "SuperSpace", 
        "Versionable", 
        "Publishable", 
        "HasRelatedText"
    ], 
    "entity-type": "document", 
    "state": "project", 
    "isCheckedOut": true, 
    "contextParameters": {}, 
    "path": "/default-domain/workspaces/amp/plates/Plate", 
    "type": "Plate"
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which seems to indicate to me the document has been created just fine. However, it is apparently not stored, because the next invocation gives the 404:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&lt;A href="http://localhost:8080/nuxeo/site/automation/Blob.Attach" target="test_blank"&gt;http://localhost:8080/nuxeo/site/automation/Blob.Attach&lt;/A&gt;
{"params":{"document": "33a41d27-528a-46f2-9e89-8fd60e430930","xpath": "plate:top_image"}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can anyone suggest a way forward for me?&lt;/P&gt;
&lt;P&gt;Cheers!
Chris&lt;/P&gt;</description>
      <pubDate>Fri, 29 Nov 2013 05:15:33 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/session-savedocument-doesn-apos-t-seem-to-store/m-p/318507#M5508</guid>
      <dc:creator>chrisd_</dc:creator>
      <dc:date>2013-11-29T05:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: Session.saveDocument doesn&amp;apos;t seem to store?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/session-savedocument-doesn-apos-t-seem-to-store/m-p/318508#M5509</link>
      <description>&lt;P&gt;Try to use the session.save method:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;doc = session.saveDocument(doc);
session.save();
return doc;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Dec 2013 07:06:53 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/session-savedocument-doesn-apos-t-seem-to-store/m-p/318508#M5509</guid>
      <dc:creator>adam_bo_</dc:creator>
      <dc:date>2013-12-03T07:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: Session.saveDocument doesn&amp;apos;t seem to store?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/session-savedocument-doesn-apos-t-seem-to-store/m-p/318509#M5510</link>
      <description>&lt;P&gt;Also note that if you call &lt;CODE&gt;session.createDocument&lt;/CODE&gt; you don't need to follow it immediately with &lt;CODE&gt;session.saveDocument&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2013 15:03:01 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/session-savedocument-doesn-apos-t-seem-to-store/m-p/318509#M5510</guid>
      <dc:creator>Florent_Guillau</dc:creator>
      <dc:date>2013-12-03T15:03:01Z</dc:date>
    </item>
    <item>
      <title>Re: Session.saveDocument doesn&amp;apos;t seem to store?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/session-savedocument-doesn-apos-t-seem-to-store/m-p/318510#M5511</link>
      <description>&lt;P&gt;Tried session.save() but it doesn't make a difference. Any other logging i should check to see where an error may occur?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2013 05:23:31 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/session-savedocument-doesn-apos-t-seem-to-store/m-p/318510#M5511</guid>
      <dc:creator>chrisd_</dc:creator>
      <dc:date>2013-12-04T05:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: Session.saveDocument doesn&amp;apos;t seem to store?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/session-savedocument-doesn-apos-t-seem-to-store/m-p/318511#M5512</link>
      <description>&lt;P&gt;Ok, I found my problem, which was as usual between keyboard and chair unfortunately.&lt;/P&gt;
&lt;P&gt;I had an event-handler on the document created event that pushed a document property into a context variable and  my create function didn't set that property so the SetContextVariable operation crashed on that (bit surprised at that, I would have expected it to just push null into the context variable, but ok). And apparently that caused the saving of the document to fail utterly.&lt;/P&gt;
&lt;P&gt;I've now made sure that property always contains a non-null value and everything works fine. Thanks adam_bo and Florent for thinking with me&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2013 05:45:42 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/session-savedocument-doesn-apos-t-seem-to-store/m-p/318511#M5512</guid>
      <dc:creator>chrisd_</dc:creator>
      <dc:date>2013-12-04T05:45:42Z</dc:date>
    </item>
  </channel>
</rss>

