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 0e8740e2aee..d633b10d5bc 100644 --- a/src/app/core/data/relationship-data.service.ts +++ b/src/app/core/data/relationship-data.service.ts @@ -531,40 +531,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 21d0fcb5f62..43c018bbce2 100644 --- a/src/app/core/data/relationship-type-data.service.ts +++ b/src/app/core/data/relationship-type-data.service.ts @@ -16,6 +16,7 @@ import { FollowLinkConfig, } from '../../shared/utils/follow-link-config.model'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; +import { RequestParam } from '../cache/models/request-param.model'; import { ObjectCacheService } from '../cache/object-cache.service'; import { HALEndpointService } from '../shared/hal-endpoint.service'; import { ItemType } from '../shared/item-relationships/item-type.model'; @@ -143,14 +144,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); }); @@ -122,7 +122,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); }); @@ -130,7 +130,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); }); @@ -140,7 +140,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); @@ -151,7 +151,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 4b033436848..e0672e3207c 100644 --- a/src/app/core/eperson/eperson-data.service.ts +++ b/src/app/core/eperson/eperson-data.service.ts @@ -163,7 +163,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); } @@ -180,7 +180,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/notifications/qa/events/quality-assurance-event-data.service.spec.ts b/src/app/core/notifications/qa/events/quality-assurance-event-data.service.spec.ts index 847eea7c7e6..c981afbe57a 100644 --- a/src/app/core/notifications/qa/events/quality-assurance-event-data.service.spec.ts +++ b/src/app/core/notifications/qa/events/quality-assurance-event-data.service.spec.ts @@ -16,6 +16,7 @@ import { NotificationsService } from '../../../../shared/notifications/notificat import { createSuccessfulRemoteDataObject } from '../../../../shared/remote-data.utils'; import { ObjectCacheServiceStub } from '../../../../shared/testing/object-cache-service.stub'; import { RemoteDataBuildService } from '../../../cache/builders/remote-data-build.service'; +import { RequestParam } from '../../../cache/models/request-param.model'; import { ObjectCacheService } from '../../../cache/object-cache.service'; import { RestResponse } from '../../../cache/response.models'; import { FindListOptions } from '../../../data/find-list-options.model'; @@ -131,10 +132,7 @@ describe('QualityAssuranceEventDataService', () => { it('should proxy the call to searchData.searchBy', () => { const options: FindListOptions = { searchParams: [ - { - fieldName: 'topic', - fieldValue: topic, - }, + new RequestParam('topic', topic), ], }; service.getEventsByTopic(topic); diff --git a/src/app/core/notifications/qa/events/quality-assurance-event-data.service.ts b/src/app/core/notifications/qa/events/quality-assurance-event-data.service.ts index 787de7b636c..7e6e8884173 100644 --- a/src/app/core/notifications/qa/events/quality-assurance-event-data.service.ts +++ b/src/app/core/notifications/qa/events/quality-assurance-event-data.service.ts @@ -16,6 +16,7 @@ import { hasValue } from '../../../../shared/empty.util'; import { NotificationsService } from '../../../../shared/notifications/notifications.service'; import { FollowLinkConfig } from '../../../../shared/utils/follow-link-config.model'; import { RemoteDataBuildService } from '../../../cache/builders/remote-data-build.service'; +import { RequestParam } from '../../../cache/models/request-param.model'; import { ObjectCacheService } from '../../../cache/object-cache.service'; import { CreateData, @@ -97,10 +98,7 @@ export class QualityAssuranceEventDataService extends IdentifiableDataService[]): Observable>> { options.searchParams = [ - { - fieldName: 'topic', - fieldValue: topic, - }, + new RequestParam('topic', topic), ]; return this.searchData.searchBy('findByTopic', options, true, true, ...linksToFollow); } diff --git a/src/app/core/statistics/usage-report-data.service.ts b/src/app/core/statistics/usage-report-data.service.ts index 457b33f4ecb..2737e875de9 100644 --- a/src/app/core/statistics/usage-report-data.service.ts +++ b/src/app/core/statistics/usage-report-data.service.ts @@ -4,6 +4,7 @@ import { map } from 'rxjs/operators'; import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; +import { RequestParam } from '../cache/models/request-param.model'; import { ObjectCacheService } from '../cache/object-cache.service'; import { IdentifiableDataService } from '../data/base/identifiable-data.service'; import { @@ -49,10 +50,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/correctiontype-data.service.ts b/src/app/core/submission/correctiontype-data.service.ts index 9fb771288f5..550fdcacbac 100644 --- a/src/app/core/submission/correctiontype-data.service.ts +++ b/src/app/core/submission/correctiontype-data.service.ts @@ -76,10 +76,7 @@ export class CorrectionTypeDataService extends IdentifiableDataService { const options = new FindListOptions(); options.searchParams = [ - { - fieldName: 'topic', - fieldValue: topic, - }, + new RequestParam('topic', topic), ]; return this.searchData.searchBy(this.searchByTopic, options, useCachedVersionIfAvailable, reRequestOnStale).pipe( 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 94c3b39365f..575f6113353 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 @@ -7,6 +7,7 @@ import { import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; +import { RequestParam } from '../cache/models/request-param.model'; import { ObjectCacheService } from '../cache/object-cache.service'; import { BaseDataService } from '../data/base/base-data.service'; import { @@ -54,17 +55,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/vocabularies/vocabulary.data.service.spec.ts b/src/app/core/submission/vocabularies/vocabulary.data.service.spec.ts index 68c7c3ff808..0596b21d577 100644 --- a/src/app/core/submission/vocabularies/vocabulary.data.service.spec.ts +++ b/src/app/core/submission/vocabularies/vocabulary.data.service.spec.ts @@ -33,8 +33,8 @@ describe('VocabularyDataService', () => { spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(null)); service.getVocabularyByMetadataAndCollection('dc.contributor.author', '1234-1234'); const options = Object.assign(new FindListOptions(), { - searchParams: [Object.assign(new RequestParam('metadata', encodeURIComponent('dc.contributor.author'))), - Object.assign(new RequestParam('collection', encodeURIComponent('1234-1234')))], + searchParams: [Object.assign(new RequestParam('metadata', 'dc.contributor.author')), + Object.assign(new RequestParam('collection', '1234-1234'))], }); expect((service as any).searchData.getSearchByHref).toHaveBeenCalledWith('byMetadataAndCollection', options); expect(service.findByHref).toHaveBeenCalledWith(vocabularyByMetadataAndCollectionEndpoint, true, true); diff --git a/src/app/core/submission/vocabularies/vocabulary.data.service.ts b/src/app/core/submission/vocabularies/vocabulary.data.service.ts index 57669d93491..62691cef8f2 100644 --- a/src/app/core/submission/vocabularies/vocabulary.data.service.ts +++ b/src/app/core/submission/vocabularies/vocabulary.data.service.ts @@ -78,8 +78,8 @@ export class VocabularyDataService extends IdentifiableDataService i */ public getVocabularyByMetadataAndCollection(metadataField: string, collectionUUID: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig[]): Observable> { const findListOptions = new FindListOptions(); - findListOptions.searchParams = [new RequestParam('metadata', encodeURIComponent(metadataField)), - new RequestParam('collection', encodeURIComponent(collectionUUID))]; + findListOptions.searchParams = [new RequestParam('metadata', metadataField), + new RequestParam('collection', collectionUUID)]; const href$ = this.searchData.getSearchByHref(this.searchByMetadataAndCollectionPath, findListOptions, ...linksToFollow); return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); } diff --git a/src/app/core/submission/workflowitem-data.service.ts b/src/app/core/submission/workflowitem-data.service.ts index 88846ee2906..c7a6b482318 100644 --- a/src/app/core/submission/workflowitem-data.service.ts +++ b/src/app/core/submission/workflowitem-data.service.ts @@ -115,7 +115,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.spec.ts b/src/app/core/submission/workspaceitem-data.service.spec.ts index 644cae85cb6..43a61bef991 100644 --- a/src/app/core/submission/workspaceitem-data.service.spec.ts +++ b/src/app/core/submission/workspaceitem-data.service.spec.ts @@ -154,7 +154,7 @@ describe('WorkspaceitemDataService test', () => { it('should proxy the call to UpdateDataServiceImpl.findByHref', () => { scheduler.schedule(() => service.findByItem('1234-1234', true, true, pageInfo)); scheduler.flush(); - const searchUrl = service.getIDHref('item', [new RequestParam('uuid', encodeURIComponent('1234-1234'))]); + const searchUrl = service.getIDHref('item', [new RequestParam('uuid', '1234-1234')]); expect((service as any).findByHref).toHaveBeenCalledWith(searchUrl, true, true); }); diff --git a/src/app/core/submission/workspaceitem-data.service.ts b/src/app/core/submission/workspaceitem-data.service.ts index 6df06ccad53..1e22c87d591 100644 --- a/src/app/core/submission/workspaceitem-data.service.ts +++ b/src/app/core/submission/workspaceitem-data.service.ts @@ -90,7 +90,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.getIDHref(this.searchByItemLinkPath, findListOptions, ...linksToFollow); return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); }