64574: relationship-service's getRelatedItemsByLabel returns paginated list using new REST API search endpoint + test cases on publication pages

This commit is contained in:
Kristof De Langhe
2019-08-26 17:51:42 +02:00
parent 7d0439b006
commit 02cf98c759
7 changed files with 91 additions and 34 deletions

View File

@@ -10,7 +10,7 @@ import {
getRemoteDataPayload, getResponseFromEntry,
getSucceededRemoteData
} from '../shared/operators';
import { DeleteRequest, RestRequest } from './request.models';
import { DeleteRequest, FindAllOptions, RestRequest } from './request.models';
import { Observable } from 'rxjs/internal/Observable';
import { RestResponse } from '../cache/response.models';
import { Item } from '../shared/item.model';
@@ -22,23 +22,42 @@ import { zip as observableZip } from 'rxjs';
import { PaginatedList } from './paginated-list';
import { ItemDataService } from './item-data.service';
import {
compareArraysUsingIds, filterRelationsByTypeLabel,
compareArraysUsingIds, filterRelationsByTypeLabel, paginatedRelationsToItems,
relationsToItems
} from '../../+item-page/simple/item-types/shared/item-relationships-utils';
import { ObjectCacheService } from '../cache/object-cache.service';
import { DataService } from './data.service';
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
import { Store } from '@ngrx/store';
import { CoreState } from '../core.reducers';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { HttpClient } from '@angular/common/http';
import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
import { SearchParam } from '../cache/models/search-param.model';
/**
* The service handling all relationship requests
*/
@Injectable()
export class RelationshipService {
export class RelationshipService extends DataService<Relationship> {
protected linkPath = 'relationships';
protected forceBypassCache = false;
constructor(protected requestService: RequestService,
protected halService: HALEndpointService,
constructor(protected itemService: ItemDataService,
protected requestService: RequestService,
protected rdbService: RemoteDataBuildService,
protected itemService: ItemDataService,
protected objectCache: ObjectCacheService) {
protected dataBuildService: NormalizedObjectBuildService,
protected store: Store<CoreState>,
protected halService: HALEndpointService,
protected objectCache: ObjectCacheService,
protected notificationsService: NotificationsService,
protected http: HttpClient,
protected comparator: DefaultChangeAnalyzer<Relationship>) {
super();
}
getBrowseEndpoint(options: FindAllOptions = {}, linkPath: string = this.linkPath): Observable<string> {
return this.halService.getEndpoint(linkPath);
}
/**
@@ -208,11 +227,20 @@ export class RelationshipService {
* @param item
* @param label
*/
getRelatedItemsByLabel(item: Item, label: string): Observable<Item[]> {
return this.getItemResolvedRelsAndTypes(item).pipe(
filterRelationsByTypeLabel(label),
relationsToItems(item.uuid)
);
getRelatedItemsByLabel(item: Item, label: string): Observable<RemoteData<PaginatedList<Item>>> {
return this.getItemRelationshipsByLabel(item, label).pipe(paginatedRelationsToItems(item.uuid));
}
/**
* Resolve a given item's relationships into related items, filtered by a relationship label
* and return the items as an array
* @param item
* @param label
*/
getItemRelationshipsByLabel(item: Item, label: string): Observable<RemoteData<PaginatedList<Relationship>>> {
const options = new FindAllOptions();
options.searchParams = [ new SearchParam('label', label), new SearchParam('dso', item.id) ];
return this.searchBy('byLabel', options);
}
/**