5 Replies Latest reply on Apr 15, 2010 9:23 AM by gregory sebert

    Using exo jcr as common data storage

    Morten Hauch Newbie

      Hi,

       

      We are going to base a new project on GateIn.

      It is important for us to be able to save all (business) data in a way that makes it searchable, versioned and exportable.

       

      All in all the obvious choice is jcr and - using GateIn - exo jcr.

       

      Can anybody give me some pointers on how to

      - setting up a repository for business data (or could/should I use the rep. configured in configuration.properties as gatein.jcr.data.xxx?)

      - obtaining a jcr Session to this repository in a portlet (or any other deployable artifact)

      ?

       

      Regards

      Morten

        • 1. Re: Using exo jcr as common data storage
          gregory sebert Newbie

          Hi,

           

          We are currently using the gatein JCR to store bussiness data from our portlet.

          This is some hints to do it:

           

          - For jcr configuration, we create a new workspace in the default repository (you can also create a new repository) to store data.

          The config file for jcr is repository-configuration.xml file located in gatein.ear/02portal.war/web-inf/conf/jcr.

          Just take a existing workspace as template to create a new one.

           

          - To access to the JCR from your portlet :

           

          import javax.jcr.RepositoryException;
          import javax.jcr.Session;

           

          import org.exoplatform.services.jcr.core.ManageableRepository;
          import org.exoplatform.container.ExoContainer;
          import org.exoplatform.container.ExoContainerContext;
          import org.exoplatform.services.jcr.RepositoryService;
          import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
          import org.exoplatform.services.jcr.ext.app.SessionProviderService;

           


          public class testJCRConnection {
              /** WORK_SPACE_NAME */
              private static final String WORK_SPACE_NAME = "myworkspace";

           

              /** repositoryService */
              private RepositoryService    repositoryService;

           


              /** repository */
              private ManageableRepository repository;

           


              /** session */
              private Session session;
             
              /** session provider*/
              private  SessionProviderService   sessionProviderService ;

           


              public void connectRepository(String repositoryName)
                {

              try {

           

              ExoContainer container = new ExoContainer();
              container = ExoContainerContext.getCurrentContainer();
                  
              repositoryService = (RepositoryService) container
                        .getComponentInstanceOfType(RepositoryService.class);
                     
              repository = repositoryService.getRepository(repositoryName);
             
              sessionProviderService = (SessionProviderService) container
               .getComponentInstanceOfType(SessionProviderService.class);
             
              session = sessionProviderService.getSessionProvider(null).getSession(
                      WORK_SPACE_NAME, repository);
             
              //Do your JCR JOB

           

              } catch (RepositoryException e) {
                          e.printStackTrace();

           

              } catch (RepositoryConfigurationException e) {
                          e.printStackTrace();
              } finally {
                    if (session != null)
                        session.logout();
              }
              }

          }

           

           

           

          Regards,

          Grégory

          • 2. Re: Using exo jcr as common data storage
            Chris Laprun Master

            You could also look into Chromattic to help with dealing with JCR: http://code.google.com/p/chromattic/

            • 3. Re: Using exo jcr as common data storage
              Morten Hauch Newbie

              Thanks a lot. This was very helpfull.

               

              Unfortunately I am unable to get a SessionProvider using:

               

              session = sessionProviderService.getSessionProvider(null);

               

              I guess the reason might be that the repository is secured - and the gateIn user is not propagated to this context (and in my understanding the method above uses current user (null)).

               

              So my next question is:

              How can I get my gateIn/JAAS user propagated to the exo jcr context?

               

              Any help is appreciated.

               

              /Morten

              • 4. Re: Using exo jcr as common data storage
                Morten Hauch Newbie

                This did it:

                 

                        SessionProvider sp = new SessionProvider(ConversationState.getCurrent());
                • 5. Re: Using exo jcr as common data storage
                  gregory sebert Newbie

                  Yes, sorry for the mistake in the sample code.