8 Replies Latest reply on Dec 11, 2013 3:48 AM by veskop86

    How to copy node with autocreated child nodes?

    veskop86

      Hello,

       

      I'm trying to create copy of node which has autocreated child nodes but it throws exception like:

       

      Cannot find a definition for a child named {childNodeName} on the node at {path} with primary type {parentNodeType} and mixin types: []

       

       

      BUG: Because of that I was looking the source code to determine why it throws exception and than I found bug (?) in method:

       

      org.modeshape.jcr.AbstractJcrNode.getAllReferences()

       

      getReferences() method is used for getting both strongReferences and weakReferences:

       

          protected PropertyIterator getAllReferences() throws RepositoryException {

              List<javax.jcr.Property> allReferences = new ArrayList<javax.jcr.Property>();

              for (PropertyIterator strongRefIterator = getReferences(); strongRefIterator.hasNext();) {

                  allReferences.add(strongRefIterator.nextProperty());

              }

              for (PropertyIterator weakRefIterator = getReferences(); weakRefIterator.hasNext();) {

                  allReferences.add(weakRefIterator.nextProperty());

              }

              return new JcrPropertyIterator(allReferences);

          }

       

      Kind regards

       

      Sorry for bad English

        • 1. Re: How to copy node with autocreated child nodes?
          rhauch

          With respect to the 'getReferences()' bug, can you log it in our JIRA? It does look like a problem.

           

          Regarding the auto-created problem, it's difficult to say without more information about the node types and (even better) a simple test case that shows the problem. Check that your node types are defined correctly.

          • 2. Re: Re: How to copy node with autocreated child nodes?
            veskop86

            Hi, thank You for quick response,

             

            Node type is simple. Just node with few autocreated subnode like

             

            test:Parent

            |---test:Folder    -autocreated, extends nt:folder,          with name Icons              requiredPrimaryType: test:Folder

            |---test:Folder    -autocrested, also extends nt:folder    with name Config              requiredPrimaryType: test:Folder

            ...

            `---test:Folder    -autocreated, extends nt:folder            with name Templates        requiredPrimaryType: test:Folder

             

            Now  when I try to copy node of this node type console is filled whit stacktrace where first message is


            Cannot find a definition for a child named 'Icons' on the node at '/Config/CustomConfig' with primary type 'test:Parent' and mixin types: []


            Because of this problem I cloned git repository to see if I missed something with configuration. After some exploring I put some loggers and released that problem occures on line 241


            dstNode.setProperty(JcrLexicon.UUID, identifierValue, true, true, false, false);


            inside of method org.modeshape.jcr.JcrWorkspace.copy(String, String, String)


            That is method that is used if nodes are referenceable. After finding this out I changed my definition not to be referenceable and started test again.

            Process of copying is finished without exceptions but subnodes of copy were doubled like:


            Copy

            |--Icons

            |--Icons

            |--Config

            |--Config

            ...

            |--Templates

            |--Templates


            Again sorry for bad English


            Kind regards

            • 3. Re: How to copy node with autocreated child nodes?
              rhauch

              The bug you logged as MODE-2114 should not affect auto-creation in your case, since you don't appear to be using REFERENCE or WEAKREFERENCE properties. Please correct me if I'm wrong and missing something.

               

              Can you share either a test case or your CND files and some sample Java code? That will help us better understand your scenario and what might be going wrong. A test case that replicates the problem would be ideal.

               

              Line 241 in JcrWorkspace.copy is simply ensuring that the new node's "jcr:uuid" property (which must be there on a node that is "mix:referenceable") be properly set to the destination node's internal identifier. I'm not sure why you think this line is suspect, nor how this might cause there to be duplicate children.

               

              Best regards

              • 4. Re: How to copy node with autocreated child nodes?
                veskop86

                Sorry i'm not so good in explaining things

                 

                 

                I edited my previous comment after Your answer because I released that I forget to mention that my nodes were referenceable and I didn't saw the answer before editing.

                I release that Line 241 is not problem but that is the place where exception was thrown (ConstraintViolationException). Exception was thrown from org.modeshape.jcr.AbstractJcrNode.nodeDefinition() after org.modeshape.jcr.RepositoryNodeTypeManager.NodeTypes.findChildNodeDefinition(Name, Collection<Name>, Name, Name, int, boolean) returned null.

                 

                 

                In copy method on jcrWorkspace, after deepCopy, before doing extra processing, in my case, subnodes were doubled as I mentioned before. Because the nodes has mix:referenceable, set uuid property was called, line 241. After that nodeDefinition() method is called(somewhere in setProperty) and than findChildNodeDefinition() where parameter numExistingSnsInParent has value of 2. There couldn't be two child nodes with same name and same type because is not defined like that (no sameNameSiblings) so findChildNodeDefinition() returns null, and throws exception noChildNodeDefinition. After removing referenceable mixin as result of copying I got node with doubled subnodes.

                 

                 

                I don't have test at the moment and I don't use CND, but custom object that wraps NodeType. I'll try to make soon enough test case and will post it here soon, I guess

                 

                 

                You are absolutely right about MODE-2114, but I've seen that there is same method for getting different values and I wanted to report it, but it is not related with my problem.

                • 5. Re: How to copy node with autocreated child nodes?
                  rhauch

                  Sorry i'm not so good in explaining things

                   

                  Please, do not worry about it. I don't think it's the language, it's simply that we already have test cases that shows it works for nominal cases. The trick is to figure out what is different about your scenario and why ModeShape is misbehaving in your scenario. Fortunately for us ModeShape is extremely flexible and thus can be used in thousands of different permutations. Unfortunately, that makes replicating problems very challenging. The best way to do that is to have a small, self-contained test case that replicates the problem. We can then run that test case and far more easily analyze the problem.

                   

                  I edited my previous comment after Your answer because I released that I forget to mention that my nodes were referenceable and I didn't saw the answer before editing.

                  This is another example of why a test case that replicates the problem is so important: its very easy to forget seemingly minor details that turn out to be very critical. In this case, I don't think failing to correctly copy the references is the ultimate cause of the problem but merely an additional bug that complicates the behavior and the location where a problem is first exhibited.

                   

                  I don't have test at the moment and I don't use CND, but custom object that wraps NodeType. I'll try to make soon enough test case and will post it here soon, I guess.

                  Does that mean you're programmatically generating new node type? Your test case can absolutely do this -- IOW you don't need a CND file. Do whatever you have to get a test case that replicates the scenario, and then (if it is complicated) keep simplifying it while it continues to exhibit the problem. If you try to remove anything that makes the problem go away, make not of it and let us know what that is when you submit the test case as a JIRA bug report.

                   

                  Thanks!!

                   

                  P.S. We're planning to release 3.7 in around one week from today (roughly Dec 17), so the sooner you can share a test case the more likely we'll fix it in the 3.7 release.

                  • 6. Re: Re: How to copy node with autocreated child nodes?
                    veskop86

                    Hello again

                    Thank you again for quick response

                     

                    Hire is the test. I created simple autocreated-child-nodes.cnd and put it on path modeshape-jcr\src\test\resources\cnd.

                     

                    After that I used JcrWorkspaceTest to create new one called CopyAutoCreatedChildrenTest.java. There are some sysouts to see what's happening.

                     

                    Hope this is helpfull

                     

                    Kind regards

                    • 7. Re: Re: How to copy node with autocreated child nodes?
                      rhauch

                      Would you mind creating a bug in our JIRA and describing the autocreation problem and attaching the test case there? Much appreciated.

                      • 8. Re: Re: How to copy node with autocreated child nodes?
                        veskop86

                        New issue is created MODE-2115