mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-29 18:59:11 +01:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user