AnsweredAssumed Answered

Controlling Versioning with Java

Question asked by alihammad on Jan 1, 2010
Latest reply on May 12, 2010 by gamin
I create a node and then write something to it. If the versioning is enabled, that creates two version, once when node is created and another when something is written to that node.

Here is how i created the node

ChildAssociationRef association = nodeService.createNode(parentNode,
            ContentModel.ASSOC_CONTAINS, QName.createQName(
                  NamespaceService.CONTENT_MODEL_PREFIX, resourceName),
            ContentModel.TYPE_CONTENT, contentProps);

I have also enabled the versioning like this

nodeService.addAspect(nodeRef, ContentModel.ASPECT_TITLED, titledProps);

After creating the node and applying versioning I write something in the node  like this.

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

      BufferedWriter out = new BufferedWriter(new OutputStreamWriter(writer
                out.write("I am writing some text in node")

But that ultimately creates two versions of the same node. The first node is created when "createNode" method is fired and it contains some ambiguous text like this

"The node's content is missing:
   node: versionStore://version2Store/70fea043-0d6c-431f-9c8a-919cabe35216
   reader: null 
Please contact your system administrator."

but the second version contains the text i wrote with buffered writer.

Is there a way that when I create the node, I could pass the content i want to write in the file, so that only one version is create.

thanks  a lot