Allow enrichment of embedded repositories on search hits (#1760)

* Introduce RepositoryCoordinates

RepositoryCoordinates will be used for the enrichment of the embedded repositories of search result hits. This is required, because if we used the normal repository for the enrichment, we would get a lot of unrelated enrichers would be applied.

* Add builder method to HalEnricherContext

With the new builder method it is possible to add an object to the context with an interface as key.

* Add enricher support for embedded repository by applying enricher for RepositoryCoordinates

* Use embedded repository for avatars
This commit is contained in:
Sebastian Sdorra
2021-08-05 15:12:48 +02:00
committed by GitHub
parent 21a6943980
commit 8ce69d9848
9 changed files with 185 additions and 43 deletions

View File

@@ -38,6 +38,7 @@ import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ObjectFactory;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryCoordinates;
import sonia.scm.repository.RepositoryManager;
import sonia.scm.search.Hit;
import sonia.scm.search.QueryResult;
@@ -87,8 +88,16 @@ public abstract class QueryResultMapper extends HalAppenderMapper {
@Nonnull
@ObjectFactory
EmbeddedRepositoryDto createDto(Repository repository) {
String self = resourceLinks.repository().self(repository.getNamespace(), repository.getName());
return new EmbeddedRepositoryDto(linkingTo().self(self).build());
Links.Builder links = linkingTo();
links.self(resourceLinks.repository().self(repository.getNamespace(), repository.getName()));
Embedded.Builder embedded = Embedded.embeddedBuilder();
HalEnricherContext context = HalEnricherContext.builder()
.put(RepositoryCoordinates.class, repository)
.build();
applyEnrichers(context, new EdisonHalAppender(links, embedded), RepositoryCoordinates.class);
return new EmbeddedRepositoryDto(links.build(), embedded.build());
}
@Nonnull
@@ -164,8 +173,8 @@ public abstract class QueryResultMapper extends HalAppenderMapper {
private String namespace;
private String name;
private String type;
public EmbeddedRepositoryDto(Links links) {
super(links);
public EmbeddedRepositoryDto(Links links, Embedded embedded) {
super(links, embedded);
}
}
}