1
0

[CST-3088] Improved VocabularyFindOptions

This commit is contained in:
Giuseppe Digilio
2020-06-24 12:52:16 +02:00
parent 1156bd3934
commit c7cf11f421
4 changed files with 58 additions and 26 deletions

View File

@@ -0,0 +1,45 @@
import { SortOptions } from '../../../cache/models/sort-options.model';
import { FindListOptions } from '../../../data/request.models';
import { RequestParam } from '../../../cache/models/request-param.model';
import { isNotEmpty } from '../../../../shared/empty.util';
/**
* Representing properties used to build a vocabulary find request
*/
export class VocabularyFindOptions extends FindListOptions {
constructor(public collection: string = '',
public name: string = '',
public metadata: string = '',
public query: string = '',
public elementsPerPage?: number,
public currentPage?: number,
public sort?: SortOptions,
public filter?: string,
public exact?: string,
public entryID?: string,
) {
super();
const searchParams = [];
if (isNotEmpty(metadata)) {
searchParams.push(new RequestParam('metadata', metadata))
}
if (isNotEmpty(collection)) {
searchParams.push(new RequestParam('collection', collection))
}
if (isNotEmpty(query)) {
searchParams.push(new RequestParam('query', query))
}
if (isNotEmpty(filter)) {
searchParams.push(new RequestParam('filter', filter))
}
if (isNotEmpty(exact)) {
searchParams.push(new RequestParam('exact', exact))
}
if (isNotEmpty(entryID)) {
searchParams.push(new RequestParam('entryID', entryID))
}
this.searchParams = searchParams;
}
}

View File

