Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2009 eXo Platform SAS.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.exoplatform.services.jcr.ext.repository;
 
 
 import java.util.List;
 
Created by The eXo Platform SAS.
Date: 27.08.2009

Author(s):
Alex Reshetnyak
Version:
$Id: NamesList.java 111 2008-11-11 11:11:11Z rainf0x $
 
 
 @Path("/jcr-service")
 public class RestRepositoryService implements ResourceContainer
 {

   
Definition the constants.
 
    public static final class Constants
    {

      
The base path to this service.
 
       public static final String BASE_URL = "/jcr-service";

      
Definition the operation types.
 
       public static final class OperationType
       {
         
Repository service configuration operation.
 
          public static final String REPOSITORY_SERVICE_CONFIGURATION = "/repository-service-configuration";

         
Default workspace configuration operations.
 
          public static final String DEFAULT_WS_CONFIG = "/default-ws-config";

         
Create new repository operations.
 
          public static final String CREATE_REPOSITORY = "/create-repository";

         
Create new workspace.
         public static final String CREATE_WORKSPACE = "/create-workspace";

         
Remove repository operation.
         public static final String REMOVE_REPOSITORY = "/remove-repository";

         
Remove workspace operation.
         public static final String REMOVE_WORKSPACE = "/remove-workspace";

         
The list of repositories name operations.
         public static final String REPOSITORIES_LIST = "/repositories";

         
The list of workspaces name operation.
         public static final String WORKSPACES_LIST = "/workspaces";

         
Update workspace configuration operation.
         public static final String UPDATE_WORKSPACE_CONFIG = "/update-workspace-config";

         
OperationType private constructor.
         private OperationType()
         {
         }
      }

      
Constants private constructor.
      private Constants()
      {
      }
   }

   
Class logger.
   private final Log log = ExoLogger.getLogger("exo.jcr.component.ext.RestRepositoryService");

   
   private final RepositoryService repositoryService;

   
To disable cache control.
   private static final CacheControl NO_CACHE = new CacheControl();
   static
   {
      // noCache = new CacheControl();
      .setNoCache(true);
      .setNoStore(true);
   }

   

Parameters:
repositoryService
   public RestRepositoryService(RepositoryService repositoryService)
   {
      this. = repositoryService;
   }

   

Returns:
Response return the Response with RepositoryServiceConf
   @GET
   @RolesAllowed("administrators")
   @Path("/repository-service-configuration")
   {
      RepositoryServiceConf conf =
         new RepositoryServiceConf(configuration.getRepositoryConfigurations(), configuration
            .getDefaultRepositoryName());
      return Response.ok(conf.).cacheControl().build();
   }

   

Parameters:
repositoryName String, the repository name
Returns:
Response return the Response with WorkspaceEntry
   @GET
   @RolesAllowed("administrators")
   @Path("/default-ws-config/{repositoryName}")
   public Response getDefaultWorkspaceConfig(@PathParam("repositoryName"String repositoryName)
   {
      String errorMessage = new String();
      Status status;
      try
      {
         String defaultWorkspaceName =
            .getRepository(repositoryName).getConfiguration().getDefaultWorkspaceName();
         for (WorkspaceEntry wEntry : .getRepository(repositoryName).getConfiguration()
            .getWorkspaceEntries())
         {
            if (defaultWorkspaceName.equals(wEntry.getName()))
            {
               return Response.ok(wEntry).cacheControl().build();
            }
         }
         return Response.status(..).entity("Can not get default workspace configuration.").type(
            .).cacheControl().build();
      }
      catch (RepositoryException e)
      {
         if (.isDebugEnabled())
         {
            .error(e.getMessage(), e);
         }
         errorMessage = e.getMessage();
         status = .;
      }
      catch (Throwable e)
      {
         if (.isDebugEnabled())
         {
            .error(e.getMessage(), e);
         }
         errorMessage = e.getMessage();
         status = .;
      }
      return Response.status(status).entity(errorMessage).type(.).cacheControl()
         .build();
   }

   

Parameters:
uriInfo UriInfo, the uri location
newRepository RepositoryEntry, the RepositoryEntry to new repository
Returns:
Response return the Response
Throws:
java.net.URISyntaxException will be generated the URISyntaxException
   @POST
   @RolesAllowed("administrators")
   @Path("/create-repository")
   public Response createRepository(@Context UriInfo uriInfoRepositoryEntry newRepositorythrows URISyntaxException
   {
      String errorMessage = new String();
      Status status;
      try
      {
         .createRepository(newRepository);
         .getConfig().retain(); // save configuration to persistence (file or persister)
         return Response.ok().cacheControl().build();
      }
      catch (RepositoryException e)
      {
         if (.isDebugEnabled())
         {
            .error(e.getMessage(), e);
         }
         errorMessage = e.getMessage();
         status = .;
      }
      catch (RepositoryConfigurationException e)
      {
         if (.isDebugEnabled())
         {
            .error(e.getMessage(), e);
         }
         errorMessage = e.getMessage();
         status = .;
      }
      catch (Throwable e)
      {
         if (.isDebugEnabled())
         {
            .error(e.getMessage(), e);
         }
         errorMessage = e.getMessage();
         status = .;
      }
      return Response.status(status).entity(errorMessage).type(.).cacheControl()
         .build();
   }

   

Parameters:
uriInfo UriInfo, the uri location
repositoryName String, the repository name
newWorkspace WorkspaceEntry, the WorkspaceEntry to new repository
Returns:
Response return the Response
Throws:
java.net.URISyntaxException will be generated the URISyntaxException
   @POST
   @RolesAllowed("administrators")
   @Path("/create-workspace/{repositoryName}")
   public Response createWorkspace(@Context UriInfo uriInfo, @PathParam("repositoryName"String repositoryName,
      WorkspaceEntry newWorkspacethrows URISyntaxException
   {
      String errorMessage = new String();
      Status status;
      try
      {
         RepositoryImpl repository = (RepositoryImpl).getRepository(repositoryName);
         repository.configWorkspace(newWorkspace);
         repository.createWorkspace(newWorkspace.getName());
         .getConfig().retain(); // save configuration to persistence (file or persister)
         return Response.ok().cacheControl().build();
      }
      catch (RepositoryException e)
      {
         if (.isDebugEnabled())
         {
            .error(e.getMessage(), e);
         }
         errorMessage = e.getMessage();
         status = .;
      }
      catch (RepositoryConfigurationException e)
      {
         if (.isDebugEnabled())
         {
            .error(e.getMessage(), e);
         }
         errorMessage = e.getMessage();
         status = .;
      }
      catch (Throwable e)
      {
         if (.isDebugEnabled())
         {
            .error(e.getMessage(), e);
         }
         errorMessage = e.getMessage();
         status = .;
      }
      return Response.status(status).entity(errorMessage).type(.).cacheControl()
         .build();
   }

   

Parameters:
uriInfo UriInfo, the uri location
repositoryName String, the repository name
forseSessionClose Boolean, flag to force session close
Returns:
Response return the Response
   @GET
   @RolesAllowed("administrators")
   @Path("/remove-repository/{repositoryName}/{forseSessionClose}")
   public Response removeRepository(@Context UriInfo uriInfo, @PathParam("repositoryName"String repositoryName,
      @PathParam("forseSessionClose"Boolean forseSessionClose)
   {
      String errorMessage = new String();
      Status status;
      try
      {
         if (forseSessionClose)
         {
            for (WorkspaceEntry wsEntry : .getConfig().getRepositoryConfiguration(repositoryName)
               .getWorkspaceEntries())
            {
               forceCloseSession(repositoryNamewsEntry.getName());
            }
         }
         if (.canRemoveRepository(repositoryName))
         {
            .removeRepository(repositoryName);
            .getConfig().retain(); // save configuration to persistence (file or persister) 
            return Response.ok().build();
         }
         return Response.status(.).entity("Can't remove repository " + repositoryName)
            .cacheControl().build();
      }
      catch (RepositoryException e)
      {
         if (.isDebugEnabled())
         {
            .error(e.getMessage(), e);
         }
         errorMessage = e.getMessage();
         status = .;
      }
      catch (Throwable e)
      {
         if (.isDebugEnabled())
         {
            .error(e.getMessage(), e);
         }
         errorMessage = e.getMessage();
         status = .;
      }
      return Response.status(status).entity(errorMessage).type(.).cacheControl()
         .build();
   }

   

Parameters:
uriInfo UriInfo, the uri location
repositoryName String, the repository name
workspaceName String, the workspace name
forseSessionClose Boolean, flag to force session close
Returns:
Response return the Response
   @POST
   @RolesAllowed("administrators")
   @Path("/remove-workspace/{repositoryName}/{workspaceName}/{forseSessionClose}/")
   public Response removeWorkspace(@Context UriInfo uriInfo, @PathParam("repositoryName"String repositoryName,
      @PathParam("workspaceName"String workspaceName, @PathParam("forseSessionClose"Boolean forseSessionClose)
   {
      String errorMessage = new String();
      Status status;
      try
      {
         ManageableRepository repository = .getRepository(repositoryName);
         if (forseSessionClose)
         {
            forceCloseSession(repositoryNameworkspaceName);
         }
         if (repository.canRemoveWorkspace(workspaceName))
         {
            repository.removeWorkspace(workspaceName);
            .getConfig().retain(); // save configuration to persistence (file or persister)
            return Response.ok().build();
         }
         return Response.status(.).entity(
            "Can't remove workspace " + workspaceName + " in repository " + repositoryName).cacheControl()
            .build();
      }
      catch (RepositoryException e)
      {
         if (.isDebugEnabled())
         {
            .error(e.getMessage(), e);
         }
         errorMessage = e.getMessage();
         status = .;
      }
      catch (RepositoryConfigurationException e)
      {
         if (.isDebugEnabled())
         {
            .error(e.getMessage(), e);
         }
         errorMessage = e.getMessage();
         status = .;
      }
      catch (Throwable e)
      {
         if (.isDebugEnabled())
         {
            .error(e.getMessage(), e);
         }
         errorMessage = e.getMessage();
         status = .;
      }
      return Response.status(status).entity(errorMessage).type(.).cacheControl()
         .build();
   }

   

Returns:
Response return the Response with list of repository names
   @GET
   @RolesAllowed("administrators")
   @Path("/repositories")
   {
      List<Stringrepositories = new ArrayList<String>();
      {
         repositories.add(rEntry.getName());
      }
      return Response.ok(new NamesList(repositories)).cacheControl().build();
   }

   

Parameters:
repositoryName String, the repository name
Returns:
Response return the Response with list of workspace names
   @GET
   @RolesAllowed("administrators")
   @Path("/workspaces/{repositoryName}")
   public Response getWorkspaceNames(@PathParam("repositoryName"String repositoryName)
   {
      String errorMessage = new String();
      Status status;
      try
      {
         List<Stringworkspaces = new ArrayList<String>();
         for (WorkspaceEntry wEntry : .getRepository(repositoryName).getConfiguration()
            .getWorkspaceEntries())
         {
            workspaces.add(wEntry.getName());
         }
         return Response.ok(new NamesList(workspaces)).cacheControl().build();
      }
      catch (RepositoryException e)
      {
         if (.isDebugEnabled())
         {
            .error(e.getMessage(), e);
         }
         errorMessage = e.getMessage();
         status = .;
      }
      catch (Throwable e)
      {
         if (.isDebugEnabled())
         {
            .error(e.getMessage(), e);
         }
         errorMessage = e.getMessage();
         status = .;
      }
      return Response.status(status).entity(errorMessage).type(.).cacheControl()
         .build();
   }

   
*

Parameters:
repositoryName String, the repository name
workspaceName String, the workspace name
workspaceEntry WorkspaceEntry, the confg to workspace
Returns:
Response return the Response
   @POST
   @RolesAllowed("administrators")
   @Path("/update-workspace-config/{repositoryName}/{workspaceName}")
   public Response updateWorkspaceConfiguration(@PathParam("repositoryName"String repositoryName,
      @PathParam("workspaceName"String workspaceNameWorkspaceEntry workspaceEntry)
   {
      return Response.status(.).entity("The method /update-workspace-config not implemented.").type(
   }

   
forceCloseSession. Close sessions on specific workspace.

Parameters:
repositoryName repository name
workspaceName workspace name
Returns:
int return the how many sessions was closed
Throws:
org.exoplatform.services.jcr.config.RepositoryConfigurationException will be generate RepositoryConfigurationException
javax.jcr.RepositoryException will be generate RepositoryException
   private int forceCloseSession(String repositoryNameString workspaceNamethrows RepositoryException,
   {
      ManageableRepository mr = .getRepository(repositoryName);
      WorkspaceContainerFacade wc = mr.getWorkspaceContainer(workspaceName);
      SessionRegistry sessionRegistry = (SessionRegistry)wc.getComponent(SessionRegistry.class);
      return sessionRegistry.closeSessions(workspaceName);
   }
New to GrepCode? Check out our FAQ X