Merge branch 'w2p-109964_fix-vocabulary-options-with-url-as-stored-value_contribute-7.6' into w2p-109964_fix-vocabulary-options-with-url-as-stored-value_contribute-main

# Conflicts:
#	src/app/core/data/relationship-data.service.ts
#	src/app/core/data/relationship-type-data.service.ts
#	src/app/core/eperson/eperson-data.service.spec.ts
#	src/app/core/statistics/usage-report-data.service.ts
#	src/app/core/submission/submission-cc-license-url-data.service.ts
#	src/app/core/submission/workspaceitem-data.service.ts
This commit is contained in:
Alexandre Vryghem
2024-03-24 13:53:52 +01:00
15 changed files with 43 additions and 82 deletions

View File

@@ -1,9 +1,14 @@
/** /**
* Class representing a query parameter (query?fieldName=fieldValue) used in FindListOptions object * Class representing a query parameter (query?fieldName=fieldValue) used in FindListOptions object
*/ */
export class RequestParam { 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);
}
} }
} }

View File

@@ -531,40 +531,18 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
* @param arrayOfItemIds The uuid of the items to be found on the other side of returned relationships * @param arrayOfItemIds The uuid of the items to be found on the other side of returned relationships
*/ */
searchByItemsAndType(typeId: string,itemUuid: string,relationshipLabel: string, arrayOfItemIds: string[] ): Observable<RemoteData<PaginatedList<Relationship>>> { searchByItemsAndType(typeId: string,itemUuid: string,relationshipLabel: string, arrayOfItemIds: string[] ): Observable<RemoteData<PaginatedList<Relationship>>> {
const searchParams: RequestParam[] = [
const searchParams = [ new RequestParam('typeId', typeId),
{ new RequestParam('focusItem', itemUuid),
fieldName: 'typeId', new RequestParam('relationshipLabel', relationshipLabel),
fieldValue: typeId, new RequestParam('size', arrayOfItemIds.length),
}, new RequestParam('embed', 'leftItem'),
{ new RequestParam('embed', 'rightItem'),
fieldName: 'focusItem',
fieldValue: itemUuid,
},
{
fieldName: 'relationshipLabel',
fieldValue: relationshipLabel,
},
{
fieldName: 'size',
fieldValue: arrayOfItemIds.length,
},
{
fieldName: 'embed',
fieldValue: 'leftItem',
},
{
fieldName: 'embed',
fieldValue: 'rightItem',
},
]; ];
arrayOfItemIds.forEach( (itemId) => { arrayOfItemIds.forEach( (itemId) => {
searchParams.push( searchParams.push(
{ new RequestParam('relatedItem', itemId),
fieldName: 'relatedItem',
fieldValue: itemId,
},
); );
}); });

View File

@@ -16,6 +16,7 @@ import {
FollowLinkConfig, FollowLinkConfig,
} from '../../shared/utils/follow-link-config.model'; } from '../../shared/utils/follow-link-config.model';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; 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 { ObjectCacheService } from '../cache/object-cache.service';
import { HALEndpointService } from '../shared/hal-endpoint.service'; import { HALEndpointService } from '../shared/hal-endpoint.service';
import { ItemType } from '../shared/item-relationships/item-type.model'; import { ItemType } from '../shared/item-relationships/item-type.model';
@@ -143,14 +144,8 @@ export class RelationshipTypeDataService extends BaseDataService<RelationshipTyp
'byEntityType', 'byEntityType',
{ {
searchParams: [ searchParams: [
{ new RequestParam('type', type),
fieldName: 'type', new RequestParam('size', 100),
fieldValue: type,
},
{
fieldName: 'size',
fieldValue: 100,
},
], ],
}, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow, }, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow,
).pipe( ).pipe(

View File

@@ -114,7 +114,7 @@ describe('EPersonDataService', () => {
it('search by default scope (byMetadata) and no query', () => { it('search by default scope (byMetadata) and no query', () => {
service.searchByScope(null, ''); service.searchByScope(null, '');
const options = Object.assign(new FindListOptions(), { 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); expect(service.searchBy).toHaveBeenCalledWith('byMetadata', options, true, true);
}); });
@@ -122,7 +122,7 @@ describe('EPersonDataService', () => {
it('search metadata scope and no query', () => { it('search metadata scope and no query', () => {
service.searchByScope('metadata', ''); service.searchByScope('metadata', '');
const options = Object.assign(new FindListOptions(), { 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); expect(service.searchBy).toHaveBeenCalledWith('byMetadata', options, true, true);
}); });
@@ -130,7 +130,7 @@ describe('EPersonDataService', () => {
it('search metadata scope and with query', () => { it('search metadata scope and with query', () => {
service.searchByScope('metadata', 'test'); service.searchByScope('metadata', 'test');
const options = Object.assign(new FindListOptions(), { 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); expect(service.searchBy).toHaveBeenCalledWith('byMetadata', options, true, true);
}); });
@@ -140,7 +140,7 @@ describe('EPersonDataService', () => {
spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(null)); spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(null));
service.searchByScope('email', ''); service.searchByScope('email', '');
const options = Object.assign(new FindListOptions(), { 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 as any).searchData.getSearchByHref).toHaveBeenCalledWith('byEmail', options);
expect(service.findByHref).toHaveBeenCalledWith(epersonsEndpoint, true, true); expect(service.findByHref).toHaveBeenCalledWith(epersonsEndpoint, true, true);
@@ -151,7 +151,7 @@ describe('EPersonDataService', () => {
spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(EPersonMock)); spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(EPersonMock));
service.searchByScope('email', EPersonMock.email); service.searchByScope('email', EPersonMock.email);
const options = Object.assign(new FindListOptions(), { 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 as any).searchData.getSearchByHref).toHaveBeenCalledWith('byEmail', options);
expect(service.findByHref).toHaveBeenCalledWith(epersonsEndpoint, true, true); expect(service.findByHref).toHaveBeenCalledWith(epersonsEndpoint, true, true);

View File

@@ -163,7 +163,7 @@ export class EPersonDataService extends IdentifiableDataService<EPerson> impleme
*/ */
public getEPersonByEmail(query: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<EPerson>[]): Observable<RemoteData<EPerson | NoContent>> { public getEPersonByEmail(query: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<EPerson>[]): Observable<RemoteData<EPerson | NoContent>> {
const findListOptions = new FindListOptions(); 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); const href$ = this.searchData.getSearchByHref(this.searchByEmailPath, findListOptions, ...linksToFollow);
return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
} }
@@ -180,7 +180,7 @@ export class EPersonDataService extends IdentifiableDataService<EPerson> impleme
* {@link HALLink}s should be automatically resolved * {@link HALLink}s should be automatically resolved
*/ */
private getEpeopleByMetadata(query: string, options?: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<EPerson>[]): Observable<RemoteData<PaginatedList<EPerson>>> { private getEpeopleByMetadata(query: string, options?: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<EPerson>[]): Observable<RemoteData<PaginatedList<EPerson>>> {
const searchParams = [new RequestParam('query', encodeURIComponent(query))]; const searchParams = [new RequestParam('query', query)];
return this.getEPeopleBy(searchParams, this.searchByMetadataPath, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); return this.getEPeopleBy(searchParams, this.searchByMetadataPath, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
} }

View File

@@ -16,6 +16,7 @@ import { NotificationsService } from '../../../../shared/notifications/notificat
import { createSuccessfulRemoteDataObject } from '../../../../shared/remote-data.utils'; import { createSuccessfulRemoteDataObject } from '../../../../shared/remote-data.utils';
import { ObjectCacheServiceStub } from '../../../../shared/testing/object-cache-service.stub'; import { ObjectCacheServiceStub } from '../../../../shared/testing/object-cache-service.stub';
import { RemoteDataBuildService } from '../../../cache/builders/remote-data-build.service'; 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 { ObjectCacheService } from '../../../cache/object-cache.service';
import { RestResponse } from '../../../cache/response.models'; import { RestResponse } from '../../../cache/response.models';
import { FindListOptions } from '../../../data/find-list-options.model'; import { FindListOptions } from '../../../data/find-list-options.model';
@@ -131,10 +132,7 @@ describe('QualityAssuranceEventDataService', () => {
it('should proxy the call to searchData.searchBy', () => { it('should proxy the call to searchData.searchBy', () => {
const options: FindListOptions = { const options: FindListOptions = {
searchParams: [ searchParams: [
{ new RequestParam('topic', topic),
fieldName: 'topic',
fieldValue: topic,
},
], ],
}; };
service.getEventsByTopic(topic); service.getEventsByTopic(topic);

View File

@@ -16,6 +16,7 @@ import { hasValue } from '../../../../shared/empty.util';
import { NotificationsService } from '../../../../shared/notifications/notifications.service'; import { NotificationsService } from '../../../../shared/notifications/notifications.service';
import { FollowLinkConfig } from '../../../../shared/utils/follow-link-config.model'; import { FollowLinkConfig } from '../../../../shared/utils/follow-link-config.model';
import { RemoteDataBuildService } from '../../../cache/builders/remote-data-build.service'; 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 { ObjectCacheService } from '../../../cache/object-cache.service';
import { import {
CreateData, CreateData,
@@ -97,10 +98,7 @@ export class QualityAssuranceEventDataService extends IdentifiableDataService<Qu
*/ */
public getEventsByTopic(topic: string, options: FindListOptions = {}, ...linksToFollow: FollowLinkConfig<QualityAssuranceEventObject>[]): Observable<RemoteData<PaginatedList<QualityAssuranceEventObject>>> { public getEventsByTopic(topic: string, options: FindListOptions = {}, ...linksToFollow: FollowLinkConfig<QualityAssuranceEventObject>[]): Observable<RemoteData<PaginatedList<QualityAssuranceEventObject>>> {
options.searchParams = [ options.searchParams = [
{ new RequestParam('topic', topic),
fieldName: 'topic',
fieldValue: topic,
},
]; ];
return this.searchData.searchBy('findByTopic', options, true, true, ...linksToFollow); return this.searchData.searchBy('findByTopic', options, true, true, ...linksToFollow);
} }

View File

@@ -4,6 +4,7 @@ import { map } from 'rxjs/operators';
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model'; import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; 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 { ObjectCacheService } from '../cache/object-cache.service';
import { IdentifiableDataService } from '../data/base/identifiable-data.service'; import { IdentifiableDataService } from '../data/base/identifiable-data.service';
import { import {
@@ -49,10 +50,7 @@ export class UsageReportDataService extends IdentifiableDataService<UsageReport>
searchStatistics(uri: string, page: number, size: number): Observable<UsageReport[]> { searchStatistics(uri: string, page: number, size: number): Observable<UsageReport[]> {
return this.searchBy('object', { return this.searchBy('object', {
searchParams: [ searchParams: [
{ new RequestParam('uri', uri),
fieldName: `uri`,
fieldValue: uri,
},
], ],
currentPage: page, currentPage: page,
elementsPerPage: size, elementsPerPage: size,

View File

@@ -76,10 +76,7 @@ export class CorrectionTypeDataService extends IdentifiableDataService<Correctio
findByTopic(topic: string, useCachedVersionIfAvailable = true, reRequestOnStale = true): Observable<CorrectionType> { findByTopic(topic: string, useCachedVersionIfAvailable = true, reRequestOnStale = true): Observable<CorrectionType> {
const options = new FindListOptions(); const options = new FindListOptions();
options.searchParams = [ options.searchParams = [
{ new RequestParam('topic', topic),
fieldName: 'topic',
fieldValue: topic,
},
]; ];
return this.searchData.searchBy(this.searchByTopic, options, useCachedVersionIfAvailable, reRequestOnStale).pipe( return this.searchData.searchBy(this.searchByTopic, options, useCachedVersionIfAvailable, reRequestOnStale).pipe(

View File

@@ -7,6 +7,7 @@ import {
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model'; import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; 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 { ObjectCacheService } from '../cache/object-cache.service';
import { BaseDataService } from '../data/base/base-data.service'; import { BaseDataService } from '../data/base/base-data.service';
import { import {
@@ -54,17 +55,8 @@ export class SubmissionCcLicenseUrlDataService extends BaseDataService<Submissio
return this.searchData.getSearchByHref( return this.searchData.getSearchByHref(
'rightsByQuestions',{ 'rightsByQuestions',{
searchParams: [ searchParams: [
{ new RequestParam('license', ccLicense.id),
fieldName: 'license', ...ccLicense.fields.map((field: Field) => new RequestParam(`answer_${field.id}`, options.get(field).id)),
fieldValue: ccLicense.id,
},
...ccLicense.fields.map(
(field) => {
return {
fieldName: `answer_${field.id}`,
fieldValue: options.get(field).id,
};
}),
], ],
}, },
).pipe( ).pipe(

View File

@@ -33,8 +33,8 @@ describe('VocabularyDataService', () => {
spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(null)); spyOn(service, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(null));
service.getVocabularyByMetadataAndCollection('dc.contributor.author', '1234-1234'); service.getVocabularyByMetadataAndCollection('dc.contributor.author', '1234-1234');
const options = Object.assign(new FindListOptions(), { const options = Object.assign(new FindListOptions(), {
searchParams: [Object.assign(new RequestParam('metadata', encodeURIComponent('dc.contributor.author'))), searchParams: [Object.assign(new RequestParam('metadata', 'dc.contributor.author')),
Object.assign(new RequestParam('collection', encodeURIComponent('1234-1234')))], Object.assign(new RequestParam('collection', '1234-1234'))],
}); });
expect((service as any).searchData.getSearchByHref).toHaveBeenCalledWith('byMetadataAndCollection', options); expect((service as any).searchData.getSearchByHref).toHaveBeenCalledWith('byMetadataAndCollection', options);
expect(service.findByHref).toHaveBeenCalledWith(vocabularyByMetadataAndCollectionEndpoint, true, true); expect(service.findByHref).toHaveBeenCalledWith(vocabularyByMetadataAndCollectionEndpoint, true, true);

View File

@@ -78,8 +78,8 @@ export class VocabularyDataService extends IdentifiableDataService<Vocabulary> i
*/ */
public getVocabularyByMetadataAndCollection(metadataField: string, collectionUUID: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Vocabulary>[]): Observable<RemoteData<Vocabulary>> { public getVocabularyByMetadataAndCollection(metadataField: string, collectionUUID: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Vocabulary>[]): Observable<RemoteData<Vocabulary>> {
const findListOptions = new FindListOptions(); const findListOptions = new FindListOptions();
findListOptions.searchParams = [new RequestParam('metadata', encodeURIComponent(metadataField)), findListOptions.searchParams = [new RequestParam('metadata', metadataField),
new RequestParam('collection', encodeURIComponent(collectionUUID))]; new RequestParam('collection', collectionUUID)];
const href$ = this.searchData.getSearchByHref(this.searchByMetadataAndCollectionPath, findListOptions, ...linksToFollow); const href$ = this.searchData.getSearchByHref(this.searchByMetadataAndCollectionPath, findListOptions, ...linksToFollow);
return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
} }

View File

@@ -115,7 +115,7 @@ export class WorkflowItemDataService extends IdentifiableDataService<WorkflowIte
*/ */
public findByItem(uuid: string, useCachedVersionIfAvailable = false, reRequestOnStale = true, options: FindListOptions = {}, ...linksToFollow: FollowLinkConfig<WorkspaceItem>[]): Observable<RemoteData<WorkspaceItem>> { public findByItem(uuid: string, useCachedVersionIfAvailable = false, reRequestOnStale = true, options: FindListOptions = {}, ...linksToFollow: FollowLinkConfig<WorkspaceItem>[]): Observable<RemoteData<WorkspaceItem>> {
const findListOptions = new FindListOptions(); 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); const href$ = this.searchData.getSearchByHref(this.searchByItemLinkPath, findListOptions, ...linksToFollow);
return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
} }

View File

@@ -154,7 +154,7 @@ describe('WorkspaceitemDataService test', () => {
it('should proxy the call to UpdateDataServiceImpl.findByHref', () => { it('should proxy the call to UpdateDataServiceImpl.findByHref', () => {
scheduler.schedule(() => service.findByItem('1234-1234', true, true, pageInfo)); scheduler.schedule(() => service.findByItem('1234-1234', true, true, pageInfo));
scheduler.flush(); 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); expect((service as any).findByHref).toHaveBeenCalledWith(searchUrl, true, true);
}); });

View File

@@ -90,7 +90,7 @@ export class WorkspaceitemDataService extends IdentifiableDataService<WorkspaceI
*/ */
public findByItem(uuid: string, useCachedVersionIfAvailable = false, reRequestOnStale = true, options: FindListOptions = {}, ...linksToFollow: FollowLinkConfig<WorkspaceItem>[]): Observable<RemoteData<WorkspaceItem>> { public findByItem(uuid: string, useCachedVersionIfAvailable = false, reRequestOnStale = true, options: FindListOptions = {}, ...linksToFollow: FollowLinkConfig<WorkspaceItem>[]): Observable<RemoteData<WorkspaceItem>> {
const findListOptions = new FindListOptions(); 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); const href$ = this.getIDHref(this.searchByItemLinkPath, findListOptions, ...linksToFollow);
return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); return this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
} }