93803: Rename findAllByHref to findListByHref

To avoid confusion with FindAllData:
- findAll is a "feature" to retrieve all resources from the endpoint itself ~ a plain GET
- findAllByHref is retrieves lists of resources in general
This commit is contained in:
Yura Bondarenko
2022-08-24 17:05:08 +02:00
parent ad316f7316
commit 05b131edb9
49 changed files with 111 additions and 111 deletions

View File

@@ -370,7 +370,7 @@ describe('BaseDataService', () => {
});
describe(`findAllByHref`, () => {
describe(`findListByHref`, () => {
let findListOptions;
beforeEach(() => {
findListOptions = { currentPage: 5 };
@@ -383,7 +383,7 @@ describe('BaseDataService', () => {
spyOn(rdbService, 'buildList').and.returnValue(cold('a', { a: remoteDataMocks.Success }));
spyOn(service as any, 'reRequestStaleRemoteData').and.returnValue(() => cold('a', { a: remoteDataMocks.Success }));
service.findAllByHref(selfLink, findListOptions, true, true, ...linksToFollow);
service.findListByHref(selfLink, findListOptions, true, true, ...linksToFollow);
expect(service.buildHrefFromFindOptions).toHaveBeenCalledWith(selfLink, findListOptions, [], ...linksToFollow);
});
});
@@ -394,11 +394,11 @@ describe('BaseDataService', () => {
spyOn(rdbService, 'buildList').and.returnValue(cold('a', { a: remoteDataMocks.Success }));
spyOn(service as any, 'reRequestStaleRemoteData').and.returnValue(() => cold('a', { a: remoteDataMocks.Success }));
service.findAllByHref(selfLink, findListOptions, true, true, ...linksToFollow);
service.findListByHref(selfLink, findListOptions, true, true, ...linksToFollow);
expect((service as any).createAndSendGetRequest).toHaveBeenCalledWith(jasmine.anything(), true);
expectObservable(rdbService.buildList.calls.argsFor(0)[0]).toBe('(a|)', { a: 'bingo!' });
service.findAllByHref(selfLink, findListOptions, false, true, ...linksToFollow);
service.findListByHref(selfLink, findListOptions, false, true, ...linksToFollow);
expect((service as any).createAndSendGetRequest).toHaveBeenCalledWith(jasmine.anything(), false);
expectObservable(rdbService.buildList.calls.argsFor(1)[0]).toBe('(a|)', { a: 'bingo!' });
});
@@ -410,29 +410,29 @@ describe('BaseDataService', () => {
spyOn(rdbService, 'buildList').and.returnValue(cold('a', { a: remoteDataMocks.Success }));
spyOn(service as any, 'reRequestStaleRemoteData').and.returnValue(() => cold('a', { a: remoteDataMocks.Success }));
service.findAllByHref(selfLink, findListOptions, true, true, ...linksToFollow);
service.findListByHref(selfLink, findListOptions, true, true, ...linksToFollow);
expect(rdbService.buildList).toHaveBeenCalledWith(jasmine.anything() as any, ...linksToFollow);
expectObservable(rdbService.buildList.calls.argsFor(0)[0]).toBe('(a|)', { a: 'bingo!' });
});
});
it(`should call reRequestStaleRemoteData with reRequestOnStale and the exact same findAllByHref call as a callback`, () => {
it(`should call reRequestStaleRemoteData with reRequestOnStale and the exact same findListByHref call as a callback`, () => {
testScheduler.run(({ cold, expectObservable }) => {
spyOn(service, 'buildHrefFromFindOptions').and.returnValue('bingo!');
spyOn(rdbService, 'buildList').and.returnValue(cold('a', { a: remoteDataMocks.SuccessStale }));
spyOn(service as any, 'reRequestStaleRemoteData').and.returnValue(() => cold('a', { a: remoteDataMocks.SuccessStale }));
service.findAllByHref(selfLink, findListOptions, true, true, ...linksToFollow);
service.findListByHref(selfLink, findListOptions, true, true, ...linksToFollow);
expect((service as any).reRequestStaleRemoteData.calls.argsFor(0)[0]).toBeTrue();
spyOn(service, 'findAllByHref').and.returnValue(cold('a', { a: remoteDataMocks.SuccessStale }));
spyOn(service, 'findListByHref').and.returnValue(cold('a', { a: remoteDataMocks.SuccessStale }));
// prove that the spy we just added hasn't been called yet
expect(service.findAllByHref).not.toHaveBeenCalled();
expect(service.findListByHref).not.toHaveBeenCalled();
// call the callback passed to reRequestStaleRemoteData
(service as any).reRequestStaleRemoteData.calls.argsFor(0)[1]();
// verify that findAllByHref _has_ been called now, with the same params as the original call
expect(service.findAllByHref).toHaveBeenCalledWith(jasmine.anything(), findListOptions, true, true, ...linksToFollow);
// verify that findListByHref _has_ been called now, with the same params as the original call
expect(service.findListByHref).toHaveBeenCalledWith(jasmine.anything(), findListOptions, true, true, ...linksToFollow);
// ... except for selflink, which will have been turned in to an observable.
expectObservable((service.findAllByHref as jasmine.Spy).calls.argsFor(0)[0]).toBe('(a|)', { a: selfLink });
expectObservable((service.findListByHref as jasmine.Spy).calls.argsFor(0)[0]).toBe('(a|)', { a: selfLink });
});
});
@@ -446,7 +446,7 @@ describe('BaseDataService', () => {
a: 'bingo!',
};
expectObservable(service.findAllByHref(selfLink, findListOptions, true, true, ...linksToFollow)).toBe(expected, values);
expectObservable(service.findListByHref(selfLink, findListOptions, true, true, ...linksToFollow)).toBe(expected, values);
});
});
@@ -474,7 +474,7 @@ describe('BaseDataService', () => {
e: remoteDataMocks.SuccessStale,
};
expectObservable(service.findAllByHref(selfLink, findListOptions, true, true, ...linksToFollow)).toBe(expected, values);
expectObservable(service.findListByHref(selfLink, findListOptions, true, true, ...linksToFollow)).toBe(expected, values);
});
});
@@ -495,7 +495,7 @@ describe('BaseDataService', () => {
e: remoteDataMocks.SuccessStale,
};
expectObservable(service.findAllByHref(selfLink, findListOptions, true, true, ...linksToFollow)).toBe(expected, values);
expectObservable(service.findListByHref(selfLink, findListOptions, true, true, ...linksToFollow)).toBe(expected, values);
});
});
@@ -525,7 +525,7 @@ describe('BaseDataService', () => {
e: remoteDataMocks.SuccessStale,
};
expectObservable(service.findAllByHref(selfLink, findListOptions, false, true, ...linksToFollow)).toBe(expected, values);
expectObservable(service.findListByHref(selfLink, findListOptions, false, true, ...linksToFollow)).toBe(expected, values);
});
});
@@ -546,7 +546,7 @@ describe('BaseDataService', () => {
e: remoteDataMocks.SuccessStale,
};
expectObservable(service.findAllByHref(selfLink, findListOptions, false, true, ...linksToFollow)).toBe(expected, values);
expectObservable(service.findListByHref(selfLink, findListOptions, false, true, ...linksToFollow)).toBe(expected, values);
});
});

