Package org.exoplatform.services.jcr.impl.core

Examples of org.exoplatform.services.jcr.impl.core.NodeImpl


   private static final String fileName = "FileToRewrite";

   public void testRewriteNode() throws Exception
   {

      NodeImpl node = (NodeImpl)root.addNode(fileName, "nt:file");
      NodeImpl cont = (NodeImpl)node.addNode("jcr:content", "nt:resource");
      cont.setProperty("jcr:mimeType", "text/plain");
      cont.setProperty("jcr:lastModified", Calendar.getInstance());
      // cont.setProperty("jcr:encoding","UTF-8");

      cont.setProperty("jcr:data", "The Quick brown fox jumped over the lazy dog");
      root.save();

      IndexReader reader = defaultSearchIndex.getIndexReader();
      IndexSearcher is = new IndexSearcher(reader);
      TermQuery query = new TermQuery(new Term(FieldNames.FULLTEXT, "fox"));
      Hits result = is.search(query);
      assertEquals(1, result.length());

      cont.setProperty("jcr:data", "Bahama mama");
      root.save();

      reader = defaultSearchIndex.getIndexReader();
      is = new IndexSearcher(reader);
      query = new TermQuery(new Term(FieldNames.FULLTEXT, "mama"));
View Full Code Here


      TesterItemsPersistenceListener pl = new TesterItemsPersistenceListener(this.session);

      File file = this.createBLOBTempFile(310);
      FileInputStream fis = new FileInputStream(file);

      NodeImpl node = (NodeImpl)root.addNode("file", "nt:file");
      NodeImpl cont = (NodeImpl)node.addNode("jcr:content", "nt:resource");
      cont.setProperty("jcr:mimeType", "text/plain");
      cont.setProperty("jcr:lastModified", Calendar.getInstance());
      cont.setProperty("jcr:encoding", "UTF-8");

      cont.setProperty("jcr:data", fis);
      root.save();

      fis.close();

      file.delete();
View Full Code Here

public class TestMultiValueSearch extends BaseQueryTest
{

   public void testString() throws Exception
   {
      NodeImpl node = (NodeImpl)root.addNode("String", "nt:unstructured");
      node.setProperty("jcr:data", new String[]{"First", "Second"});
      root.save();

      // Check is node indexed
      Document doc = getDocument(node.getInternalIdentifier(), false);
      assertNotNull("Node is not indexed", doc);
      System.out.println("its doc " + doc);

      QueryManager qman = this.workspace.getQueryManager();
View Full Code Here

      assertEquals("Second value isnt found.", 1, res.getNodes().getSize());
   }

   public void testBinary() throws Exception
   {
      NodeImpl node = (NodeImpl)root.addNode("Binary", "nt:unstructured");
      NodeImpl cont = (NodeImpl)node.addNode("jcr:content");
      cont.setProperty("jcr:mimeType", "text/plain");
      cont.setProperty("jcr:data", new String[]{"FirstB", "SecondB"}, PropertyType.BINARY);
      root.save();

      // Check is node indexed
      Document doc = getDocument(node.getInternalIdentifier(), false);
      assertNotNull("Node is not indexed", doc);
View Full Code Here

    * @throws Exception
    */
   public void testUser() throws Exception
   {
      // Mary only node, Mary membership is '*:/exo', seems it's user
      NodeImpl maryNode = (NodeImpl) testRoot.addNode("mary");
      maryNode.addMixin("exo:privilegeable");
      if (!session.getUserID().equals("mary"))
      {
         maryNode.setPermission("mary", PermissionType.ALL);
         maryNode.removePermission(session.getUserID());
      }
      maryNode.removePermission(SystemIdentity.ANY);
      testRoot.save();

      try
      {
         Session marySession =
            repository.login(new CredentialsImpl("mary", "exo".toCharArray()), session.getWorkspace().getName());
         NodeImpl myNode = (NodeImpl)marySession.getItem(maryNode.getPath());
         Node test = myNode.addNode("test");
         test.setProperty("property", "any data");
         myNode.save();
         test.remove();
         myNode.save();
      }
      catch (AccessControlException e)
      {
         e.printStackTrace();
         fail(e.getMessage());
View Full Code Here

   private NodeTypeDataManager ntHolder;

   public void testDumpMatcher() throws Exception
   {
      NodeImpl node = (NodeImpl)root.addNode("test");
      NodeImpl node1 = (NodeImpl)root.addNode("test1");
      QPath[] paths = new QPath[]{node.getInternalPath(), node1.getInternalPath()};

      SessionEventMatcher matcher =
         new SessionEventMatcher(Event.NODE_ADDED, paths, true, null, new InternalQName[]{Constants.NT_BASE,
            Constants.NT_UNSTRUCTURED, Constants.NT_QUERY}, ntHolder);
      System.out.println(matcher.dump());
View Full Code Here

   public void testMatchDeepPath() throws Exception
   {
      SessionActionCatalog catalog =
         (SessionActionCatalog)container.getComponentInstanceOfType(SessionActionCatalog.class);
      catalog.clear();
      NodeImpl node = (NodeImpl)root.addNode("test");

      // test by path
      SessionEventMatcher matcher =
         new SessionEventMatcher(Event.NODE_ADDED, new QPath[]{node.getInternalPath()}, true, null, null, ntHolder);
      catalog.addAction(matcher, new DummyAction());
      Condition cond = new Condition();

      cond = new Condition();
      cond.put(SessionEventMatcher.EVENTTYPE_KEY, Event.NODE_ADDED);
      cond.put(SessionEventMatcher.PATH_KEY, node.getInternalPath());

      // test for this path
      assertEquals(1, catalog.getActions(cond).size());

      cond.put(SessionEventMatcher.PATH_KEY, Constants.ROOT_PATH);
      assertEquals(0, catalog.getActions(cond).size());

      // test for child path
      QPath child = QPath.makeChildPath(node.getInternalPath(), Constants.EXO_PREFIX);
      cond.put(SessionEventMatcher.PATH_KEY, child);
      assertEquals(1, catalog.getActions(cond).size());

      // test for grandchild path - found as deep = true
      QPath grandchild = QPath.makeChildPath(child, Constants.EXO_PREFIX);
View Full Code Here

   public void testMatchNotDeepPath() throws Exception
   {
      SessionActionCatalog catalog =
         (SessionActionCatalog)container.getComponentInstanceOfType(SessionActionCatalog.class);
      catalog.clear();
      NodeImpl node = (NodeImpl)root.addNode("test");

      // test by path
      SessionEventMatcher matcher =
         new SessionEventMatcher(Event.NODE_ADDED, new QPath[]{((NodeImpl)root).getInternalPath()}, false, null, null,
            ntHolder);
      catalog.addAction(matcher, new DummyAction());
      Condition cond = new Condition();

      cond = new Condition();
      cond.put(SessionEventMatcher.EVENTTYPE_KEY, Event.NODE_ADDED);

      // test for this path
      cond.put(SessionEventMatcher.PATH_KEY, Constants.ROOT_PATH);
      assertEquals(1, catalog.getActions(cond).size());

      // test for child path
      cond.put(SessionEventMatcher.PATH_KEY, node.getInternalPath());
      assertEquals(1, catalog.getActions(cond).size());

      // test for grandchild path - not found as deep = false
      QPath child = QPath.makeChildPath(node.getInternalPath(), Constants.EXO_PREFIX);
      cond.put(SessionEventMatcher.PATH_KEY, child);
      assertEquals(0, catalog.getActions(cond).size());

   }
View Full Code Here

   public void testUserCanRemoveParentButCanNotRemoveChild() throws Exception
   {
      // login as Mary and create subNode
      Session sessMary = repository.login(new CredentialsImpl("mary", "exo".toCharArray()));
      Node testRoot = sessMary.getRootNode().getNode("testRoot");
      NodeImpl subNode = (NodeImpl)testRoot.addNode("subNode");
      subNode.addMixin("exo:privilegeable");
      sessMary.save();

      subNode.setPermission("mary", PermissionType.ALL);
      subNode.removePermission("john");
      subNode.removePermission(SystemIdentity.ANY);
      sessMary.save();
      sessMary.logout();

      // login as John and try remove subnode
      Session sessJohn = repository.login(new CredentialsImpl("john", "exo".toCharArray()));
      try
      {
         subNode = (NodeImpl)sessJohn.getRootNode().getNode("testRoot").getNode("subNode");
         subNode.remove();
         sessJohn.save();
         fail("There must be AccessDeniedException");
      }
      catch (AccessDeniedException e)
      {
         //Ok
      }

      // try to remove parent node node
      sessJohn.refresh(false);
      try
      {
         testRoot = sessJohn.getRootNode().getNode("testRoot");
         testRoot.remove();
         sessJohn.save();
         fail("There must be AccessDeniedException");
      }
      catch (AccessDeniedException e)
      {
         //Ok
      }
      finally
      {
         sessJohn.logout();
      }

      // now try with all permissions
      sessMary = repository.login(new CredentialsImpl("mary", "exo".toCharArray()));
      testRoot = sessMary.getRootNode().getNode("testRoot");
      subNode = (NodeImpl)testRoot.getNode("subNode");
      subNode.setPermission(SystemIdentity.ANY, PermissionType.ALL);
      sessMary.save();
      sessMary.logout();

      sessJohn = repository.login(new CredentialsImpl("john", "exo".toCharArray()));
      testRoot = sessJohn.getRootNode().getNode("testRoot");
View Full Code Here

    */
   public void testUserCanNotRemoveParentButCanRemoveChild() throws Exception
   {
      // login as Mary and create subNode
      Session sessMary = repository.login(new CredentialsImpl("mary", "exo".toCharArray()));
      NodeImpl testRoot = (NodeImpl)sessMary.getRootNode().getNode("testRoot");
      NodeImpl subNode = (NodeImpl)testRoot.addNode("subNode");
      subNode.addMixin("exo:privilegeable");
      sessMary.save();

      //set permissions
      subNode.setPermission("mary", PermissionType.ALL);
      subNode.removePermission("john");
      subNode.removePermission(SystemIdentity.ANY);
      sessMary.save();

      testRoot.setPermission("john", PermissionType.ALL);
      testRoot.removePermission("mary");
      testRoot.setPermission("mary", new String[]{PermissionType.READ});
      testRoot.removePermission(SystemIdentity.ANY);
      sessMary.save();
      sessMary.logout();

      //try to remove parent as Mary - must fail
      sessMary = repository.login(new CredentialsImpl("mary", "exo".toCharArray()));
      try
      {
         testRoot = (NodeImpl)sessMary.getRootNode().getNode("testRoot");
         testRoot.remove();
         sessMary.save();
         fail("There must be AccessDeniedException");
      }
      catch (AccessDeniedException e)
      {
         //Ok
      }
      sessMary.refresh(false);

      // remove subnode as mary
      subNode = (NodeImpl)sessMary.getRootNode().getNode("testRoot").getNode("subNode");
      subNode.remove();
      sessMary.save();
      assertFalse(sessMary.getRootNode().getNode("testRoot").hasNode("subNode"));
      sessMary.logout();
   }
View Full Code Here

TOP

Related Classes of org.exoplatform.services.jcr.impl.core.NodeImpl

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.