mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 00:15:44 +01:00
Make smaller functions
This commit is contained in:
@@ -38,9 +38,20 @@ public class ContentResource {
|
|||||||
@Path("{revision}/{path: .*}")
|
@Path("{revision}/{path: .*}")
|
||||||
public Response get(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("revision") String revision, @PathParam("path") String path) {
|
public Response get(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("revision") String revision, @PathParam("path") String path) {
|
||||||
try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
|
try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
|
||||||
StreamingOutput stream = os -> {
|
StreamingOutput stream = createStreamingOutput(namespace, name, revision, path, repositoryService);
|
||||||
|
Response.ResponseBuilder responseBuilder = Response.ok(stream);
|
||||||
|
return createContentHeader(namespace, name, revision, path, repositoryService, responseBuilder);
|
||||||
|
} catch (RepositoryNotFoundException e) {
|
||||||
|
LOG.debug("path '{}' not found in repository {}/{}", path, namespace, name, e);
|
||||||
|
return Response.status(Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private StreamingOutput createStreamingOutput(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("revision") String revision, @PathParam("path") String path, RepositoryService repositoryService) {
|
||||||
|
return os -> {
|
||||||
try {
|
try {
|
||||||
repositoryService.getCatCommand().setRevision(revision).retriveContent(os, path);
|
repositoryService.getCatCommand().setRevision(revision).retriveContent(os, path);
|
||||||
|
os.close();
|
||||||
} catch (PathNotFoundException e) {
|
} catch (PathNotFoundException e) {
|
||||||
LOG.debug("path '{}' not found in repository {}/{}", path, namespace, name, e);
|
LOG.debug("path '{}' not found in repository {}/{}", path, namespace, name, e);
|
||||||
throw new WebApplicationException(Status.NOT_FOUND);
|
throw new WebApplicationException(Status.NOT_FOUND);
|
||||||
@@ -48,15 +59,7 @@ public class ContentResource {
|
|||||||
LOG.info("error reading repository resource {} from {}/{}", path, namespace, name, e);
|
LOG.info("error reading repository resource {} from {}/{}", path, namespace, name, e);
|
||||||
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
|
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
os.close();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Response.ResponseBuilder responseBuilder = Response.ok(stream);
|
|
||||||
return createContentHeader(namespace, name, revision, path, repositoryService, responseBuilder);
|
|
||||||
} catch (RepositoryNotFoundException e) {
|
|
||||||
LOG.debug("path '{}' not found in repository {}/{}", path, namespace, name, e);
|
|
||||||
return Response.status(Status.NOT_FOUND).build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@HEAD
|
@HEAD
|
||||||
|
|||||||
Reference in New Issue
Block a user