Generate link to branches for repository

This commit is contained in:
René Pfeuffer
2018-07-04 08:37:57 +02:00
parent fb811ef725
commit 7c662ed42a
10 changed files with 92 additions and 5 deletions

View File

@@ -0,0 +1,18 @@
package sonia.scm.api.v2.resources;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
public class BranchCollectionResource {
@GET
@Path("")
public Response getAll(@DefaultValue("0") @QueryParam("page") int page,
@DefaultValue("10") @QueryParam("pageSize") int pageSize,
@QueryParam("sortBy") String sortBy,
@DefaultValue("false") @QueryParam("desc") boolean desc) {
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,20 @@
package sonia.scm.api.v2.resources;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.Path;
public class BranchRootResource {
private final Provider<BranchCollectionResource> branchCollectionResource;
@Inject
public BranchRootResource(Provider<BranchCollectionResource> branchCollectionResource) {
this.branchCollectionResource = branchCollectionResource;
}
@Path("")
public BranchCollectionResource getBranchCollectionResource() {
return branchCollectionResource.get();
}
}

View File

@@ -25,13 +25,19 @@ public class RepositoryResource {
private final RepositoryManager manager;
private final SingleResourceManagerAdapter<Repository, RepositoryDto, RepositoryException> adapter;
private final Provider<TagRootResource> tagRootResource;
private final Provider<BranchRootResource> branchRootResource;
@Inject
public RepositoryResource(RepositoryToRepositoryDtoMapper repositoryToDtoMapper, RepositoryManager manager, Provider<TagRootResource> tagRootResource) {
public RepositoryResource(
RepositoryToRepositoryDtoMapper repositoryToDtoMapper,
RepositoryManager manager,
Provider<TagRootResource> tagRootResource,
Provider<BranchRootResource> branchRootResource) {
this.manager = manager;
this.repositoryToDtoMapper = repositoryToDtoMapper;
this.adapter = new SingleResourceManagerAdapter<>(manager);
this.tagRootResource = tagRootResource;
this.branchRootResource = branchRootResource;
}
@GET
@@ -65,4 +71,9 @@ public class RepositoryResource {
public TagRootResource tags() {
return tagRootResource.get();
}
@Path("branches/")
public BranchRootResource branches() {
return branchRootResource.get();
}
}

View File

@@ -35,6 +35,7 @@ public abstract class RepositoryToRepositoryDtoMapper extends BaseMapper<Reposit
linksBuilder.single(link("update", resourceLinks.repository().update(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())));
target.add(linksBuilder.build());
}
}

View File

@@ -130,14 +130,30 @@ class ResourceLinks {
}
static class TagCollectionLinks {
private final LinkBuilder repositoryLinkBuilder;
private final LinkBuilder tagLinkBuilder;
private TagCollectionLinks(UriInfo uriInfo) {
repositoryLinkBuilder = new LinkBuilder(uriInfo, RepositoryRootResource.class, RepositoryResource.class, TagRootResource.class, TagCollectionResource.class);
tagLinkBuilder = new LinkBuilder(uriInfo, RepositoryRootResource.class, RepositoryResource.class, TagRootResource.class, TagCollectionResource.class);
}
String self(String namespace, String name) {
return repositoryLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("tags").parameters().method("getTagCollectionResource").parameters().method("getAll").parameters().href();
return tagLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("tags").parameters().method("getTagCollectionResource").parameters().method("getAll").parameters().href();
}
}
public BranchCollectionLinks branchCollection() {
return new BranchCollectionLinks(uriInfoStore.get());
}
static class BranchCollectionLinks {
private final LinkBuilder branchLinkBuilder;
private BranchCollectionLinks(UriInfo uriInfo) {
branchLinkBuilder = new LinkBuilder(uriInfo, RepositoryRootResource.class, RepositoryResource.class, BranchRootResource.class, BranchCollectionResource.class);
}
String self(String namespace, String name) {
return branchLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("branches").parameters().method("getBranchCollectionResource").parameters().method("getAll").parameters().href();
}
}
}