Package org.apache.jackrabbit.ocm.manager

Examples of org.apache.jackrabbit.ocm.manager.ObjectContentManager


     */
    public void testDescendantAncestor()
    {
        try
        {
          ObjectContentManager ocm = getObjectContentManager();


            // --------------------------------------------------------------------------------
            // Create and store an object A in the repository
            // --------------------------------------------------------------------------------
            Descendant a = new Descendant();
            a.setPath("/descendant");
            a.setStringData("testdata");
            ocm.insert(a);
            ocm.save();          

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            a = (Descendant) ocm.getObject( "/descendant");
            assertNotNull("a is null", a);
            String uuidA = a.getUuid();
            assertNotNull("uuid is null", uuidA);
            System.out.println("UUID : " + uuidA);
           
            // --------------------------------------------------------------------------------
            // Update the object
            // --------------------------------------------------------------------------------
            a.setStringData("testdata2");
            ocm.update(a);
            ocm.save();

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            a = (Descendant) ocm.getObject("/descendant");
            assertNotNull("a is null", a);
            assertTrue("The uuid has been modified", uuidA.equals(a.getUuid()));
           
            // --------------------------------------------------------------------------------
            // Get the object with the uuid
            // --------------------------------------------------------------------------------          
            a = (Descendant) ocm.getObjectByUuid(uuidA);
            assertNotNull("a is null", a);
            assertTrue("Invalid object found with the uuid ", "testdata2".equals(a.getStringData()));
           
           
        }
View Full Code Here


  }
 

  public void testSimpleVersion()
  {
         ObjectContentManager ocm = getObjectContentManager();
             try
             {
              
               Page page = new Page();
               page.setPath("/page");
               page.setTitle("Page Title");              
               page.addParagraph(new Paragraph("para1"));
               page.addParagraph(new Paragraph("para2"));
               ocm.insert(page);
               ocm.save();
              
                
               page.addParagraph(new Paragraph("para3"));
               ocm.checkout("/page");
               ocm.update(page);
               ocm.save();
               ocm.checkin("/page");
              
               page.addParagraph(new Paragraph("para4"));
               ocm.checkout("/page");
               ocm.update(page);
               ocm.save();
               ocm.checkin("/page");              

               VersionIterator versionIterator = ocm.getAllVersions("/page");
               assertNotNull("VersionIterator is null", versionIterator);
               assertTrue("Invalid number of versions found", versionIterator.getSize() == 3);
              
               while (versionIterator.hasNext())
               {
                 Version version = (Version) versionIterator.next();
                 log.info("version found : "+ version.getName() + " - " + version.getPath() + " - " +  version.getCreated().getTime());
                
               }
              
               Version baseVersion = ocm.getBaseVersion("/page");
               System.out.println("Base version : " + baseVersion.getName());

               Version rootVersion = ocm.getRootVersion("/page");
               System.out.println("Root version : " + rootVersion.getName());
               //this.exportDocument("/home/christophe/export.xml", "/jcr:system/jcr:versionStorage", true, false);
                            
                 //Get the latest version
               page = (Page) ocm.getObject( "/page");
               assertNotNull("Last version is nulll", page);
               assertTrue("Invalid number of paragraph found in the last  version", page.getParagraphs().size() == 4);

              
               //Get the object matching to the first version
                 Page  page1 = (Page) ocm.getObject( "/page", "1.0");
               assertNotNull("version 1.0 object is null", page1);
               assertTrue("Invalid number of paragraph found in the root version", page1.getParagraphs().size() == 3);

             }
             catch(Exception e)
View Full Code Here

    public void testResidualNodes()
    {
        try
        {
          ObjectContentManager ocm = getObjectContentManager();

            // --------------------------------------------------------------------------------
            // Create and store an object graph in the repository with null values
            // --------------------------------------------------------------------------------

            Residual residual = new Residual.ResidualNodes();
            residual.setPath("/test");
            ocm.insert(residual);
            ocm.save();

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            residual = (Residual) ocm.getObject( "/test");
            assertNotNull("Object is null", residual);
            assertNull("Map is not null", residual.getElements());
           
            // --------------------------------------------------------------------------------
            // Update an object graph in the repository
            // --------------------------------------------------------------------------------
            residual = new Residual.ResidualNodes();
            residual.setPath("/test");
           
            ManagedHashMap map = new ManagedHashMap();
            map.put("value1", new Paragraph("Value1"));
            map.put("value2", new Paragraph("Value2"));
            map.put("value3", new Paragraph("Value3"));
            map.put("value4", new Paragraph("Value4"));
            residual.setElements(map);
           
            ocm.update(residual);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            residual = (Residual) ocm.getObject( "/test");
            assertNotNull("Object is null", residual);
            assertTrue("Incorrect number of values", residual.getElements().size() == 4);           
            assertTrue("Incorrect collection element type", (residual.getElements().get("value2") instanceof Paragraph));
            assertEquals("Incorrect collection element text", ((Paragraph) residual.getElements().get("value2")).getText(), "Value2");
           
            // --------------------------------------------------------------------------------
            // Update the object
            // --------------------------------------------------------------------------------
            map = new ManagedHashMap();
            map.put("value11", new Paragraph("Value11"));
            map.put("value12", new Paragraph("Value12"));
            map.put("value13", new Paragraph("Value13"));
            map.put("value14", new Paragraph("Value14"));
            map.put("value15", new Paragraph("Value15"));
            residual.setElements(map);
           
            ocm.update(residual);
            ocm.save();

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          

            residual = (Residual) ocm.getObject( "/test");
            assertNotNull("Object is null", residual);
            assertTrue("Incorrect number of values", residual.getElements().size() == 5);
            assertNull("Unexpected collection element", residual.getElements().get("value2"));
            assertTrue("Incorrect collection element type", (residual.getElements().get("value15") instanceof Paragraph));
            assertEquals("Incorrect collection element text", ((Paragraph) residual.getElements().get("value15")).getText(), "Value15");
View Full Code Here

   
    public void testBasicLock()
    {
        try
        {
          ObjectContentManager ocm = getObjectContentManager();


            // --------------------------------------------------------------------------------
            // Create and store an object graph in the repository
            // --------------------------------------------------------------------------------
            A a = new A();
            a.setPath("/test");
            a.setA1("a1");
            a.setA2("a2");
            B b = new B();
            b.setB1("b1");
            b.setB2("b2");
            a.setB(b);
           
            C c1 = new C();
            c1.setId("first");
            c1.setName("First Element");
            C c2 = new C();
            c2.setId("second");
            c2.setName("Second Element");
           
            C c3 = new C();
            c3.setId("third");
            c3.setName("Third Element");
           
           
            Collection collection = new ArrayList();
            collection.add(c1);
            collection.add(c2);
            collection.add(c3);
           
            a.setCollection(collection);
           
            ocm.insert(a);
            ocm.save();
           

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            a = (A) ocm.getObject( "/test");
            assertNotNull("a is null", a);
           
            // --------------------------------------------------------------------------------
            // Check if the object is locked
            // --------------------------------------------------------------------------------
            assertFalse("the object is locked", ocm.isLocked("/test"));
           
            // --------------------------------------------------------------------------------
            // Lock the object
            // --------------------------------------------------------------------------------          
           
            Lock lock = ocm.lock("/test", true, false);
            assertTrue("the Lock owner is not correct", lock.getLockOwner().equals("superuser"));
           
            // --------------------------------------------------------------------------------
            // Check if the object is locked
            // --------------------------------------------------------------------------------
            assertTrue("the object is not locked", ocm.isLocked("/test"));
           
            // --------------------------------------------------------------------------------
            // Unlock the object
            // --------------------------------------------------------------------------------          
            ocm.unlock("/test", lock.getLockToken());

            // --------------------------------------------------------------------------------
            // Check if the object is locked
            // --------------------------------------------------------------------------------
            assertFalse("the object is locked", ocm.isLocked("/test"));

            // --------------------------------------------------------------------------------
            // Lock & update
            // --------------------------------------------------------------------------------
            lock = ocm.lock("/test", true, false);
            a = (A) ocm.getObject("/test");
            a.setA1("new a1 Value");
            ocm.update(a);
            ocm.save();
            ocm.unlock("/test", lock.getLockToken());
           
           
            // --------------------------------------------------------------------------------
            // Remove the object
            // --------------------------------------------------------------------------------          
            ocm.remove(a);
            ocm.save();
           
        }
        catch (Exception e)
        {
            e.printStackTrace();
View Full Code Here

  }

 
  public void testVersionLabels()
  {
         ObjectContentManager ocm = getObjectContentManager();
             try
             {
              
               Page page = new Page();
               page.setPath("/page");
               page.setTitle("Page Title");              
               page.addParagraph(new Paragraph("para1"));
               page.addParagraph(new Paragraph("para2"));
               ocm.insert(page);
               ocm.save();
              
                
               page.addParagraph(new Paragraph("para3"));
               ocm.checkout("/page");
               ocm.update(page);
               ocm.save();
               ocm.checkin("/page", new String[] {"A", "B"});
              
               page.addParagraph(new Paragraph("para4"));
               ocm.checkout("/page");
               ocm.update(page);
               ocm.save();
               ocm.checkin("/page", new String[] {"C", "D"});           

               String[] allLabels = ocm.getAllVersionLabels("/page");
               assertTrue("Incorrect number of labels", allLabels.length == 4);

               String[] versionLabels = ocm.getVersionLabels("/page", "1.1");
               assertTrue("Incorrect number of labels", versionLabels.length == 2);
               assertTrue("Incorrect label", versionLabels[0].equals("C") || versionLabels[0].equals("D"));
               assertTrue("Incorrect label", versionLabels[1].equals("C") || versionLabels[0].equals("D"));
             
View Full Code Here

     */
    public void testLockWithNodeType()
    {
        try
        {
          ObjectContentManager ocm = getObjectContentManager();


            // --------------------------------------------------------------------------------
            // Create an object which is associated to the
            // --------------------------------------------------------------------------------
            Lockable lockable = new Lockable();
            lockable.setPath("/test");
            lockable.setA1("a1");
            lockable.setA2("a2");
            ocm.insert(lockable);
            ocm.save();
           

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            lockable = (Lockable) ocm.getObject("/test");
            assertNotNull("a is null", lockable);
           
            // --------------------------------------------------------------------------------
            // Check if the object is locked
            // --------------------------------------------------------------------------------
            assertFalse("the object is locked", ocm.isLocked("/test"));
            assertNull("Attribute lockowner is not null", lockable.getLockOwner());
            // --------------------------------------------------------------------------------
            // Lock the object
            // --------------------------------------------------------------------------------                      
            Lock lock = ocm.lock("/test", true, false);
           
            // --------------------------------------------------------------------------------
            // Check if the object is locked
            // --------------------------------------------------------------------------------
            assertTrue("the object is not locked", ocm.isLocked("/test"));
           
            // --------------------------------------------------------------------------------
            // Unlock the object
            // --------------------------------------------------------------------------------          
            ocm.unlock("/test", lock.getLockToken());

            // --------------------------------------------------------------------------------
            // Check if the object is locked
            // --------------------------------------------------------------------------------
            assertFalse("the object is locked", ocm.isLocked("/test"));


            // --------------------------------------------------------------------------------
            // Lock & update
            // --------------------------------------------------------------------------------
            lock = ocm.lock("/test", true, false);
            assertTrue("the object is not locked", ocm.isLocked("/test"));
            lockable = (Lockable) ocm.getObject("/test");
            assertNotNull("Attribute lockowner is null", lockable.getLockOwner());
            lockable.setA1("new a1 Value");
            ocm.update(lockable);
            ocm.save();
            ocm.unlock("/test", lock.getLockToken());
           
           
            // --------------------------------------------------------------------------------
            // Remove the object
            // --------------------------------------------------------------------------------          
            ocm.remove(lockable);
            ocm.save();
           
        }
        catch (Exception e)
        {
            e.printStackTrace();
View Full Code Here

  public void testRetrieveSingleton()
  {

    try
    {
      ObjectContentManager ocm = this.getObjectContentManager();

      //---------------------------------------------------------------------------------------------------------
      // Insert a  folder (class mapped to jcr:folder) with one file (class mapped to jcr:file)
      //---------------------------------------------------------------------------------------------------------     
            Resource resource = new Resource();
            resource.setData(new ByteArrayInputStream("this is the content".getBytes()));           
            resource.setLastModified(Calendar.getInstance());
            resource.setMimeType("plain/text");
            File file = new File();   
            file.setResource(resource);
           
           
            Folder folder = new Folder();
            folder.setPath("/folder1");
            folder.addChild(file);
           
            ocm.insert(folder);           
      ocm.save();
     
     
      //---------------------------------------------------------------------------------------------------------
      // Retrieve a document object
      //---------------------------------------------------------------------------------------------------------           
      folder = (Folder) ocm.getObject( "/folder1");
      assertNotNull("folder is null", folder);
      System.out.println("Folder creation date : " + folder.getCreationDate());
      assertTrue("Invalid number of children", folder.getChildren().size() == 1);
      file = (File) folder.getChildren().iterator().next();
      assertNotNull("resource is null", file.getResource())
View Full Code Here

    public void testCollection()
    {
        try
        {
          ObjectContentManager ocm = getObjectContentManager();
           
          // --------------------------------------------------------------------------------
            // Create and store an object graph in the repository with a null collection
            // --------------------------------------------------------------------------------

            Page page = new Page();
            page.setPath("/test");
            page.setTitle("Page Title");
           
            ocm.insert(page);
            ocm.save();

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            page = (Page) ocm.getObject( "/test");
            assertNull("page.getParagraphs is not null", page.getParagraphs());
            assertTrue("Incorrect page title", page.getTitle().equals("Page Title"));                       
           
            // --------------------------------------------------------------------------------
            // Create and store an object graph in the repository
            // --------------------------------------------------------------------------------
            ArrayList paragraphs = new ArrayList();
           
            paragraphs.add(new Paragraph("Para 1"));
            paragraphs.add(new Paragraph("Para 2"));
            paragraphs.add(new Paragraph("Para 3"));
            page.setParagraphs(paragraphs);
           
            ocm.update(page);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            page = (Page) ocm.getObject( "/test");
            assertNotNull("page.getParagraphs is null", page.getParagraphs());
            assertTrue("Incorrect page title", page.getTitle().equals("Page Title"));
            assertTrue("Incorrect page.getParagraphs size", page.getParagraphs().size() == 3);
            assertTrue("Incorrect para element", ((Paragraph) page.getParagraphs().iterator().next()).getText().equals("Para 1"));
           
            // --------------------------------------------------------------------------------
            // Update the object
            // --------------------------------------------------------------------------------
            paragraphs = new ArrayList();
           
            paragraphs.add(new Paragraph("Para 1"));
            paragraphs.add(new Paragraph("Para 2"));
            paragraphs.add(new Paragraph("Para 4"));
            paragraphs.add(new Paragraph("Para 5"));
            page.setParagraphs(paragraphs);
           
            ocm.update(page);
            ocm.save();

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          

            page = (Page) ocm.getObject( "/test");
            assertNotNull("page.getParagraphs is null", page.getParagraphs());
            assertTrue("Incorrect page title", page.getTitle().equals("Page Title"));
            assertTrue("Incorrect page.getParagraphs size", page.getParagraphs().size() == 4);
            assertTrue("Incorrect para element", ((Paragraph) page.getParagraphs().iterator().next()).getText().equals("Para 1"));
           
View Full Code Here

  public void testRetrieveSingleton()
  {

    try
    {
      ObjectContentManager ocm = this.getObjectContentManager();

      //---------------------------------------------------------------------------------------------------------
      // Insert a  folder (class mapped to jcr:folder) with one file (class mapped to jcr:file)
      //---------------------------------------------------------------------------------------------------------     
            Resource resource = new Resource();
            resource.setData(new ByteArrayInputStream("this is the content".getBytes()));           
            resource.setLastModified(Calendar.getInstance());
            resource.setMimeType("plain/text");
            File file = new File();   
            file.setResource(resource);
           
           
            Folder folder = new Folder();
            folder.setPath("/folder1");
            folder.addChild(file);
           
            ocm.insert(folder);           
      ocm.save();
     
     
      //---------------------------------------------------------------------------------------------------------
      // Retrieve a document object
      //---------------------------------------------------------------------------------------------------------           
      folder = (Folder) ocm.getObject( "/folder1");
      assertNotNull("folder is null", folder);
      System.out.println("Folder creation date : " + folder.getCreationDate());
      assertTrue("Invalid number of children", folder.getChildren().size() == 1);
      file = (File) folder.getChildren().iterator().next();
      assertNotNull("resource is null", file.getResource())
View Full Code Here

  }

  public void testRetrieveSingleton() {

    try {
      ObjectContentManager ocm = this.getObjectContentManager();

      //---------------------------------------------------------------------------------------------------------
      // Insert a descendant object
      //---------------------------------------------------------------------------------------------------------     
      Descendant descendant = new Descendant();
      descendant.setDescendantField("descendantValue");
      descendant.setAncestorField("ancestorValue");
      descendant.setIntField(200);
      descendant.setPath("/test");
      ocm.insert(descendant);
      ocm.save();

      //---------------------------------------------------------------------------------------------------------
      // Retrieve a descendant object
      //---------------------------------------------------------------------------------------------------------           
      descendant = null;
      descendant = (Descendant) ocm.getObject(   "/test");
      assertEquals("Descendant path is invalid", descendant.getPath(), "/test");
      assertEquals("Descendant ancestorField is invalid", descendant.getAncestorField(), "ancestorValue");
      assertEquals("Descendant descendantField is invalid", descendant.getDescendantField(), "descendantValue");
      assertEquals("Descendant intField is invalid", descendant.getIntField(), 200);

      //---------------------------------------------------------------------------------------------------------
      // Update  a descendant object
      //---------------------------------------------------------------------------------------------------------           
      descendant.setAncestorField("anotherAncestorValue");
      descendant.setIntField(123);
      ocm.update(descendant);
      ocm.save();

      //---------------------------------------------------------------------------------------------------------
      // Retrieve the updated descendant object
      //---------------------------------------------------------------------------------------------------------           
      descendant = null;
      descendant = (Descendant) ocm.getObject(   "/test");
      assertEquals("Descendant path is invalid", descendant.getPath(), "/test");
      assertEquals("Descendant ancestorField is invalid", descendant.getAncestorField(), "anotherAncestorValue");
      assertEquals("Descendant descendantField is invalid", descendant  .getDescendantField(), "descendantValue");
      assertEquals("Descendant intField is invalid", descendant.getIntField(), 123);

      Ancestor ancestor = (Ancestor) ocm.getObject("/test");
      assertTrue("Invalid object instance", ancestor instanceof Descendant );
      assertEquals("Ancestor  path is invalid", ancestor.getPath(), "/test");
      assertEquals("Ancestor ancestorField is invalid", ancestor.getAncestorField(), "anotherAncestorValue");
     
     
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.ocm.manager.ObjectContentManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.