4 Replies Latest reply on Apr 4, 2013 11:29 AM by mashtun

    FileSystemConnector and creating content in new nt:file nodes

    mashtun

      Using 3.1.3 Final I have a view of an external filesystem projected into a repository using FileSystemConnector.  If I create a new federated node with primary type nt:file and add content to it should I see a non-empty file created on disk in my external filesystem?

       

      This code :

       

            Node node = root.getNode("federated/foo").addNode("bar.xml", "nt:file");
            Node contentNode = node.addNode("jcr:content", "nt:resource");
            Binary binary = session.getValueFactory().createBinary(new ByteArrayInputStream(SOME_STRING_CONTAINING_XML.getBytes()));
            contentNode.setProperty("jcr:data", binary);
            session.save();
      

       

      creates an empty file foo/bar.xml at the correct location in the external filesystem.

       

      If I step through the code then in FileSystemConnector.store(Document) I never see the

       

                  } else if (isContentNode(id)) {
      

       

      branch (on line 513) taken.  It looks like this is because id at this point ends with "bar.xml/content" while isContentNode(id) tests for id ending with "/jcr:content".  The "jcr:" prefix has been removed at this point during writing (but is present when getNode("jcr:content") is called).  If I extend FileSystemConnector and override isContentNode(String) and fileFor(String) so they handle a suffix of "/content" as well as "/jcr:content" then I get the behaviour I expect i.e. a non-empty XML file with the correct content.

       

      I'm not sure if this is a misunderstanding as to how FileSystemConnector works, a bug in FileSystemConnector or, more likely given my newness to ModeShape/JCR, caused by something I'm doing wrong (perhaps related to the config described in Problem getting the binary value from a federated node).

       

      Help gratefully received!

        • 1. Re: FileSystemConnector and creating content in new nt:file nodes
          rhauch

          It looks like this is because id at this point ends with "bar.xml/content" while isContentNode(id) tests for id ending with "/jcr:content".  The "jcr:" prefix has been removed at this point during writing (but is present when getNode("jcr:content") is called).  If I extend FileSystemConnector and override isContentNode(String) and fileFor(String) so they handle a suffix of "/content" as well as "/jcr:content" then I get the behaviour I expect i.e. a non-empty XML file with the correct content.

          This is indeed strange. The ID should not have just "bar.xml/content", so this looks like a bug.

           

          Looking at the code, it looks like the ID is being written with only the local name (e.g., "content" without the prefix) on line 543. Please log a defect. IIRC, we're using only the local part because the IDs are translated into filenames, which generally shouldn't have a ":" character. At a minimum, we need to decide how we want to encode the node names into IDs, but we should probably handle "jcr:content" nodes in a special way in the "newDocumentId(..)" method. I think it's a bit too dangerous to change the "isContentNode(String)" method and "fileFor(String)" method to consider any ID ending in "content" as the file content node.

           

          Do you want to try this? If so, do you want to create a pull-request with the change??

          • 2. Re: FileSystemConnector and creating content in new nt:file nodes
            mashtun

            Thanks, Randall.  Your suggestion does indeed work.  I created MODE-1880 and linked it to a pull request.  I'm an infrequent github user but hopefully got the process right.

            • 3. Re: FileSystemConnector and creating content in new nt:file nodes
              rhauch

              You did everything perfectly. (UPDATE: Actually, see my comment on the pull-request: you should make your changes on a topic branch. It's okay this time.)

               

              Thanks! I'll merge the pull-request shortly.

              • 4. Re: FileSystemConnector and creating content in new nt:file nodes
                mashtun

                Thanks for the pointer to the workflow page - I'll certainly be sure to use a topic branch in future.