8 Replies Latest reply on Oct 26, 2013 4:52 AM by fazileh

    Remove all children of a node [modeshape]

    fazileh

      Hi,

      I have node with some properties and a child node that is [nt:folder] type and there are some [nt:file] node type into that. Now I want to remove this node with all sub tree (prpperties and childs) .

      I tried this command:

       

      node.remove();

      But the node just removed and files child in reporsitory remain yet.

       

      I tried these code:

       

      JcrTools tools = new JcrTools();

      tools.removeAllChildren(node);

      PropertyIterator pIt = node.getProperties();

                  while (pIt.hasNext()) {

                      javax.jcr.Property property = pIt.nextProperty();

                      if (!property.isNode()) {

                          System.out.println("pname: " + property.getName());           // just for test

                          property.remove();

                      } else {

                          property.getNode().remove();

                      }

                  }

      node.remove();

       

      But throws:

      java.io.FileNotFoundException: home/user/Repository/83 (Is a directory) ...

       

      If my way is not correct , I will be appreciate if you help me.

      Thank you.

        • 1. Re: Remove all children of a node [modeshape]
          hchiorean

          node.remove() should remove the node and its entire subgraph. However, you need to call session.save() to make sure the changes are persisted (even if you use JcrTools, you still need to call session.save afterwards)

          • 2. Re: Remove all children of a node [modeshape]
            fazileh

            Thanks for your answer, but I used session.save() after these codes but files childs remain yet!

            • 3. Re: Remove all children of a node [modeshape]
              hchiorean

              Ok, in this case please attach your configuration and if possible the node types involved in this scenario. Did you check the logs/output for any errors/warnings during the remove operation ?

               

              Are you using federation by any chance ? The only cases I can think of when a  java.io.FileNotFoundException would be raised in relation to removing a node would either be a) you're using an ISPN file store and something is corrupted on the disk or b)  you're using federation and the FS connector.

              • 4. Re: Remove all children of a node [modeshape]
                fazileh

                This is infinispan_configuration.xml:

                 

                <?xml version="1.0" encoding="UTF-8"?>

                <infinispan

                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                       xsi:schemaLocation="urn:infinispan:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd"

                       xmlns="urn:infinispan:config:5.1">

                    <namedCache name="MyRepository">

                         <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"

                                    transactionMode="TRANSACTIONAL"

                                    lockingMode="PESSIMISTIC"/>

                         <loaders passivation="false" shared="false" preload="false">

                 

                         <loader class="org.infinispan.loaders.file.FileCacheStore"

                                  fetchPersistentState="false"

                                  purgeOnStartup="false">

                             <properties>

                                       <property name="location" value="/home/fazileh/MyStorage"/>

                             </properties>

                 

                          </loader>

                       </loaders>

                    </namedCache>

                </infinispan>

                ---------------------------------------------------------------------------------------------------------------------------

                This is repository.json file:

                {

                    "name" : "MyRepository",

                    "transactionMode" : "auto",

                    "monitoring" : {

                        "enabled" : true,

                        },

                    "workspaces" : {

                        "predefined" : ["otherWorkspace"],

                        "default" : "my_wsp",

                        "allowCreation" : true

                    },

                    "security" : {

                        "anonymous" : {

                            "roles" : ["readonly","readwrite","admin"],

                            "useOnFailedLogin" : false

                        }

                    },

                    "storage" : {

                        "cacheName" : "MyRepository",

                        "cacheConfiguration" : "${user.home}/.MyRep/infinispan_configuration.xml",

                        "transactionManagerLookup" = "org.infinispan.transaction.lookup.GenericTransactionManagerLookup",

                        "binaryStorage" : {

                              "type" : "file",

                              "directory" : "${user.home}/MyStorage/MyRepository",

                              "minimumBinarySizeInBytes" : 4096

                          }

                      }

                }

                ------------------------------------------------------------------------------------------------------------------------------------------------

                and I do not use "FS connector" !


                My node is:

                -Email<node>

                     - subject (String)

                     - from (String)

                     - cc (multi value)

                     .

                     .

                     .

                     - attach <node> [nt:folder]

                          - file <node> [nt:file]

                               - content

                          - file <node> [nt:file]

                               - content

                    

                Thank you again.

                • 5. Re: Remove all children of a node [modeshape]
                  hchiorean

                  Thanks for data, your configuration looks ok (the transactionManagerLookup attribute is deprecated, but doesn't influence anything).

                   

                  I should've asked the first time: are you using the 3.2.0 version of Modeshape ? (I noticed the ISPN xsd is 5.1, while 3.2.0 uses Infinispan 5.2.5)

                   

                  Also, can you please attach the server log so I can see the full stacktrace of the exception ?

                  • 6. Re: Remove all children of a node [modeshape]
                    fazileh

                    I am using ModeShpae 3.1.1 version.

                    and this is server log:

                     

                    this exception occures on [ property.remove();] line.

                     

                    pname: jcr:primaryType

                    pname: cc

                    java.lang.NullPointerException

                              at org.modeshape.jcr.AbstractJcrNode.isNodeType(AbstractJcrNode.java:2231)

                              at org.modeshape.jcr.AbstractJcrNode.isCheckedOut(AbstractJcrNode.java:3042)

                              at org.modeshape.jcr.AbstractJcrProperty.checkForCheckedOut(AbstractJcrProperty.java:207)

                              at org.modeshape.jcr.AbstractJcrProperty.remove(AbstractJcrProperty.java:310)

                              at com.ayriksoft.kardar.test.EmailTest.deleteEmail(EmailTest.java:209)

                              at com.ayriksoft.kardar.test.EmailTest.f(EmailTest.java:39)

                              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

                              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

                              at java.lang.reflect.Method.invoke(Method.java:601)

                              at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)

                              at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)

                              at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)

                              at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)

                              at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)

                              at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)

                              at org.testng.TestRunner.privateRun(TestRunner.java:767)

                              at org.testng.TestRunner.run(TestRunner.java:617)

                              at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)

                              at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)

                              at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)

                              at org.testng.SuiteRunner.run(SuiteRunner.java:240)

                              at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)

                              at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)

                              at org.testng.TestNG.runSuitesSequentially(TestNG.java:1197)

                              at org.testng.TestNG.runSuitesLocally(TestNG.java:1122)

                              at org.testng.TestNG.run(TestNG.java:1030)

                              at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)

                              at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)

                              at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

                     

                    Apr 30, 2013 12:26:54 PM org.infinispan.loaders.file.FileCacheStore$NumericNamedFilesFilter accept

                    WARN: ISPN000163: FileCacheStore ignored an unexpected file trash in path /home/fazileh/MyStorage/MyRepository. The store path should be dedicated!

                    Apr 30, 2013 12:26:55 PM org.infinispan.loaders.file.FileCacheStore loadBucket

                    ERROR: ISPN000062: Error while reading from file: /home/fazileh/MyStorage/MyRepository/83

                    java.io.FileNotFoundException: /home/fazileh/MyStorage/MyRepository/83 (Is a directory)

                              at java.io.FileInputStream.open(Native Method)

                              at java.io.FileInputStream.<init>(FileInputStream.java:138)

                              at org.infinispan.loaders.file.FileCacheStore.loadBucket(FileCacheStore.java:311)

                              at org.infinispan.loaders.file.FileCacheStore.doPurge(FileCacheStore.java:254)

                              at org.infinispan.loaders.file.FileCacheStore.purgeInternal(FileCacheStore.java:233)

                              at org.infinispan.loaders.AbstractCacheStore$2.run(AbstractCacheStore.java:106)

                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

                              at java.lang.Thread.run(Thread.java:722)

                    • 7. Re: Remove all children of a node [modeshape]
                      hchiorean

                      Please try using ModeShape 3.2.0 and check if this is still happenning. Not only have we fixed 120 issues from 3.1.1 to 3.2.0, but the change in Infinispan from 5.1.x to 5.2.x is significant.

                       

                      Thanks

                      • 8. Re: Remove all children of a node [modeshape]
                        fazileh

                        I will use Modeshape 3.2.0 and test it.

                        Thank you for considering my problem.