Merged in coar-CST-12535 (pull request #990)

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

Approved-by: Andrea Bollini
This commit is contained in:
Alisa Ismailati
2023-11-10 13:17:25 +00:00
committed by Andrea Bollini
17 changed files with 165 additions and 105 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,53 @@ 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(); 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)', {
a: paginatedListRD
});
expect(result).toBeObservable(expected);
});
});
describe('searchTopicsBySource', () => {
it('should call searchData.searchBy with the correct parameters', () => {
const options = { elementsPerPage: 10 };
const useCachedVersionIfAvailable = true;
const reRequestOnStale = true;
service.searchTopicsBySource(options, useCachedVersionIfAvailable, reRequestOnStale);
expect((service as any).searchData.searchBy).toHaveBeenCalledWith(
'bySource',
options,
useCachedVersionIfAvailable,
reRequestOnStale,
);
});
it('should return a RemoteData<PaginatedList<QualityAssuranceTopicObject>> for the object with the given URL', () => {
const result = service.searchTopicsBySource();
const expected = cold('(a)', { const expected = cold('(a)', {
a: paginatedListRD a: paginatedListRD
}); });
@@ -121,5 +152,4 @@ describe('QualityAssuranceTopicDataService', () => {
expect(result).toBeObservable(expected); expect(result).toBeObservable(expected);
}); });
}); });
}); });

View File

@@ -15,8 +15,8 @@ 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';
import { FindAllData, FindAllDataImpl } from '../../../data/base/find-all-data';
/** /**
* The service handling all Quality Assurance topic REST requests. * The service handling all Quality Assurance topic REST requests.
@@ -29,6 +29,7 @@ export class QualityAssuranceTopicDataService extends IdentifiableDataService<Qu
private searchData: SearchData<QualityAssuranceTopicObject>; private searchData: SearchData<QualityAssuranceTopicObject>;
private searchByTargetMethod = 'byTarget'; private searchByTargetMethod = 'byTarget';
private searchBySourceMethod = 'bySource';
/** /**
* Initialize service variables * Initialize service variables
@@ -50,23 +51,6 @@ export class QualityAssuranceTopicDataService extends IdentifiableDataService<Qu
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,10 +59,22 @@ 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
*/ */

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

@@ -2,7 +2,11 @@
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<h2 class="border-bottom pb-2">{{'quality-assurance.title'| translate}}</h2> <h2 class="border-bottom pb-2">{{'quality-assurance.title'| translate}}</h2>
<ds-alert [type]="'alert-info'">{{'quality-assurance.topics.description'| translate:{source: sourceId} }}</ds-alert> <ds-alert *ngIf="!targetId" [type]="'alert-info'">{{'quality-assurance.topics.description'| translate:{source: sourceId} }}</ds-alert>
<ds-alert *ngIf="targetId" [type]="'alert-info'">
{{'quality-assurance.topics.description-with-target'| translate:{source: sourceId} }}
<a [routerLink]="itemPageUrl">{{(getTargetItemTitle() | async)}}</a>
</ds-alert>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
@@ -15,7 +19,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 +44,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,7 @@ 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'; import { ItemDataService } from '../../../core/data/item-data.service';
describe('QualityAssuranceTopicsComponent test suite', () => { describe('QualityAssuranceTopicsComponent test suite', () => {
let fixture: ComponentFixture<QualityAssuranceTopicsComponent>; let fixture: ComponentFixture<QualityAssuranceTopicsComponent>;
@@ -44,18 +44,14 @@ 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 },
{ provide: ItemDataService, useValue: {} },
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

@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Observable, Subscription } from 'rxjs'; import { Observable, Subscription } from 'rxjs';
import { distinctUntilChanged, take } from 'rxjs/operators'; import { distinctUntilChanged, map, take, tap } from 'rxjs/operators';
import { SortOptions } from '../../../core/cache/models/sort-options.model'; import { SortOptions } from '../../../core/cache/models/sort-options.model';
import { import {
@@ -15,7 +15,10 @@ 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'; import { ItemDataService } from '../../../core/data/item-data.service';
import { getFirstCompletedRemoteData, getRemoteDataPayload } from '../../../core/shared/operators';
import { Item } from '../../../core/shared/item.model';
import { getItemPageRoute } from '../../../item-page/item-page-routing-paths';
/** /**
* Component to display the Quality Assurance topic list. * Component to display the Quality Assurance topic list.
@@ -66,6 +69,11 @@ export class QualityAssuranceTopicsComponent implements OnInit {
*/ */
public targetId: string; public targetId: string;
/**
* The URL of the item page.
*/
public itemPageUrl: string;
/** /**
* Initialize the component variables. * Initialize the component variables.
* @param {PaginationService} paginationService * @param {PaginationService} paginationService
@@ -77,18 +85,16 @@ export class QualityAssuranceTopicsComponent implements OnInit {
private paginationService: PaginationService, private paginationService: PaginationService,
private activatedRoute: ActivatedRoute, private activatedRoute: ActivatedRoute,
private notificationsStateService: SuggestionNotificationsStateService, private notificationsStateService: SuggestionNotificationsStateService,
private qualityAssuranceTopicsService: QualityAssuranceTopicsService private itemService: ItemDataService
) { ) {
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 +107,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 +135,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
); );
}); });
} }
@@ -158,6 +166,32 @@ export class QualityAssuranceTopicsComponent implements OnInit {
} }
} }
/**
* Returns an Observable that emits the title of the target item.
* The target item is retrieved by its ID using the itemService.
* The title is extracted from the first metadata value of the item.
* The item page URL is also set in the component.
* @returns An Observable that emits the title of the target item.
*/
getTargetItemTitle(): Observable<string> {
return this.itemService.findById(this.targetId).pipe(
take(1),
getFirstCompletedRemoteData(),
getRemoteDataPayload(),
tap((item: Item) => this.itemPageUrl = getItemPageRoute(item)),
map((item: Item) => item.firstMetadataValue('dc.title'))
);
}
/**
* Returns the page route for the given item.
* @param item The item to get the page route for.
* @returns The page route for the given item.
*/
getItemPageRoute(item: Item): string {
return getItemPageRoute(item);
}
/** /**
* Unsubscribe from all subscriptions. * Unsubscribe from all subscriptions.
*/ */

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

View File

@@ -3232,6 +3232,8 @@
"quality-assurance.topics.description": "Below you can see all the topics received from the subscriptions to {{source}}.", "quality-assurance.topics.description": "Below you can see all the topics received from the subscriptions to {{source}}.",
"quality-assurance.topics.description-with-target": "Below you can see all the topics received from the subscriptions to {{source}} in regards to the",
"quality-assurance.source.description": "Below you can see all the notification's sources.", "quality-assurance.source.description": "Below you can see all the notification's sources.",
"quality-assurance.topics": "Current Topics", "quality-assurance.topics": "Current Topics",