-
Notifications
You must be signed in to change notification settings - Fork 530
Lookup relations - Search external sources #539
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
de4b32d
67478: Intermediate commit - Basic components
Atmire-Kristof edbc326
67478: LookupRelationService, external source tabs, list implementation
Atmire-Kristof b3e2041
67478: External source tabs test cases
Atmire-Kristof 558285d
67478: Automatically fill query in search form
Atmire-Kristof e9a8a25
67478: AoT build fixes
Atmire-Kristof b51218a
Merge branch 'master' into w2p-67478_Search-external-sources-in-submi…
Atmire-Kristof cdbb9b6
67478: External source entries loading on search-option change
Atmire-Kristof 64eb5db
67478: JSDocs intermediate commit
Atmire-Kristof 9042281
Merge remote-tracking branch 'atmire/clean-relationships-in-submissio…
Atmire-Kristof 890d60a
67478: External source link + pagination fix
Atmire-Kristof 4ba3b01
Merge branch 'master' into w2p-67478_Search-external-sources-in-submi…
Atmire-Kristof 617bbbb
67478: Remove redundant test
Atmire-Kristof File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/app/core/cache/models/normalized-external-source-entry.model.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { autoserialize, autoserializeAs, inheritSerialization } from 'cerialize'; | ||
| import { NormalizedObject } from './normalized-object.model'; | ||
| import { ExternalSourceEntry } from '../../shared/external-source-entry.model'; | ||
| import { mapsTo } from '../builders/build-decorators'; | ||
| import { MetadataMap, MetadataMapSerializer } from '../../shared/metadata.models'; | ||
|
|
||
| /** | ||
| * Normalized model class for an external source entry | ||
| */ | ||
| @mapsTo(ExternalSourceEntry) | ||
| @inheritSerialization(NormalizedObject) | ||
| export class NormalizedExternalSourceEntry extends NormalizedObject<ExternalSourceEntry> { | ||
| /** | ||
| * Unique identifier | ||
| */ | ||
| @autoserialize | ||
| id: string; | ||
|
|
||
| /** | ||
| * The value to display | ||
| */ | ||
| @autoserialize | ||
| display: string; | ||
|
|
||
| /** | ||
| * The value to store the entry with | ||
| */ | ||
| @autoserialize | ||
| value: string; | ||
|
|
||
| /** | ||
| * Metadata of the entry | ||
| */ | ||
| @autoserializeAs(MetadataMapSerializer) | ||
| metadata: MetadataMap; | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
src/app/core/cache/models/normalized-external-source.model.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { autoserialize, inheritSerialization } from 'cerialize'; | ||
| import { NormalizedObject } from './normalized-object.model'; | ||
| import { ExternalSource } from '../../shared/external-source.model'; | ||
| import { mapsTo } from '../builders/build-decorators'; | ||
|
|
||
| /** | ||
| * Normalized model class for an external source | ||
| */ | ||
| @mapsTo(ExternalSource) | ||
| @inheritSerialization(NormalizedObject) | ||
| export class NormalizedExternalSource extends NormalizedObject<ExternalSource> { | ||
tdonohue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * Unique identifier | ||
| */ | ||
| @autoserialize | ||
| id: string; | ||
|
|
||
| /** | ||
| * The name of this external source | ||
| */ | ||
| @autoserialize | ||
| name: string; | ||
|
|
||
| /** | ||
| * Is the source hierarchical? | ||
| */ | ||
| @autoserialize | ||
| hierarchical: boolean; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { ExternalSourceService } from './external-source.service'; | ||
| import { createPaginatedList, createSuccessfulRemoteDataObject$ } from '../../shared/testing/utils'; | ||
| import { ExternalSourceEntry } from '../shared/external-source-entry.model'; | ||
| import { of as observableOf } from 'rxjs'; | ||
| import { GetRequest } from './request.models'; | ||
|
|
||
| describe('ExternalSourceService', () => { | ||
| let service: ExternalSourceService; | ||
|
|
||
| let requestService; | ||
| let rdbService; | ||
| let halService; | ||
|
|
||
| const entries = [ | ||
| Object.assign(new ExternalSourceEntry(), { | ||
| id: '0001-0001-0001-0001', | ||
| display: 'John Doe', | ||
| value: 'John, Doe', | ||
| metadata: { | ||
| 'dc.identifier.uri': [ | ||
| { | ||
| value: 'https://orcid.org/0001-0001-0001-0001' | ||
| } | ||
| ] | ||
| } | ||
| }), | ||
| Object.assign(new ExternalSourceEntry(), { | ||
| id: '0001-0001-0001-0002', | ||
| display: 'Sampson Megan', | ||
| value: 'Sampson, Megan', | ||
| metadata: { | ||
| 'dc.identifier.uri': [ | ||
| { | ||
| value: 'https://orcid.org/0001-0001-0001-0002' | ||
| } | ||
| ] | ||
| } | ||
| }) | ||
| ]; | ||
|
|
||
| function init() { | ||
| requestService = jasmine.createSpyObj('requestService', { | ||
| generateRequestId: 'request-uuid', | ||
| configure: {} | ||
| }); | ||
| rdbService = jasmine.createSpyObj('rdbService', { | ||
| buildList: createSuccessfulRemoteDataObject$(createPaginatedList(entries)) | ||
| }); | ||
| halService = jasmine.createSpyObj('halService', { | ||
| getEndpoint: observableOf('external-sources-REST-endpoint') | ||
| }); | ||
| service = new ExternalSourceService(requestService, rdbService, undefined, undefined, undefined, halService, undefined, undefined, undefined); | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| init(); | ||
| }); | ||
|
|
||
| describe('getExternalSourceEntries', () => { | ||
| let result; | ||
|
|
||
| beforeEach(() => { | ||
| result = service.getExternalSourceEntries('test'); | ||
| }); | ||
|
|
||
| it('should configure a GetRequest', () => { | ||
| expect(requestService.configure).toHaveBeenCalledWith(jasmine.any(GetRequest)); | ||
| }); | ||
|
|
||
| it('should return the entries', () => { | ||
| result.subscribe((resultRD) => { | ||
| expect(resultRD.payload.page).toBe(entries); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { Injectable } from '@angular/core'; | ||
| import { DataService } from './data.service'; | ||
| import { ExternalSource } from '../shared/external-source.model'; | ||
| import { RequestService } from './request.service'; | ||
| import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; | ||
| import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service'; | ||
| import { Store } from '@ngrx/store'; | ||
| import { CoreState } from '../core.reducers'; | ||
| import { ObjectCacheService } from '../cache/object-cache.service'; | ||
| import { HALEndpointService } from '../shared/hal-endpoint.service'; | ||
| import { NotificationsService } from '../../shared/notifications/notifications.service'; | ||
| import { HttpClient } from '@angular/common/http'; | ||
| import { FindListOptions, GetRequest } from './request.models'; | ||
| import { Observable } from 'rxjs/internal/Observable'; | ||
| import { distinctUntilChanged, map, switchMap } from 'rxjs/operators'; | ||
| import { PaginatedSearchOptions } from '../../shared/search/paginated-search-options.model'; | ||
| import { hasValue, isNotEmptyOperator } from '../../shared/empty.util'; | ||
| import { configureRequest } from '../shared/operators'; | ||
| import { RemoteData } from './remote-data'; | ||
| import { PaginatedList } from './paginated-list'; | ||
| import { ExternalSourceEntry } from '../shared/external-source-entry.model'; | ||
| import { DefaultChangeAnalyzer } from './default-change-analyzer.service'; | ||
|
|
||
| /** | ||
| * A service handling all external source requests | ||
| */ | ||
| @Injectable() | ||
| export class ExternalSourceService extends DataService<ExternalSource> { | ||
tdonohue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| protected linkPath = 'externalsources'; | ||
|
|
||
| constructor( | ||
| protected requestService: RequestService, | ||
| protected rdbService: RemoteDataBuildService, | ||
| protected dataBuildService: NormalizedObjectBuildService, | ||
| protected store: Store<CoreState>, | ||
| protected objectCache: ObjectCacheService, | ||
| protected halService: HALEndpointService, | ||
| protected notificationsService: NotificationsService, | ||
| protected http: HttpClient, | ||
| protected comparator: DefaultChangeAnalyzer<ExternalSource>) { | ||
| super(); | ||
| } | ||
|
|
||
| /** | ||
| * Get the endpoint to browse external sources | ||
| * @param options | ||
| * @param linkPath | ||
| */ | ||
| getBrowseEndpoint(options: FindListOptions = {}, linkPath: string = this.linkPath): Observable<string> { | ||
tdonohue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return this.halService.getEndpoint(linkPath); | ||
| } | ||
|
|
||
| /** | ||
| * Get the endpoint for an external source's entries | ||
| * @param externalSourceId The id of the external source to fetch entries for | ||
| */ | ||
| getEntriesEndpoint(externalSourceId: string): Observable<string> { | ||
| return this.getBrowseEndpoint().pipe( | ||
| map((href) => this.getIDHref(href, externalSourceId)), | ||
| switchMap((href) => this.halService.getEndpoint('entries', href)) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Get the entries for an external source | ||
| * @param externalSourceId The id of the external source to fetch entries for | ||
| * @param searchOptions The search options to limit results to | ||
| */ | ||
| getExternalSourceEntries(externalSourceId: string, searchOptions?: PaginatedSearchOptions): Observable<RemoteData<PaginatedList<ExternalSourceEntry>>> { | ||
| const requestUuid = this.requestService.generateRequestId(); | ||
|
|
||
| const href$ = this.getEntriesEndpoint(externalSourceId).pipe( | ||
| isNotEmptyOperator(), | ||
| distinctUntilChanged(), | ||
| map((endpoint: string) => hasValue(searchOptions) ? searchOptions.toRestUrl(endpoint) : endpoint) | ||
| ); | ||
|
|
||
| href$.pipe( | ||
| map((endpoint: string) => new GetRequest(requestUuid, endpoint)), | ||
| configureRequest(this.requestService) | ||
| ).subscribe(); | ||
|
|
||
| return this.rdbService.buildList(href$); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.