mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 00:15:44 +01:00
Peer review
This commit is contained in:
@@ -16,6 +16,7 @@ public class BrowserResultDto extends HalRepresentation implements Iterable<File
|
||||
private String revision;
|
||||
private String tag;
|
||||
private String branch;
|
||||
// REVIEW files nicht embedded?
|
||||
private List<FileObjectDto> files;
|
||||
|
||||
@Override
|
||||
@@ -24,6 +25,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;
|
||||
|
||||
@@ -39,7 +39,11 @@ public class BrowserResultMapper {
|
||||
}
|
||||
|
||||
private void addLinks(BrowserResult browserResult, BrowserResultDto dto, NamespaceAndName namespaceAndName) {
|
||||
dto.add(Links.linkingTo().self(resourceLinks.source().self(namespaceAndName.getNamespace(), namespaceAndName.getName(), browserResult.getRevision())).build());
|
||||
if (browserResult.getRevision() == null) {
|
||||
dto.add(Links.linkingTo().self(resourceLinks.source().selfWithoutRevision(namespaceAndName.getNamespace(), namespaceAndName.getName())).build());
|
||||
} else {
|
||||
dto.add(Links.linkingTo().self(resourceLinks.source().self(namespaceAndName.getNamespace(), namespaceAndName.getName(), browserResult.getRevision())).build());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,9 +25,12 @@ public abstract class FileObjectMapper extends BaseMapper<FileObject, FileObject
|
||||
|
||||
@AfterMapping
|
||||
void addLinks(FileObject fileObject, @MappingTarget FileObjectDto dto, @Context NamespaceAndName namespaceAndName, @Context String revision) {
|
||||
dto.add(Links.linkingTo()
|
||||
.self(resourceLinks.source().sourceWithPath(namespaceAndName.getNamespace(), namespaceAndName.getName(), revision, fileObject.getName()))
|
||||
.single(link("content", resourceLinks.source().content(namespaceAndName.getNamespace(), namespaceAndName.getName(), revision, fileObject.getName())))
|
||||
.build());
|
||||
Links.Builder links = Links.linkingTo()
|
||||
.self(resourceLinks.source().sourceWithPath(namespaceAndName.getNamespace(), namespaceAndName.getName(), revision, fileObject.getPath()));
|
||||
if (!dto.isDirectory()) {
|
||||
links.single(link("content", resourceLinks.source().content(namespaceAndName.getNamespace(), namespaceAndName.getName(), revision, fileObject.getPath())));
|
||||
}
|
||||
|
||||
dto.add(links.build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,11 +291,11 @@ class ResourceLinks {
|
||||
}
|
||||
|
||||
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).method("sources").parameters().method("getAll").parameters(revision).href();
|
||||
}
|
||||
|
||||
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("getAllWithoutRevision").parameters().href();
|
||||
}
|
||||
|
||||
public String source(String namespace, String name, String revision) {
|
||||
@@ -303,7 +303,11 @@ class ResourceLinks {
|
||||
}
|
||||
|
||||
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();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
public String content(String namespace, String name, String revision, String path) {
|
||||
|
||||
@@ -31,7 +31,14 @@ public class SourceRootResource {
|
||||
|
||||
@GET
|
||||
@Produces(VndMediaType.SOURCE)
|
||||
@Path("{revision : (\\w+)?}")
|
||||
@Path("")
|
||||
public Response getAllWithoutRevision(@PathParam("namespace") String namespace, @PathParam("name") String name) {
|
||||
return getSource(namespace, name, "/", null);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Produces(VndMediaType.SOURCE)
|
||||
@Path("{revision}")
|
||||
public Response getAll(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("revision") String revision) {
|
||||
return getSource(namespace, name, "/", revision);
|
||||
}
|
||||
@@ -44,8 +51,6 @@ public class SourceRootResource {
|
||||
}
|
||||
|
||||
private Response getSource(String namespace, String repoName, String path, String revision) {
|
||||
BrowserResult browserResult;
|
||||
Response response;
|
||||
NamespaceAndName namespaceAndName = new NamespaceAndName(namespace, repoName);
|
||||
try (RepositoryService repositoryService = serviceFactory.create(namespaceAndName)) {
|
||||
BrowseCommandBuilder browseCommand = repositoryService.getBrowseCommand();
|
||||
@@ -53,19 +58,18 @@ public class SourceRootResource {
|
||||
if (revision != null && !revision.isEmpty()) {
|
||||
browseCommand.setRevision(revision);
|
||||
}
|
||||
browserResult = browseCommand.getBrowserResult();
|
||||
BrowserResult browserResult = browseCommand.getBrowserResult();
|
||||
|
||||
if (browserResult != null) {
|
||||
response = Response.ok(browserResultMapper.map(browserResult, namespaceAndName)).build();
|
||||
return Response.ok(browserResultMapper.map(browserResult, namespaceAndName)).build();
|
||||
} else {
|
||||
response = Response.status(Response.Status.NOT_FOUND).build();
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
|
||||
} catch (RepositoryNotFoundException e) {
|
||||
response = Response.status(Response.Status.NOT_FOUND).build();
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
} catch (RepositoryException | IOException e) {
|
||||
response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user