Skip to content

Commit d5cf236

Browse files
Refactored code to always encode the RequestParams
1 parent 404ccd9 commit d5cf236

9 files changed

Lines changed: 34 additions & 66 deletions
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
21
/**
32
* Class representing a query parameter (query?fieldName=fieldValue) used in FindListOptions object
43
*/
54
export class RequestParam {
6-
constructor(public fieldName: string, public fieldValue: any) {
7-
5+
constructor(
6+
public fieldName: string,
7+
public fieldValue: any,
8+
public encodeValue = true,
9+
) {
10+
if (encodeValue) {
11+
this.fieldValue = encodeURIComponent(fieldValue);
12+
}
813
}
914
}

src/app/core/data/relationship-data.service.ts

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -492,40 +492,18 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
492492
* @param arrayOfItemIds The uuid of the items to be found on the other side of returned relationships
493493
*/
494494
searchByItemsAndType(typeId: string,itemUuid: string,relationshipLabel: string, arrayOfItemIds: string[] ): Observable<RemoteData<PaginatedList<Relationship>>> {
495-
496-
const searchParams = [
497-
{
498-
fieldName: 'typeId',
499-
fieldValue: typeId
500-
},
501-
{
502-
fieldName: 'focusItem',
503-
fieldValue: itemUuid
504-
},
505-
{
506-
fieldName: 'relationshipLabel',
507-
fieldValue: relationshipLabel
508-
},
509-
{
510-
fieldName: 'size',
511-
fieldValue: arrayOfItemIds.length
512-
},
513-
{
514-
fieldName: 'embed',
515-
fieldValue: 'leftItem'
516-
},
517-
{
518-
fieldName: 'embed',
519-
fieldValue: 'rightItem'
520-
},
521-
];
495+
const searchParams: RequestParam[] = [
496+
new RequestParam('typeId', typeId),
497+
new RequestParam('focusItem', itemUuid),
498+
new RequestParam('relationshipLabel', relationshipLabel),
499+
new RequestParam('size', arrayOfItemIds.length),
500+
new RequestParam('embed', 'leftItem'),
501+
new RequestParam('embed', 'rightItem'),
502+
];
522503

523504
arrayOfItemIds.forEach( (itemId) => {
524505
searchParams.push(
525-
{
526-
fieldName: 'relatedItem',
527-
fieldValue: itemId,
528-
}
506+
new RequestParam('relatedItem', itemId),
529507
);
530508
});
531509

src/app/core/data/relationship-type-data.service.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { FindAllDataImpl } from './base/find-all-data';
1717
import { SearchDataImpl } from './base/search-data';
1818
import { ObjectCacheService } from '../cache/object-cache.service';
1919
import { dataService } from './base/data-service.decorator';
20+
import { RequestParam } from '../cache/models/request-param.model';
2021

2122
/**
2223
* Check if one side of a RelationshipType is the ItemType with the given label
@@ -130,14 +131,8 @@ export class RelationshipTypeDataService extends BaseDataService<RelationshipTyp
130131
'byEntityType',
131132
{
132133
searchParams: [
133-
{
134-
fieldName: 'type',
135-
fieldValue: type,
136-
},
137-
{
138-
fieldName: 'size',
139-
fieldValue: 100,
140-
},
134+
new RequestParam('type', type),
135+
new RequestParam('size', 100),
141136
],
142137
}, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow,
143138
).pipe(

src/app/core/eperson/eperson-data.service.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,23 @@ describe('EPersonDataService', () => {
9696
it('search by default scope (byMetadata) and no query', () => {
9797
service.searchByScope(null, '');
9898
const options = Object.assign(new FindListOptions(), {
99-
searchParams: [Object.assign(new RequestParam('query', encodeURIComponent('')))]
99+
searchParams: [Object.assign(new RequestParam('query', ''))],
100100
});
101101
expect(service.searchBy).toHaveBeenCalledWith('byMetadata', options, true, true);
102102
});
103103

104104
it('search metadata scope and no query', () => {
105105
service.searchByScope('metadata', '');
106106
const options = Object.assign(new FindListOptions(), {
107-
searchParams: [Object.assign(new RequestParam('query', encodeURIComponent('')))]
107+
searchParams: [Object.assign(new RequestParam('query', ''))],
108108
});
109109
expect(service.searchBy).toHaveBeenCalledWith('byMetadata', options, true, true);
110110
});
111111

112112
it('search metadata scope and with query', () => {
113113
service.searchByScope('metadata', 'test');
114114
const options = Object.assign(new FindListOptions(), {
115-
searchParams: [Object.assign(new RequestParam('query', encodeURIComponent('test')))]
115+
searchParams: [Object.assign(new RequestParam('query', 'test'))],
116116
});
117117
expect(service.searchBy).toHaveBeenCalledWith('byMetadata', options, true, true);
118118
});
@@ -122,7 +122,7 @@ describe('EPersonDataService', () => {
122122
spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(null));
123123
service.searchByScope('email', '');
124124
const options = Object.assign(new FindListOptions(), {
125-
searchParams: [Object.assign(new RequestParam('email', encodeURIComponent('')))]
125+
searchParams: [Object.assign(new RequestParam('email', ''))],
126126
});
127127
expect((service as any).searchData.getSearchByHref).toHaveBeenCalledWith('byEmail', options);
128128
expect(service.findByHref).toHaveBeenCalledWith(epersonsEndpoint, true, true);
@@ -133,7 +133,7 @@ describe('EPersonDataService', () => {
133133
spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(EPersonMock));
134134
service.searchByScope('email', EPersonMock.email);
135135
const options = Object.assign(new FindListOptions(), {
136-
searchParams: [Object.assign(new RequestParam('email', encodeURIComponent(EPersonMock.email)))]
136+
searchParams: [Object.assign(new RequestParam('email', EPersonMock.email))],
137137
});
138138
expect((service as any).searchData.getSearchByHref).toHaveBeenCalledWith('byEmail', options);
139139
expect(service.findByHref).toHaveBeenCalledWith(epersonsEndpoint, true, true);

src/app/core/eperson/eperson-data.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class EPersonDataService extends IdentifiableDataService<EPerson> impleme
130130
*/
131131
public getEPersonByEmail(query: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<EPerson>[]): Observable<RemoteData<EPerson | NoContent>> {
132132
const findListOptions = new FindListOptions();
133-
findListOptions.searchParams = [new RequestParam('email', encodeURIComponent(query))];
133+
findListOptions.searchParams = [new RequestParam('email', query)];
134134
const href$ = this.searchData.getSearchByHref(this.searchByEmailPath, findListOptions, ...linksToFollow);
135135
return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
136136
}
@@ -147,7 +147,7 @@ export class EPersonDataService extends IdentifiableDataService<EPerson> impleme
147147
* {@link HALLink}s should be automatically resolved
148148
*/
149149
private getEpeopleByMetadata(query: string, options?: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<EPerson>[]): Observable<RemoteData<PaginatedList<EPerson>>> {
150-
const searchParams = [new RequestParam('query', encodeURIComponent(query))];
150+
const searchParams = [new RequestParam('query', query)];
151151
return this.getEPeopleBy(searchParams, this.searchByMetadataPath, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
152152
}
153153

src/app/core/statistics/usage-report-data.service.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
1515
import { RemoteData } from '../data/remote-data';
1616
import { PaginatedList } from '../data/paginated-list.model';
1717
import { dataService } from '../data/base/data-service.decorator';
18+
import { RequestParam } from '../cache/models/request-param.model';
1819

1920
/**
2021
* A service to retrieve {@link UsageReport}s from the REST API
@@ -45,10 +46,7 @@ export class UsageReportDataService extends IdentifiableDataService<UsageReport>
4546
searchStatistics(uri: string, page: number, size: number): Observable<UsageReport[]> {
4647
return this.searchBy('object', {
4748
searchParams: [
48-
{
49-
fieldName: `uri`,
50-
fieldValue: uri,
51-
},
49+
new RequestParam('uri', uri),
5250
],
5351
currentPage: page,
5452
elementsPerPage: size,

src/app/core/submission/submission-cc-license-url-data.service.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
1616
import { RemoteData } from '../data/remote-data';
1717
import { PaginatedList } from '../data/paginated-list.model';
1818
import { dataService } from '../data/base/data-service.decorator';
19+
import { RequestParam } from '../cache/models/request-param.model';
1920

2021
@Injectable()
2122
@dataService(SUBMISSION_CC_LICENSE_URL)
@@ -43,17 +44,8 @@ export class SubmissionCcLicenseUrlDataService extends BaseDataService<Submissio
4344
return this.searchData.getSearchByHref(
4445
'rightsByQuestions',{
4546
searchParams: [
46-
{
47-
fieldName: 'license',
48-
fieldValue: ccLicense.id
49-
},
50-
...ccLicense.fields.map(
51-
(field) => {
52-
return {
53-
fieldName: `answer_${field.id}`,
54-
fieldValue: options.get(field).id,
55-
};
56-
}),
47+
new RequestParam('license', ccLicense.id),
48+
...ccLicense.fields.map((field: Field) => new RequestParam(`answer_${field.id}`, options.get(field).id)),
5749
]
5850
}
5951
).pipe(

src/app/core/submission/workflowitem-data.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class WorkflowItemDataService extends IdentifiableDataService<WorkflowIte
107107
*/
108108
public findByItem(uuid: string, useCachedVersionIfAvailable = false, reRequestOnStale = true, options: FindListOptions = {}, ...linksToFollow: FollowLinkConfig<WorkspaceItem>[]): Observable<RemoteData<WorkspaceItem>> {
109109
const findListOptions = new FindListOptions();
110-
findListOptions.searchParams = [new RequestParam('uuid', encodeURIComponent(uuid))];
110+
findListOptions.searchParams = [new RequestParam('uuid', uuid)];
111111
const href$ = this.searchData.getSearchByHref(this.searchByItemLinkPath, findListOptions, ...linksToFollow);
112112
return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
113113
}

src/app/core/submission/workspaceitem-data.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class WorkspaceitemDataService extends IdentifiableDataService<WorkspaceI
5454
*/
5555
public findByItem(uuid: string, useCachedVersionIfAvailable = false, reRequestOnStale = true, options: FindListOptions = {}, ...linksToFollow: FollowLinkConfig<WorkspaceItem>[]): Observable<RemoteData<WorkspaceItem>> {
5656
const findListOptions = new FindListOptions();
57-
findListOptions.searchParams = [new RequestParam('uuid', encodeURIComponent(uuid))];
57+
findListOptions.searchParams = [new RequestParam('uuid', uuid)];
5858
const href$ = this.getSearchByHref(this.searchByItemLinkPath, findListOptions, ...linksToFollow);
5959
return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
6060
}

0 commit comments

Comments
 (0)