diff --git a/src/app/core/cache/models/request-param.model.ts b/src/app/core/cache/models/request-param.model.ts index ac21fe0b8a8..b78fa45e337 100644 --- a/src/app/core/cache/models/request-param.model.ts +++ b/src/app/core/cache/models/request-param.model.ts @@ -1,9 +1,14 @@ - /** * Class representing a query parameter (query?fieldName=fieldValue) used in FindListOptions object */ export class RequestParam { - constructor(public fieldName: string, public fieldValue: any) { - + constructor( + public fieldName: string, + public fieldValue: any, + public encodeValue = true, + ) { + if (encodeValue) { + this.fieldValue = encodeURIComponent(fieldValue); + } } } diff --git a/src/app/core/data/relationship-data.service.ts b/src/app/core/data/relationship-data.service.ts index 46a51a2d010..00ef14548ad 100644 --- a/src/app/core/data/relationship-data.service.ts +++ b/src/app/core/data/relationship-data.service.ts @@ -492,40 +492,18 @@ export class RelationshipDataService extends IdentifiableDataService>> { - - const searchParams = [ - { - fieldName: 'typeId', - fieldValue: typeId - }, - { - fieldName: 'focusItem', - fieldValue: itemUuid - }, - { - fieldName: 'relationshipLabel', - fieldValue: relationshipLabel - }, - { - fieldName: 'size', - fieldValue: arrayOfItemIds.length - }, - { - fieldName: 'embed', - fieldValue: 'leftItem' - }, - { - fieldName: 'embed', - fieldValue: 'rightItem' - }, - ]; + const searchParams: RequestParam[] = [ + new RequestParam('typeId', typeId), + new RequestParam('focusItem', itemUuid), + new RequestParam('relationshipLabel', relationshipLabel), + new RequestParam('size', arrayOfItemIds.length), + new RequestParam('embed', 'leftItem'), + new RequestParam('embed', 'rightItem'), + ]; arrayOfItemIds.forEach( (itemId) => { searchParams.push( - { - fieldName: 'relatedItem', - fieldValue: itemId, - } + new RequestParam('relatedItem', itemId), ); }); diff --git a/src/app/core/data/relationship-type-data.service.ts b/src/app/core/data/relationship-type-data.service.ts index 3020e52d47d..81612d02780 100644 --- a/src/app/core/data/relationship-type-data.service.ts +++ b/src/app/core/data/relationship-type-data.service.ts @@ -17,6 +17,7 @@ import { FindAllDataImpl } from './base/find-all-data'; import { SearchDataImpl } from './base/search-data'; import { ObjectCacheService } from '../cache/object-cache.service'; import { dataService } from './base/data-service.decorator'; +import { RequestParam } from '../cache/models/request-param.model'; /** * Check if one side of a RelationshipType is the ItemType with the given label @@ -130,14 +131,8 @@ export class RelationshipTypeDataService extends BaseDataService { it('search by default scope (byMetadata) and no query', () => { service.searchByScope(null, ''); const options = Object.assign(new FindListOptions(), { - searchParams: [Object.assign(new RequestParam('query', encodeURIComponent('')))] + searchParams: [Object.assign(new RequestParam('query', ''))], }); expect(service.searchBy).toHaveBeenCalledWith('byMetadata', options, true, true); }); @@ -104,7 +104,7 @@ describe('EPersonDataService', () => { it('search metadata scope and no query', () => { service.searchByScope('metadata', ''); const options = Object.assign(new FindListOptions(), { - searchParams: [Object.assign(new RequestParam('query', encodeURIComponent('')))] + searchParams: [Object.assign(new RequestParam('query', ''))], }); expect(service.searchBy).toHaveBeenCalledWith('byMetadata', options, true, true); }); @@ -112,7 +112,7 @@ describe('EPersonDataService', () => { it('search metadata scope and with query', () => { service.searchByScope('metadata', 'test'); const options = Object.assign(new FindListOptions(), { - searchParams: [Object.assign(new RequestParam('query', encodeURIComponent('test')))] + searchParams: [Object.assign(new RequestParam('query', 'test'))], }); expect(service.searchBy).toHaveBeenCalledWith('byMetadata', options, true, true); }); @@ -122,7 +122,7 @@ describe('EPersonDataService', () => { spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(null)); service.searchByScope('email', ''); const options = Object.assign(new FindListOptions(), { - searchParams: [Object.assign(new RequestParam('email', encodeURIComponent('')))] + searchParams: [Object.assign(new RequestParam('email', ''))], }); expect((service as any).searchData.getSearchByHref).toHaveBeenCalledWith('byEmail', options); expect(service.findByHref).toHaveBeenCalledWith(epersonsEndpoint, true, true); @@ -133,7 +133,7 @@ describe('EPersonDataService', () => { spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(EPersonMock)); service.searchByScope('email', EPersonMock.email); const options = Object.assign(new FindListOptions(), { - searchParams: [Object.assign(new RequestParam('email', encodeURIComponent(EPersonMock.email)))] + searchParams: [Object.assign(new RequestParam('email', EPersonMock.email))], }); expect((service as any).searchData.getSearchByHref).toHaveBeenCalledWith('byEmail', options); expect(service.findByHref).toHaveBeenCalledWith(epersonsEndpoint, true, true); diff --git a/src/app/core/eperson/eperson-data.service.ts b/src/app/core/eperson/eperson-data.service.ts index d30030365ca..00e55ab97f0 100644 --- a/src/app/core/eperson/eperson-data.service.ts +++ b/src/app/core/eperson/eperson-data.service.ts @@ -130,7 +130,7 @@ export class EPersonDataService extends IdentifiableDataService impleme */ public getEPersonByEmail(query: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig[]): Observable> { const findListOptions = new FindListOptions(); - findListOptions.searchParams = [new RequestParam('email', encodeURIComponent(query))]; + findListOptions.searchParams = [new RequestParam('email', query)]; const href$ = this.searchData.getSearchByHref(this.searchByEmailPath, findListOptions, ...linksToFollow); return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); } @@ -147,7 +147,7 @@ export class EPersonDataService extends IdentifiableDataService impleme * {@link HALLink}s should be automatically resolved */ private getEpeopleByMetadata(query: string, options?: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig[]): Observable>> { - const searchParams = [new RequestParam('query', encodeURIComponent(query))]; + const searchParams = [new RequestParam('query', query)]; return this.getEPeopleBy(searchParams, this.searchByMetadataPath, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); } diff --git a/src/app/core/statistics/usage-report-data.service.ts b/src/app/core/statistics/usage-report-data.service.ts index fde82984888..5ce186f4ca6 100644 --- a/src/app/core/statistics/usage-report-data.service.ts +++ b/src/app/core/statistics/usage-report-data.service.ts @@ -15,6 +15,7 @@ import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model'; import { RemoteData } from '../data/remote-data'; import { PaginatedList } from '../data/paginated-list.model'; import { dataService } from '../data/base/data-service.decorator'; +import { RequestParam } from '../cache/models/request-param.model'; /** * A service to retrieve {@link UsageReport}s from the REST API @@ -45,10 +46,7 @@ export class UsageReportDataService extends IdentifiableDataService searchStatistics(uri: string, page: number, size: number): Observable { return this.searchBy('object', { searchParams: [ - { - fieldName: `uri`, - fieldValue: uri, - }, + new RequestParam('uri', uri), ], currentPage: page, elementsPerPage: size, diff --git a/src/app/core/submission/submission-cc-license-url-data.service.ts b/src/app/core/submission/submission-cc-license-url-data.service.ts index 3d5dedb505c..5ccaf9bc4dd 100644 --- a/src/app/core/submission/submission-cc-license-url-data.service.ts +++ b/src/app/core/submission/submission-cc-license-url-data.service.ts @@ -16,6 +16,7 @@ import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model'; import { RemoteData } from '../data/remote-data'; import { PaginatedList } from '../data/paginated-list.model'; import { dataService } from '../data/base/data-service.decorator'; +import { RequestParam } from '../cache/models/request-param.model'; @Injectable() @dataService(SUBMISSION_CC_LICENSE_URL) @@ -43,17 +44,8 @@ export class SubmissionCcLicenseUrlDataService extends BaseDataService { - return { - fieldName: `answer_${field.id}`, - fieldValue: options.get(field).id, - }; - }), + new RequestParam('license', ccLicense.id), + ...ccLicense.fields.map((field: Field) => new RequestParam(`answer_${field.id}`, options.get(field).id)), ] } ).pipe( diff --git a/src/app/core/submission/workflowitem-data.service.ts b/src/app/core/submission/workflowitem-data.service.ts index 47d18470d39..7f8649b2e65 100644 --- a/src/app/core/submission/workflowitem-data.service.ts +++ b/src/app/core/submission/workflowitem-data.service.ts @@ -107,7 +107,7 @@ export class WorkflowItemDataService extends IdentifiableDataService[]): Observable> { const findListOptions = new FindListOptions(); - findListOptions.searchParams = [new RequestParam('uuid', encodeURIComponent(uuid))]; + findListOptions.searchParams = [new RequestParam('uuid', uuid)]; const href$ = this.searchData.getSearchByHref(this.searchByItemLinkPath, findListOptions, ...linksToFollow); return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); } diff --git a/src/app/core/submission/workspaceitem-data.service.ts b/src/app/core/submission/workspaceitem-data.service.ts index f285fb6eca5..d219de0ddc9 100644 --- a/src/app/core/submission/workspaceitem-data.service.ts +++ b/src/app/core/submission/workspaceitem-data.service.ts @@ -54,7 +54,7 @@ export class WorkspaceitemDataService extends IdentifiableDataService[]): Observable> { const findListOptions = new FindListOptions(); - findListOptions.searchParams = [new RequestParam('uuid', encodeURIComponent(uuid))]; + findListOptions.searchParams = [new RequestParam('uuid', uuid)]; const href$ = this.getSearchByHref(this.searchByItemLinkPath, findListOptions, ...linksToFollow); return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); }