[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 ],
path: `${QUALITY_ASSURANCE_EDIT_PATH}/:sourceId/:targetId`,
path: `${QUALITY_ASSURANCE_EDIT_PATH}/:sourceId/target/:targetId`,
component: AdminQualityAssuranceTopicsPageComponent,
pathMatch: 'full',
resolve: {

View File

@@ -80,22 +80,27 @@ describe('QualityAssuranceTopicDataService', () => {
notificationsService
);
spyOn((service as any).findAllData, 'findAll').and.callThrough();
spyOn((service as any), 'findById').and.callThrough();
spyOn((service as any).searchData, 'searchBy').and.callThrough();
});
describe('getTopics', () => {
it('should call findListByHref', (done) => {
service.getTopics().subscribe(
(res) => {
expect((service as any).findAllData.findAll).toHaveBeenCalledWith({}, true, true);
}
describe('searchTopicsByTarget', () => {
it('should call searchData.searchBy with the correct parameters', () => {
const options = { elementsPerPage: 10 };
const useCachedVersionIfAvailable = 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', () => {
const result = service.getTopics();
const result = service.searchTopicsByTarget();
const expected = cold('(a)', {
a: paginatedListRD
});
@@ -103,20 +108,26 @@ describe('QualityAssuranceTopicDataService', () => {
});
});
describe('getTopic', () => {
it('should call findByHref', (done) => {
service.getTopic(qualityAssuranceTopicObjectMorePid.id).subscribe(
(res) => {
expect((service as any).findById).toHaveBeenCalledWith(qualityAssuranceTopicObjectMorePid.id, true, true);
}
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,
);
done();
});
it('should return a RemoteData<QualityAssuranceTopicObject> for the object with the given URL', () => {
const result = service.getTopic(qualityAssuranceTopicObjectMorePid.id);
it('should return a RemoteData<PaginatedList<QualityAssuranceTopicObject>> for the object with the given URL', () => {
const result = service.searchTopicsBySource();
const expected = cold('(a)', {
a: qaTopicObjectRD
a: paginatedListRD
});
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 { dataService } from '../../../data/base/data-service.decorator';
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';
/**
@@ -25,10 +24,10 @@ import { SearchData, SearchDataImpl } from '../../../../core/data/base/search-da
@dataService(QUALITY_ASSURANCE_TOPIC_OBJECT)
export class QualityAssuranceTopicDataService extends IdentifiableDataService<QualityAssuranceTopicObject> {
private findAllData: FindAllData<QualityAssuranceTopicObject>;
private searchData: SearchData<QualityAssuranceTopicObject>;
private searchByTargetMethod = 'byTarget';
private searchBySourceMethod = 'bySource';
/**
* Initialize service variables
@@ -46,27 +45,9 @@ export class QualityAssuranceTopicDataService extends IdentifiableDataService<Qu
protected notificationsService: NotificationsService
) {
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);
}
/**
* 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.
* @param options The search options.
@@ -75,31 +56,26 @@ export class QualityAssuranceTopicDataService extends IdentifiableDataService<Qu
* @param linksToFollow The links to follow.
* @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);
}
/**
* 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
*/
public clearFindAllTopicsRequests() {
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="pl-4 align-self-center">{{'item.qa-event-notification.check.notification-info' | translate : {num:
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
}}</button>
</div>

View File

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

View File

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

View File

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

View File

@@ -15,7 +15,7 @@
[collectionSize]="(totalElements$ | async)"
[hideGear]="false"
[hideSortOptions]="true"
(paginationChange)="getQualityAssuranceTopics()">
(paginationChange)="getQualityAssuranceTopics(sourceId, targetId)">
<ds-loading class="container" *ngIf="(isTopicsProcessing() | async)" message="'quality-assurance.loading' | translate"></ds-loading>
<ng-container *ngIf="!(isTopicsProcessing() | async)">
@@ -40,7 +40,7 @@
<button
class="btn btn-outline-primary btn-sm"
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>
<i class="fas fa-info fa-fw"></i>
</button>

View File

@@ -16,7 +16,6 @@ import { SuggestionNotificationsStateService } from '../../suggestion-notificati
import { cold } from 'jasmine-marbles';
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
import { PaginationService } from '../../../core/pagination/pagination.service';
import { QualityAssuranceTopicsService } from './quality-assurance-topics.service';
describe('QualityAssuranceTopicsComponent test suite', () => {
let fixture: ComponentFixture<QualityAssuranceTopicsComponent>;
@@ -44,18 +43,13 @@ describe('QualityAssuranceTopicsComponent test suite', () => {
providers: [
{ provide: SuggestionNotificationsStateService, useValue: mockNotificationsStateService },
{ provide: ActivatedRoute, useValue: { data: observableOf(activatedRouteParams), snapshot: {
paramMap: {
get: () => 'openaire',
params: {
sourceId: 'openaire',
targetId: null
},
}}},
{ provide: PaginationService, useValue: paginationService },
QualityAssuranceTopicsComponent,
// tslint:disable-next-line: no-empty
{ provide: QualityAssuranceTopicsService, useValue: {
setSourceId: (sourceId: string) => { } ,
setTargetId: (targetId: string) => { }
}
}
],
schemas: [NO_ERRORS_SCHEMA]
}).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';
import { PaginationService } from '../../../core/pagination/pagination.service';
import { ActivatedRoute } from '@angular/router';
import { QualityAssuranceTopicsService } from './quality-assurance-topics.service';
/**
* Component to display the Quality Assurance topic list.
@@ -76,19 +75,16 @@ export class QualityAssuranceTopicsComponent implements OnInit {
constructor(
private paginationService: PaginationService,
private activatedRoute: ActivatedRoute,
private notificationsStateService: SuggestionNotificationsStateService,
private qualityAssuranceTopicsService: QualityAssuranceTopicsService
private notificationsStateService: SuggestionNotificationsStateService
) {
this.sourceId = this.activatedRoute.snapshot.params.sourceId;
this.targetId = this.activatedRoute.snapshot.params.targetId;
}
/**
* Component initialization.
*/
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.totalElements$ = this.notificationsStateService.getQualityAssuranceTopicsTotals();
}
@@ -101,7 +97,7 @@ export class QualityAssuranceTopicsComponent implements OnInit {
this.notificationsStateService.isQualityAssuranceTopicsLoaded().pipe(
take(1)
).subscribe(() => {
this.getQualityAssuranceTopics();
this.getQualityAssuranceTopics(this.sourceId, this.targetId);
})
);
}
@@ -129,13 +125,15 @@ export class QualityAssuranceTopicsComponent implements OnInit {
/**
* 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(
distinctUntilChanged(),
).subscribe((options: PaginationComponentOptions) => {
this.notificationsStateService.dispatchRetrieveQualityAssuranceTopics(
options.pageSize,
options.currentPage
options.currentPage,
source,
target
);
});
}

View File

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

View File

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

View File

@@ -42,31 +42,46 @@ describe('QualityAssuranceTopicsService', () => {
beforeEach(() => {
restService = TestBed.inject(QualityAssuranceTopicDataService);
restServiceAsAny = restService;
restServiceAsAny.getTopics.and.returnValue(observableOf(paginatedListRD));
restServiceAsAny.searchTopicsBySource.and.returnValue(observableOf(paginatedListRD));
restServiceAsAny.searchTopicsByTarget.and.returnValue(observableOf(paginatedListRD));
service = new QualityAssuranceTopicsService(restService);
serviceAsAny = service;
});
describe('getTopics', () => {
it('Should proxy the call to qualityAssuranceTopicRestService.getTopics', () => {
describe('getTopicsBySource', () => {
it('should proxy the call to qualityAssuranceTopicRestService.searchTopicsBySource', () => {
const sortOptions = new SortOptions('name', SortDirection.ASC);
const findListOptions: FindListOptions = {
elementsPerPage: elementsPerPage,
currentPage: currentPage,
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);
expect((service as any).qualityAssuranceTopicRestService.getTopics).toHaveBeenCalledWith(findListOptions);
const result = service.getTopics(elementsPerPage, currentPage, 'openaire');
expect((service as any).qualityAssuranceTopicRestService.searchTopicsBySource).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|)', {
a: paginatedList
});
const result = service.getTopics(elementsPerPage, currentPage);
const result = service.getTopics(elementsPerPage, currentPage, 'openaire');
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
) { }
/**
* 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.
@@ -49,21 +40,25 @@ export class QualityAssuranceTopicsService {
* @return Observable<PaginatedList<QualityAssuranceTopicObject>>
* 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 findListOptions: FindListOptions = {
elementsPerPage: elementsPerPage,
currentPage: currentPage,
sort: sortOptions,
searchParams: [new RequestParam('source', this.sourceId)]
searchParams: [new RequestParam('source', source)]
};
if (hasValue(this.targetId)) {
findListOptions.searchParams.push(new RequestParam('target', this.targetId));
let request$: Observable<RemoteData<PaginatedList<QualityAssuranceTopicObject>>>;
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(),
map((rd: RemoteData<PaginatedList<QualityAssuranceTopicObject>>) => {
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', () => {
const elementsPerPage = 3;
const currentPage = 1;
const action = new RetrieveAllTopicsAction(elementsPerPage, currentPage);
service.dispatchRetrieveQualityAssuranceTopics(elementsPerPage, currentPage);
const action = new RetrieveAllTopicsAction(elementsPerPage, currentPage, 'source', 'target');
service.dispatchRetrieveQualityAssuranceTopics(elementsPerPage, currentPage, 'source', 'target');
expect(serviceAsAny.store.dispatch).toHaveBeenCalledWith(action);
});
});

View File

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