AnsweredAssumed Answered

JCR & versioning

Question asked by anweber on Apr 19, 2006
Hi,

   I have a little problem.  When I give the "versionable" aspect to a node that I just have created, the webclient shows me this node as an "checked out" node (but without a working copy) even if I call the checkin method.

   There is my code :


package org.alfresco.jcr.example;

import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;



/**
* Simple test
*
* @author Andr? W?ber
*/
public class AweJcrTest
{

    public static void main(String[] args)
        throws Exception
    {
        // Setup Spring and Transaction Service
        //ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/jcr-context.xml");
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:org/alfresco/jcr/example/AweJcrTest-context.xml");
       
       
        // Retrieve Repository
        Repository repository = (Repository)context.getBean("JCR.Repository");

        // Login to workspace
        // Note: Default workspace is the one used by Alfresco Web Client which contains all the Spaces
        //       and their documents
        Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

        try
        {
            // Retrieve Company Home
            Node root = session.getRootNode();
            Node companyHome = root.getNode("app:company_home");

            System.out.println("try to create AWE objects");
          
            // create the root AWE folder
            Node folder = companyHome.addNode("cm:aweTestFolder", "cm:folder");
            folder.setProperty("cm:name", "AWE test folder");
            folder.setProperty("cm:description", "AWE test folder, created with JCR");
            folder.save();

            // create a document inside this folder
            Node document = folder.addNode("cm:aweTestDoc", "cm:content");
            document.setProperty("cm:name", "AWE test doc");
            document.setProperty("cm:description", "AWE test document, created with JCR");
            document.setProperty("cm:title", "AWE's document");
            document.setProperty("cm:content", "What's up, doctor?");
            document.addMixin("mix:versionable");
           
            document.checkin();
           
           session.save();
            System.out.println("AWE objects created");
         }
        catch(Exception exc){
           System.err.println("exception" + exc.getMessage());
           exc.printStackTrace();
        }
        finally
        {
            session.logout();
            System.exit(0);
        }
       
    }
   
}


     Thanks for your help,

             Andre

PS : Sorry to work in your package ("org.alfresco.jcr.example").  :oops:  I will create my own as soon as possible.

Outcomes