Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(platform-service): Exclude place thesarus keywords #915

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,95 @@ describe('Gn4PlatformService', () => {
})
})
})
describe('#searchKeywords', () => {
beforeEach(() => {
jest.spyOn(service, 'searchKeywords')
})
it('calls api service with qeury', () => {
service.searchKeywords('road').subscribe()
expect(registriesApiService.searchKeywords).toHaveBeenCalledWith(
'road',
'fre',
10,
0,
null,
['external.theme.httpinspireeceuropaeutheme-theme'],
null,
'*road*'
)
})
it('returns mapped thesaurus with translated values', async () => {
const keywords = await lastValueFrom(service.searchKeywords('road'))
expect(keywords).toEqual([
{
description:
'Localisation des propriétés fondée sur les identifiants des adresses, habituellement le nom de la rue, le numéro de la maison et le code postal.',
key: 'http://inspire.ec.europa.eu/theme/ad',
label: 'Adresses',
thesaurus: {
id: 'external.theme.httpinspireeceuropaeutheme-theme',
name: 'GEMET - INSPIRE themes, version 1.0',
type: 'theme',
url: new URL(
'http://localhost:8080/geonetwork/srv/api/registries/vocabularies/external.theme.httpinspireeceuropaeutheme-theme'
),
},
type: 'theme',
},
{
description:
"Modèles numériques pour l'altitude des surfaces terrestres, glaciaires et océaniques. Comprend l'altitude terrestre, la bathymétrie et la ligne de rivage.",
key: 'http://inspire.ec.europa.eu/theme/el',
label: 'Altitude',
thesaurus: {
id: 'external.theme.httpinspireeceuropaeutheme-theme',
name: 'GEMET - INSPIRE themes, version 1.0',
type: 'theme',
url: new URL(
'http://localhost:8080/geonetwork/srv/api/registries/vocabularies/external.theme.httpinspireeceuropaeutheme-theme'
),
},
type: 'theme',
},
])
})
describe('if translations are unavailable', () => {
it('uses default values', async () => {
service['langService']['iso3'] = 'ger'
const keywords = await lastValueFrom(service.searchKeywords('road'))
expect(keywords).toEqual([
{
description: 'localization of properties',
key: 'http://inspire.ec.europa.eu/theme/ad',
label: 'addresses',
thesaurus: {
id: 'external.theme.httpinspireeceuropaeutheme-theme',
name: 'GEMET - INSPIRE themes, version 1.0',
type: 'theme',
url: new URL(
'http://localhost:8080/geonetwork/srv/api/registries/vocabularies/external.theme.httpinspireeceuropaeutheme-theme'
),
},
type: 'theme',
},
{
description: 'digital terrain models',
key: 'http://inspire.ec.europa.eu/theme/el',
label: 'altitude',
thesaurus: {
id: 'external.theme.httpinspireeceuropaeutheme-theme',
name: 'GEMET - INSPIRE themes, version 1.0',
type: 'theme',
url: new URL(
'http://localhost:8080/geonetwork/srv/api/registries/vocabularies/external.theme.httpinspireeceuropaeutheme-theme'
),
},
type: 'theme',
},
])
})
})
})
describe('#getKeywordsByUri', () => {
it('calls api service ', async () => {
service.getKeywordsByUri('http://inspire.ec.europa.eu/theme/')
Expand Down
41 changes: 25 additions & 16 deletions libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Injectable } from '@angular/core'
import { Observable, combineLatest, of, switchMap } from 'rxjs'
import { catchError, map, shareReplay, tap } from 'rxjs/operators'
import { catchError, concatMap, map, shareReplay, tap } from 'rxjs/operators'
import {
MeApiService,
RegistriesApiService,
SiteApiService,
ThesaurusInfoApiModel,
ToolsApiService,
UserfeedbackApiService,
UsersApiService,
Expand Down Expand Up @@ -146,25 +145,35 @@ export class Gn4PlatformService implements PlatformServiceInterface {
)
.pipe(
map((thesaurus) => {
// FIXME: find a better way to exclude place keywords
// thesaurus[0].filter((thes) => thes.dname !== 'place')
return thesaurus[0] as ThesaurusApiResponse[]
const thesauriWithoutPlace = thesaurus[0].filter(
(thes) => thes.dname !== 'place'
)
return thesauriWithoutPlace as ThesaurusApiResponse[]
}),
shareReplay(1)
)

searchKeywords(query: string): Observable<Keyword[]> {
const keywords$: Observable<KeywordApiResponse[]> =
this.registriesApiService.searchKeywords(
query,
this.langService.iso3,
10,
0,
null,
null,
null,
`*${query}*`
) as Observable<KeywordApiResponse[]>
const keywords$: Observable<KeywordApiResponse[]> = this.allThesaurus$.pipe(
concatMap((thesaurus) => {
Angi-Kinas marked this conversation as resolved.
Show resolved Hide resolved
return this.registriesApiService
.searchKeywords(
query,
this.langService.iso3,
10,
0,
null,
thesaurus.map((thes) => thes.key),
null,
`*${query}*`
)
.pipe(
Angi-Kinas marked this conversation as resolved.
Show resolved Hide resolved
map((keywords) => {
return keywords as KeywordApiResponse[]
})
)
})
)

return combineLatest([keywords$, this.allThesaurus$]).pipe(
map(([keywords, thesaurus]) => {
Expand Down
Loading