mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 17:26:22 +01:00
Add requested revision to browse result
This commit is contained in:
@@ -53,13 +53,19 @@ import java.io.Serializable;
|
|||||||
public class BrowserResult implements Serializable {
|
public class BrowserResult implements Serializable {
|
||||||
|
|
||||||
private String revision;
|
private String revision;
|
||||||
|
private String requestedRevision;
|
||||||
private FileObject file;
|
private FileObject file;
|
||||||
|
|
||||||
public BrowserResult() {
|
public BrowserResult() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public BrowserResult(String revision, FileObject file) {
|
public BrowserResult(String revision, FileObject file) {
|
||||||
|
this(revision, revision, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BrowserResult(String revision, String requestedRevision, FileObject file) {
|
||||||
this.revision = revision;
|
this.revision = revision;
|
||||||
|
this.requestedRevision = requestedRevision;
|
||||||
this.file = file;
|
this.file = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +73,10 @@ public class BrowserResult implements Serializable {
|
|||||||
return revision;
|
return revision;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRequestedRevision() {
|
||||||
|
return requestedRevision;
|
||||||
|
}
|
||||||
|
|
||||||
public FileObject getFile() {
|
public FileObject getFile() {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ public class GitBrowseCommand extends AbstractGitCommand
|
|||||||
|
|
||||||
if (revId != null)
|
if (revId != null)
|
||||||
{
|
{
|
||||||
result = new BrowserResult(revId.getName(), getEntry(repo, request, revId));
|
result = new BrowserResult(revId.getName(), request.getRevision(), getEntry(repo, request, revId));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -138,7 +138,7 @@ public class GitBrowseCommand extends AbstractGitCommand
|
|||||||
logger.warn("could not find head of repository, empty?");
|
logger.warn("could not find head of repository, empty?");
|
||||||
}
|
}
|
||||||
|
|
||||||
result = new BrowserResult(Constants.HEAD, createEmtpyRoot());
|
result = new BrowserResult(Constants.HEAD, request.getRevision(), createEmtpyRoot());
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class BrowserResultToFileObjectDtoMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FileObjectDto map(BrowserResult browserResult, NamespaceAndName namespaceAndName) {
|
public FileObjectDto map(BrowserResult browserResult, NamespaceAndName namespaceAndName) {
|
||||||
FileObjectDto fileObjectDto = fileObjectToFileObjectDtoMapper.map(browserResult.getFile(), namespaceAndName, browserResult.getRevision());
|
FileObjectDto fileObjectDto = fileObjectToFileObjectDtoMapper.map(browserResult.getFile(), namespaceAndName, browserResult);
|
||||||
fileObjectDto.setRevision( browserResult.getRevision() );
|
fileObjectDto.setRevision( browserResult.getRevision() );
|
||||||
return fileObjectDto;
|
return fileObjectDto;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.mapstruct.Context;
|
|||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.Mapping;
|
import org.mapstruct.Mapping;
|
||||||
import org.mapstruct.ObjectFactory;
|
import org.mapstruct.ObjectFactory;
|
||||||
|
import sonia.scm.repository.BrowserResult;
|
||||||
import sonia.scm.repository.FileObject;
|
import sonia.scm.repository.FileObject;
|
||||||
import sonia.scm.repository.NamespaceAndName;
|
import sonia.scm.repository.NamespaceAndName;
|
||||||
import sonia.scm.repository.SubRepository;
|
import sonia.scm.repository.SubRepository;
|
||||||
@@ -22,23 +23,23 @@ public abstract class FileObjectToFileObjectDtoMapper extends HalAppenderMapper
|
|||||||
private ResourceLinks resourceLinks;
|
private ResourceLinks resourceLinks;
|
||||||
|
|
||||||
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
|
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
|
||||||
protected abstract FileObjectDto map(FileObject fileObject, @Context NamespaceAndName namespaceAndName, @Context String revision);
|
protected abstract FileObjectDto map(FileObject fileObject, @Context NamespaceAndName namespaceAndName, @Context BrowserResult browserResult);
|
||||||
|
|
||||||
abstract SubRepositoryDto mapSubrepository(SubRepository subRepository);
|
abstract SubRepositoryDto mapSubrepository(SubRepository subRepository);
|
||||||
|
|
||||||
@ObjectFactory
|
@ObjectFactory
|
||||||
FileObjectDto createDto(@Context NamespaceAndName namespaceAndName, @Context String revision, FileObject fileObject) {
|
FileObjectDto createDto(@Context NamespaceAndName namespaceAndName, @Context BrowserResult browserResult, FileObject fileObject) {
|
||||||
String path = removeFirstSlash(fileObject.getPath());
|
String path = removeFirstSlash(fileObject.getPath());
|
||||||
Links.Builder links = Links.linkingTo();
|
Links.Builder links = Links.linkingTo();
|
||||||
if (fileObject.isDirectory()) {
|
if (fileObject.isDirectory()) {
|
||||||
links.self(resourceLinks.source().sourceWithPath(namespaceAndName.getNamespace(), namespaceAndName.getName(), revision, path));
|
links.self(resourceLinks.source().sourceWithPath(namespaceAndName.getNamespace(), namespaceAndName.getName(), browserResult.getRevision(), path));
|
||||||
} else {
|
} else {
|
||||||
links.self(resourceLinks.source().content(namespaceAndName.getNamespace(), namespaceAndName.getName(), revision, path));
|
links.self(resourceLinks.source().content(namespaceAndName.getNamespace(), namespaceAndName.getName(), browserResult.getRevision(), path));
|
||||||
links.single(link("history", resourceLinks.fileHistory().self(namespaceAndName.getNamespace(), namespaceAndName.getName(), revision, path)));
|
links.single(link("history", resourceLinks.fileHistory().self(namespaceAndName.getNamespace(), namespaceAndName.getName(), browserResult.getRevision(), path)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Embedded.Builder embeddedBuilder = embeddedBuilder();
|
Embedded.Builder embeddedBuilder = embeddedBuilder();
|
||||||
applyEnrichers(new EdisonHalAppender(links, embeddedBuilder), fileObject, namespaceAndName, revision);
|
applyEnrichers(new EdisonHalAppender(links, embeddedBuilder), fileObject, namespaceAndName, browserResult, browserResult.getRevision());
|
||||||
|
|
||||||
return new FileObjectDto(links.build(), embeddedBuilder.build());
|
return new FileObjectDto(links.build(), embeddedBuilder.build());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
import sonia.scm.repository.BrowserResult;
|
||||||
import sonia.scm.repository.FileObject;
|
import sonia.scm.repository.FileObject;
|
||||||
import sonia.scm.repository.NamespaceAndName;
|
import sonia.scm.repository.NamespaceAndName;
|
||||||
import sonia.scm.repository.SubRepository;
|
import sonia.scm.repository.SubRepository;
|
||||||
@@ -49,7 +50,7 @@ public class FileObjectToFileObjectDtoMapperTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldMapAttributesCorrectly() {
|
public void shouldMapAttributesCorrectly() {
|
||||||
FileObject fileObject = createFileObject();
|
FileObject fileObject = createFileObject();
|
||||||
FileObjectDto dto = mapper.map(fileObject, new NamespaceAndName("namespace", "name"), "revision");
|
FileObjectDto dto = mapper.map(fileObject, new NamespaceAndName("namespace", "name"), new BrowserResult("revision", fileObject));
|
||||||
|
|
||||||
assertEqualAttributes(fileObject, dto);
|
assertEqualAttributes(fileObject, dto);
|
||||||
}
|
}
|
||||||
@@ -57,7 +58,7 @@ public class FileObjectToFileObjectDtoMapperTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldHaveCorrectSelfLinkForDirectory() {
|
public void shouldHaveCorrectSelfLinkForDirectory() {
|
||||||
FileObject fileObject = createDirectoryObject();
|
FileObject fileObject = createDirectoryObject();
|
||||||
FileObjectDto dto = mapper.map(fileObject, new NamespaceAndName("namespace", "name"), "revision");
|
FileObjectDto dto = mapper.map(fileObject, new NamespaceAndName("namespace", "name"), new BrowserResult("revision", fileObject));
|
||||||
|
|
||||||
assertThat(dto.getLinks().getLinkBy("self").get().getHref()).isEqualTo(expectedBaseUri.resolve("namespace/name/sources/revision/foo/bar").toString());
|
assertThat(dto.getLinks().getLinkBy("self").get().getHref()).isEqualTo(expectedBaseUri.resolve("namespace/name/sources/revision/foo/bar").toString());
|
||||||
}
|
}
|
||||||
@@ -66,7 +67,7 @@ public class FileObjectToFileObjectDtoMapperTest {
|
|||||||
public void shouldHaveCorrectContentLink() {
|
public void shouldHaveCorrectContentLink() {
|
||||||
FileObject fileObject = createFileObject();
|
FileObject fileObject = createFileObject();
|
||||||
fileObject.setDirectory(false);
|
fileObject.setDirectory(false);
|
||||||
FileObjectDto dto = mapper.map(fileObject, new NamespaceAndName("namespace", "name"), "revision");
|
FileObjectDto dto = mapper.map(fileObject, new NamespaceAndName("namespace", "name"), new BrowserResult("revision", fileObject));
|
||||||
|
|
||||||
assertThat(dto.getLinks().getLinkBy("self").get().getHref()).isEqualTo(expectedBaseUri.resolve("namespace/name/content/revision/foo/bar").toString());
|
assertThat(dto.getLinks().getLinkBy("self").get().getHref()).isEqualTo(expectedBaseUri.resolve("namespace/name/content/revision/foo/bar").toString());
|
||||||
}
|
}
|
||||||
@@ -84,7 +85,7 @@ public class FileObjectToFileObjectDtoMapperTest {
|
|||||||
mapper.setRegistry(registry);
|
mapper.setRegistry(registry);
|
||||||
|
|
||||||
FileObject fileObject = createFileObject();
|
FileObject fileObject = createFileObject();
|
||||||
FileObjectDto dto = mapper.map(fileObject, new NamespaceAndName("hitchhiker", "hog"), "42");
|
FileObjectDto dto = mapper.map(fileObject, new NamespaceAndName("hitchhiker", "hog"), new BrowserResult("42", fileObject));
|
||||||
|
|
||||||
assertThat(dto.getLinks().getLinkBy("hog").get().getHref()).isEqualTo("http://hitchhiker/hog/foo/42");
|
assertThat(dto.getLinks().getLinkBy("hog").get().getHref()).isEqualTo("http://hitchhiker/hog/foo/42");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user