diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/BrowserStreamingOutput.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/BrowserStreamingOutput.java index c9f9f5f680..5b2dcfa50b 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/BrowserStreamingOutput.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/BrowserStreamingOutput.java @@ -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; } diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/DiffStreamingOutput.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/DiffStreamingOutput.java index a8f7c93ef4..ad55889c0d 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/DiffStreamingOutput.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/DiffStreamingOutput.java @@ -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 ------------------------------------------------------------ @@ -66,19 +66,14 @@ public class DiffStreamingOutput implements StreamingOutput //~--- constructors --------------------------------------------------------- /** - * Constructs ... + * 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; } diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java index 8880bc6a70..ca577885a9 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java @@ -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 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,37 +668,37 @@ public class RepositoryResource { Response response = null; StreamingOutput output = null; - Repository repository = repositoryManager.get(id); - if (repository != null) + try { - try + RepositoryService service = servicefactory.create(id); + CatCommandBuilder builder = service.getCatCommand(); + + if (!Strings.isNullOrEmpty(revision)) { - RepositoryBrowser browser = - repositoryManager.getRepositoryBrowser(repository); - - if (browser != null) - { - output = new BrowserStreamingOutput(browser, revision, path); - - String contentDispositionName = - getContentDispositionNameFromPath(path); - - response = Response.ok(output).header("Content-Disposition", - contentDispositionName).build(); - } - else if (logger.isWarnEnabled()) - { - logger.warn("could not find repository browser for respository {}", - repository.getId()); - response = Response.status(Response.Status.NOT_FOUND).build(); - } - } - catch (Exception ex) - { - logger.error("could not retrive content", ex); - response = createErrorResonse(ex); + builder.setRevision(revision); } + + output = new BrowserStreamingOutput(builder, path); + + String contentDispositionName = getContentDispositionNameFromPath(path); + + response = Response.ok(output).header("Content-Disposition", + contentDispositionName).build(); + } + catch (RepositoryNotFoundException ex) + { + 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); - - if (diffViewer != null) - { - String name = - repository.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(); - } + builder.setRevision(revision); } + + if (!Strings.isNullOrEmpty(path)) + { + builder.setPath(path); + } + + String name = service.getRepository().getName().concat("-").concat( + revision).concat(".diff"); + String contentDispositionName = getContentDispositionName(name); + + 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 securityContextProvider; + + /** Field description */ + private RepositoryServiceFactory servicefactory; }