4 Replies Latest reply on Nov 26, 2009 3:55 PM by rhauch

    Capturing sidecar meta-data


      Hello all
      I am trying to use DNA to have a JCR interface to a filesystem.
      The meta-data is stored in a sidecar file in the system i.e. file.pdf has its meta-data stored in file.pdf.properties.
      Is it possible with DNA to capture the sidecar meta-data file with some customizations ?
      Can I customize the existing DNA version FileSystem connector to achieve this ? As it is not possible to add data to jcr:content node, I thought of adding the jcr:content through customized filesystem connector.
      And lastly by when can we excpect DNA version 1 ?

      Thanking you in anticipation.

        • 1. Re: Capturing sidecar meta-data
          rhauch

          Yes, this is a great use case. It certainly is possible to customize the file system connector (by subclassing and creating your own connector) to expose additional properties on the nt:folder, nt:file, nt:resource objects.

          I do wish the existing classes made it easier to add custom properties, so I'll probably make some changes today in trunk so that it's easier to do this (see https://jira.jboss.org/jira/browse/DNA-553). This would then be included in the next release (0.7), which should happen in the next few weeks. (Trunk is actually pretty stable at the moment, as most of the changes apply to new features that aren't yet integrated, like query/search and observation).

          The plan is to release 1.0 within a few weeks after 0.7, so mid-December.

          • 2. Re: Capturing sidecar meta-data
            rhauch

            I just committed the changes for DNA-553, so that it is much easier to define how non-standard properties can be made to appear on nt:folder, nt:file, and nt:resource nodes. By default, the file system connector behaves as it has in the past: it only uses the standard properties defined by JCR for files, folders and content nodes.

            There is a new CustomPropertiesFactory interface that defines several methods for getting and setting custom properties. Simply implement this interface, and call FileSystemSource.setCustomPropertiesFactory(...) with an instance of your implementation. (Or, optionally subclass FileSystemSource, set the factory in the subclass' constructor, and inherit all other functionality).

            The connector uses this factory whenever it reads 'nt:folder', 'nt:file', or 'nt:resource' nodes, and includes in these nodes the properties returned by the factory. The factory methods take several arguments, including the ExecutionContext (which can be used to obtain the PropertyFactory, value factories used to create property values, and even the MIME type detector), the java.io.File object, the Location (which includes the path), and other information. Hopefully this is sufficient to construct the necessary custom properties.

            Please let me know if this helps with your use case.

            • 3. Re: Capturing sidecar meta-data

              Thanks a lot for the changes. I am eagerly waiting for 0.7 to test the changes :-)

              My use case scenario is like this:
              I have 2 files in the repository i.e. "bigredstripe.gif" having binary data and
              "bigredstripe.desc" <meta data> containing metadata of "bigredstripe.gif"
              I need to consolidate the data of ".desc" with main file while reading the data from repository.

              bigredstripe.gif
              -jcr:created = "2001-05-03T00:00:00.000Z"
              -jcr:content
              --myapp:image = <binary data>
              bigredstripe.desc
              --myapp:desc = "An excellent example"

              TO

              bigredstripe.gif
              -jcr:created = "2001-05-03T00:00:00.000Z"
              -jcr:content
              --myapp:image = <binary data>
              --myapp:desc = "An excellent example"
              This scenarion is described in JSR-170-1.0 Spec. Chapter-5 pages 41-42.

              1- Can I implement this use case with JBossDNA with my custom conenctor ?
              2- When should I parse the sidecar file holding metadata and add its content to the main file ?
              i.e. At what time does DNA reads a file from repository i.e. "bigredstripe.gif" so that I can extend and make it parse "bigredstripe.desc" and add its content as metadata.

              Thanks.

              • 4. Re: Capturing sidecar meta-data
                rhauch

                1) Yes, this use case can indeed be solved with the FileSystemConnector. And the recent enhancement to the file system connector make this a lot easier to do. Just set up a FileSystemSource instance (pointing to the area of the file system that should be exposed), and then call "setCustomPropertiesFactory(...)" with your custom implementation of the CustomPropertiesFactory (see below).

                The connector represents files using the JCR convention: directories are represented as "nt:folder" nodes; files are represented as "nt:file" nodes; and the content of a file is represented as child of type "nt:resource" and named "jcr:content". The separation of the node representing the file from the node representing the file's content is beneficial, because it allows accessing the 'file' node and it's file metadata (as properties on the node) without having to load the content. So, for example, a UI widget that shows the structure of the file system as a tree can show the structure without having to load the content of any of the files.

                We designed the CustomPropertiesFactory interface to have separate methods for each of the three types of nodes. So here's the answer to your second question:

                2) If you want the metadata in the '.desc' file to be properties on the "nt:file" node, then you should read the '.desc' file in the CustomPropertiesFactory.getFileProperties(...). However, if you would rather the metadata in the '.desc' file be represented as properties on the file's "jcr:content" child node (of type "nt:resource"), you should read the '.desc' file in the CustomPropertiesFactory.getResourceProperties(...). Of course, if some properties go on the "nt:file" node and others go on the "jcr:content" child node, you'd probably read the file in each of the methods. (Of course, you could get more sophisticated and cache the contents of the '.desc' files to save a read, but I'd only do that once you know that becomes a bottleneck.)