cancel
Showing results for 
Search instead for 
Did you mean: 

Session.saveDocument doesn't seem to store?

chrisd_
Champ in-the-making
Champ in-the-making

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:

@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 {
	    	<<-- snipped away some JAXB init code -->>
	    	// 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);
    	} <<-- snipped exception handling -->>

Now when using this code via the URL and JSON payload (and the attached blob of course):

http://localhost:8080/nuxeo/site/automation/APAS_CreatePlate
{"params":{"folder": "c5667b68-f712-42ec-a814-fa211e8c89dd"}

I get a JSON response:

{
    "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"
}

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:

http://localhost:8080/nuxeo/site/automation/Blob.Attach
{"params":{"document": "33a41d27-528a-46f2-9e89-8fd60e430930","xpath": "plate:top_image"}

Can anyone suggest a way forward for me?

Cheers! Chris

4 REPLIES 4

adam_bo_
Star Contributor
Star Contributor

Try to use the session.save method:

doc = session.saveDocument(doc);
session.save();
return doc;

Also note that if you call session.createDocument you don't need to follow it immediately with session.saveDocument.

chrisd_
Champ in-the-making
Champ in-the-making

Tried session.save() but it doesn't make a difference. Any other logging i should check to see where an error may occur?

chrisd_
Champ in-the-making
Champ in-the-making

Ok, I found my problem, which was as usual between keyboard and chair unfortunately.

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.

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

Getting started

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.