@@ -4,7 +4,7 @@ import { DSpaceRESTV2Response } from '../../dspace-rest-v2/dspace-rest-v2-respon
import { VocabularyEntriesResponseParsingService } from './vocabulary-entries-response-parsing.service'; import { VocabularyEntriesResponseParsingService } from './vocabulary-entries-response-parsing.service';
import { VocabularyEntriesRequest } from '../../data/request.models'; import { VocabularyEntriesRequest } from '../../data/request.models';
fdescribe('VocabularyEntriesResponseParsingService', () => { describe('VocabularyEntriesResponseParsingService', () => {
let service: VocabularyEntriesResponseParsingService; let service: VocabularyEntriesResponseParsingService;
const metadata = 'dc.type'; const metadata = 'dc.type';
const collectionUUID = '8b39g7ya-5a4b-438b-851f-be1d5b4a1c5a'; const collectionUUID = '8b39g7ya-5a4b-438b-851f-be1d5b4a1c5a';

View File

@@ -19,6 +19,7 @@ import { RestResponse } from '../../cache/response.models';
import { VocabularyService } from './vocabulary.service'; import { VocabularyService } from './vocabulary.service';
import { getMockRequestService } from '../../../shared/mocks/request.service.mock'; import { getMockRequestService } from '../../../shared/mocks/request.service.mock';
import { getMockRemoteDataBuildService } from '../../../shared/mocks/remote-data-build.service.mock'; import { getMockRemoteDataBuildService } from '../../../shared/mocks/remote-data-build.service.mock';
import { VocabularyFindOptions } from './models/vocabulary-find-options.model';
describe('VocabularyService', () => { describe('VocabularyService', () => {
let scheduler: TestScheduler; let scheduler: TestScheduler;
@@ -95,6 +96,7 @@ describe('VocabularyService', () => {
const vocabularyId = 'types'; const vocabularyId = 'types';
const metadata = 'dc.type'; const metadata = 'dc.type';
const collectionUUID = '8b39g7ya-5a4b-438b-851f-be1d5b4a1c5a'; const collectionUUID = '8b39g7ya-5a4b-438b-851f-be1d5b4a1c5a';
const vocabularyOptions = new VocabularyFindOptions(collectionUUID, vocabularyId, metadata);
const searchRequestURL = `https://rest.api/rest/api/submission/vocabularies/search/byMetadataAndCollection?metadata=${metadata}&collection=${collectionUUID}`; const searchRequestURL = `https://rest.api/rest/api/submission/vocabularies/search/byMetadataAndCollection?metadata=${metadata}&collection=${collectionUUID}`;
const entriesRequestURL = `https://rest.api/rest/api/submission/vocabularies/${vocabulary.id}/entries?metadata=${metadata}&collection=${collectionUUID}`; const entriesRequestURL = `https://rest.api/rest/api/submission/vocabularies/${vocabulary.id}/entries?metadata=${metadata}&collection=${collectionUUID}`;
@@ -223,14 +225,14 @@ describe('VocabularyService', () => {
new RequestParam('metadata', metadata), new RequestParam('metadata', metadata),
new RequestParam('collection', collectionUUID) new RequestParam('collection', collectionUUID)
]; ];
scheduler.schedule(() => service.searchByMetadataAndCollection(metadata, collectionUUID).subscribe()); scheduler.schedule(() => service.searchByMetadataAndCollection(vocabularyOptions).subscribe());
scheduler.flush(); scheduler.flush();
expect((service as any).dataService.findByHref).toHaveBeenCalledWith(searchRequestURL); expect((service as any).dataService.findByHref).toHaveBeenCalledWith(searchRequestURL);
}); });
it('should return a RemoteData<Vocabulary> for the search', () => { it('should return a RemoteData<Vocabulary> for the search', () => {
const result = service.searchByMetadataAndCollection(metadata, collectionUUID); const result = service.searchByMetadataAndCollection(vocabularyOptions);
const expected = cold('a|', { const expected = cold('a|', {
a: vocabularyRD a: vocabularyRD
}); });
@@ -251,14 +253,14 @@ describe('VocabularyService', () => {
it('should configure a new VocabularyEntriesRequest', () => { it('should configure a new VocabularyEntriesRequest', () => {
const expected = new VocabularyEntriesRequest(requestService.generateRequestId(), entriesRequestURL); const expected = new VocabularyEntriesRequest(requestService.generateRequestId(), entriesRequestURL);
scheduler.schedule(() => service.getVocabularyEntries(vocabularyId, metadata, collectionUUID).subscribe()); scheduler.schedule(() => service.getVocabularyEntries(vocabularyOptions).subscribe());
scheduler.flush(); scheduler.flush();
expect(requestService.configure).toHaveBeenCalledWith(expected); expect(requestService.configure).toHaveBeenCalledWith(expected);
}); });
it('should call RemoteDataBuildService to create the RemoteData Observable', () => { it('should call RemoteDataBuildService to create the RemoteData Observable', () => {
service.getVocabularyEntries(vocabularyId, metadata, collectionUUID); service.getVocabularyEntries(vocabularyOptions);
expect(rdbService.toRemoteDataObservable).toHaveBeenCalled(); expect(rdbService.toRemoteDataObservable).toHaveBeenCalled();

View File

@@ -19,13 +19,13 @@ import { NotificationsService } from '../../../shared/notifications/notification
import { ChangeAnalyzer } from '../../data/change-analyzer'; import { ChangeAnalyzer } from '../../data/change-analyzer';
import { DefaultChangeAnalyzer } from '../../data/default-change-analyzer.service'; import { DefaultChangeAnalyzer } from '../../data/default-change-analyzer.service';
import { PaginatedList } from '../../data/paginated-list'; import { PaginatedList } from '../../data/paginated-list';
import { RequestParam } from '../../cache/models/request-param.model';
import { Vocabulary } from './models/vocabulary.model'; import { Vocabulary } from './models/vocabulary.model';
import { VOCABULARY } from './models/vocabularies.resource-type'; import { VOCABULARY } from './models/vocabularies.resource-type';
import { VocabularyEntry } from './models/vocabulary-entry.model'; import { VocabularyEntry } from './models/vocabulary-entry.model';
import { hasValue, isNotEmptyOperator } from '../../../shared/empty.util'; import { hasValue, isNotEmptyOperator } from '../../../shared/empty.util';
import { configureRequest, filterSuccessfulResponses, getRequestFromRequestHref } from '../../shared/operators'; import { configureRequest, filterSuccessfulResponses, getRequestFromRequestHref } from '../../shared/operators';
import { GenericSuccessResponse } from '../../cache/response.models'; import { GenericSuccessResponse } from '../../cache/response.models';
import { VocabularyFindOptions } from './models/vocabulary-find-options.model';
/* tslint:disable:max-classes-per-file */ /* tslint:disable:max-classes-per-file */
@@ -111,22 +111,13 @@ export class VocabularyService {
/** /**
* Return the {@link VocabularyEntry} list for a given {@link Vocabulary} * Return the {@link VocabularyEntry} list for a given {@link Vocabulary}
* *
* @param id The vocabulary id to retrieve the entries for * @param options The {@link VocabularyFindOptions} for the request
* @param metadata The metadata name
* @param collectionUUID The collection UUID
* @param options The {@link FindListOptions} for the request
* @return {Observable<RemoteData<PaginatedList<VocabularyEntry>>>} * @return {Observable<RemoteData<PaginatedList<VocabularyEntry>>>}
* Return an observable that emits object list * Return an observable that emits object list
*/ */
getVocabularyEntries(id: string, metadata: string, collectionUUID: string, options: FindListOptions = {}): Observable<RemoteData<PaginatedList<VocabularyEntry>>> { getVocabularyEntries(options: VocabularyFindOptions): Observable<RemoteData<PaginatedList<VocabularyEntry>>> {
options = Object.assign({}, options, {
searchParams: [
new RequestParam('metadata', metadata),
new RequestParam('collection', collectionUUID)
]
});
return this.dataService.getFindAllHref(options, `${id}/entries`).pipe( return this.dataService.getFindAllHref(options, `${options.name}/entries`).pipe(
isNotEmptyOperator(), isNotEmptyOperator(),
distinctUntilChanged(), distinctUntilChanged(),
getVocabularyEntriesFor(this.requestService, this.rdbService) getVocabularyEntriesFor(this.requestService, this.rdbService)
@@ -136,18 +127,12 @@ export class VocabularyService {
/** /**
* Return the controlled {@link Vocabulary} configured for the specified metadata and collection if any. * Return the controlled {@link Vocabulary} configured for the specified metadata and collection if any.
* *
* @param metadata The metadata name * @param options The {@link VocabularyFindOptions} for the request
* @param collectionUUID The collection UUID
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved * @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved
* @return {Observable<RemoteData<PaginatedList<Vocabulary>>>} * @return {Observable<RemoteData<PaginatedList<Vocabulary>>>}
* Return an observable that emits object list * Return an observable that emits object list
*/ */
searchByMetadataAndCollection(metadata: string, collectionUUID: string, ...linksToFollow: Array<FollowLinkConfig<Vocabulary>>): Observable<RemoteData<Vocabulary>> { searchByMetadataAndCollection(options: VocabularyFindOptions, ...linksToFollow: Array<FollowLinkConfig<Vocabulary>>): Observable<RemoteData<Vocabulary>> {
const options = new FindListOptions();
options.searchParams = [
new RequestParam('metadata', metadata),
new RequestParam('collection', collectionUUID)
];
return this.dataService.getSearchByHref(this.searchByMetadataAndCollectionMethod, options).pipe( return this.dataService.getSearchByHref(this.searchByMetadataAndCollectionMethod, options).pipe(
first((href: string) => hasValue(href)), first((href: string) => hasValue(href)),