View File

@@ -287,7 +287,7 @@ export class BaseDataService<T extends CacheableObject> implements HALDataServic
* @param reRequestOnStale Whether or not the request should automatically be re-requested after the response becomes stale
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved
*/
findAllByHref(href$: string | Observable<string>, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<T>[]): Observable<RemoteData<PaginatedList<T>>> {
findListByHref(href$: string | Observable<string>, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<T>[]): Observable<RemoteData<PaginatedList<T>>> {
if (typeof href$ === 'string') {
href$ = observableOf(href$);
}
@@ -307,7 +307,7 @@ export class BaseDataService<T extends CacheableObject> implements HALDataServic
// cached completed object
skipWhile((rd: RemoteData<PaginatedList<T>>) => useCachedVersionIfAvailable ? rd.isStale : rd.hasCompleted),
this.reRequestStaleRemoteData(reRequestOnStale, () =>
this.findAllByHref(href$, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow)),
this.findListByHref(href$, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow)),
);
}

View File

@@ -85,7 +85,7 @@ export class FindAllDataImpl<T extends CacheableObject> extends BaseDataService<
* Return an observable that emits object list
*/
findAll(options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<T>[]): Observable<RemoteData<PaginatedList<T>>> {
return this.findAllByHref(this.getFindAllHref(options), options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
return this.findListByHref(this.getFindAllHref(options), options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
/**

View File

@@ -37,5 +37,5 @@ export interface HALDataService<T extends HALResource> {
* @param reRequestOnStale Whether or not the request should automatically be re-requested after the response becomes stale
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved
*/
findAllByHref(href$: string | Observable<string>, findListOptions?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<T>[]): Observable<RemoteData<PaginatedList<T>>>;
findListByHref(href$: string | Observable<string>, findListOptions?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<T>[]): Observable<RemoteData<PaginatedList<T>>>;
}

View File

@@ -110,7 +110,7 @@ export class SearchDataImpl<T extends CacheableObject> extends BaseDataService<T
searchBy(searchMethod: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<T>[]): Observable<RemoteData<PaginatedList<T>>> {
const hrefObs = this.getSearchByHref(searchMethod, options, ...linksToFollow);
return this.findAllByHref(hrefObs, undefined, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
return this.findListByHref(hrefObs, undefined, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
/**

View File

@@ -76,7 +76,7 @@ export class BitstreamDataService extends IdentifiableDataService<Bitstream> imp
* {@link HALLink}s should be automatically resolved
*/
findAllByBundle(bundle: Bundle, options?: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Bitstream>[]): Observable<RemoteData<PaginatedList<Bitstream>>> {
return this.findAllByHref(bundle._links.bitstreams.href, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
return this.findListByHref(bundle._links.bitstreams.href, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
/**

View File

@@ -73,12 +73,12 @@ describe('BundleDataService', () => {
describe('findAllByItem', () => {
beforeEach(() => {
spyOn(service, 'findAllByHref');
spyOn(service, 'findListByHref');
service.findAllByItem(item);
});
it('should call findAllByHref with the item\'s bundles link', () => {
expect(service.findAllByHref).toHaveBeenCalledWith(bundleLink, undefined, true, true);
it('should call findListByHref with the item\'s bundles link', () => {
expect(service.findListByHref).toHaveBeenCalledWith(bundleLink, undefined, true, true);
});
});

View File

@@ -61,7 +61,7 @@ export class BundleDataService extends IdentifiableDataService<Bundle> implement
* {@link HALLink}s should be automatically resolved
*/
findAllByItem(item: Item, options?: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Bundle>[]): Observable<RemoteData<PaginatedList<Bundle>>> {
return this.findAllByHref(item._links.bundles.href, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
return this.findListByHref(item._links.bundles.href, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
/**

View File

@@ -280,7 +280,7 @@ export class CollectionDataService extends ComColDataService<Collection> {
* @param findListOptions Pagination and search options.
*/
findMappedCollectionsFor(item: Item, findListOptions?: FindListOptions): Observable<RemoteData<PaginatedList<Collection>>> {
return this.findAllByHref(item._links.mappedCollections.href, findListOptions);
return this.findListByHref(item._links.mappedCollections.href, findListOptions);
}

View File

@@ -98,7 +98,7 @@ export abstract class ComColDataService<T extends Community | Collection> extend
const href$ = this.getFindByParentHref(parentUUID).pipe(
map((href: string) => this.buildHrefFromFindOptions(href, options))
);
return this.findAllByHref(href$, options, true, true, ...linksToFollow);
return this.findListByHref(href$, options, true, true, ...linksToFollow);
}
/**

View File

@@ -42,7 +42,7 @@ export class CommunityDataService extends ComColDataService<Community> {
findTop(options: FindListOptions = {}, ...linksToFollow: FollowLinkConfig<Community>[]): Observable<RemoteData<PaginatedList<Community>>> {
const hrefObs = this.getFindAllHref(options, this.topLinkPath);
return this.findAllByHref(hrefObs, undefined, true, true, ...linksToFollow);
return this.findListByHref(hrefObs, undefined, true, true, ...linksToFollow);
}
protected getFindByParentHref(parentUUID: string): Observable<string> {

View File

@@ -145,7 +145,7 @@ export class EntityTypeService extends BaseDataService<ItemType> implements Find
*/
getEntityTypeRelationships(entityTypeId: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<RelationshipType>[]): Observable<RemoteData<PaginatedList<RelationshipType>>> {
const href$ = this.getRelationshipTypesEndpoint(entityTypeId);
return this.relationshipTypeService.findAllByHref(href$, undefined, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
return this.relationshipTypeService.findListByHref(href$, undefined, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
/**

View File

@@ -74,7 +74,7 @@ export class ExternalSourceService extends IdentifiableDataService<ExternalSourc
);
// TODO create a dedicated ExternalSourceEntryDataService and move this entire method to it. Then the "as any"s won't be necessary
return this.findAllByHref(href$, undefined, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow as any) as any;
return this.findListByHref(href$, undefined, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow as any) as any;
}
/**

View File

@@ -48,33 +48,33 @@ describe(`HrefOnlyDataService`, () => {
});
});
describe(`findAllByHref`, () => {
describe(`findListByHref`, () => {
beforeEach(() => {
spy = spyOn((service as any).dataService, 'findAllByHref').and.returnValue(createSuccessfulRemoteDataObject$(null));
spy = spyOn((service as any).dataService, 'findListByHref').and.returnValue(createSuccessfulRemoteDataObject$(null));
});
it(`should delegate to findAllByHref on the internal DataService`, () => {
service.findAllByHref(href, findListOptions, false, false, ...followLinks);
it(`should delegate to findListByHref on the internal DataService`, () => {
service.findListByHref(href, findListOptions, false, false, ...followLinks);
expect(spy).toHaveBeenCalledWith(href, findListOptions, false, false, ...followLinks);
});
describe(`when findListOptions is omitted`, () => {
it(`should call findAllByHref on the internal DataService with findListOptions = {}`, () => {
service.findAllByHref(href);
it(`should call findListByHref on the internal DataService with findListOptions = {}`, () => {
service.findListByHref(href);
expect(spy).toHaveBeenCalledWith(jasmine.anything(), {}, jasmine.anything(), jasmine.anything());
});
});
describe(`when useCachedVersionIfAvailable is omitted`, () => {
it(`should call findAllByHref on the internal DataService with useCachedVersionIfAvailable = true`, () => {
service.findAllByHref(href);
it(`should call findListByHref on the internal DataService with useCachedVersionIfAvailable = true`, () => {
service.findListByHref(href);
expect(spy).toHaveBeenCalledWith(jasmine.anything(), jasmine.anything(), true, jasmine.anything());
});
});
describe(`when reRequestOnStale is omitted`, () => {
it(`should call findAllByHref on the internal DataService with reRequestOnStale = true`, () => {
service.findAllByHref(href);
it(`should call findListByHref on the internal DataService with reRequestOnStale = true`, () => {
service.findListByHref(href);
expect(spy).toHaveBeenCalledWith(jasmine.anything(), jasmine.anything(), jasmine.anything(), true);
});
});

View File

@@ -27,8 +27,8 @@ import { dataService } from './base/data-service.decorator';
* Additionally, this service may be used to retrieve objects by `href` regardless of their type
* For example
* ```
* const items$: Observable<RemoteData<PaginatedList<Item>>> = hrefOnlyDataService.findAllByHref<Item>(href);
* const sites$: Observable<RemoteData<PaginatedList<Site>>> = hrefOnlyDataService.findAllByHref<Site>(href);
* const items$: Observable<RemoteData<PaginatedList<Item>>> = hrefOnlyDataService.findListByHref<Item>(href);
* const sites$: Observable<RemoteData<PaginatedList<Site>>> = hrefOnlyDataService.findListByHref<Site>(href);
* ```
* This means we cannot extend from {@link BaseDataService} directly because the method signatures would not match.
*/
@@ -82,7 +82,7 @@ export class HrefOnlyDataService implements HALDataService<any> {
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
* {@link HALLink}s should be automatically resolved
*/
findAllByHref<T extends CacheableObject>(href: string | Observable<string>, findListOptions: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<T>[]): Observable<RemoteData<PaginatedList<T>>> {
return this.dataService.findAllByHref(href, findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
findListByHref<T extends CacheableObject>(href: string | Observable<string>, findListOptions: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<T>[]): Observable<RemoteData<PaginatedList<T>>> {
return this.dataService.findListByHref(href, findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
}

View File

@@ -50,7 +50,7 @@ export class ProcessDataService extends IdentifiableDataService<Process> impleme
*/
getFiles(processId: string): Observable<RemoteData<PaginatedList<Bitstream>>> {
const href$ = this.getFilesEndpoint(processId);
return this.bitstreamDataService.findAllByHref(href$);
return this.bitstreamDataService.findListByHref(href$);
}
/**

View File

@@ -196,7 +196,7 @@ export class RelationshipService extends IdentifiableDataService<Relationship> i
* should be automatically resolved
*/
getItemRelationshipsArray(item: Item, ...linksToFollow: FollowLinkConfig<Relationship>[]): Observable<Relationship[]> {
return this.findAllByHref(item._links.relationships.href, undefined, true, false, ...linksToFollow).pipe(
return this.findListByHref(item._links.relationships.href, undefined, true, false, ...linksToFollow).pipe(
getFirstSucceededRemoteData(),
getRemoteDataPayload(),
map((rels: PaginatedList<Relationship>) => rels.page),

View File

@@ -106,7 +106,7 @@ describe('VersionHistoryDataService', () => {
});
versionService = jasmine.createSpyObj('objectCache', {
findByHref: jasmine.createSpy('findByHref'),
findAllByHref: jasmine.createSpy('findAllByHref'),
findListByHref: jasmine.createSpy('findListByHref'),
getHistoryFromVersion: jasmine.createSpy('getHistoryFromVersion'),
});
halService = new HALEndpointServiceStub(url);
@@ -132,8 +132,8 @@ describe('VersionHistoryDataService', () => {
result = service.getVersions('1');
});
it('should call versionService.findAllByHref', () => {
expect(versionService.findAllByHref).toHaveBeenCalled();
it('should call versionService.findListByHref', () => {
expect(versionService.findListByHref).toHaveBeenCalled();
});
});
@@ -141,8 +141,8 @@ describe('VersionHistoryDataService', () => {
beforeEach(waitForAsync(() => {
service.getVersions(versionHistoryId);
}));
it('findAllByHref should have been called', () => {
expect(versionService.findAllByHref).toHaveBeenCalled();
it('findListByHref should have been called', () => {
expect(versionService.findListByHref).toHaveBeenCalled();
});
});

View File

@@ -77,7 +77,7 @@ export class VersionHistoryDataService extends IdentifiableDataService<VersionHi
map((href) => searchOptions ? searchOptions.toRestUrl(href) : href)
);
return this.versionDataService.findAllByHref(hrefObs, undefined, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
return this.versionDataService.findListByHref(hrefObs, undefined, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
/**