mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 00:15:44 +01:00
Added optional revision path param to SourceRootResource#getAll
This commit is contained in:
@@ -1,11 +1,7 @@
|
|||||||
package sonia.scm.api.v2.resources;
|
package sonia.scm.api.v2.resources;
|
||||||
|
|
||||||
import de.otto.edison.hal.Links;
|
import de.otto.edison.hal.Links;
|
||||||
import org.mapstruct.AfterMapping;
|
import org.mapstruct.*;
|
||||||
import org.mapstruct.Context;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.Mapping;
|
|
||||||
import org.mapstruct.MappingTarget;
|
|
||||||
import sonia.scm.repository.Branch;
|
import sonia.scm.repository.Branch;
|
||||||
import sonia.scm.repository.NamespaceAndName;
|
import sonia.scm.repository.NamespaceAndName;
|
||||||
|
|
||||||
@@ -29,7 +25,7 @@ public abstract class BranchToBranchDtoMapper {
|
|||||||
.self(resourceLinks.branch().self(namespaceAndName, target.getName()))
|
.self(resourceLinks.branch().self(namespaceAndName, target.getName()))
|
||||||
.single(linkBuilder("history", resourceLinks.branch().history(namespaceAndName, target.getName())).build())
|
.single(linkBuilder("history", resourceLinks.branch().history(namespaceAndName, target.getName())).build())
|
||||||
.single(linkBuilder("changeset", resourceLinks.changeset().changeset(namespaceAndName.getNamespace(), namespaceAndName.getName(), target.getRevision())).build())
|
.single(linkBuilder("changeset", resourceLinks.changeset().changeset(namespaceAndName.getNamespace(), namespaceAndName.getName(), target.getRevision())).build())
|
||||||
.single(linkBuilder("source", resourceLinks.source().source(namespaceAndName.getNamespace(), namespaceAndName.getName(), target.getRevision())).build());
|
.single(linkBuilder("source", resourceLinks.source().self(namespaceAndName.getNamespace(), namespaceAndName.getName(), target.getRevision())).build());
|
||||||
target.add(linksBuilder.build());
|
target.add(linksBuilder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,6 @@ public abstract class FileObjectMapper extends BaseMapper<FileObject, FileObject
|
|||||||
|
|
||||||
@AfterMapping
|
@AfterMapping
|
||||||
void addLinks(FileObject fileObject, @MappingTarget FileObjectDto dto, @Context NamespaceAndName namespaceAndName, @Context String revision) {
|
void addLinks(FileObject fileObject, @MappingTarget FileObjectDto dto, @Context NamespaceAndName namespaceAndName, @Context String revision) {
|
||||||
dto.add(Links.linkingTo().self(resourceLinks.source().withPath(namespaceAndName.getNamespace(), namespaceAndName.getName(), revision, fileObject.getName())).build());
|
dto.add(Links.linkingTo().self(resourceLinks.source().sourceWithPath(namespaceAndName.getNamespace(), namespaceAndName.getName(), revision, fileObject.getName())).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public abstract class RepositoryToRepositoryDtoMapper extends BaseMapper<Reposit
|
|||||||
linksBuilder.single(link("tags", resourceLinks.tagCollection().self(target.getNamespace(), target.getName())));
|
linksBuilder.single(link("tags", resourceLinks.tagCollection().self(target.getNamespace(), target.getName())));
|
||||||
linksBuilder.single(link("branches", resourceLinks.branchCollection().self(target.getNamespace(), target.getName())));
|
linksBuilder.single(link("branches", resourceLinks.branchCollection().self(target.getNamespace(), target.getName())));
|
||||||
linksBuilder.single(link("changesets", resourceLinks.changeset().self(target.getNamespace(), target.getName())));
|
linksBuilder.single(link("changesets", resourceLinks.changeset().self(target.getNamespace(), target.getName())));
|
||||||
linksBuilder.single(link("sources", resourceLinks.source().withoutRevision(target.getNamespace(), target.getName())));
|
linksBuilder.single(link("sources", resourceLinks.source().selfWithoutRevision(target.getNamespace(), target.getName())));
|
||||||
target.add(linksBuilder.build());
|
target.add(linksBuilder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -291,18 +291,18 @@ class ResourceLinks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String self(String namespace, String name, String revision) {
|
String self(String namespace, String name, String revision) {
|
||||||
return sourceLinkBuilder.method("getRepositoryResource").parameters(namespace, name, revision).method("sources").parameters().method("getAll").parameters().href();
|
return sourceLinkBuilder.method("getRepositoryResource").parameters(namespace, name, revision).method("sources").parameters().method("getAll").parameters("").href();
|
||||||
}
|
}
|
||||||
|
|
||||||
String withoutRevision(String namespace, String name) {
|
String selfWithoutRevision(String namespace, String name) {
|
||||||
return sourceLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("sources").parameters().method("getAll").parameters().href();
|
return sourceLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("sources").parameters().method("getAll").parameters("").href();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String source(String namespace, String name, String revision) {
|
public String source(String namespace, String name, String revision) {
|
||||||
return sourceLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("sources").parameters().method("get").parameters(revision).href();
|
return sourceLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("sources").parameters().method("get").parameters(revision).href();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String withPath(String namespace, String name, String revision, String path) {
|
public String sourceWithPath(String namespace, String name, String revision, String path) {
|
||||||
return sourceLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("sources").parameters().method("get").parameters(revision, path).href();
|
return sourceLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("sources").parameters().method("get").parameters(revision, path).href();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ public class SourceRootResource {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(VndMediaType.SOURCE)
|
@Produces(VndMediaType.SOURCE)
|
||||||
@Path("")
|
@Path("{revision : (\\w+)?}")
|
||||||
public Response getAll(@PathParam("namespace") String namespace, @PathParam("name") String name) {
|
public Response getAll(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("revision") String revision) {
|
||||||
|
|
||||||
BrowserResult browserResult;
|
BrowserResult browserResult;
|
||||||
Response response;
|
Response response;
|
||||||
@@ -40,6 +40,9 @@ public class SourceRootResource {
|
|||||||
try (RepositoryService repositoryService = serviceFactory.create(namespaceAndName)) {
|
try (RepositoryService repositoryService = serviceFactory.create(namespaceAndName)) {
|
||||||
BrowseCommandBuilder browseCommand = repositoryService.getBrowseCommand();
|
BrowseCommandBuilder browseCommand = repositoryService.getBrowseCommand();
|
||||||
browseCommand.setPath("/");
|
browseCommand.setPath("/");
|
||||||
|
if (revision != null && !revision.isEmpty()) {
|
||||||
|
browseCommand.setRevision(revision);
|
||||||
|
}
|
||||||
browserResult = browseCommand.getBrowserResult();
|
browserResult = browseCommand.getBrowserResult();
|
||||||
|
|
||||||
if (browserResult != null) {
|
if (browserResult != null) {
|
||||||
|
|||||||
@@ -135,8 +135,8 @@ public class ResourceLinksTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateCorrectBranchSourceUrl() {
|
public void shouldCreateCorrectBranchSourceUrl() {
|
||||||
String url = resourceLinks.source().source("space", "name", "revision");
|
String url = resourceLinks.source().selfWithoutRevision("space", "name");
|
||||||
assertEquals(BASE_URL + RepositoryRootResource.REPOSITORIES_PATH_V2 + "space/name/sources/revision", url);
|
assertEquals(BASE_URL + RepositoryRootResource.REPOSITORIES_PATH_V2 + "space/name/sources/", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -147,18 +147,18 @@ public class ResourceLinksTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateCorrectSourceCollectionUrl() {
|
public void shouldCreateCorrectSourceCollectionUrl() {
|
||||||
String url = resourceLinks.source().withoutRevision("space", "repo");
|
String url = resourceLinks.source().selfWithoutRevision("space", "repo");
|
||||||
assertEquals(BASE_URL + RepositoryRootResource.REPOSITORIES_PATH_V2 + "space/repo/sources/", url);
|
assertEquals(BASE_URL + RepositoryRootResource.REPOSITORIES_PATH_V2 + "space/repo/sources/", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateCorrectSourceUrlWithFilename() {
|
public void shouldCreateCorrectSourceUrlWithFilename() {
|
||||||
String url = resourceLinks.source().withPath("foo", "bar", "rev", "file");
|
String url = resourceLinks.source().sourceWithPath("foo", "bar", "rev", "file");
|
||||||
assertEquals(BASE_URL + RepositoryRootResource.REPOSITORIES_PATH_V2 + "foo/bar/sources/rev/file", url);
|
assertEquals(BASE_URL + RepositoryRootResource.REPOSITORIES_PATH_V2 + "foo/bar/sources/rev/file", url);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateCorrectPermissionCollectionUrl() {
|
public void shouldCreateCorrectPermissionCollectionUrl() {
|
||||||
String url = resourceLinks.source().withoutRevision("space", "repo");
|
String url = resourceLinks.source().selfWithoutRevision("space", "repo");
|
||||||
assertEquals(BASE_URL + RepositoryRootResource.REPOSITORIES_PATH_V2 + "space/repo/sources/", url);
|
assertEquals(BASE_URL + RepositoryRootResource.REPOSITORIES_PATH_V2 + "space/repo/sources/", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user