AnsweredAssumed Answered

Content update problem: url is unmodified

Question asked by ale_carraro on Jul 13, 2009
Latest reply on Jul 13, 2009 by ale_carraro
Hi to everyone, I've a strange problem.

First I introduce briefly what I'm trying to do:
I'm trying to create a tool so that a workflow could write its history into its package documents (open offcice). To do this, i have a 'javascript' action (that is, a BaseProcessorExtension mapped into a javascript variable so that I could invoke that operation by a custom action or by a 'normal' org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript.

The action is called in the right manner, an I'm able to use a sort of template filler (greatly based on jooreports) with the following syntax (inside the wf):

   template = {}; =;
   template.surname =; = new Date().toString();
   ooTemplateWriter.transform(bpm_package.children[i], bpm_package.children[i], template);

The document produced is correct. However from the user interface the document is unmodified in its content (the mod date is updated).

Debugging I finally found the problem: the contentUrl part of property cm:content is updated (in the sense that DbNodeServiceImpl.setProperty(NodeRef nodeRef, QName qname, Serializable value) is normally called and returns without errors, but in the node browser it is not. The correct url points to a .bin file that is the correct openOffice file, but the node browser points instead to the old url, so when downloading I get the template document.

The code I'm using is similar to the one inside the OpenOffice translator:

       ContentReader reader = contentService.getReader(source.getNodeRef(), ContentModel.PROP_CONTENT);
        // create temporary files to convert from and to
        File tempFromFile = TempFileProvider.createTempFile("OpenOfficeContentFiller-source-", ".odt");
        File tempToFile = TempFileProvider.createTempFile("OpenOfficeContentFiller-target-", ".odt");
        // download the content from the source reader

        InputStream is = new FileInputStream(tempFromFile);
        ZippedDocumentTemplate zippedDocumentTemplate = new ZippedDocumentTemplate(is);

        OutputStream os = new FileOutputStream(tempToFile);
        zippedDocumentTemplate.createDocument(m, os);

        ContentWriter writer = contentService.getWriter(destinationNode.getNodeRef(), ContentModel.PROP_CONTENT, true);

        // upload the temp output to the writer given us

Note that I'm sure that everything besides the last line is absolutely correct.

An interesting thing might be the following: Copying the first snippet in a js file and put that in the Scrips directory, replacing every "bpm_package.children" with "document" works perfectly.
What could it be?