mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
Remove tags and branches from browse result and embed files
This commit is contained in:
@@ -97,7 +97,7 @@ public class RepositoryAccessITCase {
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK)
|
||||
.extract()
|
||||
.path("files.find{it.name=='a.txt'}._links.self.href");
|
||||
.path("_embedded.files.find{it.name=='a.txt'}._links.self.href");
|
||||
|
||||
given()
|
||||
.when()
|
||||
@@ -112,7 +112,7 @@ public class RepositoryAccessITCase {
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK)
|
||||
.extract()
|
||||
.path("files.find{it.name=='subfolder'}._links.self.href");
|
||||
.path("_embedded.files.find{it.name=='subfolder'}._links.self.href");
|
||||
String selfOfSubfolderUrl = given()
|
||||
.when()
|
||||
.get(subfolderSourceUrl)
|
||||
@@ -127,7 +127,7 @@ public class RepositoryAccessITCase {
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK)
|
||||
.extract()
|
||||
.path("files[0]._links.self.href");
|
||||
.path("_embedded.files[0]._links.self.href");
|
||||
given()
|
||||
.when()
|
||||
.get(subfolderContentUrl)
|
||||
|
||||
@@ -6,18 +6,13 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class BrowserResultDto extends HalRepresentation implements Iterable<FileObjectDto> {
|
||||
public class BrowserResultDto extends HalRepresentation {
|
||||
private String revision;
|
||||
private String tag;
|
||||
private String branch;
|
||||
// REVIEW files nicht embedded?
|
||||
private List<FileObjectDto> files;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("squid:S1185") // We want to have this method available in this package
|
||||
@@ -25,16 +20,7 @@ public class BrowserResultDto extends HalRepresentation implements Iterable<File
|
||||
return super.add(links);
|
||||
}
|
||||
|
||||
// REVIEW return null?
|
||||
@Override
|
||||
public Iterator<FileObjectDto> iterator() {
|
||||
Iterator<FileObjectDto> it = null;
|
||||
|
||||
if (files != null)
|
||||
{
|
||||
it = files.iterator();
|
||||
}
|
||||
|
||||
return it;
|
||||
public void setFiles(List<FileObjectDto> files) {
|
||||
this.withEmbedded("files", files);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ public class BrowserResultToBrowserResultDtoMapper {
|
||||
public BrowserResultDto map(BrowserResult browserResult, NamespaceAndName namespaceAndName, String path) {
|
||||
BrowserResultDto browserResultDto = new BrowserResultDto();
|
||||
|
||||
browserResultDto.setTag(browserResult.getTag());
|
||||
browserResultDto.setBranch(browserResult.getBranch());
|
||||
browserResultDto.setRevision(browserResult.getRevision());
|
||||
|
||||
List<FileObjectDto> fileObjectDtoList = new ArrayList<>();
|
||||
@@ -48,6 +46,4 @@ public class BrowserResultToBrowserResultDtoMapper {
|
||||
dto.add(Links.linkingTo().self(resourceLinks.source().sourceWithPath(namespaceAndName.getNamespace(), namespaceAndName.getName(), browserResult.getRevision(), path)).build());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.SubRepository;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.net.URI;
|
||||
|
||||
@Mapper
|
||||
public abstract class FileObjectToFileObjectDtoMapper extends BaseMapper<FileObject, FileObjectDto> {
|
||||
@@ -27,19 +26,14 @@ public abstract class FileObjectToFileObjectDtoMapper extends BaseMapper<FileObj
|
||||
String path = removeFirstSlash(fileObject.getPath());
|
||||
Links.Builder links = Links.linkingTo();
|
||||
if (dto.isDirectory()) {
|
||||
links.self(addPath(resourceLinks.source().sourceWithPath(namespaceAndName.getNamespace(), namespaceAndName.getName(), revision, ""), path));
|
||||
links.self(resourceLinks.source().sourceWithPath(namespaceAndName.getNamespace(), namespaceAndName.getName(), revision, path));
|
||||
} else {
|
||||
links.self(addPath(resourceLinks.source().content(namespaceAndName.getNamespace(), namespaceAndName.getName(), revision, ""), path));
|
||||
links.self(resourceLinks.source().content(namespaceAndName.getNamespace(), namespaceAndName.getName(), revision, path));
|
||||
}
|
||||
|
||||
dto.add(links.build());
|
||||
}
|
||||
|
||||
// we have to add the file path using URI, so that path separators (aka '/') will not be encoded as '%2F'
|
||||
private String addPath(String sourceWithPath, String path) {
|
||||
return URI.create(sourceWithPath).resolve(path).toASCIIString();
|
||||
}
|
||||
|
||||
private String removeFirstSlash(String source) {
|
||||
return source.startsWith("/") ? source.substring(1) : source;
|
||||
}
|
||||
|
||||
@@ -331,15 +331,16 @@ class ResourceLinks {
|
||||
}
|
||||
|
||||
public String sourceWithPath(String namespace, String name, String revision, String path) {
|
||||
if (revision == null) {
|
||||
return sourceLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("sources").parameters().method("get").parameters(null, path).href();
|
||||
} else {
|
||||
return sourceLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("sources").parameters().method("get").parameters(revision, path).href();
|
||||
}
|
||||
return addPath(sourceLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("sources").parameters().method("get").parameters(revision, "").href(), path);
|
||||
}
|
||||
|
||||
public String content(String namespace, String name, String revision, String path) {
|
||||
return sourceLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("content").parameters().method("get").parameters(revision, path).href();
|
||||
return addPath(sourceLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("content").parameters().method("get").parameters(revision, "").href(), path);
|
||||
}
|
||||
|
||||
// we have to add the file path using URI, so that path separators (aka '/') will not be encoded as '%2F'
|
||||
private String addPath(String sourceWithPath, String path) {
|
||||
return URI.create(sourceWithPath).resolve(path).toASCIIString();
|
||||
}
|
||||
}
|
||||
public PermissionLinks permission() {
|
||||
|
||||
@@ -18,8 +18,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
public class BrowserResultToBrowserResultDtoMapperTest {
|
||||
@@ -60,6 +62,8 @@ public class BrowserResultToBrowserResultDtoMapperTest {
|
||||
fileObject2.setPath("/path/object/2");
|
||||
fileObject2.setDescription("description of file object 2");
|
||||
fileObject2.setDirectory(true);
|
||||
|
||||
when(fileObjectToFileObjectDtoMapper.map(any(), any(), any())).thenReturn(new FileObjectDto());
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -99,9 +103,7 @@ public class BrowserResultToBrowserResultDtoMapperTest {
|
||||
|
||||
private BrowserResult createBrowserResult() {
|
||||
BrowserResult browserResult = new BrowserResult();
|
||||
browserResult.setTag("Tag");
|
||||
browserResult.setRevision("Revision");
|
||||
browserResult.setBranch("Branch");
|
||||
browserResult.setFiles(createFileObjects());
|
||||
|
||||
return browserResult;
|
||||
@@ -116,8 +118,6 @@ public class BrowserResultToBrowserResultDtoMapperTest {
|
||||
}
|
||||
|
||||
private void assertEqualAttributes(BrowserResult browserResult, BrowserResultDto dto) {
|
||||
assertThat(dto.getTag()).isEqualTo(browserResult.getTag());
|
||||
assertThat(dto.getBranch()).isEqualTo(browserResult.getBranch());
|
||||
assertThat(dto.getRevision()).isEqualTo(browserResult.getRevision());
|
||||
}
|
||||
|
||||
|
||||
@@ -90,8 +90,6 @@ public class SourceRootResourceTest {
|
||||
dispatcher.invoke(request, response);
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
assertThat(response.getContentAsString()).contains("\"revision\":\"revision\"");
|
||||
assertThat(response.getContentAsString()).contains("\"tag\":\"tag\"");
|
||||
assertThat(response.getContentAsString()).contains("\"branch\":\"branch\"");
|
||||
assertThat(response.getContentAsString()).contains("\"files\":");
|
||||
}
|
||||
|
||||
@@ -108,9 +106,7 @@ public class SourceRootResourceTest {
|
||||
@Test
|
||||
public void shouldGetResultForSingleFile() throws URISyntaxException, IOException, RevisionNotFoundException {
|
||||
BrowserResult browserResult = new BrowserResult();
|
||||
browserResult.setBranch("abc");
|
||||
browserResult.setRevision("revision");
|
||||
browserResult.setTag("tag");
|
||||
FileObject fileObject = new FileObject();
|
||||
fileObject.setName("File Object!");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user