mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-06 12:20:56 +01:00
Append import bundle link to repository type if unbundle command is supported
This commit is contained in:
@@ -47,8 +47,13 @@ public abstract class RepositoryTypeToRepositoryTypeDtoMapper extends BaseMapper
|
||||
void appendLinks(RepositoryType repositoryType, @MappingTarget RepositoryTypeDto target) {
|
||||
Links.Builder linksBuilder = linkingTo().self(resourceLinks.repositoryType().self(repositoryType.getName()));
|
||||
|
||||
if (RepositoryPermissions.create().isPermitted() && repositoryType.getSupportedCommands().contains(Command.PULL)) {
|
||||
linksBuilder.array(Link.linkBuilder("import", resourceLinks.repository().importFromUrl(repositoryType.getName())).withName("url").build());
|
||||
if (RepositoryPermissions.create().isPermitted()) {
|
||||
if (repositoryType.getSupportedCommands().contains(Command.PULL)) {
|
||||
linksBuilder.array(Link.linkBuilder("import", resourceLinks.repository().importFromUrl(repositoryType.getName())).withName("url").build());
|
||||
}
|
||||
if (repositoryType.getSupportedCommands().contains(Command.UNBUNDLE)) {
|
||||
linksBuilder.array(Link.linkBuilder("import", resourceLinks.repository().importFromBundle(repositoryType.getName())).withName("bundle").build());
|
||||
}
|
||||
}
|
||||
|
||||
target.add(linksBuilder.build());
|
||||
|
||||
@@ -360,6 +360,10 @@ class ResourceLinks {
|
||||
String importFromUrl(String type) {
|
||||
return repositoryImportLinkBuilder.method("getRepositoryImportResource").parameters().method("importFromUrl").parameters(type).href();
|
||||
}
|
||||
|
||||
String importFromBundle(String type) {
|
||||
return repositoryImportLinkBuilder.method("getRepositoryImportResource").parameters().method("importFromBundle").parameters(type).href();
|
||||
}
|
||||
}
|
||||
|
||||
RepositoryCollectionLinks repositoryCollection() {
|
||||
|
||||
@@ -112,4 +112,31 @@ public class RepositoryTypeToRepositoryTypeDtoMapperTest {
|
||||
RepositoryTypeDto dto = mapper.map(type);
|
||||
assertFalse(dto.getLinks().getLinkBy("import").isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAppendImportFromBundleLink() {
|
||||
RepositoryType type = new RepositoryType("hk", "Hitchhiker", ImmutableSet.of(Command.UNBUNDLE));
|
||||
when(subject.isPermitted("repository:create")).thenReturn(true);
|
||||
|
||||
RepositoryTypeDto dto = mapper.map(type);
|
||||
assertEquals(
|
||||
"https://scm-manager.org/scm/v2/repositories/import/hk/bundle",
|
||||
dto.getLinks().getLinkBy("import").get().getHref()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotAppendImportFromBundleLinkIfCommandNotSupported() {
|
||||
when(subject.isPermitted("repository:create")).thenReturn(true);
|
||||
RepositoryTypeDto dto = mapper.map(type);
|
||||
assertFalse(dto.getLinks().getLinkBy("import").isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotAppendImportFromBundleLinkIfNotPermitted() {
|
||||
RepositoryType type = new RepositoryType("hk", "Hitchhiker", ImmutableSet.of(Command.UNBUNDLE));
|
||||
|
||||
RepositoryTypeDto dto = mapper.map(type);
|
||||
assertFalse(dto.getLinks().getLinkBy("import").isPresent());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user