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

WIP : Advanced filters #702

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class="py-[37px] pl-[47px] rounded-lg border bg-white mb-5 card-shadow cursor-pointer"
[figure]="recordsCount$ | async"
[icon]="'folder_open'"
[title]="'catalog.figures.datasets'"
[title]="'catalog.figures.datasets' | translate"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is useless as the gn-ui-figure already does a translation.

[color]="'secondary'"
></gn-ui-figure>
</a>
Expand All @@ -13,7 +13,7 @@
class="py-[37px] pl-[47px] rounded-lg bg-white border card-shadow cursor-pointer"
[figure]="orgsCount$ | async"
[icon]="'corporate_fare'"
[title]="'catalog.figures.organisations'"
[title]="'catalog.figures.organisations' | translate"
[color]="'secondary'"
></gn-ui-figure>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { combineLatest, Observable, of, switchMap, takeLast } from 'rxjs'
import { filter, map, shareReplay, startWith, tap } from 'rxjs/operators'
import { LangService } from '@geonetwork-ui/util/i18n'
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface'
import { coerce, satisfies, valid } from 'semver'

const IMAGE_URL = '/geonetwork/images/harvesting/'

Expand Down Expand Up @@ -144,6 +145,7 @@ export class OrganizationsFromMetadataService
}

