Skip to content

Commit

Permalink
Only set relevance if context. Get name from context relevance
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarvelle committed Nov 11, 2024
1 parent d2fee19 commit 620dcde
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/main/java/no/ndla/taxonomy/service/dtos/NodeDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ public NodeDTO(
this.paths = filteredContexts.stream().map(TaxonomyContext::path).collect(Collectors.toList());
this.path = entity.getPrimaryPath().or(() -> paths.stream().findFirst());

Optional<Relevance> relevance =
entity.getParentConnections().stream().findFirst().flatMap(NodeConnection::getRelevance);
var relevanceName = relevance.map(LanguageField::fromRelevance).orElse(new LanguageField<>());
this.relevanceId = relevance.map(Relevance::getPublicId);

this.translations = entity.getTranslations().stream()
.map(TranslationDTO::new)
.collect(Collectors.toCollection(TreeSet::new));
Expand All @@ -152,7 +147,7 @@ public NodeDTO(

Optional<TaxonomyContext> selected = entity.pickContext(contextId, parent, root, filteredContexts);
selected.ifPresent(ctx -> {
var contextDto = getTaxonomyContextDTO(entity, ctx, relevanceName);
var contextDto = getTaxonomyContextDTO(entity, ctx);

// TODO: this changes the content in context breadcrumbs
LanguageField<List<String>> breadcrumbList =
Expand All @@ -171,12 +166,11 @@ public NodeDTO(
includeContexts
.filter(Boolean::booleanValue)
.ifPresent(includeCtx -> this.contexts = filteredContexts.stream()
.map(ctx -> getTaxonomyContextDTO(entity, ctx, relevanceName))
.map(ctx -> getTaxonomyContextDTO(entity, ctx))
.toList());
}

private TaxonomyContextDTO getTaxonomyContextDTO(
Node entity, TaxonomyContext ctx, LanguageField<String> finalRelevanceName) {
private TaxonomyContextDTO getTaxonomyContextDTO(Node entity, TaxonomyContext ctx) {
var parentContexts = entity.getAllParentContexts();
var parents = ctx.parentContextIds().stream()
.map(parentCtxId -> {
Expand All @@ -202,6 +196,7 @@ private TaxonomyContextDTO getTaxonomyContextDTO(
}
})
.toList();
var relevance = Relevance.unsafeGetRelevance(URI.create(ctx.relevanceId()));
return new TaxonomyContextDTO(
entity.getPublicId(),
entity.getPublicId(),
Expand All @@ -211,7 +206,7 @@ private TaxonomyContextDTO getTaxonomyContextDTO(
LanguageFieldDTO.fromLanguageFieldList(ctx.breadcrumbs()),
entity.getContextType(),
URI.create(ctx.relevanceId()),
LanguageFieldDTO.fromLanguageField(finalRelevanceName),
LanguageFieldDTO.fromLanguageField(LanguageField.fromRelevance(relevance)),
entity.getResourceTypes().stream()
.sorted((o1, o2) -> {
if (o1.getParent().isEmpty()) return -1;
Expand Down

0 comments on commit 620dcde

Please sign in to comment.