[CST-12535] GET quality assurance topics by source/target

This commit is contained in:
Alisa Ismailati
2023-11-07 15:28:04 +01:00
parent 546c892eb1
commit 4bd80c9951
16 changed files with 110 additions and 133 deletions

View File

@@ -51,7 +51,7 @@ import { SourceDataResolver } from './admin-quality-assurance-source-page-compon
}, },
{ {
canActivate: [ AuthenticatedGuard ], canActivate: [ AuthenticatedGuard ],
path: `${QUALITY_ASSURANCE_EDIT_PATH}/:sourceId/:targetId`, path: `${QUALITY_ASSURANCE_EDIT_PATH}/:sourceId/target/:targetId`,
component: AdminQualityAssuranceTopicsPageComponent, component: AdminQualityAssuranceTopicsPageComponent,
pathMatch: 'full', pathMatch: 'full',
resolve: { resolve: {

View File

@@ -80,22 +80,27 @@ describe('QualityAssuranceTopicDataService', () => {
notificationsService notificationsService
); );
spyOn((service as any).findAllData, 'findAll').and.callThrough(); spyOn((service as any).searchData, 'searchBy').and.callThrough();
spyOn((service as any), 'findById').and.callThrough();
}); });
describe('getTopics', () => { describe('searchTopicsByTarget', () => {
it('should call findListByHref', (done) => { it('should call searchData.searchBy with the correct parameters', () => {
service.getTopics().subscribe( const options = { elementsPerPage: 10 };
(res) => { const useCachedVersionIfAvailable = true;
expect((service as any).findAllData.findAll).toHaveBeenCalledWith({}, true, true); const reRequestOnStale = true;
}
service.searchTopicsByTarget(options, useCachedVersionIfAvailable, reRequestOnStale);
expect((service as any).searchData.searchBy).toHaveBeenCalledWith(
'byTarget',
options,
useCachedVersionIfAvailable,
reRequestOnStale
); );
done();
}); });
it('should return a RemoteData<PaginatedList<QualityAssuranceTopicObject>> for the object with the given URL', () => { it('should return a RemoteData<PaginatedList<QualityAssuranceTopicObject>> for the object with the given URL', () => {
const result = service.getTopics(); const result = service.searchTopicsByTarget();
const expected = cold('(a)', { const expected = cold('(a)', {
a: paginatedListRD a: paginatedListRD
}); });
@@ -103,20 +108,26 @@ describe('QualityAssuranceTopicDataService', () => {
}); });
}); });
describe('getTopic', () => { describe('searchTopicsBySource', () => {
it('should call findByHref', (done) => { it('should call searchData.searchBy with the correct parameters', () => {
service.getTopic(qualityAssuranceTopicObjectMorePid.id).subscribe( const options = { elementsPerPage: 10 };
(res) => { const useCachedVersionIfAvailable = true;
expect((service as any).findById).toHaveBeenCalledWith(qualityAssuranceTopicObjectMorePid.id, true, true); const reRequestOnStale = true;
}
service.searchTopicsBySource(options, useCachedVersionIfAvailable, reRequestOnStale);
expect((service as any).searchData.searchBy).toHaveBeenCalledWith(
'bySource',
options,
useCachedVersionIfAvailable,
reRequestOnStale,
); );
done();
}); });
it('should return a RemoteData<QualityAssuranceTopicObject> for the object with the given URL', () => { it('should return a RemoteData<PaginatedList<QualityAssuranceTopicObject>> for the object with the given URL', () => {
const result = service.getTopic(qualityAssuranceTopicObjectMorePid.id); const result = service.searchTopicsBySource();
const expected = cold('(a)', { const expected = cold('(a)', {
a: qaTopicObjectRD a: paginatedListRD
}); });
expect(result).toBeObservable(expected); expect(result).toBeObservable(expected);
}); });

View File

@@ -15,7 +15,6 @@ import { FindListOptions } from '../../../data/find-list-options.model';
import { IdentifiableDataService } from '../../../data/base/identifiable-data.service'; import { IdentifiableDataService } from '../../../data/base/identifiable-data.service';
import { dataService } from '../../../data/base/data-service.decorator'; import { dataService } from '../../../data/base/data-service.decorator';
import { QUALITY_ASSURANCE_TOPIC_OBJECT } from '../models/quality-assurance-topic-object.resource-type'; import { QUALITY_ASSURANCE_TOPIC_OBJECT } from '../models/quality-assurance-topic-object.resource-type';
import { FindAllData, FindAllDataImpl } from '../../../data/base/find-all-data';
import { SearchData, SearchDataImpl } from '../../../../core/data/base/search-data'; import { SearchData, SearchDataImpl } from '../../../../core/data/base/search-data';
/** /**
@@ -25,10 +24,10 @@ import { SearchData, SearchDataImpl } from '../../../../core/data/base/search-da
@dataService(QUALITY_ASSURANCE_TOPIC_OBJECT) @dataService(QUALITY_ASSURANCE_TOPIC_OBJECT)
export class QualityAssuranceTopicDataService extends IdentifiableDataService<QualityAssuranceTopicObject> { export class QualityAssuranceTopicDataService extends IdentifiableDataService<QualityAssuranceTopicObject> {
private findAllData: FindAllData<QualityAssuranceTopicObject>;
private searchData: SearchData<QualityAssuranceTopicObject>; private searchData: SearchData<QualityAssuranceTopicObject>;
private searchByTargetMethod = 'byTarget'; private searchByTargetMethod = 'byTarget';
private searchBySourceMethod = 'bySource';
/** /**
* Initialize service variables * Initialize service variables
@@ -46,27 +45,9 @@ export class QualityAssuranceTopicDataService extends IdentifiableDataService<Qu
protected notificationsService: NotificationsService protected notificationsService: NotificationsService
) { ) {
super('qualityassurancetopics', requestService, rdbService, objectCache, halService); super('qualityassurancetopics', requestService, rdbService, objectCache, halService);
this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
this.searchData = new SearchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive); this.searchData = new SearchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
} }
/**
* Return the list of Quality Assurance topics.
*
* @param options Find list options object.
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
* no valid cached version. Defaults to true
* @param reRequestOnStale Whether or not the request should automatically be re-
* requested after the response becomes stale
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved.
*
* @return Observable<RemoteData<PaginatedList<QualityAssuranceTopicObject>>>
* The list of Quality Assurance topics.
*/
public getTopics(options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<QualityAssuranceTopicObject>[]): Observable<RemoteData<PaginatedList<QualityAssuranceTopicObject>>> {
return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
/** /**
* Search for Quality Assurance topics. * Search for Quality Assurance topics.
* @param options The search options. * @param options The search options.
@@ -75,31 +56,26 @@ export class QualityAssuranceTopicDataService extends IdentifiableDataService<Qu
* @param linksToFollow The links to follow. * @param linksToFollow The links to follow.
* @returns An observable of remote data containing a paginated list of Quality Assurance topics. * @returns An observable of remote data containing a paginated list of Quality Assurance topics.
*/ */
public searchTopics(options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<QualityAssuranceTopicObject>[]): Observable<RemoteData<PaginatedList<QualityAssuranceTopicObject>>> { public searchTopicsByTarget(options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<QualityAssuranceTopicObject>[]): Observable<RemoteData<PaginatedList<QualityAssuranceTopicObject>>> {
return this.searchData.searchBy(this.searchByTargetMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); return this.searchData.searchBy(this.searchByTargetMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
} }
/**
* Searches for quality assurance topics by source.
* @param options The search options.
* @param useCachedVersionIfAvailable Whether to use a cached version if available.
* @param reRequestOnStale Whether to re-request the data if it's stale.
* @param linksToFollow The links to follow.
* @returns An observable of the remote data containing the paginated list of quality assurance topics.
*/
public searchTopicsBySource(options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<QualityAssuranceTopicObject>[]): Observable<RemoteData<PaginatedList<QualityAssuranceTopicObject>>> {
return this.searchData.searchBy(this.searchBySourceMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
/** /**
* Clear FindAll topics requests from cache * Clear FindAll topics requests from cache
*/ */
public clearFindAllTopicsRequests() { public clearFindAllTopicsRequests() {
this.requestService.setStaleByHrefSubstring('qualityassurancetopics'); this.requestService.setStaleByHrefSubstring('qualityassurancetopics');
} }
/**
* Return a single Quality Assurance topic.
*
* @param id The Quality Assurance topic id
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
* no valid cached version. Defaults to true
* @param reRequestOnStale Whether or not the request should automatically be re-
* requested after the response becomes stale
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved.
*
* @return Observable<RemoteData<QualityAssuranceTopicObject>>
* The Quality Assurance topic.
*/
public getTopic(id: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<QualityAssuranceTopicObject>[]): Observable<RemoteData<QualityAssuranceTopicObject>> {
return this.findById(id, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
} }

View File

@@ -5,7 +5,7 @@
<div class="w-100 d-flex justify-content-between"> <div class="w-100 d-flex justify-content-between">
<div class="pl-4 align-self-center">{{'item.qa-event-notification.check.notification-info' | translate : {num: <div class="pl-4 align-self-center">{{'item.qa-event-notification.check.notification-info' | translate : {num:
source.totalEvents } }} </div> source.totalEvents } }} </div>
<button [routerLink]="['/admin/notifications/quality-assurance', source, item.id]" <button [routerLink]="['/admin/notifications/quality-assurance', (source.id | dsSplit: ':')[0], 'target', item.id]"
class="btn btn-primary align-self-center">{{'item.qa-event-notification-info.check.button' | translate class="btn btn-primary align-self-center">{{'item.qa-event-notification-info.check.button' | translate
}}</button> }}</button>
</div> </div>

View File

@@ -1838,8 +1838,8 @@ export function getMockNotificationsStateService(): any {
*/ */
export function getMockQualityAssuranceTopicRestService(): QualityAssuranceTopicDataService { export function getMockQualityAssuranceTopicRestService(): QualityAssuranceTopicDataService {
return jasmine.createSpyObj('QualityAssuranceTopicDataService', { return jasmine.createSpyObj('QualityAssuranceTopicDataService', {
getTopics: jasmine.createSpy('getTopics'), searchTopicsBySource: jasmine.createSpy('searchTopicsBySource'),
getTopic: jasmine.createSpy('getTopic'), searchTopicsByTarget: jasmine.createSpy('searchTopicsByTarget'),
}); });
} }

View File

@@ -140,7 +140,6 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy {
return this.getQualityAssuranceEvents(); return this.getQualityAssuranceEvents();
}) })
).subscribe((events: QualityAssuranceEventData[]) => { ).subscribe((events: QualityAssuranceEventData[]) => {
console.log(events);
this.eventsUpdated$.next(events); this.eventsUpdated$.next(events);
this.isEventPageLoading.next(false); this.isEventPageLoading.next(false);
}); });
@@ -356,7 +355,6 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy {
if (rd.hasSucceeded) { if (rd.hasSucceeded) {
this.totalElements$.next(rd.payload.totalElements); this.totalElements$.next(rd.payload.totalElements);
if (rd.payload.totalElements > 0) { if (rd.payload.totalElements > 0) {
console.log(rd.payload.page);
return this.fetchEvents(rd.payload.page); return this.fetchEvents(rd.payload.page);
} else { } else {
return of([]); return of([]);

View File

@@ -25,6 +25,8 @@ export class RetrieveAllTopicsAction implements Action {
payload: { payload: {
elementsPerPage: number; elementsPerPage: number;
currentPage: number; currentPage: number;
source: string;
target?: string;
}; };
/** /**
@@ -35,10 +37,12 @@ export class RetrieveAllTopicsAction implements Action {
* @param currentPage * @param currentPage
* The page number to retrieve * The page number to retrieve
*/ */
constructor(elementsPerPage: number, currentPage: number) { constructor(elementsPerPage: number, currentPage: number, source: string, target?: string) {
this.payload = { this.payload = {
elementsPerPage, elementsPerPage,
currentPage currentPage,
source,
target
}; };
} }
} }

View File

@@ -15,7 +15,7 @@
[collectionSize]="(totalElements$ | async)" [collectionSize]="(totalElements$ | async)"
[hideGear]="false" [hideGear]="false"
[hideSortOptions]="true" [hideSortOptions]="true"
(paginationChange)="getQualityAssuranceTopics()"> (paginationChange)="getQualityAssuranceTopics(sourceId, targetId)">
<ds-loading class="container" *ngIf="(isTopicsProcessing() | async)" message="'quality-assurance.loading' | translate"></ds-loading> <ds-loading class="container" *ngIf="(isTopicsProcessing() | async)" message="'quality-assurance.loading' | translate"></ds-loading>
<ng-container *ngIf="!(isTopicsProcessing() | async)"> <ng-container *ngIf="!(isTopicsProcessing() | async)">
@@ -40,7 +40,7 @@
<button <button
class="btn btn-outline-primary btn-sm" class="btn btn-outline-primary btn-sm"
title="{{'quality-assurance.button.detail' | translate }}" title="{{'quality-assurance.button.detail' | translate }}"
[routerLink]="[topicElement.id]"> [routerLink]="['/admin/notifications/quality-assurance',sourceId, topicElement.id]">
<span class="badge badge-info">{{topicElement.totalEvents}}</span> <span class="badge badge-info">{{topicElement.totalEvents}}</span>
<i class="fas fa-info fa-fw"></i> <i class="fas fa-info fa-fw"></i>
</button> </button>

View File

@@ -16,7 +16,6 @@ import { SuggestionNotificationsStateService } from '../../suggestion-notificati
import { cold } from 'jasmine-marbles'; import { cold } from 'jasmine-marbles';
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub'; import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
import { PaginationService } from '../../../core/pagination/pagination.service'; import { PaginationService } from '../../../core/pagination/pagination.service';
import { QualityAssuranceTopicsService } from './quality-assurance-topics.service';
describe('QualityAssuranceTopicsComponent test suite', () => { describe('QualityAssuranceTopicsComponent test suite', () => {
let fixture: ComponentFixture<QualityAssuranceTopicsComponent>; let fixture: ComponentFixture<QualityAssuranceTopicsComponent>;
@@ -44,18 +43,13 @@ describe('QualityAssuranceTopicsComponent test suite', () => {
providers: [ providers: [
{ provide: SuggestionNotificationsStateService, useValue: mockNotificationsStateService }, { provide: SuggestionNotificationsStateService, useValue: mockNotificationsStateService },
{ provide: ActivatedRoute, useValue: { data: observableOf(activatedRouteParams), snapshot: { { provide: ActivatedRoute, useValue: { data: observableOf(activatedRouteParams), snapshot: {
paramMap: { params: {
get: () => 'openaire', sourceId: 'openaire',
targetId: null
}, },
}}}, }}},
{ provide: PaginationService, useValue: paginationService }, { provide: PaginationService, useValue: paginationService },
QualityAssuranceTopicsComponent, QualityAssuranceTopicsComponent,
// tslint:disable-next-line: no-empty
{ provide: QualityAssuranceTopicsService, useValue: {
setSourceId: (sourceId: string) => { } ,
setTargetId: (targetId: string) => { }
}
}
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}).compileComponents().then(() => { }).compileComponents().then(() => {

View File

@@ -15,7 +15,6 @@ import {
} from '../../../admin/admin-notifications/admin-quality-assurance-topics-page/admin-quality-assurance-topics-page-resolver.service'; } from '../../../admin/admin-notifications/admin-quality-assurance-topics-page/admin-quality-assurance-topics-page-resolver.service';
import { PaginationService } from '../../../core/pagination/pagination.service'; import { PaginationService } from '../../../core/pagination/pagination.service';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { QualityAssuranceTopicsService } from './quality-assurance-topics.service';
/** /**
* Component to display the Quality Assurance topic list. * Component to display the Quality Assurance topic list.
@@ -76,19 +75,16 @@ export class QualityAssuranceTopicsComponent implements OnInit {
constructor( constructor(
private paginationService: PaginationService, private paginationService: PaginationService,
private activatedRoute: ActivatedRoute, private activatedRoute: ActivatedRoute,
private notificationsStateService: SuggestionNotificationsStateService, private notificationsStateService: SuggestionNotificationsStateService
private qualityAssuranceTopicsService: QualityAssuranceTopicsService
) { ) {
this.sourceId = this.activatedRoute.snapshot.params.sourceId;
this.targetId = this.activatedRoute.snapshot.params.targetId;
} }
/** /**
* Component initialization. * Component initialization.
*/ */
ngOnInit(): void { ngOnInit(): void {
this.sourceId = this.activatedRoute.snapshot.paramMap.get('sourceId');
this.targetId = this.activatedRoute.snapshot.paramMap.get('targetId');
this.qualityAssuranceTopicsService.setSourceId(this.sourceId);
this.qualityAssuranceTopicsService.setTargetId(this.targetId);
this.topics$ = this.notificationsStateService.getQualityAssuranceTopics(); this.topics$ = this.notificationsStateService.getQualityAssuranceTopics();
this.totalElements$ = this.notificationsStateService.getQualityAssuranceTopicsTotals(); this.totalElements$ = this.notificationsStateService.getQualityAssuranceTopicsTotals();
} }
@@ -101,7 +97,7 @@ export class QualityAssuranceTopicsComponent implements OnInit {
this.notificationsStateService.isQualityAssuranceTopicsLoaded().pipe( this.notificationsStateService.isQualityAssuranceTopicsLoaded().pipe(
take(1) take(1)
).subscribe(() => { ).subscribe(() => {
this.getQualityAssuranceTopics(); this.getQualityAssuranceTopics(this.sourceId, this.targetId);
}) })
); );
} }
@@ -129,13 +125,15 @@ export class QualityAssuranceTopicsComponent implements OnInit {
/** /**
* Dispatch the Quality Assurance topics retrival. * Dispatch the Quality Assurance topics retrival.
*/ */
public getQualityAssuranceTopics(): void { public getQualityAssuranceTopics(source: string, target?: string): void {
this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig).pipe( this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig).pipe(
distinctUntilChanged(), distinctUntilChanged(),
).subscribe((options: PaginationComponentOptions) => { ).subscribe((options: PaginationComponentOptions) => {
this.notificationsStateService.dispatchRetrieveQualityAssuranceTopics( this.notificationsStateService.dispatchRetrieveQualityAssuranceTopics(
options.pageSize, options.pageSize,
options.currentPage options.currentPage,
source,
target
); );
}); });
} }

View File

@@ -37,7 +37,9 @@ export class QualityAssuranceTopicsEffects {
switchMap(([action, currentState]: [RetrieveAllTopicsAction, any]) => { switchMap(([action, currentState]: [RetrieveAllTopicsAction, any]) => {
return this.qualityAssuranceTopicService.getTopics( return this.qualityAssuranceTopicService.getTopics(
action.payload.elementsPerPage, action.payload.elementsPerPage,
action.payload.currentPage action.payload.currentPage,
action.payload.source,
action.payload.target
).pipe( ).pipe(
map((topics: PaginatedList<QualityAssuranceTopicObject>) => map((topics: PaginatedList<QualityAssuranceTopicObject>) =>
new AddTopicsAction(topics.page, topics.totalPages, topics.currentPage, topics.totalElements) new AddTopicsAction(topics.page, topics.totalPages, topics.currentPage, topics.totalElements)

View File

@@ -29,7 +29,7 @@ describe('qualityAssuranceTopicsReducer test suite', () => {
const expectedState = qualityAssuranceTopicInitialState; const expectedState = qualityAssuranceTopicInitialState;
expectedState.processing = true; expectedState.processing = true;
const action = new RetrieveAllTopicsAction(elementPerPage, currentPage); const action = new RetrieveAllTopicsAction(elementPerPage, currentPage, 'source', 'target');
const newState = qualityAssuranceTopicsReducer(qualityAssuranceTopicInitialState, action); const newState = qualityAssuranceTopicsReducer(qualityAssuranceTopicInitialState, action);
expect(newState).toEqual(expectedState); expect(newState).toEqual(expectedState);

View File

@@ -42,31 +42,46 @@ describe('QualityAssuranceTopicsService', () => {
beforeEach(() => { beforeEach(() => {
restService = TestBed.inject(QualityAssuranceTopicDataService); restService = TestBed.inject(QualityAssuranceTopicDataService);
restServiceAsAny = restService; restServiceAsAny = restService;
restServiceAsAny.getTopics.and.returnValue(observableOf(paginatedListRD)); restServiceAsAny.searchTopicsBySource.and.returnValue(observableOf(paginatedListRD));
restServiceAsAny.searchTopicsByTarget.and.returnValue(observableOf(paginatedListRD));
service = new QualityAssuranceTopicsService(restService); service = new QualityAssuranceTopicsService(restService);
serviceAsAny = service; serviceAsAny = service;
}); });
describe('getTopics', () => { describe('getTopicsBySource', () => {
it('Should proxy the call to qualityAssuranceTopicRestService.getTopics', () => { it('should proxy the call to qualityAssuranceTopicRestService.searchTopicsBySource', () => {
const sortOptions = new SortOptions('name', SortDirection.ASC); const sortOptions = new SortOptions('name', SortDirection.ASC);
const findListOptions: FindListOptions = { const findListOptions: FindListOptions = {
elementsPerPage: elementsPerPage, elementsPerPage: elementsPerPage,
currentPage: currentPage, currentPage: currentPage,
sort: sortOptions, sort: sortOptions,
searchParams: [new RequestParam('source', 'ENRICH!MORE!ABSTRACT')] searchParams: [new RequestParam('source', 'openaire')]
}; };
service.setSourceId('ENRICH!MORE!ABSTRACT'); const result = service.getTopics(elementsPerPage, currentPage, 'openaire');
const result = service.getTopics(elementsPerPage, currentPage); expect((service as any).qualityAssuranceTopicRestService.searchTopicsBySource).toHaveBeenCalledWith(findListOptions);
expect((service as any).qualityAssuranceTopicRestService.getTopics).toHaveBeenCalledWith(findListOptions);
}); });
it('Should return a paginated list of Quality Assurance topics', () => { it('should return a paginated list of Quality Assurance topics', () => {
const expected = cold('(a|)', { const expected = cold('(a|)', {
a: paginatedList a: paginatedList
}); });
const result = service.getTopics(elementsPerPage, currentPage); const result = service.getTopics(elementsPerPage, currentPage, 'openaire');
expect(result).toBeObservable(expected); expect(result).toBeObservable(expected);
}); });
it('should include targetId in searchParams if set', () => {
const sortOptions = new SortOptions('name', SortDirection.ASC);
const findListOptions: FindListOptions = {
elementsPerPage: elementsPerPage,
currentPage: currentPage,
sort: sortOptions,
searchParams: [
new RequestParam('source', 'openaire'),
new RequestParam('target', '0000-0000-0000-0000-0000')
]
};
const result = service.getTopics(elementsPerPage, currentPage,'openaire', '0000-0000-0000-0000-0000');
expect((service as any).qualityAssuranceTopicRestService.searchTopicsByTarget).toHaveBeenCalledWith(findListOptions);
});
}); });
}); });

View File

@@ -29,15 +29,6 @@ export class QualityAssuranceTopicsService {
private qualityAssuranceTopicRestService: QualityAssuranceTopicDataService private qualityAssuranceTopicRestService: QualityAssuranceTopicDataService
) { } ) { }
/**
* sourceId used to get topics
*/
sourceId: string;
/**
* targetId used to get topics
*/
targetId: string;
/** /**
* Return the list of Quality Assurance topics managing pagination and errors. * Return the list of Quality Assurance topics managing pagination and errors.
@@ -49,21 +40,25 @@ export class QualityAssuranceTopicsService {
* @return Observable<PaginatedList<QualityAssuranceTopicObject>> * @return Observable<PaginatedList<QualityAssuranceTopicObject>>
* The list of Quality Assurance topics. * The list of Quality Assurance topics.
*/ */
public getTopics(elementsPerPage, currentPage): Observable<PaginatedList<QualityAssuranceTopicObject>> { public getTopics(elementsPerPage, currentPage, source: string, target?: string): Observable<PaginatedList<QualityAssuranceTopicObject>> {
const sortOptions = new SortOptions('name', SortDirection.ASC); const sortOptions = new SortOptions('name', SortDirection.ASC);
const findListOptions: FindListOptions = { const findListOptions: FindListOptions = {
elementsPerPage: elementsPerPage, elementsPerPage: elementsPerPage,
currentPage: currentPage, currentPage: currentPage,
sort: sortOptions, sort: sortOptions,
searchParams: [new RequestParam('source', this.sourceId)] searchParams: [new RequestParam('source', source)]
}; };
if (hasValue(this.targetId)) { let request$: Observable<RemoteData<PaginatedList<QualityAssuranceTopicObject>>>;
findListOptions.searchParams.push(new RequestParam('target', this.targetId));
if (hasValue(target)) {
findListOptions.searchParams.push(new RequestParam('target', target));
request$ = this.qualityAssuranceTopicRestService.searchTopicsByTarget(findListOptions);
} else {
request$ = this.qualityAssuranceTopicRestService.searchTopicsBySource(findListOptions);
} }
return this.qualityAssuranceTopicRestService.getTopics(findListOptions).pipe( return request$.pipe(
getFirstCompletedRemoteData(), getFirstCompletedRemoteData(),
map((rd: RemoteData<PaginatedList<QualityAssuranceTopicObject>>) => { map((rd: RemoteData<PaginatedList<QualityAssuranceTopicObject>>) => {
if (rd.hasSucceeded) { if (rd.hasSucceeded) {
@@ -74,20 +69,4 @@ export class QualityAssuranceTopicsService {
}) })
); );
} }
/**
* set sourceId which is used to get topics
* @param sourceId string
*/
setSourceId(sourceId: string) {
this.sourceId = sourceId;
}
/**
* set targetId which is used to get topics
* @param targetId string
*/
setTargetId(targetId: string) {
this.targetId = targetId;
}
} }

View File

@@ -271,8 +271,8 @@ describe('NotificationsStateService', () => {
it('Should call store.dispatch', () => { it('Should call store.dispatch', () => {
const elementsPerPage = 3; const elementsPerPage = 3;
const currentPage = 1; const currentPage = 1;
const action = new RetrieveAllTopicsAction(elementsPerPage, currentPage); const action = new RetrieveAllTopicsAction(elementsPerPage, currentPage, 'source', 'target');
service.dispatchRetrieveQualityAssuranceTopics(elementsPerPage, currentPage); service.dispatchRetrieveQualityAssuranceTopics(elementsPerPage, currentPage, 'source', 'target');
expect(serviceAsAny.store.dispatch).toHaveBeenCalledWith(action); expect(serviceAsAny.store.dispatch).toHaveBeenCalledWith(action);
}); });
}); });

View File

@@ -118,8 +118,8 @@ export class SuggestionNotificationsStateService {
* @param currentPage * @param currentPage
* The number of the current page. * The number of the current page.
*/ */
public dispatchRetrieveQualityAssuranceTopics(elementsPerPage: number, currentPage: number): void { public dispatchRetrieveQualityAssuranceTopics(elementsPerPage: number, currentPage: number, sourceId: string, targteId?: string): void {
this.store.dispatch(new RetrieveAllTopicsAction(elementsPerPage, currentPage)); this.store.dispatch(new RetrieveAllTopicsAction(elementsPerPage, currentPage, sourceId, targteId));
} }
// Quality Assurance source // Quality Assurance source