6 Replies Latest reply on Jan 28, 2013 5:04 PM by nl

    Versioning question

    nl

      Hi,

       

      apparently things work differently in MS3 then in MS2. In MS2 I remember the version's uuid to look it up later on. But in MS3 it does not work anymore.

      Having a version v, v.getProperty("jcr:uuid") (e.g. 46d2350b-2db1-46c4-b2cd-40c9f14bc476) does not return the same as v.getIdentifier() (e.g. 454d822317f1e746d2350b-2db1-46c4-b2cd-40c9f14bc476).

       

      Moreover a node with the version's uuid cannot be found at all.

       

      See code below:

       

      {code}

              Node root = session.getRootNode();

              // create node

              Node n = root.addNode("files/test.txt","nt:file");

              Node rn = n.addNode("jcr:content", "nt:resource");

              rn.addMixin("mix:versionable");

              rn.setProperty("jcr:data", "Hello World");

              session.save();

              vm.checkin(rn.getPath());

              System.out.println(rn.getIdentifier() + " - " + rn.getProperty("jcr:uuid").getString());

             

              // update node

              vm.checkout(rn.getPath());

              rn.setProperty("jcr:data", "Hello World2");

              session.save();

              vm.checkin(rn.getPath());

              System.out.println(rn.getIdentifier() + " - " + rn.getProperty("jcr:uuid").getString());

             

              // get a version

              VersionHistory vh = vm.getVersionHistory(rn.getPath());

              Version v = vh.getAllLinearVersions().nextVersion();

              session.getNodeByIdentifier(v.getProperty("jcr:uuid").getString()); // throws ItemNotFoundException

              session.getNodeByIdentifier(v.getIdentifier()); // works

       

      {code}

       

      Is this correct behaviour?

       

      Thanks, Niels

        • 1. Re: Versioning question
          rhauch

          No, it is not correct. You should always be able to find a node given it's identifier (from "node.getIdentifier()") OR its "jcr:uuid" property value (if it has one). I've created MODE-1775 to cover this. Obviously you found the workaround.

           

          Thanks! We'll get this fixed in 3.1.1.

          • 2. Re: Versioning question
            nl

            Thanks, Randall.

             

            What will happen, if I use the migration tool announced for 2.8.4? Will the uuids stay the same after migration?

            Currently I store uuids (of "real" nodes as well as of "versions") in our application database as a link to documents in modeshape. And I fear that those uuids will be useless afterwards.

             

            And a second question regarding versions:

            In MS2 the following (maybe crude) logic works to get the "original" node for a given version node by searching its references.

             

            {code}

            public static Node findFileNodebyVersion(Version v)

                        throws RepositoryException {

                    // if it is a version node find the base version

                    if (v == null) {

                        return null;

                    }

                    for (PropertyIterator it = v.getReferences(); it.hasNext();) {

                        Property p = (Property) it.next();

                        Node n = p.getParent();

                        if (n != null

                                && (n.isNodeType(NT_RESOURCE) || n.isNodeType(NT_UNSTRUCTURED))) {

                            return n.getParent();

                        }

                    }

             

                    return findFileNodebyVersion(v.getLinearSuccessor());

                }

            {code}

             

            But it doesn't work anymore in MS3. Is there a (new)  recipe to do so?

             

            Many thanks,

             

            Niels

            • 3. Re: Versioning question
              rhauch

              What will happen, if I use the migration tool announced for 2.8.4? Will the uuids stay the same after migration?

              Currently I store uuids (of "real" nodes as well as of "versions") in our application database as a link to documents in modeshape. And I fear that those uuids will be useless afterwards.

               

              We shoud be able to keep the same UUIDs (e.g., "jcr:uuid") value. (At this point, I see no reason we won't be able to do this.)

               

               

              Niels Lippke wrote:

               

              In MS2 the following (maybe crude) logic works to get the "original" node for a given version node by searching its references.

               

              
              public static Node findFileNodebyVersion(Version v)
                          throws RepositoryException {
                      // if it is a version node find the base version
                      if (v == null) {
                          return null;
                      }
                      for (PropertyIterator it = v.getReferences(); it.hasNext();) {
                          Property p = (Property) it.next();
                          Node n = p.getParent();
                          if (n != null
                                  && (n.isNodeType(NT_RESOURCE) || n.isNodeType(NT_UNSTRUCTURED))) {
                              return n.getParent();
                          }
                      }
              
                      return findFileNodebyVersion(v.getLinearSuccessor());
                  }
              

               

               

              But it doesn't work anymore in MS3. Is there a (new)  recipe to do so?

               

              The "correct" way in both ModeShape 2 and 3 is to walk the version history using the JCR API (see Section 3.13 of the JSR-283 spec). You can get the version history via the "VersionManager.getVersionHistory(path)" and then use either getAllLinearVersions() or getAllVersions(), whichever suits your needs to find the version(s) you're looing for. (It sounds like you're looking for the "root version", which is really the first version added to the history when the node was first made versionable.)  You call also label specific versions (usually at the time of creation), so you can later find versions by a given label.

              • 4. Re: Versioning question
                nl

                My problem is the following:

                 

                User creates several version of a document (e.g.  "/files/test.doc"). References to those versions are stored in the application (outside modeshape) as jcr:uuids. Afterwards the user wants to delete the document incl. all versions. All I know is the stored uuid.

                I jump into modeshape and call session.getNodeByIdentifier(uuid), get a Version and I am stuck. I cannot call VersionManager.getVersionHistory() on the version node's path. So how do I know if this version belongs to "/files/test.doc"?

                 

                Thanks for any help, Niels

                • 5. Re: Versioning question
                  rhauch

                  Okay, so given a Version that you look up by UUID, you can call "getContainingHistory()" to obtain the VersionHistory that contains that Version. (If you want to get to the versionable node in the workspace for which the VersionHistory exists and for which the Version was one snapshot, simply call "getVersionableUUID()" on the VersionHistory.)

                  • 6. Re: Versioning question
                    nl

                    Oh, missed that in the API. Thank you so much !!!