2 Replies Latest reply on Jan 17, 2014 3:09 AM by Aritz Maeztu

    Implementing a document repository. Federation or File System connector?

    Aritz Maeztu Newbie

      I'm just a beginner in Modeshape-JCR stuff. I did post a question for that at http://stackoverflow.com/questions/21017536/federating-the-file-system-results-in-child-not-found

       

      I've seen JCR features around repository content, which allow to full-search, versioning and annotations, apart from other much benefits. Ok, let's say we want to develop a kind of CMS (a very simple one), which will mainly store Microsoft Office files. We're interested in having that directories naturally named in the File System, for the developer to be more intuitive to see what's going on without the need of starting the ModeShape engine. Apart from that, we will also like to have a repository which stands all of this, to provide our repository the features Modeshape-JCR allows.

       

      Surfing into the web, I found a Modeshape Git repo which has some examples about how all of this works. I've also been looking though documentation for the last stable version (3.x branches). The examples show how to create a FS connector based repository (I think this want isn't what I need, since node names are taking hexadecimal values) and also to federate an existing File System. For my needs, I understand that federation is what I need, however Federation is defined by yourselves as a kind of ability  to mix different connectors at the same repo, however I only want a repo which will persist the documents. So don't understand why I could not just use the FS connector!

       

      Finally, I couldn't make federation example work out of the test case. The example is nice, but I would like to try it out with some absolute path. This is the test case I tried and already posted in StackOverflow:

       

      {
          "name" : "Test Repository",
          "jndiName" : "jcr/Test Repository",
          "monitoring" : {
              "enabled" : true
          },
      
          "externalSources" : {
              "files" : {
                 "classname" : "org.modeshape.connector.filesystem.FileSystemConnector",
                 "directoryPath" : "C:/modeshape-repo",
                 "projections" : [ "default:/files/ => /" ]
              }
          }
      }
      
      @Test
      public void modeShapeFederating() throws LoginException,
              RepositoryException, IOException, URISyntaxException {
          File testDir = new File("C:/modeshape-repo");
          Assert.assertTrue(testDir.exists() && testDir.isDirectory());
          URL myTestURL = ClassLoader.getSystemResource("my_repository.json");
          File configFile = new File(myTestURL.toURI());
          Assert.assertTrue(configFile.exists());
          ModeShapeEngine engine = new ModeShapeEngine();
          engine.start();
          RepositoryConfiguration config = RepositoryConfiguration
                  .read(configFile);
          Repository repository = engine.deploy(config);
          System.out.println(engine.getState());
          Session session = repository.login(); //Here is where the execution breaks
          try {
              Node filesNode = session.getRootNode().getNode("files");
              Assert.assertTrue(filesNode.getNodes().getSize() > 0);
          } finally {
              session.logout();
          }
      }
      

       

      I would be very grateful if anybody can help me with this.

       

      Yours, Aritz

        • 1. Re: Implementing a document repository. Federation or File System connector?
          Randall Hauch Master

          A repository must have its own storage system, mainly to store configuration, metadata, and system content.

           

          The other thing to be aware of is that the file system connector is really only able to store "nt:file", "nt:folder" and "nt:resource" nodes - and really what it is doing is projecting/exposing as nodes in the repository the actual files and folders on the filesystem. That's the primary purpose of this connector. One example shows how that is done is at modeshape-examples/modeshape-federation; btw, I can successfully run this example even when I change the directoryPath configuration property (this line in the configuration file) to an absolute path of an existing directory (e.g., the path of the "target/files" directory in my local git clone, namely "/Users/jsmith/path/to/modeshape-examples/modeshape-federation-example/target/files"). Be aware this referenced directory must exist and be readable by the Java process.

           

          We're interested in having that directories naturally named in the File System, for the developer to be more intuitive to see what's going on...

          To my knowledge there is no JCR implementation that stores every node as a separate file in a directory structure that mirrors the node hierarchy.

          • 2. Re: Implementing a document repository. Federation or File System connector?
            Aritz Maeztu Newbie

            Hi Randall,

             

            Fist of all, thanks for your response. I finally achieved to configure the federation example in order to work with my own directory at the file system. It seems to be creating a sidecar file (with .modeshape.json extension) as it does in the example project, so that's great. I also created and deleted some nodes in order to test it's properly working.

             

            That's my current configuration just for completeness:

             

            {

                "name" : "Federated Repository",

                "workspaces" : {

                    "predefined" : ["otherWorkspace"],

                    "default" : "default",

                    "allowCreation" : true

                },

                "security" : {

                    "anonymous" : {

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

                        "useOnFailedLogin" : false

                    }

                },

                "storage" : {

                    "cacheConfiguration" : "infinispan-configuration.xml",

                    "cacheName" : "persistentRepository",

                    "binaryStorage" : {

                        "type" : "file",

                        "directory": "C:/modeshape-repo/binaries",

                        "minimumBinarySizeInBytes" : 999

                    }

                },

                "externalSources" : {

                    "target-fs" : {

                        "classname" : "filesystem",

                        "directoryPath" : "C:/modeshape-repo",

                        "extraPropertiesStorage" : "json",

                        "cacheTtlSeconds" : 1,

                        "projections" : [

                            "default:/rootFolder => /"

                        ]

                    }

                } ,

                "node-types" : ["any-properties.cnd"]

            }