private getAggregationSearchRequest(gnVersion: string) {
const semVersion = valid(coerce(gnVersion))
return this.esService.getSearchRequestBody({
contact: {
nested: {
Expand All @@ -152,9 +154,10 @@ export class OrganizationsFromMetadataService
aggs: {
org: {
terms: {
field: gnVersion.startsWith('4.2.2')
? 'contactForResource.organisation'
: 'contactForResource.organisationObject.default.keyword',
field:
semVersion === '4.2.2'
? 'contactForResource.organisation'
: 'contactForResource.organisationObject.default.keyword',
exclude: '',
size: 5000,
order: { _key: 'asc' },
Expand All @@ -164,12 +167,9 @@ export class OrganizationsFromMetadataService
terms: {
size: 50,
exclude: '',
field:
gnVersion.startsWith('4.2.2') ||
gnVersion.startsWith('4.2.3') ||
gnVersion.startsWith('4.2.4')
? 'contactForResource.email.keyword'
: 'contactForResource.email',
field: satisfies(semVersion, '4.2.2 - 4.2.4')
? 'contactForResource.email.keyword'
: 'contactForResource.email',
},
},
logoUrl: {
Expand All @@ -187,9 +187,10 @@ export class OrganizationsFromMetadataService
terms: {
size: 5000,
exclude: '',
field: gnVersion.startsWith('4.2.2')
? 'OrgForResource'
: 'OrgForResourceObject.default',
field:
semVersion === '4.2.2'
? 'OrgForResource'
: 'OrgForResourceObject.default',
order: {
_key: 'asc',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ export class Gn4PlatformMapper {
credentialsNonExpired,
...user
} = apiUser
return { ...apiUser, id: id + '' } as UserModel
return { ...apiUser, id: id.toString() } as UserModel
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@geonetwork-ui/data-access/gn4'
import { TestBed } from '@angular/core/testing'
import { Gn4PlatformService } from './gn4-platform.service'
import { firstValueFrom, lastValueFrom, of, Subject } from 'rxjs'
import { firstValueFrom, of, Subject } from 'rxjs'
import { AvatarServiceInterface } from '../auth/avatar.service.interface'
import { Gn4PlatformMapper } from './gn4-platform.mapper'

Expand All @@ -31,6 +31,7 @@ class MeApiMock {
getMe() {
return this._me$
}

_me$ = new Subject()
}

Expand All @@ -46,6 +47,7 @@ class SiteApiServiceMock {
})
)
}

class UsersApiServiceMock {
getUsers() {
return of([
Expand Down Expand Up @@ -98,11 +100,32 @@ describe('Gn4PlatformService', () => {
expect(service).toBeTruthy()
})

it('fetches version from settings', async () => {
geonetworkVersion = '4.2.0'
const version = await firstValueFrom(service.getApiVersion())
expect(version).toEqual('4.2.0')
describe('version', () => {
describe('when version is lower than 4.2.2', () => {
beforeEach(() => {
geonetworkVersion = '4.2.0'
})
it('throws an error', async () => {
let error
await firstValueFrom(service.getApiVersion()).catch((e) => (error = e))
expect(error).toEqual(
new Error(
'Gn4 API version is not compatible.\nMinimum: 4.2.2\nYour version: 4.2.0'
)
)
})
})
describe('when version is euqal or greater than 4.2.2', () => {
beforeEach(() => {
geonetworkVersion = '4.2.2'
})
it('fetches version from settings', async () => {
const version = await firstValueFrom(service.getApiVersion())
expect(version).toEqual('4.2.2')
})
})
})

it('fetches users from api', async () => {
const users = await firstValueFrom(service.getUsers())
expect(users).toEqual([
Expand Down
24 changes: 10 additions & 14 deletions libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.
import { UserModel } from '@geonetwork-ui/common/domain/model/user/user.model'
import { Organization } from '@geonetwork-ui/common/domain/model/record'
import { Gn4PlatformMapper } from './gn4-platform.mapper'
import { ltr } from 'semver'

const minApiVersion = '4.2.0'
const minApiVersion = '4.2.2'
@Injectable()
export class Gn4PlatformService implements PlatformServiceInterface {
private readonly type = 'GeoNetwork'
private me$: Observable<UserModel>
private users$: Observable<UserModel[]>
isAnonymous$: Observable<boolean>
private isAnonymous$: Observable<boolean>

private settings$ = of(true).pipe(
switchMap(() => this.siteApiService.getSiteOrPortalDescription()),
Expand All @@ -26,18 +27,16 @@ export class Gn4PlatformService implements PlatformServiceInterface {

private readonly apiVersion$ = this.settings$.pipe(
map((info) => info['system/platform/version'] as string),
tap((version) => {
if (ltr(version, minApiVersion)) {
throw new Error(
`Gn4 API version is not compatible.\nMinimum: ${minApiVersion}\nYour version: ${version}`
)
}
}),
shareReplay(1)
)

private readonly isApiCompatible$ = this.apiVersion$.pipe(
tap(
(version) =>
version < minApiVersion &&
console.warn(`The GeoNetwork Api version is too low ${version}`)
),
map((version) => version >= minApiVersion)
)

constructor(
private siteApiService: SiteApiService,
private meApi: MeApiService,
Expand All @@ -62,9 +61,6 @@ export class Gn4PlatformService implements PlatformServiceInterface {
getApiVersion(): Observable<string> {
return this.apiVersion$
}
isApiCompatible(): Observable<boolean> {
return this.isApiCompatible$
}

getMe(): Observable<UserModel> {
return this.me$
Expand Down
1 change: 0 additions & 1 deletion libs/common/domain/src/lib/platform.service.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Organization } from './model/record/organization.model'
export abstract class PlatformServiceInterface {
abstract getType(): string
abstract getApiVersion(): Observable<string>
abstract isApiCompatible(): Observable<boolean>

abstract getMe(): Observable<UserModel>
abstract isAnonymous(): Observable<boolean>
Expand Down
135 changes: 135 additions & 0 deletions libs/data-access/gn4/src/custom-api/thesaurus.api.service.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The content of the commit has nothing to do with the commit message.

Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { Inject, Injectable, Optional } from '@angular/core'
import {
HttpClient,
HttpHeaders,
HttpParameterCodec,
} from '@angular/common/http'
import { Observable } from 'rxjs'
import { CustomHttpParameterCodec } from '../openapi/encoder'
import { Configuration } from '../openapi/configuration'

import { BASE_PATH } from '../openapi/variables'

export interface thesaurusResponse {
values: { [key: string]: string }
definitions: { [key: string]: string }
coordEast?: string
coordWest?: string
coordSouth?: string
coordNorth?: string
thesaurusKey: string
value: string
uri: string
definition?: string
}

@Injectable({
providedIn: 'root',
})
export class ThesaurusApiService {
protected basePath = 'https://apps.titellus.net/geonetwork/srv/api'
public defaultHeaders = new HttpHeaders()
public configuration = new Configuration()
public encoder: HttpParameterCodec

constructor(
protected httpClient: HttpClient,
@Optional() @Inject(BASE_PATH) basePath: string,
@Optional() configuration: Configuration
) {
if (configuration) {
this.configuration = configuration
}
if (typeof this.configuration.basePath !== 'string') {
if (typeof basePath !== 'string') {
basePath = this.basePath
}
this.configuration.basePath = basePath
}
this.encoder = this.configuration.encoder || new CustomHttpParameterCodec()
}

/**
* List database translations (used to overrides client application translations).
* @param esFieldName set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param iso3 set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public getTranslationsFromThesaurus(
thesaurusName: string,
langIso3: string,
observe?: 'body',
reportProgress?: boolean,
options?: { httpHeaderAccept?: 'application/json' }
): Observable<any>
public getTranslationsFromThesaurus(
thesaurusName: string,
langIso3: string,
observe?: 'response',
reportProgress?: boolean,
options?: { httpHeaderAccept?: 'application/json' }
): Observable<thesaurusResponse[]>
public getTranslationsFromThesaurus(
thesaurusName: string,
langIso3: string,
observe?: 'events',
reportProgress?: boolean,
options?: { httpHeaderAccept?: 'application/json' }
): Observable<thesaurusResponse[]>
public getTranslationsFromThesaurus(
thesaurusName: string,
langIso3: string,
observe: any = 'body',
reportProgress: boolean = false,
options?: { httpHeaderAccept?: 'application/json' }
): Observable<any> {
if (
thesaurusName === null ||
thesaurusName === undefined ||
langIso3 === null ||
langIso3 === undefined
) {
throw new Error(
'Required parameter pack was null or undefined when calling getTranslationsFromThesaurus.'
)
}

let headers = this.defaultHeaders

let httpHeaderAcceptSelected: string | undefined =
options && options.httpHeaderAccept
if (httpHeaderAcceptSelected === undefined) {
// to determine the Accept header
const httpHeaderAccepts: string[] = ['application/json']
httpHeaderAcceptSelected =
this.configuration.selectHeaderAccept(httpHeaderAccepts)
}
if (httpHeaderAcceptSelected !== undefined) {
headers = headers.set('Accept', httpHeaderAcceptSelected)
}

let responseType_: 'text' | 'json' = 'json'
if (
httpHeaderAcceptSelected &&
httpHeaderAcceptSelected.startsWith('text')
) {
responseType_ = 'text'
}

return this.httpClient.get<thesaurusResponse[]>(
`${
this.configuration.basePath
}/registries/vocabularies/search?rows=1000&type=CONTAINS&sort=DESC&thesaurus=${encodeURIComponent(
String(thesaurusName)
)}&lang=${encodeURIComponent(langIso3)}`,
{
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress,
}
)
}
}
Loading
Loading