use new repository service api for repository rest resource

This commit is contained in:
Sebastian Sdorra
2012-06-16 14:12:58 +02:00
parent c5789e8691
commit 8d6d7d1b44
3 changed files with 120 additions and 110 deletions

View File

@@ -39,9 +39,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.repository.PathNotFoundException;
import sonia.scm.repository.RepositoryBrowser;
import sonia.scm.repository.RepositoryException;
import sonia.scm.repository.RevisionNotFoundException;
import sonia.scm.repository.api.CatCommandBuilder;
//~--- JDK imports ------------------------------------------------------------
@@ -71,13 +71,13 @@ public class BrowserStreamingOutput implements StreamingOutput
*
* @param browser
* @param revision
*
* @param builder
* @param path
*/
public BrowserStreamingOutput(RepositoryBrowser browser, String revision,
String path)
public BrowserStreamingOutput(CatCommandBuilder builder, String path)
{
this.browser = browser;
this.revision = revision;
this.builder = builder;
this.path = path;
}
@@ -98,7 +98,7 @@ public class BrowserStreamingOutput implements StreamingOutput
{
try
{
browser.getContent(revision, path, output);
builder.retriveContent(output, path);
}
catch (PathNotFoundException ex)
{
@@ -130,11 +130,8 @@ public class BrowserStreamingOutput implements StreamingOutput
//~--- fields ---------------------------------------------------------------
/** Field description */
private RepositoryBrowser browser;
private CatCommandBuilder builder;
/** Field description */
private String path;
/** Field description */
private String revision;
}

View File

@@ -38,10 +38,10 @@ package sonia.scm.api.rest.resources;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.repository.DiffViewer;
import sonia.scm.repository.PathNotFoundException;
import sonia.scm.repository.RepositoryException;
import sonia.scm.repository.RevisionNotFoundException;
import sonia.scm.repository.api.DiffCommandBuilder;
//~--- JDK imports ------------------------------------------------------------
@@ -69,16 +69,11 @@ public class DiffStreamingOutput implements StreamingOutput
* Constructs ...
*
*
* @param diffViewer
* @param revision
* @param path
* @param builder
*/
public DiffStreamingOutput(DiffViewer diffViewer, String revision,
String path)
public DiffStreamingOutput(DiffCommandBuilder builder)
{
this.diffViewer = diffViewer;
this.revision = revision;
this.path = path;
this.builder = builder;
}
//~--- methods --------------------------------------------------------------
@@ -98,7 +93,7 @@ public class DiffStreamingOutput implements StreamingOutput
{
try
{
diffViewer.getDiff(revision, path, output);
builder.retriveContent(output);
}
catch (PathNotFoundException ex)
{
@@ -130,11 +125,5 @@ public class DiffStreamingOutput implements StreamingOutput
//~--- fields ---------------------------------------------------------------
/** Field description */
private DiffViewer diffViewer;
/** Field description */
private String path;
/** Field description */
private String revision;
private DiffCommandBuilder builder;
}

View File

@@ -35,6 +35,7 @@ package sonia.scm.api.rest.resources;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Strings;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@@ -45,30 +46,30 @@ import org.codehaus.enunciate.modules.jersey.ExternallyManagedLifecycle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.NotSupportedFeatuerException;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.repository.BlameResult;
import sonia.scm.repository.BlameViewerUtil;
import sonia.scm.repository.BrowserResult;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.ChangesetPagingResult;
import sonia.scm.repository.ChangesetViewerUtil;
import sonia.scm.repository.DiffViewer;
import sonia.scm.repository.Permission;
import sonia.scm.repository.PermissionType;
import sonia.scm.repository.PermissionUtil;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryBrowser;
import sonia.scm.repository.RepositoryBrowserUtil;
import sonia.scm.repository.RepositoryException;
import sonia.scm.repository.RepositoryHandler;
import sonia.scm.repository.RepositoryIsNotArchivedException;
import sonia.scm.repository.RepositoryManager;
import sonia.scm.repository.RepositoryNotFoundException;
import sonia.scm.repository.RepositoryUtil;
import sonia.scm.repository.api.BlameCommandBuilder;
import sonia.scm.repository.api.BrowseCommandBuilder;
import sonia.scm.repository.api.CatCommandBuilder;
import sonia.scm.repository.api.CommandNotSupportedException;
import sonia.scm.repository.api.DiffCommandBuilder;
import sonia.scm.repository.api.LogCommandBuilder;
import sonia.scm.repository.api.RepositoryService;
import sonia.scm.repository.api.RepositoryServiceFactory;
import sonia.scm.security.ScmSecurityException;
import sonia.scm.util.AssertUtil;
import sonia.scm.util.HttpUtil;
import sonia.scm.util.Util;
import sonia.scm.web.security.WebSecurityContext;
@@ -125,6 +126,7 @@ public class RepositoryResource
* @param configuration
* @param repositoryManager
* @param securityContextProvider
* @param servicefactory
* @param changesetViewerUtil
* @param repositoryBrowserUtil
* @param blameViewerUtil
@@ -133,17 +135,13 @@ public class RepositoryResource
public RepositoryResource(
ScmConfiguration configuration, RepositoryManager repositoryManager,
Provider<WebSecurityContext> securityContextProvider,
ChangesetViewerUtil changesetViewerUtil,
RepositoryBrowserUtil repositoryBrowserUtil,
BlameViewerUtil blameViewerUtil)
RepositoryServiceFactory servicefactory)
{
super(repositoryManager);
this.configuration = configuration;
this.repositoryManager = repositoryManager;
this.servicefactory = servicefactory;
this.securityContextProvider = securityContextProvider;
this.changesetViewerUtil = changesetViewerUtil;
this.repositoryBrowserUtil = repositoryBrowserUtil;
this.blameViewerUtil = blameViewerUtil;
setDisableCache(false);
}
@@ -354,8 +352,15 @@ public class RepositoryResource
{
AssertUtil.assertIsNotNull(path);
BlameResult blamePagingResult = blameViewerUtil.getBlame(id, revision,
path);
RepositoryService service = servicefactory.create(id);
BlameCommandBuilder builder = service.getBlameCommand();
if (!Strings.isNullOrEmpty(revision))
{
builder.setRevision(revision);
}
BlameResult blamePagingResult = builder.getBlameResult(path);
if (blamePagingResult != null)
{
@@ -374,7 +379,7 @@ public class RepositoryResource
{
response = Response.status(Response.Status.NOT_FOUND).build();
}
catch (NotSupportedFeatuerException ex)
catch (CommandNotSupportedException ex)
{
response = Response.status(Response.Status.BAD_REQUEST).build();
}
@@ -416,8 +421,20 @@ public class RepositoryResource
try
{
BrowserResult result = repositoryBrowserUtil.getResult(id, revision,
path);
RepositoryService service = servicefactory.create(id);
BrowseCommandBuilder builder = service.getBrowseCommand();
if (!Strings.isNullOrEmpty(revision))
{
builder.setRevision(revision);
}
if (!Strings.isNullOrEmpty(path))
{
builder.setPath(path);
}
BrowserResult result = builder.getBrowserResult();
if (result != null)
{
@@ -432,7 +449,7 @@ public class RepositoryResource
{
response = Response.status(Response.Status.NOT_FOUND).build();
}
catch (NotSupportedFeatuerException ex)
catch (CommandNotSupportedException ex)
{
response = Response.status(Response.Status.BAD_REQUEST).build();
}
@@ -513,7 +530,8 @@ public class RepositoryResource
{
try
{
Changeset changeset = changesetViewerUtil.getChangeset(id, revision);
RepositoryService service = servicefactory.create(id);
Changeset changeset = service.getLogCommand().getChangeset(revision);
if (changeset != null)
{
@@ -528,7 +546,7 @@ public class RepositoryResource
{
response = Response.status(Response.Status.NOT_FOUND).build();
}
catch (NotSupportedFeatuerException ex)
catch (CommandNotSupportedException ex)
{
response = Response.status(Response.Status.BAD_REQUEST).build();
}
@@ -585,17 +603,22 @@ public class RepositoryResource
try
{
ChangesetPagingResult changesets = null;
RepositoryService service = servicefactory.create(id);
LogCommandBuilder builder = service.getLogCommand();
if (Util.isEmpty(path))
if (!Strings.isNullOrEmpty(path))
{
changesets = changesetViewerUtil.getChangesets(id, start, limit);
builder.setPath(path);
}
else
if (!Strings.isNullOrEmpty(revision))
{
changesets = changesetViewerUtil.getChangesets(id, path, revision,
start, limit);
builder.setStartChangeset(revision);
}
changesets =
builder.setPagingStart(start).setPagingLimit(limit).getChangesets();
if (changesets != null)
{
response = Response.ok(changesets).build();
@@ -609,7 +632,7 @@ public class RepositoryResource
{
response = Response.status(Response.Status.NOT_FOUND).build();
}
catch (NotSupportedFeatuerException ex)
catch (CommandNotSupportedException ex)
{
response = Response.status(Response.Status.BAD_REQUEST).build();
}
@@ -645,38 +668,38 @@ public class RepositoryResource
{
Response response = null;
StreamingOutput output = null;
Repository repository = repositoryManager.get(id);
if (repository != null)
{
try
{
RepositoryBrowser browser =
repositoryManager.getRepositoryBrowser(repository);
RepositoryService service = servicefactory.create(id);
CatCommandBuilder builder = service.getCatCommand();
if (browser != null)
if (!Strings.isNullOrEmpty(revision))
{
output = new BrowserStreamingOutput(browser, revision, path);
builder.setRevision(revision);
}
String contentDispositionName =
getContentDispositionNameFromPath(path);
output = new BrowserStreamingOutput(builder, path);
String contentDispositionName = getContentDispositionNameFromPath(path);
response = Response.ok(output).header("Content-Disposition",
contentDispositionName).build();
}
else if (logger.isWarnEnabled())
catch (RepositoryNotFoundException ex)
{
logger.warn("could not find repository browser for respository {}",
repository.getId());
logger.warn("could not find repository browser for respository {}", id);
response = Response.status(Response.Status.NOT_FOUND).build();
}
catch (CommandNotSupportedException ex)
{
response = Response.status(Response.Status.BAD_REQUEST).build();
}
catch (Exception ex)
{
logger.error("could not retrive content", ex);
response = createErrorResonse(ex);
}
}
return response;
}
@@ -718,32 +741,39 @@ public class RepositoryResource
try
{
Repository repository = repositoryManager.get(id);
RepositoryService service = servicefactory.create(id);
DiffCommandBuilder builder = service.getDiffCommand();
if (repository != null)
if (!Strings.isNullOrEmpty(revision))
{
DiffViewer diffViewer = repositoryManager.getDiffViewer(repository);
builder.setRevision(revision);
}
if (diffViewer != null)
if (!Strings.isNullOrEmpty(path))
{
String name =
repository.getName().concat("-").concat(revision).concat(".diff");
builder.setPath(path);
}
String name = service.getRepository().getName().concat("-").concat(
revision).concat(".diff");
String contentDispositionName = getContentDispositionName(name);
response = Response.ok(new DiffStreamingOutput(diffViewer, revision,
path)).header("Content-Disposition",
contentDispositionName).build();
}
else
{
response = Response.status(Response.Status.NOT_FOUND).build();
}
}
response = Response.ok(new DiffStreamingOutput(builder)).header(
"Content-Disposition", contentDispositionName).build();
}
catch (RepositoryNotFoundException ex)
{
response = Response.status(Response.Status.NOT_FOUND).build();
}
catch (CommandNotSupportedException ex)
{
response = Response.status(Response.Status.BAD_REQUEST).build();
}
catch (Exception ex)
{
logger.error("could not create diff", ex);
response = createErrorResonse(ex);
}
return response;
}
@@ -909,21 +939,15 @@ public class RepositoryResource
//~--- fields ---------------------------------------------------------------
/** Field description */
private BlameViewerUtil blameViewerUtil;
/** Field description */
private ChangesetViewerUtil changesetViewerUtil;
/** Field description */
private ScmConfiguration configuration;
/** Field description */
private RepositoryBrowserUtil repositoryBrowserUtil;
/** Field description */
private RepositoryManager repositoryManager;
/** Field description */
private Provider<WebSecurityContext> securityContextProvider;
/** Field description */
private RepositoryServiceFactory servicefactory;
}